pax_global_header 0000666 0000000 0000000 00000000064 12276402000 0014503 g ustar 00root root 0000000 0000000 52 comment=e26a0a7d1a1f192a6b5046a627168bd13c18b10e
icinga-1.10.3/ 0000775 0000000 0000000 00000000000 12276402000 0013017 5 ustar 00root root 0000000 0000000 icinga-1.10.3/AUTHORS 0000664 0000000 0000000 00000001154 12276402000 0014070 0 ustar 00root root 0000000 0000000 Bernd Arnold
Hendrik Baecker
Ricardo Bartels
Jochen Bern
Gunnar Beutner
Matthew Brooks
Rune Darrud
Karl DeBisschop
Thomas Dressler
Carsten Emde
Andreas Ericsson
Duncan Ferguson
Michael Friedrich
Massimo Forni
Jean Gabes
Mathieu Gagné
Ethan Galstad
Mark Gius
DECOIT GmbH
Stephen Gran
Marius Hein
Alexander Hofmann
Matthieu Kermagoret
Petya Kohts
Julius Kriukas
Ondra 'Kepi' Kudlík
Joerg Linge
Opsera Ltd
Opsview Team
Michael Luebben
Christoph Maser
Bill McGonigle
Viranch Metha
Sean Millichamp
Chris Moates
Steven D. Morrey
Wolfgang Nieder
Hiren Patel
William Preston
Tobias Scherbaum
Ton Voon
Vitali Voroth
Mark Young
icinga-1.10.3/Changelog 0000664 0000000 0000000 00000437577 12276402000 0014660 0 ustar 00root root 0000000 0000000 #####################################################
Icinga Core / Classic UI / IDOUtils / Docs Change Log
#####################################################
Thanks to all contributers, testers and developers. Please read AUTHORS and THANKS for a detailed list :-)
UPGRADE NOTES
* for idoutils database upgrades, check the following for upgrade sql scripts
- ${source}/module/idoutils/db//upgrade/
* for configuration file changes, check the following for added/removed config options
- core, classic ui: ${source}/sample-config/updates/
- idoutils: ${source}/module/idoutils/config/updates
* package locations may differ!
1.10.3 - 11/02/2014
ENHANCEMENTS
* initscript: implement IcingaPrecacheFallback option for the init script (thx Immobilienscout24) #4968 - GB
FIXES
* core: fix passive host check commands check service's passive check acceptance (thx Naemon) #5568 - MF
* core: fix host state translation for passive host check results #5575 - MF
* classic ui: aggressively check for possible buffer overflows in cmd.cgi (thx GitHub) #5434 - MF
* classic ui: add missing jquery and jquery-ui-timepicker-addon sources #5564 - MF
* idoutils: wait for child processes on exit preventing zombies (thx Laurent Bigonville) #4427 - MF
* initscript: fix ido2db returning invalid lsb codes (Marco Hoyer) #4825 - MF
* spec: only add apache user to the icingacmd group if existing #5263 - MF
* spec: fix usermod error on SUSE #5430 - GB
* spec: backport fedora spec file fixes (thx Fedora & Shawn Starr) #5545 - MF
** Import iconset from fedora into sample config objects.
** Also use the Apache 2.4 RequireAll authorization container.
1.10.2 - 05/12/2013
ENHANCEMENTS
* core: Add an Icinga syntax plugin for Vim #4150 - LE/MF
FIXES
* core: Document dropped options log_external_commands_user and event_profiling_enabled #4957 - BA
* core: type in spec file on ido2db startup #5000 - MF
* core: Build fails: xdata/xodtemplate.c requires stdint.h #5021 - SH
* classic ui: fix status output in JSON format not including short and long plugin output properly #5217 - RB
* classic ui: fix possible buffer overflows #5250 - RB
* classic ui: fix Off-by-one memory access in process_cgivars() #5251 - RB
* idoutils: idoutils oracle compile error #5059 - TD
* idoutils: Oracle update script 1.10.0 failes while trying to drop nonexisting index #5256 - RB
1.10.1 - 04/11/2013
ENHANCEMENTS
* core: add line number information to config verification error messages #4967 - GB
FIXES
* core/idoutils: revert check_source attribute due to mod_gearman manipulating in-memory checkresult list #4958 - MF
** classic ui/idoutils schema: functionality is kept only for Icinga 2 support
* classic ui: fix context help on mouseover in cmd.cgi (Marc-Christian Petersen) #4971 - MF
* classic ui: correction of colspan value in status.cgi (Bernd Arnold) #4961 - MF
* idoutils: fix pgsql update script #4953 - AW/MF
* idoutils: fix logentry_type being integer, not unsigned long (thx David Mikulksi) #4953 - MF
1.10.0 - 24/10/2013
* idoutils: slahistory table must be removed manually after enable_sla removal #4363
- DROP TABLE icinga_slahistory
* idoutils: timedevents & timedeventqueue tables are deprecated and removed #4482
ENHANCEMENTS
* core: allow exclude (!) to work for regexp matches as well (Matthias Kerk) #3720 - MF
* core: make logging of external command errors more verbose (Anton Lofgren, op5 team) #4402 - MF
* core: avoid unnecessary ctime() calls when debugging is disabled, increase performance (Opsview Team) #4681 - MF
* core: add check source to checkresult/status data #4709 - MF
* core: fix check fails when using environment variables (Sven Nierlein) #2647 - MF
* classic ui: add display filter modification for status.cgi #852 - RB
* classic ui: log errors into cgi log (use_logging=1) #4389 - MF
* classic ui: show custom variables in extended info #4390 - MF
* classic ui: allow to exclude custom variable name/value based on pattern #4390 - MF
* classic ui: add make install-classicui-standalone-conf as seperated config installation #4664 - MF
* classic ui: added performance data to extinfo json output #4728 - RB
* classic ui: show backend version info from status file (1.x or 2.x) #4737 - MF
* classic ui: added option for partial servicegroups #2740 - RB
* classic ui: show check source in extinfo #4709 - MF
* classic ui: added live search #1657 - Kepi/RB
* idoutils: add a table trimming option for 'downtime history' #3989 - MF
* idoutils: allow to disable customvar status updates with dump_customvar_status=0|1 in idomod.cfg #4479 - MF
* idoutils: add check_source to status tables #4709 - MF
* idoutils: add object_id (host, service) to logentries status updates/state changes #4754 - MF
* docs: add samples files for reference #4422 - WN
* docs: update pnp screenshots #4288 - WN
* docs: explain icinga web expander icon #4527 - WN
* docs: add hint to views.xml config file #4690 - WN
* docs: add "show_partial_servicegroups" to cgi.cfg #4730 - WN
* docs: add "dump_customvar_status" to idomod.cfg #4705 - WN
* install: allow enable perfdata config switch via configure #3996 - MF
* install: add --enable-debug=yes/no to set specific compiler flags for gdb, valgrind #4387 - MF
* install: detect /etc/apache2/conf-available on debian with apache2.4 #4509 - MF
* install: add manpages from debian upstream #4055 - MF
* contrib: add vim highlight script for Icinga syntax #4150 - LE
FIXES
* core: multiple idomod modules: only first gets data from registered callback functions #4199 - MF
* core: fix services with no host mappings are not accepted (Viranch Metha) #3961 - MF
* core: remove event_profiling_enabled functionality causing core dumps #2244 - MF
* core: fix init script status exit codes on not running daemon and present pid file #4243 - MF
* core: replace localtime() with reentrant localtime_r() (Opsview Team) #4682 - MF
* core: fix config parser ignores errors on non-existing templates used in multiple templates levels #4702 - MF
* core: add colon to illegal_object_name_chars #4227 - MF
* core: fix umask after reset for cmd pipe #4771 - MF
* core: dump host/service initial states on event loop initialization again #3838 - MF
* core: fix scheduling a downtime should preserve the author's name if provided, not setting "(Icinga Process)" (thx Eric Stanley) #4822 - MF
* core: fix external commands for CHANGE_*_INTERVAL don't accept floating point values #4897 - MF
* classic ui: fixed Generated HTML code partly invalid #3608 - RB/Dakon
* classic ui: fix empty REMOTE_ADDR env var causes sigsegv in cmd.cgi (use_logging=1) #4445 - MF
* classic ui: fixed disapearing scheduled downtime for down hosts in tac.cgi #4260 - RB
* classic ui: Hostgroup/Servicegroup Overview: hosts not sorted alphabetical #4404 - RB
* idoutils: remove enable_sla functionality (deprecated in 1.9) #4363
* idoutils: fix duration integer columns could run out of range (William Epler) #4420 #4939 - MF
* idoutils: remove timedevent support and tables #4482 - MF
* idoutils: fix comments(history) UK misses object_id, not allowing the same comment on host AND service #4544 - MF
* idoutils: fix contact_notificationcommands contain garbage and insert faulty command object ids (thx mhein/mjentsch) #4799 - MF
* idoutils: deprecate clean_{config,realtime}_tables_on_core_startup #4791 - MF
* idoutils: fix ido2db does not clear scheduleddowntime table on instance startup #4808 - MF
* docs: quickstart guides / default changed to compilation of IDOUtils #4203 - WN
* docs: update icinga web troubleshooting for timezones #4554 - WN
* docs: remove enable_sla, timedevent* from idoutils docs #4487 - MF
* docs: add colon to illegal_object_name_chars #4704 - MF
* install: fix initscripts exit-code 1 on start when service is already started (thx Marco Hoyer) #4393 - MF
* install: fix ido2db initscript: kill fails on stop() on debian wheezy #4504 - MF
* icinga.spec: remove commandgrp/user flags for configure (INSTALL_OPTS useless on package build) #4394 - MF
SUPPORT
* fixed gcc warnings about unused vars and unused return values #3984 - RB
* fixed gcc errors in extinfo.c and ido2db.c #4392 - CF
* fix warnings with CLANG compiler #4159 - MF
* added cgi JSON output tests #3203 - RB
* classic ui: javascript cleanup and common.lib added #4324 - RB
CHANGES
* core: multiple neb modules from same bin are copied to tmp with random name (again) #4199
** trick dlopen() to register callbacks for every neb module with different instance_name
** no need to manually copy binaries around
* core: drop event_profiling_enabled functionality #2244
* core: add colon to illegal_object_name_chars #4227
** reason are on-demand macros not working in #4005
* core: broker_{host,service}_data accept check_source parameter #4709
* core: dump_retained_host_service_states_to_neb is now disabled (re-enabled timing loop updates instead) #3838
* classic ui: added custom vars to json_output in extinfo.cgi #4390
* classic ui: add exclude_customvar_name and exclude_customvar_value to cfg.cfg #4390
** patterns to be excluded, comma seperated list
* classic ui: make install-classicui-standalone does not install configs anymore #4664
** use make install-classicui-standalone-conf instead
* idoutils: add max_downtimhistory_age to ido2db.cfg #3989
* idoutils: remove enable_sla functionality (deprecated in 1.9) #4363
* idoutils: remove timedevents functionality, drop tables #4482
* idoutils: unique constraint on comments/commenthistory tables #4544
* idoutils: customvariablestatus table not updated by default (dump_customvar_status=0) #4479
* idoutils: dump_customvar_status=0|1 in idomod.cfg #4479
* idoutils: add 'check_source' column to {host,service}_status tables #4709
* idoutils: clean_{config,realtime}_tables_on_core_startup are now DEPRECATED #4791
* idoutils: add 'object_id' to logentries table (NULL if not provided) #4754
* install: configure --enable-perfdata sets icinga.cfg:process_performance_data #3996
1.9.3 - 07/07/2013
FIXES
* core: fix init script status exit codes on not running daemon and present pid file #4243 - MF
* idoutils: fix workaround on libdbi fetch_next_row() bug applied for postgresql too, causing faulty queries #4367 - MF
1.9.2 - 30/06/2013
FIXES
* core: fix bug with non-ASCII (> 127) illegal macro output characters on char-to-int cast (Jason Young) #4211 - MF
* core: bail early if main config file cannot be read - MF
* classic ui: fixed searching hostgroup results in wrong 'all' view filter urls #4206 - RB
* classic ui: fix URL construction issue in icinga_reload_scroll_position() javascript (Karsten Sühring) #4233 - MF
* idoutils: fix mysql: output/perfdata limits cut escaped string leaving '\' at the end (Yannik Charton) #4196 - MF
* idoutils: bugfixes for socket queue, transactions and libdbi handling #4049 - GB
* idoutils: fix ido2db gradually consumes more and more CPU time with time #4210 - CF
* idoutils: fix wrong clob freeing in eventhandlers #4357 - TD
1.9.1 - 22/05/2013
FIXES
* core: fix objects.cache does not get updated on (re)start, but config verify (Christian Ruppert) #4155 - MF
* classic ui: fixed UNICODE characters in JSON output from getting discarded #4193 - RB
* idoutils: fix segfaults on reload with multiple neb modules of the same binary #4033 - MF
1.9.0 - 07/05/2013
NOTES
* idoutils uses a socket queue and transactions for large object dumps! #3527 #3533
* ido2db.cfg enable_sla is now deprecated! #3450
* icinga.cfg event_profiling_enabled is now deprecated! #4054
ENHANCEMENTS
* core: increase performance with hash comparing hosts/services on config read #3722 - GB
* core: introduce warning level -vv on config verification #3510 - MF
* core: refuse to start if neb modules fail to load (Andreas Ericsson, op5 Team) #3812 - MF
* core: keep logfile open, reducing open/close performance decreases (Andreas Ericsson, op5 Team) #3390 - MF
* core: enhance illegal macro character processing performance (Andreas Ericsson, op5 Team) #3389 - MF
* core: add the notification type by string to debug logs; set CUSTOM=8, STALKING=9 (Andreas Ericsson, op5 Team) #3818 - MF
* core: skip writing status.dat if explicitely set to /dev/null (e.g. when using alternate data retrieval methods like IDOUtils) (Andreas Ericsson, op5 Team) #3819 - MF
* core: avoid writing objects.cache if set to /dev/null (Andreas Ericsson, op5 Team) #3819 - MF
* core: increase performance on host->service relation counter (config reading, flapping) #3820 - MF
* core: fix unable to exclude hostgroups when using nested hostgroups (Alexander Sulfrian) #2619 - MF
* classic ui: increase performance with hash comparing hosts/services to show/filter #3722 - GB
* classic ui: Add "set_expire_ack_by_default" to cgi configuration #3476 - CF
* classic ui: Add "send_ack_notifications" to cgi configuration (TheCry) #3467 - CF
* classic ui: Changed field size for hours to 4 when setting flexible downtime #3484 - RB
* classic ui: Added process status to JSON response #3172 - RB
* classic ui: Added date/time selection to 'log file navigation' #3168 - RB
* classic ui: Added setting focus to main frame on first site load #3202 - RB
* classic ui: Made sort buttons larger #3814 - RB
* classic ui: Made classic ui work standalone #3869 - RB
* classic ui: add 'executed command' to extinfo.cgi linking to command expander #3901 - MF
* idoutils: use transactions for large object dumps #3527 - GB
* idoutils: add socket queue proxy addressing core reload problems #3533 - GB
* idoutils: add more indexes for sla reporting #3649 - MF
* idoutils: Oracle - change output fields to clob #3412 - TD
* install: set --enable-idoutils/event-broker to true as default configure flags #3813 - MF
* install: add lighttp config samples to contrib/lighttp #2253 - RB
* install: add --with-httpd-conf-file to allow specific apache config to be installed #3962 - MF
* install: make install-webconf-auth installs htpasswd.users automatically, allowing default icingaadmin login out-of-the-box #3963 - MF
* install: add 'make classicui-standalone' and 'make install-classicui-standalone' #3963 - MF
* docs: Temporary files should mention temp_file option in icinga.cfg #3748 - WN
* docs: add upgrade/troubleshooting notes about invisible icinga web cronks/modules after upgrade #3939 - WN
* docs: make install-webconf-auth installs htpasswd.user with icingaadmin credentials #3964 - WN
* docs: icinga web 1.9: new menu style (smaller icons) #3944 - MF
* docs: icinga web 1.9: new filtering methods #3947 - MF
* docs: add userpreferences.xml to icinga web configs #3991 - WN
* docs: add web gui comparison to beginners #3907 - WN
FIXES
* core: fix faulty macro cleaning, replacing spaces with pluses where they shouldn't be cleaned #3397 - MF
* core: fix macro escaping logs incorrect warning for $$escapes #3404 - MF
* core: fix wrong escalation notification due to state based escalation range behaviour changes #3441 - MF
* core: change ownership of (debug) log file before dropping privileges (Andreas Ericsson, op5 Team) #3521 - MF
* core: fix keep_unknown_macros still exposes wrong warnings to logs #3725 - MF
* core: fix host_check, last_check == next_check wrong in scheduling queue #2195 - MF
* core: fix triggered downtimes for child hosts are missing after icinga restart (thx Michael Lucka) #3390 - MF
* core: fix services with empty hostgroups aren't processed even if it has host_name specified (allow_empty_hostgroups=1) (thx Viranch Metha) #3736 - MF
* core: revamp USE_LTDL definitions in nebmods (Andreas Ericsson, op5 Team) #3817 - MF
* core: fix checkresult reaper cleanup fails due to relative file path #3937 - MaF
* core: do not export host/servicegroupmembers as environment macros in large installations #3859 - MF
* core: set default permissions to icinga/ido2db binaries to 755 #3902 - GB
* classic ui: fix cmd.cgi does not honor commandpipe location; overwrites from empty environment variable #3418 - MF
* classic ui: fixed Double-listed host dependencies in host extinfo.cgi #3295 - RB
* classic ui: fixed sort_icinga_logfiles_by_name() in readlogs.c fails to take NULL pointers into consideration #3398 - CF
* classic ui: fixed committing acknowledgement cmd negates flags for send_notification and sticky_ack #3329 - RB
* classic ui: fixed backtrack_archives only getting calculated on a daily log rotation basis #3416 - RB
* classic ui: fixed invalid freeing of last_check in 'scheduling queue' for first time checks #3444 - RB
* classic ui: fixed Warning and Unknown States are mixed up in Alert Summary Report #3488 - RB
* classic ui: fixed extinfo.cgi shows localtime(0) instead of "NOT SET" when global notifications are not set to expire #3482 - RB
* classic ui: fixed CGIs generating invalid html code/ json when throwing error #3507 - RB
* classic ui: fixed JSON output is insufficiently escaped #3541 - RB
* classic ui: fixed segfault when reading malformed log entries #3528 - RB
* classic ui: "fixed" Incorrect positioning status popup in statusmap #3861 - RB
* classic ui: fixed possible NULL dereference-bug in summary.c #3740 - RB
* classic ui: fixed Command expansion problem with percentage signs #3929 - RB
* classic ui: cleaned up the jquery-ui includes to allow debian pkg dependencies #3808 - RB
* classic ui: fixed Trigger Time in Scheduled Downtime displaying 01-01-1970 01:00:00 when not triggered #3980 - RB
* classic-ui: fixed host and service names are not allowed to have a '+' included #1843 - RB
* idoutils: fix many memory leaks in ido2db on dbi_result_free and others (thx Klaus Wagner) #3406 - MF
* idoutils: fix ido2db crashes when Oracle queries fail #3324 - GB
* idoutils: fix ORA-1461 writing data to varchar2 exceeding field size limit output, command_arg and commandline data written to Oracle #3324 #3325 - TD
* idoutils: fix unsafe handling of dbi_conn_sequence_last, rewrite last_insert_id/sequence fetching #3408 - MF
* idoutils: fix ido2db does not cleanly exit the client on wrong schema version check in db_hello #3419 - MF
* idoutils: fix FROM_UNIXTIME(NULL) does not work with MySQL 5.0.x #3399 #3466 - CF
* idoutils: fix unknown column contactaddress_id (thx fmbiete) #3483 - MF
* idoutils: fix empty output/perfdata segfaults for mysql string truncate #3516 - MF
* idoutils: unlink leftover socket on startup, if using unix sockets - MF
* idoutils: fix long output data causes wrong data in database #2342 - MF
* idoutils: fix idomod leaks memory on core reload #3749 - GB
* idoutils: add workaround fix for num_rows_affected broken in libdbi/mariadb, returned ids are 0 #3728 - MF
* install: drop unused daemon-init-readhat script (spec uses daemon-init) #3402 - MF
* install: fix broken configure ssl detection for idoutils on ubuntu/debian (Oliver Skibbe) #3413 - MF
* docs: add missing cmd_mod description in cgi params #3438 - MF
* docs: search_string as cgi GET param works also for status.cgi #3451 - MF
* docs: fix typo pqsql -> pgsql #3461 - WN
* docs: recurring downtimes: should tell about dev/experimental state living in contrib/ better #3647 - WN
* docs: middle-clicking on TOC links doesn't open pages in new tab #3561 - WN
* icinga.spec: add idoutils as transitional package (thx Stefan Marx, Michael Grüner) #3640 - MF
* icinga.spec: fix double %{logdir}/gui/ definitions in icinga and icinga-gui (thx René Koch) #3802 - MF
CHANGES
* ido2db.cfg: enable_sla is now deprecated! #3450
* icinga.cfg: event_profiling_enabled is now deprecated! #4054
* icinga.cfg: enable_state_based_escalation_ranges=0 (disabled if not set) fix for #3441
* icinga.cfg: set status_file=/dev/null to disable its creation #3819
* icinga.cfg: set object_cache_file=/dev/null to disable its creation #3819
* idoutils: use transactions for large object dumps #3527
* idoutils: add socket queue proxy addressing core reload problems #3533
* core: -v param can be used more than once #3510
* core: 'Warning: Host ... has no service associated with it!' now happens only in icinga -vv icinga.cfg #3510
* core: refuse to start if neb modules fail to load #3812
* core: notification type nr CUSTOM=8 and STALKING=9 (reflected in idoutils tables) #3818
* core: using nested hostgroups you can exclude (!) hostgroup_members #2619
* core: host/servicegroupmembers are not exported as environment macros #3859
** if enable_environment_macros=1
** and use_large_installation_tweaks=1
* icinga.spec: add idoutils as transitional package #3640
* install: set --enable-idoutils/event-broker to true as default configure flags #3813
* install: add --with-httpd-conf-file to allow specific apache config to be installed #3962
** this is important when installing standalone classic ui for e.g. Icinga2
* install: make install-webconf-auth installs htpasswd.users, allowing default icingaadmin login out-of-the-box #3963
* install: add --enable-classicui-standalone #3869
** sets cgi.cfg standalone_installation=1
* install: add 'make classicui-standalone' and 'make install-classicui-standalone' #3963
** this will install classic ui standalone, if enabled
* install: default permissions for icinga/ido2db binaries are now 755 #3902
1.8.4 - 13/01/2013
FIXES
* core: add fix for CVE-2012-6096 - history.cgi remote command execution (Eric Stanley, Markus Frosch) #3532 - MF
* classic ui: Changed field size for hours to 4 when setting flexible downtime #3484 - RB
* classic ui: fixed Warning and Unknown States are mixed up in Alert Summary Report #3488 - RB
* idoutils: fix empty output/perfdata segfaults for mysql string truncate #3516 - MF
* idoutils: unlink leftover socket on startup, if using unix sockets - MF
* idoutils: fix long output data causes wrong data in database #2342 - MF
1.8.3 - 12/12/2012
FIXES
* idoutils: fix unknown column contactaddress_id (thx fmbiete) #3483 - MF
1.8.2 - 28/11/2012
FIXES
* core: fix macro escaping logs incorrect warning for $$escapes #3404 - MF
* core: fix wrong escalation notification due to state based escalation range behaviour changes #3441 - MF
* idoutils: fix many memory leaks in ido2db on dbi_result_free and others (thx Klaus Wagner) #3406 - MF
* idoutils: fix ido2db crashes when Oracle queries fail #3324 - GB
* idoutils: fix ORA-1461 writing data to varchar2 exceeding field size limit output, command_arg and commandline data written to Oracle #3324 #3325 - TD
* idoutils: fix unsafe handling of dbi_conn_sequence_last, rewrite last_insert_id/sequence fetching #3408 - MF
* idoutils: fix ido2db does not cleanly exit the client on wrong schema version check in db_hello #3419 - MF
* idoutils: fix FROM_UNIXTIME(NULL) does not work with MySQL 5.0.x #3399 #3466 - CF
* install: drop unused daemon-init-readhat script (spec uses daemon-init) #3402 - MF
* install: fix broken configure ssl detection for idoutils on ubuntu/debian (Oliver Skibbe) #3413 - MF
* classic ui: fix cmd.cgi does not honor commandpipe location; overwrites from empty environment variable #3418 - MF
* classic ui: fixed double-listed host dependencies in host extinfo.cgi #3295 - RB
* classic ui: fixed sort_icinga_logfiles_by_name() in readlogs.c fails to take NULL pointers into consideration #3398 - CF
* classic ui: fixed committing acknowledgement cmd negates flags for send_notification and sticky_ack #3329 - RB
* classic ui: fixed backtrack_archives only getting calculated on a daily log rotation basis #3416 - RB
* classic ui: fixed invalid freeing of last_check in 'scheduling queue' for first time checks #3444 - RB
* docs: add missing cmd_mod description in cgi params #3438 - MF
* docs: search_string as cgi GET param works also for status.cgi #3451 - MF
* docs: fix typo pqsql -> pgsql #3461 - WN
CHANGES
* icinga.cfg - enable_state_based_escalation_ranges=0 (disabled if not set) fix for #3441
1.8.1 - 25/10/2012
FIXES
* core: fix faulty macro cleaning, replacing spaces with pluses where they shouldn't be cleaned #3397 - MF
1.8.0 - 18/10/2012
host object attributes 'vrml_image' and '3dcoords' are deprecated due to the removal of the 3d statusmap (statuswrl).
ENHANCEMENTS
* core: pass long_output to neb api for statechange data #2650 - MF
* core/classic ui: make hashfunc more efficient by using sdbm #2761 - MF/GB
* core: try the most common macros ($ARGn$, $USERn$) first (Andreas Ericsson) #2674 - MF
* core: use binary search when looking up macro names, instead of insane strcmp() loops (Andreas Ericsson) #2675 - MF
* core: add useful message to p1.pl when epn plugin does not call exit() (Sven Nierlein) #2431 -MF
* core: re-enable state based escalation ranges, using cast tricks #2878 - MF
** livestatus and other neb modules not using the icinga headers won't see those
* core: add a command to disable notifications program-wide with expire time as scheduled event #905 - MF
** DISABLE_NOTIFICATIONS_EXPIRE_TIME, works for global notifications
* core: add hint on icinga.cfg package location, and tip to read Changelog CHANGES on upgrades #2879 - MF
* core: add new callback NEBTYPE_CONTACTNOTIFICATIONMETHOD_EXECUTE to allow override of sending notifications #2041 - MF
* core: only reap results when checkresult_list is not overloaded (max_check_result_list_items) (thx Thomas Gelf) #3099 - MF
* core: log a message when reaper max time is reached #3159 - MF
* classic ui: Dropped statuswml.cgi #2654 - RB
* classic ui: Dropped statuswrl.cgi #2359 - RB
* classic ui: Added action_url/notes_url to status.cgi for csvoutput and jsonoutput #2553 - RB
* classic ui: Added pagination to various cgi's (thx to ideas and partly source from Nagios, Thruk, Icinga Web) #2725 - RB
** status.cgi for host & service status
** config.cgi
** extinfo.cgi for scheduling queue, comments and downtimes
** history.cgi
** notifications.cgi
** showlog.cgi
** icons sourced from "Silk icon set" (http://www.famfamfam.com/lab/icons/silk/) created by Mark James.
* classic ui: Changed search in config.cgi to regex #2884 - RB
* classic ui: Added config option to let read-only users see comments and downtimes #2699 - RB
* classic ui: Added selection of timeperiod for notifications and history #2341 - RB
* classic ui: add support for disable notifications with expire time to extinfo.cgi, Process Info #905 - MF
* classic ui: Refactored reading of logfiles again #972 - RB
* classic ui: Dropped context help entirely #2892 - RB
* classic ui: Separate host_name/display_name and service_description/display_name in json output #2693 - RB
* classic ui: Added date/time selection for all date/time input fields #2576 - RB
* classic ui: Added 'All Problems' to 'Problems' group in menu #2645 - RB
* classic ui: Added host/service selection for commands, leaving out passive only checks on check reschedule in cmd.cgi #2697 - RB
* classic ui: add host_has_been_acknowledged and service_has_been_acknowledged to extinfo.cgi jsonoutput (Torsten Rehn) #3000 - MF
* classic ui: Added host/service group filter to notifications.cgi & history.cgi #2679 - RB
* classic ui: javascript refresh jumps to page top, not restoring previous scrolling position; add url param 'scroll=' #2855 - MF
* classic ui: Cleaned up "linkBox" in all cgi's #3154 - RB
* classic ui: add command to delete host downtime and all associated service downtimes (extinfo.cgi, status.cgi command drop down) #1572 - RD/MF
* classic ui: Added config option to convert login username to lower case #3171 - AH
* classic ui: Added a refresh button to tac.cgi in header mode #3164 - RB
* classic ui: Added state type to JSON in status.cgi #3195 - RB
* idoutils: do not pass host and port if not set in the config, letting mysql|pgsql drivers autoselect the socket #2698 - MF
* idoutils: fix doubled quotes by skipping escaping data (Oracle only) #2534 - TD
* idoutils: change hasfunc to use sdbm algorithm for hashing precached objects #2792i - MF/GB
* idoutils: add disable_notif_expire_time to programstatus table - #905 - MF
* idoutils: add socket_perm to set unix socket permissions (Lennart Betz) #2659 - MF
* idoutils: upgradedb script for mysql installs all updates between $version and $currentrelease (Philipp Deneu) #2685 - MF
* idoutils: add --with-libdbi-driver-dir to configure, libdbi_driver_dir to ido2db.cfg to pass the driver location instead of NULL by default #2691 - MF
* idoutils: add experimental ido event to en/disable objects to ido2db (unusued in idomod!) #3068 - MF
* install: add --with-mainurl to configure, allowing to set the main frame target url for index.html #2611 - MF
* config: add config added/removed diffs between versions for better upgrading #2608 - MF
** sample-config/updates/ and module/idoutils/config/updates/
* contrib: add nginx configuration for icinga classicui by Francisco Miguel Biete into contrib/nginx #2253 - MF
* docs: add a new stylesheet and rework docbook.xsl #3046 - MF
* docs: add tocs for all sections #3193 - WN
* docs: add jquery toggle for toc #3193 - MF
* docs: create a dedicated page for packages and their customizations #2905 - LB
* docs: create a howto define a command, translate macros and testdrive plugins manually #2692 - WN
* docs: add a hint to debian backports, ubuntu ppa and rhel repoforge and link to wiki url for quickstart guides #2803 - WN
* docs: add new icinga-web-intro, icinga reporting for 1.8 #3218 #3264 - LB
* docs: all other new config options due to 1.8 features, please check https://dev.icinga.org/projects/icinga-docs/versions/80
* icinga.spec: use --with-mainurl to set the default to /icinga/cgi-bin/status.cgi?host=all&type=detail&servicestatustypes=29 #2611 - MF
* icinga.spec: add devel package #2634 - MF
FIXES
* core: unify check scheduling replacement logic for new events (Andreas Ericsson) #2676 - MF
* core: get rid of the instame macro usage while logging alerts and states (Andreas Ericsson) #2665 - MF
* core: revamp the detection of embedded perl usage directive "# icinga: +epn" (Andreas Ericsson) #2197 - MF
* core: fix whitespaces are not stripped using multiple templates ("use abc, def, ghi") #2701
* core: make delete_downtime_by_hostname_service_description_start_time_comment threadsafe (Andreas Ericsson) #2899
* core: bail out early with config error if resource.cfg macros contain NULL values #2879 - MF
* core: fix logical bug on icinga.cfg detection on config read #2879 - MF
* core: free raw_command immediately after processing the macros / not needing them anymore - MF
* core: fsync() files before fclose() (Andreas Ericsson) #2949 - MF
* ocre: remove weird switch() statement when scanning checkresult queue (Andreas Ericsson) #2950 - MF
* core: fix deleting too old check result files (Andreas Ericsson) #2951 - MF
* core: avoid duplicate events when scheduling forced host|service check (Imri Zvik) #2993 - MF
* core: unknown macros are not replaced, and misleading to single dollar signs #2291 - MF
** you can revert to the old behaviour with keep_unknown_macros=1 in icinga.cfg
* core: fix having empty host/servicegroups, $HOST|SERVICEGROUPMEMBERS$ on-demand macro returns garbage on realloc (thx roguelazer) #2913 - MF
* core: allow multiple empty (host)groups chained with enabled allow_empty_hostgroup_assignment #2437 - MF
* core: fixed when deleting an expiring ack the event to delete the ack doesn't get deleted #3084 - RB
* core: fix error checking on subgroup expanding on host|service|contactgroup members #3088 - MF/RB
* core: fix lockup on DEL_DOWNTIME_BY_HOST_NAME command #1572 - MF
* core: fix next_check attribute not updated after scheduling new check #2265 - MF
* classic ui: fix setting send_notification or sticky_ack as GET param has no effect on cmd.cgi acks #2926 - MF
** now you can finally disable checkboxes default ticked with these options
* classic ui: Fixed clicking an (action|notes)url in a row automatically ticks the row for the commands #2809 - RB
* classic ui: menu search can't handle umlauts in hostnames correctly (changed to utf8) #2999 - MF
* classic ui: fix cmd.cgi does not read enviroment variable ICINGA_COMMAND_FILE (thx Dirk Goetz) #3106 - MF
* classic ui: Fixed stylesheets for tac_header and menu not working well #3026 - RB
* idoutils: set result handle explicitely to NULL after dbi_result_free() to prevent memory free'ing corruption #2612 - MF/GB
* idoutils: fix ignoring mysql password in create_mysqldb.sh #2994 - MF
* idoutils: fix sla_downtime_select query and result handle; scheduled downtime merge statement #2780 - MF
* idoutils: fix insert on duplicate key with multiple unique keys marked unsafe in mysql >= 5.5.24; rewrite all queries #3008 - MF
* idoutils: fix redundant indexes in MySQL schema (thx Michael Renner) #3018 - MF
* idoutils: re-add missing indexes from #1110 resolving performance issues on all supported rdbms #2618 - MF
* idoutils: fix IDOUtils on PostgreSQL, recreates service objects in icinga_objects (thx Torsten Fohrer) #3166 - MF
* install: fix icinga.xml for solaris pkg not updated #2609 - CF
* docs: fix wrong charset UTF-8 set in documentation #2091 - MF
* docs: update the beginners page #3213 - WN
* docs: update external command descriptions for DEL_DOWNTIME_BY_HOST_NAME, DEL_DOWNTIME_BY_START_TIME_COMMENT, DEL_DOWNTIME_BY_HOSTGROUP_NAME #3165 - WN
* docs: add tar.gz urls to nsca and nrpe docs #2797 - WN
* docs: fix cgi.conf - HTML and inline documentation mess and errors #2891 - WN
* docs: cgiparams: cmd.cgi: send_notifications and sticky_ack now require 0|1 values, default is enabled #2927 - WN
* docs: replace make db-doc2sql with location of plain schema sqls in etc/schema #2936 - WN
* docs: fix icinga.conf and HTML documentation mess #2941 - LB
* docs: fix an illegal_macro_output_char is missing from the sample config #2842 - WN
* docs: fix Erronous example in Macros documentation #2966 - WN
* docs: Names of config files irrelevant #3097 - WN
* docs: fix idoutils db user grants miss EXECUTE #3192 - MF
* docs: fix rong restart command in list of external commands #3214 - MF
* icinga.spec: fix permissions on ido2db.cfg potentially world readable (Aaron Russo) #2897 - MF
* icinga.spec: drop unsupported configure flags #3037 - MF
CHANGES
* core: neb struct statechange data += long_ouput #2650 - MF
* core: new command
** DISABLE_NOTIFICATIONS_EXPIRE_TIME;; (set schedule_time to now()) #905
* core: unknown macros are not left on the output anymore, logging a warning instead
** either fix your config (i.e. wrong macros, escape dollar signs with another one)
** or set keep_unknown_macros=1 in icinga.cfg to revert to the old behaviour
* core: max_check_result_list_items will set the max number of checkresults waiting for being processed #3099
** if checkresult_list is "full", the checkresult reaper will bail early
** leaving the core time to process the existing items on checkresult list
** max_check_result_list_items=0 is the default, disabling this feature
** max_check_result_list_items=1024 should work in larger distributed setups
* core: new NEB callback NEBTYPE_CONTACTNOTIFICATIONMETHOD_EXECUTE (606) #2041
* classic ui: changed "cgi_json_version" to 1.8 -> see Changelog_json for changes
* classic ui: Changed cgi GET params
** Added "limit" and "start" for pagination to various cgi's - #2725
** Added "ts_start", "ts_end" and "order" to history.cgi and notifications.cgi - #2341
** Removed "archive" and "oldestfirst" from history.cgi and notifications.cgi - #2341
** Added "start_time", "end_time" and "timeperiod" to notifications.cgi - #2341
** "send_notification" and "sticky_ack" on cmd.cgi require 0|1 vars, if not set, default is 1 #2926
** add "scroll", interpreted by javascript reload to restore the scrolling position #2855
** Added "hostgroup" and "servicegroup" to history.cgi and notifications.cgi #2679
** Added "scroll", interpreted by javascript reload to restore the scrolling position #2855
** Added "search_string" and "item_name" to config.cgi #2884
classic ui: Added/Changed cgi.cfg options
** authorized_for_comments_read_only - #2699
** authorized_for_downtimes_read_only - #2699
** authorized_contactgroup_for_comments_read_only - #2699
** authorized_contactgroup_for_downtimes_read_only - #2699
** "result_limit" (default: 50) - #2725
** "result_limit" replaces "default_num_displayed_log_entries" - #2725
** default_expiring_disabled_notifications_duration=86400 #905
** lowercase_user_name - #3171
* classic ui: change strings in json output: !!!IMPORTANT!!!
** host -> host_name #2693
** service -> service_description #2693
** description -> service_description #2693
** added host_display_name #2693
** added service_display_name #2693
** added host_has_been_acknowledged and service_has_been_acknowledged to extinfo.cgi #3000
** added state_type to host and service status in status.cgi #3195
* classic ui: added checkbox in cmd.cgi to deselect unintentional selected hosts/services #2697
* idoutils: add disable_notif_expire_time to programstatus table #905
* idoutils: ido2db.cfg new config options
** socket_perm (default 0755) #2659
** libdbi_driver_dir (default NULL) #2691
* idoutils: add experimental IDO_API_{EN,DIS}ABLE_OBJECT in ido2db #3068
* install: add --with-libdbi-driver-dir to configure #2691
* docs: new stylesheet in html/docs/stylesheets/icinga-docs.css #3046
* docs: add tocs for all sections #3193
* docs: add toc toogle javascript in html/docs/js/{icinga-docs.js,jquery-min.js} #3193
* icinga.spec: add devel package #2634
* icinga.spec: forced update on icinga.cfg change package locations #2923
1.7.4 - 13/01/2013
FIXES
* core: add fix for CVE-2012-6096 - history.cgi remote command execution (Eric Stanley, Markus Frosch) #3532 - MF
1.7.3 - 08/11/2012
FIXES
* core: fix embedded perl segfault #3027 - MF
* idoutils: fix IDOUtils on PostgreSQL, recreates service objects in icinga_objects (thx Torsten Fohrer) #3166 - MF
1.7.2 - 27/08/2012
FIXES
* core: fix duplicated events on check scheduling logic for new events (Andreas Ericsson) #2676 #2993 - MF
* core: avoid duplicate events when scheduling forced host|service check (Imri Zvik) #2993 - MF
* core: get rid of the instame macro usage while logging alerts and states (Andreas Ericsson) #2665 - MF
* core: revamp the detection of embedded perl usage directive "# icinga: +epn" (Andreas Ericsson) #2197 - MF
* core: fix whitespaces are not stripped using multiple templates ("use abc, def, ghi") #2701 - MF
* core: add hint on icinga.cfg package location, and tip to read Changelog CHANGES on upgrades #2879 - MF
* core: bail out early with config error if resource.cfg macros contain NULL values #2879 - MF
* core: fix logical bug on icinga.cfg detection on config read #2879 - MF
* core: fsync() files before fclose() (Andreas Ericsson) #2948 - MF
* core: remove weird switch() statement when scanning checkresult queue (Andreas Ericsson) #2950 - MF
* core: fix deleting too old check result files (Andreas Ericsson) #2951 - MF
* idoutils: fix icinga mysql db creation script grants access to all dbs #2917 - MF
* idoutils: fix ignoring mysql password in create_mysqldb.sh #2994 - MF
* icinga.spec: forced update on icinga.cfg change package locations #2923 -MF
* icinga.spec: fix permissions on ido2db.cfg potentially world readable (Aaron Russo) #2897 - MF
1.7.1 - 18/06/2012
FIXES
* core: use prefix in solaris service definition #2609 - TD/CF
* core: fix various memory leaks in downtime eventhandling on SIGHUP (Carlos Velasco) #2666 - MF
* classic ui: Fixed status.cgi time out when displaying hostgroups in large environments #2617 - RB
* classic ui: Fixed Invalid JSON output for hostgroup overview (Torsten Rehn) #2680 - RB
* classic ui: Fixed Confusing use of display_name in JSON and CSV output (Torsten Rehn) #2681 - RB
* classic ui: Fixed wrong totals in "Service Status Summary" on Status Summary page (Mark Ziesemer) #2689 - RB
* idoutils: fix small compiler issues #2620 - TD/CF
* idoutils: fix upgradedb script typos & past changes #2682 - MF
* config: check_ido2db_procs.cfg should not depend on local-service template #2616 - MF
* install: adapt lsb headers for icinga and ido2db #2637 - MF
* install: fix typo in contrib/eventhandlers/redundancy-scenario1/handle-master-proc-event (thanks uosiu) #2671 - MF
1.7.0 - 15/05/2012
!!! ATTENTION !!!
idomod.o was renamed to idomod.so, module extension is now .so
idomod.so will now be installed to $libdir instead of $bindir
Check the upgrade docs: http://docs.icinga.org/latest/en/upgrading.html
!!! ATTENTION !!!
ENHANCEMENTS
* core: notifications: Create contact list after eventbroker callbacks (Andreas Ericsson) #2110 - MF
* core: fix event removal from queues with O(1) removal from doubly linked lists (Andreas Ericsson) #2183 - MF
* core: avoid senseless looping when free()'ing macros (Andreas Ericsson) #2184 - MF
* core: avoid insane looping through event list when rescheduling checks (Mathias Kettner, Andreas Ericsson) #2182 - MF
* core: allow empty host groups in service and host dependencies if allow_empty_hostgroup_assignment flag is set (Daniel Wittenberg) #2255 - MF
* core: fix compatibility problems on solaris 10 (affects core, cgis, ido) (Carl R. Friend) #2292 - MF/RB/TD
* core: add trigger_time to downtimes to allow calculating of flexible downtimes endtime #2537 - MF
* core: add nebmodule version/name check for idomod (this allows future version dependencies) #2569 - MF
* classic ui: Added option for max log entries displayed in showlog.cgi #2145 - RB
* classic ui: Added config option for status totals in status.cgi #2018 - RB
* classic ui: Added multiple hosts/services to status.cgi GET #1981 - RB
* classic ui: Added nostatusheader in status.cgi as config option #2018 - RB
* classic ui: Added statusmap resizing with exclude/include button (thanks to Mat) #2186 - RB
* classic ui: Added Select hosts or services by clicking on line instead of box #2118 - RB
* classic ui: include graph icons by default in logos #2222 - MF
* classic ui: added missing comment tool tip box to outages.cgi #2396 - RB
* classic ui: add javascript to refresh page/pause easier #2119 - RB
* classic ui: Added Scheduling queue filter for specific host or service #2421 - RB
* classic ui: add display_status_totals as cgi.cfg option in order to allow the status totals to be shown again #2443 - RB
* classic ui: Changed reading of auth information from cgiauth.c to cgiutils.c #2524 - RB
* classic ui: Added readonly cgi.cfg view into the config section #1776 - RB
* classic ui: add is_in_effect and trigger_time to downtime view for html, csv, json #2538 - MF
* classic ui: add modified attributes row to extinfo.cgi showing diffs to original config (thx Sven Nierlein for the idea) #2473 - MF
* classic ui: add modified attributes reset command to extinfo.cgi allowing to reset to original config #2474 - MF
* idoutils: add new index for state in table statehistory #2274 - TD
* idoutils: add is_in_effect and trigger_time to scheduleddowntime and downtimehistory tables #2539 - MF
* idoutils: change varchar(255) to TEXT in mysql (not cs and address rfc columns) #2181 - MF
* idoutils: enhance dbversion table with modified and created columns #2562 - MF
* idoutils: set module info in idomod, to be checked on neb module load in future versions #2569 - MF
* install: add configure option --with-temp-file= to set temp_file for icinga.cfg #2121 - MF
* install: add --with-plugin-dir to configure for setting the plugins path accordingly #2344 - MF
* install: change default target location of idomod.so from $bindir to $libdir #2346 - MF
** packagers dreams come finally true! :)
* install: introduce "lib/" in default prefix install for modules #2347 - MF
* install: revamp the broker_module entry in icinga.cfg pointing to new module definition #2348 - MF
* install: change idomod extension from .o to .so, make .so the default extension for modules #2354 - MF
* install: add configure target --with-eventhandler-dir and "make install-eventhandlers" for contrib/eventhandlers #2352 - MF
* install: add --enable-cgi-log to configure to enable cgi logging during build #2364 - MF
* install: fix configure --ido-instance-name is incorrect, missing 'with' (thx Marco) #2407 - MF
* install: add --enable-nagiosenv to configure to expose custom variables with prefix NAGIOS_ instead of ICINGA_ for easier reuse of well known check scripts #2083 - TD
* install: add --with-http-auth-file to allow different file/loc of htpasswd.users #2533 - MF
* install: make the location of the ido.sock, ido2db.lock, icinga.chk, idomod.tmp configurable #1856 - MF
* install: use custom state dir instead of hardcoded localstatedir #2583 - MF
* config: introduce conf.d as place for own configs #2360 - MF
* tests: replace libtap with an actively developed version #1192 - MF
* tests: fix and rewrite perl tests in t/ #2369 - AW
* icinga.spec: use --with-plugin-dir instead of --libexexdir for nagios plugins dir #2344 - MF
* icinga.spec: make aware of the change of idomod.o location and changed extension (now .so) #2350 - MF
* icinga.spec: add "README LICENSE Changelog UPGRADING" to all packages as docs (thx Michael Gruener) #2212 - MF
* icinga.spec: put module/idoutils/db into docs instead of manually copying to /etc/icinga/idoutils (thx Michael Gruener) #2357 - MF
* icinga.spec: add README.RHEL README.RHEL.idoutils to upstream, being installed as docs (thx Michael Gruener, Stefan Marx) #2212 - MF
* icinga.spec: use eventhandler configure/make in package creation from #2352 #2363 - MF
* icinga.spec: use --enable-cgi-log from upstream instead of manual sed #2365 - MF
* icinga.spec: introduce conf.d as place for own configs #2367 - MF
* icinga.spec: introduce icinga-idoutils-libdbi-mysql|pgsql as seperate packages #2361 - MF
* icinga.spec: updates from rhel bug #1666 - MF
** move pid file to _localstatedir/run/icinga.pid
** install icinga.logrotate example
** move ext cmd file location to _localstatedir/spool/icinga/cmd/icinga.cmd
** set icinga user's home to _localstatedir/spool/icinga
** move checkresults to _localstatedir/spool/icinga/checkresults
** use --with-http-auth-file from #2533
** add default /etc/icinga/passwd with icingaadmin:icingaadmin default login
* icinga.spec: use ido2db.lock, ido.sock, idomod.tmp, icinga.chk configure params #1856 - MF
* icinga.spec: use --with-state-dir for spool dir #2583 - MF
FIXES
* core: Plug some macro leaks triggered when sending notifications (Andreas Ericsson) #2109 - MF
* core: mark services as executing only when we know we will actually run them (Andreas Ericsson) #2302 - MF
* core: fix handling of allow_empty_hostgroup_assignment when hitting NULL'edhost_name attribute, now properly finishing #949 - MF
* core: drop abbreviations in debug log and make them more telling #2138 - MF
* core: remove deprecated code for log_external_commands_user #1619 - MF
* core: fix scheduled_downtime_depth falsely incremented if in flexible downtime with duration < end-starttime window #2536 - MF
* core: log error reason when failing to create the status file (Ulf Lange) #2560 - MF
* core: deny to load idomod.o if detected in old config #2354 #2569 - MF
* classic ui: Fixed status totals are wrong when searching #1524 - RB
* classic ui: Fixed wrong URLs for status.cgi overview #2173 - RB
* classic ui: Fixed Host status sorting in status.cgi not working #2220 - RB
* classic ui: Fixed notifications.cgi - memory access error #2234 - RB
* classic ui: Done clean up document_header() and unused vars in cgi's #2252 - RB
* classic ui: Fixed status.cgi: host param not honoured with servicefilter #2262 - RB
* classic ui: fixed Tooltip from action_url interfering with pnp4nagios integration #2198 - RB
* classic ui: fixed json output for comments and downtimes in extinfo.cgi sometimes invalid #2343 - RB
* classic ui: fixed invalid json output for tac.cgi #2160 - RB
* classic ui: Fixed Invalid json data if field value is multiline #2263 - RB
* classic ui: fixed Commit commands with more then 500 multiple pairs of hosts and services #2373 - RB
* classic ui: fixed reset forms on return after submitting command #2117 - RB
* classic ui: Change Excel icon to odf spreadsheet icon #2391 - RB
* classic ui: fixed Availability Records Break if JavaScript is disabled #2412 - RB
* classic ui: fixed Truncated HTML table when displaying outages in outages.cgi #2323 - RB
* classic ui: fixed Log File Navigation in current/ealier/recent archive clarification #2441 - RB
* classic ui: fixed Extra leading space in status.cgi CSV output #2535 - RB
* classic ui: fixed Authentication in trends.cgi not working correctly #2209 - RB
* classic ui: fixed Reuse of a buffer causes incorrect results in scheduling queue display (extinfo.cgi) #2603 - CF
* idoutils: fix ORA-00913 too many values when MERGE INTO eventhandlers #2319 - MF
* idoutils: change standard string escaping for postgresql queries to use the E'foo' notation #1974 - MF
* idoutils: fix several build problems in solaris: use supplied sprintf functions in preference over local one, build .so instead of .o shared librarys, use explicit -fPIC compiler switch #524,#1772,#2354 - TD
* idoutils: fix core dumps in solaris when using os supplied printf functions #2271,#1253,#2503,#2292 - TD
* idoutils: fix lob handling in Oracle #2303,#2342 - TD
* idoutils: fix sample shell db create script for mysql #2358 - TD
* idoutils: fix OCI-21500 when freeing lobs #2509 - TD
* idoutils: add note to "if process data is not dumped via idomod, ido2db won't clean tables and set objects inactive" #2237 - MF
* idoutils: fix pgsql unix_timestamp cannot handle timstamp with timezone #2203 - MF
* idoutils: fix ido2db forks endless if database is not available, race condition on unclosed socket #2458 - MF/TD/CF
* install: Fix notification template installation (Todd Zullinger) #2235 - MF
* install: uninstall old idomod.o #2570 - MF
CHANGES
* neb api: move creation of notification contact list AFTER event broker callback NEBTYPE_NOTIFICATION_START #2110
** allows neb modules to cancel/override notification list creation on notification start
* debug: set debug_verbosity=2 by default
* configure: --enable-libtap=yes by default for builtin 'make test-tap'
* install: --with-temp-file= #2121
** sets path to an Icinga exclusive update temp file i.e. /tmp/icinga.tmp
* install: --with-plugin-dir= #2344
** sets path to plugins directory path i.e. $prefix/libexec
* install: change default target location of idomod.so from $bindir to $libdir #2346
* install: change idomod extension from .o to .so, make .so the default extension for modules #2354
** make sure to UPDATE the location in your CONFIG !!!
* install: introduce "lib/" in default prefix install for modules #2347
* install: --with-eventhandler-dir= #2352
** sets path to eventhandler directory path i.e. $prefix/libexec/eventhandlers
* install: make install-eventhandlers #2352
** install sample eventhandlers to defined location
* install: --enable-cgi-log #2364
** enables cgi logging (EXPERIMENTAL)
* install: --with-http-auth-file #2533
** sets location/name of htpasswd.users
* install: ido2db lockfile, ido.sock file, icinga.chk, idomod.tmp as configure params #1856
** --with-icinga-chkfile=
** --with-ido2db-lockfile=
** --with-ido-sockfile=
** --with-idomod-tmpfile=
* install: use custom state dir --with-state-dir #2583
* config: $sysconfdir/conf.d #2360
* install: --enable-libtap is now deprecated, new libtap does not require configure anymore #1192
* tests: you can now test with pleasure: $ make distclean ; ./configure ; make test #2369 #1192
* core: add trigger_time to downtimes #2537
** downtimes in status.dat/retention.dat now holding trigger_time
** nebstruct and event broker api now passing trigger_time and is_in_effect
* core: nebcallback for downtime start now happens *after* setting "in effect" attributes #2539
** needed to pass is_in_effect and trigger_time to neb modules
* core: new neb module load error: NEBMODULE_ERROR_IDO_VERSION #2569
* classic ui: Added option for max log entries displayed in showlog.cgi #2145
** added new config option "default_num_displayed_log_entries"
** added new input field to redefine amount of displayed log entries
** added "switch" to show/hide filters in showlog.cgi
* classic ui: status.cgi
** added new config option "display_status_totals"
** you can define more then one object to display
** host=hostA&host=hostB&host=...
** same with hostgroups and servicegroups
** nostatusheader is still available as URL param
** hostgroup=all now only shows hosts which are in a host groups
** host sorting is working now
** added 2 new cgi vars
** sortobject = determine if to sort host or service list (host_service_view)
** allunhandledproblems = to display ALL unhanded problems
** fixed and reorganized the links in status totals
** searching returns more then one hostgroup/servicegroup if group name matches
** combined Host/Service view now properly supported
** dropped "ALT" and "TITLE" tag from action url image in host and service status list
** status totals are now split into "displayed/all" for filtering
** filtering host/services/hostgroups/servicegroups is now possible via status totals
* classic ui: add javascript to refresh page/pause easier #2119
** DO A FULL PAGE RELOAD AFTER UPGRADING
** no reload necessary to pause refresh
** selecting item in status.cgi/extinfo.cgi resets' refresh counter
** added cgi config option "refresh_type" to choose between http header refresh and javascript refresh
* classic ui: Added statusmap resizing with exclude/include button #2186
** now statusmap get's displayed much better (thanks to Mat)
* classic ui: Added Select hosts or services by clicking on line instead of box #2118
** selecting a host/service/downtime/comment checkbox now works also by clicking the row
* classic ui: fixed reset forms on return after submitting command #2117
** forms getting reset on page load
** fixed problem with downtime checkbox selection
** changed all forms to POST request
* classic ui: fixed json output for comments and downtimes in extinfo.cgi sometimes invalid #2343
** changes array names in json output of extinfo.cgi
** comments -> host_comments / service_comments
** downtimes -> host_downtimes / service_downtimes
* classic ui: fixed Commit commands with more then 500 multiple pairs of hosts and services #2373
** now it's possible to submit ~990 commands at the same time
* classic ui: outages.cgi
** added missing comment tool tip box
** fixed truncating of outages list
* classic ui: Added Scheduling queue filter for specific host or service #2421
** now everyone who is authorized for can see hosts/services in scheduling queue
** added links to host/service extinfo
* classic ui: Added readonly cgi.cfg view into the config section #1776
** New Option in config.cgi to view all cgi config options and their current values
* classic ui: statuswml.cgi and statuswrl.cgi are DEPRECATED now !!!!!!!!!
** both will be removed in Icinga 1.8 !!!!!!
* classic ui: cmd.cgi now accepts change commands with attr command #2474
** CHANGE_HOST_MODATTR, CHANGE_SVC_MODATTR
** but ONLY 0 = reset, other values will trigger an error
* idoutils: limit long_output and perfdata database storage in mysql to 32k #2342
* idoutils: enlarge field "FAILURE_PREDICTION_OPTIONS" in table hosts from 64 to 128 Bytes #2479
* idoutils: Oracle only->change method retrieving lastid, introduce individual sequence caching sizes #2510
* idoutils: fix pgsql unix_timestamp cannot handle timstamp with timezone #2203
* idoutils change varchar(255) to TEXT in mysql # 2181
* idoutils: add create_time and modify_time to dbversion table #2562
** allows to determine the initial import plus modified date
1.6.2 - 13/01/2013
ENHANCEMENTS
* core: add trigger_time to downtimes to allow calculating of flexible downtimes endtime #2537 - MF
* classic ui: add is_in_effect and trigger_time to downtime view for html, csv, json #2538 - MF
FIXES
* core: add trigger_time to downtimes to allow calculating of flexible downtimes endtime #2537 - MF
* core: add fix for CVE-2012-6096 - history.cgi remote command execution (Eric Stanley, Markus Frosch) #3532 - MF
* classic ui: fixed invalid json output for tac.cgi #2160
* classic ui: fixed json output for comments and downtimes in extinfo.cgi sometimes invalid #2343
* classic ui: fixed Truncated HTML table when displaying outages in outages.cgi #2323
+ classic ui: fixed Extra leading space in status.cgi CSV output #2535
+ classic ui: fixed msdropdown jquery issues with opera #2515
* idoutils: change standard string escaping for postgresql queries to use the E'foo' notation #1974
* idoutils: fix ORA-00913 too many values when MERGE INTO eventhandlers #2319
* idoutils: partly cherry-pick fixes for solaris segfaults from #2271
* idoutils: fix OCI-21500 when freeing lobs #2509
CHANGES
1.6.1 - 02/12/2011
FIXES
* core: fix freshness checks are generating stale alerts, even if result was received in time #2136
CHANGES
1.6.0 - 30/11/2011
ENHANCEMENTS
* core: acknowledgements can now expire by providing an end_time through commands #770
* core: allow startup with no hosts/services/contacts defined, only warn #2015
* core: log error on non-existing host/service/contact/*group when sending a command to the core #1737
* core: reduce notification load by moving notification viability check into notification list creation (Opsview Team) #1744
* core: protect downtime and comment list modification with a lock (Andreas Ericsson) #2025
* core: determine last_program_stop from creation of retention.dat and use that for decision if passive checks are fresh or not (Andreas Ericsson) #2027
* core: add icinga startup delay checks to example configs, including perfdata #1937
* core: indicate event loop start in logs #2036
* core: add notifications to stalking hosts/services, not only logging/event handlers #1367
* core: add eventloop mutex, will be used by IcingaMQ #2040
* classic ui: add expiry option and end_time to acknowledgements on cmd.cgi #770
* classic ui: Acknowledge child hosts from on blocking outages #1858
* classic ui: add opt-in extinfo_show_child_hosts to show child hosts in extinfo.cgi #1820
* classic ui: add complete command line to config.cgi #1329
** if resource.cfg readable by webserver for $USERn$ macros
** adds host/service params to config.cgi to process their macros
* classic ui: Add more info of (ack, downtime, ... ) status to json export in status.cgi (ivo) #1988
* classic ui: add hostgroup and servicegroup summary to menu.html #2007
* classic ui: Change markup color for unreachable hosts in statusmap.c #1464
* idoutils: add SLA monitoring via opt-in enable_sla cfg option #2037
** pgsql timestamp with timezone changes remain experimental in SLA table
* idoutils: added end_time column for acknowledgelemts expiry #770
* idoutils: add Indices for notification queries for Icinga Web #1964
* idoutils: add option to format debug log timestamp like locale %c (debug_readable_timestamp in ido2db.cfg) #2033
* idoutils: add max_notifications_age, max_contactnotifications_age, max_contactnotificationmethods_age as housekeeping for notification tables #2051
* idoutils: use local timestamp datatype instead of date/datetime, store icinga timestamps as UTC #1954
* idoutils: change timestamp to use time zone by default in postgresql (thx Florian Helmberger) #2106
* config: add config examples for local monitoring - check_procs for ido2db #1870
* icinga.spec: enable cmd.cgi logging by default #2124
FIXES
* core: fix downtime and comments delete with wrong loop pointers causing segfaults #1979
* core: fix $NOTIFICATIONRECIPIENTS$ macro contains all contacts assigned to host|service, not only notified contacts #2023
* core: plug memory leak in downtimes comment add (Dorian Guillois) #1979
* core: make first_notification_delay depend on the first !OK hard state change and don't reset timer for new hard states which would replace it (Rogerio F Cunha) #1918
* core: fix memory leak in xodtemplate.c (thx Dorian Guillois)
* classic ui: fix for Classic-UI displays bad timeperiods #1989
* classic ui: fixed wrong color in histogram and trends for unknown/unreachable #2042
* classic ui: fixed search not returning all results, only first match (without * at the end) #844
* classic ui: fixed wrong output from status.cgi with option hostservicedetail #2019
* classic ui: fix typo in histogram.c (thanks Sven-Göran Bergh)
* idoutils: host state change last_hard_state overrides last_state, last_hard_state always -1 #1932
* idoutils: extend conninfo.agent_version field to varchar(16) #2104
* idoutils: terminate threads cleanly, including db connection
* install: rework the version updates in icinga and idoutils
* icinga.spec: --libexecdir does not point to possible location of nagios-plugins in resource.cfg:$USER1$ #2123
CHANGES
* package: complete remove icinga-api as module #1935
** Development is being discontinued for now, 1.5.0 was last combined release.
** remove files in module/icinga-api
** update configure and mark options deprecated
** mark as deprecated in Makefile, install-api spits out warning
** remove build from icinga.spec
** add module/icinga-api/README for further instructions for non Changelog readers
* core: new commands and event
** CMD_ACKNOWLEDGE_HOST_PROBLEM_EXPIRE 174
** CMD_ACKNOWLEDGE_SVC_PROBLEM_EXPIRE 175
** EVENT_EXPIRE_ACKNOWLEDGEMENT
* core: new notification type (internal and macros)
** NOTIFICATION_STALKING
* classic ui: "showlog_initial_states" and "showlog_current_states" are now disabled by default to prevent browser freezes #1172
* classic ui: highlight_table_rows is now enabled by default #1777
* classic ui: removed unused javascript libraries
** html/js/: builder.js, controls.js, dragdrop.js, effects.js, slider.js, sound.js, mootools.js
* classicui: new regex search uses 'search_string' instead of 'navbarsearch=1&host=', both are kept for compatibility reasons #844
* icinga.cfg: stalking_notifications_for_hosts=0 stalking_notifications_for_services=0
* cgi.cfg: default_expiring_acknowledgement_duration=86400
* cgi.cfg: extinfo_show_child_hosts=0 added
* cgi.cfg: authorized_for_full_command_resolution and authorized_contactgroup_for_full_command_resolution added
* add objects/ido2db_check_proc.cfg (not included by default) #1870
* ido2db.cfg
** enable_sla=0
** debug_readable_timestamp=0
** max_notifications_age, max_contactnotifications_age, max_contactnotificationmethods_age
* icinga.spec
** enable cmd.cgi logging by default in rpm
1.5.1 - 09/09/2011
FIXES
* core: free memory allocated notification macros right after sending the notification, not in next notification
* classic ui: fix Localization: Form validation message could be improved (thx Mario Rimann) #1849
* classic ui: fix wrong titles in list of scheduled downtimes (thx Mario Rimann) #1848
* classic ui: fix host and service names are not allowed to have a '+' included #1843
* claasic ui: fix service overview for single hostgroups when show_partial_hostgroups is switched on #1013
* claasic ui: fix authorized_for_all_hosts/authorized_for_all_services retruns true for historical data #1166
* idoutils: idomod: change stacked memory allocation for broker_data IDO_MAX_BUFLEN #1879
* idoutils: fix idomod should log more verbose on errors, asking for a running ido2db process #1885
* spec file: re-add processing headers
CHANGES
1.5.0 - 24/08/2011
ENHANCEMENTS
* core: do not update host/service status during scheduler initialization on startup (idoutils already know that) #1741
* classic ui: Added option to suppress coloring of hosts/services in maintenance #992
* classic ui: Added option to show partial hostgroups #1013
* classic ui: changing drop down menu in status.cgi to jquery-dd #1644
* classic ui: default downtime duration is configurable in cgi.cfg #1642
* classic ui: Added ability to combine host and service in one CGI parameter (Aaron Brady) #1633
* classic ui: Changed tac.cgi to distinct between active, passive and disabled properly #1120
* classic ui: Add log entries to json output of avail.cgi #1659
* classic ui: add host urgency sort order in status.cgi (Jochen Bern) #1452
* classic ui: add author to comment tooltips in status.cgi #1691
* classic ui: reduce the header part of status.cgi #1507
** &nostatusheader used in frameset menu, info table is smaller
* classic ui: authorization for * in cgi.cfg via contactgroups (Stephen Gran) #1752
** authorized_contactgroup_for_all_hosts, authorized_contactgroup_for_all_services, authorized_contactgroup_for_system_information,
** authorized_contactgroup_for_configuration_information, authorized_contactgroup_for_all_host_commands,
** authorized_contactgroup_for_all_service_commands, authorized_contactgroup_for_system_commands, authorized_contactgroup_for_read_only
* classic ui: add xml output to avail.cgi for direct source of jasper reports #1712
* classic ui: add combined view of all unhandled hosts and services including the multiple command dropdowns for each (initial idea by Thruk) #1328
* classic ui: add "link to this page" to all cgis #1783
* classic ui: add export icons instead of "export to..." text on cgis supporting it (csv, json, xml, link) #1789
* classic ui: add highlight_table_rows to status.cgi, can be disabled via cfg option #1777
* idoutils: add update-version-schema for updating the idoutils db schema versions automagically, independant of update-version #1616
* idoutils: dump multiline mbufs as bulk inserts #1110
** configfile/runtime variables, host contacts/parents, service contacts, timeranges, host/service/contactgroup memebers
** oracle uses bulk arrays binded on prepared insert statements
* idoutils: remove host and service checks from default data_processing_options as they are not used by icinga-web #1757
* idoutils: Add logging of bind variable value for oracle #1314
* idoutils: oracle change perfdata columns to clob #1749
* idoutils: oracle: change logentry_data type to clob #1750
* install: add --with-p1-file-dir allowing custom location (default is now $libdir instead of $bindir) #1569
** only when embedded perl is enabled
** affects (new_)mini_epn and icinga.cfg
* install: add configure option to set log dir and cgi log dir and phpapi log dir #1715
** e.g. --with-phpapi-log-dir=/var/log/icinga/api --with-log-dir=/var/log/icinga --with-cgi-log-dir=/var/log/icinga/gui
** apache user permissions
* install: after daemon stop in init script, retry and then issue a kill -9 on the daemon #1747
* config: add easy-to-use config examples and scripts for notifications #1697
** advanced notify-by-email
** notify-by-jabber, notify-by-twitter examples
* config: add check_dummy command definitions as example to commands.cfg #1719
* config: tune icinga.cfg for performance, enable_environment_macros=0, enable_embedded_perl=0 by default #1635
* style: add new ident tools #1617
FIXES
* core: remove duplicated unlinks for check result files with multiple results (Ton Voon) #1615
* core: fix retain status file over an init script reload #1579
* core: fix freshness_threshold problem in host checks by using check_interval in HARD or OK state, else retry_interval (like service checks) (Andreas Ericsson) #1331
* core: make command_check_interval=-1 equal to 5s instead of 60s, targetting as often as possible (Andreas Ericsson) #1651
* core: fix problem where acknowledgements were getting reset when a hard state change occurred (Ton Voon) #1618
* core: avoid using global macros when sending notifications (Andreas Ericsson) #1653
* core: avoid sending notifications to the wrong contact (Andreas Ericsson) #1654
* core: try to avoid a single check being reaped multiple times (Andreas Ericsson) #1652
* core: Fix typo in configure.in preventing compilation on FreeBSD (thanks sag47) #1732
* core: plug memory leak with display_name on start/reload #1841
* core: fix content of macro $NOTIFICATIONRECIPIENTS$ grows and grows #1695
* classic ui: fix cross site scripting vulnerability in config.cgi on config expander arguments #1605
* classic ui: better handling of writing to cgi.log in cmd.cgi #1161
* classic ui: fixing tac.cgi header problems with counting and adding pending and descriptions #1505 #1506 #1508
* classic ui: corrected behaviour of pending states in tac header #1508
* classic ui: fix counting for services in tac header is wrong #1508
* classic ui: remove sidebar.html inclusion in index.html causing troubles on reload #1632
* classic ui: fixed: User can execute host/servicegroup commands even if not authorized for (Sven Nierlein) #1679
* classic ui: fixed: plugin_output_short didn't get checked properly and caused segfault in status.cgi #1673
* classic ui: fixed: submitting non existent host/service on avail.cgi causes segfault #1700
* classic ui: fixed: Alert History State filter for HARD/SOFT state not working (Lennart Betz) #1722
* classic ui: fixed: jquery 1.5.2 triggers memory leak in IE #1740
* classic ui: fixed: ssi files don't get included if icinga path contains uppercase letters #1716
* idoutils: do not update start_time of already started downtimes #1658
* idoutils: fix started downtime update for table scheduleddowntime in oracle #1658
* idoutils: remove leftover socket file in init-script startup, e.g. from a system crash #1745
* idoutils: simplify ido2db_get_object_id oracle function #1655
* idoutils: fix oracle long_output column in eventhandlers missed #1748
* idoutils: fix oracle ocilib 3.9.2+ fixes causing wrong 4byte->8Byte casts #1751
* idoutils: fix ORA-00600 while executing merge #1362
* install: fix event handlers cmd file location in contrib #1501
* install: icinga.spec should not provide nagios version #1562
* install: don't include git meta data in upstream tarballs #1562
* install: fix make install-idoutils overwrites sample - adding idoutils.cfg-sample instead #1625
* install: fix icinga.cmd and log dir replacement in icinga-api aubmodule #1573 #1715
* install: fix DEBUG_LOG_PATH in p1.pl, will now be using configurable log-dir #1715
* install: do not overwrite config in make fullinstall #1754
* install: fix configure should tell if ocilib or libdbi if idoutils enabled in summary #1780
* config: deprecate log_external_commands_user #1619
CHANGES
https://wiki.icinga.org/display/Dev/Changes
* location of p1.pl is now default in %{_libdir}/icinga instead of %{_bindir}/icinga: configure flag for pkg --with-p1-file-dir=
* new notification examples: contrib/notifications/* sample-config/template-object/notifications.cfg
* eventhandlers got their proper icinga.cmd location through configure
* p1.pl.in will be created from configure into p1.pl
* module/idoutils/config/idoutils.cfg-sample is now installed instead of idoutils.cfg
* add log dir options for core, cgi and phpapi log
** --with-log-dir=%{logdir} --with-cgi-log-dir=%{logdir}/gui --with-phpapi-log-dir=%{logdir}/api
** p1.pl DEBUG_LOG_PATH is replaced
** icinga.cfg logdir, archive, debug_file uses (LOGDIR) ac macro
** cgi.cfg cgi logfir, archive uses (CGILOGDIR) ac macro
** phpapi log and icinga.cmd target are overwritten by core configure in their places
** ownership of cgi and api log dirs is apache user and group
* cgi.cfg config changes
** cgi_log_file=@CGILOGDIR@/icinga-cgi.log cgi_log_archive_path=@CGILOGDIR@
** show_partial_hostgroups=0 default_downtime_duration=7200 suppress_maintenance_downtime=0
** authorized_contactgroup_for_all_hosts, authorized_contactgroup_for_all_services, authorized_contactgroup_for_system_information,
** authorized_contactgroup_for_configuration_information, authorized_contactgroup_for_all_host_commands,
** authorized_contactgroup_for_all_service_commands, authorized_contactgroup_for_system_commands, authorized_contactgroup_for_read_only
** highlight_table_rows
* icinga.cfg config changes
** log_archive_path=@LOGDIR@/archives p1_file=@P1FILELOC@/p1.pl debug_file=@LOGDIR@/icinga.debug
** enable_embedded_perl=0 enable_environment_macros=0
* idomod.cfg config changes
** data_processing_options=67108669
1.4.0 - 11/05/2011
ENHANCEMENTS
* core: re-allow perfdata with empty results being put on perfdata channel, disable via opt-in cfg option #1413
* core: add downtime delete commands made "distributable" by deleting by host group name, host name or start time/comment (Opsview team) #1344
* core: add 'module' as object config, allowing cfg_dir usage loading multiple modules without touching broker_module in icinga.cfg #162
* classic ui: merged reading of logfiles into one function. It's easier now to add enhancements. #972
* classic ui: Adding some more icons to showlog.cgi #1239
* classic ui: adding entry time of comments in tooltip's in status.cgi #1244
* classic ui: Searching in the Icinga Logfile #516
* classic ui: changed print_generic_error() function to support csv output #1270
* classic ui: Added parameter to get_log_entries() function to use beginning and end timestamp #1271
* classic ui: Show downtime in host detail and service detail view #1141
* classic ui: Store cmd.cgi submissions in log #1161
* classic ui: enforce a need for comment for action taken in cmd.cgi #610
* classic ui: Add config option to set start of week (sunday/monday) #1269
* classic ui: Allow display of Network Outages for authorized hosts #1320 (thx mjbrooks)
* classic ui: remove useless memory allocation when reading logfiles reverse (lifo) #1387
* classic ui: speed up data processing in summary.cgi #1392
* classic ui: Add an alternative CGI driven view for the top frame (Matthew Brooks) #1406
** hosts/services counts with active unack, passiv unack, acked, totals (title tooltip)
** performance information on the right
** added urls and appropriate url filters
* classic ui: Added json output "&jsonoutput" to nearly all pages in classic ui #1217
* classic ui: allow searching for host display_name normal and via regexp #1393
* classic ui: display host/service dependencies in host/service details in extinfo.cgi #1300
* classic ui: add module object definition for viewing with config.cgi including csv+json output #162
* idoutils: add db socket as config option in ido2db.cfg for mysql and postgresql #1107
* idoutils: reduce housekeeping cycle to every 3600s, set housekeeping thread startup delay to 300s #1157
* idoutils: introduce schema version and check against that instead of program version #1368
* idoutils: install sample (commented) config in modules/idoutils.cfg using new 'module' object config #162
* idoutils: add configure flag to set ido instance_name other than 'default' in idomod.cfg #1167
* config: increase default debug file size to 100M #1316
* install: add --with-ext-cmd-file-dir= to configure, allowing icinga.cmd dir to be altered #1268
* install: add make option to install doxygen development docu "install-dev-docu" #1309
FIXES
* core: fix flexible downtime on service hard state change doesn't get triggered/activated #1128
* core: fix timeperiods daylight saving time problem (Luca Di Stefano) #1370
* core: do not update host/service status during scheduler initialization on startup #1741
* core: do not dump retained host state states to neb modules, re-enable via dump_retained_host_service_states_to_neb #1742
* classic ui: Fixing tooltip's in status.cgi, not showing messages with carriage return #1244
* classic ui: fixed csv export link to make it XSS save (IE) #1275
* classic ui: cmd.cgi: acknowledgement multiline comment -> command not being processed #1257
* classic ui: statusmap.cgi: fixed XSS vulnerability #1281
* classic ui: fix display_name survive reconfiguration and is use instead of host_name in classic ui #1282
* classic ui: don't show pause/continue urls on non-refreshable pages
* classic ui: fix segfaults if no default_user_name= given in cgi.cfg #1289
* classic ui: Prevent statusmap.cgi markup from drawing when host should not be drawn (Matthew Brooks) #1383
* idoutils: update oracle hints in ido2db.cfg with tnsnames.ora and port cfg #1283
* idoutils: idomod: larger buffer size (by Opsview) #1286
* idoutils: fix rdbms deconnect after connection error #1313
* idoutils: fix race condition when issueing multiple reloads results in hanging IDO2DB processes #1410
* idoutils: fix postgresql: integer not big enough for bytes_processed (Stig Sandbeck) #1401
* install: use *.so instead of *.o for solaris, patch in contrib/solaris/ #524
1.3.0 - 16/02/2011
ENHANCEMENTS
* classic ui: add instance hostname to html title #954
* classic ui: use the signal-colour red more economically in tac.css stylesheet (Joachim Raber) #868
* classic ui: add attribute based authorization based on Shibboleth (Tibor Vago, NIIF) #909
* classic ui: add config expander urls to extinfo.cgi for active checks and eventhandlers (Jochen Bern) #965
* classic ui: add collapse the display filter part on status.cgi #923
* classic ui: add tabfriendly titles, enabled by default (Jochen Bern) #975
* classic ui: add service states to annotate with current notification number opt-in (Jochen Bern) #976
* classic ui: change displayed name for hostgroups and servicegroups in extinfo.cgi
* classic ui: adding "Attempt" column to host status detail list
* classic ui: change default url target frame to main #1014
* classic ui: add url_stylesheet_path to cgi.cfg to allow custom css path #898
* classic ui: change color of unknown/unreachable state to more warm signalling purple #1029
* classic ui: move "add service/host comment" to the command box on extinfo.cgi, abandon remove all in favor of multiple comment delete #837
* classic ui: add trend timeperiod feature to locate the next problem (Carsten Emde) #1074
* classic ui: add configurable http charset support (default utf-8) within the cgis #1002
* classic ui: add csv export to config.cgi #1052
* classic ui: beautify and modularize error msg #1198
* core: add support for same host service dependencies with servicegroups (Mathieu Gagné) #928
* core: allow eventbroker modules to override sending notifications (Matthieu Kermagoret) #1057
* core: allow empty hostgroup aissgments for services as opt-in config option (Max Schubert) #949
* core: do not copy broker modules (OMD patch) #896
* core: fix host alias saved in resention data survived reconfiguration #935
* core: add basic dualstacked IPv6 support (core/cgi patch by Julius Kriukas, slight changes on Icinga, own IDOUtils backend code) #674
** address6 as host definition attribute (to be used dual stacked, address stays default!)
** host macro $HOSTADDRESS6$ for e.g. check-host-alive
** if not set, host name is set as default (same behaviour as address)
** shown in classic ui only if set (not matching host name)
** idoutils mysql/postgresql/oracle hosts config table gets new column 'address6' populated
** note: as of this release, idoutils depends hard on include/objects.h of icinga core. internal idomod api changed, new datatype added.
* install: add sysconfig source to init script #1015
* install: set -Wall gcc flags based on os/compiler #959
* install: create doxygen templates and add to html/doxygen #446
* idoutils: add index to table icinga_statehistory for usage in reporting module #957
* idoutils: add check for configuration file availability for idomod and ido2db (idea from Ricardo Maraschini) #1087
* idoutils: add cfg option to enable/disable oci errors to syslog through error handler #1060
* idoutils: add dbversion upgrade scripts for 1.3 #633
* idoutils: add dbversion check in ido2db and print error to syslog in case of non-matching #633
* idoutils: do not clear host|service|scheduleddowntime status tables on core restart/reload (inspired by Opsview) #1106 #1176
* idoutils: only insert service and host checks when they are finally processed, increase performance by replacing insert/update with single insert (idea by Opsview/Opsera Ltd with mysql and servicechecks) #1100
** servicechecks table is heavily used next to hostchecks
**- if the core does a host|service check, there are 3 situations the event broker will get data: INITIATE, ASYNC_PRECHECK, PROCESSED
** idomod/ido2db process INITIATE (insert) and PROCESSED (update) til now
** now, ido2db takes only PROCESSED with a full insert, mysql and postgres use sql standard insert, oracle a prepared statement with insert
** reduced number of check events sent to IDOUtils by 66%
** reduced number of fired SQL statements by 50%
** changed 1 SQL statement for each rdbms, making it smaller and saving index lookup (and virtual table by merge in oracle)
** index savings, and dropped unique keys - check upgrade sql scripts for mysql/postgresql/oracle
* idoutils: add indexes for logentries, preventing heavy load #1055
* idoutils: enable max_logentries_age & max_acknowledgements_age with 31 days for cleaning by default in ido2db.cfg #1155
* idoutils: add multi valued inserts for host|service_contacts instead of single insert/update loops (thx Opsview) #1108
* contrib: bring daemonchk.cgi building into shape (Elan Ruusamäe) #1051
FIXES
* core: base/utils: Refactor my_fcopy() (Andreas Ericsson) #427
* core: base/nebmods: Replace local file-copy hack with my_fdcopy() (Andreas Ericsson) #424
* core: force my_free() macro users to end the statement with a semi-colon (Andreas Ericsson) #927
* core: fix problem with extra whitespace in command definition and ePN (Jason Young) #918
* core: fix NOTIFICATIONTYPE MACRO never became CUSTOM (Alexey Dvoryanchikov) #950
* core: only catch SIGSEGV if we're not dumping core and running as a daemon #457
* core: protect against callbacks removing themsevles in nebmods (Andreas Ericsson) #1021
* core: fix possible validation error with empty hostgroups/servicegroups (Sven-Göran Bergh) #1040
* core: performance-data handling and checking is now thread-safe so long as embedded perl is not used (Andreas Ericsson) #1022
* core: children should no longer hang on mutex locks held in parent for localtime() (and similar) calls (Andreas Ericsson) #1039
* core: debug logging is now properly serialized, using soft-locking with a timeout of 150 milliseconds to avoid multiple threads competing for the privilege to write debug info (Andreas Ericsson) #1035
* core: fix parsing of long plugin output for async host checks (Jochen Bern) #1046
* core: log error reason when failing to open the status file (Andreas Ericsson) #1078
* core: fix allocate memory once for *GROUPMEMBERS macros (Stephane Lapie) #1076
* core: protect against poorly behaving thread-libraries (Andreas Ericsson) #1080
* core: fix extraneous alerts for services when host is down (Ton Voon) #1097
* core: reduce duplication of code for is_contact_member_of_contactgroup (Stephen Gran) #1126
* core: fix bug with passive host checks being incorrectly sent to event brokers as active checks (Ethan Galstad) #1133
* core: fix bug where passive host check status updates were not being propagated to event brokers (Ethan Galstad) #1134
* core: fix first_notification_delay logic (GalaxyMaster) #1145
* core: fix race condition on flexible downtime commands when duration not set or zero #1061
* classic ui: change servicestatus letter color to default black, not grey #946
* classic ui: fix waste of cpu in status summary (TomTom) #933
* classic ui: fix config.cgi start page wrong "command cxpansion" url (Alexey Dvoryanchikov) #951
* classic ui: do not allow url_encode returning empty string on Solaris (Ethan Galstad, Ton Voon) #924
* classic ui: fix object values in utf8 are displayed incorrectly in the web interface (Alexey Dvoryanchikov) #952
* classic ui: make html header w3c conform #952
* classic ui: fix typo for css attribute in extinfo.cgi (Ton Voon) #963
* classic ui: fix whitespace escaping in html urls (Jochen Bern) #965
* classic ui: fix config expander printing [SP] instead of [WS] (Jochen Bern) #965
* classic ui: fix status totals - incoherence between displayed list and values #993
* classic ui: fix deleting host comments won't work #994
* classic ui: changed naming of cgi config options for showlog_current_state(s) and showlog_current_state(s) #899
* classic ui: fix form/table DOM confusion in cgis (Sven-Göran Bergh) #1081
* classic ui: fix tac.cgi with incorrect links to filtered host details (Yannick Charton) #1065
* classic ui: fix missing html label/text for searchbox () #John Giacalone #1114
* classic ui: fix authorized_for_read_only can execute command over the status.cgi #1154
* install: fix LD_LIBRARY_PATH export on non bash in idoutils init script (Alexander Skwar) #936
* install: add log2ido for adding archived logs onto socket/rdbms #926
* install: add hint to configure that libpq is not yet fully working #622
* idoutils: fix unescape display name (Matthieu Kermagoret) #1027
* idoutils: fix solaris <= lacks asprintf (Julian Wiesner) #1048
* idoutils: fix unfreed oci handles in prepared statements #1093
* idoutils: increase debugoutput for conversion functions #1094
* idoutils: fix libdbi 0.8.3 deprecated functions dbi_result_get_(u)long #559
* idoutils: fix after core restart/reload on oracle db ORA-01403: no data found #1059
* idoutils: fix string escaping for backslashes in postgresql #1121
* idoutils: fix check for empty command args in host|service|notification definitions #1047
1.2.1 - 25/10/2010
ENHANCEMENTS:
* core: fix initscript, no error when stopping stale lock (OMD patch) #897
* classic ui: Added config options to hide initial state and current state log entries in showlog.cgi #899
* classic ui: extinfo comment table cell names (Oliver Graf) #861
* classic ui: add csv export to avail.cgi (single|all hosts|services|servicegroups|hostgroups) #925
FIXES:
* core: corrected wrong implementation of fix #584 - re notification for downtime after icinga restart
* core: fix epn tag for disabling ePN (Yannick Charton) #914
* core: fix snprintf in make for Solaris #858
* core: fix config file parsing end of definition check #913
* core: fix ignoring empty definitions, only warn #860
* classic ui: fix for "Schedule a check of all services on this host" not working properly #895
* classic ui: comment tooltip now show's quotes and back slashes #907
* classic ui: fix change statusmap logo name to icinga #922
* classic ui: add support for ICINGA_ env vars for cgis #921
* idoutils: fix disconnecting on errors misbheaving, not closing db and daemon #886
1.2.0 - 06/10/2010
ENHANCEMENTS
* core: add eventhandler override (Sven Nierlein) #731
* core: add config option to disable logging into the daemon log file #311
* core: fix delay sorting of comments/downtimes (Ton Voon) #753
* core: fix custom macros being cleaned/stripped (as they are user-defined and should be trusted) (Peter Morch) #752
* core: add the possibility to use * as a wildcard for all hosts in servicegroup definition #813
* core: fix scheduled downtime notifications resent on restart/reload #584
* core: disable eventprofiler on Solaris gcc3, preventing core dumps #702 #572
* classic ui: add commands expander to config display (Jochen Bern) #746
- $ARGn$ substitution will be shown between command_line and
check_command associated for hosts, services, etc and help
getting to know/use commands the core will execute.
* classic ui: change menu, add unhandled host/service problems #745
* classic ui: reduce line-height of menu items (Martin F. Krafft) #833
* classic ui: allow searching for host without service attached to it #601
* classic ui: added tooltip for comments in status.cgi #805
* classic ui: remove php dependency by dropping extended live search #800
* classic ui: added csv export to most cgi pages #806
* classic ui: added possibility to delete multiple downtimes and comments (taken loads of ideas from Rune Darrud) #523
* classic ui: Beautifying the design of submit form in cmd.cgi and everything else in cmd.cgi #804
FIXES
* core: fix send comments to the broker with proper expiration_time (Matthieu Kermagoret) #747
* core: fix segfault in escalation conditions when using object tricks (Vitali Voroth) #751
* core: fix for retaining host display name and alias, as well as service display name (Folkert van Heusden) #760
* core: fix format errors for logging eventhandlers (Guillaume Rousse) #779
* core: remove program update checks as scheduled timed events, not written to status/retention.dat anymore #790
* core: don't skip hostchecks when servicechecks are disabled (Stephen Gran) #778
* core: move eventprofiler init after config parsing, checking if enabled, making it optional all over #572 #702
* classic ui: update jquery for multiple cmds dropdown, resolve conflicts with pnp #807
* classic ui: moved individual document_header and document_footer to cgiutils.c, distinction by cgi_id #808
* classic ui: removed double header in tac.c #808
* classic ui: changed size of checkbox column to 16 #809
* classic ui: remove useless utils.inc.php since check-program-updates is dropped from core #800
* classic ui: fix status.cgi segfault without hostgroup parameter on solaris 10 #594
* classic ui: drop dead code on cgis (check_daemon_running)
* classic ui: avoid the horizontal scroll bar at the bottom of the menu (Yannick Charton) #835
* idoutils: fix ido2db forking if database connection failed, now immediately disconnecting the client #773
* idoutils: fix database port in ido2db.cfg not honoured using libdbi #825
* install: remove php dependency and files for updatechecks/extended search in icinga.spec #800
* install: add mkdir -p for HTTPDCONF directory creation instead of install -D (misses on Unix) #802
* install: remove installing from ido2db init script from Makefile when installing idoutils #814
* install: better ssl detection in solaris when /usr/local/ssl used for --with-ssl #821
* install: replace echo -n by printf in init scripts (Lars Engels) #834
* config: fix typo preserve_state_information in description of retention file
1.0.3 - 18/08/2010
ENHANCEMENTS
* core: new config option to set initial state of persistence for acknowledgements
* core: add opt-in log_external_commands_user in icinga.cfg, user will be logged by the core if enabled and sent through icinga.cmd
* core: add config option to disable the logging of current state in log after rotation (Ricardo Bartels)
* core: add config option to log long plugin output (Ricardo Bartels)
* core: add config option to enable event handlers for stalked hosts/services (Petya Kohts)
* core: scheduled downtime can now start on SOFT error states
* idoutils: add syslog output for start/stop, client connecting
* idoutils: add db trimming thread startup delay config option
* classic ui: cgi config option to show long_plugin_output in status.cgi (Ricardo Bartels)
* classic ui: add config option to only show HARD states in tac.cgi
* classic ui: add multiple selection/command sending to host/service status page
- added extra column in host and service status with checkboxes using jquery
- It is now possible to check off the hosts you want to send commands to Icinga.
- Ex: schedule downtime for a custom selection of hosts or X number of services.
* classic ui: add a pause/continue update button (main parts by Steve Koenig)
- affects status.cgi and allows to select and run commands w/o page reload
FIXES
* core: fix temp_path overwritten by check_result_path in base/config.c
* core: modify execv to execvp, accepting 4096 cmd args, for both host and service checks with adapted error handling
* core: execvp searches in PATH too like popen, and returns if error, outputting the errno string
* core: fix possible overflows and increase command length limit in mini_epn's (Thomas Guyot-Sionnest)
* core: fix new_mini_epn to allow any command line length without breaking on extra trailing or leading whitespace (Ray Bengen)
* core: fix wrong is_volatile conditions causing wrong service alerts in the logs
* core: fix notify-service-by-email command from the stock template cuts off service check output
* core: fix service checks should recognize that exit code 126 means plugin is not executable
* core: fix service event handlers when service problem becomes hard during host down
* core: fix service in soft state after hard state without recovery
* core: fix all comments disappear after restart if one user comment is non-persistent (Ricardo Bartels)
* core: fix macro processing (Jochen Bern)
* core: fix non-scheduled hosts/services not being updated in IDO*
* core: move the malloc block in insert_skiplist below dupcheck to avoid memory leaks (Thomas Guyot-Sionnest, Holger Weiss)
* core: fix missing variable reset for use_syslog_local_facility and syslog_local_facility
* classic ui: fix image urls in stylesheets
* classic ui: remove check_daemon_running, remains useless
* classic ui: fix multiurl action/status icon wrong name
* classic ui: cmd.cgi "his" instead of "its" in command description
* classic ui: fix customers can see machines from other customers when entering a downtime
* classic ui: fix invalid pointer in extinfo.cgi type=7
* classic ui: for new Splunk integration query parameters
* classic ui: fix for incorrect host state counts in status CGI when viewing servicegroups
* classic ui: fix for extra colum in CSV export
* install: fix api not installed using make install-unstripped
* install: enable debuginfo in spec file
* install: remove daemonchk.cgi from init-script
* install: improve output of rhel init-script
* install: add config checks for start, reload and restart on rhel init script
* install: fix duplicated configcheck on restart in init-script
* install: fix specfile for idoutils description
* install: fix Makefile output if Icinga API not available
* install: fix t/ and daemon-ini-redhat in distclean
* install: add note about api installed successfully
* idoutils: adapt oracle-drop.sql for current schema
* idoutils: fix binding null values to name1/name2 in oracle
* idoutils: fix typo in servicedepencies query for oracle
* idoutils: fix oracle prep statement contactnotifmethoddata
* idoutils: full rewrite of binding NULL values for oracle with ocilib
* idoutils: change display_name to varchar(255) for mysql/oracle
* idoutils: update pgsql schema, replace varchar(n) by text
* idoutils: change configfilevariables varvalue to 1024 length for mysql/oracle
1.0.2 - 30/06/2010
ENHANCEMENTS
* core: init script shows config errors option; don't remove pidfile if icinga did not stop in a timely manner
* core: check if icinga running before starting; if died remove lockfile first
* core: add in sync retention facility (Ton Voon, Opsera Ltd)
* core: add new is_volatile setting of 2 for services, which respects the re-notification interval for notifications (Ton Voon)
* core: add Icinga option -S functions much like -s but will dump the entire scheduling queue is it would run,
in addition to providing the summary data (Steven (Steven D. Morrey)
* core: icinga can send log messages to syslogd using a local facility instead of the default one
* core: enhanced diagnostic output when a regular expression fails to compile (Max Schubert)
* core: add state-based escalation ranges (Mark Gius)
The directives first_notification and last_notification apply to the
total count of notifications on a particular service or host. It is
sometimes desirable to escalate after the Nth critical notification,
rather than after a total number of N notifications have been sent.
NOTE: This can be enabled through configure, it is currently incompaitble with mk_livestatus!
* core: add event profiling option for stats of event counts and time taken for events
* core: retention file loading speedup (Matthieu Kermagoret)
* cgi: add opt-in display_name from hosts/services definitions; if set, they will be shown in the classical ui
* cgi: re-add quick search to navmenu in order to provide quick host/service lookups without idoutils/api
* cgi: add event profiling stats of event counts and time taken for events in 'Performance Info'
* cgi: add config option show_all_services_host_is_authorized_for to cgi.cfg
It's possible to disable that the user can see all services only being an authorized contact for the host
* cgi: add multiple urls for notes|action_url on host|service object definition (Jochen Bernd)
* idoutils: add config options to allow users decision on clearing realtime and config tables on Icinga core startup
Actual config objects are marked as (in)active, because disabling the clearing results in historical config
* idoutils: remove mysql binary selects, use case-sensitive collation instead (William Preston)
* idoutils: Spread the list of linked lists thinner (extend objects hash slots) (Opsera Ltd)
* idoutils: change select * into select [*_]id if unused results
* idoutils: add syslog output, if ido2db is unable to do initial db query
* idoutils: rewrite initscript not only depending on lockfile
* idoutils: check if ido2db running before starting; if died remove lockfile first
* idoutils: add upgrade scripts to fix object relations to historical data
* config: add trailing slash in apache config for html dir
FIXES
* core: fix scheduling downtime for all services AND the host (cgi url, external commands)
* core: fix custom notifications being sent during downtimes (Sven Nierlein)
* core: fix spurious dollar signs added to command_lines (Alexander Wirt)
* core: fix for choosing next valid time on day of DST change when clocks go one hour backwards (Ton Voon)
* core: fix for nagios now erroring when "Error: Could not find any contactgroup matching..." displayed (Ton Voon)
* core: minor cleanups to icingastats.c (Eric Sesterhenn)
* core: remove dead code (Andreas Ericsson)
* core: introduce common/shared.c and include/shared.h (Andreas Ericsson)
* core: move cgiutils.h compile time option macros to config.h (Andreas Ericsson)
* core: icinga.c: remove conditional main() configuration (Andreas Ericsson)
* core: icinga.c: replace asprintf() + write_to_logs_and_console() with logit() (Andreas Ericsson)
* core: revamp logging somewhat (Andreas Ericsson)
* core: create logging.h, with stubs for the common function in cgiutils.c (Andreas Ericsson)
* core: Janitor patch: Remove unused variables (Andreas Ericsson)
* core: base/utils.c: typo-fix s/escape_newlines==/escape_newlines_please==/ (Andreas Ericsson)
* core: cgi/cmd.c: Squelch warning about empty gnu_printf format string (Andreas Ericsson)
* core: more linker tricks and less #ifdef's - log_debug_info() stubbed (Andreas Ericsson)
* core: common/objects.c: Use calloc() instead of malloc() + manual NULL'ing (Andreas Ericsson)
* core: macros: Protect against typos in macro names (Andreas Ericsson)
* core: macros: Add NOTIFICATIONISESCALATED to the list of macro names (Marc Powell)
* core: comments: Remove one comment at a time from hashlist (Hiren Patel)
* core: fix checking of the open(2) system call (David Glick)
* core: xodtemplate: Use macro magic to get rid of 900 LoC (Andreas Ericsson)
* core: more s/malloc(size) + init/calloc(1, size)/ replacements (Andreas Ericsson)
* core: header files: Remove dead prototypes (Andreas Ericsson)
* core: base/commands.c: Fix error path of opening checkresult files (Andreas Ericsson)
* core: fix open() error checking in move_check_result_to_queue() (Andreas Ericsson)
* core: xdata/xpddefault.c: Close perfdata files if fd's are >= 0 (Andreas Ericsson)
* core: fix xpddefault_{host,service}_perfdata_file_pipe not set properly on configuration re-read
* core: fix SIGSEGV in checks.c on Solaris (Torsten Huebler)
* core: added icinga object version variable in neb api for usage with idomod
* core: fix notification_period inheritance for services (Gordon Messmer)
* core: fix for notifications not being sent out when scheduled downtime is cancelled (Daniel Pouzzner)
* core: fix for first notification delay being calculated incorrectly, and notifications potentially going out early (reported by Pawel Malachowski)(Ethan Galstad)
* core: error out if services defined without description in service object definition (service def and/or used templates)
* core: fix servicechecks with timeperiods containing 'exclude' directives are incorrectly re-scheduled
* cgi: minor cleanups to cgiutils.c (Eric Sesterhenn)
* cgi: fix cmd.cgi incomplete output for command description
* cgi: fix typo: "stye" instead of "style" in cgi/tac.c
* cgi: check_daemon_running() not working on MacOS (Hendrik Baecker)
* cgi: fix CGIs don't show correct error on missing archived icinga-DATE.log file
* cgi: fix missing js files
* idoutils: Host DB inserts use string 'NULL\n' instead of NULL (William Preston)
* idoutils: ndo2db_get_object_id fails to return existing IDs (William Preston)
* idoutils: fix postgres wrong type in service_object_id
* idoutils: modify string escaping again (mysql, pgsql), needs a full rewrite though
* idoutils: fix for oracle when binding a NULL value on contactnotificationmethods
* idoutils: completely renamed idoutils (s/ndo/ido/g etc), removing old sources
* idoutils: fix compilation error of SUN_LEN on Solaris
* idoutils: add configure check for gethostbyname including -nsl on Solaris (Alexander Skwar)
* idoutils: fix host 2d y coord not stored properly
1.0.1 - 03/03/2010
ENHANCEMENTS
* core: updated docs
* core: fix config parsing for icinga_user and icinga_group
* core: fix status.dat ok, no daemon running, show error instead of old data
* core: permanently remove sleep on run_event == FALSE in main loop (Max Schubert)
* core: add service_check_timeout_state configuration variable
This setting determines the state Icinga will report when a
service check times out - it does not respond within
service_check_timeout seconds.
c - Critical (default)
u - Unknown
w - Warning
o - OK
* core: add escalation_condition definition (Vitali Voroth DECOIT GmbH)
The escalation_condition option is completely optional and can be
defined for host escalations as well as for service escalations.
escalation_condition ( [ & / | ] )*
where is either host hostname = [u,d,o] or
service hostname.service_description] = [w,u,c,o].
The escalation_condition accepts a list of one or more conditions
separated by & (logical AND) or | (logical OR).
w = WARNING
u = UNKNOWN
c = CRITICAL
o = OK for services or UP for hosts
d = DOWN for hosts
* idoutils: add ido2db threaded housekeeper
- periodic cleanup will now be performed in own thread
- startup blocking behavior removed
- housekeeper will wait for idomod instance, idle wait using und db_hello
- creates own db connection and does its job
* idoutils: add indexes for delete/select statements
- delete/select will perform faster
- getting cached objects with select runs faster
- getting logentries within icinga-web is faster
* idoutils: reorganize db setup files for MySQL/Postgresql/Oracle
- module/idoutils/db// holds needed files
- module/idoutils/scripts/ with installdb/upgradedb for MySQL
- updated Makefile, README
* idoutils: complete oracle rewrite to improve performance
- query rewrite
- 1x SELECT latest data time as is (called only at startup)
- dynamic binded procedure for DELETE on table by instance_id called at startup
for cleaning config/status
- dynamic binded procedure for DELETE on tably by instance_id, field
");
return ERROR;
}
roles = getenv("entitlement");
roles_tmp = (char *)malloc(strlen(roles) + 1);
/* read in authorization config file */
if ((thefile = mmap_fopen(filename)) != NULL) {
while (1) {
/* read the next line */
if ((input = mmap_fgets_multiline(thefile)) == NULL)
break;
strip(input);
test_char[0] = input[0];
test_char[1] = '\0';
/* ignore comment */
if (strcmp(test_char, "#") == 0)
continue;
temp_ptr = strtok(input, "=");
if (temp_ptr == NULL)
continue;
temp_rule = strtok(NULL, "=");
if (temp_rule == NULL)
continue;
strcpy(roles_tmp, roles);
role = strtok(roles_tmp, ";");
while (role != NULL) {
if (strcmp(role, temp_ptr) == 0) {
role_match = TRUE;
break;
}
role = strtok(NULL, ";");
}
if (role_match == FALSE)
continue;
authinfo->number_of_authentication_rules++;
strip(temp_rule);
/* increment the authentication_rules array */
authinfo->authentication_rules = realloc(authinfo->authentication_rules, (sizeof(char*)) * authinfo->number_of_authentication_rules);
if (authinfo->authentication_rules == NULL)
return ERROR;
authinfo->authentication_rules[authinfo->number_of_authentication_rules - 1] = malloc(sizeof(char) * (strlen(temp_rule) + 1));
strcpy(authinfo->authentication_rules[authinfo->number_of_authentication_rules - 1], temp_rule);
}
/* free memory and close the file */
free(input);
mmap_fclose(thefile);
}
free(roles_tmp);
return OK;
}
/* set default authz permissions */
int set_authz_permissions(char* permission, authdata* authinfo) {
if (strcmp(permission, "r") == 0) { /* only read permissions */
authinfo->authorized_for_read_only = TRUE;
authinfo->authorized_for_system_information = TRUE;
authinfo->authorized_for_configuration_information = TRUE;
authinfo->authorized_for_system_commands = FALSE;
authinfo->authorized_for_all_service_commands = FALSE;
authinfo->authorized_for_all_host_commands = FALSE;
} else if (strcmp(permission, "w") == 0) { /* read + write permissions */
authinfo->authorized_for_read_only = FALSE;
authinfo->authorized_for_system_information = TRUE;
authinfo->authorized_for_system_commands = TRUE;
authinfo->authorized_for_configuration_information = TRUE;
authinfo->authorized_for_all_service_commands = TRUE;
authinfo->authorized_for_all_host_commands = TRUE;
}
return TRUE;
}
/* check if user is authorized to view information about a particular host */
int is_authorized_for_host(host *hst, authdata *authinfo) {
contact *temp_contact;
char *host_list = NULL;
char *host_list2 = NULL;
char *list_tmp = NULL;
char *list_tmp2 = NULL;
char *host2 = NULL;
char *tmp = NULL;
char *tmp_permission = NULL;
char *tmp_service = NULL;
char *hg_name = NULL;
int i;
int j;
char permission[2];
int ok = FALSE;
int is_ok = FALSE;
/* if we're not using authentication, fake it */
if (use_authentication == FALSE)
return TRUE;
/* if this user has not authenticated return error */
if (authinfo->authenticated == FALSE)
return FALSE;
/* if this user is authorized for all hosts, they are for this one... */
if (is_authorized_for_all_hosts(authinfo) == TRUE)
return TRUE;
/* see if we have a host to check */
if (hst == NULL)
return FALSE;
/* find the contact */
temp_contact = find_contact(authinfo->username);
/* see if this user is a contact for the host */
if (is_contact_for_host(hst, temp_contact) == TRUE)
return TRUE;
/* see if this user is an escalated contact for the host */
if (is_escalated_contact_for_host(hst, temp_contact) == TRUE)
return TRUE;
/* authz parsing */
if (authinfo->number_of_authentication_rules != 0) {
strcpy(permission, "r");
for (i = 0; i < authinfo->number_of_authentication_rules; i++) {
list_tmp = malloc(strlen(authinfo->authentication_rules[i]) + 1);
strcpy(list_tmp, authinfo->authentication_rules[i]);
strip(list_tmp);
/* for this situation: :service:r */
if (list_tmp[0] == ':')
continue;
/* "w" is the maximum permission, do not need continue */
if (strcmp(permission, "w") == 0)
break;
host_list = strtok(list_tmp, ":");
host_list2 = malloc(strlen(host_list) + 1);
strcpy(host_list2, host_list);
tmp_service = strtok(NULL, ":");
tmp_permission = strtok(NULL, ":");
host2 = strtok(host_list2, ",");
while (host2 != NULL) {
list_tmp2 = malloc(strlen(host2) + 1);
strcpy(list_tmp2, host2);
strip(list_tmp2);
/* host group parsing */
if (list_tmp2[0] == '@') {
hg_name = malloc(strlen(list_tmp2) + 1);
strcpy(hg_name, list_tmp2);
for (j = 0; j < strlen(hg_name); j++)
hg_name[j] = hg_name[j + 1];
if (is_host_member_of_hostgroup(find_hostgroup(hg_name), hst) == TRUE) {
is_ok = TRUE;
} else {
host2 = strtok(NULL, ",");
free(hg_name);
continue;
}
free(hg_name);
}
if (strcmp(list_tmp2, hst->name) == 0 || strcmp(list_tmp2, "*") == 0)
is_ok = TRUE;
if (is_ok == TRUE) {
/* for this situation: host::r */
if (tmp_permission == NULL)
tmp_permission = tmp_service;
if (tmp_permission != NULL) {
tmp = malloc(strlen(tmp_permission) + 1);
strcpy(tmp, tmp_permission);
strip(tmp); /* "w" will overwrite "r" permission */
if (strcmp(permission, "r") == 0 && strcmp(tmp, "w") == 0) {
strcpy(permission, "w");
}
free(tmp);
}
ok = TRUE;
}
host2 = strtok(NULL, ",");
free(list_tmp2);
}
free(list_tmp);
free(host_list2);
}
if (ok == TRUE) {
set_authz_permissions(permission, authinfo);
return TRUE;
}
} /* end of authz parsing */
return FALSE;
}
/* check if user is authorized to view information about all hosts in a particular hostgroup */
int is_authorized_for_hostgroup(hostgroup *hg, authdata *authinfo) {
hostsmember *temp_hostsmember;
host *temp_host;
if (hg == NULL)
return FALSE;
/* CHANGED in 2.0 - user must be authorized for ALL hosts in a hostgroup, not just one */
/* see if user is authorized for all hosts in the hostgroup */
for (temp_hostsmember = hg->members; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
temp_host = find_host(temp_hostsmember->host_name);
if (is_authorized_for_host(temp_host, authinfo) == FALSE)
return FALSE;
}
return TRUE;
}
/* check if user is authorized to view information about all services in a particular servicegroup */
int is_authorized_for_servicegroup(servicegroup *sg, authdata *authinfo) {
servicesmember *temp_servicesmember;
service *temp_service;
if (sg == NULL)
return FALSE;
/* see if user is authorized for all services in the servicegroup */
for (temp_servicesmember = sg->members; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) {
temp_service = find_service(temp_servicesmember->host_name, temp_servicesmember->service_description);
if (is_authorized_for_service(temp_service, authinfo) == FALSE)
return FALSE;
}
return TRUE;
}
/* check if current user is restricted to read only */
int is_authorized_for_read_only(authdata *authinfo) {
/* if we're not using authentication, fake it */
if (use_authentication == FALSE)
return FALSE;
/* if this user has not authenticated return error */
if (authinfo->authenticated == FALSE)
return FALSE;
return authinfo->authorized_for_read_only;
}
/* check if current user is allowed to view read only comment data */
int is_authorized_for_comments_read_only(authdata *authinfo) {
/* if we're not using authentication, fake it */
if (use_authentication == FALSE)
return FALSE;
/* if this user has not authenticated return error */
if (authinfo->authenticated == FALSE)
return FALSE;
return authinfo->authorized_for_comments_read_only;
}
/* check if current user is allowed to view read only downtime data */
int is_authorized_for_downtimes_read_only(authdata *authinfo) {
/* if we're not using authentication, fake it */
if (use_authentication == FALSE)
return FALSE;
/* if this user has not authenticated return error */
if (authinfo->authenticated == FALSE)
return FALSE;
return authinfo->authorized_for_downtimes_read_only;
}
/* check if user is authorized to view information about a particular service */
int is_authorized_for_service(service *svc, authdata *authinfo) {
host *temp_host = NULL;
contact *temp_contact = NULL;
char *host_list = NULL;
char *host_list2 = NULL;
char *service_list = NULL;
char *list_tmp = NULL;
char *service = NULL;
char *host2 = NULL;
char *read_only = NULL;
char *list_tmp2 = NULL;
char *list_tmp3 = NULL;
char *list_tmp4 = NULL;
char *sg_name = NULL;
char *hg_name = NULL;
int i = 0;
int j = 0;
int ok = FALSE;
int is_ok = FALSE;
int is_ok2 = FALSE;
char permission[2];
/* if we're not using authentication, fake it */
if (use_authentication == FALSE)
return TRUE;
/* if this user has not authenticated return error */
if (authinfo->authenticated == FALSE)
return FALSE;
/* if this user is authorized for all services, they are for this one... */
if (is_authorized_for_all_services(authinfo) == TRUE)
return TRUE;
/* see if we have a service to check */
if (svc == NULL)
return FALSE;
/* find the host */
temp_host = find_host(svc->host_name);
if (temp_host == NULL)
return FALSE;
/* if this user is authorized for this host, they are for all services on it as well... */
/* 06-02-2010 added config option, if set FALSE, this condition won't match and
user must be authorized for the services too in order to view them */
if (is_authorized_for_host(temp_host, authinfo) == TRUE) {
/* first off, let attribute based auth decide, then show_all_services_host_is_authorized_for==TRUE */
/* authz parsing */
if (authinfo->number_of_authentication_rules != 0) {
strcpy(permission, "r");
for (i = 0; i < authinfo->number_of_authentication_rules; i++) {
/* "w" is the maximum permission, do not need continue */
if (strcmp(permission, "w") == 0) break;
list_tmp = malloc(strlen(authinfo->authentication_rules[i]) + 1);
strcpy(list_tmp, authinfo->authentication_rules[i]);
host_list = strtok(list_tmp, ":");
host_list2 = malloc(strlen(host_list) + 1);
strcpy(host_list2, host_list);
service_list = strtok(NULL, ":");
read_only = strtok(NULL, ":");
service = strtok(service_list, ",");
while (service != NULL) {
list_tmp2 = malloc(strlen(service) + 1);
strcpy(list_tmp2, service);
strip(list_tmp2);
/* service group parsing */
if (list_tmp2[0] == '@') {
sg_name = malloc(strlen(list_tmp2) + 1);
strcpy(sg_name, list_tmp2);
for (j = 0; j < strlen(sg_name); j++)
sg_name[j] = sg_name[j + 1];
if (is_service_member_of_servicegroup(find_servicegroup(sg_name), svc) == TRUE) {
is_ok2 = TRUE;
} else {
service = strtok(NULL, ",");
free(sg_name);
continue;
}
free(sg_name);
}
if (strcmp(list_tmp2, svc->display_name) == 0 || strcmp(list_tmp2, "*") == 0)
is_ok2 = TRUE;
if (is_ok2 == TRUE) {
host2 = strtok(host_list2, ",");
while (host2 != NULL) {
list_tmp3 = malloc(strlen(host2) + 1);
strcpy(list_tmp3, host2);
strip(list_tmp3);
/* host group parsing */
if (list_tmp3[0] == '@') {
hg_name = malloc(strlen(list_tmp3) + 1);
strcpy(hg_name, list_tmp3);
for (j = 0; j < strlen(hg_name); j++)
hg_name[j] = hg_name[j + 1];
if (is_host_member_of_hostgroup(find_hostgroup(hg_name), temp_host) == TRUE) {
is_ok = TRUE;
} else {
host2 = strtok(NULL, ",");
free(hg_name);
continue;
}
free(hg_name);
}
if (strcmp(list_tmp2, svc->host_name) == 0 || strcmp(list_tmp2, "*") == 0)
is_ok = TRUE;
if (is_ok == TRUE) {
if (read_only != NULL) {
list_tmp4 = malloc(strlen(read_only) + 1);
strcpy(list_tmp4, read_only);
strip(list_tmp4); /* "w" will overwrite "r" permission */
if (strcmp(permission, "r") == 0 && strcmp(list_tmp4, "w") == 0) {
strcpy(permission, "w");
}
free(list_tmp4);
}
ok = TRUE;
}
host2 = strtok(NULL, ",");
free(list_tmp3);
}
}
service = strtok(NULL, ",");
free(list_tmp2);
}
free(list_tmp);
free(host_list2);
}
if (ok == TRUE) {
set_authz_permissions(permission, authinfo);
return TRUE;
}
} /* end of authz parsing */
else {
/* user does not need to be authorized for the services too in order to view them? */
if (show_all_services_host_is_authorized_for == TRUE) {
return TRUE;
}
}
}
/* find the contact */
temp_contact = find_contact(authinfo->username);
/* see if this user is a contact for the service */
if (is_contact_for_service(svc, temp_contact) == TRUE)
return TRUE;
/* see if this user is an escalated contact for the service */
if (is_escalated_contact_for_service(svc, temp_contact) == TRUE)
return TRUE;
return FALSE;
}
/* check if current user is authorized to view information on all hosts */
int is_authorized_for_all_hosts(authdata *authinfo) {
/* if we're not using authentication, fake it */
if (use_authentication == FALSE)
return TRUE;
/* if this user has not authenticated return error */
if (authinfo->authenticated == FALSE)
return FALSE;
return authinfo->authorized_for_all_hosts;
}
/* check if current user is authorized to view information on all service */
int is_authorized_for_all_services(authdata *authinfo) {
/* if we're not using authentication, fake it */
if (use_authentication == FALSE)
return TRUE;
/* if this user has not authenticated return error */
if (authinfo->authenticated == FALSE)
return FALSE;
return authinfo->authorized_for_all_services;
}
/* check if current user is authorized to view system information */
int is_authorized_for_system_information(authdata *authinfo) {
/* if we're not using authentication, fake it */
if (use_authentication == FALSE)
return TRUE;
/* if this user has not authenticated return error */
if (authinfo->authenticated == FALSE)
return FALSE;
return authinfo->authorized_for_system_information;
}
/* check if current user is authorized to view configuration information */
int is_authorized_for_configuration_information(authdata *authinfo) {
/* if we're not using authentication, fake it */
if (use_authentication == FALSE)
return TRUE;
/* if this user has not authenticated return error */
if (authinfo->authenticated == FALSE)
return FALSE;
return authinfo->authorized_for_configuration_information;
}
/* check if current user is authorized to view raw commandline configuration information */
int is_authorized_for_full_command_resolution(authdata *authinfo) {
/* if we're not using authentication, fake it */
if (use_authentication == FALSE)
return TRUE;
/* if this user has not authenticated return error */
if (authinfo->authenticated == FALSE)
return FALSE;
return authinfo->authorized_for_full_command_resolution;
}
/* check if current user is authorized to issue system commands */
int is_authorized_for_system_commands(authdata *authinfo) {
/* if we're not using authentication, fake it */
if (use_authentication == FALSE)
return TRUE;
/* if this user has not authenticated return error */
if (authinfo->authenticated == FALSE)
return FALSE;
return authinfo->authorized_for_system_commands;
}
/* check is the current user is authorized to issue commands relating to a particular service */
int is_authorized_for_service_commands(service *svc, authdata *authinfo) {
host *temp_host;
contact *temp_contact;
if (svc == NULL)
return FALSE;
/* if we're not using authentication, fake it */
if (use_authentication == FALSE)
return TRUE;
/* if this user has not authenticated return error */
if (authinfo->authenticated == FALSE)
return FALSE;
/* the user is authorized if they have rights to the service */
if (is_authorized_for_service(svc, authinfo) == TRUE) {
/* find the host */
temp_host = find_host(svc->host_name);
if (temp_host == NULL)
return FALSE;
/* find the contact */
temp_contact = find_contact(authinfo->username);
/* reject if contact is not allowed to issue commands */
if (temp_contact && temp_contact->can_submit_commands == FALSE)
return FALSE;
/* see if this user is a contact for the host */
if (is_contact_for_host(temp_host, temp_contact) == TRUE)
return TRUE;
/* see if this user is an escalated contact for the host */
if (is_escalated_contact_for_host(temp_host, temp_contact) == TRUE)
return TRUE;
/* this user is a contact for the service, so they have permission... */
if (is_contact_for_service(svc, temp_contact) == TRUE)
return TRUE;
/* this user is an escalated contact for the service, so they have permission... */
if (is_escalated_contact_for_service(svc, temp_contact) == TRUE)
return TRUE;
/* this user is not a contact for the host, so they must have been given explicit permissions to all service commands */
if (authinfo->authorized_for_all_service_commands == TRUE)
return TRUE;
}
return FALSE;
}
/* check is the current user is authorized to issue commands relating to a particular host */
int is_authorized_for_host_commands(host *hst, authdata *authinfo) {
contact *temp_contact;
if (hst == NULL)
return FALSE;
/* if we're not using authentication, fake it */
if (use_authentication == FALSE)
return TRUE;
/* if this user has not authenticated return error */
if (authinfo->authenticated == FALSE)
return FALSE;
/* the user is authorized if they have rights to the host */
if (is_authorized_for_host(hst, authinfo) == TRUE) {
/* find the contact */
temp_contact = find_contact(authinfo->username);
/* reject if contact is not allowed to issue commands */
if (temp_contact && temp_contact->can_submit_commands == FALSE)
return FALSE;
/* this user is a contact for the host, so they have permission... */
if (is_contact_for_host(hst, temp_contact) == TRUE)
return TRUE;
/* this user is an escalated contact for the host, so they have permission... */
if (is_escalated_contact_for_host(hst, temp_contact) == TRUE)
return TRUE;
/* this user is not a contact for the host, so they must have been given explicit permissions to all host commands */
if (authinfo->authorized_for_all_host_commands == TRUE)
return TRUE;
}
return FALSE;
}
/* check is the current user is authorized to issue commands relating to a particular servicegroup */
int is_authorized_for_servicegroup_commands(servicegroup *sg, authdata *authinfo) {
servicesmember *temp_servicesmember;
service *temp_service;
if (sg == NULL)
return FALSE;
/* see if user is authorized for all services commands in the servicegroup */
for (temp_servicesmember = sg->members; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) {
temp_service = find_service(temp_servicesmember->host_name, temp_servicesmember->service_description);
if (is_authorized_for_service_commands(temp_service, authinfo) == FALSE)
return FALSE;
}
return TRUE;
}
/* check is the current user is authorized to issue commands relating to a particular hostgroup */
int is_authorized_for_hostgroup_commands(hostgroup *hg, authdata *authinfo) {
hostsmember *temp_hostsmember;
host *temp_host;
if (hg == NULL)
return FALSE;
/* see if user is authorized for all hosts in the hostgroup */
for (temp_hostsmember = hg->members; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
temp_host = find_host(temp_hostsmember->host_name);
if (is_authorized_for_host_commands(temp_host, authinfo) == FALSE)
return FALSE;
}
return TRUE;
}
icinga-1.10.3/cgi/cgiutils.c 0000664 0000000 0000000 00000375477 12276402000 0015577 0 ustar 00root root 0000000 0000000 /***********************************************************************
*
* CGIUTILS.C - Common utilities for Icinga CGIs
*
* Copyright (c) 1999-2009 Ethan Galstad (egalstad@nagios.org)
* Copyright (c) 2012 Nagios Core Development Team and Community Contributors
* Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
***********************************************************************/
#include "../include/config.h"
#include "../include/common.h"
#include "../include/locations.h"
#include "../include/objects.h"
#include "../include/macros.h"
#include "../include/statusdata.h"
#include "../include/comments.h"
#include "../include/cgiutils.h"
char main_config_file[MAX_FILENAME_LENGTH];
char command_file[MAX_FILENAME_LENGTH];
char physical_html_path[MAX_FILENAME_LENGTH];
char physical_images_path[MAX_FILENAME_LENGTH];
char physical_ssi_path[MAX_FILENAME_LENGTH];
char url_html_path[MAX_FILENAME_LENGTH];
char url_docs_path[MAX_FILENAME_LENGTH];
char url_images_path[MAX_FILENAME_LENGTH];
char url_logo_images_path[MAX_FILENAME_LENGTH];
char url_stylesheets_path[MAX_FILENAME_LENGTH];
char url_js_path[MAX_FILENAME_LENGTH];
char url_jquiryui_path[MAX_FILENAME_LENGTH];
char url_jquiryui_addon_path[MAX_FILENAME_LENGTH];
char url_media_path[MAX_FILENAME_LENGTH];
char *service_critical_sound = NULL;
char *service_warning_sound = NULL;
char *service_unknown_sound = NULL;
char *host_down_sound = NULL;
char *host_unreachable_sound = NULL;
char *normal_sound = NULL;
char *statusmap_background_image = NULL;
char *illegal_output_chars = NULL;
char illegal_output_char_map[] = CHAR_MAP_INIT(0);
char *http_charset = NULL;
char *notes_url_target = NULL;
char *action_url_target = NULL;
char *csv_delimiter = CSV_DELIMITER;
char *csv_data_enclosure = CSV_DATA_ENCLOSURE;
int highlight_table_rows = TRUE;
char nagios_check_command[MAX_INPUT_BUFFER] = "";
char nagios_process_info[MAX_INPUT_BUFFER] = "";
int enable_splunk_integration = FALSE;
char *splunk_url = NULL;
int lock_author_names = TRUE;
char *authorization_config_file = NULL;
char *authorized_for_all_host_commands = NULL;
char *authorized_for_all_hosts = NULL;
char *authorized_for_all_service_commands = NULL;
char *authorized_for_all_services = NULL;
char *authorized_for_configuration_information = NULL;
char *authorized_for_full_command_resolution = NULL;
char *authorized_for_read_only = NULL;
char *authorized_for_comments_read_only = NULL;
char *authorized_for_downtimes_read_only = NULL;
char *authorized_for_system_commands = NULL;
char *authorized_for_system_information = NULL;
char *authorized_contactgroup_for_all_host_commands = NULL;
char *authorized_contactgroup_for_all_hosts = NULL;
char *authorized_contactgroup_for_all_service_commands = NULL;
char *authorized_contactgroup_for_all_services = NULL;
char *authorized_contactgroup_for_configuration_information = NULL;
char *authorized_contactgroup_for_full_command_resolution = NULL;
char *authorized_contactgroup_for_read_only = NULL;
char *authorized_contactgroup_for_comments_read_only = NULL;
char *authorized_contactgroup_for_downtimes_read_only = NULL;
char *authorized_contactgroup_for_system_commands = NULL;
char *authorized_contactgroup_for_system_information = NULL;
char *exclude_customvar_name = NULL;
char *exclude_customvar_value = NULL;
char *default_user_name = NULL;
extern time_t program_start;
extern int nagios_pid;
extern int daemon_mode;
extern int enable_notifications;
extern int execute_service_checks;
extern int accept_passive_service_checks;
extern int execute_host_checks;
extern int accept_passive_host_checks;
extern int obsess_over_hosts;
extern int enable_flap_detection;
extern int enable_event_handlers;
extern int obsess_over_services;
extern int enable_failure_prediction;
extern int process_performance_data;
extern int check_service_freshness;
extern int check_host_freshness;
extern time_t disable_notifications_expire_time;
extern time_t last_command_check;
extern time_t last_log_rotation;
extern time_t status_file_creation_time;
extern char *status_file_icinga_version;
/* resource file */
char resource_file[MAX_INPUT_BUFFER];
extern char *macro_user[MAX_USER_MACROS];
/** readlogs.c **/
int log_rotation_method = LOG_ROTATION_NONE;
char log_file[MAX_INPUT_BUFFER];
char log_archive_path[MAX_INPUT_BUFFER];
int status_update_interval = 60;
int check_external_commands = 0;
int date_format = DATE_FORMAT_US;
int use_authentication = TRUE;
int interval_length = 60;
int show_all_services_host_is_authorized_for = TRUE;
int use_pending_states = TRUE;
int host_status_has_been_read = FALSE;
int service_status_has_been_read = FALSE;
int program_status_has_been_read = FALSE;
int refresh_rate = DEFAULT_REFRESH_RATE;
int refresh_type = JAVASCRIPT_REFRESH;
int escape_html_tags = FALSE;
int persistent_ack_comments = FALSE;
int send_ack_notifications = TRUE;
int use_ssl_authentication = FALSE;
int lowercase_user_name = FALSE;
int default_statusmap_layout_method = 0;
int color_transparency_index_r = 255;
int color_transparency_index_g = 255;
int color_transparency_index_b = 255;
int status_show_long_plugin_output = FALSE;
int tac_show_only_hard_state = FALSE;
int extinfo_show_child_hosts = SHOW_CHILD_HOSTS_NONE;
int suppress_maintenance_downtime = FALSE;
int show_tac_header = TRUE;
int show_tac_header_pending = TRUE;
int showlog_initial_states = FALSE;
int showlog_current_states = FALSE;
int tab_friendly_titles = FALSE;
int add_notif_num_hard = 0;
int add_notif_num_soft = 0;
int enforce_comments_on_actions = FALSE;
int week_starts_on_monday = FALSE;
int show_partial_hostgroups = FALSE;
int show_partial_servicegroups = FALSE;
int default_downtime_duration = 7200;
int default_expiring_acknowledgement_duration = 86400;
int set_expire_ack_by_default = FALSE;
int default_expiring_disabled_notifications_duration = 86400;
int result_limit = 50;
extern hostgroup *hostgroup_list;
extern contactgroup *contactgroup_list;
extern command *command_list;
extern timeperiod *timeperiod_list;
extern contact *contact_list;
extern serviceescalation *serviceescalation_list;
extern hoststatus *hoststatus_list;
extern servicestatus *servicestatus_list;
char encoded_url_string[4][MAX_INPUT_BUFFER]; // 2 to be able use url_encode 4 times
char encoded_html_string[2][(MAX_COMMAND_BUFFER * 6)]; // 2 to be able use html_encode twice
#ifdef HAVE_TZNAME
#ifdef CYGWIN
extern char *_tzname[2] __declspec(dllimport);
#else
extern char *tzname[2];
#endif
#endif
int content_type = HTML_CONTENT;
int embedded = FALSE;
int display_header = TRUE;
int display_status_totals = FALSE;
int refresh = TRUE;
int daemon_check = TRUE;
int tac_header = FALSE;
extern int CGI_ID;
/* used for logging function */
char cgi_log_file[MAX_FILENAME_LENGTH] = "";
char cgi_log_archive_path[MAX_FILENAME_LENGTH] = "";
int use_logging = FALSE;
int cgi_log_rotation_method = LOG_ROTATION_NONE;
/*
* These function stubs allow us to compile a lot of the
* source-files common to cgi's and daemon without adding
* a whole bunch of #ifdef's everywhere. Note that we can't
* have them as macros, since the goal is to compile the
* source-files once. A decent linker will make the call
* a no-op anyway, so it's not a big issue
*/
int log_debug_info(int leve, int verbosity, const char *fmt, ...) {
return 0;
}
/*
* pipe all common logit calls into our cgi log file
* if enabled using 'use_logging'
* ATTENTION: do not use logit() calls within cgi log rotate.
* creates a loop.
*/
void logit(int data_type, int display, const char *fmt, ...) {
if (use_logging) {
va_list ap;
char *buffer = NULL;
va_start(ap, fmt);
if (vasprintf(&buffer, fmt, ap) > 0) {
write_to_cgi_log(buffer);
free(buffer);
}
va_end(ap);
}
}
/* check if customvar name or value must be excluded */
int check_exclude_customvar(customvariablesmember *customvariable) {
char *temp_ptr;
char temp_data[MAX_INPUT_BUFFER];
#define EXCLUDE_CUSTOMVAR(type) \
if (exclude_customvar_##type != NULL && strlen(exclude_customvar_##type) > 0) { \
strncpy(temp_data, exclude_customvar_##type, sizeof(temp_data) -1); \
for (temp_ptr = strtok(temp_data, ","); temp_ptr != NULL; temp_ptr = strtok(NULL, ",")) { \
if (strstr(customvariable->variable_##type, temp_ptr) || !strcmp(temp_ptr, "*")) { \
return TRUE; \
} \
} \
}
EXCLUDE_CUSTOMVAR(name)
EXCLUDE_CUSTOMVAR(value)
/* if both did not hit do not exclude any */
return FALSE;
}
/**********************************************************
***************** CLEANUP FUNCTIONS **********************
**********************************************************/
/* reset all variables used by the CGIs */
void reset_cgi_vars(void) {
strcpy(main_config_file, "");
strcpy(physical_html_path, "");
strcpy(physical_images_path, "");
strcpy(physical_ssi_path, "");
strcpy(url_html_path, "");
strcpy(url_docs_path, "");
strcpy(url_stylesheets_path, "");
strcpy(url_js_path, "");
strcpy(url_media_path, "");
strcpy(url_images_path, "");
strcpy(log_file, "");
strcpy(log_archive_path, DEFAULT_LOG_ARCHIVE_PATH);
if (log_archive_path[strlen(log_archive_path) - 1] != '/' && strlen(log_archive_path) < sizeof(log_archive_path) - 2)
strcat(log_archive_path, "/");
strcpy(command_file, get_cmd_file_location());
strcpy(nagios_check_command, "");
strcpy(nagios_process_info, "");
log_rotation_method = LOG_ROTATION_NONE;
cgi_log_rotation_method = LOG_ROTATION_NONE;
use_authentication = TRUE;
interval_length = 60;
refresh_rate = DEFAULT_REFRESH_RATE;
refresh_type = JAVASCRIPT_REFRESH;
default_statusmap_layout_method = 0;
default_statusmap_layout_method = 0;
service_critical_sound = NULL;
service_warning_sound = NULL;
service_unknown_sound = NULL;
host_down_sound = NULL;
host_unreachable_sound = NULL;
normal_sound = NULL;
my_free(http_charset);
http_charset = strdup(DEFAULT_HTTP_CHARSET);
statusmap_background_image = NULL;
color_transparency_index_r = 255;
color_transparency_index_g = 255;
color_transparency_index_b = 255;
return;
}
/* free all memory for object definitions */
void free_memory(void) {
/* free memory for common object definitions */
free_object_data();
/* free memory for status data */
free_status_data();
/* free misc data */
free(service_critical_sound);
free(service_warning_sound);
free(service_unknown_sound);
free(host_down_sound);
free(host_unreachable_sound);
free(normal_sound);
free(statusmap_background_image);
return;
}
/**********************************************************
*************** CONFIG FILE FUNCTIONS ********************
**********************************************************/
/* read the CGI config file location from an environment variable */
char * get_cgi_config_location(void) {
static char *cgiloc = NULL;
if (!cgiloc) {
cgiloc = getenv("ICINGA_CGI_CONFIG");
if (!cgiloc) {
/* stay compatible */
cgiloc = getenv("NAGIOS_CGI_CONFIG");
if (!cgiloc) {
cgiloc = DEFAULT_CGI_CONFIG_FILE;
}
}
}
return cgiloc;
}
/* read the command file location from an environment variable */
char * get_cmd_file_location(void) {
static char *cmdloc = NULL;
if (!cmdloc) {
cmdloc = getenv("ICINGA_COMMAND_FILE");
if (!cmdloc) {
/* stay compatible */
cmdloc = getenv("NAGIOS_COMMAND_FILE");
if (!cmdloc) {
cmdloc = command_file;
}
}
}
return cmdloc;
}
/*read the CGI configuration file */
int read_cgi_config_file(char *filename) {
char *input = NULL;
mmapfile *thefile;
char *var = NULL;
char *val = NULL;
char *p = NULL;
int standalone_installation = 0;
if ((thefile = mmap_fopen(filename)) == NULL)
return ERROR;
while (1) {
/* free memory */
free(input);
/* read the next line */
if ((input = mmap_fgets_multiline(thefile)) == NULL)
break;
strip(input);
var = strtok(input, "=");
val = strtok(NULL, "\n");
if (var == NULL || val == NULL)
continue;
if (!strcmp(var, "main_config_file")) {
strncpy(main_config_file, val, sizeof(main_config_file));
main_config_file[sizeof(main_config_file) - 1] = '\x0';
strip(main_config_file);
}
else if (!strcmp(var, "standalone_installation"))
standalone_installation = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "show_all_services_host_is_authorized_for"))
show_all_services_host_is_authorized_for = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "show_partial_hostgroups"))
show_partial_hostgroups = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "show_partial_servicegroups"))
show_partial_servicegroups = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "use_pending_states"))
use_pending_states = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "use_authentication"))
use_authentication = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "nagios_check_command")) {
strncpy(nagios_check_command, val, sizeof(nagios_check_command));
nagios_check_command[sizeof(nagios_check_command) - 1] = '\x0';
strip(nagios_check_command);
}
else if (!strcmp(var, "refresh_rate"))
refresh_rate = atoi(val);
else if (!strcmp(var, "refresh_type"))
refresh_type = (atoi(val) > 0) ? JAVASCRIPT_REFRESH : HTTPHEADER_REFRESH;
else if (!strcmp(var, "physical_html_path")) {
strncpy(physical_html_path, val, sizeof(physical_html_path));
physical_html_path[sizeof(physical_html_path) - 1] = '\x0';
strip(physical_html_path);
if (physical_html_path[strlen(physical_html_path) - 1] != '/' && (strlen(physical_html_path) < sizeof(physical_html_path) - 1))
strcat(physical_html_path, "/");
snprintf(physical_images_path, sizeof(physical_images_path), "%simages/", physical_html_path);
physical_images_path[sizeof(physical_images_path) - 1] = '\x0';
snprintf(physical_ssi_path, sizeof(physical_images_path), "%sssi/", physical_html_path);
physical_ssi_path[sizeof(physical_ssi_path) - 1] = '\x0';
}
else if (!strcmp(var, "url_html_path")) {
strncpy(url_html_path, val, sizeof(url_html_path));
url_html_path[sizeof(url_html_path) - 1] = '\x0';
strip(url_html_path);
if (url_html_path[strlen(url_html_path) - 1] != '/' && (strlen(url_html_path) < sizeof(url_html_path) - 1))
strcat(url_html_path, "/");
snprintf(url_docs_path, sizeof(url_docs_path), "%sdocs/", url_html_path);
url_docs_path[sizeof(url_docs_path) - 1] = '\x0';
snprintf(url_images_path, sizeof(url_images_path), "%simages/", url_html_path);
url_images_path[sizeof(url_images_path) - 1] = '\x0';
snprintf(url_logo_images_path, sizeof(url_logo_images_path), "%slogos/", url_images_path);
url_logo_images_path[sizeof(url_logo_images_path) - 1] = '\x0';
snprintf(url_js_path, sizeof(url_js_path), "%sjs/", url_html_path);
url_js_path[sizeof(url_js_path) - 1] = '\x0';
snprintf(url_jquiryui_path, sizeof(url_jquiryui_path), "%sjquery-ui/", url_html_path);
url_jquiryui_path[sizeof(url_jquiryui_path) - 1] = '\x0';
snprintf(url_jquiryui_addon_path, sizeof(url_jquiryui_addon_path), "%sjquery-ui-addon/", url_html_path);
url_jquiryui_addon_path[sizeof(url_jquiryui_addon_path) - 1] = '\x0';
snprintf(url_media_path, sizeof(url_media_path), "%smedia/", url_html_path);
url_media_path[sizeof(url_media_path) - 1] = '\x0';
}
else if (!strcmp(var, "url_stylesheets_path")) {
strncpy(url_stylesheets_path, val, sizeof(url_stylesheets_path));
url_stylesheets_path[sizeof(url_stylesheets_path) - 1] = '\x0';
strip(url_stylesheets_path);
if (url_stylesheets_path[strlen(url_stylesheets_path) - 1] != '/' && (strlen(url_stylesheets_path) < sizeof(url_stylesheets_path) - 1))
strcat(url_stylesheets_path, "/");
} else if (!strcmp(var, "cgi_log_archive_path")) {
strncpy(cgi_log_archive_path, val, sizeof(cgi_log_archive_path));
cgi_log_archive_path[sizeof(cgi_log_archive_path) - 1] = '\x0';
strip(cgi_log_archive_path);
if (cgi_log_archive_path[strlen(cgi_log_archive_path) - 1] != '/' && (strlen(cgi_log_archive_path) < sizeof(cgi_log_archive_path) - 1))
strcat(cgi_log_archive_path, "/");
} else if (!strcmp(var, "cgi_log_file")) {
strncpy(cgi_log_file, val, sizeof(cgi_log_file));
cgi_log_file[sizeof(cgi_log_file) - 1] = '\x0';
strip(cgi_log_file);
} else if (!strcmp(var, "cgi_log_rotation_method")) {
if (!strcmp(val, "h"))
cgi_log_rotation_method = LOG_ROTATION_HOURLY;
else if (!strcmp(val, "d"))
cgi_log_rotation_method = LOG_ROTATION_DAILY;
else if (!strcmp(val, "w"))
cgi_log_rotation_method = LOG_ROTATION_WEEKLY;
else if (!strcmp(val, "m"))
cgi_log_rotation_method = LOG_ROTATION_MONTHLY;
} else if (!strcmp(var, "use_logging"))
use_logging = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "enforce_comments_on_actions"))
enforce_comments_on_actions = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "first_day_of_week"))
week_starts_on_monday = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "service_critical_sound"))
service_critical_sound = strdup(val);
else if (!strcmp(var, "service_warning_sound"))
service_warning_sound = strdup(val);
else if (!strcmp(var, "service_unknown_sound"))
service_unknown_sound = strdup(val);
else if (!strcmp(var, "host_down_sound"))
host_down_sound = strdup(val);
else if (!strcmp(var, "host_unreachable_sound"))
host_unreachable_sound = strdup(val);
else if (!strcmp(var, "normal_sound"))
normal_sound = strdup(val);
else if (!strcmp(var, "statusmap_background_image"))
statusmap_background_image = strdup(val);
else if (!strcmp(var, "color_transparency_index_r"))
color_transparency_index_r = atoi(val);
else if (!strcmp(var, "color_transparency_index_g"))
color_transparency_index_g = atoi(val);
else if (!strcmp(var, "color_transparency_index_b"))
color_transparency_index_b = atoi(val);
else if (!strcmp(var, "default_statusmap_layout"))
default_statusmap_layout_method = atoi(val);
else if (!strcmp(var, "action_url_target"))
action_url_target = strdup(val);
else if (!strcmp(var, "illegal_macro_output_chars"))
illegal_output_chars = strdup(val);
else if (!strcmp(var, "http_charset"))
http_charset = strdup(val);
else if (!strcmp(var, "notes_url_target"))
notes_url_target = strdup(val);
else if (!strcmp(var, "enable_splunk_integration"))
enable_splunk_integration = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "splunk_url"))
splunk_url = strdup(val);
else if (!strcmp(var, "escape_html_tags"))
escape_html_tags = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "persistent_ack_comments"))
persistent_ack_comments = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "send_ack_notifications"))
send_ack_notifications = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "default_expiring_acknowledgement_duration"))
default_expiring_acknowledgement_duration = atoi(val);
else if (!strcmp(var, "set_expire_ack_by_default"))
set_expire_ack_by_default = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "default_expiring_disabled_notifications_duration"))
default_expiring_disabled_notifications_duration = atoi(val);
else if (!strcmp(var, "lock_author_names"))
lock_author_names = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "default_downtime_duration"))
default_downtime_duration = atoi(val);
else if (!strcmp(var, "result_limit"))
result_limit = atoi(val);
else if (!strcmp(var, "use_ssl_authentication"))
use_ssl_authentication = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "lowercase_user_name"))
lowercase_user_name = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "status_show_long_plugin_output"))
status_show_long_plugin_output = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "tac_show_only_hard_state"))
tac_show_only_hard_state = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "extinfo_show_child_hosts")) {
if (atoi(val) == SHOW_CHILD_HOSTS_IMMEDIATE)
extinfo_show_child_hosts = SHOW_CHILD_HOSTS_IMMEDIATE;
else if (atoi(val) == SHOW_CHILD_HOSTS_ALL)
extinfo_show_child_hosts = SHOW_CHILD_HOSTS_ALL;
} else if (!strcmp(var, "suppress_maintenance_downtime"))
suppress_maintenance_downtime = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "show_tac_header"))
show_tac_header = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "show_tac_header_pending"))
show_tac_header_pending = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "showlog_initial_state") || !strcmp(var, "showlog_initial_states"))
showlog_initial_states = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "showlog_current_state") || !strcmp(var, "showlog_current_states"))
showlog_current_states = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "tab_friendly_titles"))
tab_friendly_titles = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "add_notif_num_hard"))
add_notif_num_hard = atoi(val);
else if (!strcmp(var, "add_notif_num_soft"))
add_notif_num_soft = atoi(val);
else if (!strcmp(var, "csv_delimiter"))
csv_delimiter = strdup(val);
else if (!strcmp(var, "csv_data_enclosure"))
csv_data_enclosure = strdup(val);
else if (!strcmp(var, "highlight_table_rows"))
highlight_table_rows = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "display_status_totals"))
display_status_totals = (atoi(val) > 0) ? TRUE : FALSE;
else if (!strcmp(var, "authorization_config_file")) {
authorization_config_file = strdup(val);
strip(authorization_config_file);
} else if (!strcmp(var, "authorized_for_all_host_commands")) {
authorized_for_all_host_commands = strdup(val);
strip(authorized_for_all_host_commands);
} else if (!strcmp(var, "authorized_for_all_hosts")) {
authorized_for_all_hosts = strdup(val);
strip(authorized_for_all_hosts);
} else if (!strcmp(var, "authorized_for_all_service_commands")) {
authorized_for_all_service_commands = strdup(val);
strip(authorized_for_all_service_commands);
} else if (!strcmp(var, "authorized_for_all_services")) {
authorized_for_all_services = strdup(val);
strip(authorized_for_all_services);
} else if (!strcmp(var, "authorized_for_configuration_information")) {
authorized_for_configuration_information = strdup(val);
strip(authorized_for_configuration_information);
} else if (!strcmp(var, "authorized_for_full_command_resolution")) {
authorized_for_full_command_resolution = strdup(val);
strip(authorized_for_full_command_resolution);
} else if (!strcmp(var, "authorized_for_read_only")) {
authorized_for_read_only = strdup(val);
strip(authorized_for_read_only);
} else if (!strcmp(var, "authorized_for_comments_read_only")) {
authorized_for_comments_read_only = strdup(val);
strip(authorized_for_comments_read_only);
} else if (!strcmp(var, "authorized_for_downtimes_read_only")) {
authorized_for_downtimes_read_only = strdup(val);
strip(authorized_for_downtimes_read_only);
} else if (!strcmp(var, "authorized_for_system_commands")) {
authorized_for_system_commands = strdup(val);
strip(authorized_for_system_commands);
} else if (!strcmp(var, "authorized_for_system_information")) {
authorized_for_system_information = strdup(val);
strip(authorized_for_system_information);
} else if (!strcmp(var, "authorized_contactgroup_for_all_host_commands")) {
authorized_contactgroup_for_all_host_commands = strdup(val);
strip(authorized_contactgroup_for_all_host_commands);
} else if (!strcmp(var, "authorized_contactgroup_for_all_hosts")) {
authorized_contactgroup_for_all_hosts = strdup(val);
strip(authorized_contactgroup_for_all_hosts);
} else if (!strcmp(var, "authorized_contactgroup_for_all_service_commands")) {
authorized_contactgroup_for_all_service_commands = strdup(val);
strip(authorized_contactgroup_for_all_service_commands);
} else if (!strcmp(var, "authorized_contactgroup_for_all_services")) {
authorized_contactgroup_for_all_services = strdup(val);
strip(authorized_contactgroup_for_all_services);
} else if (!strcmp(var, "authorized_contactgroup_for_configuration_information")) {
authorized_contactgroup_for_configuration_information = strdup(val);
strip(authorized_contactgroup_for_configuration_information);
} else if (!strcmp(var, "authorized_contactgroup_for_full_command_resolution")) {
authorized_contactgroup_for_full_command_resolution = strdup(val);
strip(authorized_contactgroup_for_full_command_resolution);
} else if (!strcmp(var, "authorized_contactgroup_for_read_only")) {
authorized_contactgroup_for_read_only = strdup(val);
strip(authorized_contactgroup_for_read_only);
} else if (!strcmp(var, "authorized_contactgroup_for_comments_read_only")) {
authorized_contactgroup_for_comments_read_only = strdup(val);
strip(authorized_contactgroup_for_comments_read_only);
} else if (!strcmp(var, "authorized_contactgroup_for_downtimes_read_only")) {
authorized_contactgroup_for_downtimes_read_only = strdup(val);
strip(authorized_contactgroup_for_downtimes_read_only);
} else if (!strcmp(var, "authorized_contactgroup_for_system_commands")) {
authorized_contactgroup_for_system_commands = strdup(val);
strip(authorized_contactgroup_for_system_commands);
} else if (!strcmp(var, "authorized_contactgroup_for_system_information")) {
authorized_contactgroup_for_system_information = strdup(val);
strip(authorized_contactgroup_for_system_information);
} else if (!strcmp(var, "exclude_customvar_name")) {
exclude_customvar_name = strdup(val);
strip(exclude_customvar_name);
} else if (!strcmp(var, "exclude_customvar_value")) {
exclude_customvar_value = strdup(val);
strip(exclude_customvar_value);
} else if (!strcmp(var, "default_user_name")) {
default_user_name = strdup(val);
strip(default_user_name);
}
}
for (p = illegal_output_chars; p && *p; p++)
illegal_output_char_map[(int)*p] = 1;
/* free memory and close the file */
free(input);
mmap_fclose(thefile);
/* check if stylesheet path was set */
if (!strcmp(url_stylesheets_path, "")) {
snprintf(url_stylesheets_path, sizeof(url_stylesheets_path), "%sstylesheets/", url_html_path);
url_stylesheets_path[sizeof(url_stylesheets_path) - 1] = '\x0';
}
if (!strcmp(main_config_file, "")) {
if (standalone_installation == TRUE) {
/*
* if standalone_installation is switched on, we assume that
* all vars are defined in cgi.cfg
*/
strncpy(main_config_file, filename, sizeof(main_config_file));
main_config_file[sizeof(main_config_file) - 1] = '\x0';
/*
* If not, we assume default location for main_config_file
*/
} else {
strncpy(main_config_file, DEFAULT_CONFIG_FILE, sizeof(main_config_file));
main_config_file[sizeof(main_config_file) - 1] = '\x0';
}
}
/* if we are standalone install, we force to use cgi.cfg instead of icinga.cfg! */
if (standalone_installation == TRUE) {
strncpy(main_config_file, filename, sizeof(main_config_file));
main_config_file[sizeof(main_config_file) - 1] = '\x0';
}
return OK;
}
/* read the main configuration file */
int read_main_config_file(char *filename) {
char *input = NULL;
char *temp_buffer;
mmapfile *thefile;
if ((thefile = mmap_fopen(filename)) == NULL)
return ERROR;
/*
Icinga 2 compat layer:
when adding config lines to this function,
DON'T forget to add them to cgi.cfg.in as well
*/
while (1) {
/* free memory */
free(input);
/* read the next line */
if ((input = mmap_fgets_multiline(thefile)) == NULL)
break;
strip(input);
if (strstr(input, "resource_file=") == input) {
temp_buffer = strtok(input, "=");
temp_buffer = strtok(NULL, "\x0");
strncpy(resource_file, (temp_buffer == NULL) ? "" : temp_buffer, sizeof(resource_file));
resource_file[sizeof(resource_file) - 1] = '\x0';
strip(resource_file);
}
else if (strstr(input, "interval_length=") == input) {
temp_buffer = strtok(input, "=");
temp_buffer = strtok(NULL, "\x0");
interval_length = (temp_buffer == NULL) ? 60 : atoi(temp_buffer);
}
else if (strstr(input, "status_update_interval=") == input) {
temp_buffer = strtok(input, "=");
temp_buffer = strtok(NULL, "\x0");
status_update_interval = (temp_buffer == NULL) ? 60 : atoi(temp_buffer);
}
else if (strstr(input, "log_file=") == input) {
temp_buffer = strtok(input, "=");
temp_buffer = strtok(NULL, "\x0");
strncpy(log_file, (temp_buffer == NULL) ? "" : temp_buffer, sizeof(log_file));
log_file[sizeof(log_file) - 1] = '\x0';
strip(log_file);
}
else if (strstr(input, "log_archive_path=") == input) {
temp_buffer = strtok(input, "=");
temp_buffer = strtok(NULL, "\n");
strncpy(log_archive_path, (temp_buffer == NULL) ? "" : temp_buffer, sizeof(log_archive_path));
log_archive_path[sizeof(log_archive_path) - 1] = '\x0';
strip(physical_html_path);
if (log_archive_path[strlen(log_archive_path) - 1] != '/' && (strlen(log_archive_path) < sizeof(log_archive_path) - 1))
strcat(log_archive_path, "/");
}
else if (strstr(input, "log_rotation_method=") == input) {
temp_buffer = strtok(input, "=");
temp_buffer = strtok(NULL, "\x0");
if (temp_buffer == NULL)
log_rotation_method = LOG_ROTATION_NONE;
else if (!strcmp(temp_buffer, "h"))
log_rotation_method = LOG_ROTATION_HOURLY;
else if (!strcmp(temp_buffer, "d"))
log_rotation_method = LOG_ROTATION_DAILY;
else if (!strcmp(temp_buffer, "w"))
log_rotation_method = LOG_ROTATION_WEEKLY;
else if (!strcmp(temp_buffer, "m"))
log_rotation_method = LOG_ROTATION_MONTHLY;
}
else if (strstr(input, "command_file=") == input) {
temp_buffer = strtok(input, "=");
temp_buffer = strtok(NULL, "\x0");
strncpy(command_file, (temp_buffer == NULL) ? "" : temp_buffer, sizeof(command_file));
command_file[sizeof(command_file) - 1] = '\x0';
strip(command_file);
}
else if (strstr(input, "check_external_commands=") == input) {
temp_buffer = strtok(input, "=");
temp_buffer = strtok(NULL, "\x0");
check_external_commands = (temp_buffer == NULL) ? 0 : atoi(temp_buffer);
}
else if (strstr(input, "date_format=") == input) {
temp_buffer = strtok(input, "=");
temp_buffer = strtok(NULL, "\x0");
if (temp_buffer == NULL)
date_format = DATE_FORMAT_US;
else if (!strcmp(temp_buffer, "euro"))
date_format = DATE_FORMAT_EURO;
else if (!strcmp(temp_buffer, "iso8601"))
date_format = DATE_FORMAT_ISO8601;
else if (!strcmp(temp_buffer, "strict-iso8601"))
date_format = DATE_FORMAT_STRICT_ISO8601;
else
date_format = DATE_FORMAT_US;
}
}
/* free memory and close the file */
free(input);
mmap_fclose(thefile);
return OK;
}
/* read all object definitions */
int read_all_object_configuration_data(char *config_file, int options) {
int result = OK;
/* read in all external config data of the desired type(s) */
result = read_object_config_data(config_file, options, FALSE, FALSE);
return result;
}
/* read all status data */
int read_all_status_data(char *config_file, int options) {
int result = OK;
/* don't duplicate things we've already read in */
if (program_status_has_been_read == TRUE && (options & READ_PROGRAM_STATUS))
options -= READ_PROGRAM_STATUS;
if (host_status_has_been_read == TRUE && (options & READ_HOST_STATUS))
options -= READ_HOST_STATUS;
if (service_status_has_been_read == TRUE && (options & READ_SERVICE_STATUS))
options -= READ_SERVICE_STATUS;
/* bail out if we've already read what we need */
if (options <= 0)
return OK;
/* read in all external status data */
result = read_status_data(config_file, options);
/* mark what items we've read in... */
if (options & READ_PROGRAM_STATUS)
program_status_has_been_read = TRUE;
if (options & READ_HOST_STATUS)
host_status_has_been_read = TRUE;
if (options & READ_SERVICE_STATUS)
service_status_has_been_read = TRUE;
return result;
}
/* processes macros in resource file */
int read_icinga_resource_file(char *resource_file) {
char *input = NULL;
char *variable = NULL;
char *value = NULL;
char *temp_ptr = NULL;
mmapfile *thefile = NULL;
int error = FALSE;
int user_index = 0;
if ((thefile = mmap_fopen(resource_file)) == NULL) {
return ERROR;
}
/* process all lines in the resource file */
while (1) {
/* free memory */
my_free(input);
/* read the next line */
if ((input = mmap_fgets_multiline(thefile)) == NULL)
break;
/* skip blank lines and comments */
if (input[0] == '#' || input[0] == '\x0' || input[0] == '\n' || input[0] == '\r')
continue;
strip(input);
/* get the variable name */
if ((temp_ptr = my_strtok(input, "=")) == NULL) {
error = TRUE;
break;
}
if ((variable = (char *)strdup(temp_ptr)) == NULL) {
error = TRUE;
break;
}
/* get the value */
if ((temp_ptr = my_strtok(NULL, "\n")) == NULL) {
error = TRUE;
break;
}
if ((value = (char *)strdup(temp_ptr)) == NULL) {
error = TRUE;
break;
}
/* what should we do with the variable/value pair? */
/* check for macro declarations */
if (variable[0] == '$' && variable[strlen(variable) - 1] == '$') {
/* $USERx$ macro declarations */
if (strstr(variable, "$USER") == variable && strlen(variable) > 5) {
user_index = atoi(variable + 5) - 1;
if (user_index >= 0 && user_index < MAX_USER_MACROS) {
my_free(macro_user[user_index]);
macro_user[user_index] = (char *)strdup(value);
}
}
}
my_free(variable);
my_free(value);
}
my_free(variable);
my_free(value);
/* free leftover memory and close the file */
my_free(input);
mmap_fclose(thefile);
if (error == TRUE)
return ERROR;
return OK;
}
/**********************************************************
*************** COMMON HEADER AND FOOTER *****************
**********************************************************/
void document_header(int cgi_id, int use_stylesheet, char *cgi_title) {
char date_time[MAX_DATETIME_LENGTH];
char run_time_string[24];
char *cgi_name = NULL;
char *cgi_css = NULL;
char *cgi_body_class = NULL;
char *timezone = "";
time_t expire_time;
time_t current_time;
int result = 0;
int days = 0;
int hours = 0;
int minutes = 0;
int seconds = 0;
struct tm *tm_ptr = NULL;
switch (cgi_id) {
case STATUS_CGI_ID:
cgi_name = STATUS_CGI;
cgi_css = STATUS_CSS;
cgi_body_class = "status";
break;
case AVAIL_CGI_ID:
cgi_name = AVAIL_CGI;
cgi_css = AVAIL_CSS;
cgi_body_class = "avail";
refresh = FALSE;
break;
case CMD_CGI_ID:
cgi_name = CMD_CGI;
cgi_css = CMD_CSS;
cgi_body_class = "cmd";
refresh = FALSE;
break;
case CONFIG_CGI_ID:
cgi_name = CONFIG_CGI;
cgi_css = CONFIG_CSS;
cgi_body_class = "config";
refresh = FALSE;
break;
case EXTINFO_CGI_ID:
cgi_name = EXTINFO_CGI;
cgi_css = EXTINFO_CSS;
cgi_body_class = "extinfo";
break;
case HISTOGRAM_CGI_ID:
cgi_name = HISTOGRAM_CGI;
cgi_css = HISTOGRAM_CSS;
cgi_body_class = "histogram";
refresh = FALSE;
break;
case HISTORY_CGI_ID:
cgi_name = HISTORY_CGI;
cgi_css = HISTORY_CSS;
cgi_body_class = "history";
refresh = FALSE;
break;
case NOTIFICATIONS_CGI_ID:
cgi_name = NOTIFICATIONS_CGI;
cgi_css = NOTIFICATIONS_CSS;
cgi_body_class = "notifications";
refresh = FALSE;
break;
case OUTAGES_CGI_ID:
cgi_name = OUTAGES_CGI;
cgi_css = OUTAGES_CSS;
cgi_body_class = "outages";
break;
case SHOWLOG_CGI_ID:
cgi_name = SHOWLOG_CGI;
cgi_css = SHOWLOG_CSS;
cgi_body_class = "showlog";
refresh = FALSE;
break;
case STATUSMAP_CGI_ID:
cgi_name = STATUSMAP_CGI;
cgi_css = STATUSMAP_CSS;
cgi_body_class = "statusmap";
break;
case SUMMARY_CGI_ID:
cgi_name = SUMMARY_CGI;
cgi_css = SUMMARY_CSS;
cgi_body_class = "summary";
refresh = FALSE;
break;
case TAC_CGI_ID:
cgi_name = TAC_CGI;
cgi_css = TAC_CSS;
cgi_body_class = "tac";
if (tac_header == TRUE && show_tac_header == FALSE)
refresh = FALSE;
break;
case TRENDS_CGI_ID:
cgi_name = TRENDS_CGI;
cgi_css = TRENDS_CSS;
cgi_body_class = "trends";
refresh = FALSE;
break;
}
if (!strcmp(cgi_title, "Error"))
cgi_body_class = "error";
// don't refresh non html output
if (content_type == JSON_CONTENT || content_type == CSV_CONTENT)
refresh = FALSE;
time(¤t_time);
// send top http header
printf("Cache-Control: no-store\r\n");
printf("Pragma: no-cache\r\n");
if (refresh_type == HTTPHEADER_REFRESH && refresh == TRUE)
printf("Refresh: %d\r\n", refresh_rate);
get_time_string(¤t_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME);
printf("Last-Modified: %s\r\n", date_time);
expire_time = (time_t)0L;
get_time_string(&expire_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME);
printf("Expires: %s\r\n", date_time);
if (content_type == IMAGE_CONTENT) {
printf("Content-Type: image/png\r\n\r\n");
return;
}
if (content_type == CSV_CONTENT) {
printf("Content-type: text/plain; charset=\"%s\"\r\n\r\n", http_charset);
return;
}
if (content_type == JSON_CONTENT) {
/* read program status */
result = read_all_status_data(main_config_file, READ_PROGRAM_STATUS);
/* total running time */
if ( program_start != 0L) {
get_time_breakdown(current_time - program_start, &days, &hours, &minutes, &seconds);
sprintf(run_time_string, "%dd %dh %dm %ds", days, hours, minutes, seconds);
} else {
run_time_string[0] = '0';
run_time_string[1] = '\0';
}
tm_ptr = localtime(¤t_time);
#ifdef HAVE_TM_ZONE
timezone = (char *)tm_ptr->tm_zone;
#else
timezone = (tm_ptr->tm_isdst) ? tzname[1] : tzname[0];
#endif
printf("Content-type: text/json; charset=\"%s\"\r\n\r\n", http_charset);
printf("{ \"cgi_json_version\": \"%s\",\n", JSON_OUTPUT_VERSION);
printf("\"icinga_status\": {\n");
printf("\"status_data_age\": %lu,\n", current_time - status_file_creation_time);
printf("\"status_update_interval\": %d,\n", status_update_interval);
printf("\"reading_status_data_ok\": %s,\n", (result == ERROR && daemon_check == TRUE) ? "false" : "true");
printf("\"program_version\": \"%s\",\n", status_file_icinga_version);
printf("\"icinga_pid\": %d,\n", nagios_pid);
#ifdef USE_OLDCRUD
printf(",\"running_as_a_daemon\": %s\n", (daemon_mode == TRUE) ? "true" : "false");
#endif
printf("\"timezone\": \"%s\",\n", timezone);
if (date_format == DATE_FORMAT_EURO)
printf("\"date_format\": \"euro\",\n");
else if (date_format == DATE_FORMAT_ISO8601 || date_format == DATE_FORMAT_STRICT_ISO8601)
printf("\"date_format\": \"%siso8601\",\n", (date_format == DATE_FORMAT_STRICT_ISO8601) ? "strict-" : "");
else
printf("\"date_format\": \"us\",\n");
printf("\"program_start\": %lu,\n", program_start);
printf("\"total_running_time\": \"%s\",\n", run_time_string);
printf("\"last_external_command_check\": %lu,\n", last_command_check);
printf("\"last_log_file_rotation\": %lu,\n", last_log_rotation);
printf("\"notifications_enabled\": %s,\n", (enable_notifications == TRUE) ? "true" : "false");
printf("\"disable_notifications_expire_time\": %lu,\n", disable_notifications_expire_time);
printf("\"service_checks_being_executed\": %s,\n", (execute_service_checks == TRUE) ? "true" : "false");
printf("\"passive_service_checks_being_accepted\": %s,\n", (accept_passive_service_checks == TRUE) ? "true" : "false");
printf("\"host_checks_being_executed\": %s,\n", (execute_host_checks == TRUE) ? "true" : "false");
printf("\"passive_host_checks_being_accepted\": %s,\n", (accept_passive_host_checks == TRUE) ? "true" : "false");
printf("\"obsessing_over_services\": %s,\n", (obsess_over_services == TRUE) ? "true" : "false");
printf("\"obsessing_over_hosts\": %s,\n", (obsess_over_hosts == TRUE) ? "true" : "false");
printf("\"check_service_freshness\": %s,\n", (check_service_freshness == TRUE) ? "true" : "false");
printf("\"check_host_freshness\": %s,\n", (check_host_freshness == TRUE) ? "true" : "false");
printf("\"event_handlers_enabled\": %s,\n", (enable_event_handlers == TRUE) ? "true" : "false");
printf("\"flap_detection_enabled\": %s,\n", (enable_flap_detection == TRUE) ? "true" : "false");
printf("\"performance_data_being_processed\": %s\n", (process_performance_data == TRUE) ? "true" : "false");
#ifdef PREDICT_FAILURES
printf(",\"failure_prediction_enabled\": %s\n", (enable_failure_prediction == TRUE) ? "true" : "false");
#endif
printf("}, \n");
printf("\"%s\": {\n", cgi_body_class);
return;
}
if (content_type == XML_CONTENT) {
printf("Content-type: text/xml; charset=\"%s\"\r\n\r\n", http_charset);
printf("\n", http_charset);
return;
}
printf("Content-type: text/html; charset=\"%s\"\r\n\r\n", http_charset);
if (embedded == TRUE)
return;
if (cgi_id != STATUSMAP_CGI_ID)
printf("\n");
printf("\n");
printf("\n");
printf("\n", url_images_path);
printf("\n");
printf("\n", http_charset);
printf("%s\n", cgi_title);
// static style sheet for error messages.
if (!strcmp(cgi_title, "Error")) {
printf("\n");
}
if (cgi_id == TAC_CGI_ID && tac_header == TRUE) {
printf("\n", url_stylesheets_path, (show_tac_header == TRUE) ? TAC_HEADER_CSS : COMMON_CSS);
} else if (use_stylesheet) {
printf("\n", url_stylesheets_path, COMMON_CSS);
printf("\n", url_stylesheets_path, cgi_css);
}
/* first: jQuery JavaScript library */
printf("\n", url_js_path, JQUERY_MAIN_JS);
/* second: common functions library */
printf("\n", url_js_path, COMMON_FUNCTIONS_JS);
/* third: javascript refresh */
if (refresh_type == JAVASCRIPT_REFRESH) {
printf("\n");
printf("\n", url_js_path, PAGE_REFRESH_JS);
}
/* forth: jquery-ui libs and css */
if (cgi_id == CMD_CGI_ID || cgi_id == NOTIFICATIONS_CGI_ID || cgi_id == SHOWLOG_CGI_ID || cgi_id == HISTORY_CGI_ID || cgi_id == STATUS_CGI_ID) {
printf("\n", url_jquiryui_path, JQ_UI_CORE_JS);
printf("\n", url_jquiryui_path, JQ_UI_WIDGET_JS);
printf("\n", url_jquiryui_path, JQ_UI_ALL_CSS);
}
if (cgi_id == STATUS_CGI_ID || cgi_id == NOTIFICATIONS_CGI_ID || cgi_id == SHOWLOG_CGI_ID) {
printf("\n", url_jquiryui_path, JQ_UI_EFFECT_JS);
printf("\n", url_jquiryui_path, JQ_UI_EFFECT_BLIND_JS);
}
if (cgi_id == STATUS_CGI_ID) {
printf("\n", url_jquiryui_path, JQ_UI_BUTTON_JS);
printf("\n", url_js_path, STATUS_FILTER_JS);
}
if (cgi_id == CMD_CGI_ID || cgi_id == NOTIFICATIONS_CGI_ID || cgi_id == SHOWLOG_CGI_ID || cgi_id == HISTORY_CGI_ID ) {
printf("\n", url_jquiryui_path, JQ_UI_MOUSE_JS);
printf("\n", url_jquiryui_path, JQ_UI_SLIDER_JS);
printf("\n", url_jquiryui_path, JQ_UI_DATEPICKER_JS);
printf("\n", url_jquiryui_addon_path, JQ_UI_TIMEPICKER_JS);
printf("\n", url_jquiryui_addon_path, JQ_UI_TIMEPICKER_CSS);
printf("\n");
}
/* Add jQuery MSDropDown to sites with pagination and status.cgi */
if (cgi_id == STATUS_CGI_ID || cgi_id == EXTINFO_CGI_ID || cgi_id == CONFIG_CGI_ID || cgi_id == HISTORY_CGI_ID || cgi_id == NOTIFICATIONS_CGI_ID || cgi_id == SHOWLOG_CGI_ID) {
/* This CSS IS needed for proper dropdown menu's (bypass the use_stylesheets above, who does without anyway?) */
printf("\n", url_js_path, JQUERY_DD_JS);
printf("\n", url_stylesheets_path, JQUERY_DD_CSS);
/* functions to handle the checkboxes and dropdown menus */
printf("\n", url_js_path, CHECKBOX_FUNCTIONS_JS);
}
if (cgi_id == STATUSMAP_CGI_ID || cgi_id == TRENDS_CGI_ID) {
/* write JavaScript code for popup window */
write_popup_code(cgi_id);
}
printf("\n");
if (cgi_id == STATUSMAP_CGI_ID)
printf("\n", cgi_body_class);
else if (cgi_id == TAC_CGI_ID && tac_header == FALSE)
printf("\n", cgi_body_class);
else
printf("\n", cgi_body_class);
/* include user SSI header */
if (tac_header == FALSE)
include_ssi_files(cgi_name, SSI_HEADER);
/* this line was also in histogram.c, is this necessary??? */
if (cgi_id == HISTOGRAM_CGI_ID || cgi_id == STATUSMAP_CGI_ID || cgi_id == TRENDS_CGI_ID)
printf("\n");
if (cgi_id == STATUS_CGI_ID || cgi_id == CMD_CGI_ID || cgi_id == OUTAGES_CGI_ID) {
printf("\n\n", url_js_path, SKINNYTIP_JS);
printf("\n");
}
return;
}
void document_footer(int cgi_id) {
char *cgi_name = NULL;
switch (cgi_id) {
case STATUS_CGI_ID:
cgi_name = STATUS_CGI;
break;
case AVAIL_CGI_ID:
cgi_name = AVAIL_CGI;
break;
case CMD_CGI_ID:
cgi_name = CMD_CGI;
break;
case CONFIG_CGI_ID:
cgi_name = CONFIG_CGI;
break;
case EXTINFO_CGI_ID:
cgi_name = EXTINFO_CGI;
break;
case HISTOGRAM_CGI_ID:
cgi_name = HISTOGRAM_CGI;
break;
case HISTORY_CGI_ID:
cgi_name = HISTORY_CGI;
break;
case NOTIFICATIONS_CGI_ID:
cgi_name = NOTIFICATIONS_CGI;
break;
case OUTAGES_CGI_ID:
cgi_name = OUTAGES_CGI;
break;
case SHOWLOG_CGI_ID:
cgi_name = SHOWLOG_CGI;
break;
case STATUSMAP_CGI_ID:
cgi_name = STATUSMAP_CGI;
break;
case SUMMARY_CGI_ID:
cgi_name = SUMMARY_CGI;
break;
case TAC_CGI_ID:
cgi_name = TAC_CGI;
break;
case TRENDS_CGI_ID:
cgi_name = TRENDS_CGI;
break;
}
if (content_type == XML_CONTENT)
return;
if (content_type == JSON_CONTENT) {
printf("}\n}\n");
return;
}
/*
top is embedded, so if this is top we don't want to return
otherwise if embedded or HTML_CONTENT we do want to return
*/
if (embedded || content_type != HTML_CONTENT)
return;
/* include user SSI footer */
if (tac_header == FALSE)
include_ssi_files(cgi_name, SSI_FOOTER);
printf("\n");
printf("\n");
return;
}
/* write JavaScript code an layer for popup window */
void write_popup_code(int cgi_id) {
char *border_color = "#000000";
char *background_color = "#ffffcc";
int border = 1;
int padding = 3;
int x_offset = 3;
int y_offset = 3;
printf("\n");
return;
}
/**********************************************************
*************** MISC UTILITY FUNCTIONS *******************
**********************************************************/
/* unescapes newlines in a string */
char *unescape_newlines(char *rawbuf) {
register int x, y;
for (x = 0, y = 0; rawbuf[x] != (char)'\x0'; x++) {
if (rawbuf[x] == '\\') {
/* unescape newlines */
if (rawbuf[x + 1] == 'n') {
rawbuf[y++] = '\n';
x++;
}
/* unescape backslashes and other stuff */
if (rawbuf[x + 1] != '\x0') {
rawbuf[y++] = rawbuf[x + 1];
x++;
}
} else
rawbuf[y++] = rawbuf[x];
}
rawbuf[y] = '\x0';
return rawbuf;
}
/* escapes newlines in a string */
char *escape_newlines(char *rawbuf) {
char *newbuf = NULL;
register int x, y;
if (rawbuf == NULL)
return NULL;
/* allocate enough memory to escape all chars if necessary */
if ((newbuf = malloc((strlen(rawbuf) * 2) + 1)) == NULL)
return NULL;
for (x = 0, y = 0; rawbuf[x] != (char)'\x0'; x++) {
/* escape backslashes */
if (rawbuf[x] == '\\') {
newbuf[y++] = '\\';
newbuf[y++] = '\\';
}
/* escape newlines */
else if (rawbuf[x] == '\n') {
newbuf[y++] = '\\';
newbuf[y++] = 'n';
}
else
newbuf[y++] = rawbuf[x];
}
newbuf[y] = '\x0';
return newbuf;
}
/* strips HTML and bad stuff from plugin output */
void sanitize_plugin_output(char *buffer) {
int x = 0;
int y = 0;
int in_html = FALSE;
char *new_buffer;
if (buffer == NULL)
return;
new_buffer = strdup(buffer);
if (new_buffer == NULL)
return;
/* check each character */
for (x = 0, y = 0; buffer[x] != '\x0'; x++) {
/* we just started an HTML tag */
if (buffer[x] == '<') {
in_html = TRUE;
continue;
}
/* end of an HTML tag */
else if (buffer[x] == '>') {
in_html = FALSE;
continue;
}
/* skip everything inside HTML tags */
else if (in_html == TRUE)
continue;
/* strip single and double quotes */
else if (buffer[x] == '\'' || buffer[x] == '\"')
new_buffer[y++] = ' ';
/* strip semicolons (replace with colons) */
else if (buffer[x] == ';')
new_buffer[y++] = ':';
/* strip pipe and ampersand */
else if (buffer[x] == '&' || buffer[x] == '|')
new_buffer[y++] = ' ';
/* normal character */
else
new_buffer[y++] = buffer[x];
}
/* terminate sanitized buffer */
new_buffer[y++] = '\x0';
/* copy the sanitized buffer back to the original */
strcpy(buffer, new_buffer);
/* free memory allocated to the new buffer */
free(new_buffer);
return;
}
/* get date/time string */
void get_time_string(time_t *raw_time, char *buffer, int buffer_length, int type) {
time_t t;
struct tm *tm_ptr = NULL;
int hour = 0;
int minute = 0;
int second = 0;
int month = 0;
int day = 0;
int year = 0;
char *weekdays[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
char *tzone = "";
if (raw_time == NULL)
time(&t);
else
t = *raw_time;
if (type == HTTP_DATE_TIME)
tm_ptr = gmtime(&t);
else
tm_ptr = localtime(&t);
hour = tm_ptr->tm_hour;
minute = tm_ptr->tm_min;
second = tm_ptr->tm_sec;
month = tm_ptr->tm_mon + 1;
day = tm_ptr->tm_mday;
year = tm_ptr->tm_year + 1900;
#ifdef HAVE_TM_ZONE
tzone = (char *)tm_ptr->tm_zone;
#else
tzone = (tm_ptr->tm_isdst) ? tzname[1] : tzname[0];
#endif
/* ctime() style */
if (type == LONG_DATE_TIME)
snprintf(buffer, buffer_length, "%s %s %d %02d:%02d:%02d %s %d", weekdays[tm_ptr->tm_wday], months[tm_ptr->tm_mon], day, hour, minute, second, tzone, year);
/* short style */
else if (type == SHORT_DATE_TIME) {
if (date_format == DATE_FORMAT_EURO)
snprintf(buffer, buffer_length, "%02d-%02d-%04d %02d:%02d:%02d", tm_ptr->tm_mday, tm_ptr->tm_mon + 1, tm_ptr->tm_year + 1900, tm_ptr->tm_hour, tm_ptr->tm_min, tm_ptr->tm_sec);
else if (date_format == DATE_FORMAT_ISO8601 || date_format == DATE_FORMAT_STRICT_ISO8601)
snprintf(buffer, buffer_length, "%04d-%02d-%02d%c%02d:%02d:%02d", tm_ptr->tm_year + 1900, tm_ptr->tm_mon + 1, tm_ptr->tm_mday, (date_format == DATE_FORMAT_STRICT_ISO8601) ? 'T' : ' ', tm_ptr->tm_hour, tm_ptr->tm_min, tm_ptr->tm_sec);
else
snprintf(buffer, buffer_length, "%02d-%02d-%04d %02d:%02d:%02d", tm_ptr->tm_mon + 1, tm_ptr->tm_mday, tm_ptr->tm_year + 1900, tm_ptr->tm_hour, tm_ptr->tm_min, tm_ptr->tm_sec);
}
/* short date */
else if (type == SHORT_DATE) {
if (date_format == DATE_FORMAT_EURO)
snprintf(buffer, buffer_length, "%02d-%02d-%04d", day, month, year);
else if (date_format == DATE_FORMAT_ISO8601 || date_format == DATE_FORMAT_STRICT_ISO8601)
snprintf(buffer, buffer_length, "%04d-%02d-%02d", year, month, day);
else
snprintf(buffer, buffer_length, "%02d-%02d-%04d", month, day, year);
}
/* expiration date/time for HTTP headers */
else if (type == HTTP_DATE_TIME)
snprintf(buffer, buffer_length, "%s, %02d %s %d %02d:%02d:%02d GMT", weekdays[tm_ptr->tm_wday], day, months[tm_ptr->tm_mon], year, hour, minute, second);
/* short time */
else
snprintf(buffer, buffer_length, "%02d:%02d:%02d", hour, minute, second);
buffer[buffer_length - 1] = '\x0';
return;
}
/* get time string for an interval of time */
void get_interval_time_string(double time_units, char *buffer, int buffer_length) {
unsigned long total_seconds;
int hours = 0;
int minutes = 0;
int seconds = 0;
total_seconds = (unsigned long)(time_units * interval_length);
hours = (int)total_seconds / 3600;
total_seconds %= 3600;
minutes = (int)total_seconds / 60;
total_seconds %= 60;
seconds = (int)total_seconds;
snprintf(buffer, buffer_length, "%dh %dm %ds", hours, minutes, seconds);
buffer[buffer_length - 1] = '\x0';
return;
}
/* encodes a string in proper URL format */
char * url_encode(char *input) {
int len, output_len;
int x, y;
char temp_expansion[4];
static int num_encoded_url = 0;
char* str = encoded_url_string[num_encoded_url];
/* initialize return string */
strcpy(str, "");
if (input == NULL)
return str;
len = (int)strlen(input);
output_len = (int)sizeof(encoded_url_string[num_encoded_url]);
str[0] = '\x0';
for (x = 0, y = 0; x <= len && y < output_len - 1; x++) {
/* end of string */
if ((char)input[x] == (char)'\x0') {
str[y] = '\x0';
break;
}
/* alpha-numeric characters and a few other characters don't get encoded */
else if (((char)input[x] >= '0' && (char)input[x] <= '9') || ((char)input[x] >= 'A' && (char)input[x] <= 'Z') || ((char)input[x] >= (char)'a' && (char)input[x] <= (char)'z') || (char)input[x] == (char)'.' || (char)input[x] == (char)'-' || (char)input[x] == (char)'_') {
str[y] = input[x];
y++;
}
/* high bit characters don't get encoded */
else if ((unsigned char)input[x] >= 0x7f) {
str[y] = input[x];
y++;
}
/* spaces are pluses */
else if ((char)input[x] == (char)' ') {
str[y] = '+';
y++;
}
/* anything else gets represented by its hex value */
else {
str[y] = '\x0';
if ((int)strlen(str) < (output_len - 3)) {
sprintf(temp_expansion, "%%%02X", (unsigned int)input[x]);
strcat(str, temp_expansion);
y += 3;
}
}
}
str[ sizeof(encoded_url_string[num_encoded_url]) - 1] = '\x0';
if (num_encoded_url >= 3)
num_encoded_url = 0;
else
num_encoded_url++;
return str;
}
/* escapes a string used in HTML */
char * html_encode(char *input, int escape_newlines) {
int len, output_len;
int x, y;
char temp_expansion[10];
static int num_encoded_html = 0;
char* str = encoded_html_string[num_encoded_html];
/* initialize return string */
strcpy(str, "");
if (input == NULL)
return str;
len = (int)strlen(input);
output_len = (int)sizeof(encoded_html_string[num_encoded_html]);
str[0] = '\x0';
for (x = 0, y = 0; x <= len && y < output_len - 1; x++) {
/* end of string */
if ((char)input[x] == (char)'\x0') {
str[y] = '\x0';
break;
}
/* alpha-numeric characters and spaces don't get encoded */
else if (((char)input[x] == (char)' ') || ((char)input[x] >= '0' && (char)input[x] <= '9') || ((char)input[x] >= 'A' && (char)input[x] <= 'Z') || ((char)input[x] >= (char)'a' && (char)input[x] <= (char)'z'))
str[y++] = input[x];
/* newlines turn to tags */
else if (escape_newlines == TRUE && (char)input[x] == (char)'\n') {
strcpy(&str[y], " ");
y += 4;
} else if (escape_newlines == TRUE && (char)input[x] == (char)'\\' && (char)input[x + 1] == (char)'n') {
strcpy(&str[y], " ");
y += 4;
x++;
}
/* TODO - strip all but allowed HTML tags out... */
else if ((char)input[x] == (char)'<') {
if (escape_html_tags == FALSE)
str[y++] = input[x];
else {
str[y] = '\x0';
if ((int)strlen(str) < (output_len - 4)) {
strcat(str, "<");
y += 4;
}
}
}
else if ((char)input[x] == (char)'>') {
if (escape_html_tags == FALSE)
str[y++] = input[x];
else {
str[y] = '\x0';
if ((int)strlen(str) < (output_len - 4)) {
strcat(str, ">");
y += 4;
}
}
}
/* high bit chars don't get encoded, so we won't be breaking utf8 characters */
else if ((unsigned char)input[x] >= 0x7f)
str[y++] = input[x];
/* for simplicity, all other chars represented by their numeric value */
else {
if (escape_html_tags == FALSE)
str[y++] = input[x];
else {
str[y] = '\x0';
sprintf(temp_expansion, "%d;", (unsigned char)input[x]);
if ((int)strlen(str) < (output_len - strlen(temp_expansion))) {
strcat(str, temp_expansion);
y += strlen(temp_expansion);
}
}
}
}
str[y++] = '\x0';
num_encoded_html = (num_encoded_html == 0) ? 1 : 0;
return str;
}
/* strip > and < from string */
void strip_html_brackets(char *buffer) {
register int x;
register int y;
register int z;
if (buffer == NULL || buffer[0] == '\x0')
return;
/* remove all occurances in string */
z = (int)strlen(buffer);
for (x = 0, y = 0; x < z; x++) {
if (buffer[x] == '<' || buffer[x] == '>')
continue;
buffer[y++] = buffer[x];
}
buffer[y++] = '\x0';
return;
}
/* escape string for html form usage */
char * escape_string(char *input) {
int len, output_len;
int x, y;
char temp_expansion[10];
static int num_encoded_html = 0;
char* str = encoded_html_string[num_encoded_html];
/* initialize return string */
strcpy(str, "");
if (input == NULL)
return str;
len = (int)strlen(input);
output_len = (int)sizeof(encoded_html_string[num_encoded_html]);
str[0] = '\x0';
for (x = 0, y = 0; x <= len && y < output_len - 1; x++) {
/* end of string */
if ((char)input[x] == (char)'\x0') {
str[y] = '\x0';
break;
}
/* alpha-numeric characters don't get encoded */
else if (((char)input[x] >= '0' && (char)input[x] <= '9') || ((char)input[x] >= 'A' && (char)input[x] <= 'Z') || ((char)input[x] >= (char)'a' && (char)input[x] <= (char)'z'))
str[y++] = input[x];
/* spaces, hyphens, periods, underscores and colons don't get encoded */
else if (((char)input[x] == (char)' ') || ((char)input[x] == (char)'-') || ((char)input[x] == (char)'.') || ((char)input[x] == (char)'_') || ((char)input[x] == (char)':'))
str[y++] = input[x];
/* high bit characters don't get encoded */
else if ((unsigned char)input[x] >= 0x7f)
str[y++] = input[x];
/* for simplicity, all other chars represented by their numeric value */
else {
str[y] = '\x0';
sprintf(temp_expansion, "%d;", (unsigned char)input[x]);
if ((int)strlen(str) < (output_len - strlen(temp_expansion))) {
strcat(str, temp_expansion);
y += strlen(temp_expansion);
}
}
}
str[y++] = '\x0';
num_encoded_html = (num_encoded_html == 0) ? 1 : 0;
return str;
}
/**********************************************************
*************** COMMON HTML FUNCTIONS ********************
**********************************************************/
void display_info_table(char *title, authdata *current_authdata, int daemon_check) {
char date_time[MAX_DATETIME_LENGTH];
char disable_notif_expire_time[MAX_DATETIME_LENGTH];
char *dir_to_check = NULL;
time_t current_time;
int result;
int x, last = 0;
/* read program status */
result = read_all_status_data(main_config_file, READ_PROGRAM_STATUS);
printf("
\n");
printf("
\n");
printf("
%s
\n", title);
time(¤t_time);
get_time_string(¤t_time, date_time, (int)sizeof(date_time), LONG_DATE_TIME);
/* disabled notifications expire time */
get_time_string(&disable_notifications_expire_time, disable_notif_expire_time, (int)sizeof(disable_notif_expire_time), SHORT_DATE_TIME);
printf("Last Updated: %s ", date_time);
/* display only if refresh is supported */
if (CGI_ID == EXTINFO_CGI_ID || CGI_ID == OUTAGES_CGI_ID || CGI_ID == STATUS_CGI_ID || CGI_ID == STATUSMAP_CGI_ID || CGI_ID == TAC_CGI_ID) {
if (CGI_ID == STATUS_CGI_ID && display_status_totals == TRUE)
printf(" ");
else
printf("- ");
if (refresh_type == JAVASCRIPT_REFRESH)
printf("Refresh done......\n", url_images_path, RELOAD_ICON);
else
printf("Update every %d seconds\n", refresh_rate);
}
printf(" %s Classic UI %s (Backend %s) -\n", PROGRAM_NAME, PROGRAM_VERSION, status_file_icinga_version);
if (current_authdata != NULL)
printf("Logged in as %s\n", (!strcmp(current_authdata->username, "")) ? "?" : current_authdata->username);
/* add here every cgi_id which uses logging, this should limit the testing of write access to the necessary amount */
if (use_logging == TRUE && CGI_ID == CMD_CGI_ID) {
asprintf(&dir_to_check, "%s", cgi_log_file);
for (x = 0; x <= (int)strlen(dir_to_check); x++) {
/* end of string */
if ((char)dir_to_check[x] == (char)'\x0') {
break;
}
if ((char)dir_to_check[x] == '/')
last = x;
}
dir_to_check[last] = '\x0';
if (!strcmp(cgi_log_file, "")) {
printf("
Warning: Logging is activated but no logfile is configured
");
} else {
if (access(dir_to_check, W_OK) != 0)
printf("
Warning: No permission to write logfile to %s
", dir_to_check);
}
if (cgi_log_rotation_method != LOG_ROTATION_NONE) {
if (!strcmp(cgi_log_archive_path, ""))
printf("
Warning: Log rotation is configured but option \"cgi_log_archive_path\" isn't
");
else {
if (access(cgi_log_archive_path, W_OK) != 0)
printf("
Warning: No permission to write to \"cgi_log_archive_path\": %s
\n");
printf("\n");
return;
}
/* prints the additional notes or action url for a hostgroup (with macros substituted) */
void print_extra_hostgroup_url(char *group_name, char *url) {
char input_buffer[MAX_INPUT_BUFFER] = "";
char output_buffer[MAX_INPUT_BUFFER] = "";
char *temp_buffer;
int in_macro = FALSE;
hostgroup *temp_hostgroup = NULL;
if (group_name == NULL || url == NULL)
return;
temp_hostgroup = find_hostgroup(group_name);
if (temp_hostgroup == NULL) {
printf("%s", url);
return;
}
strncpy(input_buffer, url, sizeof(input_buffer) - 1);
input_buffer[sizeof(input_buffer) - 1] = '\x0';
for (temp_buffer = my_strtok(input_buffer, "$"); temp_buffer != NULL; temp_buffer = my_strtok(NULL, "$")) {
if (in_macro == FALSE) {
if (strlen(output_buffer) + strlen(temp_buffer) < sizeof(output_buffer) - 1) {
strncat(output_buffer, temp_buffer, sizeof(output_buffer) - strlen(output_buffer) - 1);
output_buffer[sizeof(output_buffer) - 1] = '\x0';
}
in_macro = TRUE;
} else {
if (strlen(output_buffer) + strlen(temp_buffer) < sizeof(output_buffer) - 1) {
if (!strcmp(temp_buffer, "HOSTGROUPNAME"))
strncat(output_buffer, url_encode(temp_hostgroup->group_name), sizeof(output_buffer) - strlen(output_buffer) - 1);
}
in_macro = FALSE;
}
}
printf("%s", output_buffer);
return;
}
/* prints the additional notes or action url for a servicegroup (with macros substituted) */
void print_extra_servicegroup_url(char *group_name, char *url) {
char input_buffer[MAX_INPUT_BUFFER] = "";
char output_buffer[MAX_INPUT_BUFFER] = "";
char *temp_buffer;
int in_macro = FALSE;
servicegroup *temp_servicegroup = NULL;
if (group_name == NULL || url == NULL)
return;
temp_servicegroup = find_servicegroup(group_name);
if (temp_servicegroup == NULL) {
printf("%s", url);
return;
}
strncpy(input_buffer, url, sizeof(input_buffer) - 1);
input_buffer[sizeof(input_buffer) - 1] = '\x0';
for (temp_buffer = my_strtok(input_buffer, "$"); temp_buffer != NULL; temp_buffer = my_strtok(NULL, "$")) {
if (in_macro == FALSE) {
if (strlen(output_buffer) + strlen(temp_buffer) < sizeof(output_buffer) - 1) {
strncat(output_buffer, temp_buffer, sizeof(output_buffer) - strlen(output_buffer) - 1);
output_buffer[sizeof(output_buffer) - 1] = '\x0';
}
in_macro = TRUE;
} else {
if (strlen(output_buffer) + strlen(temp_buffer) < sizeof(output_buffer) - 1) {
if (!strcmp(temp_buffer, "SERVICEGROUPNAME"))
strncat(output_buffer, url_encode(temp_servicegroup->group_name), sizeof(output_buffer) - strlen(output_buffer) - 1);
}
in_macro = FALSE;
}
}
printf("%s", output_buffer);
return;
}
/* include user-defined SSI footers or headers */
void include_ssi_files(char *cgi_name, int type) {
char common_ssi_file[MAX_INPUT_BUFFER];
char cgi_ssi_file[MAX_INPUT_BUFFER];
char raw_cgi_name[MAX_INPUT_BUFFER];
char *stripped_cgi_name;
/* common header or footer */
snprintf(common_ssi_file, sizeof(common_ssi_file) - 1, "%scommon-%s.ssi", physical_ssi_path, (type == SSI_HEADER) ? "header" : "footer");
common_ssi_file[sizeof(common_ssi_file) - 1] = '\x0';
/* CGI-specific header or footer */
strncpy(raw_cgi_name, cgi_name, sizeof(raw_cgi_name) - 1);
raw_cgi_name[sizeof(raw_cgi_name) - 1] = '\x0';
stripped_cgi_name = strtok(raw_cgi_name, ".");
snprintf(cgi_ssi_file, sizeof(cgi_ssi_file) - 1, "%s%s-%s.ssi", physical_ssi_path, (stripped_cgi_name == NULL) ? "" : stripped_cgi_name, (type == SSI_HEADER) ? "header" : "footer");
cgi_ssi_file[sizeof(cgi_ssi_file) - 1] = '\x0';
if (type == SSI_HEADER) {
printf("\n\n", PROGRAM_NAME, PROGRAM_NAME_LC);
include_ssi_file(common_ssi_file);
include_ssi_file(cgi_ssi_file);
} else {
include_ssi_file(cgi_ssi_file);
include_ssi_file(common_ssi_file);
printf("\n\n", PROGRAM_NAME, PROGRAM_NAME_LC);
}
return;
}
/* include user-defined SSI footer or header */
void include_ssi_file(char *filename) {
char buffer[MAX_INPUT_BUFFER];
FILE *fp;
struct stat stat_result;
int call_return;
/* if file is executable, we want to run it rather than print it */
call_return = stat(filename, &stat_result);
/* file is executable */
if (call_return == 0 && (stat_result.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) {
/* must flush output stream first so that output
from script shows up in correct place. Other choice
is to open program under pipe and copy the data from
the program to our output stream.
*/
fflush(stdout);
/* ignore return status from system call. */
call_return = system(filename);
return;
}
/* an error occurred trying to stat() the file */
else if (call_return != 0) {
/* Handle error conditions. Assume that standard posix error codes and errno are available. If not, comment this section out. */
switch (errno) {
case ENOTDIR: /* - A component of the path is not a directory. */
case ELOOP: /* Too many symbolic links encountered while traversing the path. */
case EFAULT: /* Bad address. */
case ENOMEM: /* Out of memory (i.e. kernel memory). */
case ENAMETOOLONG: /* File name too long. */
printf(" A stat call returned %d while looking for the file %s. ", errno, filename);
return;
case EACCES: /* Permission denied. -- The file should be accessible by nagios. */
printf(" A stat call returned a permissions error(%d) while looking for the file %s. ", errno, filename);
return;
case ENOENT: /* A component of the path file_name does not exist, or the path is an empty string. Just return if the file doesn't exist. */
return;
default:
return;
}
}
fp = fopen(filename, "r");
if (fp == NULL)
return;
/* print all lines in the SSI file */
while (fgets(buffer, (int)(sizeof(buffer) - 1), fp) != NULL)
printf("%s", buffer);
fclose(fp);
return;
}
/* displays an error if CGI config file could not be read */
void cgi_config_file_error(char *config_file, int tac_header) {
if (content_type == CSV_CONTENT) {
printf("Error: Could not open CGI config file '%s' for reading!\n", config_file);
return;
}
if (content_type == JSON_CONTENT) {
printf("\"title\": \"Could not open CGI config file '%s' for reading!\"\n,", config_file);
printf("\"text\": \"");
printf("Make sure you've installed a CGI config file in its proper location. A sample CGI configuration file (named cgi.cfg) can be found in the 'sample-config' subdirectory of the %s source code distribution. ", PROGRAM_NAME);
printf("Also make sure the user your web server is running as has permission to read the CGI config file.");
printf("\"\n");
return;
}
if (tac_header == TRUE) {
printf("
Error: Could not open CGI config file '%s' for reading!
\n", config_file);
return;
}
printf("
Whoops!
\n");
printf("
Error: Could not open CGI config file '%s' for reading!
\n", config_file);
printf("
\n");
printf("Here are some things you should check in order to resolve this error:\n");
printf("
\n");
printf("\n");
printf("
Make sure you've installed a CGI config file in its proper location. A sample CGI configuration file (named cgi.cfg) can be found in the sample-config/ subdirectory of the %s source code distribution.\n", PROGRAM_NAME);
printf("
Make sure the user your web server is running as has permission to read the CGI config file.\n");
printf("
\n");
printf("
\n");
printf("Make sure you read the documentation on installing and configuring %s thoroughly before continuing. If everything else fails, try sending a message to one of the mailing lists. More information can be found at http://www.icinga.org.\n", PROGRAM_NAME);
printf("
\n");
return;
}
/* displays an error if main config file could not be read */
void main_config_file_error(char *config_file, int tac_header) {
if (content_type == CSV_CONTENT) {
printf("Error: Could not open main config file '%s' for reading!\n", config_file);
return;
}
if (content_type == JSON_CONTENT) {
printf("\"title\": \"Could not open main config file '%s' for reading!\"\n,", config_file);
printf("\"text\": \"");
printf("Make sure you've installed a main config file in its proper location. A sample main configuration file (named icinga.cfg) can be found in the 'sample-config' subdirectory of the %s source code distribution. ", PROGRAM_NAME);
printf("Also make sure the user your web server is running as has permission to read the main config file.");
printf("\"\n");
return;
}
if (tac_header == TRUE) {
printf("
Error: Could not open main config file '%s' for reading!
\n", config_file);
return;
}
printf("
Whoops!
\n");
printf("
Error: Could not open main config file '%s' for reading!
\n", config_file);
printf("
\n");
printf("Here are some things you should check in order to resolve this error:\n");
printf("
\n");
printf("\n");
printf("
Make sure you've installed a main config file in its proper location. A sample main configuration file (named icinga.cfg) can be found in the sample-config/ subdirectory of the %s source code distribution.\n", PROGRAM_NAME);
printf("
Make sure the user your web server has permission to read the main config file.\n");
printf("
\n");
printf("
\n");
printf("Make sure you read the documentation on installing and configuring %s thoroughly before continuing. If everything else fails, try sending a message to one of the mailing lists. More information can be found at http://www.icinga.org.\n", PROGRAM_NAME);
printf("
\n");
return;
}
/* displays an error if object data could not be read */
void object_data_error(int tac_header) {
if (content_type == CSV_CONTENT) {
printf("Error: Could not read object configuration data!\n");
return;
}
if (content_type == JSON_CONTENT) {
printf("\"title\": \"Could not read object configuration data!\"\n,");
printf("\"text\": \"");
printf("Verify configuration options using the '-v' command-line option to check for errors. ");
printf("Check the %s log file for messages relating to startup or status data errors.", PROGRAM_NAME);
printf("\"\n");
return;
}
if (tac_header == TRUE) {
printf("
Error: Could not read object configuration data!
\n");
return;
}
printf("
Whoops!
\n");
printf("
Error: Could not read object configuration data!
\n");
printf("
\n");
printf("Here are some things you should check in order to resolve this error:\n");
printf("
\n");
printf("\n");
printf("
Verify configuration options using the -v command-line option to check for errors.\n");
printf("
Check the %s log file for messages relating to startup or status data errors.\n", PROGRAM_NAME);
printf("
\n");
printf("
\n");
printf("Make sure you read the documentation on installing, configuring and running %s thoroughly before continuing. If everything else fails, try sending a message to one of the mailing lists. More information can be found at http://www.icinga.org.\n", PROGRAM_NAME);
printf("
\n");
return;
}
/* displays an error if status data could not be read */
void status_data_error(int tac_header) {
if (content_type == CSV_CONTENT) {
printf("Error: Could not read host and service status information!\n");
return;
}
if (content_type == JSON_CONTENT) {
printf("\"title\": \"Could not read host and service status information!\"\n,");
printf("\"text\": \"");
printf("It seems that %s is not running or has not yet finished the startup procedure and then creating the status data file. If %s is indeed not running, this is a normal error message. ", PROGRAM_NAME, PROGRAM_NAME);
printf("Please note that event broker modules and/or rdbms backends may slow down the overall (re)start and the cgis cannot retrieve any status information.");
printf("\"\n");
return;
}
if (tac_header == TRUE) {
printf("
Error: Could not read host and service status information!
\n");
return;
}
printf("
Whoops!
\n");
printf("
Error: Could not read host and service status information!
\n");
printf("
\n");
printf("It seems that %s is not running or has not yet finished the startup procedure and then creating the status data file. If %s is indeed not running, this is a normal error message.\n", PROGRAM_NAME, PROGRAM_NAME);
printf("Please note that event broker modules and/or rdbms backends may slow down the overall (re)start and the cgis cannot retrieve any status information.");
printf("
\n");
printf("
\n");
printf("Things to check in order to resolve this error include:\n");
printf("
\n");
printf("\n");
printf("
Check the %s log file for messages relating to startup or status data errors.\n", PROGRAM_NAME);
printf("
Always verify configuration options using the -v command-line option before starting or restarting %s!\n", PROGRAM_NAME);
printf("
If using any event broker module for %s, look into their respective logs and/or on their behavior!\n", PROGRAM_NAME);
printf("
\n");
printf("
\n");
printf("Make sure you read the documentation on installing, configuring and running %s thoroughly before continuing. If everything else fails, try sending a message to one of the mailing lists. More information can be found at http://www.icinga.org.\n", PROGRAM_NAME);
printf("
\n");
return;
}
/** print an error depending on error_type */
void print_error(char *config_file, int error_type, int tac_header) {
/* Giving credits to stop.png image source */
if (content_type == HTML_CONTENT) {
if (tac_header == TRUE) {
printf("
\n");
printf("
");
printf("
");
} else {
printf("\n\n\n");
printf("
\n");
printf("
");
if (error_type != ERROR_CGI_CFG_FILE)
printf("", url_images_path, CMD_STOP_ICON);
printf("
");
}
}
switch (error_type) {
case ERROR_CGI_STATUS_DATA:
status_data_error(tac_header);
break;
case ERROR_CGI_OBJECT_DATA:
object_data_error(tac_header);
break;
case ERROR_CGI_CFG_FILE:
cgi_config_file_error(config_file, tac_header);
break;
case ERROR_CGI_MAIN_CFG:
main_config_file_error(config_file, tac_header);
break;
}
if (content_type == HTML_CONTENT) {
printf("
\n");
printf("
\n");
}
return;
}
void display_splunk_host_url(host *hst) {
if (enable_splunk_integration == FALSE)
return;
if (hst == NULL)
return;
printf("\n", splunk_url, url_encode(hst->name), url_images_path, SPLUNK_SMALL_WHITE_ICON);
return;
}
void display_splunk_service_url(service *svc) {
if (enable_splunk_integration == FALSE)
return;
if (svc == NULL)
return;
printf("\n", url_encode(svc->description), url_images_path, SPLUNK_SMALL_WHITE_ICON);
return;
}
void display_splunk_generic_url(char *buf, int icon) {
char *newbuf = NULL;
if (enable_splunk_integration == FALSE)
return;
if (buf == NULL)
return;
if ((newbuf = (char *)strdup(buf)) == NULL)
return;
strip_splunk_query_terms(newbuf);
printf("", splunk_url, url_encode(newbuf));
if (icon > 0)
printf("", url_images_path, (icon == 1) ? SPLUNK_SMALL_WHITE_ICON : SPLUNK_SMALL_BLACK_ICON);
printf("\n");
free(newbuf);
return;
}
/* strip quotes and from string */
void strip_splunk_query_terms(char *buffer) {
register int x;
register int y;
register int z;
if (buffer == NULL || buffer[0] == '\x0')
return;
/* remove all occurances in string */
z = (int)strlen(buffer);
for (x = 0, y = 0; x < z; x++) {
if (buffer[x] == '\'' || buffer[x] == '\"' || buffer[x] == ';' || buffer[x] == ':' || buffer[x] == ',' || buffer[x] == '-' || buffer[x] == '=')
buffer[y++] = ' ';
else
buffer[y++] = buffer[x];
}
buffer[y++] = '\x0';
return;
}
void print_generic_error_message(char *title, char *text, int returnlevels) {
if (content_type == CSV_CONTENT) {
if (title != NULL && title[0] != '\x0')
printf("ERROR: %s\n", title);
if (text != NULL && text[0] != '\x0')
printf("ERROR: %s\n", text);
} else if (content_type == JSON_CONTENT) {
printf("\"error\": {\n\"title\": ");
if (title != NULL && title[0] != '\x0')
printf("\"%s\",\n", title);
else
printf("null,\n");
printf("\"text\": ");
if (text != NULL && text[0] != '\x0')
printf("\"%s\"\n}", text);
else
printf("null\n}");
} else {
printf("
\n");
if (returnlevels != 0)
printf(" \n", returnlevels);
printf("
\n");
}
return;
}
/** @brief prints export link with little icons
* @param [in] content_type can be \c CSV_CONTENT , \c JSON_CONTENT , \c XML_CONTENT or \c HTML_CONTENT
* @param [in] cgi name of cgi as defined in include/cgiutils.h
* @param [in] add_to_url is additional string to add to url (set to NULL if nothing should be added)
* @note takes care that each link is XSS save #1275
*
* This function prints a little icon, depending on @ref content_type, which points to
* a new page with the desired content.
**/
void print_export_link(int content_type, char *cgi, char *add_to_url) {
char stripped_query_string[MAX_INPUT_BUFFER] = "";
char link[MAX_INPUT_BUFFER] = "";
if (cgi == NULL)
return;
strcat(link, cgi);
/* just do stuff if some options are requested */
if (getenv("QUERY_STRING") != NULL && strcmp(getenv("QUERY_STRING"), "")) {
if(strlen(getenv("QUERY_STRING")) > MAX_INPUT_BUFFER) {
write_to_cgi_log("print_export_link(): Query string exceeds max length. Returning without displaying export link.\n");
return;
}
strcpy(stripped_query_string, getenv("QUERY_STRING"));
strip_html_brackets(stripped_query_string);
/* check if concatenated strings exceed MAX_INPUT_BUFFER */
if (strlen(link) + strlen(stripped_query_string) + 2 > MAX_INPUT_BUFFER) {
write_to_cgi_log("print_export_link(): Full query string exceeds max length. Returning without displaying export link.\n");
return;
}
strcat(link, "?");
strcat(link, stripped_query_string);
}
/* add string to url */
if (add_to_url != NULL && strlen(add_to_url) != 0 && strlen(link) + strlen(stripped_query_string) + strlen(add_to_url) + 2 <= MAX_INPUT_BUFFER) {
if (strlen(stripped_query_string) != 0)
strcat(link, "&");
else
strcat(link, "?");
strcat(link, add_to_url);
}
/* print formatted link */
if (content_type == CSV_CONTENT)
printf("\n", link, (strlen(stripped_query_string) != 0) ? "&" : "?", url_images_path, EXPORT_CSV_ICON, EXPORT_CSV_ICON_ALT, EXPORT_CSV_ICON_ALT);
else if (content_type == JSON_CONTENT)
printf("\n", link, (strlen(stripped_query_string) != 0) ? "&" : "?", url_images_path, EXPORT_JSON_ICON, EXPORT_JSON_ICON_ALT, EXPORT_JSON_ICON_ALT);
else if (content_type == XML_CONTENT)
printf("\n", link, (strlen(stripped_query_string) != 0) ? "&" : "?", url_images_path, EXPORT_XML_ICON, EXPORT_XML_ICON_ALT, EXPORT_XML_ICON_ALT);
else
printf("\n", link, url_images_path, EXPORT_LINK_ICON, EXPORT_LINK_ICON_ALT, EXPORT_LINK_ICON_ALT);
return;
}
/**
* Logging and file functions
**/
int write_to_cgi_log(char *buffer) {
FILE *fp;
time_t log_time;
int write_retries = 10, i = 0;
/* we don't do anything if logging is deactivated or no logfile configured */
if (use_logging == FALSE || !strcmp(cgi_log_file, ""))
return OK;
time(&log_time);
// always check if log file has to be rotated
rotate_cgi_log_file();
// open log file and try again if failed
while ((fp = fopen(cgi_log_file, "a+")) == NULL && i < write_retries) {
usleep(10);
i++;
}
if (i >= write_retries)
return ERROR;
/* verify that fp is really opened */
if (fp == NULL)
return ERROR;
/* strip any newlines from the end of the buffer */
strip(buffer);
/* write the buffer to the log file */
fprintf(fp, "[%lu] %s\n", log_time, buffer);
fclose(fp);
return OK;
}
/* rotates the cgi log file */
int rotate_cgi_log_file() {
char temp_buffer[MAX_INPUT_BUFFER] = "";
char method_string[16] = "";
char *log_archive = NULL;
struct tm *ts;
int rename_result = 0;
int stat_result = -1;
struct stat log_file_stat;
int sub = 0, weekday;
time_t current_time, rotate_ts;
/* if there is no log arhive configured we don't do anything */
if (!strcmp(cgi_log_archive_path, ""))
return ERROR;
/* get the current time */
time(¤t_time);
ts = localtime(¤t_time);
ts->tm_sec = 0;
ts->tm_min = 0;
ts->tm_isdst = -1;
weekday = ts->tm_wday;
/* implement start of week (Sunday/Monday) as config option
weekday=ts->tm_wday;
weekday--;
if (weekday==-1)
weekday=6;
*/
if (cgi_log_rotation_method == LOG_ROTATION_NONE)
return OK;
else if (cgi_log_rotation_method == LOG_ROTATION_HOURLY)
strcpy(method_string, "HOURLY");
else if (cgi_log_rotation_method == LOG_ROTATION_DAILY) {
strcpy(method_string, "DAILY");
ts->tm_hour = 0;
} else if (cgi_log_rotation_method == LOG_ROTATION_WEEKLY) {
strcpy(method_string, "WEEKLY");
ts->tm_hour = 0;
sub = (60 * 60 * 24 * weekday);
} else if (cgi_log_rotation_method == LOG_ROTATION_MONTHLY) {
strcpy(method_string, "MONTHLY");
ts->tm_hour = 0;
ts->tm_mday = 1;
} else
return ERROR;
// determine the timestamp for next rotation
rotate_ts = (time_t)(mktime(ts) - sub);
/* get stats of current log file */
stat_result = stat(cgi_log_file, &log_file_stat);
// timestamp for rotation hasn't passed. don't rotate log file
if (rotate_ts < log_file_stat.st_atime)
return OK;
// from here on file gets rotated.
/* get the archived filename to use */
asprintf(&log_archive, "%s/icinga-cgi-%02d-%02d-%d-%02d.log", cgi_log_archive_path, ts->tm_mon + 1, ts->tm_mday, ts->tm_year + 1900, ts->tm_hour);
/* rotate the log file */
rename_result = my_rename(cgi_log_file, log_archive);
if (rename_result) {
my_free(log_archive);
return ERROR;
}
/* record the log rotation after it has been done... */
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "LOG ROTATION: %s\n", method_string);
temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
write_to_cgi_log(temp_buffer);
/* give a warning about use */
write_to_cgi_log("This log is highly experimental and changes may occure without notice. Use at your own risk!!");
if (stat_result == 0) {
chmod(cgi_log_file, log_file_stat.st_mode);
chown(cgi_log_file, log_file_stat.st_uid, log_file_stat.st_gid);
}
my_free(log_archive);
return OK;
}
/* renames a file - works across filesystems (Mike Wiacek) */
int my_rename(char *source, char *dest) {
int rename_result = 0;
/* make sure we have something */
if (source == NULL || dest == NULL)
return -1;
/* first see if we can rename file with standard function */
rename_result = rename(source, dest);
/* handle any errors... */
if (rename_result == -1) {
/* an error occurred because the source and dest files are on different filesystems */
if (errno == EXDEV) {
/* try copying the file */
if (my_fcopy(source, dest) == ERROR) {
return -1;
}
/* delete the original file */
unlink(source);
/* reset result since we successfully copied file */
rename_result = 0;
}
/* some other error occurred */
else {
return rename_result;
}
}
return rename_result;
}
/* copies a file */
int my_fcopy(char *source, char *dest) {
int dest_fd, result;
/* make sure we have something */
if (source == NULL || dest == NULL)
return ERROR;
/* unlink destination file first (not doing so can cause problems on network file systems like CIFS) */
unlink(dest);
/* open destination file for writing */
if ((dest_fd = open(dest, O_WRONLY | O_TRUNC | O_CREAT | O_APPEND, 0644)) < 0) {
return ERROR;
}
result = my_fdcopy(source, dest, dest_fd);
close(dest_fd);
return result;
}
/*
* copy a file from the path at source to the already opened
* destination file dest.
* This is handy when creating tempfiles with mkstemp()
*/
int my_fdcopy(char *source, char *dest, int dest_fd) {
int source_fd, rd_result = 0, wr_result = 0;
unsigned long tot_written = 0, tot_read = 0, buf_size = 0;
struct stat st;
char *buf;
/* open source file for reading */
if ((source_fd = open(source, O_RDONLY, 0644)) < 0) {
return ERROR;
}
/*
* find out how large the source-file is so we can be sure
* we've written all of it
*/
if (fstat(source_fd, &st) < 0) {
close(source_fd);
return ERROR;
}
/*
* If the file is huge, read it and write it in chunks.
* This value (128K) is the result of "pick-one-at-random"
* with some minimal testing and may not be optimal for all
* hardware setups, but it should work ok for most. It's
* faster than 1K buffers and 1M buffers, so change at your
* own peril. Note that it's useful to make it fit in the L2
* cache, so larger isn't necessarily better.
*/
buf_size = st.st_size > 128 << 10 ? 128 << 10 : st.st_size;
buf = malloc(buf_size);
if (!buf) {
close(source_fd);
return ERROR;
}
/* most of the times, this loop will be gone through once */
while (tot_written < st.st_size) {
int loop_wr = 0;
rd_result = read(source_fd, buf, buf_size);
if (rd_result < 0) {
if (errno == EAGAIN || errno == EINTR)
continue;
break;
}
tot_read += rd_result;
while (loop_wr < rd_result) {
wr_result = write(dest_fd, buf + loop_wr, rd_result - loop_wr);
if (wr_result < 0) {
if (errno == EAGAIN || errno == EINTR)
continue;
break;
}
loop_wr += wr_result;
}
if (wr_result < 0)
break;
tot_written += loop_wr;
}
/*
* clean up irregardless of how things went. dest_fd comes from
* our caller, so we mustn't close it.
*/
close(source_fd);
free(buf);
if (rd_result < 0 || wr_result < 0) {
/* don't leave half-written files around */
unlink(dest);
return ERROR;
}
return OK;
}
/* Checks if the given time is in daylight time saving period */
int is_dlst_time(time_t *time) {
struct tm *bt = localtime(time);
return bt->tm_isdst;
}
/* convert timeperiodes to timestamps */
void convert_timeperiod_to_times(int type, time_t *ts_start, time_t *ts_end) {
time_t current_time;
int weekday = 0;
struct tm *t;
/* get the current time */
time(¤t_time);
/* everything before start of unix time is invalid */
if ((unsigned long int)ts_start > (unsigned long int)current_time)
*ts_start = 0L;
t = localtime(¤t_time);
t->tm_sec = 0;
t->tm_min = 0;
t->tm_hour = 0;
t->tm_isdst = -1;
/* see if weeks starts on sunday or monday */
weekday = t->tm_wday;
if (week_starts_on_monday == TRUE) {
weekday--;
if (weekday == -1)
weekday = 6;
}
switch (type) {
case TIMEPERIOD_LAST24HOURS:
*ts_start = current_time - (60 * 60 * 24);
*ts_end = current_time;
break;
case TIMEPERIOD_TODAY:
*ts_start = mktime(t);
*ts_end = current_time;
break;
case TIMEPERIOD_SINGLE_DAY:
if (*ts_start == 0L && *ts_end == 0L) {
*ts_start = mktime(t);
*ts_end = current_time;
}
break;
case TIMEPERIOD_YESTERDAY:
*ts_start = (time_t)(mktime(t) - (60 * 60 * 24));
*ts_end = (time_t)mktime(t) - 1;
break;
case TIMEPERIOD_THISWEEK:
*ts_start = (time_t)(mktime(t) - (60 * 60 * 24 * weekday));
*ts_end = current_time;
break;
case TIMEPERIOD_LASTWEEK:
t->tm_wday--;
*ts_start = (time_t)(mktime(t) - (60 * 60 * 24 * weekday) - (60 * 60 * 24 * 7));
*ts_end = (time_t)(mktime(t) - (60 * 60 * 24 * weekday) - 1);
break;
case TIMEPERIOD_THISMONTH:
t->tm_mday = 1;
*ts_start = mktime(t);
*ts_end = current_time;
break;
case TIMEPERIOD_LASTMONTH:
t->tm_mday = 1;
*ts_end = mktime(t) - 1;
if (t->tm_mon == 0) {
t->tm_mon = 11;
t->tm_year--;
} else
t->tm_mon--;
*ts_start = mktime(t);
break;
case TIMEPERIOD_THISYEAR:
t->tm_mon = 0;
t->tm_mday = 1;
*ts_start = mktime(t);
*ts_end = current_time;
break;
case TIMEPERIOD_LASTYEAR:
t->tm_mon = 0;
t->tm_mday = 1;
*ts_end = mktime(t) - 1;
t->tm_year--;
*ts_start = mktime(t);
break;
case TIMEPERIOD_LAST7DAYS:
*ts_start = (time_t)(mktime(t) - (60 * 60 * 24 * 7));
*ts_end = current_time;
break;
case TIMEPERIOD_LAST31DAYS:
*ts_start = (time_t)(mktime(t) - (60 * 60 * 24 * 31));
*ts_end = current_time;
break;
case TIMEPERIOD_THISQUARTER:
/* not implemented */
break;
case TIMEPERIOD_LASTQUARTER:
/* not implemented */
break;
case TIMEPERIOD_NEXTPROBLEM:
/* Time period will be defined later */
/* only used in trends.cgi */
break;
default:
break;
}
/* check if interval is across dlst change and adjust timestamps with compensation */
if (is_dlst_time(ts_start) != is_dlst_time(ts_end)) {
t = localtime(¤t_time);
/* in DST */
if (t->tm_isdst == 1) {
/* if end is also in DST */
if (is_dlst_time(ts_end) == 1)
*ts_start = *ts_start + 3600;
} else {
if (is_dlst_time(ts_end) == 0)
*ts_start = *ts_start - 3600;
}
}
return;
}
/* converts a time string to a UNIX timestamp, respecting the date_format option */
int string_to_time(char *buffer, time_t *t) {
struct tm lt;
int ret = 0;
/* Initialize some variables just in case they don't get parsed
by the sscanf() call. A better solution is to also check the
CGI input for validity, but this should suffice to prevent
strange problems if the input is not valid.
Jan 15 2003 Steve Bonds */
lt.tm_mon = 0;
lt.tm_mday = 1;
lt.tm_year = 1900;
lt.tm_hour = 0;
lt.tm_min = 0;
lt.tm_sec = 0;
lt.tm_wday = 0;
lt.tm_yday = 0;
if (date_format == DATE_FORMAT_EURO)
ret = sscanf(buffer, "%02d-%02d-%04d %02d:%02d:%02d", <.tm_mday, <.tm_mon, <.tm_year, <.tm_hour, <.tm_min, <.tm_sec);
else if (date_format == DATE_FORMAT_ISO8601 || date_format == DATE_FORMAT_STRICT_ISO8601)
ret = sscanf(buffer, "%04d-%02d-%02d%*[ T]%02d:%02d:%02d", <.tm_year, <.tm_mon, <.tm_mday, <.tm_hour, <.tm_min, <.tm_sec);
else
ret = sscanf(buffer, "%02d-%02d-%04d %02d:%02d:%02d", <.tm_mon, <.tm_mday, <.tm_year, <.tm_hour, <.tm_min, <.tm_sec);
if (ret != 6)
return ERROR;
lt.tm_mon--;
lt.tm_year -= 1900;
/* tell mktime() to try and compute DST automatically */
lt.tm_isdst = -1;
*t = mktime(<);
return OK;
}
char *json_encode(char *input) {
char *encoded_string;
int len = 0;
int i, j;
/* we need up to twice the space to do the conversion */
len = (int)strlen(input);
if ((encoded_string = (char *)malloc(len * 2 + 1)) == NULL)
return "";
for (i = 0, j = 0; i < len; i++) {
/* escape quotes and backslashes */
if ((char)input[i] == (char)'"' || (char)input[i] == (char)'\\') {
encoded_string[j++] = '\\';
encoded_string[j++] = input[i];
/* escape newlines */
} else if ((char)input[i] == (char)'\n') {
encoded_string[j++] = '\\';
encoded_string[j++] = 'n';
/* ignore control caracters */
} else if ((input[i] > 1 && input[i] < 32) || input[i] == 127) {
continue;
} else
encoded_string[j++] = input[i];
}
encoded_string[j] = '\x0';
return encoded_string;
}
/******************************************************************/
/********* print a tooltip to show comments *********************/
/******************************************************************/
void print_comment_icon(char *host_name, char *svc_description) {
comment *temp_comment = NULL;
char *comment_entry_type = "";
char comment_data[MAX_INPUT_BUFFER] = "";
char entry_time[MAX_DATETIME_LENGTH];
int len, output_len;
int x, y;
char *escaped_output_string = NULL;
int saved_escape_html_tags_var = FALSE;
if (svc_description == NULL)
printf("
\n", display_from, display_to, total_entries);
/* copy page navigation to top of the page */
printf("\n");
return;
}
void page_limit_selector(int result_start) {
static int id = 0; // gets every dropdown a single id to activate msdropdown
char link[MAX_INPUT_BUFFER] = "";
char stripped_query_string[MAX_INPUT_BUFFER] = "";
char *temp_buffer;
/* define base url */
switch (CGI_ID) {
case STATUS_CGI_ID:
strcat(link, STATUS_CGI);
break;
case CONFIG_CGI_ID:
strcat(link, CONFIG_CGI);
break;
case EXTINFO_CGI_ID:
strcat(link, EXTINFO_CGI);
break;
case HISTORY_CGI_ID:
strcat(link, HISTORY_CGI);
break;
case NOTIFICATIONS_CGI_ID:
strcat(link, NOTIFICATIONS_CGI);
break;
case SHOWLOG_CGI_ID:
strcat(link, SHOWLOG_CGI);
break;
default:
strcat(link, "NO_URL_DEFINED");
break;
}
/* get url options but filter out "limit" and "status" */
if (getenv("QUERY_STRING") != NULL && strcmp(getenv("QUERY_STRING"), "")) {
if(strlen(getenv("QUERY_STRING")) > MAX_INPUT_BUFFER) {
write_to_cgi_log("page_limit_selector(): Query string exceeds max length. Returning without displaying page limit selector.\n");
return;
}
strcpy(stripped_query_string, getenv("QUERY_STRING"));
strip_html_brackets(stripped_query_string);
/* check if concatenated strings exceed MAX_INPUT_BUFFER */
if (strlen(link) + strlen(stripped_query_string) + 1 > MAX_INPUT_BUFFER) {
write_to_cgi_log("page_limit_selector(): Full query string exceeds max length. Returning without displaying page limit selector.\n");
return;
}
for (temp_buffer = my_strtok(stripped_query_string, "&"); temp_buffer != NULL; temp_buffer = my_strtok(NULL, "&")) {
if (strncmp(temp_buffer, "limit=", 6) != 0 && strncmp(temp_buffer, "start=", 6) != 0) {
if (strstr(link, "?"))
strcat(link, "&");
else
strcat(link, "?");
strcat(link, temp_buffer);
}
}
}
/* display drop down menu to select result limit */
printf("
\n");
printf("\n");
/* Print out the activator for the dropdown (which must be between the body tags */
printf("\n");
printf("
\n");
id++;
return;
}
icinga-1.10.3/cgi/cmd.c 0000664 0000000 0000000 00000373735 12276402000 0014512 0 ustar 00root root 0000000 0000000 /**************************************************************************
*
* CMD.C - Icinga Command CGI
*
* Copyright (c) 1999-2009 Ethan Galstad (egalstad@nagios.org)
* Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
*
* Last Modified: 08-08-2010
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*************************************************************************/
/** @file cmd.c
* @brief submits commands to Icinga command pipe
**/
#include "../include/config.h"
#include "../include/common.h"
#include "../include/objects.h"
#include "../include/comments.h"
#include "../include/downtime.h"
#include "../include/statusdata.h"
#include "../include/cgiutils.h"
#include "../include/cgiauth.h"
#include "../include/getcgi.h"
/** @name External vars
@{ **/
extern const char *extcmd_get_name(int id);
extern char main_config_file[MAX_FILENAME_LENGTH];
extern char url_html_path[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH];
extern char command_file[MAX_FILENAME_LENGTH];
extern char comment_file[MAX_FILENAME_LENGTH];
extern int check_external_commands;
extern int use_authentication;
extern int lock_author_names;
extern int persistent_ack_comments;
extern int send_ack_notifications;
extern int default_expiring_acknowledgement_duration;
extern int set_expire_ack_by_default;
extern int default_expiring_disabled_notifications_duration;
extern int display_header;
extern int daemon_check;
extern int enforce_comments_on_actions;
extern int date_format;
extern int use_logging;
extern int default_downtime_duration;
extern scheduled_downtime *scheduled_downtime_list;
extern comment *comment_list;
/** @} */
/** @name LIMITS
@{**/
#define MAX_AUTHOR_LENGTH 64
#define MAX_COMMENT_LENGTH 1024
#define NUMBER_OF_STRUCTS ((MAX_CGI_INPUT_PAIRS*2)+100) /**< Depends on amount of MAX_CGI_INPUT_PAIRS */
/** @}*/
/** @name ELEMET TEMPLATE TYPES
@{**/
#define PRINT_COMMON_HEADER 1
#define PRINT_AUTHOR 2
#define PRINT_STICKY_ACK 3
#define PRINT_PERSISTENT 4
#define PRINT_SEND_NOTFICATION 5
#define PRINT_COMMENT_BOX 6
#define PRINT_NOTIFICATION_DELAY 7
#define PRINT_START_TIME 8
#define PRINT_END_TIME 9
#define PRINT_CHECK_TIME 10
#define PRINT_FORCE_CHECK 11
#define PRINT_CHECK_OUTPUT_BOX 12
#define PRINT_PERFORMANCE_DATA_BOX 13
#define PRINT_FIXED_FLEXIBLE_TYPE 14
#define PRINT_BROADCAST_NOTIFICATION 15
#define PRINT_FORCE_NOTIFICATION 16
#define PRINT_EXPIRE_ACKNOWLEDGEMENT 17
#define PRINT_EXPIRE_DISABLE_NOTIFICATIONS 18
/** @}*/
/** @name OBJECT LIST TYPES
@{**/
#define PRINT_HOST_LIST 19
#define PRINT_SERVICE_LIST 20
#define PRINT_COMMENT_LIST 21
#define PRINT_DOWNTIME_LIST 22
/** @}*/
/** @brief host/service list structure
*
* Struct to hold information of hosts and services for batch processing
**/
struct hostlist {
char *host_name;
char *description;
};
/** @brief error list structure
*
* hold the errors we find during processing of @ref commit_command_data
**/
struct errorlist {
char *message;
};
/** @name Internal vars
@{ **/
char *host_name = ""; /**< requested host name */
char *hostgroup_name = ""; /**< requested hostgroup name */
char *servicegroup_name = ""; /**< requested servicegroup name */
char *service_desc = ""; /**< requested service name */
char *comment_author = ""; /**< submitted comment author */
char *comment_data = ""; /**< submitted comment data */
char *start_time_string = ""; /**< the requested start time */
char *end_time_string = ""; /**< the requested end time */
char help_text[MAX_INPUT_BUFFER] = ""; /**< help string */
char plugin_output[MAX_INPUT_BUFFER] = ""; /**< plugin output text for passive submitted check */
char performance_data[MAX_INPUT_BUFFER] = ""; /**< plugin performance data for passive submitted check */
int notification_delay = 0; /**< delay for submitted notification in minutes */
int schedule_delay = 0; /**< delay for sheduled actions in minutes (Icinga restart, Notfications enable/disable)
!not implemented in GUI! */
int persistent_comment = FALSE; /**< bool if omment should survive Icinga restart */
int sticky_ack = TRUE; /**< bool to disable notifications until recover */
int send_notification = FALSE; /**< bool sends a notification if service gets acknowledged */
int use_ack_end_time = FALSE; /**< bool if expire acknowledgement is selected or not */
int use_disabled_notif_end_time = FALSE; /**< bool if expire disabled notifications is selected or not */
int force_check = FALSE; /**< bool if check should be forced */
int plugin_state = STATE_OK; /**< plugin state for passive submitted check */
int affect_host_and_services = FALSE; /**< bool if notifiactions or else affect all host and services */
int propagate_to_children = FALSE; /**< bool if en/disable host notifications should propagated to children */
int fixed = FALSE; /**< bool if downtime is fixed or flexible */
unsigned long duration = 0L; /**< downtime duration */
unsigned long triggered_by = 0L; /**< downtime id which triggers submited downtime */
int child_options = 0; /**< if downtime should trigger child host downtimes */
int force_notification = 0; /**< force a notification to be send out through event handler */
int broadcast_notification = 0; /**< this options determines if notification should be broadcasted */
int command_type = CMD_NONE; /**< the requested command ID */
int command_mode = CMDMODE_REQUEST; /**< if command mode is request or commit */
time_t start_time = 0L; /**< start time as unix timestamp */
time_t end_time = 0L; /**< end time as unix timestamp */
int CGI_ID = CMD_CGI_ID; /**< ID to identify the cgi for functions in cgiutils.c */
unsigned long attr = MODATTR_NONE; /**< default modified_attributes */
double interval = 1.0; /**< default modified *_interval */
authdata current_authdata; /**< struct to hold current authentication data */
/** Initialize the struct */
struct hostlist commands[NUMBER_OF_STRUCTS];
/** initialze the error list */
struct errorlist error[NUMBER_OF_STRUCTS];
/** Hold IDs of comments and downtimes */
unsigned long multi_ids[NUMBER_OF_STRUCTS];
/** store the authentication status when data gets checked to submited */
short is_authorized[NUMBER_OF_STRUCTS];
/** store the result of each object which get submited */
short submit_result[NUMBER_OF_STRUCTS];
/** @} */
/** @brief Print form for all details to submit command
* @param [in] cmd ID of requested command
*
* This function generates the form for the command with all requested
* host/services/downtimes/comments items. This is the first page you get
* when you submit a command.
**/
void request_command_data(int);
/** @brief submits the command data and checks for sanity
* @param [in] cmd ID of requested command
*
* This function checks the submitted data (@ref request_command_data)
* for sanity. If everything is alright it passes the data to @ref commit_command.
**/
void commit_command_data(int);
/** @brief checks the authorization and passes the data to cmd_submitf
* @param [in] cmd ID of requested command
* @retval OK
* @retval ERROR
* @return success / fail
*
* Here the command get formatted properly to be readable by icinga
* core. It passes the data to @c cmd_submitf .
**/
int commit_command(int);
/** @brief write the command to Icinga command pipe
* @param [in] cmd the formatted command string
* @retval OK
* @retval ERROR
* @return success / fail
*
* This function actually writes the formatted string into Icinga command pipe.
* And if configured also to Icinga CGI log.
**/
int write_command_to_file(char *);
/** @brief strips out semicolons and newlines from comment data
* @param [in,out] buffer the stringt which should be cleaned
*
* Converts semicolons, newline and carriage return to space.
**/
void clean_comment_data(char *);
/** @brief strips out semicolons and newlines from comment data
* @param [in] element ID of the element which should be printed
* @param [in] cmd ID of requested command
*
* These are templates for the different form elements. Specify
* the element you want to print with element id.
**/
void print_form_element(int, int);
/** @brief print the list of affected objects
* @param [in] list_type ID of the item list which should be printed
*
* Used to print the list of requested objects. Depending on the command
* you can specify the list (HOST/SERVICE/COMMENT/DOWNTIME).
**/
void print_object_list(int);
/** @brief print the mouseover box with help text
* @param [in] content string which should be printed as help box
*
* This writes the mousover help box.
**/
void print_help_box(char *);
/** @brief checks start and end time and if start_time is before end_time
* @param [in] e the error element list
*
* Checks if author or comment is empty. If so it adds an error to error list.
**/
void check_comment_sanity(int*);
/** @brief checks if comment and author are not empty strings
* @param [in] e the error element list
*
* Checks the sanity of given start and end time. Checks if time is
* wrong or start_time is past end_time then if found an error it
* adds an error to error list.
**/
void check_time_sanity(int*);
/** @brief Parses the requested GET/POST variables
* @retval TRUE
* @retval FALSE
* @return wether parsing was successful or not
*
* @n This function parses the request and set's the necessary variables
**/
int process_cgivars(void);
/** @brief Yes we need a main function **/
int main(void) {
int result = OK;
/* get the arguments passed in the URL */
process_cgivars();
/* reset internal variables */
reset_cgi_vars();
/* read the CGI configuration file */
result = read_cgi_config_file(get_cgi_config_location());
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(get_cgi_config_location(), ERROR_CGI_CFG_FILE, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(main_config_file, ERROR_CGI_MAIN_CFG, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* read environment var ICINGA_COMMAND_FILE */
strcpy(command_file, get_cmd_file_location());
/* This requires the date_format parameter in the main config file */
if (strcmp(start_time_string, ""))
string_to_time(start_time_string, &start_time);
if (strcmp(end_time_string, ""))
string_to_time(end_time_string, &end_time);
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(NULL, ERROR_CGI_OBJECT_DATA, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* read all status data */
result = read_all_status_data(main_config_file, READ_ALL_STATUS_DATA);
if (result == ERROR && daemon_check == TRUE) {
document_header(CGI_ID, FALSE, "Error");
print_error(NULL, ERROR_CGI_STATUS_DATA, FALSE);
document_footer(CGI_ID);
free_memory();
return ERROR;
}
document_header(CGI_ID, TRUE, "External Command Interface");
/* get authentication information */
get_authentication_information(¤t_authdata);
if (display_header == TRUE) {
/* Giving credits to stop.png image source */
printf("\n\n\n");
/* begin top table */
printf("
\n");
/* center column of the first row */
printf("
\n");
printf("
\n");
/* right column of the first row */
printf("
\n");
printf("
\n");
/* end of top table */
printf("
\n");
printf("
\n");
}
/* if no command was specified... */
if (command_type == CMD_NONE) {
print_generic_error_message("Error: No command was specified!", NULL, 2);
}
/* if not authorized to perform commands*/
else if (is_authorized_for_read_only(¤t_authdata) == TRUE) {
print_generic_error_message("Error: It appears as though you do not have permission to perform any commands!", NULL, 1);
}
/* if this is the first request for a command, present option */
else if (command_mode == CMDMODE_REQUEST)
request_command_data(command_type);
/* the user wants to commit the command */
else if (command_mode == CMDMODE_COMMIT)
commit_command_data(command_type);
document_footer(CGI_ID);
/* free allocated memory */
free_memory();
free_object_data();
return OK;
}
int process_cgivars(void) {
char **variables;
char *temp_buffer = NULL;
int error = FALSE;
int x;
int z = 0;
int sticky_ack_set = FALSE; /* default is TRUE */
variables = getcgivars();
/* Process the variables */
for (x = 0; variables[x] != NULL; x++) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */
if (strlen(variables[x]) >= MAX_INPUT_BUFFER - 1)
continue;
/* we found the command type */
else if (!strcmp(variables[x], "cmd_typ")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
command_type = atoi(variables[x]);
}
/* we found the attr */
else if (!strcmp(variables[x], "attr")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
attr = strtoul(variables[x], NULL, 10);
}
/* we found the attr */
else if (!strcmp(variables[x], "interval")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
#ifdef HAVE_STRTOF
interval = strtof(variables[x], NULL);
#else
/* Solaris 8 doesn't have strtof() */
interval = (float)strtod(variables[x], NULL);
#endif
}
/* we found the command mode */
else if (!strcmp(variables[x], "cmd_mod")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
command_mode = atoi(variables[x]);
}
/* we found a comment id or a downtime id*/
else if (!strcmp(variables[x], "com_id") || !strcmp(variables[x], "down_id")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
multi_ids[z] = strtoul(variables[x], NULL, 10);
z++;
}
/* we found the notification delay */
else if (!strcmp(variables[x], "not_dly")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
notification_delay = atoi(variables[x]);
}
/* we found the schedule delay */
else if (!strcmp(variables[x], "sched_dly")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
schedule_delay = atoi(variables[x]);
}
/* we found the comment author */
else if (!strcmp(variables[x], "com_author")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((comment_author = (char *)strdup(variables[x])) == NULL)
comment_author = "";
strip_html_brackets(comment_author);
}
/* we found the comment data */
else if (!strcmp(variables[x], "com_data")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((comment_data = (char *)strdup(variables[x])) == NULL)
comment_data = "";
strip_html_brackets(comment_data);
}
/* we found the host name */
else if (!strcmp(variables[x], "host")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((host_name = (char *)strdup(variables[x])) == NULL)
host_name = "";
else {
strip_html_brackets(host_name);
/* Store hostname in struct */
commands[x].host_name = host_name;
}
}
/* we found the hostgroup name */
else if (!strcmp(variables[x], "hostgroup")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((hostgroup_name = (char *)strdup(variables[x])) == NULL)
hostgroup_name = "";
strip_html_brackets(hostgroup_name);
}
/* we found the service name */
else if (!strcmp(variables[x], "service")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((service_desc = (char *)strdup(variables[x])) == NULL)
service_desc = "";
else {
strip_html_brackets(service_desc);
/* Store service description in struct */
commands[(x-2)].description = service_desc;
}
}
/* we found a combined host/service */
else if (!strcmp(variables[x], "hostservice")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
temp_buffer = strtok(variables[x], "^");
if ((host_name = (char *)strdup(temp_buffer)) == NULL)
host_name = "";
else {
strip_html_brackets(host_name);
commands[x].host_name = host_name;
}
temp_buffer = strtok(NULL, "");
if ((service_desc = (char *)strdup(temp_buffer)) == NULL)
service_desc = "";
else {
strip_html_brackets(service_desc);
commands[x].description = service_desc;
}
}
/* we found the servicegroup name */
else if (!strcmp(variables[x], "servicegroup")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((servicegroup_name = (char *)strdup(variables[x])) == NULL)
servicegroup_name = "";
strip_html_brackets(servicegroup_name);
}
/* we got the persistence option for a comment */
else if (!strcmp(variables[x], "persistent"))
persistent_comment = TRUE;
/* we got the notification option for an acknowledgement */
else if (!strcmp(variables[x], "send_notification"))
send_notification = TRUE;
/* we got the acknowledgement type */
else if (!strcmp(variables[x], "sticky_ack"))
sticky_ack_set = TRUE;
/* we use the end_time as expire time */
else if (!strcmp(variables[x], "use_ack_end_time"))
use_ack_end_time = TRUE;
/* we use the end_time as disabled notifcations expire time */
else if (!strcmp(variables[x], "use_disabled_notif_end_time"))
use_disabled_notif_end_time = TRUE;
/* we got the service check force option */
else if (!strcmp(variables[x], "force_check"))
force_check = TRUE;
/* we got the option to affect host and all its services */
else if (!strcmp(variables[x], "ahas"))
affect_host_and_services = TRUE;
/* we got the option to propagate to child hosts */
else if (!strcmp(variables[x], "ptc"))
propagate_to_children = TRUE;
/* we got the option for fixed downtime */
else if (!strcmp(variables[x], "fixed")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
fixed = (atoi(variables[x]) > 0) ? TRUE : FALSE;
}
/* we got the triggered by downtime option */
else if (!strcmp(variables[x], "trigger")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
triggered_by = strtoul(variables[x], NULL, 10);
}
/* we got the child options */
else if (!strcmp(variables[x], "childoptions")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
child_options = atoi(variables[x]);
}
/* we found the plugin output */
else if (!strcmp(variables[x], "plugin_output")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
/* protect against buffer overflows */
if (strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
error = TRUE;
break;
} else
strcpy(plugin_output, variables[x]);
}
/* we found the performance data */
else if (!strcmp(variables[x], "performance_data")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
/* protect against buffer overflows */
if (strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
error = TRUE;
break;
} else
strcpy(performance_data, variables[x]);
}
/* we found the plugin state */
else if (!strcmp(variables[x], "plugin_state")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
plugin_state = atoi(variables[x]);
}
/* we found the hour duration */
else if (!strcmp(variables[x], "hours")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (atoi(variables[x]) < 0) {
error = TRUE;
break;
}
duration += (unsigned long)(atoi(variables[x]) * 3600);
}
/* we found the minute duration */
else if (!strcmp(variables[x], "minutes")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (atoi(variables[x]) < 0) {
error = TRUE;
break;
}
duration += (unsigned long)(atoi(variables[x]) * 60);
}
/* we found the start time */
else if (!strcmp(variables[x], "start_time")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
start_time_string = (char *)malloc(strlen(variables[x]) + 1);
if (start_time_string == NULL)
start_time_string = "";
else
strcpy(start_time_string, variables[x]);
}
/* we found the end time */
else if (!strcmp(variables[x], "end_time")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
end_time_string = (char *)malloc(strlen(variables[x]) + 1);
if (end_time_string == NULL)
end_time_string = "";
else
strcpy(end_time_string, variables[x]);
}
/* we found the forced notification option */
else if (!strcmp(variables[x], "force_notification"))
force_notification = NOTIFICATION_OPTION_FORCED;
/* we found the broadcast notification option */
else if (!strcmp(variables[x], "broadcast_notification"))
broadcast_notification = NOTIFICATION_OPTION_BROADCAST;
/* we got the persistence option for a comment */
else if (!strcmp(variables[x], "nodaemoncheck"))
daemon_check = FALSE;
}
if (command_mode == CMDMODE_COMMIT) {
sticky_ack = sticky_ack_set;
}
/* free memory allocated to the CGI variables */
free_cgivars(variables);
return error;
}
void print_object_list(int list_type) {
hoststatus *temp_hoststatus = NULL;
servicestatus *temp_servicestatus = NULL;
int x = 0;
int row_color = 0;
int host_passive = FALSE;
int service_passive = FALSE;
printf("
\n");
printf("
Affected Objects
\n");
printf("
\n");
printf("\n");
printf("
\n");
if (list_type == PRINT_SERVICE_LIST)
printf("
Host
Service
\n");
else if (list_type == PRINT_HOST_LIST)
printf("
\n", escape_string(comment_author), escape_string(comment_author));
else
printf("\n", escape_string(comment_author));
break;
case PRINT_COMMENT_BOX:
strcpy(help_text, "If you work with other administrators, you may find it useful to share information about a host/service "
"that is having problems if more than one of you may be working on it. "
"Make sure to enter a brief description of what you are doing.");
printf("
\n");
break;
case PRINT_CHECK_OUTPUT_BOX:
snprintf(help_text, sizeof(help_text), "Fill in the exact output string which sould be sent to %s", PROGRAM_NAME);
help_text[sizeof(help_text)-1] = '\x0';
printf("
\n");
break;
case PRINT_PERFORMANCE_DATA_BOX:
snprintf(help_text, sizeof(help_text), "Fill in the exact performance data string which sould be sent to %s", PROGRAM_NAME);
help_text[sizeof(help_text)-1] = '\x0';
printf("
\n");
break;
case PRINT_STICKY_ACK:
strcpy(help_text, "If you want acknowledgement to disable notifications until the host/service recovers, check this option.");
printf("
\n", (sticky_ack == TRUE) ? "CHECKED" : "");
break;
case PRINT_SEND_NOTFICATION:
strcpy(help_text, "If you do not want an acknowledgement notification sent out to the appropriate contacts, uncheck this option.");
printf("
\n", (send_ack_notifications == TRUE) ? "CHECKED" : "");
break;
case PRINT_PERSISTENT:
if (cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM || cmd == CMD_ACKNOWLEDGE_SVC_PROBLEM)
strcpy(help_text, "If you would like the comment to remain once the acknowledgement is removed, check this checkbox.");
else {
snprintf(help_text, sizeof(help_text), "If you uncheck this option, the comment will automatically be deleted the next time %s is restarted.", PROGRAM_NAME);
help_text[sizeof(help_text)-1] = '\x0';
}
printf("
\n", (persistent_ack_comments == TRUE || cmd == CMD_ADD_HOST_COMMENT || cmd == CMD_ADD_SVC_COMMENT) ? "CHECKED" : "");
break;
case PRINT_NOTIFICATION_DELAY:
strcpy(help_text, "The notification delay will be disregarded if the host/service changes state before the next notification is scheduled to be sent out.");
printf("
Notification Delay (minutes from now):");
print_help_box(help_text);
printf("
");
printf("", notification_delay);
printf("
Notification delay can't be zero
");
printf("
\n");
break;
case PRINT_START_TIME:
case PRINT_END_TIME:
case PRINT_CHECK_TIME:
time(&t);
if (element == PRINT_END_TIME)
t += (unsigned long)default_downtime_duration;
get_time_string(&t, buffer, sizeof(buffer) - 1, SHORT_DATE_TIME);
printf("
");
if (element == PRINT_START_TIME) {
strcpy(help_text, "Set the start date/time for the downtime.");
printf("Start Time:");
} else if (element == PRINT_END_TIME) {
strcpy(help_text, "Set the end date/time for the downtime.");
printf("End Time:");
} else {
strcpy(help_text, "Set the date/time when this check should be schedule to.");
printf("Check Time:");
}
print_help_box(help_text);
printf("
\n", (element == PRINT_END_TIME) ? "end" : "start", buffer);
break;
case PRINT_FIXED_FLEXIBLE_TYPE:
default_downtime_duration = default_downtime_duration / 60;
t_min = default_downtime_duration % 60;
default_downtime_duration = default_downtime_duration - t_min;
t_hour = (default_downtime_duration / 60) ;
snprintf(help_text, sizeof(help_text), "If you select the fixed option, the downtime will be in effect between the start and end times you specify. If you do not select the fixed "
"option, %s will treat this as flexible downtime. Flexible downtime starts when the host goes down or becomes unreachable / service becomes critical (sometime between the "
"start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed downtime.", PROGRAM_NAME);
help_text[sizeof(help_text)-1] = '\x0';
printf("
Type:");
print_help_box(help_text);
printf("
\n");
printf("\t\n");
snprintf(help_text, sizeof(help_text), "Enter here the duration of the downtime. %s will automatically delete the downtime after this time expired.", PROGRAM_NAME);
help_text[sizeof(help_text)-1] = '\x0';
printf("
\n");
break;
case PRINT_EXPIRE_ACKNOWLEDGEMENT:
strcpy(help_text, "If you want to let the acknowledgement expire, check this option.");
printf("
Use Expire Time:");
print_help_box(help_text);
printf("
");
printf("
\n", (set_expire_ack_by_default == TRUE) ? "CHECKED" : "");
snprintf(help_text, sizeof(help_text), "Enter here the expire date/time for this acknowledgement. %s will automatically delete the acknowledgement after this time expired.", PROGRAM_NAME);
help_text[sizeof(help_text)-1] = '\x0';
time(&t);
t += (unsigned long)default_expiring_acknowledgement_duration;
get_time_string(&t, buffer, sizeof(buffer) - 1, SHORT_DATE_TIME);
printf("
\n", buffer);
break;
case PRINT_EXPIRE_DISABLE_NOTIFICATIONS:
strcpy(help_text, "If you want to let the disabled notifications expire, check this option.");
printf("
Use Expire Time:");
print_help_box(help_text);
printf("
");
printf("
\n");
snprintf(help_text, sizeof(help_text), "Enter the expire date/time for disabled notifications. %s will automatically re-enable all notifications after this time expired.", PROGRAM_NAME);
help_text[sizeof(help_text)-1] = '\x0';
time(&t);
t += (unsigned long)default_expiring_disabled_notifications_duration;
get_time_string(&t, buffer, sizeof(buffer) - 1, SHORT_DATE_TIME);
printf("
\n", buffer);
break;
case PRINT_FORCE_CHECK:
snprintf(help_text, sizeof(help_text), "If you select this option, %s will force a check of the host/service regardless of both what time the scheduled check occurs and whether or not checks are enabled for the host/service.", PROGRAM_NAME);
help_text[sizeof(help_text)-1] = '\x0';
printf("
Force Check:");
print_help_box(help_text);
printf("
");
printf("
\n", (force_check == TRUE) ? "CHECKED" : "");
break;
case PRINT_BROADCAST_NOTIFICATION:
strcpy(help_text, "Selecting this option causes the notification to be sent out to all normal (non-escalated) and escalated contacts. These options allow you to override the normal notification logic if you need to get an important message out.");
printf("
Broadcast:");
print_help_box(help_text);
printf("
");
printf("
\n");
break;
case PRINT_FORCE_NOTIFICATION:
snprintf(help_text, sizeof(help_text), "Custom notifications normally follow the regular notification logic in %s. Selecting this option will force the notification to be sent out, regardless of the time restrictions, whether or not notifications are enabled, etc.", PROGRAM_NAME);
help_text[sizeof(help_text)-1] = '\x0';
printf("
Forced:");
print_help_box(help_text);
printf("
");
printf("
\n");
break;
default:
break;
}
return;
}
void request_command_data(int cmd) {
char start_time[MAX_DATETIME_LENGTH];
contact *temp_contact;
scheduled_downtime *temp_downtime;
host *temp_host = NULL;
char action[MAX_INPUT_BUFFER];
int found_trigger_objects = FALSE;
/* get default name to use for comment author */
temp_contact = find_contact(current_authdata.username);
if (temp_contact != NULL && temp_contact->alias != NULL)
comment_author = temp_contact->alias;
else
comment_author = current_authdata.username;
printf(" ");
switch (cmd) {
case CMD_ADD_HOST_COMMENT:
case CMD_ADD_SVC_COMMENT:
snprintf(action, sizeof(action), "Add %s comments", (cmd == CMD_ADD_HOST_COMMENT) ? "host" : "service");
break;
case CMD_DEL_HOST_COMMENT:
case CMD_DEL_SVC_COMMENT:
snprintf(action, sizeof(action), "Delete %s comments", (cmd == CMD_DEL_HOST_COMMENT) ? "host" : "service");
break;
case CMD_DELAY_HOST_NOTIFICATION:
case CMD_DELAY_SVC_NOTIFICATION:
snprintf(help_text, sizeof(help_text), "This command is used to delay the next problem notification that is sent out for specified %s. The notification delay will be disregarded if "
"the %s changes state before the next notification is scheduled to be sent out. This command has no effect if the %s are currently %s.", (cmd == CMD_DELAY_HOST_NOTIFICATION) ? "hosts" : "services", (cmd == CMD_DELAY_HOST_NOTIFICATION) ? "hosts" : "services", (cmd == CMD_DELAY_HOST_NOTIFICATION) ? "hosts" : "services", (cmd == CMD_DELAY_HOST_NOTIFICATION) ? "UP" : "in an OK state");
snprintf(action, sizeof(action), "Delay a %s notification", (cmd == CMD_DELAY_HOST_NOTIFICATION) ? "host" : "service");
break;
case CMD_SCHEDULE_HOST_CHECK:
case CMD_SCHEDULE_SVC_CHECK:
snprintf(help_text, sizeof(help_text), "This command is used to schedule the next check of these %s. %s will re-queue the %s to be checked at the time you specify.", (cmd == CMD_SCHEDULE_HOST_CHECK) ? "hosts" : "services", PROGRAM_NAME, (cmd == CMD_SCHEDULE_HOST_CHECK) ? "host" : "service");
snprintf(action, sizeof(action), "Schedule %s checks", (cmd == CMD_SCHEDULE_HOST_CHECK) ? "host" : "service");
break;
case CMD_ENABLE_SVC_CHECK:
case CMD_DISABLE_SVC_CHECK:
snprintf(action, sizeof(action), "%s active service checks on a program-wide basis", (cmd == CMD_ENABLE_SVC_CHECK) ? "Enable" : "Disable");
break;
case CMD_ENABLE_NOTIFICATIONS:
case CMD_DISABLE_NOTIFICATIONS:
snprintf(help_text, sizeof(help_text), "This command is used to %s host and service notifications on a program-wide basis", (cmd == CMD_ENABLE_NOTIFICATIONS) ? "enable" : "disable");
snprintf(action, sizeof(action), "%s notifications on a program-wide basis", (cmd == CMD_ENABLE_NOTIFICATIONS) ? "Enable" : "Disable");
break;
case CMD_DISABLE_NOTIFICATIONS_EXPIRE_TIME:
snprintf(help_text, sizeof(help_text), "This command is used to disable host and service notifications on a program-wide basis, with a given expire time");
snprintf(action, sizeof(action), "Disable notifications on a program-wide basis, with expire time");
break;
case CMD_SHUTDOWN_PROCESS:
case CMD_RESTART_PROCESS:
snprintf(action, sizeof(action), "%s the %s process", (cmd == CMD_SHUTDOWN_PROCESS) ? "Shutdown" : "Restart", PROGRAM_NAME);
break;
case CMD_ENABLE_HOST_SVC_CHECKS:
case CMD_DISABLE_HOST_SVC_CHECKS:
if (cmd == CMD_ENABLE_HOST_SVC_CHECKS)
snprintf(help_text, sizeof(help_text), "This command is used to enable active checks of all services associated with the specified host");
else {
snprintf(help_text, sizeof(help_text), "This command is used to disable active checks of all services associated with the specified host. "
"When a service is disabled %s will not monitor the service. Doing this will prevent any notifications being sent out for "
"the specified service while it is disabled. In order to have %s check the service in the future you will have to re-enable the service. "
"Note that disabling service checks may not necessarily prevent notifications from being sent out about the host which those services are associated with.", PROGRAM_NAME, PROGRAM_NAME);
}
snprintf(action, sizeof(action), "%s active checks of all services on these hosts", (cmd == CMD_ENABLE_HOST_SVC_CHECKS) ? "Enable" : "Disable");
break;
case CMD_SCHEDULE_HOST_SVC_CHECKS:
snprintf(action, sizeof(action), "Schedule a check of all services for these hosts");
break;
case CMD_DEL_ALL_HOST_COMMENTS:
case CMD_DEL_ALL_SVC_COMMENTS:
snprintf(action, sizeof(action), "Delete all comments for these %s", (cmd == CMD_DEL_ALL_HOST_COMMENTS) ? "hosts" : "services");
break;
case CMD_ENABLE_SVC_NOTIFICATIONS:
case CMD_DISABLE_SVC_NOTIFICATIONS:
snprintf(action, sizeof(action), "%s notifications for these services", (cmd == CMD_ENABLE_SVC_NOTIFICATIONS) ? "Enable" : "Disable");
break;
case CMD_ENABLE_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOST_NOTIFICATIONS:
snprintf(action, sizeof(action), "%s notifications for these hosts", (cmd == CMD_ENABLE_HOST_NOTIFICATIONS) ? "Enable" : "Disable");
break;
case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
snprintf(help_text, sizeof(help_text), "This command is used to %s notifications for all hosts and services that lie beyond the specified host (from the view of %s).", (cmd == CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST) ? "enable" : "disable", PROGRAM_NAME);
snprintf(action, sizeof(action), "%s notifications for all hosts and services beyond these hosts", (cmd == CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST) ? "Enable" : "Disable");
break;
case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
snprintf(action, sizeof(action), "%s notifications for all services on these hosts", (cmd == CMD_ENABLE_HOST_SVC_NOTIFICATIONS) ? "Enable" : "Disable");
break;
case CMD_ACKNOWLEDGE_HOST_PROBLEM:
case CMD_ACKNOWLEDGE_SVC_PROBLEM:
snprintf(action, sizeof(action), "Acknowledge %s problems", (cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM) ? "host" : "service");
break;
case CMD_START_EXECUTING_HOST_CHECKS:
case CMD_STOP_EXECUTING_HOST_CHECKS:
snprintf(action, sizeof(action), "%s executing host checks on a program-wide basis", (cmd == CMD_START_EXECUTING_HOST_CHECKS) ? "Start" : "Stop");
break;
case CMD_START_EXECUTING_SVC_CHECKS:
case CMD_STOP_EXECUTING_SVC_CHECKS:
if (cmd == CMD_START_EXECUTING_SVC_CHECKS)
snprintf(help_text, sizeof(help_text), "This command is used to resume execution of active service checks on a program-wide basis. Individual services which are disabled will still not be checked.");
else
snprintf(help_text, sizeof(help_text), "This command is used to temporarily stop %s from actively executing any service checks. This will have the side effect of preventing any notifications from being sent out (for any and all services and hosts). "
"Service checks will not be executed again until you issue a command to resume service check execution.", PROGRAM_NAME);
snprintf(action, sizeof(action), "%s executing active service checks", (cmd == CMD_START_EXECUTING_SVC_CHECKS) ? "Start" : "Stop");
break;
case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
snprintf(help_text, sizeof(help_text), "This command is used to make %s %s accepting passive service check results that it finds in the external command file.", PROGRAM_NAME, (cmd == CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS) ? "start" : "stop");
snprintf(action, sizeof(action), "%s accepting passive service checks on a program-wide basis", (cmd == CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS) ? "Start" : "Stop");
break;
case CMD_ENABLE_PASSIVE_SVC_CHECKS:
case CMD_DISABLE_PASSIVE_SVC_CHECKS:
if (cmd == CMD_ENABLE_PASSIVE_SVC_CHECKS)
snprintf(help_text, sizeof(help_text), "This command is used to allow %s to accept passive service check results that it finds in the external command file for this particular service.", PROGRAM_NAME);
else
snprintf(help_text, sizeof(help_text), "This command is used to stop %s accepting passive service check results that it finds in the external command file for this particular service. All passive check results that are found for this service will be ignored.", PROGRAM_NAME);
snprintf(action, sizeof(action), "%s accepting passive service checks for these services", (cmd == CMD_ENABLE_PASSIVE_SVC_CHECKS) ? "Start" : "Stop");
break;
case CMD_ENABLE_EVENT_HANDLERS:
case CMD_DISABLE_EVENT_HANDLERS:
if (cmd == CMD_ENABLE_EVENT_HANDLERS)
snprintf(help_text, sizeof(help_text), "This command is used to allow %s to run host and service event handlers.", PROGRAM_NAME);
else
snprintf(help_text, sizeof(help_text), "This command is used to temporarily prevent %s from running any host or service event handlers.", PROGRAM_NAME);
snprintf(action, sizeof(action), "%s event handlers on a program-wide basis", (cmd == CMD_ENABLE_EVENT_HANDLERS) ? "Enable" : "Disable");
break;
case CMD_ENABLE_HOST_EVENT_HANDLER:
case CMD_DISABLE_HOST_EVENT_HANDLER:
snprintf(help_text, sizeof(help_text), "This command is used to %s the event handler for the selected hosts", (cmd == CMD_ENABLE_HOST_EVENT_HANDLER) ? "enable" : "disable");
snprintf(action, sizeof(action), "%s the event handler for these hosts", (cmd == CMD_ENABLE_HOST_EVENT_HANDLER) ? "Enable" : "Disable");
break;
case CMD_ENABLE_SVC_EVENT_HANDLER:
case CMD_DISABLE_SVC_EVENT_HANDLER:
snprintf(help_text, sizeof(help_text), "This command is used to %s the event handler for the selected services", (cmd == CMD_ENABLE_SVC_EVENT_HANDLER) ? "enable" : "disable");
snprintf(action, sizeof(action), "%s the event handler for these services", (cmd == CMD_ENABLE_SVC_EVENT_HANDLER) ? "Enable" : "Disable");
break;
case CMD_ENABLE_HOST_CHECK:
case CMD_DISABLE_HOST_CHECK:
if (cmd == CMD_DISABLE_HOST_CHECK)
snprintf(help_text, sizeof(help_text), "This command is used to temporarily prevent %s from actively checking the status of a particular host. If %s needs to check the status of this host, it will assume that it is in the same state that it was in before checks were disabled.", PROGRAM_NAME, PROGRAM_NAME);
snprintf(action, sizeof(action), "%s active host checks", (cmd == CMD_ENABLE_HOST_CHECK) ? "Enable" : "Disable");
break;
case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
case CMD_START_OBSESSING_OVER_SVC_CHECKS:
if (cmd == CMD_START_OBSESSING_OVER_SVC_CHECKS)
snprintf(help_text, sizeof(help_text), "This command is used to have %s start obsessing over service checks. Read the documentation on distributed monitoring for more information on this.", PROGRAM_NAME);
snprintf(action, sizeof(action), "%s obsessing over service checks on a program-wide basis", (cmd == CMD_STOP_OBSESSING_OVER_SVC_CHECKS) ? "Stop" : "Start");
break;
case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
snprintf(help_text, sizeof(help_text), "This command is used to remove an acknowledgement for %s problems. Once the acknowledgement is removed, notifications may start being "
"sent out about the %s problem.", (cmd == CMD_REMOVE_HOST_ACKNOWLEDGEMENT) ? "host" : "service", (cmd == CMD_REMOVE_HOST_ACKNOWLEDGEMENT) ? "host" : "service");
snprintf(action, sizeof(action), "Remove %s acknowledgements", (cmd == CMD_REMOVE_HOST_ACKNOWLEDGEMENT) ? "host" : "service");
break;
case CMD_SCHEDULE_HOST_DOWNTIME:
case CMD_SCHEDULE_SVC_DOWNTIME:
snprintf(help_text, sizeof(help_text), "This command is used to schedule downtime for these %s. During the specified downtime, %s will not send notifications out about the %s. "
"When the scheduled downtime expires, %s will send out notifications for this %s as it normally would. Scheduled downtimes are preserved "
"across program shutdowns and restarts.", (cmd == CMD_SCHEDULE_HOST_DOWNTIME) ? "hosts" : "services", PROGRAM_NAME, (cmd == CMD_SCHEDULE_HOST_DOWNTIME) ? "hosts" : "services", PROGRAM_NAME, (cmd == CMD_SCHEDULE_HOST_DOWNTIME) ? "hosts" : "services");
snprintf(action, sizeof(action), "Schedule downtime for these %s", (cmd == CMD_SCHEDULE_HOST_DOWNTIME) ? "hosts" : "services");
break;
case CMD_DEL_DOWNTIME_BY_HOST_NAME:
snprintf(help_text, sizeof(help_text), "This command is used to delete all downtimes for a host and all its services specified by the host name already supplied.");
snprintf(action, sizeof(action), "Remove downtimes for all services for these hosts and the hosts themself");
break;
case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
snprintf(help_text, sizeof(help_text), "This command is used to schedule downtime for a particular host and all of its services. During the specified downtime, %s will not send notifications out about the host. "
"Normally, a host in downtime will not send alerts about any services in a failed state. This option will explicitly set downtime for all services for this host. "
"When the scheduled downtime expires, %s will send out notifications for this host as it normally would. Scheduled downtimes are preserved "
"across program shutdowns and restarts.", PROGRAM_NAME, PROGRAM_NAME);
snprintf(action, sizeof(action), "Schedule downtime for all services for these hosts and the hosts themself");
break;
case CMD_PROCESS_HOST_CHECK_RESULT:
case CMD_PROCESS_SERVICE_CHECK_RESULT:
snprintf(help_text, sizeof(help_text), "This command is used to submit a passive check result for these %s. "
"It is particularly useful for resetting security-related %s to %s states once they have been dealt with.", (cmd == CMD_PROCESS_HOST_CHECK_RESULT) ? "hosts" : "services", (cmd == CMD_PROCESS_HOST_CHECK_RESULT) ? "hosts" : "services", (cmd == CMD_PROCESS_HOST_CHECK_RESULT) ? "UP" : "OK");
snprintf(action, sizeof(action), "Submit a passive check result for these %s", (cmd == CMD_PROCESS_HOST_CHECK_RESULT) ? "hosts" : "services");
break;
case CMD_ENABLE_HOST_FLAP_DETECTION:
case CMD_DISABLE_HOST_FLAP_DETECTION:
snprintf(action, sizeof(action), "%s flap detection for these hosts", (cmd == CMD_ENABLE_HOST_FLAP_DETECTION) ? "Enable" : "Disable");
break;
case CMD_ENABLE_SVC_FLAP_DETECTION:
case CMD_DISABLE_SVC_FLAP_DETECTION:
snprintf(action, sizeof(action), "%s flap detection for these services", (cmd == CMD_ENABLE_SVC_FLAP_DETECTION) ? "Enable" : "Disable");
break;
case CMD_ENABLE_FLAP_DETECTION:
case CMD_DISABLE_FLAP_DETECTION:
snprintf(action, sizeof(action), "%s flap detection for hosts and services on a program-wide basis", (cmd == CMD_ENABLE_FLAP_DETECTION) ? "Enable" : "Disable");
break;
case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
snprintf(action, sizeof(action), "%s notifications for all services in a particular hostgroup", (cmd == CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS) ? "Enable" : "Disable");
break;
case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
snprintf(action, sizeof(action), "%s notifications for all hosts in a particular hostgroup", (cmd == CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS) ? "Enable" : "Disable");
break;
case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
snprintf(action, sizeof(action), "%s active checks of all services in a particular hostgroup", (cmd == CMD_ENABLE_HOSTGROUP_SVC_CHECKS) ? "Enable" : "Disable");
break;
case CMD_DEL_HOST_DOWNTIME:
case CMD_DEL_SVC_DOWNTIME:
snprintf(action, sizeof(action), "Cancel scheduled downtime for these %s", (cmd == CMD_DEL_HOST_DOWNTIME) ? "hosts" : "services");
break;
case CMD_ENABLE_FAILURE_PREDICTION:
case CMD_DISABLE_FAILURE_PREDICTION:
snprintf(action, sizeof(action), "%s failure prediction for hosts and service on a program-wide basis", (cmd == CMD_ENABLE_FAILURE_PREDICTION) ? "Enable" : "Disable");
break;
case CMD_ENABLE_PERFORMANCE_DATA:
case CMD_DISABLE_PERFORMANCE_DATA:
snprintf(action, sizeof(action), "%s performance data processing for hosts and services on a program-wide basis", (cmd == CMD_ENABLE_PERFORMANCE_DATA) ? "Enable" : "Disable");
break;
case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
snprintf(action, sizeof(action), "Schedule downtime for all %s in a particular hostgroup", (cmd == CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME) ? "hosts" : "services");
break;
case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
snprintf(action, sizeof(action), "%s accepting passive host checks on a program-wide basis", (cmd == CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS) ? "Start" : "Stop");
break;
case CMD_ENABLE_PASSIVE_HOST_CHECKS:
case CMD_DISABLE_PASSIVE_HOST_CHECKS:
snprintf(action, sizeof(action), "%s accepting passive checks for these hosts", (cmd == CMD_ENABLE_PASSIVE_HOST_CHECKS) ? "Start" : "Stop");
break;
case CMD_START_OBSESSING_OVER_HOST_CHECKS:
case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
snprintf(action, sizeof(action), "%s obsessing over host checks on a program-wide basis", (cmd == CMD_START_OBSESSING_OVER_HOST_CHECKS) ? "Start" : "Stop");
break;
case CMD_START_OBSESSING_OVER_SVC:
case CMD_STOP_OBSESSING_OVER_SVC:
snprintf(action, sizeof(action), "%s obsessing over these services", (cmd == CMD_START_OBSESSING_OVER_SVC) ? "Start" : "Stop");
break;
case CMD_START_OBSESSING_OVER_HOST:
case CMD_STOP_OBSESSING_OVER_HOST:
snprintf(action, sizeof(action), "%s obsessing over these hosts", (cmd == CMD_START_OBSESSING_OVER_HOST) ? "Start" : "Stop");
break;
case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
snprintf(action, sizeof(action), "%s notifications for all services in a particular servicegroup", (cmd == CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS) ? "Enable" : "Disable");
break;
case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
snprintf(action, sizeof(action), "%s notifications for all hosts in a particular servicegroup", (cmd == CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS) ? "Enable" : "Disable");
break;
case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
snprintf(action, sizeof(action), "%s active checks of all services in a particular servicegroup", (cmd == CMD_ENABLE_SERVICEGROUP_SVC_CHECKS) ? "Enable" : "Disable");
break;
case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
snprintf(action, sizeof(action), "Schedule downtime for all hosts in a particular servicegroup");
break;
case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
snprintf(action, sizeof(action), "Schedule downtime for all services in a particular servicegroup");
break;
case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
snprintf(help_text, sizeof(help_text), "This command is used to send a custom notification about the specified %s. Useful in emergencies when you need to notify admins of an issue regarding a monitored system or service.", (cmd == CMD_SEND_CUSTOM_HOST_NOTIFICATION) ? "host" : "service");
snprintf(action, sizeof(action), "Send a custom %s notification", (cmd == CMD_SEND_CUSTOM_HOST_NOTIFICATION) ? "host" : "service");
break;
case CMD_CHANGE_HOST_MODATTR:
snprintf(action, sizeof(action), "Reset modified attributes for Host(s).");
break;
case CMD_CHANGE_SVC_MODATTR:
snprintf(action, sizeof(action), "Reset modified attributes for Service(s).");
break;
case CMD_INTERNAL_CHANGE_HOST_CHECK_RETRY_INTERVAL:
snprintf(action, sizeof(action), "Internal change of {check,retry}_interval and forced reschedule for Host(s).");
break;
case CMD_INTERNAL_CHANGE_SVC_CHECK_RETRY_INTERVAL:
snprintf(action, sizeof(action), "Internal change of {check,retry}_interval and forced reschedule for Service(s).");
break;
default:
print_generic_error_message("Sorry Dave, I can't let you do that...", "Executing an unknown command? Shame on you!", 2);
return;
}
help_text[sizeof(help_text)-1] = '\x0';
action[sizeof(action)-1] = '\x0';
/* Javascript to check input */
printf("\n");
printf("
\n");
printf("\n");
printf("
\n");
return;
}
void commit_command_data(int cmd) {
char error_string[MAX_INPUT_BUFFER];
service *temp_service;
host *temp_host;
hostgroup *temp_hostgroup;
comment *temp_comment;
scheduled_downtime *temp_downtime;
servicegroup *temp_servicegroup = NULL;
contact *temp_contact = NULL;
int x = 0;
int e = 0;
short error_found = FALSE;
short cmd_has_objects = FALSE;
short row_color = 0;
/* get authentication information */
get_authentication_information(¤t_authdata);
/* allways set the first element to FALSE*/
/* If there is a single COMMAND witch is not coverd correctly throught the following cases it won't get executed */
is_authorized[x] = FALSE;
/* get name to use for author */
if (lock_author_names == TRUE) {
temp_contact = find_contact(current_authdata.username);
if (temp_contact != NULL && temp_contact->alias != NULL)
comment_author = temp_contact->alias;
else
comment_author = current_authdata.username;
}
switch (cmd) {
case CMD_ADD_HOST_COMMENT:
case CMD_ADD_SVC_COMMENT:
case CMD_ACKNOWLEDGE_HOST_PROBLEM:
case CMD_ACKNOWLEDGE_SVC_PROBLEM:
case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
/* make sure we have author name, and comment data... */
check_comment_sanity(&e);
/* clean up the comment data */
clean_comment_data(comment_author);
clean_comment_data(comment_data);
if (use_ack_end_time == TRUE && (cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM || cmd == CMD_ACKNOWLEDGE_SVC_PROBLEM)) {
time(&start_time);
/* make sure we have end time if required */
check_time_sanity(&e);
} else
end_time = 0L;
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
cmd_has_objects = TRUE;
if (commands[x].host_name == NULL)
continue;
/* see if the user is authorized to issue a command... */
is_authorized[x] = FALSE;
if (cmd == CMD_ADD_HOST_COMMENT || cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM || cmd == CMD_SEND_CUSTOM_HOST_NOTIFICATION) {
temp_host = find_host(commands[x].host_name);
if (is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
} else {
temp_service = find_service(commands[x].host_name, commands[x].description);
if (is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
}
}
break;
case CMD_DEL_HOST_COMMENT:
case CMD_DEL_SVC_COMMENT:
if (enforce_comments_on_actions == TRUE) {
check_comment_sanity(&e);
clean_comment_data(comment_author);
clean_comment_data(comment_data);
}
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
cmd_has_objects = TRUE;
if (multi_ids[x] == FALSE)
continue;
/* check the sanity of the comment id */
if (multi_ids[x] == 0) {
error[e++].message = strdup("Comment id cannot be 0");
continue;
}
/* find the comment */
if (cmd == CMD_DEL_HOST_COMMENT)
temp_comment = find_host_comment(multi_ids[x]);
else
temp_comment = find_service_comment(multi_ids[x]);
/* see if the user is authorized to issue a command... */
is_authorized[x] = FALSE;
if (cmd == CMD_DEL_HOST_COMMENT && temp_comment != NULL) {
temp_host = find_host(temp_comment->host_name);
if (is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
}
if (cmd == CMD_DEL_SVC_COMMENT && temp_comment != NULL) {
temp_service = find_service(temp_comment->host_name, temp_comment->service_description);
if (is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
}
}
/* free comment data */
free_comment_data();
break;
case CMD_DEL_HOST_DOWNTIME:
case CMD_DEL_SVC_DOWNTIME:
if (enforce_comments_on_actions == TRUE) {
check_comment_sanity(&e);
clean_comment_data(comment_author);
clean_comment_data(comment_data);
}
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
cmd_has_objects = TRUE;
if (multi_ids[x] == FALSE)
continue;
/* check the sanity of the downtime id */
if (multi_ids[x] == 0) {
error[e++].message = strdup("Downtime id cannot be 0");
continue;
}
/* find the downtime entry */
if (cmd == CMD_DEL_HOST_DOWNTIME)
temp_downtime = find_host_downtime(multi_ids[x]);
else
temp_downtime = find_service_downtime(multi_ids[x]);
/* see if the user is authorized to issue a command... */
is_authorized[x] = FALSE;
if (cmd == CMD_DEL_HOST_DOWNTIME && temp_downtime != NULL) {
temp_host = find_host(temp_downtime->host_name);
if (is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
}
if (cmd == CMD_DEL_SVC_DOWNTIME && temp_downtime != NULL) {
temp_service = find_service(temp_downtime->host_name, temp_downtime->service_description);
if (is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
}
}
/* free downtime data */
free_downtime_data();
break;
case CMD_SCHEDULE_SVC_CHECK:
case CMD_ENABLE_SVC_CHECK:
case CMD_DISABLE_SVC_CHECK:
case CMD_DEL_ALL_SVC_COMMENTS:
case CMD_ENABLE_SVC_NOTIFICATIONS:
case CMD_DISABLE_SVC_NOTIFICATIONS:
case CMD_ENABLE_PASSIVE_SVC_CHECKS:
case CMD_DISABLE_PASSIVE_SVC_CHECKS:
case CMD_ENABLE_SVC_EVENT_HANDLER:
case CMD_DISABLE_SVC_EVENT_HANDLER:
case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
case CMD_PROCESS_SERVICE_CHECK_RESULT:
case CMD_SCHEDULE_SVC_DOWNTIME:
case CMD_DELAY_SVC_NOTIFICATION:
case CMD_ENABLE_SVC_FLAP_DETECTION:
case CMD_DISABLE_SVC_FLAP_DETECTION:
case CMD_START_OBSESSING_OVER_SVC:
case CMD_STOP_OBSESSING_OVER_SVC:
if (cmd == CMD_SCHEDULE_SVC_DOWNTIME || enforce_comments_on_actions == TRUE) {
/* make sure we have author and comment data */
check_comment_sanity(&e);
/* make sure we have start/end times for downtime */
if (cmd == CMD_SCHEDULE_SVC_DOWNTIME)
check_time_sanity(&e);
/* clean up the comment data if scheduling downtime */
clean_comment_data(comment_author);
clean_comment_data(comment_data);
}
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
cmd_has_objects = TRUE;
if (commands[x].host_name == NULL || commands[x].description == NULL)
continue;
is_authorized[x] = FALSE;
temp_service = find_service(commands[x].host_name, commands[x].description);
if (is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
}
/* make sure we have passive check info (if necessary) */
if (cmd == CMD_PROCESS_SERVICE_CHECK_RESULT && !strcmp(plugin_output, ""))
error[e++].message = strdup("Check output cannot be blank");
/* make sure we have a notification delay (if necessary) */
if (cmd == CMD_DELAY_SVC_NOTIFICATION && notification_delay <= 0)
error[e++].message = strdup("Notification delay must be greater than 0");
/* make sure we have check time (if necessary) */
if (cmd == CMD_SCHEDULE_SVC_CHECK && start_time == (time_t)0)
error[e++].message = strdup("Start time must be non-zero or bad format has been submitted");
break;
case CMD_ENABLE_NOTIFICATIONS:
case CMD_DISABLE_NOTIFICATIONS:
case CMD_SHUTDOWN_PROCESS:
case CMD_RESTART_PROCESS:
case CMD_START_EXECUTING_SVC_CHECKS:
case CMD_STOP_EXECUTING_SVC_CHECKS:
case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_ENABLE_EVENT_HANDLERS:
case CMD_DISABLE_EVENT_HANDLERS:
case CMD_START_OBSESSING_OVER_SVC_CHECKS:
case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
case CMD_ENABLE_FLAP_DETECTION:
case CMD_DISABLE_FLAP_DETECTION:
case CMD_ENABLE_FAILURE_PREDICTION:
case CMD_DISABLE_FAILURE_PREDICTION:
case CMD_ENABLE_PERFORMANCE_DATA:
case CMD_DISABLE_PERFORMANCE_DATA:
case CMD_START_EXECUTING_HOST_CHECKS:
case CMD_STOP_EXECUTING_HOST_CHECKS:
case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
case CMD_START_OBSESSING_OVER_HOST_CHECKS:
case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
if (use_disabled_notif_end_time == TRUE && cmd == CMD_DISABLE_NOTIFICATIONS) {
time(&start_time);
/* make sure we have end time if required */
check_time_sanity(&e);
} else
end_time = 0L;
if (enforce_comments_on_actions == TRUE) {
check_comment_sanity(&e);
clean_comment_data(comment_author);
clean_comment_data(comment_data);
}
/* see if the user is authorized to issue a command... */
is_authorized[x] = FALSE;
if (is_authorized_for_system_commands(¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
break;
case CMD_ENABLE_HOST_SVC_CHECKS:
case CMD_DISABLE_HOST_SVC_CHECKS:
case CMD_DEL_ALL_HOST_COMMENTS:
case CMD_SCHEDULE_HOST_SVC_CHECKS:
case CMD_ENABLE_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOST_NOTIFICATIONS:
case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
case CMD_ENABLE_HOST_EVENT_HANDLER:
case CMD_DISABLE_HOST_EVENT_HANDLER:
case CMD_ENABLE_HOST_CHECK:
case CMD_DISABLE_HOST_CHECK:
case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
case CMD_SCHEDULE_HOST_DOWNTIME:
case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
case CMD_DELAY_HOST_NOTIFICATION:
case CMD_ENABLE_HOST_FLAP_DETECTION:
case CMD_DISABLE_HOST_FLAP_DETECTION:
case CMD_PROCESS_HOST_CHECK_RESULT:
case CMD_ENABLE_PASSIVE_HOST_CHECKS:
case CMD_DISABLE_PASSIVE_HOST_CHECKS:
case CMD_SCHEDULE_HOST_CHECK:
case CMD_START_OBSESSING_OVER_HOST:
case CMD_STOP_OBSESSING_OVER_HOST:
case CMD_DEL_DOWNTIME_BY_HOST_NAME:
if (cmd == CMD_SCHEDULE_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOST_SVC_DOWNTIME || enforce_comments_on_actions == TRUE) {
/* make sure we have author and comment data */
check_comment_sanity(&e);
/* make sure we have start/end times for downtime */
if (cmd == CMD_SCHEDULE_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOST_SVC_DOWNTIME)
check_time_sanity(&e);
/* clean up the comment data if scheduling downtime */
clean_comment_data(comment_author);
clean_comment_data(comment_data);
}
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
cmd_has_objects = TRUE;
if (commands[x].host_name == NULL)
continue;
/* see if the user is authorized to issue a command... */
is_authorized[x] = FALSE;
temp_host = find_host(commands[x].host_name);
if (is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
}
/* make sure we have a notification delay (if necessary) */
if (cmd == CMD_DELAY_HOST_NOTIFICATION && notification_delay <= 0)
error[e++].message = strdup("Notification delay must be greater than 0");
/* make sure we have check time (if necessary) */
if ((cmd == CMD_SCHEDULE_HOST_CHECK || cmd == CMD_SCHEDULE_HOST_SVC_CHECKS) && start_time == (time_t)0)
error[e++].message = strdup("Start time must be non-zero or bad format has been submitted");
/* make sure we have passive check info (if necessary) */
if (cmd == CMD_PROCESS_HOST_CHECK_RESULT && !strcmp(plugin_output, ""))
error[e++].message = strdup("Check output cannot be blank");
break;
case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
if (cmd == CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME || cmd == CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME \
|| cmd == CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME) {
/* make sure we have author and comment data */
check_comment_sanity(&e);
/* make sure we have start/end times for downtime */
check_time_sanity(&e);
/* clean up the comment data if scheduling downtime */
clean_comment_data(comment_author);
clean_comment_data(comment_data);
} else if (enforce_comments_on_actions == TRUE) {
check_comment_sanity(&e);
clean_comment_data(comment_author);
clean_comment_data(comment_data);
}
/* see if the user is authorized to issue a command... */
is_authorized[x] = FALSE;
if (cmd == CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS || cmd == CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS || \
cmd == CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS || cmd == CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS || \
cmd == CMD_ENABLE_HOSTGROUP_SVC_CHECKS || cmd == CMD_DISABLE_HOSTGROUP_SVC_CHECKS || \
cmd == CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME) {
temp_hostgroup = find_hostgroup(hostgroup_name);
if (is_authorized_for_hostgroup_commands(temp_hostgroup, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
} else {
temp_servicegroup = find_servicegroup(servicegroup_name);
if (is_authorized_for_servicegroup_commands(temp_servicegroup, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
}
break;
case CMD_CHANGE_HOST_MODATTR:
case CMD_CHANGE_SVC_MODATTR:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
cmd_has_objects = TRUE;
if (commands[x].host_name == NULL)
continue;
/* see if the user is authorized to issue a command... */
is_authorized[x] = FALSE;
if (cmd == CMD_CHANGE_HOST_MODATTR) {
temp_host = find_host(commands[x].host_name);
if (is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
} else {
temp_service = find_service(commands[x].host_name, commands[x].description);
if (is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
}
/* do not allow other attributes than reset (0) */
if (attr != MODATTR_NONE) {
error[e++].message = strdup("You cannot change modified attributes other than reset them!");
}
}
break;
case CMD_INTERNAL_CHANGE_HOST_CHECK_RETRY_INTERVAL:
case CMD_INTERNAL_CHANGE_SVC_CHECK_RETRY_INTERVAL:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
cmd_has_objects = TRUE;
if (commands[x].host_name == NULL)
continue;
/* see if the user is authorized to issue a command... */
is_authorized[x] = FALSE;
if (cmd == CMD_INTERNAL_CHANGE_HOST_CHECK_RETRY_INTERVAL) {
temp_host = find_host(commands[x].host_name);
if (is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
} else {
temp_service = find_service(commands[x].host_name, commands[x].description);
if (is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
}
}
break;
default:
print_generic_error_message("Sorry Dave, I can't let you do that...", "Executing an unknown command? Shame on you!", 2);
return;
}
/*
* these are supposed to be implanted inside the
* completed commands shipped off to Icinga and
* must therefore never contain ';'
*/
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (strchr(commands[x].host_name, ';')) {
snprintf(error_string, sizeof(error_string), "The hostname \"%s\" contains a semicolon", commands[x].host_name);
error_string[sizeof(error_string)-1] = '\x0';
error[e++].message = (char *)strdup(error_string);
}
if (commands[x].description != NULL && strchr(commands[x].description, ';')) {
snprintf(error_string, sizeof(error_string), "The service description \"%s\" on host \"%s\" contains a semicolon", commands[x].description, commands[x].host_name);
error_string[sizeof(error_string)-1] = '\x0';
error[e++].message = strdup(error_string);
}
}
if (hostgroup_name && strchr(hostgroup_name, ';'))
error[e++].message = strdup("The hostgroup name contains a semicolon");
if (servicegroup_name && strchr(servicegroup_name, ';'))
error[e++].message = strdup("The servicegroup name contains a semicolon");
printf("
\n");
/* if Icinga isn't checking external commands, don't do anything... */
if (check_external_commands == FALSE) {
print_generic_error_message("Sorry, but Icinga is currently not checking for external commands, so your command will not be committed!", "Read the documentation for information on how to enable external commands...", 2);
return;
}
/* to be safe, we are going to REQUIRE that the authentication functionality is enabled... */
if (use_authentication == FALSE) {
print_generic_error_message("Sorry Dave, I can't let you do that...", "It seems that you have chosen to not use the authentication functionality of the CGIs. I don't want to be personally responsible for what may happen as a result of allowing unauthorized users to issue commands to Icinga, so you'll have to disable this safeguard if you are really stubborn and want to invite trouble. Read the section on CGI authentication in the HTML documentation to learn how you can enable authentication and why you should want to.", 2);
return;
}
/* Check if we found errors which preventing us from submiting the command */
if (e > 0) {
printf("
\n");
printf("
", url_images_path, CMD_STOP_ICON);
printf("
Following errors occured.
\n");
printf("
\n");
for (e = 0; e < NUMBER_OF_STRUCTS; e++) {
if (error[e].message == NULL)
continue;
printf("
ERROR:
%s
\n", error[e].message);
}
printf("
\n
\n");
printf(" \n");
printf("
\n");
printf("
\n");
printf("
\n");
printf("
");
return;
}
/* Let's see if we have a command which doesn't have any host, services or downtime/comment id's and check the authorisation */
if (cmd_has_objects == FALSE && is_authorized[0] == FALSE) {
print_generic_error_message("Sorry, but you are not authorized to commit the specified command.", "Read the section of the documentation that deals with authentication and authorization in the CGIs for more information.", 2);
return;
}
/* everything looks okay, so let's go ahead and commit the command... */
commit_command(cmd);
/* for commands without objects get the first result*/
if (cmd_has_objects == FALSE) {
if (submit_result[0] == OK) {
printf("
\n");
printf("
Your command request was successfully submitted to %s for processing.
\n", PROGRAM_NAME);
printf("Note: It may take a while before the command is actually processed.
\n");
printf("
\n");
printf("
\n");
} else {
print_generic_error_message("An error occurred while attempting to commit your command for processing.", "Unfortunately I can't determine the root cause of this problem.", 2);
}
} else {
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (cmd == CMD_DEL_HOST_COMMENT || cmd == CMD_DEL_SVC_COMMENT || cmd == CMD_DEL_HOST_DOWNTIME || cmd == CMD_DEL_SVC_DOWNTIME) {
if (multi_ids[x] == FALSE)
continue;
} else {
if (commands[x].host_name == NULL)
continue;
}
if (is_authorized[x] == FALSE || submit_result[x] == ERROR) {
error_found = TRUE;
break;
}
}
if (error_found) {
print_generic_error_message("An error occurred while attempting to commit your command for processing.", "Not all commands could be send off successfully...", 0);
} else {
printf("
\n");
printf("
Your command requests were successfully submitted to %s for processing.
\n", PROGRAM_NAME);
printf("Note: It may take a while before the commands are actually processed.
\n");
}
/* empty search string if regex compile failed */
if (search_regex_compile_failed == TRUE)
my_free(search_string);
/* see if user is authorized to view configuration information... */
if (is_authorized_for_configuration_information(¤t_authdata) == FALSE) {
print_generic_error_message("It appears as though you do not have permission to view the configuration information you requested...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
document_footer(CGI_ID);
return OK;
}
switch (display_type) {
case DISPLAY_HOSTS:
display_hosts();
break;
case DISPLAY_HOSTGROUPS:
display_hostgroups();
break;
case DISPLAY_SERVICEGROUPS:
display_servicegroups();
break;
case DISPLAY_CONTACTS:
display_contacts();
break;
case DISPLAY_CONTACTGROUPS:
display_contactgroups();
break;
case DISPLAY_SERVICES:
display_services();
break;
case DISPLAY_TIMEPERIODS:
display_timeperiods();
break;
case DISPLAY_COMMANDS:
display_commands();
break;
case DISPLAY_SERVICEDEPENDENCIES:
display_servicedependencies();
break;
case DISPLAY_SERVICEESCALATIONS:
display_serviceescalations();
break;
case DISPLAY_HOSTDEPENDENCIES:
display_hostdependencies();
break;
case DISPLAY_HOSTESCALATIONS:
display_hostescalations();
break;
case DISPLAY_COMMAND_EXPANSION:
display_command_expansion();
break;
case DISPLAY_MODULES:
display_modules();
break;
case DISPLAY_CGICONFIG:
display_cgiconfig();
break;
case DISPLAY_ALL:
if (content_type == JSON_CONTENT) {
display_hosts();
printf(",\n");
display_hostgroups();
printf(",\n");
display_servicegroups();
printf(",\n");
display_contacts();
printf(",\n");
display_contactgroups();
printf(",\n");
display_services();
printf(",\n");
display_timeperiods();
printf(",\n");
display_commands();
printf(",\n");
display_servicedependencies();
printf(",\n");
display_serviceescalations();
printf(",\n");
display_hostdependencies();
printf(",\n");
display_hostescalations();
printf(",\n");
display_modules();
printf(",\n");
display_cgiconfig();
break;
}
default:
if (content_type != CSV_CONTENT && content_type != JSON_CONTENT) {
printf("
\n");
printf("
Select Type of Config Data You Wish To View
\n");
printf("
\n");
printf("\n");
}
break;
}
/* regexec search string */
if (search_string != NULL) {
regfree(&search_preg);
my_free(search_string);
}
if (item_name != NULL)
my_free(item_name);
if (content_type == HTML_CONTENT && display_type != DISPLAY_NONE && display_type != DISPLAY_ALL && display_type != DISPLAY_COMMAND_EXPANSION && display_type != DISPLAY_CGICONFIG)
page_num_selector(result_start, total_entries, displayed_entries);
document_footer(CGI_ID);
return OK;
}
int process_cgivars(void) {
char **variables;
int error = FALSE;
int x;
variables = getcgivars();
to_expand[0] = '\0';
for (x = 0; variables[x] != NULL; x++) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */
if (strlen(variables[x]) >= MAX_INPUT_BUFFER - 1)
continue;
/* we found the search_string argument */
else if (!strcmp(variables[x], "search_string")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (strlen(variables[x]) != 0)
search_string = strdup(variables[x]);
}
/* we found the item_name argument */
else if (!strcmp(variables[x], "item_name")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (strlen(variables[x]) != 0)
item_name = strdup(variables[x]);
}
/* we found the host name */
else if (!strcmp(variables[x], "host")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
host_name = strdup(variables[x]);
if (host_name == NULL)
host_name = "";
strip_html_brackets(host_name);
}
/* we found the service name */
else if (!strcmp(variables[x], "service")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
service_desc = strdup(variables[x]);
if (service_desc == NULL)
service_desc = "";
strip_html_brackets(service_desc);
}
/* we found the configuration type argument */
else if (!strcmp(variables[x], "type")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
/* what information should we display? */
if (!strcmp(variables[x], "hosts"))
display_type = DISPLAY_HOSTS;
else if (!strcmp(variables[x], "hostgroups"))
display_type = DISPLAY_HOSTGROUPS;
else if (!strcmp(variables[x], "servicegroups"))
display_type = DISPLAY_SERVICEGROUPS;
else if (!strcmp(variables[x], "contacts"))
display_type = DISPLAY_CONTACTS;
else if (!strcmp(variables[x], "contactgroups"))
display_type = DISPLAY_CONTACTGROUPS;
else if (!strcmp(variables[x], "services"))
display_type = DISPLAY_SERVICES;
else if (!strcmp(variables[x], "timeperiods"))
display_type = DISPLAY_TIMEPERIODS;
else if (!strcmp(variables[x], "commands"))
display_type = DISPLAY_COMMANDS;
else if (!strcmp(variables[x], "servicedependencies"))
display_type = DISPLAY_SERVICEDEPENDENCIES;
else if (!strcmp(variables[x], "serviceescalations"))
display_type = DISPLAY_SERVICEESCALATIONS;
else if (!strcmp(variables[x], "hostdependencies"))
display_type = DISPLAY_HOSTDEPENDENCIES;
else if (!strcmp(variables[x], "hostescalations"))
display_type = DISPLAY_HOSTESCALATIONS;
else if (!strcmp(variables[x], "command"))
display_type = DISPLAY_COMMAND_EXPANSION;
else if (!strcmp(variables[x], "modules"))
display_type = DISPLAY_MODULES;
else if (!strcmp(variables[x], "cgiconfig"))
display_type = DISPLAY_CGICONFIG;
else if (!strcmp(variables[x], "all"))
display_type = DISPLAY_ALL;
/* we found the embed option */
else if (!strcmp(variables[x], "embedded"))
embedded = TRUE;
/* we found the nodaemoncheck option */
else if (!strcmp(variables[x], "nodaemoncheck"))
daemon_check = FALSE;
}
/* we found the string-to-expand argument */
else if (!strcmp(variables[x], "expand")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
strncpy(to_expand, variables[x], MAX_COMMAND_BUFFER);
to_expand[MAX_COMMAND_BUFFER - 1] = '\0';
}
/* we found the CSV output option */
else if (!strcmp(variables[x], "csvoutput")) {
display_header = FALSE;
content_type = CSV_CONTENT;
}
/* we found the JSON output option */
else if (!strcmp(variables[x], "jsonoutput")) {
display_header = FALSE;
content_type = JSON_CONTENT;
}
/* start num results to skip on displaying statusdata */
else if (!strcmp(variables[x], "start")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
result_start = atoi(variables[x]);
if (result_start < 1)
result_start = 1;
}
/* amount of results to display */
else if (!strcmp(variables[x], "limit")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
get_result_limit = atoi(variables[x]);
}
/* we received an invalid argument */
else
error = TRUE;
}
/* free memory allocated to the CGI variables */
free_cgivars(variables);
return error;
}
void display_hosts(void) {
host *temp_host = NULL;
hostsmember *temp_hostsmember = NULL;
contactsmember *temp_contactsmember = NULL;
contactgroupsmember *temp_contactgroupsmember = NULL;
char *processed_string = NULL;
int options = 0;
int odd = 0;
char time_string[2][16];
char *bg_class = "";
int contact = 0;
int json_start = TRUE;
if (content_type == JSON_CONTENT) {
printf("\"hosts\": [\n");
} else if (content_type == CSV_CONTENT) {
printf("%sHost Name%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sAlias/Description%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sDisplay Name%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sAddress%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sAddress6%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sParent Hosts%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sMax. Check Attempts%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sCheck Interval%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sRetry Interval%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sHost Check Command%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sCheck Period%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sObsess Over%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sEnable Active Checks%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sEnable Passive Checks%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sCheck Freshness%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sFreshness Threshold%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sDefault Contacts/Groups%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sNotification Interval%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sFirst Notification Delay%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sNotification Options%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sNotification Period%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sEvent Handler%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sEnable Event Handler%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sStalking Options%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sEnable Flap Detection%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sLow Flap Threshold%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sHigh Flap Threshold%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sFlap Detection Options%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sProcess Performance Data%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sEnable Failure Prediction%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sFailure Prediction Options%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sNotes%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sNotes URL%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sAction URL%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%s2-D Coords%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%s3-D Coords%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sStatusmap Image%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sVRML Image%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sLogo Image%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sImage Alt%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sRetention Options%s", csv_data_enclosure, csv_data_enclosure);
printf("\n");
} else {
printf("
\n");
printf("
\n");
printf("
Host Name
");
printf("
Alias/Description
");
printf("
Display Name
");
printf("
Address
");
printf("
Address6
");
printf("
Parent Hosts
");
printf("
Max. Check Attempts
");
printf("
Check Interval
\n");
printf("
Retry Interval
\n");
printf("
Host Check Command
");
printf("
Check Period
");
printf("
Obsess Over
\n");
printf("
Enable Active Checks
\n");
printf("
Enable Passive Checks
\n");
printf("
Check Freshness
\n");
printf("
Freshness Threshold
\n");
printf("
Default Contacts/Groups
\n");
printf("
Notification Interval
");
printf("
First Notification Delay
");
printf("
Notification Options
");
printf("
Notification Period
");
printf("
Event Handler
");
printf("
Enable Event Handler
");
printf("
Stalking Options
\n");
printf("
Enable Flap Detection
");
printf("
Low Flap Threshold
");
printf("
High Flap Threshold
");
printf("
Flap Detection Options
\n");
printf("
Process Performance Data
");
printf("
Enable Failure Prediction
");
printf("
Failure Prediction Options
");
printf("
Notes
");
printf("
Notes URL
");
printf("
Action URL
");
printf("
2-D Coords
");
printf("
3-D Coords
");
printf("
Statusmap Image
");
printf("
VRML Image
");
printf("
Logo Image
");
printf("
Image Alt
");
printf("
Retention Options
");
printf("
\n");
}
/* check all the hosts... */
for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
if (item_name != NULL && strcmp(item_name, temp_host->name) != 0)
continue;
/* try to find a match */
if (search_string != NULL && \
regexec(&search_preg, temp_host->name, 0, NULL, 0) != 0 && \
regexec(&search_preg, temp_host->display_name, 0, NULL, 0) != 0 && \
regexec(&search_preg, temp_host->alias, 0, NULL, 0) != 0 && \
regexec(&search_preg, temp_host->address, 0, NULL, 0) != 0 && \
regexec(&search_preg, temp_host->address6, 0, NULL, 0) != 0)
continue;
if (result_limit != 0 && (((total_entries + 1) < result_start) || (total_entries >= ((result_start + result_limit) - 1)))) {
total_entries++;
continue;
}
displayed_entries++;
total_entries++;
/* grab macros */
grab_host_macros_r(mac, temp_host);
if (odd) {
odd = 0;
bg_class = "dataOdd";
} else {
odd = 1;
bg_class = "dataEven";
}
/* print list in json format */
if (content_type == JSON_CONTENT) {
// always add a comma, except for the first line
if (json_start == FALSE)
printf(",\n");
json_start = FALSE;
printf("{ \"host_name\": \"%s\", ", json_encode(temp_host->name));
printf("\"alias\": \"%s\", ", json_encode(temp_host->alias));
printf("\"host_display_name\": \"%s\", ", json_encode(temp_host->display_name));
printf("\"address\": \"%s\", ", temp_host->address);
printf("\"address6\": \"%s\", ", temp_host->address6);
printf("\"parent_hosts\": [ ");
/* print list in csv format */
} else if (content_type == CSV_CONTENT) {
printf("%s%s%s%s", csv_data_enclosure, temp_host->name, csv_data_enclosure, csv_delimiter);
printf("%s%s%s%s", csv_data_enclosure, temp_host->alias, csv_data_enclosure, csv_delimiter);
printf("%s%s%s%s", csv_data_enclosure, temp_host->display_name, csv_data_enclosure, csv_delimiter);
printf("%s%s%s%s", csv_data_enclosure, temp_host->address, csv_data_enclosure, csv_delimiter);
printf("%s%s%s%s", csv_data_enclosure, temp_host->address6, csv_data_enclosure, csv_delimiter);
printf("%s", csv_data_enclosure);
} else {
printf("
", bg_class);
/* find all the hosts that are members of this hostgroup... */
for (temp_hostsmember = temp_hostgroup->members; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
if (temp_hostsmember != temp_hostgroup->members)
printf(", ");
printf("%s", CONFIG_CGI, url_encode(temp_hostsmember->host_name), html_encode(temp_hostsmember->host_name, FALSE));
}
printf("
\n", CONFIG_CGI, url_encode(temp_service->host_name), html_encode(temp_service->host_name, FALSE));
/* find a way to show display_name if set once */
printf("
\n");
else if (content_type == JSON_CONTENT)
printf("\n]\n");
return;
}
void display_cgiconfig(void) {
int odd = 0;
int json_start = TRUE;
char *temp_ptr;
/** BEGIN MACRO declaration */
/** @brief Macro to expand a config line with an integer value
* @param [in] var the var name with the value AFTER config file was parsed
* @param [in] org_var the var name with the value BEFORE config file was parsed
* name of org_var also determines the option name
* @param [in] type can be "int" or "bool"
* @warning It is important that the org_var var name is a concatenation of "org_"
* and the option name. i.E. option is called "foo_bar", then org_var
* MUST be named "org_foo_bar".
*
* Macro to print one config option of type int. "bool" adds TRUE & FALSE to HTML output
* and "int" prints just plain numbers
**/
#define PRINT_CONFIG_LINE_INT(var,org_var,type) \
/* prints a config line with type int */ \
if (content_type == JSON_CONTENT) { \
/* always add a comma, except for the first line */ \
if (json_start == FALSE) \
printf(",\n"); \
json_start = FALSE; \
printf("{ \"config_option_name\": \"%s\", ", json_encode(#org_var + 4)); \
if (!strcmp(type, "bool")) { \
printf("\"default_setting\": %s, ", (org_var == 1) ? "true" : "false"); \
printf("\"current_setting\": %s }", (var == 1) ? "true" : "false"); \
} else \
printf("\"default_setting\": %d, \"current_setting\": %d }", org_var, var); \
} else if (content_type == CSV_CONTENT) { \
printf("%s%s%s%s", csv_data_enclosure, #org_var + 4, csv_data_enclosure, csv_delimiter); \
printf("%s%d%s%s", csv_data_enclosure, org_var, csv_data_enclosure, csv_delimiter); \
printf("%s%d%s\n", csv_data_enclosure, var, csv_data_enclosure); \
} else { \
odd = (odd == 0) ? 1 : 0; \
if (!strcmp(type, "bool")) { \
printf("
\n", \
(odd == 0) ? "dataEven" : "dataOdd", #org_var + 4, org_var, (var != org_var) ? "class='dataDiff'" : "" , var); \
} \
}
/** @brief Macro to expand a config line with an char/string value
* @param [in] var the var name with the value AFTER config file was parsed
* @param [in] org_var the var name with the value BEFORE config file was parsed
* name of org_var also determines the option name
* @warning It is important that the org_var var name is a concatenation of "org_"
* and the option name. i.E. option is called "foo_bar", then org_var
* MUST be named "org_foo_bar".
*
* Macro to print one config option of type char.
**/
#define PRINT_CONFIG_LINE_STRING(var,org_var) \
/* prints a config line with type char */ \
if (content_type == JSON_CONTENT) { \
/* always add a comma, except for the first line */ \
if (json_start == FALSE) \
printf(",\n"); \
json_start = FALSE; \
printf("{ \"config_option_name\": \"%s\", ", json_encode(#org_var + 4)); \
printf("\"default_setting\": \"%s\", ", (strlen(org_var) == 0) ? "" : json_encode(org_var)); \
printf("\"current_setting\": \"%s\" }", (strlen(var) == 0) ? "" : json_encode(var)); \
} else if (content_type == CSV_CONTENT) { \
printf("%s%s%s%s", csv_data_enclosure, #org_var + 4, csv_data_enclosure, csv_delimiter); \
printf("%s%s%s%s", csv_data_enclosure, org_var, csv_data_enclosure, csv_delimiter); \
printf("%s%s%s\n", csv_data_enclosure, var, csv_data_enclosure); \
} else { \
odd = (odd == 0) ? 1 : 0; \
printf("
%s
%s
%s
\n", \
(odd == 0) ? "dataEven" : "dataOdd", #org_var + 4, (strlen(org_var) == 0) ? "<EMPTY>" : html_encode(org_var, FALSE), \
(!strcmp(var, org_var)) ? "" : "class='dataDiff'", (strlen(var) == 0) ? "<EMPTY>" : html_encode(var, FALSE)); \
}
/** @brief Macro to expand a config line with authentication information
*
* this macro creates links to the contact and contactgroup information
**/
#define PRINT_CONFIG_LINE_AUTH(var,org_var) \
/* prints a config line with type char and authorization information */ \
if (content_type == JSON_CONTENT || content_type == CSV_CONTENT) { \
PRINT_CONFIG_LINE_STRING(var,org_var) \
} else { \
odd = (odd == 0) ? 1 : 0; \
printf("
");
} else
printf(" \n");
}
if (display_type == DISPLAY_HOST_INFO) {
if (content_type == CSV_CONTENT) {
if (csv_type == CSV_COMMENT)
show_comments(HOST_COMMENT);
else if (csv_type == CSV_DOWNTIME)
show_downtime(HOST_DOWNTIME);
else
printf("Please specify the correct csvtype! possible is \"csvtype=comment\" or \"csv_type=downtime\".\n");
} else
show_host_info();
} else if (display_type == DISPLAY_SERVICE_INFO) {
if (content_type == CSV_CONTENT) {
if (csv_type == CSV_COMMENT)
show_comments(SERVICE_COMMENT);
else if (csv_type == CSV_DOWNTIME)
show_downtime(SERVICE_DOWNTIME);
else
printf("Please specify the correct csvtype! possible is \"csvtype=comment\" or \"csv_type=downtime\".\n");
} else
show_service_info();
} else if (display_type == DISPLAY_COMMENTS) {
if (is_authorized_for_read_only(¤t_authdata) == TRUE && is_authorized_for_comments_read_only(¤t_authdata) == FALSE)
printf("
Your account does not have permissions to view comments. \n");
else {
if (content_type == CSV_CONTENT || content_type == JSON_CONTENT) {
show_comments(HOST_COMMENT);
if (content_type == JSON_CONTENT)
printf(",\n");
show_comments(SERVICE_COMMENT);
} else {
printf(" \n");
printf("
Your account does not have permissions to view downtimes. \n");
else {
if (content_type == CSV_CONTENT || content_type == JSON_CONTENT) {
show_downtime(HOST_DOWNTIME);
if (content_type == JSON_CONTENT)
printf(",\n");
show_downtime(SERVICE_DOWNTIME);
} else {
printf(" \n");
printf("
\n");
}
return;
}
void show_hostgroup_info(void) {
hostgroup *temp_hostgroup;
/* get hostgroup info */
temp_hostgroup = find_hostgroup(hostgroup_name);
/* make sure the user has rights to view hostgroup information */
if (is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == FALSE) {
print_generic_error_message("It appears as though you do not have permission to view information for this hostgroup...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
return;
}
/* make sure hostgroup information exists */
if (temp_hostgroup == NULL) {
print_generic_error_message("Error: Hostgroup Not Found!", NULL, 0);
return;
}
printf("
Hostgroup Commands
\n");
if (is_authorized_for_read_only(¤t_authdata) == FALSE) {
printf("
\n");
} else {
print_generic_error_message("Your account does not have permissions to execute commands.", NULL, 0);
}
return;
}
void show_servicegroup_info() {
servicegroup *temp_servicegroup;
/* get servicegroup info */
temp_servicegroup = find_servicegroup(servicegroup_name);
/* make sure the user has rights to view servicegroup information */
if (is_authorized_for_servicegroup(temp_servicegroup, ¤t_authdata) == FALSE) {
print_generic_error_message("It appears as though you do not have permission to view information for this servicegroup...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
return;
}
/* make sure servicegroup information exists */
if (temp_servicegroup == NULL) {
print_generic_error_message("Error: Servicegroup Not Found!", NULL, 0);
return;
}
printf("
Servicegroup Commands
\n");
if (is_authorized_for_read_only(¤t_authdata) == FALSE) {
printf("
\n");
} else {
print_generic_error_message("Your account does not have permissions to execute commands.", NULL, 0);
}
return;
}
void show_performance_data(void) {
service *temp_service = NULL;
servicestatus *temp_servicestatus = NULL;
host *temp_host = NULL;
hoststatus *temp_hoststatus = NULL;
int total_active_service_checks = 0;
int total_passive_service_checks = 0;
double min_service_execution_time = 0.0;
double max_service_execution_time = 0.0;
double total_service_execution_time = 0.0;
int have_min_service_execution_time = FALSE;
int have_max_service_execution_time = FALSE;
double min_service_latency = 0.0;
double max_service_latency = 0.0;
double long total_service_latency = 0.0;
int have_min_service_latency = FALSE;
int have_max_service_latency = FALSE;
double min_host_latency = 0.0;
double max_host_latency = 0.0;
double total_host_latency = 0.0;
int have_min_host_latency = FALSE;
int have_max_host_latency = FALSE;
double min_service_percent_change_a = 0.0;
double max_service_percent_change_a = 0.0;
double total_service_percent_change_a = 0.0;
int have_min_service_percent_change_a = FALSE;
int have_max_service_percent_change_a = FALSE;
double min_service_percent_change_b = 0.0;
double max_service_percent_change_b = 0.0;
double total_service_percent_change_b = 0.0;
int have_min_service_percent_change_b = FALSE;
int have_max_service_percent_change_b = FALSE;
int active_service_checks_1min = 0;
int active_service_checks_5min = 0;
int active_service_checks_15min = 0;
int active_service_checks_1hour = 0;
int active_service_checks_start = 0;
int active_service_checks_ever = 0;
int passive_service_checks_1min = 0;
int passive_service_checks_5min = 0;
int passive_service_checks_15min = 0;
int passive_service_checks_1hour = 0;
int passive_service_checks_start = 0;
int passive_service_checks_ever = 0;
int total_active_host_checks = 0;
int total_passive_host_checks = 0;
double min_host_execution_time = 0.0;
double max_host_execution_time = 0.0;
double total_host_execution_time = 0.0;
int have_min_host_execution_time = FALSE;
int have_max_host_execution_time = FALSE;
double min_host_percent_change_a = 0.0;
double max_host_percent_change_a = 0.0;
double total_host_percent_change_a = 0.0;
int have_min_host_percent_change_a = FALSE;
int have_max_host_percent_change_a = FALSE;
double min_host_percent_change_b = 0.0;
double max_host_percent_change_b = 0.0;
double total_host_percent_change_b = 0.0;
int have_min_host_percent_change_b = FALSE;
int have_max_host_percent_change_b = FALSE;
int active_host_checks_1min = 0;
int active_host_checks_5min = 0;
int active_host_checks_15min = 0;
int active_host_checks_1hour = 0;
int active_host_checks_start = 0;
int active_host_checks_ever = 0;
int passive_host_checks_1min = 0;
int passive_host_checks_5min = 0;
int passive_host_checks_15min = 0;
int passive_host_checks_1hour = 0;
int passive_host_checks_start = 0;
int passive_host_checks_ever = 0;
time_t current_time;
time(¤t_time);
/* check all services */
for (temp_servicestatus = servicestatus_list; temp_servicestatus != NULL; temp_servicestatus = temp_servicestatus->next) {
/* find the service */
temp_service = find_service(temp_servicestatus->host_name, temp_servicestatus->description);
/* make sure the user has rights to view service information */
if (is_authorized_for_service(temp_service, ¤t_authdata) == FALSE)
continue;
/* is this an active or passive check? */
if (temp_servicestatus->checks_enabled == TRUE) {
total_active_service_checks++;
total_service_execution_time += temp_servicestatus->execution_time;
if (have_min_service_execution_time == FALSE || temp_servicestatus->execution_time < min_service_execution_time) {
have_min_service_execution_time = TRUE;
min_service_execution_time = temp_servicestatus->execution_time;
}
if (have_max_service_execution_time == FALSE || temp_servicestatus->execution_time > max_service_execution_time) {
have_max_service_execution_time = TRUE;
max_service_execution_time = temp_servicestatus->execution_time;
}
total_service_percent_change_a += temp_servicestatus->percent_state_change;
if (have_min_service_percent_change_a == FALSE || temp_servicestatus->percent_state_change < min_service_percent_change_a) {
have_min_service_percent_change_a = TRUE;
min_service_percent_change_a = temp_servicestatus->percent_state_change;
}
if (have_max_service_percent_change_a == FALSE || temp_servicestatus->percent_state_change > max_service_percent_change_a) {
have_max_service_percent_change_a = TRUE;
max_service_percent_change_a = temp_servicestatus->percent_state_change;
}
total_service_latency += temp_servicestatus->latency;
if (have_min_service_latency == FALSE || temp_servicestatus->latency < min_service_latency) {
have_min_service_latency = TRUE;
min_service_latency = temp_servicestatus->latency;
}
if (have_max_service_latency == FALSE || temp_servicestatus->latency > max_service_latency) {
have_max_service_latency = TRUE;
max_service_latency = temp_servicestatus->latency;
}
if (temp_servicestatus->last_check >= (current_time - 60))
active_service_checks_1min++;
if (temp_servicestatus->last_check >= (current_time - 300))
active_service_checks_5min++;
if (temp_servicestatus->last_check >= (current_time - 900))
active_service_checks_15min++;
if (temp_servicestatus->last_check >= (current_time - 3600))
active_service_checks_1hour++;
if (temp_servicestatus->last_check >= program_start)
active_service_checks_start++;
if (temp_servicestatus->last_check != (time_t)0)
active_service_checks_ever++;
} else if (temp_servicestatus->accept_passive_service_checks == TRUE) {
total_passive_service_checks++;
total_service_percent_change_b += temp_servicestatus->percent_state_change;
if (have_min_service_percent_change_b == FALSE || temp_servicestatus->percent_state_change < min_service_percent_change_b) {
have_min_service_percent_change_b = TRUE;
min_service_percent_change_b = temp_servicestatus->percent_state_change;
}
if (have_max_service_percent_change_b == FALSE || temp_servicestatus->percent_state_change > max_service_percent_change_b) {
have_max_service_percent_change_b = TRUE;
max_service_percent_change_b = temp_servicestatus->percent_state_change;
}
if (temp_servicestatus->last_check >= (current_time - 60))
passive_service_checks_1min++;
if (temp_servicestatus->last_check >= (current_time - 300))
passive_service_checks_5min++;
if (temp_servicestatus->last_check >= (current_time - 900))
passive_service_checks_15min++;
if (temp_servicestatus->last_check >= (current_time - 3600))
passive_service_checks_1hour++;
if (temp_servicestatus->last_check >= program_start)
passive_service_checks_start++;
if (temp_servicestatus->last_check != (time_t)0)
passive_service_checks_ever++;
}
}
/* check all hosts */
for (temp_hoststatus = hoststatus_list; temp_hoststatus != NULL; temp_hoststatus = temp_hoststatus->next) {
/* find the host */
temp_host = find_host(temp_hoststatus->host_name);
/* make sure the user has rights to view host information */
if (is_authorized_for_host(temp_host, ¤t_authdata) == FALSE)
continue;
/* is this an active or passive check? */
if (temp_hoststatus->check_type == HOST_CHECK_ACTIVE) {
total_active_host_checks++;
total_host_execution_time += temp_hoststatus->execution_time;
if (have_min_host_execution_time == FALSE || temp_hoststatus->execution_time < min_host_execution_time) {
have_min_host_execution_time = TRUE;
min_host_execution_time = temp_hoststatus->execution_time;
}
if (have_max_host_execution_time == FALSE || temp_hoststatus->execution_time > max_host_execution_time) {
have_max_host_execution_time = TRUE;
max_host_execution_time = temp_hoststatus->execution_time;
}
total_host_percent_change_a += temp_hoststatus->percent_state_change;
if (have_min_host_percent_change_a == FALSE || temp_hoststatus->percent_state_change < min_host_percent_change_a) {
have_min_host_percent_change_a = TRUE;
min_host_percent_change_a = temp_hoststatus->percent_state_change;
}
if (have_max_host_percent_change_a == FALSE || temp_hoststatus->percent_state_change > max_host_percent_change_a) {
have_max_host_percent_change_a = TRUE;
max_host_percent_change_a = temp_hoststatus->percent_state_change;
}
total_host_latency += temp_hoststatus->latency;
if (have_min_host_latency == FALSE || temp_hoststatus->latency < min_host_latency) {
have_min_host_latency = TRUE;
min_host_latency = temp_hoststatus->latency;
}
if (have_max_host_latency == FALSE || temp_hoststatus->latency > max_host_latency) {
have_max_host_latency = TRUE;
max_host_latency = temp_hoststatus->latency;
}
if (temp_hoststatus->last_check >= (current_time - 60))
active_host_checks_1min++;
if (temp_hoststatus->last_check >= (current_time - 300))
active_host_checks_5min++;
if (temp_hoststatus->last_check >= (current_time - 900))
active_host_checks_15min++;
if (temp_hoststatus->last_check >= (current_time - 3600))
active_host_checks_1hour++;
if (temp_hoststatus->last_check >= program_start)
active_host_checks_start++;
if (temp_hoststatus->last_check != (time_t)0)
active_host_checks_ever++;
}
else {
total_passive_host_checks++;
total_host_percent_change_b += temp_hoststatus->percent_state_change;
if (have_min_host_percent_change_b == FALSE || temp_hoststatus->percent_state_change < min_host_percent_change_b) {
have_min_host_percent_change_b = TRUE;
min_host_percent_change_b = temp_hoststatus->percent_state_change;
}
if (have_max_host_percent_change_b == FALSE || temp_hoststatus->percent_state_change > max_host_percent_change_b) {
have_max_host_percent_change_b = TRUE;
max_host_percent_change_b = temp_hoststatus->percent_state_change;
}
if (temp_hoststatus->last_check >= (current_time - 60))
passive_host_checks_1min++;
if (temp_hoststatus->last_check >= (current_time - 300))
passive_host_checks_5min++;
if (temp_hoststatus->last_check >= (current_time - 900))
passive_host_checks_15min++;
if (temp_hoststatus->last_check >= (current_time - 3600))
passive_host_checks_1hour++;
if (temp_hoststatus->last_check >= program_start)
passive_host_checks_start++;
if (temp_hoststatus->last_check != (time_t)0)
passive_host_checks_ever++;
}
}
if (content_type == JSON_CONTENT) {
printf("\"performance_data\": {\n");
printf("\"active_service_checks_1min_num\": %d,\n", active_service_checks_1min);
printf("\"active_service_checks_1min_percent\": \"%.1f%%\",\n", (double)(((double)active_service_checks_1min * 100.0) / (double)total_active_service_checks));
printf("\"active_service_checks_15min_num\": %d,\n", active_service_checks_15min);
printf("\"active_service_checks_15min_percent\": \"%.1f%%\",\n", (double)(((double)active_service_checks_15min * 100.0) / (double)total_active_service_checks));
printf("\"active_service_checks_1hour_num\": %d,\n", active_service_checks_1hour);
printf("\"active_service_checks_1hour_percent\": \"%.1f%%\",\n", (double)(((double)active_service_checks_1hour * 100.0) / (double)total_active_service_checks));
printf("\"active_service_checks_since_start_num\": %d,\n", active_service_checks_start);
printf("\"active_service_checks_since_start_percent\": \"%.1f%%\",\n", (double)(((double)active_service_checks_start * 100.0) / (double)total_active_service_checks));
printf("\"active_service_min_execution_time\": \"%.2f sec\",\n", min_service_execution_time);
printf("\"active_service_max_execution_time\": \"%.2f sec\",\n", max_service_execution_time);
printf("\"active_service_average_execution_time\": \"%.3f sec\",\n", (double)((double)total_service_execution_time / (double)total_active_service_checks));
printf("\"active_service_min_latency\": \"%.2f sec\",\n", min_service_latency);
printf("\"active_service_max_latency\": \"%.2f sec\",\n", max_service_latency);
printf("\"active_service_average_latency\": \"%.3f sec\",\n", (double)((double)total_service_latency / (double)total_active_service_checks));
printf("\"active_service_min_percent_change\": \"%.2f sec\",\n", min_service_percent_change_a);
printf("\"active_service_max_percent_change\": \"%.2f sec\",\n", max_service_percent_change_a);
printf("\"active_service_average_percent_change\": \"%.2f sec\",\n", (double)((double)total_service_percent_change_a / (double)total_active_service_checks));
printf("\"passive_service_checks_1min_num\": %d,\n", passive_service_checks_1min);
printf("\"passive_service_checks_1min_percent\": \"%.1f%%\",\n", (double)(((double)passive_service_checks_1min * 100.0) / (double)total_passive_service_checks));
printf("\"passive_service_checks_15min_num\": %d,\n", passive_service_checks_15min);
printf("\"passive_service_checks_15min_percent\": \"%.1f%%\",\n", (double)(((double)passive_service_checks_15min * 100.0) / (double)total_passive_service_checks));
printf("\"passive_service_checks_1hour_num\": %d,\n", passive_service_checks_1hour);
printf("\"passive_service_checks_1hour_percent\": \"%.1f%%\",\n", (double)(((double)passive_service_checks_1hour * 100.0) / (double)total_passive_service_checks));
printf("\"passive_service_checks_since_start_num\": %d,\n", passive_service_checks_start);
printf("\"passive_service_checks_since_start_percent\": \"%.1f%%\",\n", (double)(((double)passive_service_checks_start * 100.0) / (double)total_passive_service_checks));
printf("\"passive_service_min_percent_change\": \"%.2f sec\",\n", min_service_percent_change_b);
printf("\"passive_service_max_percent_change\": \"%.2f sec\",\n", max_service_percent_change_b);
printf("\"passive_service_average_percent_change\": \"%.2f sec\",\n", (double)((double)total_service_percent_change_b / (double)total_passive_service_checks));
printf("\"active_host_checks_1min_num\": %d,\n", active_host_checks_1min);
printf("\"active_host_checks_1min_percent\": \"%.1f%%\",\n", (double)(((double)active_host_checks_1min * 100.0) / (double)total_active_host_checks));
printf("\"active_host_checks_15min_num\": %d,\n", active_host_checks_15min);
printf("\"active_host_checks_15min_percent\": \"%.1f%%\",\n", (double)(((double)active_host_checks_15min * 100.0) / (double)total_active_host_checks));
printf("\"active_host_checks_1hour_num\": %d,\n", active_host_checks_1hour);
printf("\"active_host_checks_1hour_percent\": \"%.1f%%\",\n", (double)(((double)active_host_checks_1hour * 100.0) / (double)total_active_host_checks));
printf("\"active_host_checks_since_start_num\": %d,\n", active_host_checks_start);
printf("\"active_host_checks_since_start_percent\": \"%.1f%%\",\n", (double)(((double)active_host_checks_start * 100.0) / (double)total_active_host_checks));
printf("\"active_host_min_execution_time\": \"%.2f sec\",\n", min_host_execution_time);
printf("\"active_host_max_execution_time\": \"%.2f sec\",\n", max_host_execution_time);
printf("\"active_host_average_execution_time\": \"%.3f sec\",\n", (double)((double)total_host_execution_time / (double)total_active_host_checks));
printf("\"active_host_min_latency\": \"%.2f sec\",\n", min_host_latency);
printf("\"active_host_max_latency\": \"%.2f sec\",\n", max_host_latency);
printf("\"active_host_average_latency\": \"%.3f sec\",\n", (double)((double)total_host_latency / (double)total_active_host_checks));
printf("\"active_host_min_percent_change\": \"%.2f sec\",\n", min_host_percent_change_a);
printf("\"active_host_max_percent_change\": \"%.2f sec\",\n", max_host_percent_change_a);
printf("\"active_host_average_percent_change\": \"%.2f sec\",\n", (double)((double)total_host_percent_change_a / (double)total_active_host_checks));
printf("\"passive_host_checks_1min_num\": %d,\n", passive_host_checks_1min);
printf("\"passive_host_checks_1min_percent\": \"%.1f%%\",\n", (double)(((double)passive_host_checks_1min * 100.0) / (double)total_passive_host_checks));
printf("\"passive_host_checks_15min_num\": %d,\n", passive_host_checks_15min);
printf("\"passive_host_checks_15min_percent\": \"%.1f%%\",\n", (double)(((double)passive_host_checks_15min * 100.0) / (double)total_passive_host_checks));
printf("\"passive_host_checks_1hour_num\": %d,\n", passive_host_checks_1hour);
printf("\"passive_host_checks_1hour_percent\": \"%.1f%%\",\n", (double)(((double)passive_host_checks_1hour * 100.0) / (double)total_passive_host_checks));
printf("\"passive_host_checks_since_start_num\": %d,\n", passive_host_checks_start);
printf("\"passive_host_checks_since_start_percent\": \"%.1f%%\",\n", (double)(((double)passive_host_checks_start * 100.0) / (double)total_passive_host_checks));
printf("\"passive_host_min_percent_change\": \"%.2f sec\",\n", min_host_percent_change_b);
printf("\"passive_host_max_percent_change\": \"%.2f sec\",\n", max_host_percent_change_b);
printf("\"passive_host_average_percent_change\": \"%.2f sec\",\n", (double)((double)total_host_percent_change_b / (double)total_passive_host_checks));
printf("\"active_scheduled_host_checks_1min\": %d,\n", program_stats[ACTIVE_SCHEDULED_HOST_CHECK_STATS][0]);
printf("\"active_scheduled_host_checks_5min\": %d,\n", program_stats[ACTIVE_SCHEDULED_HOST_CHECK_STATS][1]);
printf("\"active_scheduled_host_checks_15min\": %d,\n", program_stats[ACTIVE_SCHEDULED_HOST_CHECK_STATS][2]);
printf("\"active_on_demand_host_checks_1min\": %d,\n", program_stats[ACTIVE_ONDEMAND_HOST_CHECK_STATS][0]);
printf("\"active_on_demand_host_checks_5min\": %d,\n", program_stats[ACTIVE_ONDEMAND_HOST_CHECK_STATS][1]);
printf("\"active_on_demand_host_checks_15min\": %d,\n", program_stats[ACTIVE_ONDEMAND_HOST_CHECK_STATS][2]);
printf("\"parallel_host_checks_1min\": %d,\n", program_stats[PARALLEL_HOST_CHECK_STATS][0]);
printf("\"parallel_host_checks_5min\": %d,\n", program_stats[PARALLEL_HOST_CHECK_STATS][1]);
printf("\"parallel_host_checks_15min\": %d,\n", program_stats[PARALLEL_HOST_CHECK_STATS][2]);
printf("\"serial_host_checks_1min\": %d,\n", program_stats[SERIAL_HOST_CHECK_STATS][0]);
printf("\"serial_host_checks_5min\": %d,\n", program_stats[SERIAL_HOST_CHECK_STATS][1]);
printf("\"serial_host_checks_15min\": %d,\n", program_stats[SERIAL_HOST_CHECK_STATS][2]);
printf("\"cached_host_checks_1min\": %d,\n", program_stats[ACTIVE_CACHED_HOST_CHECK_STATS][0]);
printf("\"cached_host_checks_5min\": %d,\n", program_stats[ACTIVE_CACHED_HOST_CHECK_STATS][1]);
printf("\"cached_host_checks_15min\": %d,\n", program_stats[ACTIVE_CACHED_HOST_CHECK_STATS][2]);
printf("\"passive_host_checks_1min\": %d,\n", program_stats[PASSIVE_HOST_CHECK_STATS][0]);
printf("\"passive_host_checks_5min\": %d,\n", program_stats[PASSIVE_HOST_CHECK_STATS][1]);
printf("\"passive_host_checks_15min\": %d,\n", program_stats[PASSIVE_HOST_CHECK_STATS][2]);
printf("\"active_scheduled_service_checks_1min\": %d,\n", program_stats[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS][0]);
printf("\"active_scheduled_service_checks_5min\": %d,\n", program_stats[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS][1]);
printf("\"active_scheduled_service_checks_15min\": %d,\n", program_stats[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS][2]);
printf("\"active_on_demand_service_checks_1min\": %d,\n", program_stats[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS][0]);
printf("\"active_on_demand_service_checks_5min\": %d,\n", program_stats[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS][1]);
printf("\"active_on_demand_service_checks_15min\": %d,\n", program_stats[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS][2]);
printf("\"cached_service_checks_1min\": %d,\n", program_stats[ACTIVE_CACHED_SERVICE_CHECK_STATS][0]);
printf("\"cached_service_checks_5min\": %d,\n", program_stats[ACTIVE_CACHED_SERVICE_CHECK_STATS][1]);
printf("\"cached_service_checks_15min\": %d,\n", program_stats[ACTIVE_CACHED_SERVICE_CHECK_STATS][2]);
printf("\"passive_service_checks_1min\": %d,\n", program_stats[PASSIVE_SERVICE_CHECK_STATS][0]);
printf("\"passive_service_checks_5min\": %d,\n", program_stats[PASSIVE_SERVICE_CHECK_STATS][1]);
printf("\"passive_service_checks_15min\": %d,\n", program_stats[PASSIVE_SERVICE_CHECK_STATS][2]);
printf("\"external_commands_1min\": %d,\n", program_stats[EXTERNAL_COMMAND_STATS][0]);
printf("\"external_commands_5min\": %d,\n", program_stats[EXTERNAL_COMMAND_STATS][1]);
printf("\"external_commands_15min\": %d,\n", program_stats[EXTERNAL_COMMAND_STATS][2]);
printf("\"external_command_buffer_in_use\": %d,\n", buffer_stats[0][1]);
printf("\"external_command_buffer_max_used\": %d,\n", buffer_stats[0][2]);
printf("\"external_command_buffer_total_available\": %d\n", buffer_stats[0][0]);
printf("}\n");
return;
}
printf("
\n");
printf("
Program-Wide Performance Information
\n");
printf("
\n");
/***** ACTIVE SERVICE CHECKS *****/
printf("
\n");
printf("
Services Actively Checked:
\n");
printf("
\n");
/* fake this so we don't divide by zero for just showing the table */
if (total_active_service_checks == 0)
total_active_service_checks = 1;
printf("
\n");
/***** PASSIVE SERVICE CHECKS *****/
printf("
\n");
printf("
Services Passively Checked:
\n");
printf("
\n");
/* fake this so we don't divide by zero for just showing the table */
if (total_passive_service_checks == 0)
total_passive_service_checks = 1;
printf("
\n");
/* fake this so we don't divide by zero for just showing the table */
if (total_passive_host_checks == 0)
total_passive_host_checks = 1;
printf("
\n");
} else if (content_type == JSON_CONTENT)
printf(" ] \n");
/* free memory allocated to sorted data list */
free_sortdata_list();
return;
}
/* sorts host and service data */
int sort_data(int s_type, int s_option) {
sortdata *new_sortdata;
sortdata *last_sortdata;
sortdata *temp_sortdata;
servicestatus *temp_svcstatus;
hoststatus *temp_hststatus;
if (s_type == SORT_NONE)
return ERROR;
/* sort all service status entries */
for (temp_svcstatus = servicestatus_list; temp_svcstatus != NULL; temp_svcstatus = temp_svcstatus->next) {
/* allocate memory for a new sort structure */
new_sortdata = (sortdata *)malloc(sizeof(sortdata));
if (new_sortdata == NULL)
return ERROR;
new_sortdata->is_service = TRUE;
new_sortdata->svcstatus = temp_svcstatus;
new_sortdata->hststatus = NULL;
last_sortdata = sortdata_list;
for (temp_sortdata = sortdata_list; temp_sortdata != NULL; temp_sortdata = temp_sortdata->next) {
if (compare_sortdata_entries(s_type, s_option, new_sortdata, temp_sortdata) == TRUE) {
new_sortdata->next = temp_sortdata;
if (temp_sortdata == sortdata_list)
sortdata_list = new_sortdata;
else
last_sortdata->next = new_sortdata;
break;
} else
last_sortdata = temp_sortdata;
}
if (sortdata_list == NULL) {
new_sortdata->next = NULL;
sortdata_list = new_sortdata;
} else if (temp_sortdata == NULL) {
new_sortdata->next = NULL;
last_sortdata->next = new_sortdata;
}
}
/* sort all host status entries */
for (temp_hststatus = hoststatus_list; temp_hststatus != NULL; temp_hststatus = temp_hststatus->next) {
/* allocate memory for a new sort structure */
new_sortdata = (sortdata *)malloc(sizeof(sortdata));
if (new_sortdata == NULL)
return ERROR;
new_sortdata->is_service = FALSE;
new_sortdata->svcstatus = NULL;
new_sortdata->hststatus = temp_hststatus;
last_sortdata = sortdata_list;
for (temp_sortdata = sortdata_list; temp_sortdata != NULL; temp_sortdata = temp_sortdata->next) {
if (compare_sortdata_entries(s_type, s_option, new_sortdata, temp_sortdata) == TRUE) {
new_sortdata->next = temp_sortdata;
if (temp_sortdata == sortdata_list)
sortdata_list = new_sortdata;
else
last_sortdata->next = new_sortdata;
break;
} else
last_sortdata = temp_sortdata;
}
if (sortdata_list == NULL) {
new_sortdata->next = NULL;
sortdata_list = new_sortdata;
} else if (temp_sortdata == NULL) {
new_sortdata->next = NULL;
last_sortdata->next = new_sortdata;
}
}
return OK;
}
int compare_sortdata_entries(int s_type, int s_option, sortdata *new_sortdata, sortdata *temp_sortdata) {
hoststatus *temp_hststatus = NULL;
servicestatus *temp_svcstatus = NULL;
time_t last_check[2];
time_t next_check[2];
int current_attempt[2];
int status[2];
char *host_name[2];
char *service_description[2];
if (new_sortdata->is_service == TRUE) {
temp_svcstatus = new_sortdata->svcstatus;
last_check[0] = temp_svcstatus->last_check;
next_check[0] = temp_svcstatus->next_check;
status[0] = temp_svcstatus->status;
host_name[0] = temp_svcstatus->host_name;
service_description[0] = temp_svcstatus->description;
current_attempt[0] = temp_svcstatus->current_attempt;
} else {
temp_hststatus = new_sortdata->hststatus;
last_check[0] = temp_hststatus->last_check;
next_check[0] = temp_hststatus->next_check;
status[0] = temp_hststatus->status;
host_name[0] = temp_hststatus->host_name;
service_description[0] = "";
current_attempt[0] = temp_hststatus->current_attempt;
}
if (temp_sortdata->is_service == TRUE) {
temp_svcstatus = temp_sortdata->svcstatus;
last_check[1] = temp_svcstatus->last_check;
next_check[1] = temp_svcstatus->next_check;
status[1] = temp_svcstatus->status;
host_name[1] = temp_svcstatus->host_name;
service_description[1] = temp_svcstatus->description;
current_attempt[1] = temp_svcstatus->current_attempt;
} else {
temp_hststatus = temp_sortdata->hststatus;
last_check[1] = temp_hststatus->last_check;
next_check[1] = temp_hststatus->next_check;
status[1] = temp_hststatus->status;
host_name[1] = temp_hststatus->host_name;
service_description[1] = "";
current_attempt[1] = temp_hststatus->current_attempt;
}
if (s_type == SORT_ASCENDING) {
if (s_option == SORT_LASTCHECKTIME) {
if (last_check[0] <= last_check[1])
return TRUE;
else
return FALSE;
}
if (s_option == SORT_NEXTCHECKTIME) {
if (next_check[0] <= next_check[1])
return TRUE;
else
return FALSE;
} else if (s_option == SORT_CURRENTATTEMPT) {
if (current_attempt[0] <= current_attempt[1])
return TRUE;
else
return FALSE;
} else if (s_option == SORT_SERVICESTATUS) {
if (status[0] <= status[1])
return TRUE;
else
return FALSE;
} else if (s_option == SORT_HOSTNAME) {
if (strcasecmp(host_name[0], host_name[1]) < 0)
return TRUE;
else
return FALSE;
} else if (s_option == SORT_SERVICENAME) {
if (strcasecmp(service_description[0], service_description[1]) < 0)
return TRUE;
else
return FALSE;
}
} else {
if (s_option == SORT_LASTCHECKTIME) {
if (last_check[0] > last_check[1])
return TRUE;
else
return FALSE;
}
if (s_option == SORT_NEXTCHECKTIME) {
if (next_check[0] > next_check[1])
return TRUE;
else
return FALSE;
} else if (s_option == SORT_CURRENTATTEMPT) {
if (current_attempt[0] > current_attempt[1])
return TRUE;
else
return FALSE;
} else if (s_option == SORT_SERVICESTATUS) {
if (status[0] > status[1])
return TRUE;
else
return FALSE;
} else if (s_option == SORT_HOSTNAME) {
if (strcasecmp(host_name[0], host_name[1]) > 0)
return TRUE;
else
return FALSE;
} else if (s_option == SORT_SERVICENAME) {
if (strcasecmp(service_description[0], service_description[1]) > 0)
return TRUE;
else
return FALSE;
}
}
return TRUE;
}
/* free all memory allocated to the sortdata structures */
void free_sortdata_list(void) {
sortdata *this_sortdata;
sortdata *next_sortdata;
/* free memory for the sortdata list */
for (this_sortdata = sortdata_list; this_sortdata != NULL; this_sortdata = next_sortdata) {
next_sortdata = this_sortdata->next;
free(this_sortdata);
}
return;
}
/* determines whether or not a specific host is an child of another host */
/* NOTE: this could be expensive in large installations, so use with care! */
int is_host_child_of_host(host *parent_host, host *child_host) {
host *temp_host;
/* not enough data */
if (child_host == NULL)
return FALSE;
/* root/top-level hosts */
if (parent_host == NULL) {
if (child_host->parent_hosts == NULL)
return TRUE;
/* mid-level/bottom hosts */
} else {
for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
/* skip this host if it is not a child */
if (is_host_immediate_child_of_host(parent_host, temp_host) == FALSE)
continue;
else {
if (!strcmp(temp_host->name, child_host->name))
return TRUE;
else {
if (is_host_child_of_host(temp_host, child_host) == FALSE)
continue;
return TRUE;
}
}
}
}
return FALSE;
}
icinga-1.10.3/cgi/getcgi.c 0000664 0000000 0000000 00000022422 12276402000 0015171 0 ustar 00root root 0000000 0000000 /*****************************************************************************
*
* GETCGI.C - Icinga CGI Input Routines
*
* Copyright (c) 1999-2009 Ethan Galstad (egalstad@nagios.org)
* Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*****************************************************************************/
#include "../include/config.h"
#include "../include/getcgi.h"
#include "../include/cgiutils.h"
#include
#include
#undef PARANOID_CGI_INPUT
/* Remove potentially harmful characters from CGI input that we don't need or want */
void sanitize_cgi_input(char **cgivars) {
char *strptr;
int x, y, i;
int keep;
/* don't strip for now... */
return;
for (strptr = cgivars[i=0]; strptr != NULL; strptr = cgivars[++i]) {
for (x = 0, y = 0; strptr[x] != '\x0'; x++) {
keep = 1;
/* remove potentially nasty characters */
if (strptr[x] == ';' || strptr[x] == '|' || strptr[x] == '&' || strptr[x] == '<' || strptr[x] == '>')
keep = 0;
#ifdef PARANOID_CGI_INPUT
else if (strptr[x] == '/' || strptr[x] == '\\')
keep = 0;
#endif
if (keep == 1)
strptr[y++] = strptr[x];
}
strptr[y] = '\x0';
}
return;
}
/* convert encoded hex string (2 characters representing an 8-bit number) to its ASCII char equivalent */
unsigned char hex_to_char(char *input) {
unsigned char outchar = '\x0';
unsigned int outint;
char tempbuf[3];
/* NULL or empty string */
if (input == NULL)
return '\x0';
if (input[0] == '\x0')
return '\x0';
tempbuf[0] = input[0];
tempbuf[1] = input[1];
tempbuf[2] = '\x0';
sscanf(tempbuf, "%X", &outint);
/* only convert "normal" ASCII characters - we don't want the rest. Normally you would
convert all characters (i.e. for allowing users to post binary files), but since we
aren't doing this, stay on the cautious side of things and reject outsiders... */
#ifdef PARANOID_CGI_INPUT
if (outint < 32 || outint > 126)
outint = 0;
#endif
outchar = (unsigned char)outint;
return outchar;
}
/* unescape hex characters and plus in CGI input */
void unescape_cgi_input(char *input) {
int x, y;
int len;
if (input == NULL)
return;
len = strlen(input);
for (x = 0, y = 0; x < len; x++, y++) {
if (input[x] == '\x0') {
break;
// RB 2013-04-07
// only allow hex conversion if '%' is follow by a valid character
} else if (input[x] == '%' && (
// 0 - 9
(input[x+1] >= 48 && input[x+1] <= 57) ||
// A - F
(input[x+1] >= 65 && input[x+1] <= 70) ||
// a - f
(input[x+1] >= 97 && input[x+1] <= 102))
) {
input[y] = hex_to_char(&input[x+1]);
x += 2;
// RB 2011-09-08
// convert plus as well that it can bu used in service and host names
} else if (input[x] == '+') {
input[y] = ' ';
} else
input[y] = input[x];
}
input[y] = '\x0';
return;
}
/* read the CGI input and place all name/val pairs into list. returns list containing name1, value1, name2, value2, ... , NULL */
/* this is a hacked version of a routine I found a long time ago somewhere - can't remember where anymore */
char **getcgivars(void) {
register int i;
char *request_method;
char *content_type;
char *content_length_string;
int content_length;
char *cgiinput;
char **cgivars;
char **pairlist;
int paircount;
char *nvpair;
char *eqpos;
/* initialize char variable(s) */
cgiinput = "";
/* depending on the request method, read all CGI input into cgiinput */
request_method = getenv("REQUEST_METHOD");
if (request_method == NULL)
request_method = "";
if (!strcmp(request_method, "GET") || !strcmp(request_method, "HEAD")) {
/* check for NULL query string environment variable - 04/28/00 (Ludo Bosmans) */
if (getenv("QUERY_STRING") == NULL) {
cgiinput = (char *)malloc(1);
if (cgiinput != NULL) {
cgiinput[0] = '\x0';
}
} else {
cgiinput = strdup(getenv("QUERY_STRING"));
if (cgiinput == NULL) {
printf("getcgivars(): Could not allocate memory for CGI input.\n");
exit(1);
}
}
}
else if (!strcmp(request_method, "POST") || !strcmp(request_method, "PUT")) {
/* if CONTENT_TYPE variable is not specified, RFC-2068 says we should assume it is "application/octet-string" */
/* mobile (WAP) stations generate CONTENT_TYPE with charset, we we should only check first 33 chars */
content_type = getenv("CONTENT_TYPE");
if (content_type == NULL)
content_type = "";
if (strlen(content_type) && strncasecmp(content_type, "application/x-www-form-urlencoded", 33)) {
printf("getcgivars(): Unsupported Content-Type.\n");
exit(1);
}
content_length_string = getenv("CONTENT_LENGTH");
if (content_length_string == NULL)
content_length_string = "0";
if (!(content_length = atoi(content_length_string))) {
printf("getcgivars(): No Content-Length was sent with the POST request.\n") ;
exit(1);
}
/* suspicious content length */
if ((content_length < 0) || (content_length >= INT_MAX - 1)) {
printf("getcgivars(): Suspicious Content-Length was sent with the POST request.\n");
exit(1);
}
if (!(cgiinput = (char *)malloc(content_length + 1))) {
printf("getcgivars(): Could not allocate memory for CGI input.\n");
exit(1);
}
if (!fread(cgiinput, content_length, 1, stdin)) {
printf("getcgivars(): Could not read input from STDIN.\n");
exit(1);
}
cgiinput[content_length] = '\0';
} else {
printf("getcgivars(): Unsupported REQUEST_METHOD -> '%s'\n", request_method);
printf("\n");
printf("I'm guessing you're trying to execute the CGI from a command line.\n");
printf("In order to do that, you need to set the REQUEST_METHOD environment\n");
printf("variable to either \"GET\", \"HEAD\", or \"POST\". When using the\n");
printf("GET and HEAD methods, arguments can be passed to the CGI\n");
printf("by setting the \"QUERY_STRING\" environment variable. If you're\n");
printf("using the POST method, data is read from standard input. Also of\n");
printf("note: if you've enabled authentication in the CGIs, you must set the\n");
printf("\"REMOTE_USER\" environment variable to be the name of the user you're\n");
printf("\"authenticated\" as.\n");
printf("\n");
exit(1);
}
/* first, split on ampersands (&) to extract the name-value pairs into pairlist */
/* allocate memory for 256 name-value pairs at a time, increasing by same
amount as necessary... */
pairlist = (char **)malloc(256 * sizeof(char **));
if (pairlist == NULL) {
printf("getcgivars(): Could not allocate memory for name-value pairlist.\n");
exit(1);
}
paircount = 0;
nvpair = strtok(cgiinput, "&");
while (nvpair) {
pairlist[paircount] = strdup(nvpair);
if(pairlist[paircount++] == NULL) {
printf("getcgivars(): Could not allocate memory for name-value pair element #%d.\n", paircount);
exit(1);
}
if (paircount > MAX_CGI_INPUT_PAIRS)
break;
if (!(paircount % 256)) {
pairlist = (char **)realloc(pairlist, (paircount + 256) * sizeof(char **));
if (pairlist == NULL) {
printf("getcgivars(): Could not re-allocate memory for name-value pairlist.\n");
exit(1);
}
}
nvpair = strtok(NULL, "&");
}
/* terminate the list */
pairlist[paircount] = '\x0';
/* extract the names and values from the pairlist */
cgivars = (char **)malloc((paircount * 2 + 1) * sizeof(char **));
if (cgivars == NULL) {
printf("getcgivars(): Could not allocate memory for name-value list.\n");
exit(1);
}
for (i = 0; i < paircount; i++) {
/* get the variable name preceding the equal (=) sign */
if ((eqpos = strchr(pairlist[i], '=')) != NULL) {
*eqpos = '\0';
cgivars[i*2+1] = strdup(eqpos + 1);
if(cgivars[i*2+1] == NULL) {
printf("getcgivars(): Could not allocate memory for cgi param value #%d.\n", i);
exit(1);
}
unescape_cgi_input(cgivars[i*2+1]);
} else {
cgivars[i*2+1] = strdup("");
if(cgivars[i*2+1] == NULL) {
printf("getcgivars(): Could not allocate memory for empty cgi param value #%d.\n", i);
exit(1);
}
}
/* get the variable value (or name/value of there was no real "pair" in the first place) */
cgivars[i*2] = strdup(pairlist[i]);
if(cgivars[i*2] == NULL) {
printf("getcgivars(): Could not allocate memory for cgi param name #%d.\n", i);
exit(1);
}
unescape_cgi_input(cgivars[i*2]);
}
/* terminate the name-value list */
cgivars[paircount*2] = '\x0';
/* free allocated memory */
free(cgiinput);
for (i = 0; pairlist[i] != NULL; i++)
free(pairlist[i]);
free(pairlist);
/* sanitize the name-value strings */
sanitize_cgi_input(cgivars);
/* return the list of name-value strings */
return cgivars;
}
/* free() memory allocated to storing the CGI variables */
void free_cgivars(char **cgivars) {
register int x;
for (x = 0; cgivars[x] != '\x0'; x++)
free(cgivars[x]);
return;
}
icinga-1.10.3/cgi/histogram.c 0000664 0000000 0000000 00000234711 12276402000 0015732 0 ustar 00root root 0000000 0000000 /*****************************************************************************
*
* HISTOGRAM.C - Icinga Alert Histogram CGI
*
* Copyright (c) 1999-2009 Ethan Galstad (egalstad@nagios.org)
* Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*****************************************************************************/
#include "../include/config.h"
#include "../include/common.h"
#include "../include/objects.h"
#include "../include/statusdata.h"
#include "../include/readlogs.h"
#include "../include/cgiutils.h"
#include "../include/getcgi.h"
#include "../include/cgiauth.h"
#include /* Boutell's GD library function */
#include /* GD library small font definition */
/*#define DEBUG 1*/
/* archived state types */
#define AS_NO_DATA 0
#define AS_PROGRAM_START 1
#define AS_PROGRAM_END 2
#define AS_HOST_UP 3
#define AS_HOST_DOWN 4
#define AS_HOST_UNREACHABLE 5
#define AS_SVC_OK 6
#define AS_SVC_UNKNOWN 7
#define AS_SVC_WARNING 8
#define AS_SVC_CRITICAL 9
/* display types */
#define DISPLAY_HOST_HISTOGRAM 0
#define DISPLAY_SERVICE_HISTOGRAM 1
#define DISPLAY_NO_HISTOGRAM 2
/* input types */
#define GET_INPUT_NONE 0
#define GET_INPUT_TARGET_TYPE 1
#define GET_INPUT_HOST_TARGET 2
#define GET_INPUT_SERVICE_TARGET 3
#define GET_INPUT_OPTIONS 4
/* breakdown types */
#define BREAKDOWN_MONTHLY 0
#define BREAKDOWN_DAY_OF_MONTH 1
#define BREAKDOWN_DAY_OF_WEEK 2
#define BREAKDOWN_HOURLY 3
#define MAX_ARCHIVE_SPREAD 65
#define MAX_ARCHIVE 65
#define MAX_ARCHIVE_BACKTRACKS 60
#define DRAWING_WIDTH 550
#define DRAWING_HEIGHT 195
#define DRAWING_X_OFFSET 60
#define DRAWING_Y_OFFSET 235
#define GRAPH_HOST_UP 1
#define GRAPH_HOST_DOWN 2
#define GRAPH_HOST_UNREACHABLE 4
#define GRAPH_SERVICE_OK 8
#define GRAPH_SERVICE_WARNING 16
#define GRAPH_SERVICE_UNKNOWN 32
#define GRAPH_SERVICE_CRITICAL 64
#define GRAPH_HOST_PROBLEMS 6
#define GRAPH_HOST_ALL 7
#define GRAPH_SERVICE_PROBLEMS 112
#define GRAPH_SERVICE_ALL 120
#define GRAPH_EVERYTHING 255
#define GRAPH_SOFT_STATETYPES 1
#define GRAPH_HARD_STATETYPES 2
#define GRAPH_ALL_STATETYPES 3
extern char main_config_file[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH];
extern char physical_images_path[MAX_FILENAME_LENGTH];
extern host *host_list;
extern service *service_list;
authdata current_authdata;
typedef struct timeslice_data_struct {
unsigned long service_ok;
unsigned long host_up;
unsigned long service_critical;
unsigned long host_down;
unsigned long service_unknown;
unsigned long host_unreachable;
unsigned long service_warning;
} timeslice_data;
timeslice_data *tsdata;
void compute_report_times(void);
void graph_all_histogram_data(void);
void add_archived_state(int, time_t);
void read_archived_state_data(void);
void draw_line(int, int, int, int, int);
void draw_dashed_line(int, int, int, int, int);
int process_cgivars(void);
time_t t1;
time_t t2;
int start_second = 0;
int start_minute = 0;
int start_hour = 0;
int start_day = 1;
int start_month = 1;
int start_year = 2000;
int end_second = 0;
int end_minute = 0;
int end_hour = 24;
int end_day = 1;
int end_month = 1;
int end_year = 2000;
extern int content_type;
int input_type = GET_INPUT_NONE;
int timeperiod_type = TIMEPERIOD_LAST24HOURS;
int breakdown_type = BREAKDOWN_HOURLY;
int compute_time_from_parts = FALSE;
int initial_states_logged = FALSE;
int assume_state_retention = TRUE;
int new_states_only = FALSE;
int last_state = AS_NO_DATA;
int program_restart_has_occurred = FALSE;
int graph_events = GRAPH_EVERYTHING;
int graph_statetypes = GRAPH_HARD_STATETYPES;
extern int embedded;
extern int display_header;
extern int daemon_check;
gdImagePtr histogram_image = 0;
int color_white = 0;
int color_black = 0;
int color_red = 0;
int color_green = 0;
int color_yellow = 0;
int color_pink = 0;
int color_darkpink = 0;
int color_lightgray = 0;
FILE *image_file = NULL;
int backtrack_archives = 0;
int earliest_archive = 0;
time_t earliest_time;
time_t latest_time;
int image_width = 900;
int image_height = 320;
int total_buckets = 96;
int display_type = DISPLAY_NO_HISTOGRAM;
char *host_name = "";
char *service_desc = "";
int CGI_ID = HISTOGRAM_CGI_ID;
int main(int argc, char **argv) {
int result = OK;
char temp_buffer[MAX_INPUT_BUFFER];
char image_template[MAX_INPUT_BUFFER];
char start_timestring[MAX_INPUT_BUFFER];
char end_timestring[MAX_INPUT_BUFFER];
host *temp_host = NULL;
service *temp_service = NULL;
int is_authorized = TRUE;
int days, hours, minutes, seconds;
char *first_service = NULL;
int x;
time_t t3;
time_t current_time;
struct tm *t;
/* initialize time period to last 24 hours */
time(&t2);
t1 = (time_t)(t2 - (60 * 60 * 24));
/* get the arguments passed in the URL */
process_cgivars();
/* reset internal CGI variables */
reset_cgi_vars();
/* read the CGI configuration file */
result = read_cgi_config_file(get_cgi_config_location());
if (result == ERROR) {
if (content_type != IMAGE_CONTENT) {
document_header(CGI_ID, FALSE, "Error");
print_error(get_cgi_config_location(), ERROR_CGI_CFG_FILE, FALSE);
document_footer(CGI_ID);
}
return ERROR;
}
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if (result == ERROR) {
if (content_type != IMAGE_CONTENT) {
document_header(CGI_ID, FALSE, "Error");
print_error(main_config_file, ERROR_CGI_MAIN_CFG, FALSE);
document_footer(CGI_ID);
}
return ERROR;
}
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if (result == ERROR) {
if (content_type != IMAGE_CONTENT) {
document_header(CGI_ID, FALSE, "Error");
print_error(NULL, ERROR_CGI_OBJECT_DATA, FALSE);
document_footer(CGI_ID);
}
return ERROR;
}
/* read all status data */
result = read_all_status_data(main_config_file, READ_ALL_STATUS_DATA);
if (result == ERROR && daemon_check == TRUE) {
if (content_type != IMAGE_CONTENT) {
document_header(CGI_ID, FALSE, "Error");
print_error(NULL, ERROR_CGI_STATUS_DATA, FALSE);
document_footer(CGI_ID);
}
free_memory();
return ERROR;
}
document_header(CGI_ID, TRUE, "Histogram");
/* get authentication information */
get_authentication_information(¤t_authdata);
if (compute_time_from_parts == TRUE)
compute_report_times();
/* make sure times are sane, otherwise swap them */
if (t2 < t1) {
t3 = t2;
t2 = t1;
t1 = t3;
}
if (content_type == HTML_CONTENT && display_header == TRUE) {
/* begin top table */
printf("
\n");
printf("
\n");
/* left column of the first row */
printf("
\n");
if (display_type == DISPLAY_HOST_HISTOGRAM)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Host Alert Histogram");
else if (display_type == DISPLAY_SERVICE_HISTOGRAM)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Service Alert Histogram");
else
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Host and Service Alert Histogram");
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
display_info_table(temp_buffer, ¤t_authdata, daemon_check);
if (display_type != DISPLAY_NO_HISTOGRAM && input_type == GET_INPUT_NONE) {
printf("
\n");
}
/* check authorization... */
if (display_type == DISPLAY_HOST_HISTOGRAM) {
temp_host = find_host(host_name);
if (is_authorized_for_host(temp_host, ¤t_authdata) == FALSE)
is_authorized = FALSE;
} else if (display_type == DISPLAY_SERVICE_HISTOGRAM) {
temp_service = find_service(host_name, service_desc);
if (is_authorized_for_service(temp_service, ¤t_authdata) == FALSE)
is_authorized = FALSE;
}
if (is_authorized == FALSE) {
if (content_type == HTML_CONTENT) {
if (display_type == DISPLAY_HOST_HISTOGRAM)
print_generic_error_message("It appears as though you are not authorized to view information for the specified host...", NULL, 0);
else
print_generic_error_message("It appears as though you are not authorized to view information for the specified service...", NULL, 0);
}
document_footer(CGI_ID);
free_memory();
return ERROR;
}
if (display_type != DISPLAY_NO_HISTOGRAM && input_type == GET_INPUT_NONE) {
/* print URL to image */
if (content_type == HTML_CONTENT) {
printf("
\n");
printf("
\n");
printf("\n");
printf("
\n");
}
/* read and process state data */
else {
/* allocate memory */
tsdata = NULL;
if (breakdown_type == BREAKDOWN_MONTHLY)
total_buckets = 12;
else if (breakdown_type == BREAKDOWN_DAY_OF_MONTH)
total_buckets = 31;
else if (breakdown_type == BREAKDOWN_DAY_OF_WEEK)
total_buckets = 7;
else
total_buckets = 96;
tsdata = (timeslice_data *)malloc(sizeof(timeslice_data) * total_buckets);
if (tsdata == NULL)
return ERROR;
for (x = 0; x < total_buckets; x++) {
tsdata[x].service_ok = 0L;
tsdata[x].service_unknown = 0L;
tsdata[x].service_warning = 0L;
tsdata[x].service_critical = 0L;
tsdata[x].host_up = 0L;
tsdata[x].host_down = 0L;
tsdata[x].host_unreachable = 0L;
}
/* read in all necessary archived state data */
read_archived_state_data();
#ifdef DEBUG
printf("Done reading archived state data.\n");
#endif
/* location of image template */
snprintf(image_template, sizeof(image_template) - 1, "%s%s", physical_images_path, HISTOGRAM_IMAGE);
image_template[sizeof(image_template)-1] = '\x0';
/* allocate buffer for storing image */
image_file = fopen(image_template, "r");
if (image_file != NULL) {
histogram_image = gdImageCreateFromPng(image_file);
fclose(image_file);
}
if (histogram_image == NULL)
histogram_image = gdImageCreate(image_width, image_height);
if (histogram_image == NULL) {
#ifdef DEBUG
printf("Error: Could not allocate memory for image\n");
#endif
return ERROR;
}
/* allocate colors used for drawing */
color_white = gdImageColorAllocate(histogram_image, 255, 255, 255);
color_black = gdImageColorAllocate(histogram_image, 0, 0, 0);
color_red = gdImageColorAllocate(histogram_image, 255, 0, 0);
color_green = gdImageColorAllocate(histogram_image, 0, 128, 0);
color_yellow = gdImageColorAllocate(histogram_image, 176, 178, 20);
color_pink = gdImageColorAllocate(histogram_image, 224, 102, 255);
color_darkpink = gdImageColorAllocate(histogram_image, 166, 75, 189);
/* set transparency index */
gdImageColorTransparent(histogram_image, color_white);
/* make sure the graphic is interlaced */
gdImageInterlace(histogram_image, 1);
#ifdef DEBUG
printf("Starting to graph data...\n");
#endif
/* graph archived state histogram data */
graph_all_histogram_data();
#ifdef DEBUG
printf("Done graphing data.\n");
#endif
/* use STDOUT for writing the image data... */
image_file = stdout;
#ifdef DEBUG
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "/tmp/%s", HISTOGRAM_IMAGE);
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
image_file = fopen(temp_buffer, "w");
#endif
/* write the image to to STDOUT */
gdImagePng(histogram_image, image_file);
#ifdef DEBUG
fclose(image_file);
#endif
/* free memory allocated to image */
gdImageDestroy(histogram_image);
/* free memory allocated for data */
free(tsdata);
}
}
/* show user a selection of hosts and services to choose from... */
if (display_type == DISPLAY_NO_HISTOGRAM || input_type != GET_INPUT_NONE) {
/* ask the user for what host they want a report for */
if (input_type == GET_INPUT_HOST_TARGET) {
printf("
Step 2: Select Host
\n");
printf("\n");
}
/* ask the user for what service they want a report for */
else if (input_type == GET_INPUT_SERVICE_TARGET) {
printf("
Step 2: Select Service
\n");
printf("\n");
}
/* ask the user for report range and options */
else if (input_type == GET_INPUT_OPTIONS) {
time(¤t_time);
t = localtime(¤t_time);
start_day = 1;
start_year = t->tm_year + 1900;
end_day = t->tm_mday;
end_year = t->tm_year + 1900;
printf("
Step 3: Select Report Options
\n");
printf("\n");
}
/* as the user whether they want a graph for a host or service */
else {
printf("
Step 1: Select Report Type
\n");
printf("\n");
}
}
document_footer(CGI_ID);
/* free all other allocated memory */
free_memory();
return OK;
}
int process_cgivars(void) {
char **variables;
char *temp_buffer = NULL;
int error = FALSE;
int x;
variables = getcgivars();
for (x = 0; variables[x] != NULL; x++) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */
if (strlen(variables[x]) >= MAX_INPUT_BUFFER - 1)
continue;
/* we found the host argument */
else if (!strcmp(variables[x], "host")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((host_name = (char *)strdup(variables[x])) == NULL)
host_name = "";
strip_html_brackets(host_name);
display_type = DISPLAY_HOST_HISTOGRAM;
}
/* we found the node width argument */
else if (!strcmp(variables[x], "service")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((service_desc = (char *)strdup(variables[x])) == NULL)
service_desc = "";
strip_html_brackets(service_desc);
display_type = DISPLAY_SERVICE_HISTOGRAM;
}
/* we found a combined host/service */
else if (!strcmp(variables[x], "hostservice")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
temp_buffer = strtok(variables[x], "^");
if ((host_name = (char *)strdup(temp_buffer)) == NULL)
host_name = "";
else
strip_html_brackets(host_name);
temp_buffer = strtok(NULL, "");
if ((service_desc = (char *)strdup(temp_buffer)) == NULL)
service_desc = "";
else
strip_html_brackets(service_desc);
display_type = DISPLAY_SERVICE_HISTOGRAM;
}
/* we found first time argument */
else if (!strcmp(variables[x], "t1")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
t1 = (time_t)strtoul(variables[x], NULL, 10);
timeperiod_type = TIMEPERIOD_CUSTOM;
}
/* we found first time argument */
else if (!strcmp(variables[x], "t2")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
t2 = (time_t)strtoul(variables[x], NULL, 10);
timeperiod_type = TIMEPERIOD_CUSTOM;
}
/* we found the image creation option */
else if (!strcmp(variables[x], "createimage")) {
content_type = IMAGE_CONTENT;
}
/* we found the backtrack archives argument */
else if (!strcmp(variables[x], "backtrack")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
backtrack_archives = atoi(variables[x]);
if (backtrack_archives < 0)
backtrack_archives = 0;
if (backtrack_archives > MAX_ARCHIVE_BACKTRACKS)
backtrack_archives = MAX_ARCHIVE_BACKTRACKS;
}
/* we found the standard timeperiod argument */
else if (!strcmp(variables[x], "timeperiod")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "today"))
timeperiod_type = TIMEPERIOD_TODAY;
else if (!strcmp(variables[x], "yesterday"))
timeperiod_type = TIMEPERIOD_YESTERDAY;
else if (!strcmp(variables[x], "thisweek"))
timeperiod_type = TIMEPERIOD_THISWEEK;
else if (!strcmp(variables[x], "lastweek"))
timeperiod_type = TIMEPERIOD_LASTWEEK;
else if (!strcmp(variables[x], "thismonth"))
timeperiod_type = TIMEPERIOD_THISMONTH;
else if (!strcmp(variables[x], "lastmonth"))
timeperiod_type = TIMEPERIOD_LASTMONTH;
else if (!strcmp(variables[x], "thisquarter"))
timeperiod_type = TIMEPERIOD_THISQUARTER;
else if (!strcmp(variables[x], "lastquarter"))
timeperiod_type = TIMEPERIOD_LASTQUARTER;
else if (!strcmp(variables[x], "thisyear"))
timeperiod_type = TIMEPERIOD_THISYEAR;
else if (!strcmp(variables[x], "lastyear"))
timeperiod_type = TIMEPERIOD_LASTYEAR;
else if (!strcmp(variables[x], "last24hours"))
timeperiod_type = TIMEPERIOD_LAST24HOURS;
else if (!strcmp(variables[x], "last7days"))
timeperiod_type = TIMEPERIOD_LAST7DAYS;
else if (!strcmp(variables[x], "last31days"))
timeperiod_type = TIMEPERIOD_LAST31DAYS;
else if (!strcmp(variables[x], "custom"))
timeperiod_type = TIMEPERIOD_CUSTOM;
else
timeperiod_type = TIMEPERIOD_TODAY;
if (timeperiod_type != TIMEPERIOD_CUSTOM)
convert_timeperiod_to_times(timeperiod_type, &t1, &t2);
}
/* we found time argument */
else if (!strcmp(variables[x], "smon")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
start_month = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "sday")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
start_day = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "syear")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
start_year = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "smin")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
start_minute = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "ssec")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
start_second = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "shour")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
start_hour = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "emon")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
end_month = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "eday")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
end_day = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "eyear")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
end_year = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "emin")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
end_minute = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "esec")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
end_second = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "ehour")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
end_hour = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found the embed option */
else if (!strcmp(variables[x], "embedded"))
embedded = TRUE;
/* we found the noheader option */
else if (!strcmp(variables[x], "noheader"))
display_header = FALSE;
/* we found the nodaemoncheck option */
else if (!strcmp(variables[x], "nodaemoncheck"))
daemon_check = FALSE;
/* we found the input option */
else if (!strcmp(variables[x], "input")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "gethost"))
input_type = GET_INPUT_HOST_TARGET;
else if (!strcmp(variables[x], "getservice"))
input_type = GET_INPUT_SERVICE_TARGET;
else if (!strcmp(variables[x], "getoptions"))
input_type = GET_INPUT_OPTIONS;
else
input_type = GET_INPUT_TARGET_TYPE;
}
/* we found the graph states option */
else if (!strcmp(variables[x], "graphevents")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
graph_events = atoi(variables[x]);
}
/* we found the graph state types option */
else if (!strcmp(variables[x], "graphstatetypes")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
graph_statetypes = atoi(variables[x]);
}
/* we found the breakdown option */
else if (!strcmp(variables[x], "breakdown")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "monthly"))
breakdown_type = BREAKDOWN_MONTHLY;
else if (!strcmp(variables[x], "dayofmonth"))
breakdown_type = BREAKDOWN_DAY_OF_MONTH;
else if (!strcmp(variables[x], "dayofweek"))
breakdown_type = BREAKDOWN_DAY_OF_WEEK;
else
breakdown_type = BREAKDOWN_HOURLY;
}
/* we found the assume state retention option */
else if (!strcmp(variables[x], "assumestateretention")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "yes"))
assume_state_retention = TRUE;
else
assume_state_retention = FALSE;
}
/* we found the initial states logged option */
else if (!strcmp(variables[x], "initialstateslogged")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "yes"))
initial_states_logged = TRUE;
else
initial_states_logged = FALSE;
}
/* we found the new states only option */
else if (!strcmp(variables[x], "newstatesonly")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "yes"))
new_states_only = TRUE;
else
new_states_only = FALSE;
}
}
/* free memory allocated to the CGI variables */
free_cgivars(variables);
return error;
}
/* graphs histogram data */
void graph_all_histogram_data(void) {
int pixel_x;
int pixel_y;
int last_pixel_y;
int current_bucket;
int actual_bucket;
unsigned long max_value;
double x_scaling_factor;
double y_scaling_factor;
double x_units;
double y_units;
int current_unit;
int actual_unit;
char temp_buffer[MAX_INPUT_BUFFER];
int string_width;
int string_height;
char *days[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
char *months[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
char start_time[MAX_INPUT_BUFFER];
char end_time[MAX_INPUT_BUFFER];
unsigned long state1_max = 0L;
unsigned long state1_min = 0L;
int have_state1_min = FALSE;
unsigned long state1_sum = 0L;
double state1_avg = 0.0;
unsigned long state2_max = 0L;
unsigned long state2_min = 0L;
int have_state2_min = FALSE;
unsigned long state2_sum = 0L;
double state2_avg = 0.0;
unsigned long state3_max = 0L;
unsigned long state3_min = 0L;
int have_state3_min = FALSE;
unsigned long state3_sum = 0L;
double state3_avg = 0.0;
unsigned long state4_max = 0L;
unsigned long state4_min = 0L;
int have_state4_min = FALSE;
unsigned long state4_sum = 0L;
double state4_avg = 0.0;
host *temp_host = NULL;
service *temp_service = NULL;
/* find the host */
temp_host = find_host(host_name);
/* find the service */
temp_service = find_service(host_name, service_desc);
#ifdef DEBUG
printf("Total Buckets: %d\n", total_buckets);
#endif
/* determine max value in the buckets (for scaling) */
max_value = 0L;
for (current_bucket = 0; current_bucket < total_buckets; current_bucket++) {
if (tsdata[current_bucket].service_ok > max_value)
max_value = tsdata[current_bucket].service_ok;
if (tsdata[current_bucket].service_warning > max_value)
max_value = tsdata[current_bucket].service_warning;
if (tsdata[current_bucket].service_unknown > max_value)
max_value = tsdata[current_bucket].service_unknown;
if (tsdata[current_bucket].service_critical > max_value)
max_value = tsdata[current_bucket].service_critical;
if (tsdata[current_bucket].host_up > max_value)
max_value = tsdata[current_bucket].host_up;
if (tsdata[current_bucket].host_down > max_value)
max_value = tsdata[current_bucket].host_down;
if (tsdata[current_bucket].host_unreachable > max_value)
max_value = tsdata[current_bucket].host_unreachable;
}
#ifdef DEBUG
printf("Done determining max bucket values\n");
printf("MAX_VALUE=%lu\n", max_value);
printf("DRAWING_HEIGHT=%d\n", DRAWING_HEIGHT);
#endif
/* min number of values to graph */
if (max_value < 10)
max_value = 10;
#ifdef DEBUG
printf("ADJUSTED MAX_VALUE=%lu\n", max_value);
#endif
/* determine y scaling factor */
/*y_scaling_factor=floor((double)DRAWING_HEIGHT/(double)max_value);*/
y_scaling_factor = (double)((double)DRAWING_HEIGHT / (double)max_value);
/* determine x scaling factor */
x_scaling_factor = (double)((double)DRAWING_WIDTH / (double)total_buckets);
/* determine y units resolution - we want a max of about 10 y grid lines */
/*
y_units=(double)((double)DRAWING_HEIGHT/19.0);
y_units=ceil(y_units/y_scaling_factor)*y_scaling_factor;
*/
y_units = ceil(19.0 / y_scaling_factor);
/* determine x units resolution */
if (breakdown_type == BREAKDOWN_HOURLY)
x_units = (double)((double)DRAWING_WIDTH / (double)(total_buckets / 4.0));
else
x_units = x_scaling_factor;
#ifdef DEBUG
printf("DRAWING_WIDTH: %d\n", DRAWING_WIDTH);
printf("DRAWING_HEIGHT: %d\n", DRAWING_HEIGHT);
printf("max_value: %lu\n", max_value);
printf("x_scaling_factor: %.3f\n", x_scaling_factor);
printf("y_scaling_factor: %.3f\n", y_scaling_factor);
printf("x_units: %.3f\n", x_units);
printf("y_units: %.3f\n", y_units);
printf("y units to draw: %.3f\n", ((double)max_value / y_units));
#endif
string_height = gdFontSmall->h;
#ifdef DEBUG
printf("Starting to draw Y grid lines...\n");
#endif
/* draw y grid lines */
if (max_value > 0) {
for (current_unit = 1; (current_unit * y_units * y_scaling_factor) <= DRAWING_HEIGHT; current_unit++) {
draw_dashed_line(DRAWING_X_OFFSET, DRAWING_Y_OFFSET - (current_unit * y_units * y_scaling_factor), DRAWING_X_OFFSET + DRAWING_WIDTH, DRAWING_Y_OFFSET - (current_unit * y_units * y_scaling_factor), color_lightgray);
#ifdef DEBUG
printf(" Drawing Y unit #%d @ %d\n", current_unit, (int)(current_unit * y_units * y_scaling_factor));
#endif
}
}
#ifdef DEBUG
printf("Starting to draw X grid lines...\n");
#endif
/* draw x grid lines */
for (current_unit = 1; (int)(current_unit * x_units) <= DRAWING_WIDTH; current_unit++)
draw_dashed_line(DRAWING_X_OFFSET + (int)(current_unit * x_units), DRAWING_Y_OFFSET, DRAWING_X_OFFSET + (int)(current_unit * x_units), DRAWING_Y_OFFSET - DRAWING_HEIGHT, color_lightgray);
#ifdef DEBUG
printf("Starting to draw grid units...\n");
#endif
/* draw y units */
if (max_value > 0) {
for (current_unit = 0; (current_unit * y_units * y_scaling_factor) <= DRAWING_HEIGHT; current_unit++) {
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%d", (int)(current_unit * y_units));
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
string_width = gdFontSmall->w * strlen(temp_buffer);
gdImageString(histogram_image, gdFontSmall, DRAWING_X_OFFSET - string_width - 5, DRAWING_Y_OFFSET - (current_unit * y_units * y_scaling_factor) - (string_height / 2), (unsigned char *)temp_buffer, color_black);
}
}
/* draw x units */
for (current_unit = 0, actual_unit = 0; (int)(current_unit * x_units) <= DRAWING_WIDTH; current_unit++, actual_unit++) {
if (actual_unit >= total_buckets)
actual_unit = 0;
if (breakdown_type == BREAKDOWN_MONTHLY)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%s", months[actual_unit]);
else if (breakdown_type == BREAKDOWN_DAY_OF_MONTH)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%d", actual_unit + 1);
else if (breakdown_type == BREAKDOWN_DAY_OF_WEEK)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%s", days[actual_unit]);
else
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%02d:00", (actual_unit == 24) ? 0 : actual_unit);
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
string_width = gdFontSmall->w * strlen(temp_buffer);
gdImageStringUp(histogram_image, gdFontSmall, DRAWING_X_OFFSET + (current_unit * x_units) - (string_height / 2), DRAWING_Y_OFFSET + 5 + string_width, (unsigned char *)temp_buffer, color_black);
}
/* draw y unit measure */
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Number of Events");
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
string_width = gdFontSmall->w * strlen(temp_buffer);
gdImageStringUp(histogram_image, gdFontSmall, 0, DRAWING_Y_OFFSET - (DRAWING_HEIGHT / 2) + (string_width / 2), (unsigned char *)temp_buffer, color_black);
/* draw x unit measure */
if (breakdown_type == BREAKDOWN_MONTHLY)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Month");
else if (breakdown_type == BREAKDOWN_DAY_OF_MONTH)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Day of the Month");
else if (breakdown_type == BREAKDOWN_DAY_OF_WEEK)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Day of the Week");
else
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Hour of the Day (15 minute increments)");
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
string_width = gdFontSmall->w * strlen(temp_buffer);
gdImageString(histogram_image, gdFontSmall, DRAWING_X_OFFSET + (DRAWING_WIDTH / 2) - (string_width / 2), DRAWING_Y_OFFSET + 70, (unsigned char *)temp_buffer, color_black);
/* draw title */
snprintf(start_time, sizeof(start_time) - 1, "%s", ctime(&t1));
start_time[sizeof(start_time)-1] = '\x0';
start_time[strlen(start_time)-1] = '\x0';
snprintf(end_time, sizeof(end_time) - 1, "%s", ctime(&t2));
end_time[sizeof(end_time)-1] = '\x0';
end_time[strlen(end_time)-1] = '\x0';
if (display_type == DISPLAY_HOST_HISTOGRAM)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Event History For Host '%s'", (temp_host != NULL && temp_host->display_name != NULL) ? temp_host->display_name : host_name);
else
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Event History For Service '%s' On Host '%s'", (temp_service != NULL && temp_service->display_name != NULL) ? temp_service->display_name : service_desc, (temp_host != NULL && temp_host->display_name != NULL) ? temp_host->display_name : host_name);
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
string_width = gdFontSmall->w * strlen(temp_buffer);
gdImageString(histogram_image, gdFontSmall, DRAWING_X_OFFSET + (DRAWING_WIDTH / 2) - (string_width / 2), 0, (unsigned char *)temp_buffer, color_black);
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%s to %s", start_time, end_time);
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
string_width = gdFontSmall->w * strlen(temp_buffer);
gdImageString(histogram_image, gdFontSmall, DRAWING_X_OFFSET + (DRAWING_WIDTH / 2) - (string_width / 2), string_height + 5, (unsigned char *)temp_buffer, color_black);
#ifdef DEBUG
printf("About to starting graphing (total_buckets=%d)...\n", total_buckets);
#endif
/* graph service states */
if (display_type == DISPLAY_HOST_HISTOGRAM) {
/* graph host recoveries */
if (graph_events & GRAPH_HOST_UP) {
last_pixel_y = 0;
for (current_bucket = 0, actual_bucket = 0; current_bucket <= total_buckets; current_bucket++, actual_bucket++) {
if (actual_bucket >= total_buckets)
actual_bucket = 0;
pixel_x = (int)(current_bucket * x_scaling_factor);
pixel_y = (int)(tsdata[actual_bucket].host_up * y_scaling_factor);
if (current_bucket > 0 && !(last_pixel_y == 0 && pixel_y == 0))
draw_line(DRAWING_X_OFFSET + pixel_x - (int)x_scaling_factor, DRAWING_Y_OFFSET - last_pixel_y, DRAWING_X_OFFSET + pixel_x, DRAWING_Y_OFFSET - pixel_y, color_green);
last_pixel_y = pixel_y;
if (current_bucket < total_buckets) {
if (have_state1_min == FALSE || tsdata[actual_bucket].host_up < state1_min) {
state1_min = tsdata[actual_bucket].host_up;
have_state1_min = TRUE;
}
if (state1_max == 0 || tsdata[actual_bucket].host_up > state1_max)
state1_max = tsdata[actual_bucket].host_up;
state1_sum += tsdata[actual_bucket].host_up;
}
}
}
#ifdef DEBUG
printf("Done graphing HOST UP states...\n");
#endif
/* graph host down states */
if (graph_events & GRAPH_HOST_DOWN) {
last_pixel_y = 0;
for (current_bucket = 0, actual_bucket = 0; current_bucket <= total_buckets; current_bucket++, actual_bucket++) {
if (actual_bucket >= total_buckets)
actual_bucket = 0;
pixel_x = (int)(current_bucket * x_scaling_factor);
pixel_y = (int)(tsdata[actual_bucket].host_down * y_scaling_factor);
if (current_bucket > 0 && !(last_pixel_y == 0 && pixel_y == 0))
draw_line(DRAWING_X_OFFSET + pixel_x - (int)x_scaling_factor, DRAWING_Y_OFFSET - last_pixel_y, DRAWING_X_OFFSET + pixel_x, DRAWING_Y_OFFSET - pixel_y, color_red);
last_pixel_y = pixel_y;
if (current_bucket < total_buckets) {
if (have_state2_min == FALSE || tsdata[actual_bucket].host_down < state2_min) {
state2_min = tsdata[actual_bucket].host_down;
have_state2_min = TRUE;
}
if (state2_max == 0 || tsdata[actual_bucket].host_down > state2_max)
state2_max = tsdata[actual_bucket].host_down;
state2_sum += tsdata[actual_bucket].host_down;
}
}
}
#ifdef DEBUG
printf("Done graphing HOST DOWN states...\n");
#endif
/* graph host unreachable states */
if (graph_events & GRAPH_HOST_UNREACHABLE) {
last_pixel_y = 0;
for (current_bucket = 0, actual_bucket = 0; current_bucket <= total_buckets; current_bucket++, actual_bucket++) {
if (actual_bucket >= total_buckets)
actual_bucket = 0;
pixel_x = (int)(current_bucket * x_scaling_factor);
pixel_y = (int)(tsdata[actual_bucket].host_unreachable * y_scaling_factor);
if (current_bucket > 0 && !(last_pixel_y == 0 && pixel_y == 0))
draw_line(DRAWING_X_OFFSET + pixel_x - (int)x_scaling_factor, DRAWING_Y_OFFSET - last_pixel_y, DRAWING_X_OFFSET + pixel_x, DRAWING_Y_OFFSET - pixel_y, color_pink);
last_pixel_y = pixel_y;
if (current_bucket < total_buckets) {
if (have_state3_min == FALSE || tsdata[actual_bucket].host_unreachable < state3_min) {
state3_min = tsdata[actual_bucket].host_unreachable;
have_state3_min = TRUE;
}
if (state3_max == 0 || tsdata[actual_bucket].host_unreachable > state3_max)
state3_max = tsdata[actual_bucket].host_unreachable;
state3_sum += tsdata[actual_bucket].host_unreachable;
}
}
}
#ifdef DEBUG
printf("Done graphing HOST UNREACHABLE states...\n");
#endif
}
/* graph service states */
else {
/* graph service recoveries */
if (graph_events & GRAPH_SERVICE_OK) {
last_pixel_y = 0;
for (current_bucket = 0, actual_bucket = 0; current_bucket <= total_buckets; current_bucket++, actual_bucket++) {
if (actual_bucket >= total_buckets)
actual_bucket = 0;
pixel_x = (int)(current_bucket * x_scaling_factor);
pixel_y = (int)(tsdata[actual_bucket].service_ok * y_scaling_factor);
if (current_bucket > 0 && !(last_pixel_y == 0 && pixel_y == 0))
draw_line(DRAWING_X_OFFSET + pixel_x - (int)x_scaling_factor, DRAWING_Y_OFFSET - last_pixel_y, DRAWING_X_OFFSET + pixel_x, DRAWING_Y_OFFSET - pixel_y, color_green);
last_pixel_y = pixel_y;
if (current_bucket < total_buckets) {
if (have_state1_min == FALSE || tsdata[actual_bucket].service_ok < state1_min) {
state1_min = tsdata[actual_bucket].service_ok;
have_state1_min = TRUE;
}
if (state1_max == 0 || tsdata[actual_bucket].service_ok > state1_max)
state1_max = tsdata[actual_bucket].service_ok;
state1_sum += tsdata[actual_bucket].service_ok;
}
}
}
/* graph service warning states */
if (graph_events & GRAPH_SERVICE_WARNING) {
last_pixel_y = 0;
for (current_bucket = 0, actual_bucket = 0; current_bucket <= total_buckets; current_bucket++, actual_bucket++) {
if (actual_bucket >= total_buckets)
actual_bucket = 0;
pixel_x = (int)(current_bucket * x_scaling_factor);
pixel_y = (int)(tsdata[actual_bucket].service_warning * y_scaling_factor);
if (current_bucket > 0 && !(last_pixel_y == 0 && pixel_y == 0))
draw_line(DRAWING_X_OFFSET + pixel_x - (int)x_scaling_factor, DRAWING_Y_OFFSET - last_pixel_y, DRAWING_X_OFFSET + pixel_x, DRAWING_Y_OFFSET - pixel_y, color_yellow);
last_pixel_y = pixel_y;
if (current_bucket < total_buckets) {
if (have_state2_min == FALSE || tsdata[actual_bucket].service_warning < state2_min) {
state2_min = tsdata[actual_bucket].service_warning;
have_state2_min = TRUE;
}
if (state2_max == 0 || tsdata[actual_bucket].service_warning > state2_max)
state2_max = tsdata[actual_bucket].service_warning;
state2_sum += tsdata[actual_bucket].service_warning;
}
}
}
/* graph service unknown states */
if (graph_events & GRAPH_SERVICE_UNKNOWN) {
last_pixel_y = 0;
for (current_bucket = 0, actual_bucket = 0; current_bucket <= total_buckets; current_bucket++, actual_bucket++) {
if (actual_bucket >= total_buckets)
actual_bucket = 0;
pixel_x = (int)(current_bucket * x_scaling_factor);
pixel_y = (int)(tsdata[actual_bucket].service_unknown * y_scaling_factor);
if (current_bucket > 0 && !(last_pixel_y == 0 && pixel_y == 0))
draw_line(DRAWING_X_OFFSET + pixel_x - (int)x_scaling_factor, DRAWING_Y_OFFSET - last_pixel_y, DRAWING_X_OFFSET + pixel_x, DRAWING_Y_OFFSET - pixel_y, color_pink);
last_pixel_y = pixel_y;
if (current_bucket < total_buckets) {
if (have_state3_min == FALSE || tsdata[actual_bucket].service_unknown < state3_min) {
state3_min = tsdata[actual_bucket].service_unknown;
have_state3_min = TRUE;
}
if (state3_max == 0 || tsdata[actual_bucket].service_unknown > state3_max)
state3_max = tsdata[actual_bucket].service_unknown;
state3_sum += tsdata[actual_bucket].service_unknown;
}
}
}
/* graph service critical states */
if (graph_events & GRAPH_SERVICE_CRITICAL) {
last_pixel_y = 0;
for (current_bucket = 0, actual_bucket = 0; current_bucket <= total_buckets; current_bucket++, actual_bucket++) {
if (actual_bucket >= total_buckets)
actual_bucket = 0;
pixel_x = (int)(current_bucket * x_scaling_factor);
pixel_y = (int)(tsdata[actual_bucket].service_critical * y_scaling_factor);
if (current_bucket > 0 && !(last_pixel_y == 0 && pixel_y == 0))
draw_line(DRAWING_X_OFFSET + pixel_x - (int)x_scaling_factor, DRAWING_Y_OFFSET - last_pixel_y, DRAWING_X_OFFSET + pixel_x, DRAWING_Y_OFFSET - pixel_y, color_red);
last_pixel_y = pixel_y;
if (current_bucket < total_buckets) {
if (have_state4_min == FALSE || tsdata[actual_bucket].service_critical < state4_min) {
state4_min = tsdata[actual_bucket].service_critical;
have_state4_min = TRUE;
}
if (state4_max == 0 || tsdata[actual_bucket].service_critical > state4_max)
state4_max = tsdata[actual_bucket].service_critical;
state4_sum += tsdata[actual_bucket].service_critical;
}
}
}
}
#ifdef DEBUG
printf("Done graphing states...\n");
#endif
/* draw graph boundaries */
draw_line(DRAWING_X_OFFSET, DRAWING_Y_OFFSET, DRAWING_X_OFFSET, DRAWING_Y_OFFSET - DRAWING_HEIGHT, color_black);
draw_line(DRAWING_X_OFFSET + DRAWING_WIDTH, DRAWING_Y_OFFSET, DRAWING_X_OFFSET + DRAWING_WIDTH, DRAWING_Y_OFFSET - DRAWING_HEIGHT, color_black);
draw_line(DRAWING_X_OFFSET, DRAWING_Y_OFFSET, DRAWING_X_OFFSET + DRAWING_WIDTH, DRAWING_Y_OFFSET, color_black);
/* graph stats */
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "EVENT TYPE");
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
string_width = gdFontSmall->w * strlen(temp_buffer);
gdImageString(histogram_image, gdFontSmall, DRAWING_X_OFFSET + DRAWING_WIDTH + 15, DRAWING_Y_OFFSET - DRAWING_HEIGHT, (unsigned char *)temp_buffer, color_black);
snprintf(temp_buffer, sizeof(temp_buffer) - 1, " MIN MAX SUM AVG");
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
string_width = gdFontSmall->w * strlen(temp_buffer);
gdImageString(histogram_image, gdFontSmall, DRAWING_X_OFFSET + DRAWING_WIDTH + 115, DRAWING_Y_OFFSET - DRAWING_HEIGHT, (unsigned char *)temp_buffer, color_black);
draw_line(DRAWING_X_OFFSET + DRAWING_WIDTH + 15, DRAWING_Y_OFFSET - DRAWING_HEIGHT + string_height + 2, DRAWING_X_OFFSET + DRAWING_WIDTH + 275, DRAWING_Y_OFFSET - DRAWING_HEIGHT + string_height + 2, color_black);
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Recovery (%s):", (display_type == DISPLAY_SERVICE_HISTOGRAM) ? "Ok" : "Up");
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
string_width = gdFontSmall->w * strlen(temp_buffer);
gdImageString(histogram_image, gdFontSmall, DRAWING_X_OFFSET + DRAWING_WIDTH + 15, DRAWING_Y_OFFSET - DRAWING_HEIGHT + ((string_height + 5) * 1), (unsigned char *)temp_buffer, color_green);
state1_avg = (double)((double)state1_sum / (double)total_buckets);
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%5lu %5lu %5lu %.2f", state1_min, state1_max, state1_sum, state1_avg);
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
string_width = gdFontSmall->w * strlen(temp_buffer);
gdImageString(histogram_image, gdFontSmall, DRAWING_X_OFFSET + DRAWING_WIDTH + 115, DRAWING_Y_OFFSET - DRAWING_HEIGHT + ((string_height + 5) * 1), (unsigned char *)temp_buffer, color_black);
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%s:", (display_type == DISPLAY_SERVICE_HISTOGRAM) ? "Warning" : "Down");
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
string_width = gdFontSmall->w * strlen(temp_buffer);
gdImageString(histogram_image, gdFontSmall, DRAWING_X_OFFSET + DRAWING_WIDTH + 15, DRAWING_Y_OFFSET - DRAWING_HEIGHT + ((string_height + 5) * 2), (unsigned char *)temp_buffer, (display_type == DISPLAY_SERVICE_HISTOGRAM) ? color_yellow : color_red);
state2_avg = (double)((double)state2_sum / (double)total_buckets);
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%5lu %5lu %5lu %.2f", state2_min, state2_max, state2_sum, state2_avg);
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
string_width = gdFontSmall->w * strlen(temp_buffer);
gdImageString(histogram_image, gdFontSmall, DRAWING_X_OFFSET + DRAWING_WIDTH + 115, DRAWING_Y_OFFSET - DRAWING_HEIGHT + ((string_height + 5) * 2), (unsigned char *)temp_buffer, color_black);
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%s:", (display_type == DISPLAY_SERVICE_HISTOGRAM) ? "Unknown" : "Unreachable");
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
string_width = gdFontSmall->w * strlen(temp_buffer);
gdImageString(histogram_image, gdFontSmall, DRAWING_X_OFFSET + DRAWING_WIDTH + 15, DRAWING_Y_OFFSET - DRAWING_HEIGHT + ((string_height + 5) * 3), (unsigned char *)temp_buffer, color_darkpink);
state3_avg = (double)((double)state3_sum / (double)total_buckets);
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%5lu %5lu %5lu %.2f", state3_min, state3_max, state3_sum, state3_avg);
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
string_width = gdFontSmall->w * strlen(temp_buffer);
gdImageString(histogram_image, gdFontSmall, DRAWING_X_OFFSET + DRAWING_WIDTH + 115, DRAWING_Y_OFFSET - DRAWING_HEIGHT + ((string_height + 5) * 3), (unsigned char *)temp_buffer, color_black);
if (display_type == DISPLAY_SERVICE_HISTOGRAM) {
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Critical:");
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
string_width = gdFontSmall->w * strlen(temp_buffer);
gdImageString(histogram_image, gdFontSmall, DRAWING_X_OFFSET + DRAWING_WIDTH + 15, DRAWING_Y_OFFSET - DRAWING_HEIGHT + ((string_height + 5) * 4), (unsigned char *)temp_buffer, color_red);
state4_avg = (double)((double)state4_sum / (double)total_buckets);
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%5lu %5lu %5lu %.2f", state4_min, state4_max, state4_sum, state4_avg);
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
string_width = gdFontSmall->w * strlen(temp_buffer);
gdImageString(histogram_image, gdFontSmall, DRAWING_X_OFFSET + DRAWING_WIDTH + 115, DRAWING_Y_OFFSET - DRAWING_HEIGHT + ((string_height + 5) * 4), (unsigned char *)temp_buffer, color_black);
}
return;
}
/* adds an archived state entry */
void add_archived_state(int state_type, time_t time_stamp) {
struct tm *our_time;
int bucket;
int skip_state = FALSE;
#ifdef DEBUG2
printf("NEW ENTRY: last=%d this=%d\n", last_state, state_type);
#endif
/* don't record program starts/stops, just make a note that one occurred */
if (state_type == AS_PROGRAM_START || state_type == AS_PROGRAM_END) {
#ifdef DEBUG2
printf("Recording a program start: %d\n", state_type);
#endif
program_restart_has_occurred = TRUE;
return;
}
/* see if we should even take into account this event */
if (program_restart_has_occurred == TRUE) {
#ifdef DEBUG2
printf("program_restart_has_occurred: last=%d this=%d\n", last_state, state_type);
#endif
if (initial_states_logged == TRUE) {
if (state_type == AS_SVC_OK && last_state == AS_SVC_OK)
skip_state = TRUE;
if (state_type == AS_HOST_UP && last_state == AS_HOST_UP)
skip_state = TRUE;
}
if (assume_state_retention == TRUE && initial_states_logged == TRUE) {
if (state_type == AS_SVC_WARNING && last_state == AS_SVC_WARNING)
skip_state = TRUE;
if (state_type == AS_SVC_UNKNOWN && last_state == AS_SVC_UNKNOWN)
skip_state = TRUE;
if (state_type == AS_SVC_CRITICAL && last_state == AS_SVC_CRITICAL)
skip_state = TRUE;
if (state_type == AS_HOST_DOWN && last_state == AS_HOST_DOWN)
skip_state = TRUE;
if (state_type == AS_HOST_UNREACHABLE && last_state == AS_HOST_UNREACHABLE)
skip_state = TRUE;
}
if (skip_state == TRUE) {
program_restart_has_occurred = FALSE;
#ifdef DEBUG2
printf("Skipping state...\n");
#endif
return;
}
}
/* reset program restart variable */
program_restart_has_occurred = FALSE;
/* are we only processing new states */
if (new_states_only == TRUE && state_type == last_state) {
#ifdef DEBUG2
printf("Skipping state (not a new state)...\n");
#endif
return;
}
#ifdef DEBUG2
printf("GOODSTATE: %d @ %lu\n", state_type, (unsigned long)time_stamp);
#endif
our_time = localtime(&time_stamp);
/* calculate the correct bucket to dump the data into */
if (breakdown_type == BREAKDOWN_MONTHLY)
bucket = our_time->tm_mon;
else if (breakdown_type == BREAKDOWN_DAY_OF_MONTH)
bucket = our_time->tm_mday - 1;
else if (breakdown_type == BREAKDOWN_DAY_OF_WEEK)
bucket = our_time->tm_wday;
else
bucket = (our_time->tm_hour * 4) + (our_time->tm_min / 15);
#ifdef DEBUG2
printf("\tBucket=%d\n", bucket);
#endif
/* save the data in the correct bucket */
if (state_type == AS_SVC_OK)
tsdata[bucket].service_ok++;
else if (state_type == AS_SVC_UNKNOWN)
tsdata[bucket].service_unknown++;
else if (state_type == AS_SVC_WARNING)
tsdata[bucket].service_warning++;
else if (state_type == AS_SVC_CRITICAL)
tsdata[bucket].service_critical++;
else if (state_type == AS_HOST_UP)
tsdata[bucket].host_up++;
else if (state_type == AS_HOST_DOWN)
tsdata[bucket].host_down++;
else if (state_type == AS_HOST_UNREACHABLE)
tsdata[bucket].host_unreachable++;
/* record last state type */
last_state = state_type;
return;
}
/* reads log files for archived state data */
void read_archived_state_data(void) {
char entry_host_name[MAX_INPUT_BUFFER];
char entry_service_desc[MAX_INPUT_BUFFER];
char *temp_buffer = NULL;
char *error_text = NULL;
logentry *temp_entry = NULL;
logentry *entry_list = NULL;
logfilter *filter_list = NULL;
int status = READLOG_OK;
/* print something so browser doesn't time out */
if (content_type == HTML_CONTENT) {
printf(" ");
fflush(NULL);
}
/* Service filter */
add_log_filter(&filter_list, LOGENTRY_SERVICE_OK, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_WARNING, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_CRITICAL, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_UNKNOWN, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_RECOVERY, LOGFILTER_INCLUDE);
/* Host filter */
add_log_filter(&filter_list, LOGENTRY_HOST_UP, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_DOWN, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_UNREACHABLE, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_RECOVERY, LOGFILTER_INCLUDE);
/* system message */
add_log_filter(&filter_list, LOGENTRY_STARTUP, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_RESTART, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SHUTDOWN, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_BAILOUT, LOGFILTER_INCLUDE);
status = get_log_entries(&entry_list, &filter_list, &error_text, NULL, FALSE, t1 - get_backtrack_seconds(backtrack_archives), t2);
free_log_filters(&filter_list);
if (status != READLOG_ERROR_FATAL) {
for (temp_entry = entry_list; temp_entry != NULL; temp_entry = temp_entry->next) {
/* program starts/restarts */
if (temp_entry->type == LOGENTRY_STARTUP)
add_archived_state(AS_PROGRAM_START, temp_entry->timestamp);
if (temp_entry->type == LOGENTRY_RESTART)
add_archived_state(AS_PROGRAM_START, temp_entry->timestamp);
/* program stops */
if (temp_entry->type == LOGENTRY_SHUTDOWN)
add_archived_state(AS_PROGRAM_END, temp_entry->timestamp);
if (temp_entry->type == LOGENTRY_BAILOUT)
add_archived_state(AS_PROGRAM_END, temp_entry->timestamp);
if (display_type == DISPLAY_HOST_HISTOGRAM) {
switch (temp_entry->type) {
/* normal host alerts and initial/current states */
case LOGENTRY_HOST_DOWN:
case LOGENTRY_HOST_UNREACHABLE:
case LOGENTRY_HOST_RECOVERY:
case LOGENTRY_HOST_UP:
/* get host name */
temp_buffer = my_strtok(temp_entry->entry_text, ":");
temp_buffer = my_strtok(NULL, ";");
strncpy(entry_host_name, (temp_buffer == NULL) ? "" : temp_buffer + 1, sizeof(entry_host_name));
entry_host_name[sizeof(entry_host_name)-1] = '\x0';
if (strcmp(host_name, entry_host_name))
continue;
/* skip soft states if necessary */
if (!(graph_statetypes & GRAPH_SOFT_STATETYPES) && strstr(temp_entry->entry_text, ";SOFT;"))
continue;
/* skip hard states if necessary */
if (!(graph_statetypes & GRAPH_HARD_STATETYPES) && strstr(temp_entry->entry_text, ";HARD;"))
continue;
if (temp_entry->type == LOGENTRY_HOST_DOWN)
add_archived_state(AS_HOST_DOWN, temp_entry->timestamp);
else if (temp_entry->type == LOGENTRY_HOST_UNREACHABLE)
add_archived_state(AS_HOST_UNREACHABLE, temp_entry->timestamp);
else if (temp_entry->type == LOGENTRY_HOST_RECOVERY || temp_entry->type == LOGENTRY_HOST_UP)
add_archived_state(AS_HOST_UP, temp_entry->timestamp);
break;
}
}
else if (display_type == DISPLAY_SERVICE_HISTOGRAM) {
switch (temp_entry->type) {
/* normal service alerts and initial/current states */
case LOGENTRY_SERVICE_CRITICAL:
case LOGENTRY_SERVICE_WARNING:
case LOGENTRY_SERVICE_UNKNOWN:
case LOGENTRY_SERVICE_RECOVERY:
case LOGENTRY_SERVICE_OK:
/* get host name */
temp_buffer = my_strtok(temp_entry->entry_text, ":");
temp_buffer = my_strtok(NULL, ";");
strncpy(entry_host_name, (temp_buffer == NULL) ? "" : temp_buffer + 1, sizeof(entry_host_name));
entry_host_name[sizeof(entry_host_name)-1] = '\x0';
if (strcmp(host_name, entry_host_name))
continue;
/* get service description */
temp_buffer = my_strtok(NULL, ";");
strncpy(entry_service_desc, (temp_buffer == NULL) ? "" : temp_buffer, sizeof(entry_service_desc));
entry_service_desc[sizeof(entry_service_desc)-1] = '\x0';
if (strcmp(service_desc, entry_service_desc))
continue;
/* skip soft states if necessary */
if (!(graph_statetypes & GRAPH_SOFT_STATETYPES) && strstr(temp_entry->entry_text, ";SOFT;"))
continue;
/* skip hard states if necessary */
if (!(graph_statetypes & GRAPH_HARD_STATETYPES) && strstr(temp_entry->entry_text, ";HARD;"))
continue;
if (temp_entry->type == LOGENTRY_SERVICE_CRITICAL)
add_archived_state(AS_SVC_CRITICAL, temp_entry->timestamp);
else if (temp_entry->type == LOGENTRY_SERVICE_WARNING)
add_archived_state(AS_SVC_WARNING, temp_entry->timestamp);
else if (temp_entry->type == LOGENTRY_SERVICE_UNKNOWN)
add_archived_state(AS_SVC_UNKNOWN, temp_entry->timestamp);
else if (temp_entry->type == LOGENTRY_SERVICE_RECOVERY || temp_entry->type == LOGENTRY_SERVICE_OK)
add_archived_state(AS_SVC_OK, temp_entry->timestamp);
break;
}
}
}
}
/* free memory */
free_log_entries(&entry_list);
return;
}
void compute_report_times(void) {
time_t current_time;
struct tm *st;
struct tm *et;
/* get the current time */
time(¤t_time);
st = localtime(¤t_time);
st->tm_sec = start_second;
st->tm_min = start_minute;
st->tm_hour = start_hour;
st->tm_mday = start_day;
st->tm_mon = start_month - 1;
st->tm_year = start_year - 1900;
st->tm_isdst = -1;
t1 = mktime(st);
et = localtime(¤t_time);
et->tm_sec = end_second;
et->tm_min = end_minute;
et->tm_hour = end_hour;
et->tm_mday = end_day;
et->tm_mon = end_month - 1;
et->tm_year = end_year - 1900;
et->tm_isdst = -1;
t2 = mktime(et);
}
/* draws a solid line */
void draw_line(int x1, int y1, int x2, int y2, int color) {
int styleSolid[1];
styleSolid[0] = color;
/* sets current style to a solid line */
gdImageSetStyle(histogram_image, styleSolid, 1);
/* draws a line (dashed) */
gdImageLine(histogram_image, x1, y1, x2, y2, gdStyled);
return;
}
/* draws a dashed line */
void draw_dashed_line(int x1, int y1, int x2, int y2, int color) {
int styleDashed[6];
styleDashed[0] = color;
styleDashed[1] = color;
styleDashed[2] = gdTransparent;
styleDashed[3] = gdTransparent;
styleDashed[4] = gdTransparent;
styleDashed[5] = gdTransparent;
/* sets current style to a solid line */
gdImageSetStyle(histogram_image, styleDashed, 6);
/* draws a line (dashed) */
gdImageLine(histogram_image, x1, y1, x2, y2, gdStyled);
return;
}
icinga-1.10.3/cgi/history.c 0000664 0000000 0000000 00000116432 12276402000 0015435 0 ustar 00root root 0000000 0000000 /*****************************************************************************
*
* HISTORY.C - Icinga History CGI
*
* Copyright (c) 1999-2009 Ethan Galstad (egalstad@nagios.org)
* Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*****************************************************************************/
/** @file history.c
* @brief cgi to browse through log history of a host/service
**/
#include "../include/config.h"
#include "../include/common.h"
#include "../include/objects.h"
#include "../include/getcgi.h"
#include "../include/cgiutils.h"
#include "../include/cgiauth.h"
#include "../include/readlogs.h"
/** @name External vars
@{ **/
extern char main_config_file[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH];
extern int enable_splunk_integration;
extern int embedded;
extern int display_header;
extern int daemon_check;
extern int result_limit;
extern int show_partial_hostgroups;
extern int show_partial_servicegroups;
/** @} */
/** @name Internal vars
@{ **/
int display_type = DISPLAY_HOSTS; /**< determine the view (host/service) */
int show_all_hosts = TRUE; /**< if historical data is requested for all hosts */
int reverse = FALSE; /**< determine if log should be viewed in reverse order */
int history_options = HISTORY_ALL; /**< determines the type of historical data */
int state_options = STATE_ALL; /**< the state of historical data */
int result_start = 1; /**< keep track from where we have to start displaying results */
int get_result_limit = -1; /**< needed to overwrite config value with result_limit we get vie GET */
int display_frills = TRUE; /**< determine if icons should be shown in listing */
int display_timebreaks = TRUE; /**< determine if time breaks should be shown */
int display_system_messages = TRUE; /**< determine if system messages should be shown */
int display_flapping_alerts = TRUE; /**< determine if flapping alerts should be shown */
int display_downtime_alerts = TRUE; /**< determine if downtime alerts should be shown */
char *host_name = "all"; /**< the requested host name */
char *service_desc = ""; /**< the requested service name */
char *hostgroup_name = ""; /**< the requested hostgroup name */
char *servicegroup_name = ""; /**< the requested hostgroup name */
time_t ts_start = 0L; /**< start time as unix timestamp */
time_t ts_end = 0L; /**< end time as unix timestamp */
authdata current_authdata; /**< struct to hold current authentication data */
int CGI_ID = HISTORY_CGI_ID; /**< ID to identify the cgi for functions in cgiutils.c */
/** @} */
/** @brief displays the requested historical log entries
*
* Applies the requested filters, reads in all necessary log files
* and afterwards showing each log entry.
**/
void show_history(void);
/** @brief Parses the requested GET/POST variables
* @return wether parsing was successful or not
* @retval TRUE
* @retval FALSE
*
* @n This function parses the request and set's the necessary variables
**/
int process_cgivars(void);
/** @brief Yes we need a main function **/
int main(void) {
int result = OK;
/* get the variables passed to us */
process_cgivars();
/* reset internal CGI variables */
reset_cgi_vars();
/* read the CGI configuration file */
result = read_cgi_config_file(get_cgi_config_location());
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(get_cgi_config_location(), ERROR_CGI_CFG_FILE, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(main_config_file, ERROR_CGI_MAIN_CFG, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(NULL, ERROR_CGI_OBJECT_DATA, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* overwrite config value with amount we got via GET */
result_limit = (get_result_limit != -1) ? get_result_limit : result_limit;
document_header(CGI_ID, TRUE, "History");
/* get authentication information */
get_authentication_information(¤t_authdata);
/* calculate timestamps for reading logs */
convert_timeperiod_to_times(TIMEPERIOD_SINGLE_DAY, &ts_start, &ts_end);
if (display_header == TRUE) {
/* begin top table */
printf("
\n");
printf("
\n");
/* left column of the first row */
printf("
\n");
if (display_type == DISPLAY_HOSTS)
display_info_table("Host Alert History", ¤t_authdata, daemon_check);
else if (display_type == DISPLAY_SERVICES)
display_info_table("Service Alert History", ¤t_authdata, daemon_check);
else if (display_type == DISPLAY_HOSTGROUPS)
display_info_table("Host Group Alert History", ¤t_authdata, daemon_check);
else if (display_type == DISPLAY_SERVICEGROUPS)
display_info_table("Service Group Alert History", ¤t_authdata, daemon_check);
else
display_info_table("Alert History", ¤t_authdata, daemon_check);
printf("
\n");
}
/* display history */
show_history();
document_footer(CGI_ID);
/* free allocated memory */
free_memory();
return OK;
}
int process_cgivars(void) {
char **variables;
int error = FALSE;
int x;
variables = getcgivars();
for (x = 0; variables[x] != NULL; x++) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */
if (strlen(variables[x]) >= MAX_INPUT_BUFFER - 1)
continue;
/* we found the host argument */
else if (!strcmp(variables[x], "host")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((host_name = (char *)strdup(variables[x])) == NULL)
host_name = "";
strip_html_brackets(host_name);
display_type = DISPLAY_HOSTS;
if (!strcmp(host_name, "all"))
show_all_hosts = TRUE;
else
show_all_hosts = FALSE;
}
/* we found the service argument */
else if (!strcmp(variables[x], "service")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((service_desc = (char *)strdup(variables[x])) == NULL)
service_desc = "";
strip_html_brackets(service_desc);
display_type = DISPLAY_SERVICES;
}
/* we found the hostgroup argument */
else if (!strcmp(variables[x], "hostgroup")) {
display_type = DISPLAY_HOSTGROUPS;
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((hostgroup_name = strdup(variables[x])) == NULL)
hostgroup_name = "";
strip_html_brackets(hostgroup_name);
}
/* we found the servicegroup argument */
else if (!strcmp(variables[x], "servicegroup")) {
display_type = DISPLAY_SERVICEGROUPS;
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((servicegroup_name = strdup(variables[x])) == NULL)
servicegroup_name = "";
strip_html_brackets(servicegroup_name);
}
/* we found the history type argument */
else if (!strcmp(variables[x], "type")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
history_options = atoi(variables[x]);
}
/* we found the history state type argument */
else if (!strcmp(variables[x], "statetype")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
state_options = atoi(variables[x]);
}
/* we found first time argument */
else if (!strcmp(variables[x], "ts_start")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
ts_start = (time_t)strtoul(variables[x], NULL, 10);
}
/* we found last time argument */
else if (!strcmp(variables[x], "ts_end")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
ts_end = (time_t)strtoul(variables[x], NULL, 10);
}
/* we found the order argument */
else if (!strcmp(variables[x], "order")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "new2old"))
reverse = FALSE;
else if (!strcmp(variables[x], "old2new"))
reverse = TRUE;
}
/* we found the embed option */
else if (!strcmp(variables[x], "embedded"))
embedded = TRUE;
/* we found the noheader option */
else if (!strcmp(variables[x], "noheader"))
display_header = FALSE;
/* we found the nodaemoncheck option */
else if (!strcmp(variables[x], "nodaemoncheck"))
daemon_check = FALSE;
/* we found the nofrills option */
else if (!strcmp(variables[x], "nofrills"))
display_frills = FALSE;
/* we found the notimebreaks option */
else if (!strcmp(variables[x], "notimebreaks"))
display_timebreaks = FALSE;
/* we found the no system messages option */
else if (!strcmp(variables[x], "nosystem"))
display_system_messages = FALSE;
/* we found the no flapping alerts option */
else if (!strcmp(variables[x], "noflapping"))
display_flapping_alerts = FALSE;
/* we found the no downtime alerts option */
else if (!strcmp(variables[x], "nodowntime"))
display_downtime_alerts = FALSE;
/* start num results to skip on displaying statusdata */
else if (!strcmp(variables[x], "start")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
result_start = atoi(variables[x]);
if (result_start < 1)
result_start = 1;
}
/* amount of results to display */
else if (!strcmp(variables[x], "limit")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
get_result_limit = atoi(variables[x]);
}
}
/* free memory allocated to the CGI variables */
free_cgivars(variables);
return error;
}
void show_history(void) {
char image[MAX_INPUT_BUFFER];
char image_alt[MAX_INPUT_BUFFER];
char match1[MAX_INPUT_BUFFER];
char match2[MAX_INPUT_BUFFER];
char date_time[MAX_DATETIME_LENGTH];
char last_message_date[MAX_INPUT_BUFFER] = "";
char current_message_date[MAX_INPUT_BUFFER] = "";
char *temp_buffer = NULL;
char *entry_host_name = NULL;
char *entry_service_desc = NULL;
char *error_text = NULL;
int system_message = FALSE;
int display_line = FALSE;
int history_type = SERVICE_HISTORY;
int history_detail_type = HISTORY_SERVICE_CRITICAL;
int status = READLOG_OK;
int displayed_entries = 0;
int total_entries = 0;
host *temp_host = NULL;
service *temp_service = NULL;
hostgroup *temp_hostgroup = NULL;
servicegroup *temp_servicegroup = NULL;
logentry *temp_entry = NULL;
struct tm *time_ptr = NULL;
logentry *entry_list = NULL;
logfilter *filter_list = NULL;
if (display_type == DISPLAY_HOSTGROUPS) {
temp_hostgroup = find_hostgroup(hostgroup_name);
if (temp_hostgroup == NULL) {
print_generic_error_message("There are no host groups with this name defined.", NULL, 0);
return;
}
/* make sure the user is authorized to view this hostgroup */
if (show_partial_hostgroups == FALSE && is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == FALSE) {
print_generic_error_message("It appears as though you do not have permission to view information for the host group you requested...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
return;
}
}
if (display_type == DISPLAY_SERVICEGROUPS) {
temp_servicegroup = find_servicegroup(servicegroup_name);
if (temp_servicegroup == NULL) {
print_generic_error_message("There are no service groups with this name defined.", NULL, 0);
return;
}
/* make sure the user is authorized to view this servicegroup */
if (show_partial_servicegroups == FALSE && is_authorized_for_servicegroup(temp_servicegroup, ¤t_authdata) == FALSE) {
print_generic_error_message("It appears as though you do not have permission to view information for the service group you requested...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
return;
}
}
add_log_filter(&filter_list, LOGENTRY_SERVICE_CRITICAL, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_WARNING, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_UNKNOWN, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_RECOVERY, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_OK, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_FLAPPING_STARTED, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_FLAPPING_STOPPED, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_FLAPPING_DISABLED, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_DOWNTIME_STARTED, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_DOWNTIME_STOPPED, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_DOWNTIME_CANCELLED, LOGFILTER_INCLUDE);
if (display_type == DISPLAY_HOSTS || display_type == DISPLAY_HOSTGROUPS) {
add_log_filter(&filter_list, LOGENTRY_HOST_DOWN, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_UNREACHABLE, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_RECOVERY, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_UP, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_FLAPPING_STARTED, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_FLAPPING_STOPPED, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_FLAPPING_DISABLED, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_FLAPPING_DISABLED, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_FLAPPING_STOPPED, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_FLAPPING_DISABLED, LOGFILTER_INCLUDE);
}
/* system log entries */
add_log_filter(&filter_list, LOGENTRY_STARTUP, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SHUTDOWN, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_BAILOUT, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_RESTART, LOGFILTER_INCLUDE);
/* scan the log file for archived state data */
status = get_log_entries(&entry_list, &filter_list, &error_text, NULL, reverse, ts_start, ts_end);
/* dealing with errors */
if (status == READLOG_ERROR_WARNING) {
if (error_text != NULL) {
print_generic_error_message(error_text, NULL, 0);
my_free(error_text);
} else
print_generic_error_message("Unkown error!", NULL, 0);
}
if (status == READLOG_ERROR_MEMORY)
print_generic_error_message("Out of memory...", "showing all I could get!", 0);
if (status == READLOG_ERROR_FATAL) {
if (error_text != NULL) {
print_generic_error_message(error_text, NULL, 0);
my_free(error_text);
}
return;
/* now we start displaying the log entries */
} else {
printf("
\n");
if (total_entries == 0) {
printf("\n");
printf("
No history information was found ");
if (display_type == DISPLAY_HOSTS)
printf("%s", (show_all_hosts == TRUE) ? "" : "for this host ");
else
printf("for this service ");
printf("in log files for selected date.
");
printf("");
} else {
printf("\n");
page_num_selector(result_start, total_entries, displayed_entries);
}
return;
}
icinga-1.10.3/cgi/notifications.c 0000664 0000000 0000000 00000126077 12276402000 0016613 0 ustar 00root root 0000000 0000000 /*****************************************************************************
*
* NOTIFICATIONS.C - Icinga Notifications CGI
*
* Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org)
* Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
*
* This CGI program will display the notification events for
* a given host or contact or for all contacts/hosts.
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*****************************************************************************/
/** @file notifications.c
* @brief cgi to browse through Icinga notification history
**/
#include "../include/config.h"
#include "../include/common.h"
#include "../include/getcgi.h"
#include "../include/cgiutils.h"
#include "../include/cgiauth.h"
#include "../include/readlogs.h"
/** @name External vars
@{ **/
extern char *csv_delimiter;
extern char *csv_data_enclosure;
extern char main_config_file[MAX_FILENAME_LENGTH];
extern int embedded;
extern int display_header;
extern int daemon_check;
extern int content_type;
extern int result_limit;
extern int show_partial_hostgroups;
extern int show_partial_servicegroups;
/** @} */
/** @name Internal vars
@{ **/
int query_type = DISPLAY_HOSTS; /**< holds requested notifications type */
int find_all = TRUE; /**< display all or just one requested host / contact */
int notification_options = NOTIFICATION_ALL; /**< determine type of notifications */
int reverse = FALSE; /**< determine if log should be viewed in reverse order */
int timeperiod_type = TIMEPERIOD_SINGLE_DAY; /**< determines the time period to view see cgiutils.h */
int result_start = 1; /**< keep track from where we have to start displaying results */
int get_result_limit = -1; /**< needed to overwrite config value with result_limit we get vie GET */
char *query_contact_name = ""; /**< the requested contact */
char *query_host_name = ""; /**< the requested host name */
char *query_svc_description = ""; /**< the requested service */
char *query_hostgroup_name = ""; /**< the requested host group */
char *query_servicegroup_name = ""; /**< the requested service group */
char *start_time_string = ""; /**< the requested start time */
char *end_time_string = ""; /**< the requested end time */
time_t ts_start = 0L; /**< start time as unix timestamp */
time_t ts_end = 0L; /**< end time as unix timestamp */
authdata current_authdata; /**< struct to hold current authentication data */
int CGI_ID = NOTIFICATIONS_CGI_ID; /**< ID to identify the cgi for functions in cgiutils.c */
/** @} */
/** @brief displays the requested notification entries
*
* Applies the requested filters, reads in all necessary log files
* and afterwards showing each matching notification log entry.
**/
void display_notifications(void);
/** @brief Parses the requested GET/POST variables
* @return wether parsing was successful or not
* @retval TRUE
* @retval FALSE
*
* @n This function parses the request and set's the necessary variables
**/
int process_cgivars(void);
/** @brief Yes we need a main function **/
int main(void) {
char buffer[MAX_DATETIME_LENGTH];
int result = OK;
/* get the arguments passed in the URL */
process_cgivars();
/* reset internal variables */
reset_cgi_vars();
/* read the CGI configuration file */
result = read_cgi_config_file(get_cgi_config_location());
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(get_cgi_config_location(), ERROR_CGI_CFG_FILE, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(main_config_file, ERROR_CGI_MAIN_CFG, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(NULL, ERROR_CGI_OBJECT_DATA, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* This requires the date_format parameter in the main config file */
if (timeperiod_type == TIMEPERIOD_CUSTOM) {
if (strcmp(start_time_string, ""))
string_to_time(start_time_string, &ts_start);
if (strcmp(end_time_string, ""))
string_to_time(end_time_string, &ts_end);
}
/* overwrite config value with amount we got via GET */
result_limit = (get_result_limit != -1) ? get_result_limit : result_limit;
/* for json and csv output return all by default */
if (get_result_limit == -1 && (content_type == JSON_CONTENT || content_type == CSV_CONTENT))
result_limit = 0;
document_header(CGI_ID, TRUE, "Alert Notifications");
/* get authentication information */
get_authentication_information(¤t_authdata);
/* calculate timestamps for reading logs */
convert_timeperiod_to_times(timeperiod_type, &ts_start, &ts_end);
if (display_header == TRUE) {
/* begin top table */
printf("
\n");
}
/* display notifications */
display_notifications();
/* display footer */
document_footer(CGI_ID);
/* free allocated memory */
free_memory();
return OK;
}
int process_cgivars(void) {
char **variables;
int error = FALSE;
int x;
variables = getcgivars();
for (x = 0; variables[x] != NULL; x++) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */
if (strlen(variables[x]) >= MAX_INPUT_BUFFER - 1)
continue;
/* we found the host argument */
else if (!strcmp(variables[x], "host")) {
query_type = DISPLAY_HOSTS;
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((query_host_name = strdup(variables[x])) == NULL)
query_host_name = "";
strip_html_brackets(query_host_name);
if (!strcmp(query_host_name, "all"))
find_all = TRUE;
else
find_all = FALSE;
}
/* we found the contact argument */
else if (!strcmp(variables[x], "contact")) {
query_type = DISPLAY_CONTACTS;
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((query_contact_name = strdup(variables[x])) == NULL)
query_contact_name = "";
strip_html_brackets(query_contact_name);
if (!strcmp(query_contact_name, "all"))
find_all = TRUE;
else
find_all = FALSE;
}
/* we found the service argument */
else if (!strcmp(variables[x], "service")) {
query_type = DISPLAY_SERVICES;
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((query_svc_description = strdup(variables[x])) == NULL)
query_svc_description = "";
strip_html_brackets(query_svc_description);
}
/* we found the hostgroup argument */
else if (!strcmp(variables[x], "hostgroup")) {
query_type = DISPLAY_HOSTGROUPS;
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((query_hostgroup_name = strdup(variables[x])) == NULL)
query_hostgroup_name = "";
strip_html_brackets(query_hostgroup_name);
}
/* we found the servicegroup argument */
else if (!strcmp(variables[x], "servicegroup")) {
query_type = DISPLAY_SERVICEGROUPS;
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((query_servicegroup_name = strdup(variables[x])) == NULL)
query_servicegroup_name = "";
strip_html_brackets(query_servicegroup_name);
}
/* we found the notification type argument */
else if (!strcmp(variables[x], "type")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
notification_options = atoi(variables[x]);
}
/* we found first time argument */
else if (!strcmp(variables[x], "ts_start")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
ts_start = (time_t)strtoul(variables[x], NULL, 10);
}
/* we found last time argument */
else if (!strcmp(variables[x], "ts_end")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
ts_end = (time_t)strtoul(variables[x], NULL, 10);
}
/* we found the start time */
else if (!strcmp(variables[x], "start_time")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
start_time_string = (char *)malloc(strlen(variables[x]) + 1);
if (start_time_string == NULL)
start_time_string = "";
else
strcpy(start_time_string, variables[x]);
}
/* we found the end time */
else if (!strcmp(variables[x], "end_time")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
end_time_string = (char *)malloc(strlen(variables[x]) + 1);
if (end_time_string == NULL)
end_time_string = "";
else
strcpy(end_time_string, variables[x]);
}
/* we found the standard timeperiod argument */
else if (!strcmp(variables[x], "timeperiod")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "today"))
timeperiod_type = TIMEPERIOD_TODAY;
else if (!strcmp(variables[x], "singelday"))
timeperiod_type = TIMEPERIOD_SINGLE_DAY;
else if (!strcmp(variables[x], "last24hours"))
timeperiod_type = TIMEPERIOD_LAST24HOURS;
else if (!strcmp(variables[x], "thisweek"))
timeperiod_type = TIMEPERIOD_THISWEEK;
else if (!strcmp(variables[x], "lastweek"))
timeperiod_type = TIMEPERIOD_LASTWEEK;
else if (!strcmp(variables[x], "thismonth"))
timeperiod_type = TIMEPERIOD_THISMONTH;
else if (!strcmp(variables[x], "lastmonth"))
timeperiod_type = TIMEPERIOD_LASTMONTH;
else if (!strcmp(variables[x], "thisyear"))
timeperiod_type = TIMEPERIOD_THISYEAR;
else if (!strcmp(variables[x], "lastyear"))
timeperiod_type = TIMEPERIOD_LASTYEAR;
else if (!strcmp(variables[x], "last7days"))
timeperiod_type = TIMEPERIOD_LAST7DAYS;
else if (!strcmp(variables[x], "last31days"))
timeperiod_type = TIMEPERIOD_LAST31DAYS;
else if (!strcmp(variables[x], "custom"))
timeperiod_type = TIMEPERIOD_CUSTOM;
else
continue;
convert_timeperiod_to_times(timeperiod_type, &ts_start, &ts_end);
}
/* we found the order argument */
else if (!strcmp(variables[x], "order")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "new2old"))
reverse = FALSE;
else if (!strcmp(variables[x], "old2new"))
reverse = TRUE;
}
/* we found the CSV output option */
else if (!strcmp(variables[x], "csvoutput")) {
display_header = FALSE;
content_type = CSV_CONTENT;
}
/* we found the JSON output option */
else if (!strcmp(variables[x], "jsonoutput")) {
display_header = FALSE;
content_type = JSON_CONTENT;
}
/* we found the embed option */
else if (!strcmp(variables[x], "embedded"))
embedded = TRUE;
/* we found the noheader option */
else if (!strcmp(variables[x], "noheader"))
display_header = FALSE;
/* we found the nodaemoncheck option */
else if (!strcmp(variables[x], "nodaemoncheck"))
daemon_check = FALSE;
/* start num results to skip on displaying statusdata */
else if (!strcmp(variables[x], "start")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
result_start = atoi(variables[x]);
if (result_start < 1)
result_start = 1;
}
/* amount of results to display */
else if (!strcmp(variables[x], "limit")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
get_result_limit = atoi(variables[x]);
}
}
/*
* Set some default values if not already set.
* Done here as they won't be set if variable
* not provided via cgi parameters
* Only required for hosts & contacts, not services
* as there is no service_name=all option
*/
if (query_type == DISPLAY_HOSTS && strlen(query_host_name) == 0) {
query_host_name = "all";
find_all = TRUE;
}
if (query_type == DISPLAY_CONTACTS && strlen(query_contact_name) == 0) {
query_contact_name = "all";
find_all = TRUE;
}
/* free memory allocated to the CGI variables */
free_cgivars(variables);
return error;
}
void display_notifications(void) {
char *temp_buffer;
char *error_text = NULL;
char date_time[MAX_DATETIME_LENGTH];
char alert_level[MAX_INPUT_BUFFER];
char alert_level_class[MAX_INPUT_BUFFER];
char contact_name[MAX_INPUT_BUFFER];
char service_name[MAX_INPUT_BUFFER];
char host_name[MAX_INPUT_BUFFER];
char method_name[MAX_INPUT_BUFFER];
char displayed_host_name[MAX_INPUT_BUFFER];
char displayed_service_desc[MAX_INPUT_BUFFER];
int show_entry;
int total_notifications = 0;
int displayed_entries = 0;
int notification_detail_type = NOTIFICATION_SERVICE_CRITICAL;
int status = READLOG_OK;
int odd = 0;
int json_start = TRUE;
host *temp_host = NULL;
service *temp_service = NULL;
hostgroup *temp_hostgroup = NULL;
servicegroup *temp_servicegroup = NULL;
logentry *temp_entry = NULL;
logentry *entry_list = NULL;
logfilter *filter_list = NULL;
if (query_type == DISPLAY_HOSTGROUPS) {
temp_hostgroup = find_hostgroup(query_hostgroup_name);
if (temp_hostgroup == NULL) {
print_generic_error_message("There are no host groups with this name defined.", NULL, 0);
return;
}
/* make sure the user is authorized to view this hostgroup */
if (show_partial_hostgroups == FALSE && is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == FALSE) {
print_generic_error_message("It appears as though you do not have permission to view information for the host group you requested...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
return;
}
}
if (query_type == DISPLAY_SERVICEGROUPS) {
temp_servicegroup = find_servicegroup(query_servicegroup_name);
if (temp_servicegroup == NULL) {
print_generic_error_message("There are no service groups with this name defined.", NULL, 0);
return;
}
/* make sure the user is authorized to view this servicegroup */
if (show_partial_servicegroups == FALSE && is_authorized_for_servicegroup(temp_servicegroup, ¤t_authdata) == FALSE) {
print_generic_error_message("It appears as though you do not have permission to view information for the service group you requested...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
return;
}
}
add_log_filter(&filter_list, LOGENTRY_HOST_NOTIFICATION, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_NOTIFICATION, LOGFILTER_INCLUDE);
/* scan the log file for notification data */
status = get_log_entries(&entry_list, &filter_list, &error_text, NULL, reverse, ts_start, ts_end);
free_log_filters(&filter_list);
/* dealing with errors */
if (status == READLOG_ERROR_WARNING) {
if (error_text != NULL) {
print_generic_error_message(error_text, NULL, 0);
my_free(error_text);
} else
print_generic_error_message("Unkown error!", NULL, 0);
}
if (status == READLOG_ERROR_MEMORY)
print_generic_error_message("Out of memory...", "showing all I could get!", 0);
if (status == READLOG_ERROR_FATAL) {
if (error_text != NULL) {
print_generic_error_message(error_text, NULL, 0);
my_free(error_text);
}
return;
/* now we start displaying the notification entries */
} else {
if (content_type == JSON_CONTENT) {
if (status != READLOG_OK)
printf(",\n");
printf("\"notifications\": [\n");
} else if (content_type == CSV_CONTENT) {
printf("%sHOST%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sSERVICE%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sTYPE%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sTIME%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sCONTACT%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sNOTIFICATION_COMMAND%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sINFORMATION%s\n", csv_data_enclosure, csv_data_enclosure);
} else {
printf("
\n");
/* add export to csv, json, link */
printf("
No notifications have been recorded");
if (find_all == FALSE) {
if (query_type == DISPLAY_SERVICES)
printf(" for this service");
else if (query_type == DISPLAY_CONTACTS)
printf(" for this contact");
else
printf(" for this host");
}
printf(" in log files for selected date.
");
}
page_num_selector(result_start, total_notifications, displayed_entries);
} else if (content_type == JSON_CONTENT) {
printf("\n]\n");
}
return;
}
icinga-1.10.3/cgi/outages.c 0000664 0000000 0000000 00000056335 12276402000 0015410 0 ustar 00root root 0000000 0000000 /**************************************************************************
*
* OUTAGES.C - Icinga Network Outages CGI
*
* Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org)
* Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*************************************************************************/
#include "../include/config.h"
#include "../include/common.h"
#include "../include/objects.h"
#include "../include/comments.h"
#include "../include/statusdata.h"
#include "../include/cgiutils.h"
#include "../include/getcgi.h"
#include "../include/cgiauth.h"
extern time_t program_start;
extern host *host_list;
extern service *service_list;
extern hoststatus *hoststatus_list;
extern servicestatus *servicestatus_list;
extern char main_config_file[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH];
/* AFFECTEDHOSTS structure */
typedef struct affected_host {
char *host_name;
struct affected_host *next;
} affected_host;
/* HOSTOUTAGE structure */
typedef struct hostoutage_struct {
host *hst;
int severity;
int affected_child_hosts;
int affected_child_services;
unsigned long monitored_time;
unsigned long time_up;
float percent_time_up;
unsigned long time_down;
float percent_time_down;
unsigned long time_unreachable;
float percent_time_unreachable;
struct affected_host *affected_hosts;
struct hostoutage_struct *next;
} hostoutage;
/* HOSTOUTAGESORT structure */
typedef struct hostoutagesort_struct {
hostoutage *outage;
struct hostoutagesort_struct *next;
} hostoutagesort;
int process_cgivars(void);
void display_network_outages(void);
void find_hosts_causing_outages(void);
void calculate_outage_effects(void);
void calculate_outage_effect_of_host(host *, int *, int *);
int is_route_to_host_blocked(host *);
int number_of_host_services(host *);
void add_hostoutage(host *);
void sort_hostoutages(void);
void free_hostoutage_list(void);
void free_hostoutagesort_list(void);
void add_affected_host(char *);
authdata current_authdata;
hostoutage *hostoutage_list = NULL;
hostoutagesort *hostoutagesort_list = NULL;
hostoutage *currently_checked_host = NULL;
int service_severity_divisor = 4; /* default = services are 1/4 as important as hosts */
extern int embedded;
extern int refresh;
extern int display_header;
extern int daemon_check;
extern int content_type;
extern char *csv_delimiter;
extern char *csv_data_enclosure;
int CGI_ID = OUTAGES_CGI_ID;
int main(void) {
int result = OK;
/* get the arguments passed in the URL */
process_cgivars();
/* reset internal variables */
reset_cgi_vars();
/* read the CGI configuration file */
result = read_cgi_config_file(get_cgi_config_location());
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(get_cgi_config_location(), ERROR_CGI_CFG_FILE, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(main_config_file, ERROR_CGI_MAIN_CFG, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(NULL, ERROR_CGI_OBJECT_DATA, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* read all status data */
result = read_all_status_data(main_config_file, READ_ALL_STATUS_DATA);
if (result == ERROR && daemon_check == TRUE) {
document_header(CGI_ID, FALSE, "Error");
print_error(NULL, ERROR_CGI_STATUS_DATA, FALSE);
document_footer(CGI_ID);
free_memory();
return ERROR;
}
document_header(CGI_ID, TRUE, "Network Outages");
/* get authentication information */
get_authentication_information(¤t_authdata);
if (display_header == TRUE) {
/* begin top table */
printf("
\n");
}
/* display network outage info */
display_network_outages();
document_footer(CGI_ID);
/* free memory allocated to comment data */
free_comment_data();
/* free all allocated memory */
free_memory();
return OK;
}
int process_cgivars(void) {
char **variables;
int error = FALSE;
int x;
variables = getcgivars();
for (x = 0; variables[x] != NULL; x++) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */
if (strlen(variables[x]) >= MAX_INPUT_BUFFER - 1)
continue;
/* we found the service severity divisor option */
if (!strcmp(variables[x], "service_divisor")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
service_severity_divisor = atoi(variables[x]);
if (service_severity_divisor < 1)
service_severity_divisor = 1;
}
/* we found the CSV output option */
else if (!strcmp(variables[x], "csvoutput")) {
display_header = FALSE;
content_type = CSV_CONTENT;
}
else if (!strcmp(variables[x], "jsonoutput")) {
display_header = FALSE;
content_type = JSON_CONTENT;
}
/* we found the embed option */
else if (!strcmp(variables[x], "embedded"))
embedded = TRUE;
/* we found the noheader option */
else if (!strcmp(variables[x], "noheader"))
display_header = FALSE;
/* we found the pause option */
else if (!strcmp(variables[x], "paused"))
refresh = FALSE;
/* we found the nodaemoncheck option */
else if (!strcmp(variables[x], "nodaemoncheck"))
daemon_check = FALSE;
}
/* free memory allocated to the CGI variables */
free_cgivars(variables);
return error;
}
/* shows all hosts that are causing network outages */
void display_network_outages(void) {
int number_of_problem_hosts = 0;
int number_of_blocking_problem_hosts = 0;
hostoutagesort *temp_hostoutagesort;
hostoutage *temp_hostoutage;
hoststatus *temp_hoststatus;
affected_host * temp_affected_host;
int odd = 0;
char *bg_class = "";
char *status = "";
int days;
int hours;
int minutes;
int seconds;
int total_comments;
time_t t;
time_t current_time;
char state_duration[48];
int total_entries = 0;
int json_start = TRUE;
/* find all hosts that are causing network outages */
find_hosts_causing_outages();
/* calculate outage effects */
calculate_outage_effects();
/* sort the outage list by severity */
sort_hostoutages();
/* count the number of top-level hosts that are down and the ones that are actually blocking children hosts */
for (temp_hostoutage = hostoutage_list; temp_hostoutage != NULL; temp_hostoutage = temp_hostoutage->next) {
number_of_problem_hosts++;
if (temp_hostoutage->affected_child_hosts > 1)
number_of_blocking_problem_hosts++;
}
if (content_type == JSON_CONTENT) {
printf("\"outages\": [\n");
} else if (content_type == CSV_CONTENT) {
printf("%sSEVERITY%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sHOST%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sSTATE%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sNOTES%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sSTATE_DURATION%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sHOSTS_AFFECTED%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sSERVICES_AFFECTED%s\n", csv_data_enclosure, csv_data_enclosure);
} else {
/* display the problem hosts... */
printf("
\n", total_entries);
} else if (content_type == JSON_CONTENT) {
printf("\n]\n");
}
/* free memory allocated to the host outage list */
free_hostoutage_list();
free_hostoutagesort_list();
return;
}
/* determine what hosts are causing network outages */
void find_hosts_causing_outages(void) {
hoststatus *temp_hoststatus;
host *temp_host;
/* check all hosts */
for (temp_hoststatus = hoststatus_list; temp_hoststatus != NULL; temp_hoststatus = temp_hoststatus->next) {
/* check only hosts that are not up and not pending */
if (temp_hoststatus->status != HOST_UP && temp_hoststatus->status != HOST_PENDING) {
/* find the host entry */
temp_host = find_host(temp_hoststatus->host_name);
if (temp_host == NULL)
continue;
if (is_authorized_for_host(temp_host, ¤t_authdata) == FALSE)
continue;
/* if the route to this host is not blocked, it is a causing an outage */
if (is_route_to_host_blocked(temp_host) == FALSE)
add_hostoutage(temp_host);
}
}
return;
}
/* adds a host outage entry */
void add_hostoutage(host *hst) {
hostoutage *new_hostoutage;
/* allocate memory for a new structure */
new_hostoutage = (hostoutage *)malloc(sizeof(hostoutage));
if (new_hostoutage == NULL)
return;
new_hostoutage->hst = hst;
new_hostoutage->severity = 0;
new_hostoutage->affected_child_hosts = 0;
new_hostoutage->affected_child_services = 0;
new_hostoutage->affected_hosts = NULL;
/* add the structure to the head of the list in memory */
new_hostoutage->next = hostoutage_list;
hostoutage_list = new_hostoutage;
return;
}
/* frees all memory allocated to the host outage list */
void free_hostoutage_list(void) {
hostoutage *this_hostoutage;
hostoutage *next_hostoutage;
affected_host *this_affected_host;
affected_host *next_affected_host;
/* free all list members */
for (this_hostoutage = hostoutage_list; this_hostoutage != NULL; this_hostoutage = next_hostoutage) {
next_hostoutage = this_hostoutage->next;
/* free affected host list */
for (this_affected_host = this_hostoutage->affected_hosts; this_affected_host != NULL; this_affected_host = next_affected_host) {
next_affected_host = this_affected_host->next;
my_free(this_affected_host->host_name);
my_free(this_affected_host);
}
my_free(this_hostoutage);
}
/* reset list pointer */
hostoutage_list = NULL;
return;
}
/* frees all memory allocated to the host outage sort list */
void free_hostoutagesort_list(void) {
hostoutagesort *this_hostoutagesort;
hostoutagesort *next_hostoutagesort;
/* free all list members */
for (this_hostoutagesort = hostoutagesort_list; this_hostoutagesort != NULL; this_hostoutagesort = next_hostoutagesort) {
next_hostoutagesort = this_hostoutagesort->next;
my_free(this_hostoutagesort);
}
/* reset list pointer */
hostoutagesort_list = NULL;
return;
}
/* calculates network outage effect of all hosts that are causing blockages */
void calculate_outage_effects(void) {
hostoutage *temp_hostoutage;
/* check all hosts causing problems */
for (temp_hostoutage = hostoutage_list; temp_hostoutage != NULL; temp_hostoutage = temp_hostoutage->next) {
currently_checked_host = temp_hostoutage;
/* calculate the outage effect of this particular hosts */
calculate_outage_effect_of_host(temp_hostoutage->hst, &temp_hostoutage->affected_child_hosts, &temp_hostoutage->affected_child_services);
temp_hostoutage->severity = (temp_hostoutage->affected_child_hosts + (temp_hostoutage->affected_child_services / service_severity_divisor));
}
return;
}
/* calculates network outage effect of a particular host being down or unreachable */
void calculate_outage_effect_of_host(host *hst, int *affected_hosts, int *affected_services) {
int total_child_hosts_affected = 0;
int total_child_services_affected = 0;
int temp_child_hosts_affected = 0;
int temp_child_services_affected = 0;
host *temp_host;
/* find all child hosts of this host */
for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
/* skip this host if it is not a child */
if (is_host_immediate_child_of_host(hst, temp_host) == FALSE)
continue;
/* calculate the outage effect of the child */
calculate_outage_effect_of_host(temp_host, &temp_child_hosts_affected, &temp_child_services_affected);
/* keep a running total of outage effects */
total_child_hosts_affected += temp_child_hosts_affected;
total_child_services_affected += temp_child_services_affected;
add_affected_host(temp_host->name);
}
*affected_hosts = total_child_hosts_affected + 1;
*affected_services = total_child_services_affected + number_of_host_services(hst);
return;
}
/* tests whether or not a host is "blocked" by upstream parents (host is already assumed to be down or unreachable) */
int is_route_to_host_blocked(host *hst) {
hostsmember *temp_hostsmember;
hoststatus *temp_hoststatus;
/* if the host has no parents, it is not being blocked by anyone */
if (hst->parent_hosts == NULL)
return FALSE;
/* check all parent hosts */
for (temp_hostsmember = hst->parent_hosts; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
/* find the parent host's status */
temp_hoststatus = find_hoststatus(temp_hostsmember->host_name);
if (temp_hoststatus == NULL)
continue;
/* at least one parent is up (or pending), so this host is not blocked */
if (temp_hoststatus->status == HOST_UP || temp_hoststatus->status == HOST_PENDING)
return FALSE;
}
return TRUE;
}
/* calculates the number of services associated a particular host */
int number_of_host_services(host *hst) {
int total_services = 0;
service *temp_service;
/* check all services */
for (temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) {
if (!strcmp(temp_service->host_name, hst->name))
total_services++;
}
return total_services;
}
/* sort the host outages by severity */
void sort_hostoutages(void) {
hostoutagesort *last_hostoutagesort;
hostoutagesort *new_hostoutagesort;
hostoutagesort *temp_hostoutagesort;
hostoutage *temp_hostoutage;
if (hostoutage_list == NULL)
return;
/* sort all host outage entries */
for (temp_hostoutage = hostoutage_list; temp_hostoutage != NULL; temp_hostoutage = temp_hostoutage->next) {
/* allocate memory for a new sort structure */
new_hostoutagesort = (hostoutagesort *)malloc(sizeof(hostoutagesort));
if (new_hostoutagesort == NULL)
return;
new_hostoutagesort->outage = temp_hostoutage;
last_hostoutagesort = hostoutagesort_list;
for (temp_hostoutagesort = hostoutagesort_list; temp_hostoutagesort != NULL; temp_hostoutagesort = temp_hostoutagesort->next) {
if (new_hostoutagesort->outage->severity >= temp_hostoutagesort->outage->severity) {
new_hostoutagesort->next = temp_hostoutagesort;
if (temp_hostoutagesort == hostoutagesort_list)
hostoutagesort_list = new_hostoutagesort;
else
last_hostoutagesort->next = new_hostoutagesort;
break;
} else
last_hostoutagesort = temp_hostoutagesort;
}
if (hostoutagesort_list == NULL) {
new_hostoutagesort->next = NULL;
hostoutagesort_list = new_hostoutagesort;
} else if (temp_hostoutagesort == NULL) {
new_hostoutagesort->next = NULL;
last_hostoutagesort->next = new_hostoutagesort;
}
}
return;
}
void add_affected_host(char *host_name) {
affected_host *new_affected_host;
affected_host *temp_affected_host;
if (currently_checked_host->affected_hosts!=NULL) {
for (temp_affected_host = currently_checked_host->affected_hosts; temp_affected_host != NULL; temp_affected_host = temp_affected_host->next) {
if (!strcmp(temp_affected_host->host_name, host_name))
return;
}
}
/* allocate memory for a new structure */
new_affected_host = (affected_host *)malloc(sizeof(affected_host));
if (new_affected_host == NULL)
return;
new_affected_host->host_name = strdup(host_name);
/* add the structure to the head of the list in memory */
new_affected_host->next = currently_checked_host->affected_hosts;
currently_checked_host->affected_hosts = new_affected_host;
return;
}
icinga-1.10.3/cgi/readlogs.c 0000664 0000000 0000000 00000050337 12276402000 0015535 0 ustar 00root root 0000000 0000000 /***********************************************************************
*
* READLOGS.C - Functions for reading Log files in Icinga CGIs
*
* Copyright (c) 1999-2009 Ethan Galstad (egalstad@nagios.org)
* Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
***********************************************************************/
/** @file readlogs.c
* @brief functions to read and filter log files in normal and reverse order
**/
#include "../include/cgiutils.h"
#include "../include/readlogs.h"
/** @brief file name data struct
*
* structure to hold single file name for file list array
**/
struct file_data {
char *file_name; /**< holds file name */
};
/** @name external vars
@{ **/
extern char log_file[MAX_FILENAME_LENGTH]; /**< the full file name of the main icinga log file */
extern char log_archive_path[MAX_FILENAME_LENGTH]; /**< the full path to the archived log files */
extern int log_rotation_method; /**< time interval of log rotation */
/** @} */
/** @brief sort helper function for icinga logfile sorting
* @param [in] a_in file a to compare
* @param [in] b_in file b to compare
* @return wether file a is newer or older then file b, based on filename
* @retval positive or negative
* @author Ricardo Bartels
**/
int sort_icinga_logfiles_by_name(const void *a_in, const void *b_in) {
char date_a[11] = "";
char date_b[11] = "";
struct file_data *a = (struct file_data *)a_in;
struct file_data *b = (struct file_data *)b_in;
if (a->file_name == NULL && b->file_name == NULL)
return 0;
if (a->file_name != NULL && b->file_name == NULL)
return 1;
if (a->file_name == NULL && b->file_name != NULL)
return -1;
// year
date_a[0] = a->file_name[13];
date_a[1] = a->file_name[14];
date_a[2] = a->file_name[15];
date_a[3] = a->file_name[16];
//month
date_a[4] = a->file_name[7];
date_a[5] = a->file_name[8];
// day
date_a[6] = a->file_name[10];
date_a[7] = a->file_name[11];
// hour
date_a[8] = a->file_name[18];
date_a[9] = a->file_name[19];
date_a[10] = 0;
// year
date_b[0] = b->file_name[13];
date_b[1] = b->file_name[14];
date_b[2] = b->file_name[15];
date_b[3] = b->file_name[16];
// month
date_b[4] = b->file_name[7];
date_b[5] = b->file_name[8];
// day
date_b[6] = b->file_name[10];
date_b[7] = b->file_name[11];
// hour
date_b[8] = b->file_name[18];
date_b[9] = b->file_name[19];
date_b[10] = 0;
// return compared values
return (int)(atoi(date_b) - atoi(date_a));
}
/** @brief Add Filter to the list of log filters
* @param [out] filter_list a list of filters of type logfilter struct where requested filter got added
* @param [in] requested_filter the id of the log entry you want to filter for
* @param [in] include_exclude type of filter
* @arg LOGFILTER_INCLUDE
* @arg LOGFILTER_EXCLUDE
* @return wether adding filter was successful or not (see readlogs.h)
* @retval READLOG_OK
* @retval READLOG_ERROR_FATAL
* @retval READLOG_ERROR_MEMORY
* @warning at the moment can be only one type of filters for all elements,
* only include for all OR exclude for all.
* Combining is not available at the moment
* @author Ricardo Bartels
*
* With this function you can add filters before reading the actual log entries
* from file. This will prevent allocating memory for log entries we don't need
* anyway. Be aware that you can use only one type of filtering (include or exclude).
* If you want to have all entries except a view, then use the filter with exclude.
* If you need just a few defined ones (like in notifications.c) then use include.
*
* - LOGFILTER_INCLUDE keeps the log entries specified and throws out the rest
* - LOGFILTER_EXCLUDE keeps all log entries except the ones which are specified
**/
int add_log_filter(logfilter **new_filter, int requested_filter, int include_exclude) {
logfilter *temp_filter = NULL;
temp_filter = (logfilter *)malloc(sizeof(logfilter));
if (temp_filter == NULL)
return READLOG_ERROR_MEMORY;
/* initialize filter */
temp_filter->next = NULL;
temp_filter->include = 0;
temp_filter->exclude = 0;
if (include_exclude == LOGFILTER_INCLUDE)
temp_filter->include = requested_filter;
else if (include_exclude == LOGFILTER_EXCLUDE)
temp_filter->exclude = requested_filter;
else {
my_free(temp_filter);
return READLOG_ERROR_FATAL;
}
if (*new_filter == NULL)
*new_filter = temp_filter;
else {
temp_filter->next = *new_filter;
*new_filter = temp_filter;
}
return READLOG_OK;
}
/** @brief Read's log data for defined timerange and stores the entries into entry_list struct
* @param [out] entry_list returns a filled entry list of requested log data
* @param [in] filter_list a list of filters of type logfilter struct
* @param [out] error_text returns a error string in case of an error execpt on READLOG_ERROR_MEMORY
* @param [in] search_string a string you are searching for
* Set to NULL to disable search function
* @param [in] reverse this bool defines which order the log entries should return
* @param [in] ts_start defines the start timestamp for log entries
* @arg >=0 means unix timestamp
* @param [in] ts_end defines the end timestamp for log entries
* @arg >=0 means unix timestamp
* @return
* @retval READLOG_OK
* @retval READLOG_ERROR_WARNING
* @retval READLOG_ERROR_FATAL
* @retval READLOG_ERROR_MEMORY
* @retval READLOG_ERROR_FILTER
* @author Ricardo Bartels
*
* This functions reads a \c log_file and and try's (if set) to filter for a search string.
* This search string uses regular expressions. The reverse option defines if you want
* have your log entries returned in normal or revers order. Normal order for returning
* would be from the newest entry to the oldest. You can also set a time "window". This
* defines if you want to exclude entries which are outside of these "window". Then only
* entries will be returned which are between start and end. Very useful if user has all
* entries in one log file.
**/
int get_log_entries(logentry **entry_list, logfilter **filter_list, char **error_text, char *search_string, int reverse, time_t ts_start, time_t ts_end) {
char *input = NULL;
char *temp_buffer = NULL;
char *search_regex = NULL;
char log_file_name[MAX_FILENAME_LENGTH];
char ts_buffer[16];
int type = 0;
int regex_i = 0, i = 0, len = 0;
int file_num = 1;
int file = 0;
int in_range = FALSE;
int return_val = READLOG_OK;
int data_found = FALSE;
short keep_entry = TRUE;
time_t timestamp = 0L;
time_t last_timestamp = 0L;
mmapfile *thefile = NULL;
logentry *temp_entry = NULL;
logentry *last_entry = NULL;
regex_t preg;
logfilter *temp_filter;
DIR *dirp;
struct dirent *dptr;
struct file_data files[10000];
/* empty error_text */
if (*error_text != NULL)
my_free(*error_text);
/* bail out if one timestamp is negative */
if (ts_start < 0 || ts_end < 0) {
*error_text = strdup("start or end timestamp are invalid. Check submited date information");
return READLOG_ERROR_FATAL;
}
/* check if search_string is set */
if (search_string != NULL) {
/* allocate for 3 extra chars, ^, $ and \0 */
search_regex = malloc(sizeof(char) * (strlen(search_string) * 2 + 3));
len = strlen(search_string);
for (i = 0; i < len; i++, regex_i++) {
if (search_string[i] == '*') {
search_regex[regex_i++] = '.';
search_regex[regex_i] = '*';
} else
search_regex[regex_i] = search_string[i];
}
search_regex[regex_i] = '\0';
/* check and compile regex, return error on failure */
if (regcomp(&preg, search_regex, REG_ICASE | REG_NOSUB) != 0) {
regfree(&preg);
my_free(search_regex);
*error_text = strdup("It seems like that reagular expressions don't like what you searched for. Please change your search string.");
return READLOG_ERROR_FATAL;
}
my_free(search_regex);
}
/* initialize file data array */
for (i=0;i<10000;i++)
files[i].file_name = NULL;
/* try to open log_archive_path, return if it fails */
if ((dirp=opendir(log_archive_path)) == NULL){
if (search_string != NULL)
regfree(&preg);
asprintf(&temp_buffer, "Unable to open \"log_archive_path\" -> \"%s\"!!!", log_archive_path);
*error_text = strdup(temp_buffer);
my_free(temp_buffer);
return READLOG_ERROR_FATAL;
} else {
/* read every dir entry */
while ((dptr=readdir(dirp)) != NULL) {
/* filter dir for icinga / nagios log files */
if ((strncmp("icinga-",dptr->d_name,7) == 0 || strncmp("nagios-",dptr->d_name,7) == 0 ) &&
strstr(dptr->d_name, ".log") && strlen(dptr->d_name) == 24)
files[file_num++].file_name = strdup(dptr->d_name);
}
closedir(dirp);
}
/* sort log files, newest first */
qsort((void *)files, file_num, sizeof(struct file_data), sort_icinga_logfiles_by_name);
/* define which log files to use */
for (i=0; i< file_num; i++) {
/* first log file is always the current log file */
if (i == 0) {
strncpy(log_file_name, log_file, sizeof(log_file_name) -1);
log_file_name[sizeof(log_file_name)-1] = '\x0';
/* return full path of logfile and store first timestamp of last file */
} else {
snprintf(log_file_name, sizeof(log_file_name) -1, "%s%s",log_archive_path, files[i].file_name);
log_file_name[sizeof(log_file_name)-1] = '\x0';
last_timestamp = timestamp;
}
/* free file entry and set to NULL. if valid file is found, entry gets refilled */
my_free(files[i].file_name);
/* we found data and we are out of range again, file must be older then ts_start. stop checking files */
if (data_found == TRUE && in_range == FALSE)
continue;
/* try to open log file, or throw error and try next log file */
if((file=open(log_file_name, O_RDONLY)) < -1) {
if (*error_text == NULL) {
asprintf(&temp_buffer, "Unable to open log file \"%s\" !!!", log_file_name);
*error_text = strdup(temp_buffer);
my_free(temp_buffer);
}
return_val = READLOG_ERROR_WARNING;
continue;
}
/* read first 16 bytes to get first timestamp, or throw error if data is not 16 bytes log (empty file) */
if(read(file,ts_buffer,16) != 16) {
if (*error_text == NULL) {
asprintf(&temp_buffer, "Log file \"%s\" invalid! No timestamp found within first 16 bytes!", log_file_name);
*error_text = strdup(temp_buffer);
my_free(temp_buffer);
}
return_val = READLOG_ERROR_WARNING;
close(file);
continue;
}
close(file);
/* get first timestamp */
temp_buffer = strtok(ts_buffer, "]");
timestamp = (temp_buffer == NULL) ? 0L : strtoul(temp_buffer + 1, NULL, 10);
/* if first (oldest) timestamp in file is newer then ts_end, skip file */
if (timestamp > ts_end)
continue;
in_range = TRUE;
/* the priviouse file holds range for ts_start */
if (last_timestamp != 0L && last_timestamp < ts_start)
in_range = FALSE;
/* keep file if in range */
if(in_range == TRUE) {
files[i].file_name = strdup(log_file_name);
data_found = TRUE;
}
}
/* read all log files we found earlier in reverse order, starting with the oldest */
for (i=file_num; i >= 0; i--) {
/* if file name is empty try next file */
if (files[i].file_name == NULL)
continue;
/* try to open log file */
if ((thefile = mmap_fopen(files[i].file_name)) == NULL)
continue;
while (1) {
/* free memory */
my_free(input);
if ((input = mmap_fgets(thefile)) == NULL)
break;
strip(input);
if ((int)strlen(input) == 0)
continue;
/* get timestamp */
temp_buffer = strtok(input, "]");
if (temp_buffer == NULL)
continue;
timestamp = strtoul(temp_buffer + 1, NULL, 10);
/* skip line if out of range */
if ((ts_end >= 0 && timestamp > ts_end) || (ts_start >= 0 && timestamp < ts_start))
continue;
/* get log entry text */
temp_buffer = strtok(NULL, "\n");
if (temp_buffer == NULL)
continue;
/* if we search for something, check if it entry matches search_string */
if (search_string != NULL) {
if (regexec(&preg, temp_buffer, 0, NULL, 0) == REG_NOMATCH)
continue;
}
/* categorize log entry */
if (strstr(temp_buffer, " starting..."))
type = LOGENTRY_STARTUP;
else if (strstr(temp_buffer, " shutting down..."))
type = LOGENTRY_SHUTDOWN;
else if (strstr(temp_buffer, "Bailing out"))
type = LOGENTRY_BAILOUT;
else if (strstr(temp_buffer, " restarting..."))
type = LOGENTRY_RESTART;
else if (strstr(temp_buffer, "HOST ALERT:") && strstr(temp_buffer, ";DOWN;"))
type = LOGENTRY_HOST_DOWN;
else if (strstr(temp_buffer, "HOST ALERT:") && strstr(temp_buffer, ";UNREACHABLE;"))
type = LOGENTRY_HOST_UNREACHABLE;
else if (strstr(temp_buffer, "HOST ALERT:") && strstr(temp_buffer, ";RECOVERY;"))
type = LOGENTRY_HOST_RECOVERY;
else if (strstr(temp_buffer, "HOST ALERT:") && strstr(temp_buffer, ";UP;"))
type = LOGENTRY_HOST_UP;
else if (strstr(temp_buffer, "HOST NOTIFICATION:"))
type = LOGENTRY_HOST_NOTIFICATION;
else if (strstr(temp_buffer, "SERVICE ALERT:") && strstr(temp_buffer, ";CRITICAL;"))
type = LOGENTRY_SERVICE_CRITICAL;
else if (strstr(temp_buffer, "SERVICE ALERT:") && strstr(temp_buffer, ";WARNING;"))
type = LOGENTRY_SERVICE_WARNING;
else if (strstr(temp_buffer, "SERVICE ALERT:") && strstr(temp_buffer, ";UNKNOWN;"))
type = LOGENTRY_SERVICE_UNKNOWN;
else if (strstr(temp_buffer, "SERVICE ALERT:") && strstr(temp_buffer, ";RECOVERY;"))
type = LOGENTRY_SERVICE_RECOVERY;
else if (strstr(temp_buffer, "SERVICE ALERT:") && strstr(temp_buffer, ";OK;"))
type = LOGENTRY_SERVICE_OK;
else if (strstr(temp_buffer, "SERVICE NOTIFICATION:"))
type = LOGENTRY_SERVICE_NOTIFICATION;
else if (strstr(temp_buffer, "SERVICE EVENT HANDLER:"))
type = LOGENTRY_SERVICE_EVENT_HANDLER;
else if (strstr(temp_buffer, "HOST EVENT HANDLER:"))
type = LOGENTRY_HOST_EVENT_HANDLER;
else if (strstr(temp_buffer, "EXTERNAL COMMAND:"))
type = LOGENTRY_EXTERNAL_COMMAND;
else if (strstr(temp_buffer, "PASSIVE SERVICE CHECK:"))
type = LOGENTRY_PASSIVE_SERVICE_CHECK;
else if (strstr(temp_buffer, "PASSIVE HOST CHECK:"))
type = LOGENTRY_PASSIVE_HOST_CHECK;
else if (strstr(temp_buffer, "LOG ROTATION:"))
type = LOGENTRY_LOG_ROTATION;
else if (strstr(temp_buffer, "active mode..."))
type = LOGENTRY_ACTIVE_MODE;
else if (strstr(temp_buffer, "standby mode..."))
type = LOGENTRY_STANDBY_MODE;
else if (strstr(temp_buffer, "SERVICE FLAPPING ALERT:") && strstr(temp_buffer, ";STARTED;"))
type = LOGENTRY_SERVICE_FLAPPING_STARTED;
else if (strstr(temp_buffer, "SERVICE FLAPPING ALERT:") && strstr(temp_buffer, ";STOPPED;"))
type = LOGENTRY_SERVICE_FLAPPING_STOPPED;
else if (strstr(temp_buffer, "SERVICE FLAPPING ALERT:") && strstr(temp_buffer, ";DISABLED;"))
type = LOGENTRY_SERVICE_FLAPPING_DISABLED;
else if (strstr(temp_buffer, "HOST FLAPPING ALERT:") && strstr(temp_buffer, ";STARTED;"))
type = LOGENTRY_HOST_FLAPPING_STARTED;
else if (strstr(temp_buffer, "HOST FLAPPING ALERT:") && strstr(temp_buffer, ";STOPPED;"))
type = LOGENTRY_HOST_FLAPPING_STOPPED;
else if (strstr(temp_buffer, "HOST FLAPPING ALERT:") && strstr(temp_buffer, ";DISABLED;"))
type = LOGENTRY_HOST_FLAPPING_DISABLED;
else if (strstr(temp_buffer, "SERVICE DOWNTIME ALERT:") && strstr(temp_buffer, ";STARTED;"))
type = LOGENTRY_SERVICE_DOWNTIME_STARTED;
else if (strstr(temp_buffer, "SERVICE DOWNTIME ALERT:") && strstr(temp_buffer, ";STOPPED;"))
type = LOGENTRY_SERVICE_DOWNTIME_STOPPED;
else if (strstr(temp_buffer, "SERVICE DOWNTIME ALERT:") && strstr(temp_buffer, ";CANCELLED;"))
type = LOGENTRY_SERVICE_DOWNTIME_CANCELLED;
else if (strstr(temp_buffer, "HOST DOWNTIME ALERT:") && strstr(temp_buffer, ";STARTED;"))
type = LOGENTRY_HOST_DOWNTIME_STARTED;
else if (strstr(temp_buffer, "HOST DOWNTIME ALERT:") && strstr(temp_buffer, ";STOPPED;"))
type = LOGENTRY_HOST_DOWNTIME_STOPPED;
else if (strstr(temp_buffer, "HOST DOWNTIME ALERT:") && strstr(temp_buffer, ";CANCELLED;"))
type = LOGENTRY_HOST_DOWNTIME_CANCELLED;
else if (strstr(temp_buffer, "INITIAL SERVICE STATE:"))
type = LOGENTRY_SERVICE_INITIAL_STATE;
else if (strstr(temp_buffer, "INITIAL HOST STATE:"))
type = LOGENTRY_HOST_INITIAL_STATE;
else if (strstr(temp_buffer, "CURRENT SERVICE STATE:"))
type = LOGENTRY_SERVICE_CURRENT_STATE;
else if (strstr(temp_buffer, "CURRENT HOST STATE:"))
type = LOGENTRY_HOST_CURRENT_STATE;
else if (strstr(temp_buffer, "error executing command"))
type = LOGENTRY_ERROR_COMMAND_EXECUTION;
else if (strstr(temp_buffer, "idomod:"))
type = LOGENTRY_IDOMOD;
else if (strstr(temp_buffer, "npcdmod:"))
type = LOGENTRY_NPCDMOD;
else if (strstr(temp_buffer, "Auto-save of"))
type = LOGENTRY_AUTOSAVE;
else if (strstr(temp_buffer, "Warning:"))
type = LOGENTRY_SYSTEM_WARNING;
else
type = LOGENTRY_UNDEFINED;
/* apply filters */
if (*filter_list != NULL) {
keep_entry = FALSE;
for (temp_filter = *filter_list; temp_filter != NULL; temp_filter = temp_filter->next) {
if (temp_filter->include != 0) {
if (temp_filter->include == type) {
keep_entry = TRUE;
break;
}
} else if (temp_filter->exclude != 0) {
if (temp_filter->exclude == type) {
keep_entry = FALSE;
break;
} else
keep_entry = TRUE;
}
}
if (keep_entry == FALSE)
continue;
}
/* initialzie */
/* allocate memory for a new log entry */
temp_entry = (logentry *)malloc(sizeof(logentry));
if (temp_entry == NULL) {
mmap_fclose(thefile);
return READLOG_ERROR_MEMORY;
}
temp_entry->timestamp = 0L;
temp_entry->type = 0;
temp_entry->entry_text = NULL;
temp_entry->next = NULL;
temp_entry->timestamp = timestamp;
temp_entry->type = type;
temp_entry->entry_text = strdup(temp_buffer);
if (reverse == TRUE) {
if (*entry_list == NULL) {
*entry_list = temp_entry;
last_entry = *entry_list;
} else {
last_entry->next = temp_entry;
last_entry = temp_entry;
}
} else {
temp_entry->next = *entry_list;
*entry_list = temp_entry;
}
}
mmap_fclose(thefile);
}
for (i=0; i< file_num;i++)
my_free(files[i].file_name);
if (search_string != NULL)
regfree(&preg);
return return_val;
}
/** @brief frees all memory allocated to list of log filters in memory
* @author Ricardo Bartels
**/
void free_log_filters(logfilter **filter_list) {
logfilter *temp_filter = NULL;
logfilter *next_filter = NULL;
for (temp_filter = *filter_list; temp_filter != NULL;) {
next_filter = temp_filter->next;
my_free(temp_filter);
temp_filter = next_filter;
}
*filter_list = NULL;
return;
}
/** @brief frees all memory allocated to list of log entries in memory
* @author Ricardo Bartels
**/
void free_log_entries(logentry **entry_list) {
logentry *temp_entry;
logentry *next_entry;
for (temp_entry = *entry_list; temp_entry != NULL;) {
next_entry = temp_entry->next;
if (temp_entry->entry_text != NULL)
my_free(temp_entry->entry_text);
my_free(temp_entry);
temp_entry = next_entry;
}
*entry_list = NULL;
return;
}
/** @brief returns amount of backtrack_seconds to substract from start_time_stamp
* @param [in] backtrack_archives number of backtrack_archives
* @return amount of backtrack_seconds
* @author Ricardo Bartels
*
* returns amount of backtrack_seconds to substract from start_time_stamp
* when reading logs, based on @log_rotation_method and @ backtrack_archives
**/
time_t get_backtrack_seconds(int backtrack_archives) {
if (log_rotation_method == LOG_ROTATION_MONTHLY)
return ( 60 * 60 * 24 * 31 * backtrack_archives);
else if (log_rotation_method == LOG_ROTATION_DAILY)
return ( 60 * 60 * 24 * backtrack_archives);
else if (log_rotation_method == LOG_ROTATION_HOURLY)
return ( 60 * 60 * backtrack_archives);
else // LOG_ROTATION_WEEKLY
return ( 60 * 60 * 24 * 7 * backtrack_archives);
}
icinga-1.10.3/cgi/showlog.c 0000664 0000000 0000000 00000110306 12276402000 0015410 0 ustar 00root root 0000000 0000000 /*****************************************************************************
*
* SHOWLOG.C - Icinga Log File CGI
*
* Copyright (c) 1999-2009 Ethan Galstad (egalstad@nagios.org)
* Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*****************************************************************************/
/** @file showlog.c
* @brief cgi to browse through Icinga log data
**/
#include "../include/config.h"
#include "../include/common.h"
#include "../include/objects.h"
#include "../include/getcgi.h"
#include "../include/cgiutils.h"
#include "../include/cgiauth.h"
#include "../include/readlogs.h"
/** @name External vars
@{ **/
extern char main_config_file[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH];
extern char *csv_delimiter;
extern char *csv_data_enclosure;
extern int enable_splunk_integration;
extern int showlog_initial_states;
extern int showlog_current_states;
extern int escape_html_tags;
extern int result_limit;
extern int embedded;
extern int display_header;
extern int daemon_check;
extern int content_type;
/** @} */
/** @name Internal vars
@{ **/
int display_frills = TRUE; /**< determine if icons should be shown in listing */
int display_timebreaks = TRUE; /**< determine if time breaks should be shown */
int reverse = FALSE; /**< determine if log should be viewed in reverse order */
int timeperiod_type = TIMEPERIOD_SINGLE_DAY; /**< determines the time period to view see cgiutils.h */
int num_displayed = -1; /**< holds amount of displayed log entries */
int result_start = 1; /**< keep track from where we have to start displaying results */
int get_result_limit = -1; /**< needed to overwrite config value with result_limit we get vie GET */
int display_filter = FALSE; /**< show filter */
int show_notifications = TRUE; /**< filter option */
int show_host_status = TRUE; /**< filter option */
int show_service_status = TRUE; /**< filter option */
int show_external_commands = TRUE; /**< filter option */
int show_system_messages = TRUE; /**< filter option */
int show_event_handler = TRUE; /**< filter option */
int show_flapping = TRUE; /**< filter option */
int show_downtime = TRUE; /**< filter option */
char *query_string = NULL; /**< the request query string */
char *start_time_string = ""; /**< the requested start time */
char *end_time_string = ""; /**< the requested end time */
time_t ts_start = 0L; /**< start time as unix timestamp */
time_t ts_end = 0L; /**< end time as unix timestamp */
authdata current_authdata; /**< struct to hold current authentication data */
int CGI_ID = SHOWLOG_CGI_ID; /**< ID to identify the cgi for functions in cgiutils.c */
/** @} */
/** @brief Parses the requested GET/POST variables
* @return wether parsing was successful or not
* @retval TRUE
* @retval FALSE
*
* @n This function parses the request and set's the necessary variables
**/
int process_cgivars(void);
/** @brief displays the requested log entries
*
* Applies the requested filters, reads in all necessary log files
* and afterwards showing each log entry.
**/
void display_logentries(void);
/** @brief displays the little filter list in the top right corner
*
* Just to show the filter in an own function. Get's called in \c main
**/
void show_filter(void);
/** @brief Yes we need a main function **/
int main(void) {
int result = OK;
/* get the CGI variables passed in the URL */
process_cgivars();
/* reset internal variables */
reset_cgi_vars();
/* read the CGI configuration file */
result = read_cgi_config_file(get_cgi_config_location());
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(get_cgi_config_location(), ERROR_CGI_CFG_FILE, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(main_config_file, ERROR_CGI_MAIN_CFG, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(NULL, ERROR_CGI_OBJECT_DATA, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* This requires the date_format parameter in the main config file */
if (timeperiod_type == TIMEPERIOD_CUSTOM) {
if (strcmp(start_time_string, ""))
string_to_time(start_time_string, &ts_start);
if (strcmp(end_time_string, ""))
string_to_time(end_time_string, &ts_end);
}
/* overwrite config value with amount we got via GET */
result_limit = (get_result_limit != -1) ? get_result_limit : result_limit;
/* for json and csv output return all by default */
if (get_result_limit == -1 && (content_type == JSON_CONTENT || content_type == CSV_CONTENT))
result_limit = 0;
document_header(CGI_ID, TRUE, "Log File");
/* calculate timestamps for reading logs */
convert_timeperiod_to_times(timeperiod_type, &ts_start, &ts_end);
/* get authentication information */
get_authentication_information(¤t_authdata);
if (display_header == TRUE) {
/* start input form */
printf("\n");
}
/* check to see if the user is authorized to view the log file */
if (is_authorized_for_system_information(¤t_authdata) == FALSE) {
print_generic_error_message("It appears as though you do not have permission to view the log file...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
} else {
/* display the contents of the log file */
display_logentries();
}
document_footer(CGI_ID);
/* free allocated memory */
free_memory();
return OK;
}
int process_cgivars(void) {
char **variables;
int error = FALSE;
int x;
variables = getcgivars();
for (x = 0; variables[x] != NULL; x++) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */
if (strlen(variables[x]) >= MAX_INPUT_BUFFER - 1)
continue;
/* found query string */
else if (!strcmp(variables[x], "query_string")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
query_string = strdup(variables[x]);
strip_html_brackets(query_string);
if (strlen(query_string) == 0)
my_free(query_string);
}
/* we found first time argument */
else if (!strcmp(variables[x], "ts_start")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
ts_start = (time_t)strtoul(variables[x], NULL, 10);
}
/* we found last time argument */
else if (!strcmp(variables[x], "ts_end")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
ts_end = (time_t)strtoul(variables[x], NULL, 10);
}
/* we found the start time */
else if (!strcmp(variables[x], "start_time")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
start_time_string = (char *)malloc(strlen(variables[x]) + 1);
if (start_time_string == NULL)
start_time_string = "";
else
strcpy(start_time_string, variables[x]);
}
/* we found the end time */
else if (!strcmp(variables[x], "end_time")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
end_time_string = (char *)malloc(strlen(variables[x]) + 1);
if (end_time_string == NULL)
end_time_string = "";
else
strcpy(end_time_string, variables[x]);
}
/* we found the standard timeperiod argument */
else if (!strcmp(variables[x], "timeperiod")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "today"))
timeperiod_type = TIMEPERIOD_TODAY;
else if (!strcmp(variables[x], "singelday"))
timeperiod_type = TIMEPERIOD_SINGLE_DAY;
else if (!strcmp(variables[x], "last24hours"))
timeperiod_type = TIMEPERIOD_LAST24HOURS;
else if (!strcmp(variables[x], "thisweek"))
timeperiod_type = TIMEPERIOD_THISWEEK;
else if (!strcmp(variables[x], "lastweek"))
timeperiod_type = TIMEPERIOD_LASTWEEK;
else if (!strcmp(variables[x], "thismonth"))
timeperiod_type = TIMEPERIOD_THISMONTH;
else if (!strcmp(variables[x], "lastmonth"))
timeperiod_type = TIMEPERIOD_LASTMONTH;
else if (!strcmp(variables[x], "thisyear"))
timeperiod_type = TIMEPERIOD_THISYEAR;
else if (!strcmp(variables[x], "lastyear"))
timeperiod_type = TIMEPERIOD_LASTYEAR;
else if (!strcmp(variables[x], "last7days"))
timeperiod_type = TIMEPERIOD_LAST7DAYS;
else if (!strcmp(variables[x], "last31days"))
timeperiod_type = TIMEPERIOD_LAST31DAYS;
else if (!strcmp(variables[x], "custom"))
timeperiod_type = TIMEPERIOD_CUSTOM;
else
continue;
convert_timeperiod_to_times(timeperiod_type, &ts_start, &ts_end);
}
/* we found the order argument */
else if (!strcmp(variables[x], "order")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "new2old"))
reverse = FALSE;
else if (!strcmp(variables[x], "old2new"))
reverse = TRUE;
}
/* show filter */
else if (!strcmp(variables[x], "display_filter")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "true"))
display_filter = TRUE;
}
/* notification filter */
else if (!strcmp(variables[x], "noti")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "off"))
show_notifications = FALSE;
}
/* host status filter */
else if (!strcmp(variables[x], "hst")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "off"))
show_host_status = FALSE;
}
/* service status filter */
else if (!strcmp(variables[x], "sst")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "off"))
show_service_status = FALSE;
}
/* external commands filter */
else if (!strcmp(variables[x], "cmd")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "off"))
show_external_commands = FALSE;
}
/* system messages filter */
else if (!strcmp(variables[x], "sms")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "off"))
show_system_messages = FALSE;
}
/* event handler filter */
else if (!strcmp(variables[x], "evh")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "off"))
show_event_handler = FALSE;
}
/* flapping filter */
else if (!strcmp(variables[x], "flp")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "off"))
show_flapping = FALSE;
}
/* downtime filter */
else if (!strcmp(variables[x], "dwn")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "off"))
show_downtime = FALSE;
}
/* we found the CSV output option */
else if (!strcmp(variables[x], "csvoutput")) {
display_header = FALSE;
content_type = CSV_CONTENT;
}
/* we found the CSV output option */
else if (!strcmp(variables[x], "jsonoutput")) {
display_header = FALSE;
content_type = JSON_CONTENT;
}
/* we found the embed option */
else if (!strcmp(variables[x], "embedded"))
embedded = TRUE;
/* we found the noheader option */
else if (!strcmp(variables[x], "noheader"))
display_header = FALSE;
/* we found the nofrills option */
else if (!strcmp(variables[x], "nofrills"))
display_frills = FALSE;
/* we found the notimebreaks option */
else if (!strcmp(variables[x], "notimebreaks"))
display_timebreaks = FALSE;
/* we found the nodaemoncheck option */
else if (!strcmp(variables[x], "nodaemoncheck"))
daemon_check = FALSE;
/* start num results to skip on displaying statusdata */
else if (!strcmp(variables[x], "start")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
result_start = atoi(variables[x]);
if (result_start < 1)
result_start = 1;
}
/* amount of results to display */
else if (!strcmp(variables[x], "limit")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
get_result_limit = atoi(variables[x]);
}
/* we received an invalid argument */
else
error = TRUE;
}
/* free memory allocated to the CGI variables */
free_cgivars(variables);
return error;
}
void display_logentries() {
char image[MAX_INPUT_BUFFER];
char image_alt[MAX_INPUT_BUFFER];
char last_message_date[MAX_INPUT_BUFFER] = "";
char current_message_date[MAX_INPUT_BUFFER] = "";
char date_time[MAX_DATETIME_LENGTH];
char *error_text = NULL;
int status = READLOG_OK;
int i = 0;
int user_has_seen_something = FALSE;
int json_start = TRUE;
int total_entries = 0;
int displayed_entries = 0;
struct tm *time_ptr = NULL;
logentry *entry_list = NULL;
logentry *temp_entry = NULL;
logfilter *filter_list = NULL;
/* Add default filters */
if (showlog_initial_states == FALSE) {
add_log_filter(&filter_list, LOGENTRY_SERVICE_INITIAL_STATE, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_INITIAL_STATE, LOGFILTER_EXCLUDE);
}
if (showlog_current_states == FALSE) {
add_log_filter(&filter_list, LOGENTRY_SERVICE_CURRENT_STATE, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_CURRENT_STATE, LOGFILTER_EXCLUDE);
}
/* Add requested filters */
if (show_notifications == FALSE) {
add_log_filter(&filter_list, LOGENTRY_HOST_NOTIFICATION, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_NOTIFICATION, LOGFILTER_EXCLUDE);
}
if (show_host_status == FALSE) {
add_log_filter(&filter_list, LOGENTRY_HOST_UP, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_DOWN, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_UNREACHABLE, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_RECOVERY, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_PASSIVE_HOST_CHECK, LOGFILTER_EXCLUDE);
}
if (show_service_status == FALSE) {
add_log_filter(&filter_list, LOGENTRY_SERVICE_OK, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_WARNING, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_CRITICAL, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_UNKNOWN, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_RECOVERY, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_PASSIVE_SERVICE_CHECK, LOGFILTER_EXCLUDE);
}
if (show_external_commands == FALSE)
add_log_filter(&filter_list, LOGENTRY_EXTERNAL_COMMAND, LOGFILTER_EXCLUDE);
if (show_system_messages == FALSE) {
add_log_filter(&filter_list, LOGENTRY_SYSTEM_WARNING, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_STARTUP, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_SHUTDOWN, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_BAILOUT, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_RESTART, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_LOG_ROTATION, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_AUTOSAVE, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_IDOMOD, LOGFILTER_EXCLUDE);
}
if (show_event_handler == FALSE) {
add_log_filter(&filter_list, LOGENTRY_SERVICE_EVENT_HANDLER, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_EVENT_HANDLER, LOGFILTER_EXCLUDE);
}
if (show_flapping == FALSE) {
add_log_filter(&filter_list, LOGENTRY_SERVICE_FLAPPING_STARTED, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_FLAPPING_STOPPED, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_FLAPPING_DISABLED, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_FLAPPING_STARTED, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_FLAPPING_STOPPED, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_FLAPPING_DISABLED, LOGFILTER_EXCLUDE);
}
if (show_downtime == FALSE) {
add_log_filter(&filter_list, LOGENTRY_SERVICE_DOWNTIME_STARTED, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_DOWNTIME_STOPPED, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_DOWNTIME_CANCELLED, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_DOWNTIME_STARTED, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_DOWNTIME_STOPPED, LOGFILTER_EXCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_DOWNTIME_CANCELLED, LOGFILTER_EXCLUDE);
}
/* scan the log file for archived state data */
status = get_log_entries(&entry_list, &filter_list, &error_text, query_string, reverse, ts_start, ts_end);
free_log_filters(&filter_list);
/* dealing with errors */
if (status == READLOG_ERROR_WARNING) {
if (error_text != NULL) {
print_generic_error_message(error_text, NULL, 0);
my_free(error_text);
} else
print_generic_error_message("Unkown error!", NULL, 0);
}
if (status == READLOG_ERROR_MEMORY)
print_generic_error_message("Out of memory...", "showing all I could get!", 0);
if (status == READLOG_ERROR_FATAL) {
if (error_text != NULL) {
print_generic_error_message(error_text, NULL, 0);
my_free(error_text);
}
user_has_seen_something = TRUE;
/* now we start displaying the log entries */
} else {
if (content_type == JSON_CONTENT) {
display_timebreaks = FALSE;
if (status != READLOG_OK)
printf(",\n");
printf("\"log_entries\": [\n");
} else if (content_type == CSV_CONTENT) {
display_timebreaks = FALSE;
printf("%sTimestamp%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sDate Time%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sLog Entry%s\n", csv_data_enclosure, csv_data_enclosure);
} else {
/* add export to csv, json, link */
printf("
");
return;
}
void show_filter(void) {
char buffer[MAX_INPUT_BUFFER];
int temp_htmlencode = escape_html_tags;
// escape all characters, otherwise they won't show up in search box
escape_html_tags = TRUE;
printf("
\n");
escape_html_tags = temp_htmlencode;
return;
}
icinga-1.10.3/cgi/status.c 0000664 0000000 0000000 00001170336 12276402000 0015263 0 ustar 00root root 0000000 0000000 /**************************************************************************
*
* STATUS.C - Icinga Status CGI
*
* Copyright (c) 1999-2010 Ethan Galstad (egalstad@nagios.org)
* Copyright (c) 2012 Nagios Core Development Team and Community Contributors
* Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
*
* Last Modified: 08-08-2010
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*************************************************************************/
/** @file status.c
* @brief display host and service status data in list format. Also host and service groups
**/
#include "../include/config.h"
#include "../include/common.h"
#include "../include/objects.h"
#include "../include/comments.h"
#include "../include/macros.h"
#include "../include/statusdata.h"
#include "../include/cgiutils.h"
#include "../include/getcgi.h"
#include "../include/cgiauth.h"
/** @name initializing macros
@{ **/
static icinga_macros *mac;
/** @} */
/** @name external vars
@{ **/
extern time_t program_start;
extern char main_config_file[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH];
extern char url_logo_images_path[MAX_FILENAME_LENGTH];
extern char url_media_path[MAX_FILENAME_LENGTH];
extern char *service_critical_sound;
extern char *service_warning_sound;
extern char *service_unknown_sound;
extern char *host_down_sound;
extern char *host_unreachable_sound;
extern char *normal_sound;
extern char *notes_url_target;
extern char *action_url_target;
extern char *csv_delimiter;
extern char *csv_data_enclosure;
extern int enable_splunk_integration;
extern int status_show_long_plugin_output;
extern int suppress_maintenance_downtime;
extern int highlight_table_rows;
extern int tab_friendly_titles;
extern int refresh;
extern int result_limit;
extern int embedded;
extern int display_header;
extern int display_status_totals;
extern int daemon_check;
extern int content_type;
extern int escape_html_tags;
extern int show_partial_hostgroups; /**< show any hosts in hostgroups the user is authorized for */
extern int show_partial_servicegroups;
extern int add_notif_num_hard;
extern int add_notif_num_soft;
extern host *host_list;
extern service *service_list;
extern hostgroup *hostgroup_list;
extern servicegroup *servicegroup_list;
extern hoststatus *hoststatus_list;
extern servicestatus *servicestatus_list;
/** @} */
/** @name DISPLAY TYPES
@{**/
#define DISPLAY_HOSTS 0 /**< use the standard view */
#define DISPLAY_HOSTGROUPS 1 /**< output is filtered by hostgroup(s) */
#define DISPLAY_SERVICEGROUPS 2 /**< output is filtered by servicegroup(s) */
/** @} */
/** @name STYLES
@{**/
#define STYLE_OVERVIEW 0 /**< host/service group status overview (no status list) */
#define STYLE_SERVICE_DETAIL 1 /**< display service status list */
#define STYLE_SUMMARY 2 /**< host/service group status summary (no status list) */
#define STYLE_GRID 3 /**< host/service group status grid (no status list) */
#define STYLE_HOST_DETAIL 4 /**< display host status list */
#define STYLE_HOST_SERVICE_DETAIL 5 /**< display combined hast and service status list */
/** @} */
/** @name STATUS TYPES
* used in statusdata_struct and to determine which dropdown menu to display
@{**/
#define HOST_STATUS 0
#define SERVICE_STATUS 1
#define NO_STATUS 2
/** @} */
/** @name STATUS ADDED / COUNTED
* used in statusdata to see if this antry has been added to statusdata_struct or counted for status totals
@{**/
#define STATUS_NOT_DISPLAYED 0
#define STATUS_ADDED 1
#define STATUS_COUNTED_UNFILTERED 2
#define STATUS_COUNTED_FILTERED 4
#define STATUS_BELONGS_TO_SG 8
#define STATUS_BELONGS_TO_HG 16
/** @} */
/** @name NUMBER OF NAMED OBJECTS
@{**/
#define NUM_NAMED_ENTRIES 1000 /**< max number of elements (hosts/hostgroups/servicegroups) submitted vie GET/POST */
/** @} */
/** @brief status data struct
*
* structure to hold host AND service status data
**/
typedef struct statusdata_struct {
int type; /**< HOST_STATUS / SERVICE_STATUS */
char *host_name; /**< holds host name */
char *svc_description; /**< holds service description */
int status; /**< the actual status OK / UP / CRITICAL / DOWN ... */
char *status_string; /**< the status as strting depending if host or service status */
char *last_check; /**< last time status is checked as string */
time_t ts_last_check; /**< last time status is checked as timestamp */
char *state_duration; /**< duration of this status as string */
time_t ts_state_duration; /**< duration of this status as timestamp */
char *attempts; /**< attempts as string */
int current_attempt; /**< attempts as integer */
char *plugin_output; /**< full processed plugin output */
int problem_has_been_acknowledged; /**< bool if problem is acknowledged */
int scheduled_downtime_depth; /**< int of downtime depth */
int notifications_enabled; /**< bool if notifications are enabled */
int checks_enabled; /**< bool if active checks are enabled */
int accept_passive_checks; /**< bool if passive checks are enabled */
int is_flapping; /**< bool if status is flapping */
int state_type; /**< type of state HARD_STATE / SOFT_STATE */
struct statusdata_struct *next; /**< next statusdata */
} statusdata;
statusdata *statusdata_list = NULL; /**< list of all status data elements */
statusdata *last_statusdata = NULL; /**< last element of status data list (needed to add new elments) */
/** @brief status sort structure
*
* holds pointers to status data in a sorted order
**/
typedef struct sort_struct {
statusdata *status; /**< pointer to status data element */
struct sort_struct *next; /**< next sort entry */
} sort;
sort *statussort_list = NULL; /**< list of all sorted elements */
/** @brief named list structure
*
* holds an char entry. useful for host/service groups
**/
struct namedlist {
char *entry;
};
/** @name Internal vars
@{ **/
int num_req_hosts = 0; /**< number of requestes hosts GET/POST */
int num_req_hostgroups = 0; /**< number of requestes hostgroups GET/POST */
int num_req_servicegroups = 0; /**< number of requestes servicegroups GET/POST */
int show_all_hosts = TRUE; /**< define if ALL hosts should be displayed */
int show_all_hostgroups = TRUE; /**< define if ALL hostgroups should be displayed */
int show_all_servicegroups = TRUE; /**< define if ALL servicegroups should be displayed */
int display_type = DISPLAY_HOSTS; /**< set default @c "DISPLAY TYPES" */
int overview_columns = 3; /**< set default num of columns in OVERVIEW */
int max_grid_width = 8; /**< set default grid width for OVERVIEW */
int group_style_type = STYLE_SERVICE_DETAIL; /**< set default @c "STYLES" type */
int navbar_search = FALSE; /**< set if user used search via menu (legacy) */
int user_is_authorized_for_statusdata = FALSE; /**< used to see if we return a no autorised or no data error message if no data is found after filtering */
int nostatusheader_option = FALSE; /**< define of status header should be displayed or not */
int display_all_unhandled_problems = FALSE; /**< special view of all unhandled problems */
int display_all_problems = FALSE; /**< special view of all problems */
int result_start = 1; /**< keep track from where we have to start displaying results */
int get_result_limit = -1; /**< needed to overwrite config value with result_limit we get vie GET */
int displayed_host_entries = 0; /**< number of displayed host entries */
int displayed_service_entries = 0; /**< number of displayed service entries */
int total_host_entries = 0; /**< number of all host entries found */
int total_service_entries = 0; /**< number of all service entries found */
int return_live_search_data = FALSE; /**< return data for live search in menu */
/** bitmask of all service status types which are used to filter services, changed via GET/POST */
int service_status_types = SERVICE_PENDING | SERVICE_OK | SERVICE_UNKNOWN | SERVICE_WARNING | SERVICE_CRITICAL;
/** bitmask of all service status types to compare with filter (won't get changed) */
int all_service_status_types = SERVICE_PENDING | SERVICE_OK | SERVICE_UNKNOWN | SERVICE_WARNING | SERVICE_CRITICAL;
/** bitmask of all host status types which are used to filter hosts, changed via GET/POST */
int host_status_types = HOST_PENDING | HOST_UP | HOST_DOWN | HOST_UNREACHABLE;
/** bitmask of all host status types to compare with filter (won't get changed) */
int all_host_status_types = HOST_PENDING | HOST_UP | HOST_DOWN | HOST_UNREACHABLE;
/** bitmask of all problem service status types to compare with filter */
int all_service_problems = SERVICE_UNKNOWN | SERVICE_WARNING | SERVICE_CRITICAL;
/** bitmask of all problem host status types to compare with filter */
int all_host_problems = HOST_DOWN | HOST_UNREACHABLE;
/** bitmask of all unhandled problem host status types to compare with filter */
int host_problems_unhandled = HOST_NO_SCHEDULED_DOWNTIME | HOST_NOT_ALL_CHECKS_DISABLED | HOST_STATE_UNACKNOWLEDGED;
/** bitmask of all unhandled problem service status types to compare with filter */
int service_problems_unhandled = SERVICE_NO_SCHEDULED_DOWNTIME | SERVICE_NOT_ALL_CHECKS_DISABLED | SERVICE_STATE_UNACKNOWLEDGED;
unsigned long host_properties = 0L; /**< bitmask of host property filter */
unsigned long service_properties = 0L; /**< bitmask of service property filter */
int sort_type = SORT_NONE; /**< defines sort order */
int sort_option = SORT_HOSTNAME; /**< defines after which column is sorted */
int sort_object = SERVICE_STATUS; /**< defines if service or hoststatus is sorted */
int hosts_need_to_be_sorted_again = FALSE; /**< if we have hosts with no services and no sort option is given, then we need to sort the hosts alphabetically again */
/** @name status data counters vars
@{ **/
int problem_hosts_down = 0; /**< num of hosts down which are not already handled to determine if sound shoud be played */
int problem_hosts_unreachable = 0; /**< num of hosts unreachable which are not already handled to determine if sound shoud be played */
int problem_services_critical = 0; /**< num of services critical which are not already handled to determine if sound shoud be played */
int problem_services_warning = 0; /**< num of services warning which are not already handled to determine if sound shoud be played */
int problem_services_unknown = 0; /**< num of services unknown which are not already handled to determine if sound shoud be played */
int num_hosts_up = 0; /**< num of hosts up (for @ref show_host_status_totals) */
int num_hosts_down = 0; /**< num of hosts down (for @ref show_host_status_totals) */
int num_hosts_unreachable = 0; /**< num of hosts unreachable (for @ref show_host_status_totals) */
int num_hosts_pending = 0; /**< num of hosts pending (for @ref show_host_status_totals) */
int num_total_hosts_up = 0; /**< num of total hosts up (for @ref show_host_status_totals) */
int num_total_hosts_down = 0; /**< num of total hosts down (for @ref show_host_status_totals) */
int num_total_hosts_unreachable = 0; /**< num of total hosts unreachable (for @ref show_host_status_totals) */
int num_total_hosts_pending = 0; /**< num of total hosts pending (for @ref show_host_status_totals) */
int num_services_ok = 0; /**< num of services ok (for @ref show_host_status_totals) */
int num_services_warning = 0; /**< num of services warning (for @ref show_host_status_totals) */
int num_services_critical = 0; /**< num of services critical (for @ref show_host_status_totals) */
int num_services_unknown = 0; /**< num of services unknown (for @ref show_host_status_totals) */
int num_services_pending = 0; /**< num of services pending (for @ref show_host_status_totals) */
int num_total_services_ok = 0; /**< num of total services ok (for @ref show_host_status_totals) */
int num_total_services_warning = 0; /**< num of total services warning (for @ref show_host_status_totals) */
int num_total_services_critical = 0; /**< num of total services critical (for @ref show_host_status_totals) */
int num_total_services_unknown = 0; /**< num of total services unknown (for @ref show_host_status_totals) */
int num_total_services_pending = 0; /**< num of total services pending (for @ref show_host_status_totals) */
/** @} */
int CGI_ID = STATUS_CGI_ID; /**< ID to identify the cgi for functions in cgiutils.c */
char *url_hosts_part = NULL; /**< url containing all requested hosts (host=localhost&host=host1&host=...) */
char *url_hostgroups_part = NULL; /**< url containing all requested hostgroups */
char *url_servicegroups_part = NULL; /**< url containing all requested servicegroups */
char *search_string = NULL; /**< contains search string if user searched something */
char *service_filter = NULL; /**< contains service filter if user wants to filter service status list by a certain service */
time_t current_time; /**< current timestamp (calculated once in main) */
authdata current_authdata; /**< struct to hold current authentication data */
struct namedlist req_hosts[NUM_NAMED_ENTRIES]; /**< initialze list of requested hosts */
struct namedlist req_hostgroups[NUM_NAMED_ENTRIES]; /**< initialze list of requested hostgroups */
struct namedlist req_servicegroups[NUM_NAMED_ENTRIES]; /**< initialze list of requested servicegroups */
/** @} */
/** @name handling status data
@{ **/
/** @brief adds status data to internal status data struct
* @param [in] status_type type of statusdata in 2. argument
* @arg HOST_STATUS
* @arg SERVICE_STATUS
* @param [in] data hoststatus/servicestatus datastruct pointer
* @retval OK
* @retval ERROR
* @return wether adding of status data was successfull or not
*
* @n This function parses host/servicedata and uses one data structure for both types.
* Data get's added to @ref statusdata_list . It also fills the global status data counters.
**/
int add_status_data(int , void *);
/** @brief frees all memory allocated to @ref statusdata_list entries in memory **/
void free_local_status_data(void);
/** @brief sorts status data by type and option
* @param [in] status_type type of statusdata in 2. argument
* @arg HOST_STATUS
* @arg SERVICE_STATUS
* @param [in] sort_type defines sort direction
* @arg SORT_ASCENDING
* @arg SORT_DESCENDING
* @param [in] sort_option the field data is sorted after, see SORT OPTIONS in cgiutils.h
*
* @retval OK
* @retval ERROR
* @return wether adding of status data was successfull or not
*
* @n It fills @ref statussort_list with pointers of @ref statusdata_list elements in desired order.
**/
int sort_status_data(int, int, int);
/** @brief compares two status data elements by type and option
* @param [in] status_type type of statusdata
* @arg HOST_STATUS
* @arg SERVICE_STATUS
* @param [in] sort_type defines sort direction
* @arg SORT_ASCENDING
* @arg SORT_DESCENDING
* @param [in] sort_option the field data is sorted after, see SORT OPTIONS in cgiutils.h
* @param [in] new_sort first status of two to comapre
* @param [in] temp_sort second status of two to comapre
*
* @retval TRUE
* @retval FALSE
* @return wether adding of status data was successfull or not
*
* @n Is only used by @ref sort_status_data . Compares first satatus with second one
* and retruns TRUE or FALSE depending on sort_type and sort_option
**/
int compare_sort_entries(int, int, int, sort *, sort *);
/** @brief frees all memory allocated to @ref statussort_list entries in memory **/
void free_sort_list(void);
/** @brief check if submited host property filters matches hoststatus
* @param [in] temp_hoststatus to check current filter settings against
* @retval TRUE
* @retval FALSE
* @return wether filter was passed or not
**/
int passes_host_properties_filter(hoststatus *);
/** @brief check if submited service property filters matches servicestatus
* @param [in] temp_servicestatus to check current filter settings against
* @retval TRUE
* @retval FALSE
* @return wether filter was passed or not
**/
int passes_service_properties_filter(servicestatus *);
/** @} */
/** @name status counter tables
@{ **/
/** @brief shows table with status counters for hosts **/
void show_host_status_totals(void);
/** @brief shows table with status counters for services **/
void show_service_status_totals(void);
/** @} */
/** @name functions to display the actual status data
@{ **/
/** @brief Display a detailed listing of all services states
*
* This is the service status list which is the default view.
* A list of services and their state.
**/
void show_service_detail(void);
/** @brief Display a detailed listing of all hosts states
*
* This is the host status list. A list of hosts and their state.
**/
void show_host_detail(void);
/** @brief Display's a overview of some/all servicegroups
*
* Iterates through all/selected servicegroups and calls @ref show_servicegroup_overview to display them.
**/
void show_servicegroup_overviews(void);
/** @brief Display's a overview entry of a specific servicegroup
* @param [in] temp_servicegroup element to display
* @retval TRUE
* @retval FALSE
* @return wether something got displayed or not
*
* Checks if servicegroup members pass all filters and calls @ref show_servicegroup_hostgroup_member_overview to display every member.
**/
int show_servicegroup_overview(servicegroup *);
/** @brief Display's a summary of some/all servicegroups
*
* Iterates through all/selected servicegroups and calls @ref show_servicegroup_summary to display them.
**/
void show_servicegroup_summaries(void);
/** @brief Displays status summary information for a specific servicegroup
* @param [in] temp_servicegroup element to display
* @param [in] odd can be 1 or 0 to determine which row colour to use
*
* Prints some html code and calls @ref show_servicegroup_host_totals_summary and @ref show_servicegroup_service_totals_summary to display every member.
**/
void show_servicegroup_summary(servicegroup *, int);
/** @brief Displays host total summary information for a specific servicegroup
* @param [in] temp_servicegroup element to display
*
* Prints a colour coded numbered list of hosts belonging to this servicegroup in different states
**/
void show_servicegroup_host_totals_summary(servicegroup *);
/** @brief Displays service total summary information for a specific servicegroup
* @param [in] temp_servicegroup element to display
*
* Prints a colour coded numbered list of services belonging to this servicegroup in different states
**/
void show_servicegroup_service_totals_summary(servicegroup *);
/** @brief Display's a grid of some/all servicegroups
*
* Iterates through all/selected servicegroups and calls @ref show_servicegroup_grid to display them.
**/
void show_servicegroup_grids(void);
/** @brief Display's a overview entry of a specific servicegroup
* @param [in] temp_servicegroup element to display
* @retval TRUE
* @retval FALSE
* @return wether something got displayed or not
*
* Checks if servicegroup members pass all filters and displays an entry of every member for host and servicestatus.
**/
int show_servicegroup_grid(servicegroup *);
/** @brief Display's a overview of some/all hostgroups
*
* Iterates through all/selected hostgroups and calls @ref show_hostgroup_overview to display them.
**/
void show_hostgroup_overviews(void);
/** @brief Display's a overview entry of a specific hostgroup
* @param [in] hstgrp hostgroup element to display
* @retval TRUE
* @retval FALSE
* @return wether something got displayed or not
*
* Checks if hostgroups members pass all filters and calls @ref show_servicegroup_hostgroup_member_overview to display every member.
**/
int show_hostgroup_overview(hostgroup *);
/** @brief Display's a summary of some/all hostgroups
*
* Iterates through all/selected hostgroups and calls @ref show_hostgroup_summary to display them.
**/
void show_hostgroup_summaries(void);
/** @brief Displays status summary information for a specific hostgroup
* @param [in] temp_hostgroup element to display
* @param [in] odd can be 1 or 0 to determine which row colour to use
*
* Prints some html code and calls @ref show_hostgroup_host_totals_summary and @ref show_hostgroup_service_totals_summary to display every member.
**/
void show_hostgroup_summary(hostgroup *, int);
/** @brief Displays host total summary information for a specific hostgroup
* @param [in] temp_hostgroup element to display
*
* Prints a colour coded numbered list of hosts belonging to this hostgroup in different states
**/
void show_hostgroup_host_totals_summary(hostgroup *);
/** @brief Displays service total summary information for a specific hostgroup
* @param [in] temp_hostgroup element to display
*
* Prints a colour coded numbered list of services belonging to this hostgroup in different states
**/
void show_hostgroup_service_totals_summary(hostgroup *);
/** @brief Display's a grid of some/all hostgroups
*
* Iterates through all/selected hostgroups and calls @ref show_hostgroup_grid to display them.
**/
void show_hostgroup_grids(void);
/** @brief Display's a grid entry of a specific hostgroup
* @param [in] temp_hostgroup element to display
* @retval TRUE
* @retval FALSE
* @return wether something got displayed or not
*
* Checks if hostgroup members pass all filters and displays an entry of every member for host and servicestatus.
**/
int show_hostgroup_grid(hostgroup *);
/** @brief Display's a single overview entry of a single host
* @param [in] hststatus element to display
* @param [in] odd can be 1 or 0 to determione which row colour to user
* @param [in] data is a servicegroup element which gets passed on to @ref show_servicegroup_hostgroup_member_service_status_totals (only needed when displaying servicegroups)
*
* Prints one line depending on host status and also calls @ref show_servicegroup_hostgroup_member_service_status_totals to print the states of the services for this host.
**/
void show_servicegroup_hostgroup_member_overview(hoststatus *, int, void *);
/** @brief Display's service status totals for host/service group overview
* @param [in] host_name of host whom services should be displayed
* @param [in] data is a servicegroup element (only needed when displaying servicegroups)
*
* Prints services part of @ show_servicegroup_hostgroup_member_overview
**/
void show_servicegroup_hostgroup_member_service_status_totals(char *, void *);
/** @} */
/** @brief return a list of hosts/services/hostgroups/servicegroups for live search **/
void show_live_search_data(void);
/** @name command drop down menus
@{ **/
/** @brief Generates the drop down menu for service commands in service status list **/
void show_servicecommand_table(void);
/** @brief Generates the drop down menu for host commands in host status list **/
void show_hostcommand_table(void);
/** @} */
/** @brief Displays the filter box if host or service status filters are set **/
void show_filters(void);
/** @brief Parses the requested GET/POST variables
* @retval TRUE
* @retval FALSE
* @return wether parsing was successful or not
*
* @n This function parses the request and set's the necessary variables
**/
int process_cgivars(void);
/** @brief print's the table header for differnt styles
* @param [in] style id of style type
*
* This function print's the table header depending on style type
**/
void print_displayed_names(int);
/** @brief Display's the page number selector
* @param [in] local_result_start the result start for the current displayed list
* @param [in] url base url to link to
* @param [in] url_add additional url options
* @param [in] status_type can be @ref HOST_STATUS or @ref SERVICE_STATUS to determine if function is called from host or service list
*
* Display's the page number selector and gernerates all links to select next/previouse page. Also copy's selector to top of the page
**/
void status_page_num_selector(int local_result_start, int status_type);
/** @brief Yes we need a main function **/
int main(void) {
int result = OK;
char *sound = NULL;
char *search_regex = NULL;
char *group_url = NULL;
char *cgi_title = NULL;
char host_service_name[MAX_INPUT_BUFFER];
char temp_buffer[MAX_INPUT_BUFFER];
host *temp_host = NULL;
service *temp_service = NULL;
hostgroup *temp_hostgroup = NULL;
servicegroup *temp_servicegroup = NULL;
hoststatus *temp_hoststatus = NULL;
servicestatus *temp_servicestatus = NULL;
servicesmember *temp_sg_member = NULL;
hostsmember *temp_hg_member = NULL;
int regex_i = 0, i = 0;
int len;
int show_dropdown = NO_STATUS;
int found = FALSE;
int show_all = TRUE;
int host_items_found = FALSE;
int service_items_found = FALSE;
regex_t preg;
/**
* gather data
**/
/* get the arguments passed in the URL */
process_cgivars();
/* reset internal variables */
reset_cgi_vars();
/* read the CGI configuration file */
result = read_cgi_config_file(get_cgi_config_location());
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(get_cgi_config_location(), ERROR_CGI_CFG_FILE, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(main_config_file, ERROR_CGI_MAIN_CFG, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(NULL, ERROR_CGI_OBJECT_DATA, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* read all status data */
result = read_all_status_data(main_config_file, READ_ALL_STATUS_DATA);
if (result == ERROR && daemon_check == TRUE) {
document_header(CGI_ID, FALSE, "Error");
print_error(NULL, ERROR_CGI_STATUS_DATA, FALSE);
document_footer(CGI_ID);
free_memory();
return ERROR;
}
/**
* Initialize some vars
**/
mac = get_global_macros();
time(¤t_time);
/* initialize macros */
init_macros();
/* get authentication information */
get_authentication_information(¤t_authdata);
/* overwrite config value with amount we got via GET */
result_limit = (get_result_limit != -1) ? get_result_limit : result_limit;
/* for json and csv output return all by default */
if (get_result_limit == -1 && (content_type == JSON_CONTENT || content_type == CSV_CONTENT))
result_limit = 0;
/* keeps backwards compatibility with old search method */
if (navbar_search == TRUE && search_string == NULL && req_hosts[0].entry != NULL) {
group_style_type = STYLE_HOST_SERVICE_DETAIL;
search_string = strdup(req_hosts[0].entry);
}
/* keep backwards compatibility with nostatusheader option */
if (nostatusheader_option == TRUE)
display_status_totals = FALSE;
/* allow service_filter only for status lists */
if (group_style_type == STYLE_SUMMARY || group_style_type == STYLE_GRID || group_style_type == STYLE_OVERVIEW)
my_free(service_filter);
/**
* filter status data if user searched for something
**/
/* see if user tried searching something */
if (search_string != NULL) {
/* build regex string */
/* allocate for 3 extra chars, ^, $ and \0 */
search_regex = malloc(sizeof(char) * (strlen(search_string) * 2 + 3));
len = strlen(search_string);
for (i = 0; i < len; i++, regex_i++) {
if (search_string[i] == '*') {
search_regex[regex_i++] = '.';
search_regex[regex_i] = '*';
} else
search_regex[regex_i] = search_string[i];
}
search_regex[regex_i] = '\0';
/* check and compile regex */
if (regcomp(&preg, search_regex, REG_ICASE | REG_NOSUB) == 0) {
/* regular expression is valid */
/* now look through all hosts to see which one matches */
for (temp_hoststatus = hoststatus_list; temp_hoststatus != NULL; temp_hoststatus = temp_hoststatus->next) {
temp_hoststatus->search_matched = FALSE;
if ((temp_host = find_host(temp_hoststatus->host_name)) == NULL)
continue;
/* try to find a match */
if (regexec(&preg, temp_host->name, 0, NULL, 0) == 0 || \
regexec(&preg, temp_host->display_name, 0, NULL, 0) == 0 || \
regexec(&preg, temp_host->alias, 0, NULL, 0) == 0 || \
regexec(&preg, temp_host->address, 0, NULL, 0) == 0 || \
regexec(&preg, temp_host->address6, 0, NULL, 0) == 0) {
temp_hoststatus->search_matched = TRUE;
host_items_found = TRUE;
}
}
for (temp_servicestatus = servicestatus_list; temp_servicestatus != NULL; temp_servicestatus = temp_servicestatus->next) {
temp_servicestatus->search_matched = FALSE;
/* find the service */
if ((temp_service = find_service(temp_servicestatus->host_name, temp_servicestatus->description)) == NULL)
continue;
/* try to find a match */
if (regexec(&preg, temp_service->description, 0, NULL, 0) == 0 || \
regexec(&preg, temp_service->display_name, 0, NULL, 0) == 0 || \
regexec(&preg, temp_service->host_name, 0, NULL, 0) == 0) {
temp_servicestatus->search_matched = TRUE;
service_items_found = TRUE;
}
/* try to match on combination of */
/* host_name + service_description */
snprintf(host_service_name, sizeof(host_service_name), "%s %s", temp_service->host_name, temp_service->description);
host_service_name[sizeof(host_service_name) - 1] = '\x0';
if (temp_servicestatus->search_matched == FALSE && regexec(&preg, host_service_name, 0, NULL, 0) == 0) {
temp_servicestatus->search_matched = TRUE;
service_items_found = TRUE;
}
/* try to match on combination of */
/* host_name + service_display_name */
snprintf(host_service_name, sizeof(host_service_name), "%s %s", temp_service->host_name, temp_service->display_name);
host_service_name[sizeof(host_service_name) - 1] = '\x0';
if (temp_servicestatus->search_matched == FALSE && regexec(&preg, host_service_name, 0, NULL, 0) == 0) {
temp_servicestatus->search_matched = TRUE;
service_items_found = TRUE;
}
if (temp_servicestatus->search_matched == FALSE) {
if ((temp_host = find_host(temp_service->host_name)) == NULL)
continue;
/* try to match on combination of */
/* host_display_name + service_description */
snprintf(host_service_name, sizeof(host_service_name), "%s %s", temp_host->display_name, temp_service->description);
host_service_name[sizeof(host_service_name) - 1] = '\x0';
if (regexec(&preg, host_service_name, 0, NULL, 0) == 0) {
temp_servicestatus->search_matched = TRUE;
service_items_found = TRUE;
}
/* try to match on combination of */
/* host_display_name + service_display_name */
snprintf(host_service_name, sizeof(host_service_name), "%s %s", temp_host->display_name, temp_service->display_name);
host_service_name[sizeof(host_service_name) - 1] = '\x0';
if (temp_servicestatus->search_matched == FALSE && regexec(&preg, host_service_name, 0, NULL, 0) == 0) {
temp_servicestatus->search_matched = TRUE;
service_items_found = TRUE;
}
}
}
/* if we didn't found anything until now we start looking for hostgroups and servicegroups */
/* or if user used live search*/
if (return_live_search_data == TRUE || (host_items_found == FALSE && service_items_found == FALSE)) {
/* try to find hostgroup */
found = FALSE;
for (temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {
if (regexec(&preg, temp_hostgroup->group_name, 0, NULL, 0) == 0 || regexec(&preg, temp_hostgroup->alias, 0, NULL, 0) == 0) {
/* simply add to requested hostgroups if user usese live search */
req_hostgroups[num_req_hostgroups++].entry = strdup(temp_hostgroup->group_name);
show_all_hostgroups = FALSE;
if (return_live_search_data == FALSE) {
display_type = DISPLAY_HOSTGROUPS;
found = TRUE;
}
}
}
/* if no hostgroup matched, try to find a servicegroup */
if (return_live_search_data == TRUE || found == FALSE) {
for (temp_servicegroup = servicegroup_list; temp_servicegroup != NULL; temp_servicegroup = temp_servicegroup->next) {
if (regexec(&preg, temp_servicegroup->group_name, 0, NULL, 0) == 0 || regexec(&preg, temp_servicegroup->alias, 0, NULL, 0) == 0) {
req_servicegroups[num_req_servicegroups++].entry = strdup(temp_servicegroup->group_name);
show_all_servicegroups = FALSE;
if (return_live_search_data == FALSE) {
display_type = DISPLAY_SERVICEGROUPS;
}
}
}
}
}
}
/* free regular expression */
regfree(&preg);
my_free(search_regex);
user_is_authorized_for_statusdata = TRUE;
/* check the search result and trigger the desired view */
if (host_items_found == TRUE && service_items_found == FALSE && group_style_type == STYLE_HOST_SERVICE_DETAIL)
group_style_type = STYLE_HOST_DETAIL;
else if (host_items_found == FALSE && service_items_found == TRUE && group_style_type == STYLE_HOST_SERVICE_DETAIL)
group_style_type = STYLE_SERVICE_DETAIL;
}
/**
* check submitted data, create url_parts and create cgi_title
**/
/* determine display of hosts */
if (req_hosts[0].entry != NULL) {
show_all_hosts = FALSE;
for (i = 0; req_hosts[i].entry != NULL; i++) {
if (!strcmp(req_hosts[i].entry, "all")) {
show_all_hosts = TRUE;
my_free(url_hosts_part);
my_free(cgi_title);
req_hosts[0].entry = strdup("all");
req_hosts[1].entry = NULL;
asprintf(&url_hosts_part, "host=all");
break;
} else {
if (i != 0) {
strncpy(temp_buffer, cgi_title, sizeof(temp_buffer));
my_free(cgi_title);
}
asprintf(&cgi_title, "%s%s[%s]", (i != 0) ? temp_buffer : "", (i != 0) ? ", " : "", html_encode(req_hosts[i].entry, FALSE));
if (i == 0)
asprintf(&url_hosts_part, "host=%s", url_encode(req_hosts[i].entry));
else {
strncpy(temp_buffer, url_hosts_part, sizeof(temp_buffer));
my_free(url_hosts_part);
asprintf(&url_hosts_part, "%s&host=%s", temp_buffer, url_encode(req_hosts[i].entry));
}
}
}
} else {
req_hosts[0].entry = strdup("all");
req_hosts[1].entry = NULL;
asprintf(&url_hosts_part, "host=all");
}
/* determine display of hostgroups */
if (req_hostgroups[0].entry != NULL) {
show_all_hostgroups = FALSE;
for (i = 0; req_hostgroups[i].entry != NULL; i++) {
if (!strcmp(req_hostgroups[i].entry, "all")) {
show_all_hostgroups = TRUE;
my_free(url_hostgroups_part);
my_free(cgi_title);
req_hostgroups[0].entry = strdup("all");
req_hostgroups[1].entry = NULL;
asprintf(&url_hostgroups_part, "hostgroup=all");
break;
} else {
if (i != 0) {
strncpy(temp_buffer, cgi_title, sizeof(temp_buffer));
my_free(cgi_title);
}
asprintf(&cgi_title, "%s%s{%s}", (i != 0) ? temp_buffer : "", (i != 0) ? ", " : "", html_encode(req_hostgroups[i].entry, FALSE));
if (i == 0)
asprintf(&url_hostgroups_part, "hostgroup=%s", url_encode(req_hostgroups[i].entry));
else {
strncpy(temp_buffer, url_hostgroups_part, sizeof(temp_buffer));
my_free(url_hostgroups_part);
asprintf(&url_hostgroups_part, "%s&hostgroup=%s", temp_buffer, url_encode(req_hostgroups[i].entry));
}
}
}
} else {
req_hostgroups[0].entry = strdup("all");
req_hostgroups[1].entry = NULL;
asprintf(&url_hostgroups_part, "hostgroup=all");
}
/* determine display of servicegroups */
if (req_servicegroups[0].entry != NULL) {
show_all_servicegroups = FALSE;
for (i = 0; req_servicegroups[i].entry != NULL; i++) {
if (!strcmp(req_servicegroups[i].entry, "all")) {
show_all_servicegroups = TRUE;
my_free(url_servicegroups_part);
my_free(cgi_title);
req_servicegroups[0].entry = strdup("all");
req_servicegroups[1].entry = NULL;
asprintf(&url_servicegroups_part, "servicegroup=all");
break;
} else {
if (i != 0) {
strncpy(temp_buffer, cgi_title, sizeof(temp_buffer));
my_free(cgi_title);
}
asprintf(&cgi_title, "%s%s(%s)", (i != 0) ? temp_buffer : "", (i != 0) ? ", " : "", html_encode(req_servicegroups[i].entry, FALSE));
if (i == 0)
asprintf(&url_servicegroups_part, "servicegroup=%s", url_encode(req_servicegroups[i].entry));
else {
strncpy(temp_buffer, url_servicegroups_part, sizeof(temp_buffer));
my_free(url_servicegroups_part);
asprintf(&url_servicegroups_part, "%s&servicegroup=%s", temp_buffer, url_encode(req_servicegroups[i].entry));
}
}
}
} else {
req_servicegroups[0].entry = strdup("all");
req_servicegroups[1].entry = NULL;
asprintf(&url_servicegroups_part, "servicegroup=all");
}
/**
* send HTML header
**/
document_header(CGI_ID, TRUE, (tab_friendly_titles && cgi_title != NULL) ? cgi_title : "Current Network Status");
my_free(cgi_title);
/* pre filter for service groups
this way we mark all services which belong to a servicegroup we want to see once.
otherwise we would have to check every service if it belongs to a servicegroup we want to see
and this is very expensive
*/
if (display_type == DISPLAY_SERVICEGROUPS || return_live_search_data == TRUE) {
if (show_all_servicegroups == FALSE) {
for (i = 0; req_servicegroups[i].entry != NULL; i++) {
temp_servicegroup = find_servicegroup(req_servicegroups[i].entry);
if (temp_servicegroup != NULL && ( show_partial_servicegroups == TRUE || is_authorized_for_servicegroup(temp_servicegroup, ¤t_authdata) == TRUE)) {
for (temp_sg_member = temp_servicegroup->members; temp_sg_member != NULL; temp_sg_member = temp_sg_member->next) {
temp_hoststatus = find_hoststatus(temp_sg_member->host_name);
if (temp_hoststatus != NULL)
temp_hoststatus->added |= STATUS_BELONGS_TO_SG;
temp_servicestatus = find_servicestatus(temp_sg_member->host_name, temp_sg_member->service_description);
if (temp_servicestatus != NULL)
temp_servicestatus->added |= STATUS_BELONGS_TO_SG;
}
}
}
} else {
for (temp_servicegroup = servicegroup_list; temp_servicegroup != NULL; temp_servicegroup = temp_servicegroup->next) {
if (show_partial_servicegroups == TRUE || is_authorized_for_servicegroup(temp_servicegroup, ¤t_authdata) == TRUE) {
for (temp_sg_member = temp_servicegroup->members; temp_sg_member != NULL; temp_sg_member = temp_sg_member->next) {
temp_hoststatus = find_hoststatus(temp_sg_member->host_name);
if (temp_hoststatus != NULL)
temp_hoststatus->added |= STATUS_BELONGS_TO_SG;
temp_servicestatus = find_servicestatus(temp_sg_member->host_name, temp_sg_member->service_description);
if (temp_servicestatus != NULL)
temp_servicestatus->added |= STATUS_BELONGS_TO_SG;
}
}
}
}
}
/* pre filter for all host groups as well */
if (display_type == DISPLAY_HOSTGROUPS || return_live_search_data == TRUE) {
if (show_all_hostgroups == FALSE) {
for (i = 0; req_hostgroups[i].entry != NULL; i++) {
temp_hostgroup = find_hostgroup(req_hostgroups[i].entry);
if (temp_hostgroup != NULL && (show_partial_hostgroups == TRUE || is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == TRUE)) {
for (temp_hg_member = temp_hostgroup->members; temp_hg_member != NULL; temp_hg_member = temp_hg_member->next) {
temp_hoststatus = find_hoststatus(temp_hg_member->host_name);
if (temp_hoststatus != NULL)
temp_hoststatus->added |= STATUS_BELONGS_TO_HG;
}
}
}
} else {
for (temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {
if (show_partial_hostgroups == TRUE || is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == TRUE) {
for (temp_hg_member = temp_hostgroup->members; temp_hg_member != NULL; temp_hg_member = temp_hg_member->next) {
temp_hoststatus = find_hoststatus(temp_hg_member->host_name);
if (temp_hoststatus != NULL)
temp_hoststatus->added |= STATUS_BELONGS_TO_HG;
}
}
}
}
}
/**
* Now iterate through servicestatus_list and hoststatus_list to find all hosts/services we need to display
* All filtering and authorization is done here
**/
/* if user just want's to see all unhandled problems */
/* prepare for services */
if (display_all_unhandled_problems == TRUE || display_all_problems == TRUE) {
host_status_types = HOST_UP | HOST_PENDING;
service_status_types = all_service_problems;
group_style_type = STYLE_HOST_SERVICE_DETAIL;
if (display_all_unhandled_problems == TRUE)
service_properties |= service_problems_unhandled;
}
for (temp_servicestatus = servicestatus_list; temp_servicestatus != NULL; temp_servicestatus = temp_servicestatus->next) {
/* this is not needed if we do a live search */
if (return_live_search_data == TRUE)
continue;
/* if user is doing a search and service didn't match try next one */
if (search_string != NULL && temp_servicestatus->search_matched == FALSE && \
show_all_hostgroups == TRUE && show_all_servicegroups == TRUE)
continue;
if (service_filter != NULL && strcmp(service_filter, temp_servicestatus->description))
continue;
/* find the service */
if ((temp_service = find_service(temp_servicestatus->host_name, temp_servicestatus->description)) == NULL) {
/* see if we should display a servicegroup */
if (display_type == DISPLAY_SERVICEGROUPS &&temp_servicestatus->added & STATUS_BELONGS_TO_SG)
temp_servicestatus->added = temp_servicestatus->added - STATUS_BELONGS_TO_SG;
continue;
}
/* make sure user has rights to see this... */
if (is_authorized_for_service(temp_service, ¤t_authdata) == FALSE) {
/* see if we should display a servicegroup */
if (display_type == DISPLAY_SERVICEGROUPS && temp_servicestatus->added & STATUS_BELONGS_TO_SG)
temp_servicestatus->added = temp_servicestatus->added - STATUS_BELONGS_TO_SG;
continue;
}
user_is_authorized_for_statusdata = TRUE;
/* get the host status information */
if ((temp_hoststatus = find_hoststatus(temp_service->host_name)) == NULL) {
/* see if we should display a hostgroup */
if (display_type == DISPLAY_HOSTGROUPS && temp_hoststatus->added & STATUS_BELONGS_TO_HG) {
temp_hoststatus->added = temp_hoststatus->added - STATUS_BELONGS_TO_HG;
/* see if we should display a servicegroup */
} else if (display_type == DISPLAY_SERVICEGROUPS && temp_servicestatus->added & STATUS_BELONGS_TO_SG) {
temp_servicestatus->added = temp_servicestatus->added - STATUS_BELONGS_TO_SG;
}
continue;
}
/* check host properties filter */
if (passes_host_properties_filter(temp_hoststatus) == FALSE) {
/* see if we should display a hostgroup */
if (display_type == DISPLAY_HOSTGROUPS && temp_hoststatus->added & STATUS_BELONGS_TO_HG) {
temp_hoststatus->added = temp_hoststatus->added - STATUS_BELONGS_TO_HG;
/* see if we should display a servicegroup */
} else if (display_type == DISPLAY_SERVICEGROUPS && temp_servicestatus->added & STATUS_BELONGS_TO_SG) {
temp_servicestatus->added = temp_servicestatus->added - STATUS_BELONGS_TO_SG;
}
continue;
}
/* check service properties filter */
if (passes_service_properties_filter(temp_servicestatus) == FALSE) {
/* see if we should display a servicegroup */
if (display_type == DISPLAY_SERVICEGROUPS && temp_servicestatus->added & STATUS_BELONGS_TO_SG)
temp_servicestatus->added = temp_servicestatus->added - STATUS_BELONGS_TO_SG;
continue;
}
/* find the host */
temp_host = find_host(temp_service->host_name);
/* see if only one host should be shown */
if (display_type == DISPLAY_HOSTS && show_all_hosts == FALSE && search_string == NULL) {
found = FALSE;
for (i = 0; req_hosts[i].entry != NULL; i++) {
if (!strcmp(req_hosts[i].entry, temp_hoststatus->host_name) || (temp_host != NULL && !strcmp(req_hosts[i].entry, temp_host->display_name))) {
found = TRUE;
break;
}
}
if (found == FALSE)
continue;
}
/* see if we should display a hostgroup */
else if (display_type == DISPLAY_HOSTGROUPS) {
if (!(temp_hoststatus->added & STATUS_BELONGS_TO_HG))
continue;
}
/* see if we should display a servicegroup */
else if (display_type == DISPLAY_SERVICEGROUPS) {
if (!(temp_servicestatus->added & STATUS_BELONGS_TO_SG))
continue;
}
if (!(temp_hoststatus->added & STATUS_COUNTED_UNFILTERED)) {
/* count host for status totals */
if (temp_hoststatus->status == HOST_DOWN)
num_total_hosts_down++;
else if (temp_hoststatus->status == HOST_UNREACHABLE)
num_total_hosts_unreachable++;
else if (temp_hoststatus->status == HOST_PENDING)
num_total_hosts_pending++;
else
num_total_hosts_up++;
temp_hoststatus->added |= STATUS_COUNTED_UNFILTERED;
}
/* see if we should display services for hosts with this type of status */
if (!(host_status_types & temp_hoststatus->status)) {
/* see if we should display a hostgroup */
if (display_type == DISPLAY_HOSTGROUPS && temp_hoststatus->added & STATUS_BELONGS_TO_HG) {
temp_hoststatus->added = temp_hoststatus->added - STATUS_BELONGS_TO_HG;
/* see if we should display a servicegroup */
} else if (display_type == DISPLAY_SERVICEGROUPS && temp_servicestatus->added & STATUS_BELONGS_TO_SG) {
temp_servicestatus->added = temp_servicestatus->added - STATUS_BELONGS_TO_SG;
}
continue;
}
if (!(temp_servicestatus->added & STATUS_COUNTED_UNFILTERED)) {
if (temp_servicestatus->status == SERVICE_CRITICAL)
num_total_services_critical++;
else if (temp_servicestatus->status == SERVICE_WARNING)
num_total_services_warning++;
else if (temp_servicestatus->status == SERVICE_UNKNOWN)
num_total_services_unknown++;
else if (temp_servicestatus->status == SERVICE_PENDING)
num_total_services_pending++;
else
num_total_services_ok++;
temp_servicestatus->added |= STATUS_COUNTED_UNFILTERED;
}
/* see if we should display this type of service status */
if (!(service_status_types & temp_servicestatus->status)) {
/* see if we should display a servicegroup */
if (display_type == DISPLAY_SERVICEGROUPS && temp_servicestatus->added & STATUS_BELONGS_TO_SG)
temp_servicestatus->added = temp_servicestatus->added - STATUS_BELONGS_TO_SG;
continue;
}
if (display_type == DISPLAY_HOSTGROUPS)
temp_servicestatus->added |= STATUS_BELONGS_TO_HG;
if (display_all_unhandled_problems == FALSE && display_all_problems == FALSE)
add_status_data(HOST_STATUS, temp_hoststatus);
add_status_data(SERVICE_STATUS, temp_servicestatus);
}
/* if user just want's to see all unhandled problems */
/* prepare for hosts */
if (display_all_unhandled_problems == TRUE || display_all_problems == TRUE) {
host_status_types = all_host_problems;
if (display_all_unhandled_problems == TRUE)
host_properties |= host_problems_unhandled;
}
/* this is only for hosts with no services attached */
/* skip this part for live search */
if (group_style_type != STYLE_SERVICE_DETAIL && return_live_search_data == FALSE) {
for (temp_hoststatus = hoststatus_list; temp_hoststatus != NULL; temp_hoststatus = temp_hoststatus->next) {
/* see if hoststatus is already recorded */
if (temp_hoststatus->added & STATUS_ADDED)
continue;
/* if user is doing a search and host didn't match try next one */
if (search_string != NULL && temp_hoststatus->search_matched == FALSE && show_all_hostgroups == TRUE)
continue;
/* find the host */
if ((temp_host = find_host(temp_hoststatus->host_name)) == NULL ) {
/* see if we should display a hostgroup */
if (display_type == DISPLAY_HOSTGROUPS && temp_hoststatus->added & STATUS_BELONGS_TO_HG) {
temp_hoststatus->added = temp_hoststatus->added - STATUS_BELONGS_TO_HG;
/* see if we should display a servicegroup */
} else if (display_type == DISPLAY_SERVICEGROUPS && temp_hoststatus->added & STATUS_BELONGS_TO_SG) {
temp_hoststatus->added = temp_hoststatus->added - STATUS_BELONGS_TO_SG;
}
continue;
}
/* make sure user has rights to see this... */
if (is_authorized_for_host(temp_host, ¤t_authdata) == FALSE) {
/* see if we should display a hostgroup */
if (display_type == DISPLAY_HOSTGROUPS && temp_hoststatus->added & STATUS_BELONGS_TO_HG) {
temp_hoststatus->added = temp_hoststatus->added - STATUS_BELONGS_TO_HG;
/* see if we should display a servicegroup */
} else if (display_type == DISPLAY_SERVICEGROUPS && temp_hoststatus->added & STATUS_BELONGS_TO_SG) {
temp_hoststatus->added = temp_hoststatus->added - STATUS_BELONGS_TO_SG;
}
continue;
}
user_is_authorized_for_statusdata = TRUE;
/* check host properties filter */
if (passes_host_properties_filter(temp_hoststatus) == FALSE) {
/* see if we should display a hostgroup */
if (display_type == DISPLAY_HOSTGROUPS && temp_hoststatus->added & STATUS_BELONGS_TO_HG) {
temp_hoststatus->added = temp_hoststatus->added - STATUS_BELONGS_TO_HG;
/* see if we should display a servicegroup */
} else if (display_type == DISPLAY_SERVICEGROUPS && temp_hoststatus->added & STATUS_BELONGS_TO_SG) {
temp_hoststatus->added = temp_hoststatus->added - STATUS_BELONGS_TO_SG;
}
continue;
}
/* see if only one host should be shown */
if (display_type == DISPLAY_HOSTS && show_all_hosts == FALSE && search_string == NULL) {
found = FALSE;
for (i = 0; req_hosts[i].entry != NULL; i++) {
if (!strcmp(req_hosts[i].entry, temp_hoststatus->host_name) || !strcmp(req_hosts[i].entry, temp_host->display_name)) {
found = TRUE;
break;
}
}
if (found == FALSE)
continue;
}
/* see if we should display a hostgroup */
else if (display_type == DISPLAY_HOSTGROUPS) {
if (!(temp_hoststatus->added & STATUS_BELONGS_TO_HG))
continue;
/* see if we should display a servicegroup */
} else if (display_type == DISPLAY_SERVICEGROUPS) {
if (!(temp_hoststatus->added & STATUS_BELONGS_TO_SG))
continue;
}
if (!(temp_hoststatus->added & STATUS_COUNTED_UNFILTERED)) {
/* count host for status totals */
if (temp_hoststatus->status == HOST_DOWN)
num_total_hosts_down++;
else if (temp_hoststatus->status == HOST_UNREACHABLE)
num_total_hosts_unreachable++;
else if (temp_hoststatus->status == HOST_PENDING)
num_total_hosts_pending++;
else
num_total_hosts_up++;
temp_hoststatus->added |= STATUS_COUNTED_UNFILTERED;
}
/* see if we should display services for hosts with this type of status */
if (!(host_status_types & temp_hoststatus->status)) {
/* see if we should display a hostgroup */
if (display_type == DISPLAY_HOSTGROUPS && temp_hoststatus->added & STATUS_BELONGS_TO_HG) {
temp_hoststatus->added = temp_hoststatus->added - STATUS_BELONGS_TO_HG;
/* see if we should display a servicegroup */
} else if (display_type == DISPLAY_SERVICEGROUPS && temp_hoststatus->added & STATUS_BELONGS_TO_SG) {
temp_hoststatus->added = temp_hoststatus->added - STATUS_BELONGS_TO_SG;
}
continue;
}
add_status_data(HOST_STATUS, temp_hoststatus);
hosts_need_to_be_sorted_again = TRUE;
}
}
/**
* Now as we have all necessary data we start displaying the page
**/
// determine which dropdown menu to show
if (group_style_type == STYLE_OVERVIEW || group_style_type == STYLE_SUMMARY || group_style_type == STYLE_GRID)
show_dropdown = NO_STATUS;
else {
if (group_style_type == STYLE_HOST_DETAIL || group_style_type == STYLE_HOST_SERVICE_DETAIL)
show_dropdown = HOST_STATUS;
else
show_dropdown = SERVICE_STATUS;
}
/* add highlight table row and form elementes (drop down) to page */
if (show_dropdown != NO_STATUS && content_type == HTML_CONTENT) {
if (highlight_table_rows == TRUE) {
printf("\n");
}
printf("\n");
/* if user couldn't see anything, print out some helpful info... */
if (total_service_entries == 0 && user_is_authorized_for_statusdata == FALSE)
print_generic_error_message("It appears as though you do not have permission to view information for any of the services you requested...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
else
status_page_num_selector(service_start, SERVICE_STATUS);
} else if (content_type == JSON_CONTENT)
printf("\n]\n");
/* free memory allocated to the sort lists */
if (use_sort == TRUE)
free_sort_list();
return;
}
/* display a detailed listing of the status of all hosts... */
void show_host_detail(void) {
char temp_buffer[MAX_INPUT_BUFFER];
char *temp_url = NULL;
char *processed_string = NULL;
char *status_class = "";
char *status_bg_class = "";
char *style = NULL;
host *temp_host = NULL;
sort *temp_sort = NULL;
statusdata *temp_statusdata = NULL;
int odd = 0;
int total_comments = 0;
int use_sort = FALSE;
int result = OK;
int first_entry = TRUE;
int json_start = TRUE;
/* sort status data if necessary */
if ((sort_type != SORT_NONE && sort_object == HOST_STATUS) || hosts_need_to_be_sorted_again == TRUE) {
result = sort_status_data(HOST_STATUS, (hosts_need_to_be_sorted_again == TRUE) ? SORT_ASCENDING : sort_type, sort_option);
if (result == ERROR)
use_sort = FALSE;
else
use_sort = TRUE;
} else
use_sort = FALSE;
if (content_type == JSON_CONTENT)
printf("\"host_status\": [\n");
else if (content_type == CSV_CONTENT) {
printf("%sHost%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sStatus%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sLast_Check%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sDuration%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sAttempt%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sStatus_Information%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sIs_Flapping%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sIn_Scheduled_Downtime%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sActive_Checks_Enabled%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sPassive_Checks_Enabled%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sNotifications_Enabled%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sProblem_Acknowledged%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sAction_URL%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sNotes_URL%s\n", csv_data_enclosure, csv_data_enclosure);
} else {
printf("
\n");
printf("
\n");
printf("
\n");
if (display_header == TRUE)
show_filters();
printf("
");
printf("
\n");
printf("
Host Status Details For ");
print_displayed_names(display_type);
printf("
\n");
printf("\n");
/* if user couldn't see anything, print out some helpful info... */
if (total_host_entries == 0 && user_is_authorized_for_statusdata == FALSE)
print_generic_error_message("It appears as though you do not have permission to view information for any of the hosts you requested...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
else
status_page_num_selector(result_start, HOST_STATUS);
} else if (content_type == JSON_CONTENT)
printf("\n]\n");
/* free memory allocated to the sort lists */
if (use_sort == TRUE)
free_sort_list();
return;
}
/* show an overview of servicegroup(s)... */
void show_servicegroup_overviews(void) {
servicesmember *temp_member = NULL;
servicestatus *temp_servicestatus = NULL;
servicegroup *temp_servicegroup = NULL;
int current_column;
int user_has_seen_something = FALSE;
int json_start = TRUE;
int partial_services = FALSE;
int i = 0, found = FALSE;
if (content_type == JSON_CONTENT) {
printf("\"servicegroup_overview\": [\n");
} else {
/* display status overviews for Servicegroups */
printf("
\n");
current_column = 1;
}
/* loop through all servicegroups... */
for (temp_servicegroup = servicegroup_list; temp_servicegroup != NULL; temp_servicegroup = temp_servicegroup->next) {
/* view only selected servicegroups */
if (show_all_servicegroups == FALSE) {
found = FALSE;
for (i = 0; req_servicegroups[i].entry != NULL; i++) {
if (!strcmp(req_servicegroups[i].entry, temp_servicegroup->group_name)) {
found = TRUE;
break;
}
}
if (found == FALSE)
continue;
}
/* make sure the user is authorized to view at least one host in this servicegroup */
if (show_partial_servicegroups == FALSE && is_authorized_for_servicegroup(temp_servicegroup, ¤t_authdata) == FALSE)
continue;
/* if we're showing partial servicegroups, find out if there will be any services that belong to the servicegroup */
if (show_partial_servicegroups == TRUE) {
partial_services = FALSE;
for (temp_member = temp_servicegroup->members; temp_member != NULL; temp_member = temp_member->next) {
/* find servicestatus */
if ((temp_servicestatus = find_servicestatus(temp_member->host_name, temp_member->service_description)) == NULL)
continue;
/* check if this servicestatus belongs to any servicegroup and has passed through all filters */
if (!(temp_servicestatus->added & STATUS_BELONGS_TO_SG))
continue;
partial_services = TRUE;
break;
}
/* if we're showing partial servicegroups, but there are no services to display, there's nothing to see here */
if (partial_services == FALSE)
continue;
}
if (content_type == JSON_CONTENT) {
/* always add a comma, except for the first line */
if (json_start == FALSE)
printf(",\n");
} else {
if (current_column == 1)
printf("
\n");
printf("
\n");
}
if (show_servicegroup_overview(temp_servicegroup) == FALSE)
continue;
json_start = FALSE;
user_has_seen_something = TRUE;
if (content_type != JSON_CONTENT) {
printf("
\n");
if (current_column == overview_columns)
printf("
\n");
if (current_column < overview_columns)
current_column++;
else
current_column = 1;
}
}
if (content_type == JSON_CONTENT)
printf(" ]\n");
else {
if (current_column != 1) {
for (; current_column <= overview_columns; current_column++)
printf("
\n");
printf("\n");
}
printf("
\n");
}
/* if user couldn't see anything, print out some helpful info... */
if (user_has_seen_something == FALSE) {
if (content_type == JSON_CONTENT)
printf(",\n");
if (servicegroup_list != NULL)
print_generic_error_message("It appears as though you do not have permission to view information for the service group you requested...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
else
print_generic_error_message("There are no service groups defined.", NULL, 0);
}
return;
}
/* shows an overview of a specific servicegroup... */
int show_servicegroup_overview(servicegroup *temp_servicegroup) {
servicesmember *temp_member;
hoststatus *last_hoststatus = NULL;
hoststatus *temp_hoststatus = NULL;
servicestatus *temp_servicestatus = NULL;
int odd = 0;
int json_start = TRUE;
int partial_services = FALSE;
/* make sure the user is authorized to view at least one service in this servicegroup */
if (show_partial_servicegroups == FALSE && is_authorized_for_servicegroup(temp_servicegroup, ¤t_authdata) == FALSE)
return FALSE;
/* if we're showing partial servicegroups, find out if there will be any services that belong to the servicegroup */
if (show_partial_servicegroups == TRUE) {
for (temp_member = temp_servicegroup->members; temp_member != NULL; temp_member = temp_member->next) {
/* find servicestatus */
if ((temp_servicestatus = find_servicestatus(temp_member->host_name, temp_member->service_description)) == NULL)
continue;
/* check if this servicestatus belongs to any servicegroup and has passed through all filters */
if (!(temp_servicestatus->added & STATUS_BELONGS_TO_SG))
continue;
partial_services = TRUE;
break;
}
}
/* if we're showing partial servicegroups, but there are no services to display, there's nothing to see here */
if (show_partial_servicegroups == TRUE && partial_services == FALSE)
return FALSE;
/* print json format */
if (content_type == JSON_CONTENT) {
printf("{ \"servicegroup_name\": \"%s\",\n", json_encode(temp_servicegroup->group_name));
printf("\"members\": [ \n");
} else {
printf("
\n");
}
/* find all hosts that have services that are members of the servicegroup */
for (temp_member = temp_servicegroup->members; temp_member != NULL; temp_member = temp_member->next) {
/* find the host status */
if ((temp_hoststatus = find_hoststatus(temp_member->host_name)) == NULL)
continue;
/* check if this hoststatus belongs to any servicegroup and has passed through all filters */
if (!(temp_hoststatus->added & STATUS_BELONGS_TO_SG))
continue;
/* skip this if it isn't a new host... */
if (temp_hoststatus == last_hoststatus)
continue;
/* get the status of the service */
if ((temp_servicestatus = find_servicestatus(temp_member->host_name, temp_member->service_description)) == NULL)
continue;
/* check if this servicestatus belongs to any servicegroup and has passed through all filters */
if (!(temp_servicestatus->added & STATUS_BELONGS_TO_SG))
continue;
if (odd) odd = 0;
else odd = 1;
if (content_type == JSON_CONTENT) {
if (json_start == FALSE)
printf(",\n");
json_start = FALSE;
}
show_servicegroup_hostgroup_member_overview(temp_hoststatus, odd, temp_servicegroup);
last_hoststatus = temp_hoststatus;
}
if (content_type == JSON_CONTENT)
printf(" ] }\n");
else
printf("
\n");
return TRUE;
}
/* show a summary of servicegroup(s)... */
void show_servicegroup_summaries(void) {
servicegroup *temp_servicegroup = NULL;
servicesmember *temp_member = NULL;
hoststatus *temp_hoststatus = NULL;
servicestatus *temp_servicestatus = NULL;
int user_has_seen_something = FALSE;
int odd = 0;
int json_start = TRUE;
int partial_services = FALSE;
int i = 0, found = FALSE;
if (content_type == JSON_CONTENT) {
printf("\"servicegroup_summary\": [\n");
} else {
printf("
\n");
printf("
\n");
printf("
Service Group
Host Status Summary
Service Status Summary
\n");
printf("
\n");
}
/* display status summary for servicegroups */
for (temp_servicegroup = servicegroup_list; temp_servicegroup != NULL; temp_servicegroup = temp_servicegroup->next) {
/* view only selected servicegroups */
if (show_all_servicegroups == FALSE) {
found = FALSE;
for (i = 0; req_servicegroups[i].entry != NULL; i++) {
if (!strcmp(req_servicegroups[i].entry, temp_servicegroup->group_name)) {
found = TRUE;
break;
}
}
if (found == FALSE)
continue;
}
/* make sure the user is authorized to view at least one service in this servicegroup */
if (show_partial_servicegroups == FALSE && is_authorized_for_servicegroup(temp_servicegroup, ¤t_authdata) == FALSE)
continue;
/* if we're showing partial servicegroups, find out if there will be any services that belong to the servicegroup */
if (show_partial_servicegroups == TRUE) {
partial_services = FALSE;
for (temp_member = temp_servicegroup->members; temp_member != NULL; temp_member = temp_member->next) {
/* find servicestatus */
if ((temp_servicestatus = find_servicestatus(temp_member->host_name, temp_member->service_description)) == NULL)
continue;
/* check if this servicestatus belongs to any servicegroup and has passed through all filters */
if (!(temp_servicestatus->added & STATUS_BELONGS_TO_SG))
continue;
partial_services = TRUE;
break;
}
/* if we're showing partial servicegroups, but there are no services to display, there's nothing to see here */
if (partial_services == FALSE)
continue;
}
user_has_seen_something = TRUE;
/* check if we have to display anything */
if (host_status_types != all_host_status_types || service_status_types != all_service_status_types) {
found = FALSE;
for (temp_member = temp_servicegroup->members; temp_member != NULL; temp_member = temp_member->next) {
if (host_status_types != all_host_status_types) {
/* find the host status */
if ((temp_hoststatus = find_hoststatus(temp_member->host_name)) == NULL)
continue;
if (!(temp_hoststatus->added & STATUS_BELONGS_TO_SG))
continue;
}
if (service_status_types != all_service_status_types) {
/* find the service status */
if ((temp_servicestatus = find_servicestatus(temp_member->host_name, temp_member->service_description)) == NULL)
continue;
if (!(temp_servicestatus->added & STATUS_BELONGS_TO_SG))
continue;
}
found = TRUE;
break;
}
if (found == FALSE)
continue;
}
if (odd == 0)
odd = 1;
else
odd = 0;
if (content_type == JSON_CONTENT) {
/* always add a comma, except for the first line */
if (json_start == FALSE)
printf(",\n");
json_start = FALSE;
}
/* show summary for this servicegroup */
show_servicegroup_summary(temp_servicegroup, odd);
}
if (content_type == JSON_CONTENT)
printf(" ]\n");
else
printf("
\n");
/* if user couldn't see anything, print out some helpful info... */
if (user_has_seen_something == FALSE) {
if (content_type == JSON_CONTENT)
printf(",\n");
if (servicegroup_list != NULL)
print_generic_error_message("It appears as though you do not have permission to view information for the service group you requested...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
else
print_generic_error_message("There are no service groups defined.", NULL, 0);
}
return;
}
/* displays status summary information for a specific servicegroup */
void show_servicegroup_summary(servicegroup *temp_servicegroup, int odd) {
char *status_bg_class = "";
if (content_type == JSON_CONTENT) {
printf("{ \"servicegroup_name\": \"%s\",\n", json_encode(temp_servicegroup->group_name));
show_servicegroup_host_totals_summary(temp_servicegroup);
show_servicegroup_service_totals_summary(temp_servicegroup);
printf("}\n");
} else {
if (odd == 1)
status_bg_class = "Even";
else
status_bg_class = "Odd";
printf("
\n");
if ((services_ok + services_warning + services_unknown + services_critical + services_pending) == 0)
printf("No matching services");
}
return;
}
/* show a grid layout of servicegroup(s)... */
void show_servicegroup_grids(void) {
servicegroup *temp_servicegroup = NULL;
int user_has_seen_something = FALSE;
int json_start = TRUE;
int i = 0, found = FALSE;
if (content_type == JSON_CONTENT) {
printf("\"servicegroup_grid\": [\n");
}
/* display status grids for servicegroups */
for (temp_servicegroup = servicegroup_list; temp_servicegroup != NULL; temp_servicegroup = temp_servicegroup->next) {
/* view only selected servicegroups */
if (show_all_servicegroups == FALSE) {
found = FALSE;
for (i = 0; req_servicegroups[i].entry != NULL; i++) {
if (!strcmp(req_servicegroups[i].entry, temp_servicegroup->group_name)) {
found = TRUE;
break;
}
}
if (found == FALSE)
continue;
}
/* make sure the user is authorized to view at least one service in this servicegroup */
if (show_partial_servicegroups == FALSE && is_authorized_for_servicegroup(temp_servicegroup, ¤t_authdata) == FALSE)
continue;
if (content_type == JSON_CONTENT) {
/* always add a comma, except for the first line */
if (json_start == FALSE)
printf(",\n");
}
/* show grid for this servicegroup */
if (show_servicegroup_grid(temp_servicegroup) == FALSE)
continue;
json_start = FALSE;
user_has_seen_something = TRUE;
}
if (content_type == JSON_CONTENT)
printf(" ]\n");
/* if user couldn't see anything, print out some helpful info... */
if (user_has_seen_something == FALSE) {
if (content_type == JSON_CONTENT)
printf(",\n");
if (servicegroup_list != NULL)
print_generic_error_message("It appears as though you do not have permission to view information for the service group you requested...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
else
print_generic_error_message("There are no service groups defined.", NULL, 0);
}
return;
}
/* displays status grid for a specific servicegroup */
int show_servicegroup_grid(servicegroup *temp_servicegroup) {
char *status_bg_class = "";
char *status = "";
char *host_status_class = "";
char *service_status_class = "";
char *processed_string = NULL;
servicesmember *temp_member;
servicesmember *temp_member2;
host *temp_host;
hoststatus *last_hoststatus = NULL;
service *temp_service;
hoststatus *temp_hoststatus = NULL;
servicestatus *temp_servicestatus;
int odd = 0;
int current_item;
int json_start = TRUE;
int json_start2 = TRUE;
int partial_services = FALSE;
/* make sure the user is authorized to view at least one service in this servicegroup */
if (show_partial_servicegroups == FALSE && is_authorized_for_servicegroup(temp_servicegroup, ¤t_authdata) == FALSE)
return FALSE;
/* if we're showing partial servicegroups, find out if there will be any services that belong to the servicegroup */
if (show_partial_servicegroups == TRUE) {
for (temp_member = temp_servicegroup->members; temp_member != NULL; temp_member = temp_member->next) {
/* find servicestatus */
if ((temp_servicestatus = find_servicestatus(temp_member->host_name, temp_member->service_description)) == NULL)
continue;
/* check if this servicestatus belongs to any servicegroup and has passed through all filters */
if (!(temp_servicestatus->added & STATUS_BELONGS_TO_SG))
continue;
partial_services = TRUE;
break;
}
}
/* if we're showing partial servicegroups, but there are no services to display, there's nothing to see here */
if (show_partial_servicegroups == TRUE && partial_services == FALSE)
return FALSE;
if (content_type == JSON_CONTENT) {
printf("{ \"servicegroup_name\": \"%s\",\n", json_encode(temp_servicegroup->group_name));
printf("\"members\": [ \n");
} else {
printf("
\n");
}
/* find all hosts that have services that are members of the servicegroup */
for (temp_member = temp_servicegroup->members; temp_member != NULL; temp_member = temp_member->next) {
/* find the host status */
if ((temp_hoststatus = find_hoststatus(temp_member->host_name)) == NULL)
continue;
/* skip this if it isn't a new host... */
if (temp_hoststatus == last_hoststatus)
continue;
/* check if this hoststatus belongs to any servicegroup and has passed through all filters */
if (!(temp_hoststatus->added & STATUS_BELONGS_TO_SG))
continue;
/* get the status of the service */
if ((temp_servicestatus = find_servicestatus(temp_member->host_name, temp_member->service_description)) == NULL)
continue;
/* check if this servicestatus belongs to any servicegroup and has passed through all filters */
if (!(temp_servicestatus->added & STATUS_BELONGS_TO_SG))
continue;
/* find the host status */
if ((temp_host = find_host(temp_member->host_name)) == NULL)
continue;
if (odd == 1) {
status_bg_class = "Even";
odd = 0;
} else {
status_bg_class = "Odd";
odd = 1;
}
if (content_type != JSON_CONTENT)
printf("
", host_status_class);
}
/* display all services on the host that are part of the servicegroup */
current_item = 1;
json_start2 = TRUE;
for (temp_member2 = temp_member; temp_member2 != NULL; temp_member2 = temp_member2->next) {
/* bail out if we've reached the end of the services that are associated with this servicegroup */
if (strcmp(temp_member2->host_name, temp_host->name))
break;
/* get the status of the service */
if ((temp_servicestatus = find_servicestatus(temp_member2->host_name, temp_member2->service_description)) == NULL)
continue;
/* check if this servicestatus belongs to any servicegroup and has passed through all filters */
if (!(temp_servicestatus->added & STATUS_BELONGS_TO_SG))
continue;
if (temp_servicestatus == NULL)
service_status_class = "NULL";
else if (temp_servicestatus->status == SERVICE_OK)
service_status_class = "OK";
else if (temp_servicestatus->status == SERVICE_WARNING)
service_status_class = "WARNING";
else if (temp_servicestatus->status == SERVICE_UNKNOWN)
service_status_class = "UNKNOWN";
else if (temp_servicestatus->status == SERVICE_CRITICAL)
service_status_class = "CRITICAL";
else
service_status_class = "PENDING";
if (content_type == JSON_CONTENT) {
if (json_start2 == FALSE)
printf(",\n");
json_start2 = FALSE;
printf("{ \"service_description\": \"%s\",\n", json_encode(temp_servicestatus->description));
temp_service = find_service(temp_servicestatus->host_name, temp_servicestatus->description);
printf("\"service_display_name\": \"%s\",\n", (temp_service != NULL && temp_service->display_name != NULL) ? json_encode(temp_service->display_name) : json_encode(temp_servicestatus->description));
if (temp_servicestatus == NULL)
printf("\"service_status\": null } ");
else
printf("\"service_status\": \"%s\" } ", service_status_class);
} else {
if (current_item > max_grid_width && max_grid_width > 0) {
printf(" \n");
current_item = 1;
}
printf("%s ", url_encode(temp_servicestatus->description), service_status_class, html_encode(temp_servicestatus->description, TRUE));
current_item++;
}
}
/* Print no matching in case of no services */
if (current_item == 1 && content_type != JSON_CONTENT)
printf("No matching services");
if (content_type == JSON_CONTENT) {
printf(" ] } \n");
} else {
/* actions */
printf("
\n");
return TRUE;
}
/* show an overview of hostgroup(s)... */
void show_hostgroup_overviews(void) {
hostgroup *temp_hostgroup = NULL;
hostsmember *temp_member = NULL;
hoststatus *temp_hoststatus = NULL;
int current_column;
int user_has_seen_something = FALSE;
int json_start = TRUE;
int partial_hosts = FALSE;
int i = 0, found = FALSE;
if (content_type == JSON_CONTENT) {
printf("\"hostgroup_overview\": [\n");
} else {
/* display status overviews for hostgroups */
printf("
\n");
current_column = 1;
}
/* loop through all hostgroups... */
for (temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {
/* view only selected hostgroups */
if (show_all_hostgroups == FALSE) {
found = FALSE;
for (i = 0; req_hostgroups[i].entry != NULL; i++) {
if (!strcmp(req_hostgroups[i].entry, temp_hostgroup->group_name)) {
found = TRUE;
break;
}
}
if (found == FALSE)
continue;
}
/* make sure the user is authorized to view this hostgroup */
if (show_partial_hostgroups == FALSE && is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == FALSE)
continue;
/* if we're showing partial hostgroups, find out if there will be any hosts that belong to the hostgroup */
if (show_partial_hostgroups == TRUE) {
partial_hosts = FALSE;
for (temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
/* find the host status */
if ((temp_hoststatus = find_hoststatus(temp_member->host_name)) == NULL)
continue;
/* check if this hoststatus belongs to any hostgroup and has passed through all filters */
if (!(temp_hoststatus->added & STATUS_BELONGS_TO_HG))
continue;
partial_hosts = TRUE;
break;
}
/* if we're showing partial hostgroups, but there are no hosts to display, there's nothing to see here */
if (partial_hosts == FALSE)
continue;
}
if (content_type == JSON_CONTENT) {
/* always add a comma, except for the first line */
if (json_start == FALSE)
printf(",\n");
} else {
if (current_column == 1)
printf("
\n");
}
if (show_hostgroup_overview(temp_hostgroup) == FALSE)
continue;
json_start = FALSE;
user_has_seen_something = TRUE;
if (content_type != JSON_CONTENT) {
if (current_column == overview_columns)
printf("
\n");
if (current_column < overview_columns)
current_column++;
else
current_column = 1;
}
}
if (content_type == JSON_CONTENT)
printf(" ]\n");
else {
if (current_column != 1) {
for (; current_column <= overview_columns; current_column++)
printf("
\n");
printf("\n");
}
printf("
\n");
}
/* if user couldn't see anything, print out some helpful info... */
if (user_has_seen_something == FALSE) {
if (content_type == JSON_CONTENT)
printf(",\n");
if (hostgroup_list != NULL)
print_generic_error_message("It appears as though you do not have permission to view information for the host group you requested...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
else
print_generic_error_message("There are no host groups defined.", NULL, 0);
}
return;
}
/* shows an overview of a specific hostgroup... */
int show_hostgroup_overview(hostgroup *temp_hostgroup) {
hostsmember *temp_member = NULL;
hoststatus *temp_hoststatus = NULL;
int odd = 0;
int json_start = TRUE;
int partial_hosts = FALSE;
/* make sure the user is authorized to view this hostgroup */
if (show_partial_hostgroups == FALSE && is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == FALSE)
return FALSE;
/* if we're showing partial hostgroups, find out if there will be any hosts that belong to the hostgroup */
if (show_partial_hostgroups == TRUE) {
for (temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
/* find the host status */
if ((temp_hoststatus = find_hoststatus(temp_member->host_name)) == NULL)
continue;
/* check if this hoststatus belongs to any hostgroup and has passed through all filters */
if (!(temp_hoststatus->added & STATUS_BELONGS_TO_HG))
continue;
partial_hosts = TRUE;
break;
}
}
/* if we're showing partial hostgroups, but there are no hosts to display, there's nothing to see here */
if (show_partial_hostgroups == TRUE && partial_hosts == FALSE)
return FALSE;
/* print json format */
if (content_type == JSON_CONTENT) {
printf("{ \"hostgroup_name\": \"%s\",\n", json_encode(temp_hostgroup->group_name));
printf("\"members\": [ \n");
} else {
printf("
\n");
}
/* find all the hosts that belong to the hostgroup */
for (temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
/* find the host status */
if ((temp_hoststatus = find_hoststatus(temp_member->host_name)) == NULL)
continue;
/* check if this hoststatus belongs to any hostgroup and has passed through all filters */
if (!(temp_hoststatus->added & STATUS_BELONGS_TO_HG))
continue;
if (odd) odd = 0;
else odd = 1;
if (content_type == JSON_CONTENT) {
if (json_start == FALSE)
printf(",\n");
json_start = FALSE;
}
show_servicegroup_hostgroup_member_overview(temp_hoststatus, odd, NULL);
}
if (content_type == JSON_CONTENT)
printf(" ] }\n");
else {
printf("
\n");
}
return;
}
/* shows services to a host status overview... */
void show_servicegroup_hostgroup_member_service_status_totals(char *host_name, void *data) {
int total_ok = 0;
int total_warning = 0;
int total_unknown = 0;
int total_critical = 0;
int total_pending = 0;
servicestatus *temp_servicestatus = NULL;
servicestatus *last_servicestatus = NULL;
statusdata *temp_status = NULL;
servicegroup *temp_servicegroup = NULL;
servicesmember *temp_member = NULL;
char temp_buffer[MAX_INPUT_BUFFER];
int service_found = FALSE;
if (display_type == DISPLAY_SERVICEGROUPS) {
temp_servicegroup = (servicegroup *)data;
for (temp_member = temp_servicegroup->members; temp_member != NULL; temp_member = temp_member->next) {
if (!strcmp(host_name, temp_member->host_name)) {
/* find service status */
if ((temp_servicestatus = find_servicestatus(temp_member->host_name, temp_member->service_description)) == NULL)
continue;
/* skip this if it isn't a new service... */
if (temp_servicestatus == last_servicestatus)
continue;
/* check if this servicestatus belongs to any servicegroup and has passed through all filters */
if (!(temp_servicestatus->added & STATUS_BELONGS_TO_SG))
continue;
if (temp_servicestatus->status == SERVICE_CRITICAL)
total_critical++;
else if (temp_servicestatus->status == SERVICE_WARNING)
total_warning++;
else if (temp_servicestatus->status == SERVICE_UNKNOWN)
total_unknown++;
else if (temp_servicestatus->status == SERVICE_OK)
total_ok++;
else if (temp_servicestatus->status == SERVICE_PENDING)
total_pending++;
else
total_ok++;
last_servicestatus = temp_servicestatus;
}
}
} else {
/* check all services... */
for (temp_status = statusdata_list; temp_status != NULL; temp_status = temp_status->next) {
if (temp_status->type != SERVICE_STATUS)
continue;
if (!strcmp(host_name, temp_status->host_name)) {
/* find service status */
if ((temp_servicestatus = find_servicestatus(temp_status->host_name, temp_status->svc_description)) == NULL)
continue;
/* check if this servicestatus belongs to any hostgroup and has passed through all filters */
if (!(temp_servicestatus->added & STATUS_BELONGS_TO_HG))
continue;
service_found = TRUE;
if (temp_status->status == SERVICE_CRITICAL)
total_critical++;
else if (temp_status->status == SERVICE_WARNING)
total_warning++;
else if (temp_status->status == SERVICE_UNKNOWN)
total_unknown++;
else if (temp_status->status == SERVICE_OK)
total_ok++;
else if (temp_status->status == SERVICE_PENDING)
total_pending++;
else
total_ok++;
/* list is in alphabetic order
therefore all services for this host appear in a row
if host doesn't match anymore we are done
*/
} else if (service_found == TRUE)
break;
}
}
if (content_type == JSON_CONTENT) {
printf("\"services_status_ok\": %d, ", total_ok);
printf("\"services_status_warning\": %d, ", total_warning);
printf("\"services_status_unknown\": %d, ", total_unknown);
printf("\"services_status_critical\": %d, ", total_critical);
printf("\"services_status_pending\": %d ", total_pending);
} else {
printf("
\n");
if ((total_ok + total_warning + total_unknown + total_critical + total_pending) == 0)
printf("No matching services");
}
return;
}
/* show a summary of hostgroup(s)... */
void show_hostgroup_summaries(void) {
hostgroup *temp_hostgroup = NULL;
hostsmember *temp_member = NULL;
hoststatus *temp_hoststatus = NULL;
int user_has_seen_something = FALSE;
int odd = 0;
int json_start = TRUE;
int partial_hosts = FALSE;
int i = 0, found = FALSE;
if (content_type == JSON_CONTENT) {
printf("\"hostgroup_summary\": [\n");
} else {
printf("
\n");
printf("
\n");
printf("
Host Group
Host Status Summary
Service Status Summary
\n");
printf("
\n");
}
/* display status summary for hostgroups */
for (temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {
partial_hosts = FALSE;
/* view only selected hostgroups */
if (show_all_hostgroups == FALSE) {
found = FALSE;
for (i = 0; req_hostgroups[i].entry != NULL; i++) {
if (!strcmp(req_hostgroups[i].entry, temp_hostgroup->group_name)) {
found = TRUE;
break;
}
}
if (found == FALSE)
continue;
}
/* make sure the user is authorized to view this hostgroup */
if (show_partial_hostgroups == FALSE && is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == FALSE)
continue;
/* if we're showing partial hostgroups, find out if there will be any hosts that belong to the hostgroup */
if (show_partial_hostgroups == TRUE) {
partial_hosts = FALSE;
for (temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
/* find the host status */
if ((temp_hoststatus = find_hoststatus(temp_member->host_name)) == NULL)
continue;
/* check if this hoststatus belongs to any hostgroup and has passed through all filters */
if (!(temp_hoststatus->added & STATUS_BELONGS_TO_HG))
continue;
partial_hosts = TRUE;
break;
}
/* if we're showing partial hostgroups, but there are no hosts to display, there's nothing to see here */
if (partial_hosts == FALSE)
continue;
}
user_has_seen_something = TRUE;
if (odd) odd = 0;
else odd = 1;
if (content_type == JSON_CONTENT) {
/* always add a comma, except for the first line */
if (json_start == FALSE)
printf(",\n");
json_start = FALSE;
}
/* show summary for this hostgroup */
show_hostgroup_summary(temp_hostgroup, odd);
}
if (content_type == JSON_CONTENT)
printf(" ]\n");
else
printf("
\n");
/* if user couldn't see anything, print out some helpful info... */
if (user_has_seen_something == FALSE) {
if (content_type == JSON_CONTENT)
printf(",\n");
if (hostgroup_list != NULL)
print_generic_error_message("It appears as though you do not have permission to view information for the host group you requested...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
else
print_generic_error_message("There are no host groups defined.", NULL, 0);
}
return;
}
/* displays status summary information for a specific hostgroup */
void show_hostgroup_summary(hostgroup *temp_hostgroup, int odd) {
char *status_bg_class = "";
if (content_type == JSON_CONTENT) {
printf("{ \"hostgroup_name\": \"%s\",\n", json_encode(temp_hostgroup->group_name));
show_hostgroup_host_totals_summary(temp_hostgroup);
show_hostgroup_service_totals_summary(temp_hostgroup);
printf("}\n");
} else {
if (odd == 1)
status_bg_class = "Even";
else
status_bg_class = "Odd";
printf("
\n");
if ((services_ok + services_warning + services_unknown + services_critical + services_pending) == 0)
printf("No matching services");
}
return;
}
/* show a grid layout of hostgroup(s)... */
void show_hostgroup_grids(void) {
hostgroup *temp_hostgroup = NULL;
int user_has_seen_something = FALSE;
int json_start = TRUE;
int i = 0, found = FALSE;
if (content_type == JSON_CONTENT) {
printf("\"hostgroup_grid\": [\n");
}
/* display status grids for hostgroups */
for (temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {
/* view only selected hostgroups */
if (show_all_hostgroups == FALSE) {
found = FALSE;
for (i = 0; req_hostgroups[i].entry != NULL; i++) {
if (!strcmp(req_hostgroups[i].entry, temp_hostgroup->group_name)) {
found = TRUE;
break;
}
}
if (found == FALSE)
continue;
}
/* make sure the user is authorized to view this hostgroup */
if (show_partial_hostgroups == FALSE && is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == FALSE)
continue;
if (content_type == JSON_CONTENT) {
/* always add a comma, except for the first line */
if (json_start == FALSE)
printf(",\n");
}
/* show grid for this hostgroup */
if (show_hostgroup_grid(temp_hostgroup) == FALSE)
continue;
json_start = FALSE;
user_has_seen_something = TRUE;
}
if (content_type == JSON_CONTENT)
printf(" ]\n");
/* if user couldn't see anything, print out some helpful info... */
if (user_has_seen_something == FALSE) {
if (content_type == JSON_CONTENT)
printf(",\n");
if (hostgroup_list != NULL)
print_generic_error_message("It appears as though you do not have permission to view information for the host group you requested...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
else
print_generic_error_message("There are no host groups defined.", NULL, 0);
}
return;
}
/* displays status grid for a specific hostgroup */
int show_hostgroup_grid(hostgroup *temp_hostgroup) {
hostsmember *temp_member;
char *status_bg_class = "";
char *status = "";
char *host_status_class = "";
char *service_status_class = "";
host *temp_host;
service *temp_service;
hoststatus *temp_hoststatus;
servicestatus *temp_servicestatus = NULL;
statusdata *temp_status = NULL;
char *processed_string = NULL;
int odd = 0;
int current_item;
int json_start = TRUE;
int json_start2 = TRUE;
int partial_hosts = FALSE;
int service_found = FALSE;
/* make sure the user is authorized to view this hostgroup */
if (show_partial_hostgroups == FALSE && is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == FALSE)
return FALSE;
/* if we're showing partial hostgroups, find out if there will be any hosts that belong to the hostgroup */
if (show_partial_hostgroups == TRUE) {
for (temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
/* find the host status */
if ((temp_hoststatus = find_hoststatus(temp_member->host_name)) == NULL)
continue;
/* check if this hoststatus belongs to any hostgroup and has passed through all filters */
if (!(temp_hoststatus->added & STATUS_BELONGS_TO_HG))
continue;
partial_hosts = TRUE;
break;
}
}
/* if we're showing partial hostgroups, but there are no hosts to display, there's nothing to see here */
if (show_partial_hostgroups == TRUE && partial_hosts == FALSE)
return FALSE;
if (content_type == JSON_CONTENT) {
printf("{ \"hostgroup_name\": \"%s\",\n", json_encode(temp_hostgroup->group_name));
printf("\"members\": [ \n");
} else {
printf("
\n");
}
/* find all the hosts that belong to the hostgroup */
for (temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
/* find the host status */
if ((temp_hoststatus = find_hoststatus(temp_member->host_name)) == NULL)
continue;
/* check if this hoststatus belongs to any hostgroup and has passed through all filters */
if (!(temp_hoststatus->added & STATUS_BELONGS_TO_HG))
continue;
/* find the host... */
if ((temp_host = find_host(temp_member->host_name)) == NULL)
continue;
/* grab macros */
grab_host_macros_r(mac, temp_host);
if (odd == 1) {
status_bg_class = "Even";
odd = 0;
} else {
status_bg_class = "Odd";
odd = 1;
}
if (content_type != JSON_CONTENT)
printf("
\n", status_bg_class);
/* get the status of the host */
if (temp_hoststatus->status == HOST_DOWN) {
status = "DOWN";
host_status_class = "HOSTDOWN";
} else if (temp_hoststatus->status == HOST_UNREACHABLE) {
status = "UNREACHABLE";
host_status_class = "HOSTUNREACHABLE";
} else {
status = "OK";
host_status_class = status_bg_class;
}
if (content_type == JSON_CONTENT) {
if (json_start == FALSE)
printf(",\n");
json_start = FALSE;
printf("{ \"host_name\": \"%s\",\n", json_encode(temp_host->name));
printf("\"host_display_name\": \"%s\", ", (temp_host->display_name != NULL) ? json_encode(temp_host->display_name) : json_encode(temp_host->name));
printf("\"host_status\": \"%s\",\n", status);
printf("\"services\": [ \n");
} else {
printf("
\n");
return;
}
/******************************************************************/
/********* DROPDOWN MENU's FOR DETAILED VIEWS ;-) ***************/
/******************************************************************/
/* Display a table with the commands for checked checkboxes, for services */
void show_servicecommand_table(void) {
if (is_authorized_for_read_only(¤t_authdata) == FALSE) {
/* A new div for the command table */
printf("
Commands for checked services
\n");
/* DropDown menu */
printf("\n");
/* Print out the activator for the dropdown (which must be between the body tags */
printf("\n");
printf("
\n");
}
}
/* Display a table with the commands for checked checkboxes, for hosts */
void show_hostcommand_table(void) {
if (is_authorized_for_read_only(¤t_authdata) == FALSE) {
/* A new div for the command table */
printf("
Commands for checked host(s)
\n");
/* DropDown menu */
printf("\n");
/* Print out the activator for the dropdown (which must be between the body tags */
printf("\n");
printf("
\n");
}
}
/* The cake is a lie! */
/******************************************************************/
/************* print name for displayed list *********************/
/******************************************************************/
void print_displayed_names(int style) {
int i = 0;
int saved_escape_html_tags_var = FALSE;
if (style == DISPLAY_HOSTS) {
if (search_string != NULL) {
saved_escape_html_tags_var = escape_html_tags;
escape_html_tags = TRUE;
printf("Host/Services matching '%s'", (content_type == HTML_CONTENT) ? html_encode(search_string, FALSE) : search_string);
escape_html_tags = saved_escape_html_tags_var;
} else if (show_all_hosts == TRUE)
printf("All Hosts");
else {
if (num_req_hosts == 1)
printf("Host '%s'", html_encode(req_hosts[0].entry, TRUE));
else {
printf("Hosts ");
for (i = 0; req_hosts[i].entry != NULL; i++) {
if (i == 3) {
printf(", ...");
break;
}
if (i != 0) {
((num_req_hosts - i) == 1) ? printf(" and ") : printf(", ");
}
printf("'%s'", html_encode(req_hosts[i].entry, TRUE));
}
}
}
} else if (style == DISPLAY_SERVICEGROUPS) {
if (show_all_servicegroups == TRUE) {
printf("All Service Groups");
if (show_partial_servicegroups == TRUE)
printf(" (Partial Servicegroups Enabled)");
} else {
if (num_req_servicegroups == 1)
printf("Service Group '%s'", html_encode(req_servicegroups[0].entry, TRUE));
else {
printf("Service Groups ");
for (i = 0; req_servicegroups[i].entry != NULL; i++) {
if (i == 3) {
printf(", ...");
break;
}
if (i != 0) {
((num_req_servicegroups - i) == 1) ? printf(" and ") : printf(", ");
}
printf("'%s'", html_encode(req_servicegroups[i].entry, TRUE));
}
}
}
} else if (style == DISPLAY_HOSTGROUPS) {
if (show_all_hostgroups == TRUE) {
printf("All Host Groups");
if (show_partial_hostgroups == TRUE)
printf(" (Partial Hostgroups Enabled)");
} else {
if (num_req_hostgroups == 1)
printf("Host Group '%s'", html_encode(req_hostgroups[0].entry, TRUE));
else {
printf("Host Groups ");
for (i = 0; req_hostgroups[i].entry != NULL; i++) {
if (i == 3) {
printf(", ...");
break;
}
if (i != 0) {
((num_req_hostgroups - i) == 1) ? printf(" and ") : printf(", ");
}
printf("'%s'", html_encode(req_hostgroups[i].entry, TRUE));
}
}
}
}
return;
}
/******************************************************************/
/******************* pagination functions ************************/
/******************************************************************/
void status_page_num_selector(int local_result_start, int status_type) {
char link[MAX_INPUT_BUFFER] = "";
char stripped_query_string[MAX_INPUT_BUFFER] = "";
char *temp_buffer;
int total_pages = 1;
int current_page = 1;
// int next_page = 0;
int previous_page = 0;
int display_total = 0;
int display_from = 0;
int display_to = 0;
/* define base url */
strcat(link, STATUS_CGI);
/* get url options but filter out "limit" and "status" */
if (getenv("QUERY_STRING") != NULL && strcmp(getenv("QUERY_STRING"), "")) {
if(strlen(getenv("QUERY_STRING")) > MAX_INPUT_BUFFER) {
write_to_cgi_log("status_page_num_selector(): Query string exceeds max length. Returning without displaying page num selector.\n");
return;
}
strcpy(stripped_query_string, getenv("QUERY_STRING"));
strip_html_brackets(stripped_query_string);
/* check if concatenated strings exceed MAX_INPUT_BUFFER */
if (strlen(link) + strlen(stripped_query_string) + 1 > MAX_INPUT_BUFFER) {
write_to_cgi_log("status_page_num_selector(): Full query string exceeds max length. Returning without displaying page num selector.\n");
return;
}
for (temp_buffer = my_strtok(stripped_query_string, "&"); temp_buffer != NULL; temp_buffer = my_strtok(NULL, "&")) {
if (strncmp(temp_buffer, "limit=", 6) != 0 && strncmp(temp_buffer, "start=", 6) != 0) {
if (strstr(link, "?"))
strcat(link, "&");
else
strcat(link, "?");
strcat(link, temp_buffer);
}
}
}
/* calculate pages */
if (result_limit > 0 && (total_host_entries + total_service_entries) > 0) {
total_pages = ((total_host_entries + total_service_entries) / result_limit);
if (((total_host_entries + total_service_entries) % result_limit) != 0)
total_pages++;
current_page = (result_start / result_limit) + 1;
previous_page = (result_start - result_limit) > 0 ? (result_start - result_limit) : 0;
// next_page = (result_start + result_limit) > (total_host_entries + total_service_entries) ? result_start : (result_start + result_limit);
}
/* links page select elements and counters */
if ((group_style_type == STYLE_HOST_SERVICE_DETAIL && status_type == SERVICE_STATUS) || group_style_type != STYLE_HOST_SERVICE_DETAIL) {
printf("
\n", display_from, display_to, display_total, (status_type == SERVICE_STATUS) ? "Services" : "Hosts");
/* copy page navigation to top of the page */
if ((group_style_type == STYLE_HOST_SERVICE_DETAIL && status_type == SERVICE_STATUS) || group_style_type != STYLE_HOST_SERVICE_DETAIL) {
printf("\n");
}
return;
}
icinga-1.10.3/cgi/statusmap.c 0000664 0000000 0000000 00000272317 12276402000 0015762 0 ustar 00root root 0000000 0000000 /*****************************************************************************
*
* STATUSMAP.C - Icinga Network Status Map CGI
*
* Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org)
* Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
*
* Description:
*
* This CGI will create a map of all hosts that are being monitored on your
* network.
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*****************************************************************************/
#include "../include/config.h"
#include "../include/common.h"
#include "../include/objects.h"
#include "../include/macros.h"
#include "../include/statusdata.h"
#include "../include/cgiutils.h"
#include "../include/getcgi.h"
#include "../include/cgiauth.h"
#include /* Boutell's GD library function */
#include /* GD library small font definition */
static icinga_macros *mac;
/*#define DEBUG*/
extern char main_config_file[MAX_FILENAME_LENGTH];
extern char physical_images_path[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH];
extern char url_logo_images_path[MAX_FILENAME_LENGTH];
extern host *host_list;
extern hostgroup *hostgroup_list;
extern service *service_list;
extern hoststatus *hoststatus_list;
extern servicestatus *servicestatus_list;
extern char *statusmap_background_image;
extern int default_statusmap_layout_method;
extern int suppress_maintenance_downtime;
#define DEFAULT_NODE_WIDTH 40
#define DEFAULT_NODE_HEIGHT 65
#define DEFAULT_NODE_VSPACING 15
#define DEFAULT_NODE_HSPACING 45
#define DEFAULT_PROXIMITY_WIDTH 1000
#define DEFAULT_PROXIMITY_HEIGHT 800
#define MINIMUM_PROXIMITY_WIDTH 250
#define MINIMUM_PROXIMITY_HEIGHT 200
#define COORDS_WARNING_WIDTH 650
#define COORDS_WARNING_HEIGHT 60
#define CIRCULAR_DRAWING_RADIUS 100
#define LAYOUT_USER_SUPPLIED 0
#define LAYOUT_SUBLAYERS 1
#define LAYOUT_COLLAPSED_TREE 2
#define LAYOUT_BALANCED_TREE 3
#define LAYOUT_CIRCULAR 4
#define LAYOUT_CIRCULAR_MARKUP 5
#define LAYOUT_CIRCULAR_BALLOON 6
typedef struct layer_struct {
char *layer_name;
struct layer_struct *next;
} layer;
int process_cgivars(void);
void display_page_header(void);
void display_map(void);
void calculate_host_coords(void);
void calculate_total_image_bounds(void);
void calculate_canvas_bounds(void);
void calculate_canvas_bounds_from_host(char *);
void calculate_scaling_factor(void);
void find_eligible_hosts(void);
void load_background_image(void);
void draw_background_image(void);
void draw_background_extras(void);
void draw_host_links(void);
void draw_hosts(void);
void draw_host_text(char *, int, int);
void draw_text(char *, int, int, int);
void write_host_popup_text(host *);
int initialize_graphics(void);
gdImagePtr load_image_from_file(char *);
void write_graphics(void);
void cleanup_graphics(void);
void draw_line(int, int, int, int, int);
void draw_dotted_line(int, int, int, int, int);
void draw_dashed_line(int, int, int, int, int);
int is_host_in_layer_list(host *);
int add_layer(char *);
void free_layer_list(void);
void print_layer_url(int);
int number_of_host_layer_members(host *, int);
int max_child_host_layer_members(host *);
int host_child_depth_separation(host *, host *);
int max_child_host_drawing_width(host *);
int number_of_host_services(host *);
int has_host_childs_in_visible_layer(host *);
void calculate_balanced_tree_coords(host *, int, int);
void calculate_circular_coords(void);
void calculate_circular_layer_coords(host *, double, double, int, int);
void draw_circular_markup(void);
void draw_circular_layer_markup(host *, double, double, int, int);
char physical_logo_images_path[MAX_FILENAME_LENGTH];
authdata current_authdata;
extern int content_type;
gdImagePtr unknown_logo_image = NULL;
gdImagePtr logo_image = NULL;
gdImagePtr map_image = NULL;
gdImagePtr background_image = NULL;
int color_white = 0;
int color_black = 0;
int color_red = 0;
int color_lightred = 0;
int color_green = 0;
int color_lightgreen = 0;
int color_pink = 0;
int color_blue = 0;
int color_yellow = 0;
int color_orange = 0;
int color_grey = 0;
int color_lightgrey = 0;
int color_transparency_index = 0;
extern int color_transparency_index_r;
extern int color_transparency_index_g;
extern int color_transparency_index_b;
extern int embedded;
extern int refresh;
extern int display_header;
extern int daemon_check;
int display_popups = TRUE;
int use_links = TRUE;
int use_text = TRUE;
int use_highlights = TRUE;
int user_supplied_canvas = FALSE;
int user_supplied_scaling = FALSE;
int layout_method = LAYOUT_USER_SUPPLIED;
int proximity_width = DEFAULT_PROXIMITY_WIDTH;
int proximity_height = DEFAULT_PROXIMITY_HEIGHT;
int coordinates_were_specified = FALSE; /* were any coordinates specified in extended host information entries? */
int scaled_image_width = 0; /* size of the image actually displayed on the screen (after scaling) */
int scaled_image_height = 0;
int canvas_width = 0; /* actual size of the image (or portion thereof) that we are drawing */
int canvas_height = 0;
int total_image_width = 0; /* actual size of the image that would be created if we drew all hosts */
int total_image_height = 0;
int max_image_width = 0; /* max image size the user wants (scaled) */
int max_image_height = 0;
double scaling_factor = 1.0; /* scaling factor to use */
double user_scaling_factor = 1.0; /* user-supplied scaling factor */
int background_image_width = 0;
int background_image_height = 0;
int max_circular_markup_x = 0;
int min_circular_markup_x = 0;
int max_circular_markup_y = 0;
int min_circular_markup_y = 0;
int canvas_x = 0; /* upper left coords of drawing canvas */
int canvas_y = 0;
int bottom_margin = 0;
int draw_child_links = FALSE;
int draw_parent_links = FALSE;
int draw_nagios_icon = FALSE; /* should we drawn the Icinga process icon? */
int nagios_icon_x = 0; /* coords of Icinga icon */
int nagios_icon_y = 0;
extern hoststatus *hoststatus_list;
extern time_t program_start;
layer *layer_list = NULL;
int exclude_layers = TRUE;
int all_layers = FALSE;
int show_all_hosts = TRUE;
char *host_name = "all";
int CGI_ID = STATUSMAP_CGI_ID;
int main(int argc, char **argv) {
int result;
mac = get_global_macros();
/* reset internal variables */
reset_cgi_vars();
/* read the CGI configuration file */
result = read_cgi_config_file(get_cgi_config_location());
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(get_cgi_config_location(), ERROR_CGI_CFG_FILE, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* defaults from CGI config file */
layout_method = default_statusmap_layout_method;
/* get the arguments passed in the URL */
process_cgivars();
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(main_config_file, ERROR_CGI_MAIN_CFG, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(NULL, ERROR_CGI_OBJECT_DATA, FALSE);
document_footer(CGI_ID);
return ERROR;
}
/* read all status data */
result = read_all_status_data(main_config_file, READ_ALL_STATUS_DATA);
if (result == ERROR && daemon_check == TRUE) {
document_header(CGI_ID, FALSE, "Error");
print_error(NULL, ERROR_CGI_STATUS_DATA, FALSE);
document_footer(CGI_ID);
free_memory();
return ERROR;
}
/* initialize macros */
init_macros();
document_header(CGI_ID, TRUE, "Network Map");
/* get authentication information */
get_authentication_information(¤t_authdata);
/* display the network map... */
display_map();
document_footer(CGI_ID);
/* free all allocated memory */
free_memory();
free_layer_list();
return OK;
}
int process_cgivars(void) {
char **variables;
int error = FALSE;
int x;
variables = getcgivars();
for (x = 0; variables[x] != NULL; x++) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */
if (strlen(variables[x]) >= MAX_INPUT_BUFFER - 1)
continue;
/* we found the host argument */
else if (!strcmp(variables[x], "host")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((host_name = (char *)strdup(variables[x])) == NULL)
host_name = "all";
else
strip_html_brackets(host_name);
if (!strcmp(host_name, "all"))
show_all_hosts = TRUE;
else
show_all_hosts = FALSE;
}
/* we found the image creation option */
else if (!strcmp(variables[x], "createimage")) {
content_type = IMAGE_CONTENT;
}
/* we found the embed option */
else if (!strcmp(variables[x], "embedded"))
embedded = TRUE;
/* we found the noheader option */
else if (!strcmp(variables[x], "noheader"))
display_header = FALSE;
/* we found the canvas origin */
else if (!strcmp(variables[x], "canvas_x")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
canvas_x = atoi(variables[x]);
user_supplied_canvas = TRUE;
} else if (!strcmp(variables[x], "canvas_y")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
canvas_y = atoi(variables[x]);
user_supplied_canvas = TRUE;
}
/* we found the canvas size */
else if (!strcmp(variables[x], "canvas_width")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
canvas_width = atoi(variables[x]);
user_supplied_canvas = TRUE;
} else if (!strcmp(variables[x], "canvas_height")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
canvas_height = atoi(variables[x]);
user_supplied_canvas = TRUE;
} else if (!strcmp(variables[x], "proximity_width")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
proximity_width = atoi(variables[x]);
if (proximity_width < 0)
proximity_width = DEFAULT_PROXIMITY_WIDTH;
} else if (!strcmp(variables[x], "proximity_height")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
proximity_height = atoi(variables[x]);
if (proximity_height < 0)
proximity_height = DEFAULT_PROXIMITY_HEIGHT;
}
/* we found the scaling factor */
else if (!strcmp(variables[x], "scaling_factor")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
user_scaling_factor = strtod(variables[x], NULL);
if (user_scaling_factor > 0.0)
user_supplied_scaling = TRUE;
}
/* we found the max image size */
else if (!strcmp(variables[x], "max_width")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
max_image_width = atoi(variables[x]);
} else if (!strcmp(variables[x], "max_height")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
max_image_height = atoi(variables[x]);
}
/* we found the layout method option */
else if (!strcmp(variables[x], "layout")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
layout_method = atoi(variables[x]);
}
/* we found the no links argument*/
else if (!strcmp(variables[x], "nolinks"))
use_links = FALSE;
/* we found the no text argument*/
else if (!strcmp(variables[x], "notext"))
use_text = FALSE;
/* we found the no highlights argument*/
else if (!strcmp(variables[x], "nohighlights"))
use_highlights = FALSE;
/* we found the no popups argument*/
else if (!strcmp(variables[x], "nopopups"))
display_popups = FALSE;
/* we found the layer inclusion/exclusion argument */
else if (!strcmp(variables[x], "layermode")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "include"))
exclude_layers = FALSE;
else
exclude_layers = TRUE;
}
/* we found the layer argument */
else if (!strcmp(variables[x], "layer")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
strip_html_brackets(variables[x]);
add_layer(variables[x]);
}
/* we found the pause option */
else if (!strcmp(variables[x], "paused"))
refresh = FALSE;
/* we found the nodaemoncheck option */
else if (!strcmp(variables[x], "nodaemoncheck"))
daemon_check = FALSE;
}
/* free memory allocated to the CGI variables */
free_cgivars(variables);
return error;
}
/* top of page */
void display_page_header(void) {
char temp_buffer[MAX_INPUT_BUFFER];
int zoom;
int zoom_width, zoom_height;
int zoom_width_granularity = 0;
int zoom_height_granularity = 0;
int current_zoom_granularity = 0;
hostgroup *temp_hostgroup;
layer *temp_layer;
int found = 0;
if (content_type != HTML_CONTENT)
return;
if (display_header == TRUE) {
/* begin top table */
printf("
\n");
printf("
\n");
/* left column of the first row */
printf("
\n");
if (show_all_hosts == TRUE)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Network Map For All Hosts");
else
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Network Map For Host %s", host_name);
temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
display_info_table(temp_buffer, ¤t_authdata, daemon_check);
printf("
\n");
}
return;
}
/* top-level map generation... */
void display_map(void) {
load_background_image();
calculate_host_coords();
calculate_total_image_bounds();
calculate_canvas_bounds();
calculate_scaling_factor();
find_eligible_hosts();
/* display page header */
display_page_header();
initialize_graphics();
draw_background_image();
draw_background_extras();
draw_host_links();
if (content_type == HTML_CONTENT)
printf("\n");
write_graphics();
cleanup_graphics();
/* write the URL location for the image we just generated - the web browser will come and get it... */
if (content_type == HTML_CONTENT) {
printf("
");
/* show the status of the host (maintenance, pending, up, down, or unreachable) */
/* first, we mark it as maintenance if that is preferred */
if (suppress_maintenance_downtime == TRUE && temp_status->scheduled_downtime_depth > 0) {
if (temp_status->status == HOST_UP)
printf("Up (Maintenance)");
else if (temp_status->status == HOST_DOWN)
printf("Down (Maintenance)");
else if (temp_status->status == HOST_UNREACHABLE)
printf("Unreachable (Maintenance)");
else if (temp_status->status == HOST_PENDING)
printf("Pending (Maintenance)");
else //catch any other state (just in case)
printf("Maintenance");
if (temp_status->problem_has_been_acknowledged == TRUE) //somewhat meaningless in this context, but possible
printf(" (Acknowledged)");
printf("");
} else if (temp_status->status == HOST_DOWN) {
printf("Down");
if (temp_status->problem_has_been_acknowledged == TRUE)
printf(" (Acknowledged)");
printf("");
} else if (temp_status->status == HOST_UNREACHABLE) {
printf("Unreachable");
if (temp_status->problem_has_been_acknowledged == TRUE)
printf(" (Acknowledged)");
printf("");
} else if (temp_status->status == HOST_UP) {
printf("Up");
} else if (temp_status->status == HOST_PENDING)
printf("Pending");
printf("
");
printf(" Services: ");
service_totals = get_servicestatus_count(hst->name, SERVICE_OK);
if (service_totals > 0)
printf("- %d ok ", service_totals);
service_totals = get_servicestatus_count(hst->name, SERVICE_CRITICAL);
if (service_totals > 0)
printf("- %d critical ", service_totals);
service_totals = get_servicestatus_count(hst->name, SERVICE_WARNING);
if (service_totals > 0)
printf("- %d warning ", service_totals);
service_totals = get_servicestatus_count(hst->name, SERVICE_UNKNOWN);
if (service_totals > 0)
printf("- %d unknown ", service_totals);
service_totals = get_servicestatus_count(hst->name, SERVICE_PENDING);
if (service_totals > 0)
printf("- %d pending ", service_totals);
return;
}
/* draws a solid line */
void draw_line(int x1, int y1, int x2, int y2, int color) {
if (content_type == HTML_CONTENT)
return;
gdImageLine(map_image, x1, y1, x2, y2, color);
return;
}
/* draws a dotted line */
void draw_dotted_line(int x1, int y1, int x2, int y2, int color) {
int styleDotted[12];
styleDotted[0] = color;
styleDotted[1] = gdTransparent;
styleDotted[2] = gdTransparent;
styleDotted[3] = gdTransparent;
styleDotted[4] = gdTransparent;
styleDotted[5] = gdTransparent;
styleDotted[6] = color;
styleDotted[7] = gdTransparent;
styleDotted[8] = gdTransparent;
styleDotted[9] = gdTransparent;
styleDotted[10] = gdTransparent;
styleDotted[11] = gdTransparent;
/* sets current style to a dashed line */
gdImageSetStyle(map_image, styleDotted, 12);
/* draws a line (dotted) */
gdImageLine(map_image, x1, y1, x2, y2, gdStyled);
return;
}
/* draws a dashed line */
void draw_dashed_line(int x1, int y1, int x2, int y2, int color) {
int styleDashed[12];
styleDashed[0] = color;
styleDashed[1] = color;
styleDashed[2] = color;
styleDashed[3] = color;
styleDashed[4] = gdTransparent;
styleDashed[5] = gdTransparent;
styleDashed[6] = color;
styleDashed[7] = color;
styleDashed[8] = color;
styleDashed[9] = color;
styleDashed[10] = gdTransparent;
styleDashed[11] = gdTransparent;
/* sets current style to a dashed line */
gdImageSetStyle(map_image, styleDashed, 12);
/* draws a line (dashed) */
gdImageLine(map_image, x1, y1, x2, y2, gdStyled);
return;
}
/******************************************************************/
/*********************** GRAPHICS FUNCTIONS ***********************/
/******************************************************************/
/* initialize graphics */
int initialize_graphics(void) {
char image_input_file[MAX_INPUT_BUFFER];
if (content_type == HTML_CONTENT)
return ERROR;
/* allocate buffer for storing image */
#ifndef HAVE_GDIMAGECREATETRUECOLOR
map_image = gdImageCreate(canvas_width, canvas_height);
#else
map_image = gdImageCreateTrueColor(canvas_width, canvas_height);
#endif
if (map_image == NULL)
return ERROR;
/* allocate colors used for drawing */
color_white = gdImageColorAllocate(map_image, 255, 255, 255);
color_black = gdImageColorAllocate(map_image, 0, 0, 0);
color_grey = gdImageColorAllocate(map_image, 128, 128, 128);
color_lightgrey = gdImageColorAllocate(map_image, 210, 210, 210);
color_red = gdImageColorAllocate(map_image, 255, 0, 0);
color_lightred = gdImageColorAllocate(map_image, 215, 175, 175);
color_green = gdImageColorAllocate(map_image, 0, 175, 0);
color_lightgreen = gdImageColorAllocate(map_image, 210, 255, 215);
color_pink = gdImageColorAllocate(map_image, 224, 102, 255);
color_blue = gdImageColorAllocate(map_image, 0, 0, 255);
color_yellow = gdImageColorAllocate(map_image, 255, 255, 0);
color_orange = gdImageColorAllocate(map_image, 255, 100, 25);
color_transparency_index = gdImageColorAllocate(map_image, color_transparency_index_r, color_transparency_index_g, color_transparency_index_b);
/* set transparency index */
#ifndef HAVE_GDIMAGECREATETRUECOLOR
gdImageColorTransparent(map_image, color_white);
#else
gdImageColorTransparent(map_image, color_transparency_index);
/* set background */
gdImageFill(map_image, 0, 0, color_transparency_index);
#endif
/* make sure the graphic is interlaced */
gdImageInterlace(map_image, 1);
/* get the path where we will be reading logo images from (GD2 format)... */
snprintf(physical_logo_images_path, sizeof(physical_logo_images_path) - 1, "%slogos/", physical_images_path);
physical_logo_images_path[sizeof(physical_logo_images_path) - 1] = '\x0';
/* load the unknown icon to use for hosts that don't have pretty images associated with them... */
snprintf(image_input_file, sizeof(image_input_file) - 1, "%s%s", physical_logo_images_path, UNKNOWN_GD2_ICON);
image_input_file[sizeof(image_input_file) - 1] = '\x0';
unknown_logo_image = load_image_from_file(image_input_file);
return OK;
}
/* loads a graphic image (GD2, JPG or PNG) from file into memory */
gdImagePtr load_image_from_file(char *filename) {
FILE *fp;
gdImagePtr im = NULL;
char *ext;
/* make sure we were passed a file name */
if (filename == NULL)
return NULL;
/* find the file extension */
if ((ext = rindex(filename, '.')) == NULL)
return NULL;
/* open the file for reading (binary mode) */
fp = fopen(filename, "rb");
if (fp == NULL)
return NULL;
/* attempt to read files in various formats */
if (!strcasecmp(ext, ".png"))
im = gdImageCreateFromPng(fp);
else if (!strcasecmp(ext, ".jpg") || !strcasecmp(ext, ".jpeg"))
im = gdImageCreateFromJpeg(fp);
else if (!strcasecmp(ext, ".xbm"))
im = gdImageCreateFromXbm(fp);
else if (!strcasecmp(ext, ".gd2"))
im = gdImageCreateFromGd2(fp);
else if (!strcasecmp(ext, ".gd"))
im = gdImageCreateFromGd(fp);
/* fall back to GD2 image format */
else
im = gdImageCreateFromGd2(fp);
/* close the file */
fclose(fp);
return im;
}
/* draw graphics */
void write_graphics(void) {
FILE *image_output_file = NULL;
if (content_type == HTML_CONTENT)
return;
/* use STDOUT for writing the image data... */
image_output_file = stdout;
/* write the image out in PNG format */
gdImagePng(map_image, image_output_file);
/* or we could write the image out in JPG format... */
/*gdImageJpeg(map_image,image_output_file,99);*/
return;
}
/* cleanup graphics resources */
void cleanup_graphics(void) {
if (content_type == HTML_CONTENT)
return;
/* free memory allocated to image */
gdImageDestroy(map_image);
return;
}
/******************************************************************/
/************************* MISC FUNCTIONS *************************/
/******************************************************************/
/* adds a layer to the list in memory */
int add_layer(char *group_name) {
layer *new_layer;
if (group_name == NULL)
return ERROR;
/* allocate memory for a new layer */
new_layer = (layer *)malloc(sizeof(layer));
if (new_layer == NULL)
return ERROR;
new_layer->layer_name = (char *)malloc(strlen(group_name) + 1);
if (new_layer->layer_name == NULL) {
free(new_layer);
return ERROR;
}
strcpy(new_layer->layer_name, group_name);
/* add new layer to head of layer list */
new_layer->next = layer_list;
layer_list = new_layer;
return OK;
}
/* frees memory allocated to the layer list */
void free_layer_list(void) {
layer *this_layer;
layer *next_layer;
return;
for (this_layer = layer_list; layer_list != NULL; this_layer = next_layer) {
next_layer = this_layer->next;
free(this_layer->layer_name);
free(this_layer);
}
return;
}
/* checks to see if a host is in the layer list */
int is_host_in_layer_list(host *hst) {
hostgroup *temp_hostgroup;
layer *temp_layer;
if (hst == NULL)
return FALSE;
/* check each layer... */
for (temp_layer = layer_list; temp_layer != NULL; temp_layer = temp_layer->next) {
/* find the hostgroup */
temp_hostgroup = find_hostgroup(temp_layer->layer_name);
if (temp_hostgroup == NULL)
continue;
/* is the requested host a member of the hostgroup/layer? */
if (is_host_member_of_hostgroup(temp_hostgroup, hst) == TRUE)
return TRUE;
}
return FALSE;
}
/* print layer url info */
void print_layer_url(int get_method) {
layer *temp_layer;
for (temp_layer = layer_list; temp_layer != NULL; temp_layer = temp_layer->next) {
if (get_method == TRUE)
printf("&layer=%s", escape_string(temp_layer->layer_name));
else
printf("\n", escape_string(temp_layer->layer_name));
}
if (get_method == TRUE)
printf("&layermode=%s", (exclude_layers == TRUE) ? "exclude" : "include");
else
printf("\n", (exclude_layers == TRUE) ? "exclude" : "include");
return;
}
/******************************************************************/
/************************ UTILITY FUNCTIONS ***********************/
/******************************************************************/
/* calculates how many "layers" separate parent and child - used by collapsed tree layout method */
int host_child_depth_separation(host *parent, host *child) {
int this_depth = 0;
int min_depth = 0;
int have_min_depth = FALSE;
host *temp_host;
if (child == NULL)
return -1;
if (parent == child)
return 0;
if (is_host_immediate_child_of_host(parent, child) == TRUE)
return 1;
for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
if (is_host_immediate_child_of_host(parent, temp_host) == TRUE) {
this_depth = host_child_depth_separation(temp_host, child);
if (this_depth >= 0 && (have_min_depth == FALSE || (have_min_depth == TRUE && (this_depth < min_depth)))) {
have_min_depth = TRUE;
min_depth = this_depth;
}
}
}
if (have_min_depth == FALSE)
return -1;
else
return min_depth + 1;
}
/* calculates how many hosts reside on a specific "layer" - used by collapsed tree layout method */
int number_of_host_layer_members(host *parent, int layer) {
int current_layer;
int layer_members = 0;
host *temp_host;
for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
current_layer = host_child_depth_separation(parent, temp_host);
if (current_layer == layer)
layer_members++;
}
return layer_members;
}
/* calculate max number of members on all "layers" beneath and including parent host - used by collapsed tree layout method */
int max_child_host_layer_members(host *parent) {
int current_layer;
int max_members = 1;
int current_members = 0;
for (current_layer = 1;; current_layer++) {
current_members = number_of_host_layer_members(parent, current_layer);
if (current_members <= 0)
break;
if (current_members > max_members)
max_members = current_members;
}
return max_members;
}
/* calculate max drawing width for host and children - used by balanced tree layout method */
int max_child_host_drawing_width(host *parent) {
host *temp_host;
int child_width = 0;
int in_layer_list = FALSE;
for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
in_layer_list = is_host_in_layer_list(temp_host);
if ((in_layer_list == TRUE && exclude_layers == TRUE) || (in_layer_list == FALSE && exclude_layers == FALSE)) {
if (has_host_childs_in_visible_layer(temp_host) == FALSE)
continue;
}
if (is_host_immediate_child_of_host(parent, temp_host) == TRUE)
child_width += max_child_host_drawing_width(temp_host);
}
/* no children, so set width to 1 for this host */
if (child_width <= 0)
return 1;
return child_width;
}
/* calculates number of services associated with a particular service */
int number_of_host_services(host *hst) {
service *temp_service;
int total_services = 0;
if (hst == NULL)
return 0;
/* check all the services */
for (temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) {
if (!strcmp(temp_service->host_name, hst->name))
total_services++;
}
return total_services;
}
/******************************************************************/
/***************** COORDINATE CALCULATION FUNCTIONS ***************/
/******************************************************************/
/* calculates coords of a host's children - used by balanced tree layout method */
void calculate_balanced_tree_coords(host *parent, int x, int y) {
int parent_drawing_width;
int start_drawing_x;
int current_drawing_x;
int this_drawing_width;
host *temp_host;
/* calculate total drawing width of parent host */
parent_drawing_width = max_child_host_drawing_width(parent);
/* calculate starting x coord */
start_drawing_x = x - (((DEFAULT_NODE_WIDTH * parent_drawing_width) + (DEFAULT_NODE_HSPACING * (parent_drawing_width - 1))) / 2);
current_drawing_x = start_drawing_x;
/* calculate coords for children */
for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
if (is_host_immediate_child_of_host(parent, temp_host) == TRUE) {
/* get drawing width of child host */
this_drawing_width = max_child_host_drawing_width(temp_host);
temp_host->x_2d = current_drawing_x + (((DEFAULT_NODE_WIDTH * this_drawing_width) + (DEFAULT_NODE_HSPACING * (this_drawing_width - 1))) / 2);
temp_host->y_2d = y + DEFAULT_NODE_HEIGHT + DEFAULT_NODE_VSPACING;
temp_host->have_2d_coords = TRUE;
temp_host->should_be_drawn = TRUE;
current_drawing_x += (this_drawing_width * DEFAULT_NODE_WIDTH) + ((this_drawing_width - 1) * DEFAULT_NODE_HSPACING) + DEFAULT_NODE_HSPACING;
/* recurse into child host ... */
calculate_balanced_tree_coords(temp_host, temp_host->x_2d, temp_host->y_2d);
}
}
return;
}
/* calculate coords of all hosts in circular layout method */
void calculate_circular_coords(void) {
int min_x = 0;
int min_y = 0;
host *temp_host;
/* calculate all host coords, starting with first layer */
max_circular_markup_x = 0;
min_circular_markup_x = 0;
max_circular_markup_y = 0;
min_circular_markup_y = 0;
calculate_circular_layer_coords(NULL, 0.0, 360.0, 1, CIRCULAR_DRAWING_RADIUS);
min_x = min_circular_markup_x;
min_y = min_circular_markup_y;
/* adjust all calculated coords so none are negative in x or y axis... */
/* calculate min x, y coords */
for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
if (temp_host->x_2d < min_x)
min_x = temp_host->x_2d;
if (temp_host->y_2d < min_y)
min_y = temp_host->y_2d;
}
/* offset all drawing coords by the min x,y coords we found */
for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
if (min_x < 0)
temp_host->x_2d -= min_x;
if (min_y < 0)
temp_host->y_2d -= min_y;
}
if (min_x < 0)
nagios_icon_x -= min_x;
if (min_y < 0)
nagios_icon_y -= min_y;
for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
temp_host->x_2d += (DEFAULT_NODE_WIDTH / 2);
temp_host->y_2d += (DEFAULT_NODE_HEIGHT / 2);
}
nagios_icon_x += (DEFAULT_NODE_WIDTH / 2);
nagios_icon_y += (DEFAULT_NODE_HEIGHT / 2);
return;
}
/* calculates coords of all hosts in a particular "layer" in circular layout method */
void calculate_circular_layer_coords(host *parent, double start_angle, double useable_angle, int layer, int radius) {
int parent_drawing_width = 0;
int this_drawing_width = 0;
int immediate_children = 0;
double current_drawing_angle = 0.0;
double this_drawing_angle = 0.0;
double available_angle = 0.0;
double clipped_available_angle = 0.0;
double x_coord = 0.0;
double y_coord = 0.0;
double tmp_x_coord;
double tmp_y_coord;
double sampling = 0.0;
int i = 0;
host *temp_host;
int in_layer_list = FALSE;
/* get the total number of immediate children to this host */
immediate_children = number_of_immediate_child_hosts(parent);
for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
if (parent == temp_host)
continue;
if (is_host_immediate_child_of_host(parent, temp_host) == TRUE) {
in_layer_list = is_host_in_layer_list(temp_host);
if ((in_layer_list == TRUE && exclude_layers == TRUE) || (in_layer_list == FALSE && exclude_layers == FALSE)) {
if (has_host_childs_in_visible_layer(temp_host) == FALSE)
immediate_children--;
}
}
}
/* bail out if we're done */
if (immediate_children <= 0)
return;
/* calculate total drawing "width" of parent host */
parent_drawing_width = max_child_host_drawing_width(parent);
/* calculate initial drawing angle */
current_drawing_angle = start_angle;
/* calculate coords for children */
for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
if (is_host_immediate_child_of_host(parent, temp_host) == TRUE) {
in_layer_list = is_host_in_layer_list(temp_host);
if ((in_layer_list == TRUE && exclude_layers == TRUE) || (in_layer_list == FALSE && exclude_layers == FALSE)) {
if (has_host_childs_in_visible_layer(temp_host) == FALSE)
continue;
}
/* get drawing width of child host */
this_drawing_width = max_child_host_drawing_width(temp_host);
/* calculate angle this host gets for drawing */
available_angle = useable_angle * ((double)this_drawing_width / (double)parent_drawing_width);
/* clip available angle if necessary */
/* this isn't really necessary, but helps keep things looking a bit more sane with less potential connection crossover */
clipped_available_angle = 360.0 / layer;
if (available_angle < clipped_available_angle)
clipped_available_angle = available_angle;
/* calculate the exact angle at which we should draw this child */
this_drawing_angle = current_drawing_angle + (available_angle / 2.0);
/* compensate for angle overflow */
while (this_drawing_angle >= 360.0)
this_drawing_angle -= 360.0;
while (this_drawing_angle < 0.0)
this_drawing_angle += 360.0;
/* calculate drawing coords of this host using good ol' geometry... */
x_coord = -(sin(-this_drawing_angle * (M_PI / 180.0)) * radius);
y_coord = -(sin((90 + this_drawing_angle) * (M_PI / 180.0)) * radius);
temp_host->x_2d = (int)x_coord;
temp_host->y_2d = (int)y_coord;
temp_host->have_2d_coords = TRUE;
temp_host->should_be_drawn = TRUE;
/* calculate drawing coords of "leftmost" divider using good ol' geometry... */
for (sampling = 0; sampling <= 1; sampling += 0.5) {
for (i = -1; i < 2; i += 2) {
tmp_x_coord = -(sin((-(current_drawing_angle + (sampling * available_angle))) * (M_PI / 180.0)) * (radius + i * (CIRCULAR_DRAWING_RADIUS / 2)));
tmp_y_coord = -(sin((90 + current_drawing_angle + (sampling * available_angle)) * (M_PI / 180.0)) * (radius + i * (CIRCULAR_DRAWING_RADIUS / 2)));
if (tmp_x_coord < min_circular_markup_x)
min_circular_markup_x = tmp_x_coord;
if (tmp_x_coord > max_circular_markup_x)
max_circular_markup_x = tmp_x_coord;
if (tmp_y_coord < min_circular_markup_y)
min_circular_markup_y = tmp_y_coord;
if (tmp_y_coord > max_circular_markup_y)
max_circular_markup_y = tmp_y_coord;
}
}
/* recurse into child host ... */
calculate_circular_layer_coords(temp_host, current_drawing_angle + ((available_angle - clipped_available_angle) / 2), clipped_available_angle, layer + 1, radius + CIRCULAR_DRAWING_RADIUS);
/* increment current drawing angle */
current_drawing_angle += available_angle;
}
}
return;
}
/* draws background "extras" for all hosts in circular markup layout */
void draw_circular_markup(void) {
/* calculate all host sections, starting with first layer */
draw_circular_layer_markup(NULL, 0.0, 360.0, 1, CIRCULAR_DRAWING_RADIUS);
return;
}
/* draws background "extras" for all hosts in a particular "layer" in circular markup layout */
void draw_circular_layer_markup(host *parent, double start_angle, double useable_angle, int layer, int radius) {
int parent_drawing_width = 0;
int this_drawing_width = 0;
int immediate_children = 0;
double current_drawing_angle = 0.0;
double available_angle = 0.0;
double clipped_available_angle = 0.0;
double x_coord[4] = {0.0, 0.0, 0.0, 0.0};
double y_coord[4] = {0.0, 0.0, 0.0, 0.0};
hoststatus *temp_hoststatus;
host *temp_host;
int x_offset = 0;
int y_offset = 0;
int center_x = 0;
int center_y = 0;
int bgcolor = 0;
double arc_start_angle = 0.0;
double arc_end_angle = 0.0;
int translated_x = 0;
int translated_y = 0;
int in_layer_list = FALSE;
/* get the total number of immediate children to this host */
immediate_children = number_of_immediate_child_hosts(parent);
for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
if (parent == temp_host)
continue;
if (is_host_immediate_child_of_host(parent, temp_host) == TRUE) {
in_layer_list = is_host_in_layer_list(temp_host);
if ((in_layer_list == TRUE && exclude_layers == TRUE) || (in_layer_list == FALSE && exclude_layers == FALSE)) {
if (has_host_childs_in_visible_layer(temp_host) == FALSE)
immediate_children--;
}
}
}
/* bail out if we're done */
if (immediate_children <= 0)
return;
/* calculate total drawing "width" of parent host */
parent_drawing_width = max_child_host_drawing_width(parent);
/* calculate initial drawing angle */
current_drawing_angle = start_angle;
/* calculate coords for children */
for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
if (is_host_immediate_child_of_host(parent, temp_host) == TRUE) {
in_layer_list = is_host_in_layer_list(temp_host);
if ((in_layer_list == TRUE && exclude_layers == TRUE) || (in_layer_list == FALSE && exclude_layers == FALSE)) {
if (has_host_childs_in_visible_layer(temp_host) == FALSE)
continue;
}
/* get drawing width of child host */
this_drawing_width = max_child_host_drawing_width(temp_host);
/* calculate angle this host gets for drawing */
available_angle = useable_angle * ((double)this_drawing_width / (double)parent_drawing_width);
/* clip available angle if necessary */
/* this isn't really necessary, but helps keep things looking a bit more sane with less potential connection crossover */
clipped_available_angle = 360.0 / layer;
if (available_angle < clipped_available_angle)
clipped_available_angle = available_angle;
/* calculate drawing coords of "leftmost" divider using good ol' geometry... */
x_coord[0] = -(sin(-current_drawing_angle * (M_PI / 180.0)) * (radius - (CIRCULAR_DRAWING_RADIUS / 2)));
y_coord[0] = -(sin((90 + current_drawing_angle) * (M_PI / 180.0)) * (radius - (CIRCULAR_DRAWING_RADIUS / 2)));
x_coord[1] = -(sin(-current_drawing_angle * (M_PI / 180.0)) * (radius + (CIRCULAR_DRAWING_RADIUS / 2)));
y_coord[1] = -(sin((90 + current_drawing_angle) * (M_PI / 180.0)) * (radius + (CIRCULAR_DRAWING_RADIUS / 2)));
/* calculate drawing coords of "rightmost" divider using good ol' geometry... */
x_coord[2] = -(sin((-(current_drawing_angle + available_angle)) * (M_PI / 180.0)) * (radius - (CIRCULAR_DRAWING_RADIUS / 2)));
y_coord[2] = -(sin((90 + current_drawing_angle + available_angle) * (M_PI / 180.0)) * (radius - (CIRCULAR_DRAWING_RADIUS / 2)));
x_coord[3] = -(sin((-(current_drawing_angle + available_angle)) * (M_PI / 180.0)) * (radius + (CIRCULAR_DRAWING_RADIUS / 2)));
y_coord[3] = -(sin((90 + current_drawing_angle + available_angle) * (M_PI / 180.0)) * (radius + (CIRCULAR_DRAWING_RADIUS / 2)));
x_offset = nagios_icon_x + (DEFAULT_NODE_WIDTH / 2) - canvas_x;
y_offset = nagios_icon_y + (DEFAULT_NODE_HEIGHT / 2) - canvas_y;
/* if the host should be drawn */
/* this enforces the privacy of hosts that are not eligble to be drawn */
if (temp_host->should_be_drawn == TRUE) {
/* draw "slice" dividers */
if (immediate_children > 1 || layer > 1) {
/* draw "leftmost" divider */
gdImageLine(map_image, (int)x_coord[0] + x_offset, (int)y_coord[0] + y_offset, (int)x_coord[1] + x_offset, (int)y_coord[1] + y_offset, color_lightgrey);
/* draw "rightmost" divider */
gdImageLine(map_image, (int)x_coord[2] + x_offset, (int)y_coord[2] + y_offset, (int)x_coord[3] + x_offset, (int)y_coord[3] + y_offset, color_lightgrey);
}
/* determine arc drawing angles */
arc_start_angle = current_drawing_angle - 90.0;
while (arc_start_angle < 0.0)
arc_start_angle += 360.0;
arc_end_angle = arc_start_angle + available_angle;
/* draw inner arc */
gdImageArc(map_image, x_offset, y_offset, (radius - (CIRCULAR_DRAWING_RADIUS / 2)) * 2, (radius - (CIRCULAR_DRAWING_RADIUS / 2)) * 2, floor(arc_start_angle), ceil(arc_end_angle), color_lightgrey);
/* draw outer arc */
gdImageArc(map_image, x_offset, y_offset, (radius + (CIRCULAR_DRAWING_RADIUS / 2)) * 2, (radius + (CIRCULAR_DRAWING_RADIUS / 2)) * 2, floor(arc_start_angle), ceil(arc_end_angle), color_lightgrey);
/* determine center of "slice" and fill with appropriate color */
center_x = -(sin(-(current_drawing_angle + (available_angle / 2.0)) * (M_PI / 180.0)) * (radius));
center_y = -(sin((90 + current_drawing_angle + (available_angle / 2.0)) * (M_PI / 180.0)) * (radius));
translated_x = center_x + x_offset;
translated_y = center_y + y_offset;
/* determine background color */
temp_hoststatus = find_hoststatus(temp_host->name);
if (temp_hoststatus == NULL)
bgcolor = color_lightgrey;
else if (suppress_maintenance_downtime == TRUE && temp_hoststatus->scheduled_downtime_depth > 0)
bgcolor = color_lightgrey;
/* lightred for both DOWN and UNREACHABLE for visual continuity and since UNREACHABLE is still a problem */
else if (temp_hoststatus->status == HOST_DOWN || temp_hoststatus->status == HOST_UNREACHABLE)
bgcolor = color_lightred;
else if ((get_servicestatus_count(temp_host->name, SERVICE_CRITICAL) > 0) || (get_servicestatus_count(temp_host->name, SERVICE_WARNING) > 0)) {
if ((in_layer_list == TRUE && exclude_layers == TRUE) || (in_layer_list == FALSE && exclude_layers == FALSE))
bgcolor = color_lightgreen;
else
bgcolor = color_yellow;
} else
bgcolor = color_lightgreen;
/* fill slice with background color */
/* the fill function only works with coordinates that are in bounds of the actual image */
if (translated_x > 0 && translated_y > 0 && translated_x < canvas_width && translated_y < canvas_height)
gdImageFillToBorder(map_image, translated_x, translated_y, color_lightgrey, bgcolor);
}
/* recurse into child host ... */
draw_circular_layer_markup(temp_host, current_drawing_angle + ((available_angle - clipped_available_angle) / 2), clipped_available_angle, layer + 1, radius + CIRCULAR_DRAWING_RADIUS);
/* increment current drawing angle */
current_drawing_angle += available_angle;
}
}
return;
}
icinga-1.10.3/cgi/statuswml.c 0000664 0000000 0000000 00000141047 12276402000 0015777 0 ustar 00root root 0000000 0000000 /**************************************************************************
*
* STATUSWML.C - Icinga Status CGI for WAP-enabled devices
*
* Copyright (c) 2001-2008 Ethan Galstad (egalstad@nagios.org)
* Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*************************************************************************/
#include "../include/config.h"
#include "../include/common.h"
#include "../include/objects.h"
#include "../include/statusdata.h"
#include "../include/cgiutils.h"
#include "../include/getcgi.h"
#include "../include/cgiauth.h"
extern time_t program_start;
extern char main_config_file[MAX_FILENAME_LENGTH];
extern host *host_list;
extern hostgroup *hostgroup_list;
extern service *service_list;
extern hoststatus *hoststatus_list;
extern servicestatus *servicestatus_list;
extern int use_ssl_authentication;
extern int enable_notifications;
extern int execute_service_checks;
extern char *ping_syntax;
#define DISPLAY_HOST 0
#define DISPLAY_SERVICE 1
#define DISPLAY_HOSTGROUP 2
#define DISPLAY_INDEX 3
#define DISPLAY_PING 4
#define DISPLAY_TRACEROUTE 5
#define DISPLAY_QUICKSTATS 6
#define DISPLAY_PROCESS 7
#define DISPLAY_ALL_PROBLEMS 8
#define DISPLAY_UNHANDLED_PROBLEMS 9
#define DISPLAY_HOSTGROUP_SUMMARY 0
#define DISPLAY_HOSTGROUP_OVERVIEW 1
#define DISPLAY_HOST_SUMMARY 0
#define DISPLAY_HOST_SERVICES 1
int process_cgivars(void);
int validate_arguments(void);
int is_valid_hostip(char *hostip);
int display_type = DISPLAY_INDEX;
int show_all_hostgroups = TRUE;
char *host_name = NULL;
char *hostgroup_name = NULL;
char *service_desc = NULL;
int hostgroup_style = DISPLAY_HOSTGROUP_SUMMARY;
int host_style = DISPLAY_HOST_SUMMARY;
void display_index(void);
void display_host(void);
void display_host_services(void);
void display_service(void);
void display_hostgroup_summary(void);
void display_hostgroup_overview(void);
void display_ping(void);
void display_traceroute(void);
void display_quick_stats(void);
void display_process(void);
void display_problems(void);
char *ping_address = "";
char *traceroute_address = "";
extern int daemon_check;
char *dummy; /* reduce compiler warnings */
authdata current_authdata;
int CGI_ID = STATUSWML_CGI_ID;
int main(void) {
int result = OK;
/* get the arguments passed in the URL */
process_cgivars();
/* reset internal variables */
reset_cgi_vars();
document_header(CGI_ID, TRUE, "Status WML");
/* validate arguments in URL */
result = validate_arguments();
if (result == ERROR) {
document_footer(CGI_ID);
return ERROR;
}
/* read the CGI configuration file */
result = read_cgi_config_file(get_cgi_config_location());
if (result == ERROR) {
printf("
Error: Could not open CGI configuration file '%s' for reading!
\n", get_cgi_config_location());
document_footer(CGI_ID);
return ERROR;
}
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if (result == ERROR) {
printf("
Error: Could not open main configuration file '%s' for reading!
\n", main_config_file);
document_footer(CGI_ID);
return ERROR;
}
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if (result == ERROR) {
printf("
Error: Could not read some or all object configuration data!
\n");
document_footer(CGI_ID);
return ERROR;
}
/* read all status data */
result = read_all_status_data(main_config_file, READ_ALL_STATUS_DATA);
if (result == ERROR && daemon_check == TRUE) {
printf("
Error: Could not read host and service status information!
\n");
document_footer(CGI_ID);
free_memory();
return ERROR;
}
/* get authentication information */
get_authentication_information(¤t_authdata);
/* decide what to display to the user */
if (display_type == DISPLAY_HOST && host_style == DISPLAY_HOST_SERVICES)
display_host_services();
else if (display_type == DISPLAY_HOST)
display_host();
else if (display_type == DISPLAY_SERVICE)
display_service();
else if (display_type == DISPLAY_HOSTGROUP && hostgroup_style == DISPLAY_HOSTGROUP_OVERVIEW)
display_hostgroup_overview();
else if (display_type == DISPLAY_HOSTGROUP && hostgroup_style == DISPLAY_HOSTGROUP_SUMMARY)
display_hostgroup_summary();
else if (display_type == DISPLAY_PING)
display_ping();
else if (display_type == DISPLAY_TRACEROUTE)
display_traceroute();
else if (display_type == DISPLAY_QUICKSTATS)
display_quick_stats();
else if (display_type == DISPLAY_PROCESS)
display_process();
else if (display_type == DISPLAY_ALL_PROBLEMS || display_type == DISPLAY_UNHANDLED_PROBLEMS)
display_problems();
else
display_index();
document_footer(CGI_ID);
/* free all allocated memory */
free_memory();
return OK;
}
int process_cgivars(void) {
char **variables;
int error = FALSE;
int x;
variables = getcgivars();
for (x = 0; variables[x] != NULL; x++) {
/* we found the hostgroup argument */
if (!strcmp(variables[x], "hostgroup")) {
display_type = DISPLAY_HOSTGROUP;
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((hostgroup_name = (char *)strdup(variables[x])) == NULL)
hostgroup_name = "";
strip_html_brackets(hostgroup_name);
if (!strcmp(hostgroup_name, "all"))
show_all_hostgroups = TRUE;
else
show_all_hostgroups = FALSE;
}
/* we found the host argument */
else if (!strcmp(variables[x], "host")) {
display_type = DISPLAY_HOST;
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((host_name = (char *)strdup(variables[x])) == NULL)
host_name = "";
strip_html_brackets(host_name);
}
/* we found the service argument */
else if (!strcmp(variables[x], "service")) {
display_type = DISPLAY_SERVICE;
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((service_desc = (char *)strdup(variables[x])) == NULL)
service_desc = "";
strip_html_brackets(service_desc);
}
/* we found the hostgroup style argument */
else if (!strcmp(variables[x], "style")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "overview"))
hostgroup_style = DISPLAY_HOSTGROUP_OVERVIEW;
else if (!strcmp(variables[x], "summary"))
hostgroup_style = DISPLAY_HOSTGROUP_SUMMARY;
else if (!strcmp(variables[x], "servicedetail"))
host_style = DISPLAY_HOST_SERVICES;
else if (!strcmp(variables[x], "processinfo"))
display_type = DISPLAY_PROCESS;
else if (!strcmp(variables[x], "aprobs"))
display_type = DISPLAY_ALL_PROBLEMS;
else if (!strcmp(variables[x], "uprobs"))
display_type = DISPLAY_UNHANDLED_PROBLEMS;
else
display_type = DISPLAY_QUICKSTATS;
}
/* we found the ping argument */
else if (!strcmp(variables[x], "ping")) {
display_type = DISPLAY_PING;
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((ping_address = (char *)strdup(variables[x])) == NULL)
ping_address = "";
strip_html_brackets(ping_address);
}
/* we found the traceroute argument */
else if (!strcmp(variables[x], "traceroute")) {
display_type = DISPLAY_TRACEROUTE;
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((traceroute_address = (char *)strdup(variables[x])) == NULL)
traceroute_address = "";
strip_html_brackets(traceroute_address);
}
/* we found the nodaemoncheck option */
else if (!strcmp(variables[x], "nodaemoncheck"))
daemon_check = FALSE;
}
/* free memory allocated to the CGI variables */
free_cgivars(variables);
return error;
}
int validate_arguments(void) {
int result = OK;
if ((strcmp(ping_address, "")) && !is_valid_hostip(ping_address)) {
printf("
Invalid host name/ip
\n");
result = ERROR;
}
if (strcmp(traceroute_address, "") && !is_valid_hostip(traceroute_address)) {
printf("
Invalid host name/ip
\n");
result = ERROR;
}
return result;
}
int is_valid_hostip(char *hostip) {
char *valid_domain_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-";
if (strcmp(hostip, "") && strlen(hostip) == strspn(hostip, valid_domain_chars) && hostip[0] != '-' && hostip[strlen(hostip)-1] != '-')
return TRUE;
return FALSE;
}
/* main intro screen */
void display_index(void) {
/**** MAIN MENU SCREEN (CARD 1) ****/
printf("\n", PROGRAM_NAME);
printf("
\n");
printf("\n");
return;
}
/* displays process info */
void display_process(void) {
/**** MAIN SCREEN (CARD 1) ****/
printf("\n");
printf("
\n");
printf("Process Info
\n");
/* check authorization */
if (is_authorized_for_system_information(¤t_authdata) == FALSE) {
printf("Error: Not authorized for process info!\n");
printf("
\n");
printf("\n");
return;
}
if (enable_notifications == TRUE)
printf("Notifications are enabled \n");
else
printf("Notifications are disabled \n");
if (execute_service_checks == TRUE)
printf("Check execution is enabled \n");
else
printf("Check execution is disabled \n");
printf(" \n");
printf("Process Commands\n");
printf("\n");
printf("\n");
/**** COMMANDS SCREEN (CARD 2) ****/
printf("\n");
printf("
\n");
printf("\n");
printf("\n");
return;
}
/* displays service status */
void display_service(void) {
service *temp_service;
servicestatus *temp_servicestatus;
char last_check[MAX_DATETIME_LENGTH];
int days;
int hours;
int minutes;
int seconds;
time_t current_time;
time_t t;
char state_duration[48];
int found;
/**** MAIN SCREEN (CARD 1) ****/
printf("\n");
printf("
\n");
printf("Service '%s' on host '%s' \n", service_desc, host_name);
/* find the service */
temp_service = find_service(host_name, service_desc);
temp_servicestatus = find_servicestatus(host_name, service_desc);
if (temp_service == NULL || temp_servicestatus == NULL) {
printf("Error: Could not find service!\n");
printf("
\n");
printf("\n");
return;
}
/* check authorization */
if (is_authorized_for_service(temp_service, ¤t_authdata) == FALSE) {
printf("Error: Not authorized for service!\n");
printf("\n");
printf("\n");
return;
}
printf("
\n");
printf("
Status:
");
if (temp_servicestatus->status == SERVICE_OK)
printf("OK");
else if (temp_servicestatus->status == SERVICE_PENDING)
printf("PENDING");
else if (temp_servicestatus->status == SERVICE_WARNING)
printf("WARNING");
else if (temp_servicestatus->status == SERVICE_UNKNOWN)
printf("UNKNOWN");
else if (temp_servicestatus->status == SERVICE_CRITICAL)
printf("CRITICAL");
else
printf("?");
printf("
");
if (state_types & AE_SOFT_STATE)
printf("Soft");
if (state_types & AE_HARD_STATE)
printf("%sHard", (state_types & AE_SOFT_STATE) ? " & " : "");
printf(" States
\n");
printf("
\n");
printf("
\n");
printf("
Host States:
\n");
printf("
");
x = 0;
if (host_states & AE_HOST_UP) {
printf("Up");
x = 1;
}
if (host_states & AE_HOST_DOWN) {
printf("%sDown", (x == 1) ? ", " : "");
x = 1;
}
if (host_states & AE_HOST_UNREACHABLE)
printf("%sUnreachable", (x == 1) ? ", " : "");
if (x == 0)
printf("None");
printf("
\n");
printf("
\n");
printf("
\n");
printf("
Service States:
\n");
printf("
");
x = 0;
if (service_states & AE_SERVICE_OK) {
printf("Ok");
x = 1;
}
if (service_states & AE_SERVICE_WARNING) {
printf("%sWarning", (x == 1) ? ", " : "");
x = 1;
}
if (service_states & AE_SERVICE_UNKNOWN) {
printf("%sUnknown", (x == 1) ? ", " : "");
x = 1;
}
if (service_states & AE_SERVICE_CRITICAL)
printf("%sCritical", (x == 1) ? ", " : "");
if (x == 0)
printf("None");
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
printf("\n");
printf("
\n");
printf("
\n");
printf("
\n");
}
printf("
\n");
/* end of top table */
printf("
\n");
printf("
\n");
}
/*********************************/
/****** GENERATE THE REPORT ******/
/*********************************/
if (generate_report == TRUE) {
read_archived_event_data();
display_report();
}
/* ask user for report options */
else {
time(¤t_time);
t = localtime(¤t_time);
start_day = 1;
start_year = t->tm_year + 1900;
end_day = t->tm_mday;
end_year = t->tm_year + 1900;
printf("
Standard Reports:
\n");
printf("\n");
printf("
Custom Report Options:
\n");
printf("\n");
}
document_footer(CGI_ID);
/* free all other allocated memory */
free_memory();
free_event_list();
free_producer_list();
return OK;
}
int process_cgivars(void) {
char **variables;
int error = FALSE;
int x;
variables = getcgivars();
for (x = 0; variables[x] != NULL; x++) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */
if (strlen(variables[x]) >= MAX_INPUT_BUFFER - 1)
continue;
/* we found first time argument */
else if (!strcmp(variables[x], "t1")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
t1 = (time_t)strtoul(variables[x], NULL, 10);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = FALSE;
}
/* we found first time argument */
else if (!strcmp(variables[x], "t2")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
t2 = (time_t)strtoul(variables[x], NULL, 10);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = FALSE;
}
/* we found the standard timeperiod argument */
else if (!strcmp(variables[x], "timeperiod")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "today"))
timeperiod_type = TIMEPERIOD_TODAY;
else if (!strcmp(variables[x], "yesterday"))
timeperiod_type = TIMEPERIOD_YESTERDAY;
else if (!strcmp(variables[x], "thisweek"))
timeperiod_type = TIMEPERIOD_THISWEEK;
else if (!strcmp(variables[x], "lastweek"))
timeperiod_type = TIMEPERIOD_LASTWEEK;
else if (!strcmp(variables[x], "thismonth"))
timeperiod_type = TIMEPERIOD_THISMONTH;
else if (!strcmp(variables[x], "lastmonth"))
timeperiod_type = TIMEPERIOD_LASTMONTH;
else if (!strcmp(variables[x], "thisquarter"))
timeperiod_type = TIMEPERIOD_THISQUARTER;
else if (!strcmp(variables[x], "lastquarter"))
timeperiod_type = TIMEPERIOD_LASTQUARTER;
else if (!strcmp(variables[x], "thisyear"))
timeperiod_type = TIMEPERIOD_THISYEAR;
else if (!strcmp(variables[x], "lastyear"))
timeperiod_type = TIMEPERIOD_LASTYEAR;
else if (!strcmp(variables[x], "last24hours"))
timeperiod_type = TIMEPERIOD_LAST24HOURS;
else if (!strcmp(variables[x], "last7days"))
timeperiod_type = TIMEPERIOD_LAST7DAYS;
else if (!strcmp(variables[x], "last31days"))
timeperiod_type = TIMEPERIOD_LAST31DAYS;
else if (!strcmp(variables[x], "custom"))
timeperiod_type = TIMEPERIOD_CUSTOM;
else
continue;
convert_timeperiod_to_times(timeperiod_type, &t1, &t2);
compute_time_from_parts = FALSE;
}
/* we found the CSV output option */
else if (!strcmp(variables[x], "csvoutput")) {
display_header = FALSE;
content_type = CSV_CONTENT;
}
/* we found the JSON output option */
else if (!strcmp(variables[x], "jsonoutput")) {
display_header = FALSE;
content_type = JSON_CONTENT;
}
/* we found the embed option */
else if (!strcmp(variables[x], "embedded"))
embedded = TRUE;
/* we found the noheader option */
else if (!strcmp(variables[x], "noheader"))
display_header = FALSE;
/* we found the nodaemoncheck option */
else if (!strcmp(variables[x], "nodaemoncheck"))
daemon_check = FALSE;
/* we found time argument */
else if (!strcmp(variables[x], "smon")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
start_month = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "sday")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
start_day = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "syear")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
start_year = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "smin")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
start_minute = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "ssec")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
start_second = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "shour")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
start_hour = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "emon")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
end_month = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "eday")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
end_day = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "eyear")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
end_year = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "emin")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
end_minute = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "esec")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
end_second = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "ehour")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
end_hour = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found the item limit argument */
else if (!strcmp(variables[x], "limit")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
item_limit = atoi(variables[x]);
}
/* we found the state types argument */
else if (!strcmp(variables[x], "statetypes")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
state_types = atoi(variables[x]);
}
/* we found the alert types argument */
else if (!strcmp(variables[x], "alerttypes")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
alert_types = atoi(variables[x]);
}
/* we found the host states argument */
else if (!strcmp(variables[x], "hoststates")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
host_states = atoi(variables[x]);
}
/* we found the service states argument */
else if (!strcmp(variables[x], "servicestates")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
service_states = atoi(variables[x]);
}
/* we found the generate report argument */
else if (!strcmp(variables[x], "report")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
generate_report = (atoi(variables[x]) > 0) ? TRUE : FALSE;
}
/* we found the display type argument */
else if (!strcmp(variables[x], "displaytype")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
display_type = atoi(variables[x]);
}
/* we found the standard report argument */
else if (!strcmp(variables[x], "standardreport")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
standard_report = atoi(variables[x]);
}
/* we found the hostgroup argument */
else if (!strcmp(variables[x], "hostgroup")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((target_hostgroup_name = (char *)strdup(variables[x])) == NULL)
target_hostgroup_name = "";
strip_html_brackets(target_hostgroup_name);
if (!strcmp(target_hostgroup_name, "all"))
show_all_hostgroups = TRUE;
else {
show_all_hostgroups = FALSE;
target_hostgroup = find_hostgroup(target_hostgroup_name);
}
}
/* we found the servicegroup argument */
else if (!strcmp(variables[x], "servicegroup")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((target_servicegroup_name = (char *)strdup(variables[x])) == NULL)
target_servicegroup_name = "";
strip_html_brackets(target_servicegroup_name);
if (!strcmp(target_servicegroup_name, "all"))
show_all_servicegroups = TRUE;
else {
show_all_servicegroups = FALSE;
target_servicegroup = find_servicegroup(target_servicegroup_name);
}
}
/* we found the host argument */
else if (!strcmp(variables[x], "host")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((target_host_name = (char *)strdup(variables[x])) == NULL)
target_host_name = "";
strip_html_brackets(target_host_name);
if (!strcmp(target_host_name, "all"))
show_all_hosts = TRUE;
else {
show_all_hosts = FALSE;
target_host = find_host(target_host_name);
}
}
}
/* free memory allocated to the CGI variables */
free_cgivars(variables);
return error;
}
/* reads log files for archived event data */
void read_archived_event_data(void) {
char entry_host_name[MAX_INPUT_BUFFER];
char entry_svc_description[MAX_INPUT_BUFFER];
char *temp_buffer;
char *plugin_output;
char *error_text = NULL;
int state;
int state_type;
int status = READLOG_OK;
logentry *temp_entry = NULL;
logentry *entry_list = NULL;
logfilter *filter_list = NULL;
/* add host filter */
add_log_filter(&filter_list, LOGENTRY_HOST_UP, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_DOWN, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_UNREACHABLE, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_RECOVERY, LOGFILTER_INCLUDE);
/* add service filter */
add_log_filter(&filter_list, LOGENTRY_SERVICE_OK, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_WARNING, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_CRITICAL, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_UNKNOWN, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_RECOVERY, LOGFILTER_INCLUDE);
/* read log entries */
status = get_log_entries(&entry_list, &filter_list, &error_text, NULL, FALSE, t1, t2);
free_log_filters(&filter_list);
if (status == READLOG_OK) {
for (temp_entry = entry_list; temp_entry != NULL; temp_entry = temp_entry->next) {
/* get the timestamp */
if (temp_entry->timestamp < t1 || temp_entry->timestamp > t2)
continue;
switch (temp_entry->type) {
/* host alerts */
case LOGENTRY_HOST_DOWN:
case LOGENTRY_HOST_UNREACHABLE:
case LOGENTRY_HOST_RECOVERY:
case LOGENTRY_HOST_UP:
/* get host name */
temp_buffer = my_strtok(temp_entry->entry_text, ":");
temp_buffer = my_strtok(NULL, ";");
strncpy(entry_host_name, (temp_buffer == NULL) ? "" : temp_buffer + 1, sizeof(entry_host_name));
entry_host_name[sizeof(entry_host_name)-1] = '\x0';
/* state type */
if (strstr(temp_entry->entry_text, ";SOFT;"))
state_type = AE_SOFT_STATE;
else
state_type = AE_HARD_STATE;
/* get the plugin output */
temp_buffer = my_strtok(NULL, ";");
temp_buffer = my_strtok(NULL, ";");
temp_buffer = my_strtok(NULL, ";");
plugin_output = my_strtok(NULL, "\n");
/* state */
if (temp_entry->type == LOGENTRY_HOST_DOWN)
state = AE_HOST_DOWN;
else if (temp_entry->type == LOGENTRY_HOST_UNREACHABLE)
state = AE_HOST_UNREACHABLE;
else if (temp_entry->type == LOGENTRY_HOST_RECOVERY || temp_entry->type == LOGENTRY_HOST_UP)
state = AE_HOST_UP;
else
break;
add_archived_event(AE_HOST_ALERT, temp_entry->timestamp, state, state_type, entry_host_name, NULL, plugin_output);
break;
/* service alerts */
case LOGENTRY_SERVICE_CRITICAL:
case LOGENTRY_SERVICE_WARNING:
case LOGENTRY_SERVICE_UNKNOWN:
case LOGENTRY_SERVICE_RECOVERY:
case LOGENTRY_SERVICE_OK:
/* get host name */
temp_buffer = my_strtok(temp_entry->entry_text, ":");
temp_buffer = my_strtok(NULL, ";");
strncpy(entry_host_name, (temp_buffer == NULL) ? "" : temp_buffer + 1, sizeof(entry_host_name));
entry_host_name[sizeof(entry_host_name)-1] = '\x0';
/* get service description */
temp_buffer = my_strtok(NULL, ";");
strncpy(entry_svc_description, (temp_buffer == NULL) ? "" : temp_buffer, sizeof(entry_svc_description));
entry_svc_description[sizeof(entry_svc_description)-1] = '\x0';
/* state type */
if (strstr(temp_entry->entry_text, ";SOFT;"))
state_type = AE_SOFT_STATE;
else
state_type = AE_HARD_STATE;
/* get the plugin output */
temp_buffer = my_strtok(NULL, ";");
temp_buffer = my_strtok(NULL, ";");
temp_buffer = my_strtok(NULL, ";");
plugin_output = my_strtok(NULL, "\n");
/* state */
if (temp_entry->type == LOGENTRY_SERVICE_CRITICAL)
state = AE_SERVICE_CRITICAL;
else if (temp_entry->type == LOGENTRY_SERVICE_WARNING)
state = AE_SERVICE_WARNING;
else if (temp_entry->type == LOGENTRY_SERVICE_UNKNOWN)
state = AE_SERVICE_UNKNOWN;
else if (temp_entry->type == LOGENTRY_SERVICE_RECOVERY || temp_entry->type == LOGENTRY_SERVICE_OK)
state = AE_SERVICE_OK;
else
break;
add_archived_event(AE_SERVICE_ALERT, temp_entry->timestamp, state, state_type, entry_host_name, entry_svc_description, plugin_output);
break;
}
}
}
/* free memory */
free_log_entries(&entry_list);
return;
}
void compute_report_times(void) {
time_t current_time;
struct tm *st;
struct tm *et;
/* get the current time */
time(¤t_time);
st = localtime(¤t_time);
st->tm_sec = start_second;
st->tm_min = start_minute;
st->tm_hour = start_hour;
st->tm_mday = start_day;
st->tm_mon = start_month - 1;
st->tm_year = start_year - 1900;
st->tm_isdst = -1;
t1 = mktime(st);
et = localtime(¤t_time);
et->tm_sec = end_second;
et->tm_min = end_minute;
et->tm_hour = end_hour;
et->tm_mday = end_day;
et->tm_mon = end_month - 1;
et->tm_year = end_year - 1900;
et->tm_isdst = -1;
t2 = mktime(et);
}
void free_event_list(void) {
archived_event *this_event = NULL;
archived_event *next_event = NULL;
for (this_event = event_list; this_event != NULL;) {
next_event = this_event->next;
if (this_event->host_name != NULL)
free(this_event->host_name);
if (this_event->service_description != NULL)
free(this_event->service_description);
if (this_event->event_info != NULL)
free(this_event->event_info);
free(this_event);
this_event = next_event;
}
event_list = NULL;
return;
}
/* adds an archived event entry to the list in memory */
void add_archived_event(int event_type, time_t time_stamp, int entry_type, int state_type, char *host_name, char *svc_description, char *event_info) {
archived_event *new_event = NULL;
service *temp_service = NULL;
host *temp_host;
/* check timestamp sanity */
if (time_stamp < t1 || time_stamp > t2)
return;
/* check alert type (host or service alert) */
if (!(alert_types & event_type))
return;
/* check state type (soft or hard state) */
if (!(state_types & state_type))
return;
/* check state (host or service state) */
if (event_type == AE_HOST_ALERT) {
if (!(host_states & entry_type))
return;
} else {
if (!(service_states & entry_type))
return;
}
/* find the host this entry is associated with */
temp_host = find_host(host_name);
/* check hostgroup match (valid filter for all reports) */
if (show_all_hostgroups == FALSE && is_host_member_of_hostgroup(target_hostgroup, temp_host) == FALSE)
return;
/* check host match (valid filter for some reports) */
if (show_all_hosts == FALSE && (display_type == REPORT_RECENT_ALERTS || display_type == REPORT_HOST_ALERT_TOTALS || display_type == REPORT_SERVICE_ALERT_TOTALS)) {
if (target_host == NULL || temp_host == NULL)
return;
if (strcmp(target_host->name, temp_host->name))
return;
}
/* check servicegroup math (valid filter for all reports) */
if (event_type == AE_SERVICE_ALERT) {
temp_service = find_service(host_name, svc_description);
if (show_all_servicegroups == FALSE && is_service_member_of_servicegroup(target_servicegroup, temp_service) == FALSE)
return;
} else {
if (show_all_servicegroups == FALSE && is_host_member_of_servicegroup(target_servicegroup, temp_host) == FALSE)
return;
}
/* check authorization */
if (event_type == AE_SERVICE_ALERT) {
if (is_authorized_for_service(temp_service, ¤t_authdata) == FALSE)
return;
} else {
if (is_authorized_for_host(temp_host, ¤t_authdata) == FALSE)
return;
}
#ifdef DEBUG
if (event_type == AE_HOST_ALERT)
printf("Adding host alert (%s) @ %lu \n", host_name, (unsigned long)time_stamp);
else
printf("Adding service alert (%s/%s) @ %lu \n", host_name, svc_description, (unsigned long)time_stamp);
#endif
/* allocate memory for the new entry */
new_event = (archived_event *)malloc(sizeof(archived_event));
if (new_event == NULL)
return;
/* allocate memory for the host name */
if (host_name != NULL) {
new_event->host_name = (char *)malloc(strlen(host_name) + 1);
if (new_event->host_name != NULL)
strcpy(new_event->host_name, host_name);
} else
new_event->host_name = NULL;
/* allocate memory for the service description */
if (svc_description != NULL) {
new_event->service_description = (char *)malloc(strlen(svc_description) + 1);
if (new_event->service_description != NULL)
strcpy(new_event->service_description, svc_description);
} else
new_event->service_description = NULL;
/* allocate memory for the event info */
if (event_info != NULL) {
new_event->event_info = (char *)malloc(strlen(event_info) + 1);
if (new_event->event_info != NULL)
strcpy(new_event->event_info, event_info);
} else
new_event->event_info = NULL;
new_event->event_type = event_type;
new_event->time_stamp = time_stamp;
new_event->entry_type = entry_type;
new_event->state_type = state_type;
/* add the new entry to the list in memory */
new_event->next = NULL;
new_event->next = event_list;
event_list = new_event;
total_items++;
return;
}
void sort_archive_states(void) {
archived_event *temp_list = NULL;
archived_event *new_event = NULL;
archived_event *last_event = NULL;
archived_event *next_event = NULL;
archived_event *temp_event = NULL;
temp_list = NULL;
for (new_event = event_list; new_event != NULL;) {
next_event = new_event->next;
last_event = temp_list;
for (temp_event = temp_list; temp_event != NULL; temp_event = temp_event->next) {
if (new_event->time_stamp >= temp_event->time_stamp) {
new_event->next = temp_event;
if (temp_event == temp_list)
temp_list = new_event;
else
last_event->next = new_event;
break;
} else
last_event = temp_event;
}
if (temp_list == NULL) {
new_event->next = NULL;
temp_list = new_event;
} else if (temp_event == NULL) {
new_event->next = NULL;
last_event->next = new_event;
}
new_event = next_event;
}
event_list = temp_list;
return;
}
/* determines standard report options */
void determine_standard_report_options(void) {
/* report over last 7 days */
convert_timeperiod_to_times(TIMEPERIOD_LAST7DAYS, &t1, &t2);
compute_time_from_parts = FALSE;
/* common options */
state_types = AE_HARD_STATE;
item_limit = 25;
/* report-specific options */
switch (standard_report) {
case SREPORT_RECENT_ALERTS:
display_type = REPORT_RECENT_ALERTS;
alert_types = AE_HOST_ALERT + AE_SERVICE_ALERT;
host_states = AE_HOST_UP + AE_HOST_DOWN + AE_HOST_UNREACHABLE;
service_states = AE_SERVICE_OK + AE_SERVICE_WARNING + AE_SERVICE_UNKNOWN + AE_SERVICE_CRITICAL;
break;
case SREPORT_RECENT_HOST_ALERTS:
display_type = REPORT_RECENT_ALERTS;
alert_types = AE_HOST_ALERT;
host_states = AE_HOST_UP + AE_HOST_DOWN + AE_HOST_UNREACHABLE;
break;
case SREPORT_RECENT_SERVICE_ALERTS:
display_type = REPORT_RECENT_ALERTS;
alert_types = AE_SERVICE_ALERT;
service_states = AE_SERVICE_OK + AE_SERVICE_WARNING + AE_SERVICE_UNKNOWN + AE_SERVICE_CRITICAL;
break;
case SREPORT_TOP_HOST_ALERTS:
display_type = REPORT_TOP_ALERTS;
alert_types = AE_HOST_ALERT;
host_states = AE_HOST_UP + AE_HOST_DOWN + AE_HOST_UNREACHABLE;
break;
case SREPORT_TOP_SERVICE_ALERTS:
display_type = REPORT_TOP_ALERTS;
alert_types = AE_SERVICE_ALERT;
service_states = AE_SERVICE_OK + AE_SERVICE_WARNING + AE_SERVICE_UNKNOWN + AE_SERVICE_CRITICAL;
break;
default:
break;
}
return;
}
/* displays report */
void display_report(void) {
hostgroup *temp_hostgroup;
host *temp_host;
service *temp_service;
servicegroup* temp_servicegroup;
if (display_type == REPORT_TOP_ALERTS) {
display_top_alerts();
return;
}
if (display_type == REPORT_RECENT_ALERTS) {
display_recent_alerts();
return;
}
if (content_type == JSON_CONTENT) {
if (display_type == REPORT_ALERT_TOTALS)
printf("\"overall_alert_totals\": [\n");
if (display_type == REPORT_HOST_ALERT_TOTALS)
printf("\"alert_totals_by_host\": {\n");
if (display_type == REPORT_HOSTGROUP_ALERT_TOTALS)
printf("\"alert_totals_by_hostgroup\": {\n");
if (display_type == REPORT_SERVICE_ALERT_TOTALS)
printf("\"alert_totals_by_service\": {\n");
if (display_type == REPORT_SERVICEGROUP_ALERT_TOTALS)
printf("\"alert_totals_by_servicegroup\": {\n");
} else if (content_type == CSV_CONTENT) {
if (display_type == REPORT_HOST_ALERT_TOTALS || display_type == REPORT_SERVICE_ALERT_TOTALS)
printf("%sHOST_NAME%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
if (display_type == REPORT_HOSTGROUP_ALERT_TOTALS)
printf("%sHOSTGROUP_NAME%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
if (display_type == REPORT_SERVICE_ALERT_TOTALS)
printf("%sSERVICE%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
if (display_type == REPORT_SERVICEGROUP_ALERT_TOTALS)
printf("%sSERVICEGROUP_NAME%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
/* Host Alerts Data */
if (alert_types & AE_HOST_ALERT && display_type != REPORT_SERVICE_ALERT_TOTALS) {
printf("%sHOST_UP_SOFT%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sHOST_UP_HARD%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sHOST_UP_TOTAL%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sHOST_DOWN_SOFT%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sHOST_DOWN_HARD%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sHOST_DOWN_TOTAL%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sHOST_UNREACHABLE_SOFT%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sHOST_UNREACHABLE_HARD%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sHOST_UNREACHABLE_TOTAL%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sHOST_ALL_SOFT%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sHOST_ALL_HARD%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sHOST_ALL_TOTAL%s", csv_data_enclosure, csv_data_enclosure);
}
/* Service Alerts Head */
if (alert_types & AE_SERVICE_ALERT) {
if (alert_types & AE_HOST_ALERT && display_type != REPORT_SERVICE_ALERT_TOTALS)
printf("%s", csv_delimiter);
printf("%sSERVICE_OK_SOFT%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sSERVICE_OK_HARD%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sSERVICE_OK_TOTAL%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sSERVICE_WARNING_SOFT%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sSERVICE_WARNING_HARD%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sSERVICE_WARNING_TOTAL%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sSERVICE_UNKNOWN_SOFT%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sSERVICE_UNKNOWN_HARD%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sSERVICE_UNKNOWN_TOTAL%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sSERVICE_CRITICAL_SOFT%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sSERVICE_CRITICAL_HARD%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sSERVICE_CRITICAL_TOTAL%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sSERVICE_ALL_SOFT%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sSERVICE_ALL_HARD%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sSERVICE_ALL_TOTAL%s\n", csv_data_enclosure, csv_data_enclosure);
} else {
printf("\n");
}
} else {
printf(" \n");
printf("
");
printf("
");
if (display_type == REPORT_ALERT_TOTALS)
printf("Overall Totals");
if (display_type == REPORT_HOST_ALERT_TOTALS)
printf("Totals By Host");
if (display_type == REPORT_HOSTGROUP_ALERT_TOTALS)
printf("Totals By Hostgroup");
if (display_type == REPORT_SERVICE_ALERT_TOTALS)
printf("Totals By Service");
if (display_type == REPORT_SERVICEGROUP_ALERT_TOTALS)
printf("Totals By Servicegroup");
printf("
\n");
/* add export to csv, json, link */
printf("
\n");
}
return;
}
icinga-1.10.3/cgi/tac.c 0000664 0000000 0000000 00000472453 12276402000 0014513 0 ustar 00root root 0000000 0000000 /***********************************************************************
*
* TAC.C - Icinga Tactical Monitoring Overview CGI
*
* Copyright (c) 2001-2008 Ethan Galstad (egalstad@nagios.org)
* Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
*
* This CGI program will display the contents of the Icinga
* log file.
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
***********************************************************************/
/** @file tac.c
* @brief display a tactical monitoring overview and the tac header
**/
/* #define DEBUG 1*/
#include "../include/config.h"
#include "../include/common.h"
#include "../include/objects.h"
#include "../include/statusdata.h"
#include "../include/getcgi.h"
#include "../include/cgiutils.h"
#include "../include/cgiauth.h"
/** @name external vars
@{ **/
extern char main_config_file[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH];
extern char url_media_path[MAX_FILENAME_LENGTH];
extern char *service_critical_sound;
extern char *service_warning_sound;
extern char *service_unknown_sound;
extern char *host_down_sound;
extern char *host_unreachable_sound;
extern char *normal_sound;
extern host *host_list;
extern hostgroup *hostgroup_list;
extern hoststatus *hoststatus_list;
extern servicestatus *servicestatus_list;
extern int enable_notifications;
extern int execute_service_checks;
extern int execute_host_checks;
extern int accept_passive_service_checks;
extern int accept_passive_host_checks;
extern int enable_event_handlers;
extern int enable_flap_detection;
extern int tac_show_only_hard_state;
extern int show_tac_header;
extern int show_tac_header_pending;
extern int embedded;
extern int refresh;
extern int refresh_type;
extern int display_header;
extern int daemon_check;
extern int tac_header;
extern int content_type;
/** @} */
/** @name TAC WARNING/CRITICAL PERCENTAGE
@{**/
#define HEALTH_WARNING_PERCENTAGE 90 /**< health below this value is considered as in warning state */
#define HEALTH_CRITICAL_PERCENTAGE 75 /**< health below this value is considered as in critical state */
/** @} */
/** @brief host outage struct
*
* holds a list hosts causing network outages
**/
typedef struct hostoutage_struct {
host *hst; /**< pointer to host element which cuase outage */
int affected_child_hosts; /**< number of affected hosts */
struct hostoutage_struct *next; /**< pointer to next host outage element */
} hostoutage;
hostoutage *hostoutage_list = NULL; /**< list of all host outage elements */
authdata current_authdata; /**< struct to hold current authentication data */
int CGI_ID = TAC_CGI_ID; /**< ID to identify the cgi for functions in cgiutils.c */
/** @name outages counters
@{**/
int total_blocking_outages = 0;
int total_nonblocking_outages = 0;
/** @} */
/** @name health counters
@{**/
int total_service_health = 0;
int total_host_health = 0;
int potential_service_health = 0;
int potential_host_health = 0;
double percent_service_health = 0.0;
double percent_host_health = 0.0;
/** @} */
/** @name statistics counters
@{**/
double min_service_execution_time = -1.0;
double max_service_execution_time = -1.0;
double total_service_execution_time = 0.0;
double average_service_execution_time = -1.0;
double min_host_execution_time = -1.0;
double max_host_execution_time = -1.0;
double total_host_execution_time = 0.0;
double average_host_execution_time = -1.0;
double min_service_latency = -1.0;
double max_service_latency = -1.0;
double total_service_latency = 0.0;
double average_service_latency = -1.0;
double min_host_latency = -1.0;
double max_host_latency = -1.0;
double total_host_latency = 0.0;
double average_host_latency = -1.0;
/** @} */
/** @name total counters
@{**/
int total_hosts = 0;
int total_services = 0;
int total_active_host_checks = 0;
int total_passive_host_checks = 0;
int total_disabled_host_checks = 0;
int total_active_host_checks_with_passive_disabled = 0;
int total_active_service_checks = 0;
int total_passive_service_checks = 0;
int total_disabled_service_checks = 0;
int total_active_service_checks_with_passive_disabled = 0;
/** @} */
/** @name flapping and disabled counters
@{**/
int flapping_services = 0;
int flapping_hosts = 0;
int flap_disabled_services = 0;
int flap_disabled_hosts = 0;
int notification_disabled_services = 0;
int notification_disabled_hosts = 0;
int event_handler_disabled_services = 0;
int event_handler_disabled_hosts = 0;
/** @} */
/** @name host status counters
@{**/
int hosts_pending = 0;
int hosts_pending_active = 0;
int hosts_pending_passive = 0;
int hosts_pending_disabled = 0;
int hosts_up = 0;
int hosts_up_active = 0;
int hosts_up_passive = 0;
int hosts_up_disabled = 0;
int hosts_down = 0;
int hosts_down_active = 0;
int hosts_down_passive = 0;
int hosts_down_disabled = 0;
int hosts_down_scheduled = 0;
int hosts_down_active_scheduled = 0;
int hosts_down_passive_scheduled = 0;
int hosts_down_disabled_scheduled = 0;
int hosts_down_acknowledged = 0;
int hosts_down_active_acknowledged = 0;
int hosts_down_passive_acknowledged = 0;
int hosts_down_disabled_acknowledged = 0;
int hosts_down_unacknowledged = 0;
int hosts_down_active_unacknowledged = 0;
int hosts_down_passive_unacknowledged = 0;
int hosts_down_disabled_unacknowledged = 0;
int hosts_unreachable = 0;
int hosts_unreachable_active = 0;
int hosts_unreachable_passive = 0;
int hosts_unreachable_disabled = 0;
int hosts_unreachable_scheduled = 0;
int hosts_unreachable_active_scheduled = 0;
int hosts_unreachable_passive_scheduled = 0;
int hosts_unreachable_disabled_scheduled = 0;
int hosts_unreachable_acknowledged = 0;
int hosts_unreachable_active_acknowledged = 0;
int hosts_unreachable_passive_acknowledged = 0;
int hosts_unreachable_disabled_acknowledged = 0;
int hosts_unreachable_unacknowledged = 0;
int hosts_unreachable_active_unacknowledged = 0;
int hosts_unreachable_passive_unacknowledged = 0;
int hosts_unreachable_disabled_unacknowledged = 0;
/** @} */
/** @name service status counters
@{**/
int services_pending = 0;
int services_pending_host_down = 0;
int services_pending_active = 0;
int services_pending_active_host_down = 0;
int services_pending_passive = 0;
int services_pending_passive_host_down = 0;
int services_pending_disabled = 0;
int services_pending_disabled_host_down = 0;
int services_ok = 0;
int services_ok_host_down = 0;
int services_ok_active = 0;
int services_ok_active_host_down = 0;
int services_ok_passive = 0;
int services_ok_passive_host_down = 0;
int services_ok_disabled = 0;
int services_ok_disabled_host_down = 0;
int services_warning = 0;
int services_warning_host_down = 0;
int services_warning_active = 0;
int services_warning_active_host_down = 0;
int services_warning_passive = 0;
int services_warning_passive_host_down = 0;
int services_warning_disabled = 0;
int services_warning_disabled_host_down = 0;
int services_warning_scheduled = 0;
int services_warning_scheduled_host_down = 0;
int services_warning_active_scheduled = 0;
int services_warning_active_scheduled_host_down = 0;
int services_warning_passive_scheduled = 0;
int services_warning_passive_scheduled_host_down = 0;
int services_warning_disabled_scheduled = 0;
int services_warning_disabled_scheduled_host_down = 0;
int services_warning_acknowledged = 0;
int services_warning_acknowledged_host_down = 0;
int services_warning_active_acknowledged = 0;
int services_warning_active_acknowledged_host_down = 0;
int services_warning_passive_acknowledged = 0;
int services_warning_passive_acknowledged_host_down = 0;
int services_warning_disabled_acknowledged = 0;
int services_warning_disabled_acknowledged_host_down = 0;
int services_warning_unacknowledged = 0;
int services_warning_unacknowledged_host_down = 0;
int services_warning_active_unacknowledged = 0;
int services_warning_active_unacknowledged_host_down = 0;
int services_warning_passive_unacknowledged = 0;
int services_warning_passive_unacknowledged_host_down = 0;
int services_warning_disabled_unacknowledged = 0;
int services_warning_disabled_unacknowledged_host_down = 0;
int services_unknown = 0;
int services_unknown_host_down = 0;
int services_unknown_active = 0;
int services_unknown_active_host_down = 0;
int services_unknown_passive = 0;
int services_unknown_passive_host_down = 0;
int services_unknown_disabled = 0;
int services_unknown_disabled_host_down = 0;
int services_unknown_scheduled = 0;
int services_unknown_scheduled_host_down = 0;
int services_unknown_active_scheduled = 0;
int services_unknown_active_scheduled_host_down = 0;
int services_unknown_passive_scheduled = 0;
int services_unknown_passive_scheduled_host_down = 0;
int services_unknown_disabled_scheduled = 0;
int services_unknown_disabled_scheduled_host_down = 0;
int services_unknown_acknowledged = 0;
int services_unknown_acknowledged_host_down = 0;
int services_unknown_active_acknowledged = 0;
int services_unknown_active_acknowledged_host_down = 0;
int services_unknown_passive_acknowledged = 0;
int services_unknown_passive_acknowledged_host_down = 0;
int services_unknown_disabled_acknowledged = 0;
int services_unknown_disabled_acknowledged_host_down = 0;
int services_unknown_unacknowledged = 0;
int services_unknown_unacknowledged_host_down = 0;
int services_unknown_active_unacknowledged = 0;
int services_unknown_active_unacknowledged_host_down = 0;
int services_unknown_passive_unacknowledged = 0;
int services_unknown_passive_unacknowledged_host_down = 0;
int services_unknown_disabled_unacknowledged = 0;
int services_unknown_disabled_unacknowledged_host_down = 0;
int services_critical = 0;
int services_critical_host_down = 0;
int services_critical_active = 0;
int services_critical_active_host_down = 0;
int services_critical_passive = 0;
int services_critical_passive_host_down = 0;
int services_critical_disabled = 0;
int services_critical_disabled_host_down = 0;
int services_critical_scheduled = 0;
int services_critical_scheduled_host_down = 0;
int services_critical_active_scheduled = 0;
int services_critical_active_scheduled_host_down = 0;
int services_critical_passive_scheduled = 0;
int services_critical_passive_scheduled_host_down = 0;
int services_critical_disabled_scheduled = 0;
int services_critical_disabled_scheduled_host_down = 0;
int services_critical_acknowledged = 0;
int services_critical_acknowledged_host_down = 0;
int services_critical_active_acknowledged = 0;
int services_critical_active_acknowledged_host_down = 0;
int services_critical_passive_acknowledged = 0;
int services_critical_passive_acknowledged_host_down = 0;
int services_critical_disabled_acknowledged = 0;
int services_critical_disabled_acknowledged_host_down = 0;
int services_critical_unacknowledged = 0;
int services_critical_unacknowledged_host_down = 0;
int services_critical_active_unacknowledged = 0;
int services_critical_active_unacknowledged_host_down = 0;
int services_critical_passive_unacknowledged = 0;
int services_critical_passive_unacknowledged_host_down = 0;
int services_critical_disabled_unacknowledged = 0;
int services_critical_disabled_unacknowledged_host_down = 0;
/** @} */
/** @brief Parses the requested GET/POST variables
* @retval TRUE
* @retval FALSE
* @return wether parsing was successful or not
*
* @n This function parses the request and set's the necessary variables
**/
int process_cgivars(void);
/** @brief fills all the counters
*
* Iterates through @ref servicestatus_list and @ref hoststatus_list to count all host and service states
**/
void analyze_status_data(void);
/** @brief displays all data
*
* After we calculated all data we have to display it.
* This functions is also responsible for the "tac header".
**/
void display_tac_overview(void);
/** @brief find all hosts that are causing network outages
*
* Function tries to find hosts causig outages and calculates how many child hosts are affected by that.
*
* Loops through @ref hoststatus_list and looks for hosts which are DOWN or UNREACHABLE and haven't been
* blocked by other DOWN/UNREACHABLE hosts (@ref is_route_to_host_blocked).
* These hosts get added to @ref hostoutage_list via @ref add_hostoutage
*
* Then it loops through @ref hostoutage_list and calls @ref calculate_outage_effect_of_host to find
* out how many hosts are affected by this outage.
**/
void find_hosts_causing_outages(void);
/** @brief calculates network outage effect of a particular host being down or unreachable
* @param [in] hst host element to calculate outage for
* @param [out] affected_hosts returns number of affected hosts
*
* Finds immediate childs of "hst" and calls itself again to finaly find all child hosts and sums them up to affected_hosts.
* This is a recursice function.
**/
void calculate_outage_effect_of_host(host *, int *);
/** @brief tests whether or not a host is "blocked" by upstream parents (host is already assumed to be down or unreachable)
* @param [in] hst host element to see if this host is blocked
* @retval TRUE
* @retval FALSE
* @return wether host is completely blocked or not
*
* Loops through all parent hosts of "hst" and tries to find a parent in state UP or PENDING. If it finds a parent in UP or
* PENDING state the function returns FALSE otherwise TRUE
**/
int is_route_to_host_blocked(host *);
/** @brief adds a host to @ref hostoutage_list
* @param [in] hst host element to add to hostoutage_list
**/
void add_hostoutage(host *);
/** @brief frees all memory allocated to @ref hostoutage_list entries in memory **/
void free_hostoutage_list(void);
/** @brief Yes we need a main function **/
int main(void) {
int result = OK;
char *sound = NULL;
#ifdef DEBUG
time_t t1, t2, t3, t4, t5, t6, t7, t8, t9;
#endif
#ifdef DEBUG
time(&t1);
#endif
/* get the CGI variables passed in the URL */
process_cgivars();
/* reset internal variables */
reset_cgi_vars();
/* read the CGI configuration file */
result = read_cgi_config_file(get_cgi_config_location());
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(get_cgi_config_location(), ERROR_CGI_CFG_FILE, tac_header);
document_footer(CGI_ID);
return ERROR;
}
#ifdef DEBUG
time(&t2);
#endif
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(main_config_file, ERROR_CGI_MAIN_CFG, tac_header);
document_footer(CGI_ID);
return ERROR;
}
#ifdef DEBUG
time(&t3);
#endif
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(NULL, ERROR_CGI_OBJECT_DATA, tac_header);
document_footer(CGI_ID);
return ERROR;
}
#ifdef DEBUG
time(&t4);
#endif
/* read all status data */
result = read_all_status_data(main_config_file, READ_ALL_STATUS_DATA);
if (result == ERROR && daemon_check == TRUE) {
document_header(CGI_ID, FALSE, "Error");
print_error(NULL, ERROR_CGI_STATUS_DATA, tac_header);
document_footer(CGI_ID);
free_memory();
return ERROR;
}
#ifdef DEBUG
time(&t5);
#endif
if (tac_header == TRUE)
document_header(CGI_ID, TRUE, "Icinga");
else
document_header(CGI_ID, TRUE, "Tactical Monitoring Overview");
/* get authentication information */
get_authentication_information(¤t_authdata);
#ifdef DEBUG
time(&t6);
#endif
/* analyze current host and service status data for tac overview */
analyze_status_data();
#ifdef DEBUG
time(&t7);
#endif
/* find all hosts that are causing network outages */
find_hosts_causing_outages();
#ifdef DEBUG
time(&t8);
#endif
/* embed sound tag if necessary... */
if (hosts_unreachable_unacknowledged > 0 && host_unreachable_sound != NULL)
sound = host_unreachable_sound;
else if (hosts_down_unacknowledged > 0 && host_down_sound != NULL)
sound = host_down_sound;
else if (services_critical_unacknowledged > 0 && service_critical_sound != NULL)
sound = service_critical_sound;
else if (services_warning_unacknowledged > 0 && service_warning_sound != NULL)
sound = service_warning_sound;
else if (services_unknown_unacknowledged == 0 && services_warning_unacknowledged == 0 && services_critical_unacknowledged == 0 && hosts_down_unacknowledged == 0 && hosts_unreachable_unacknowledged == 0 && normal_sound != NULL)
sound = normal_sound;
if (sound != NULL && content_type != JSON_CONTENT) {
printf("");
}
/**** display main tac screen ****/
display_tac_overview();
#ifdef DEBUG
time(&t9);
#endif
document_footer(CGI_ID);
/* free memory allocated to the host outage list */
free_hostoutage_list();
/* free allocated memory */
free_memory();
#ifdef DEBUG
printf("T1: %lu\n", (unsigned long)t1);
printf("T2: %lu\n", (unsigned long)t2);
printf("T3: %lu\n", (unsigned long)t3);
printf("T4: %lu\n", (unsigned long)t4);
printf("T5: %lu\n", (unsigned long)t5);
printf("T6: %lu\n", (unsigned long)t6);
printf("T7: %lu\n", (unsigned long)t7);
printf("T8: %lu\n", (unsigned long)t8);
printf("T9: %lu\n", (unsigned long)t9);
#endif
return OK;
}
int process_cgivars(void) {
char **variables;
int error = FALSE;
int x;
variables = getcgivars();
for (x = 0; variables[x] != NULL; x++) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */
if (strlen(variables[x]) >= MAX_INPUT_BUFFER - 1)
continue;
/* we found the embed option */
else if (!strcmp(variables[x], "embedded"))
embedded = TRUE;
/* we found the noheader option */
else if (!strcmp(variables[x], "noheader"))
display_header = FALSE;
/* we found the pause option */
else if (!strcmp(variables[x], "paused"))
refresh = FALSE;
/* we found the nodaemoncheck option */
else if (!strcmp(variables[x], "nodaemoncheck"))
daemon_check = FALSE;
/* we found the tac_header option */
else if (!strcmp(variables[x], "tac_header"))
tac_header = TRUE;
/* we found the JSON output option */
else if (!strcmp(variables[x], "jsonoutput")) {
display_header = FALSE;
content_type = JSON_CONTENT;
}
/* we received an invalid argument */
else
error = TRUE;
}
/* free memory allocated to the CGI variables */
free_cgivars(variables);
return error;
}
void analyze_status_data(void) {
servicestatus *temp_servicestatus;
service *temp_service;
hoststatus *temp_hoststatus;
host *temp_host;
char *last_host_name = NULL;
int host_is_down = FALSE;
/* check all services */
for (temp_servicestatus = servicestatus_list; temp_servicestatus != NULL; temp_servicestatus = temp_servicestatus->next) {
/* see if user is authorized to view this service */
temp_service = find_service(temp_servicestatus->host_name, temp_servicestatus->description);
if (is_authorized_for_service(temp_service, ¤t_authdata) == FALSE)
continue;
/* check if only hard states to be shown */
if (tac_show_only_hard_state == TRUE && temp_servicestatus->state_type != HARD_STATE)
continue;
/* get hoststatus only once for each host */
if (last_host_name == NULL || strcmp(last_host_name, temp_servicestatus->host_name)) {
last_host_name = temp_servicestatus->host_name;
// find host status
temp_hoststatus = find_hoststatus(temp_servicestatus->host_name);
host_is_down = FALSE;
if (temp_hoststatus != NULL && (temp_hoststatus->status == HOST_DOWN || temp_hoststatus->status == HOST_UNREACHABLE))
host_is_down = TRUE;
}
/******** CHECK FEATURES *******/
/* check flapping */
if (temp_servicestatus->flap_detection_enabled == FALSE)
flap_disabled_services++;
else if (temp_servicestatus->is_flapping == TRUE)
flapping_services++;
/* check notifications */
if (temp_servicestatus->notifications_enabled == FALSE)
notification_disabled_services++;
/* check event handler */
if (temp_servicestatus->event_handler_enabled == FALSE)
event_handler_disabled_services++;
/********* CHECK STATUS ********/
if (temp_servicestatus->status == SERVICE_OK) {
if (temp_servicestatus->checks_enabled == TRUE)
(host_is_down == FALSE) ? services_ok_active++ : services_ok_active_host_down++;
else if (temp_servicestatus->accept_passive_service_checks == TRUE)
(host_is_down == FALSE) ? services_ok_passive++ : services_ok_passive_host_down++;
else
(host_is_down == FALSE) ? services_ok_disabled++ : services_ok_disabled_host_down++;
(host_is_down == FALSE) ? services_ok++ : services_ok_host_down++;
} else if (temp_servicestatus->status == SERVICE_WARNING) {
if (temp_servicestatus->scheduled_downtime_depth > 0) {
if (temp_servicestatus->checks_enabled == TRUE)
(host_is_down == FALSE) ? services_warning_active_scheduled++ : services_warning_active_scheduled_host_down++;
else if (temp_servicestatus->accept_passive_service_checks == TRUE)
(host_is_down == FALSE) ? services_warning_passive_scheduled++ : services_warning_passive_scheduled_host_down++;
else
(host_is_down == FALSE) ? services_warning_disabled_scheduled++ : services_warning_disabled_scheduled_host_down++;
(host_is_down == FALSE) ? services_warning_scheduled++ : services_warning_scheduled_host_down++;
} else if (temp_servicestatus->problem_has_been_acknowledged == TRUE) {
if (temp_servicestatus->checks_enabled == TRUE)
(host_is_down == FALSE) ? services_warning_active_acknowledged++ : services_warning_active_acknowledged_host_down++;
else if (temp_servicestatus->accept_passive_service_checks == TRUE)
(host_is_down == FALSE) ? services_warning_passive_acknowledged++ : services_warning_passive_acknowledged_host_down++;
else
(host_is_down == FALSE) ? services_warning_disabled_acknowledged++ : services_warning_disabled_acknowledged_host_down++;
(host_is_down == FALSE) ? services_warning_acknowledged++ : services_warning_acknowledged_host_down++;
} else {
if (temp_servicestatus->checks_enabled == TRUE)
(host_is_down == FALSE) ? services_warning_active_unacknowledged++ : services_warning_active_unacknowledged_host_down++;
else if (temp_servicestatus->accept_passive_service_checks == TRUE)
(host_is_down == FALSE) ? services_warning_passive_unacknowledged++ : services_warning_passive_unacknowledged_host_down++;
else
(host_is_down == FALSE) ? services_warning_disabled_unacknowledged++ : services_warning_disabled_unacknowledged_host_down++;
(host_is_down == FALSE) ? services_warning_unacknowledged++ : services_warning_unacknowledged_host_down++;
}
if (temp_servicestatus->checks_enabled == TRUE)
(host_is_down == FALSE) ? services_warning_active++ : services_warning_active_host_down++;
else if (temp_servicestatus->accept_passive_service_checks == TRUE)
(host_is_down == FALSE) ? services_warning_passive++ : services_warning_passive_host_down++;
else
(host_is_down == FALSE) ? services_warning_disabled++ : services_warning_disabled_host_down++;
(host_is_down == FALSE) ? services_warning++ : services_warning_host_down++;
}
else if (temp_servicestatus->status == SERVICE_UNKNOWN) {
if (temp_servicestatus->scheduled_downtime_depth > 0) {
if (temp_servicestatus->checks_enabled == TRUE)
(host_is_down == FALSE) ? services_unknown_active_scheduled++ : services_unknown_active_scheduled_host_down++;
else if (temp_servicestatus->accept_passive_service_checks == TRUE)
(host_is_down == FALSE) ? services_unknown_passive_scheduled++ : services_unknown_passive_scheduled_host_down++;
else
(host_is_down == FALSE) ? services_unknown_disabled_scheduled++ : services_unknown_disabled_scheduled_host_down++;
(host_is_down == FALSE) ? services_unknown_scheduled++ : services_unknown_scheduled_host_down++;
} else if (temp_servicestatus->problem_has_been_acknowledged == TRUE) {
if (temp_servicestatus->checks_enabled == TRUE)
(host_is_down == FALSE) ? services_unknown_active_acknowledged++ : services_unknown_active_acknowledged_host_down++;
else if (temp_servicestatus->accept_passive_service_checks == TRUE)
(host_is_down == FALSE) ? services_unknown_passive_acknowledged++ : services_unknown_passive_acknowledged_host_down++;
else
(host_is_down == FALSE) ? services_unknown_disabled_acknowledged++ : services_unknown_disabled_acknowledged_host_down++;
(host_is_down == FALSE) ? services_unknown_acknowledged++ : services_unknown_acknowledged_host_down++;
} else {
if (temp_servicestatus->checks_enabled == TRUE)
(host_is_down == FALSE) ? services_unknown_active_unacknowledged++ : services_unknown_active_unacknowledged_host_down++;
else if (temp_servicestatus->accept_passive_service_checks == TRUE)
(host_is_down == FALSE) ? services_unknown_passive_unacknowledged++ : services_unknown_passive_unacknowledged_host_down++;
else
(host_is_down == FALSE) ? services_unknown_disabled_unacknowledged++ : services_unknown_disabled_unacknowledged_host_down++;
(host_is_down == FALSE) ? services_unknown_unacknowledged++ : services_unknown_unacknowledged_host_down++;
}
if (temp_servicestatus->checks_enabled == TRUE)
(host_is_down == FALSE) ? services_unknown_active++ : services_unknown_active_host_down++;
else if (temp_servicestatus->accept_passive_service_checks == TRUE)
(host_is_down == FALSE) ? services_unknown_passive++ : services_unknown_passive_host_down++;
else
(host_is_down == FALSE) ? services_unknown_disabled++ : services_unknown_disabled_host_down++;
(host_is_down == FALSE) ? services_unknown++ : services_unknown_host_down++;
}
else if (temp_servicestatus->status == SERVICE_CRITICAL) {
if (temp_servicestatus->scheduled_downtime_depth > 0) {
if (temp_servicestatus->checks_enabled == TRUE)
(host_is_down == FALSE) ? services_critical_active_scheduled++ : services_critical_active_scheduled_host_down++;
else if (temp_servicestatus->accept_passive_service_checks == TRUE)
(host_is_down == FALSE) ? services_critical_passive_scheduled++ : services_critical_passive_scheduled_host_down++;
else
(host_is_down == FALSE) ? services_critical_disabled_scheduled++ : services_critical_disabled_scheduled_host_down++;
(host_is_down == FALSE) ? services_critical_scheduled++ : services_critical_scheduled_host_down++;
} else if (temp_servicestatus->problem_has_been_acknowledged == TRUE) {
if (temp_servicestatus->checks_enabled == TRUE)
(host_is_down == FALSE) ? services_critical_active_acknowledged++ : services_critical_active_acknowledged_host_down++;
else if (temp_servicestatus->accept_passive_service_checks == TRUE)
(host_is_down == FALSE) ? services_critical_passive_acknowledged++ : services_critical_passive_acknowledged_host_down++;
else
(host_is_down == FALSE) ? services_critical_disabled_acknowledged++ : services_critical_disabled_acknowledged_host_down++;
(host_is_down == FALSE) ? services_critical_acknowledged++ : services_critical_acknowledged_host_down++;
} else {
if (temp_servicestatus->checks_enabled == TRUE)
(host_is_down == FALSE) ? services_critical_active_unacknowledged++ : services_critical_active_unacknowledged_host_down++;
else if (temp_servicestatus->accept_passive_service_checks == TRUE)
(host_is_down == FALSE) ? services_critical_passive_unacknowledged++ : services_critical_passive_unacknowledged_host_down++;
else
(host_is_down == FALSE) ? services_critical_disabled_unacknowledged++ : services_critical_disabled_unacknowledged_host_down++;
(host_is_down == FALSE) ? services_critical_unacknowledged++ : services_critical_unacknowledged_host_down++;
}
if (temp_servicestatus->checks_enabled == TRUE)
(host_is_down == FALSE) ? services_critical_active++ : services_critical_active_host_down++;
else if (temp_servicestatus->accept_passive_service_checks == TRUE)
(host_is_down == FALSE) ? services_critical_passive++ : services_critical_passive_host_down++;
else
(host_is_down == FALSE) ? services_critical_disabled++ : services_critical_disabled_host_down++;
(host_is_down == FALSE) ? services_critical++ : services_critical_host_down++;
}
else if (temp_servicestatus->status == SERVICE_PENDING) {
if (temp_servicestatus->checks_enabled == TRUE)
(host_is_down == FALSE) ? services_pending_active++ : services_pending_active_host_down++;
else if (temp_servicestatus->accept_passive_service_checks == TRUE)
(host_is_down == FALSE) ? services_pending_passive++ : services_pending_passive_host_down++;
else
(host_is_down == FALSE) ? services_pending_disabled++ : services_pending_disabled_host_down++;
(host_is_down == FALSE) ? services_pending++ : services_pending_host_down++;
}
/* get health stats */
if (temp_servicestatus->status == SERVICE_OK)
total_service_health += 2;
else if (temp_servicestatus->status == SERVICE_WARNING || temp_servicestatus->status == SERVICE_UNKNOWN)
total_service_health++;
if (temp_servicestatus->status != SERVICE_PENDING)
potential_service_health += 2;
/* calculate execution time and latency stats */
if (temp_servicestatus->checks_enabled == TRUE) {
total_active_service_checks++;
if (temp_servicestatus->accept_passive_service_checks == FALSE)
total_active_service_checks_with_passive_disabled++;
if (min_service_latency == -1.0 || temp_servicestatus->latency < min_service_latency)
min_service_latency = temp_servicestatus->latency;
if (max_service_latency == -1.0 || temp_servicestatus->latency > max_service_latency)
max_service_latency = temp_servicestatus->latency;
if (min_service_execution_time == -1.0 || temp_servicestatus->execution_time < min_service_execution_time)
min_service_execution_time = temp_servicestatus->execution_time;
if (max_service_execution_time == -1.0 || temp_servicestatus->execution_time > max_service_execution_time)
max_service_execution_time = temp_servicestatus->execution_time;
total_service_latency += temp_servicestatus->latency;
total_service_execution_time += temp_servicestatus->execution_time;
} else if (temp_servicestatus->accept_passive_service_checks == TRUE)
total_passive_service_checks++;
else
total_disabled_service_checks++;
total_services++;
}
/* check all hosts */
for (temp_hoststatus = hoststatus_list; temp_hoststatus != NULL; temp_hoststatus = temp_hoststatus->next) {
/* see if user is authorized to view this host */
temp_host = find_host(temp_hoststatus->host_name);
if (is_authorized_for_host(temp_host, ¤t_authdata) == FALSE)
continue;
/* check if only hard states to be shown */
if (tac_show_only_hard_state == TRUE && temp_hoststatus->state_type != HARD_STATE)
continue;
/******** CHECK FEATURES *******/
/* check flapping */
if (temp_hoststatus->flap_detection_enabled == FALSE)
flap_disabled_hosts++;
else if (temp_hoststatus->is_flapping == TRUE)
flapping_hosts++;
/* check notifications */
if (temp_hoststatus->notifications_enabled == FALSE)
notification_disabled_hosts++;
/* check event handler */
if (temp_hoststatus->event_handler_enabled == FALSE)
event_handler_disabled_hosts++;
/********* CHECK STATUS ********/
if (temp_hoststatus->status == HOST_UP) {
if (temp_hoststatus->checks_enabled == TRUE)
hosts_up_active++;
else if (temp_hoststatus->accept_passive_host_checks == TRUE)
hosts_up_passive++;
else
hosts_up_disabled++;
hosts_up++;
}
else if (temp_hoststatus->status == HOST_DOWN) {
if (temp_hoststatus->scheduled_downtime_depth > 0) {
if (temp_hoststatus->checks_enabled == TRUE)
hosts_down_active_scheduled++;
else if (temp_hoststatus->accept_passive_host_checks == TRUE)
hosts_down_passive_scheduled++;
else
hosts_down_disabled_scheduled++;
hosts_down_scheduled++;
} else if (temp_hoststatus->problem_has_been_acknowledged == TRUE) {
if (temp_hoststatus->checks_enabled == TRUE)
hosts_down_active_acknowledged++;
else if (temp_hoststatus->accept_passive_host_checks == TRUE)
hosts_down_passive_acknowledged++;
else
hosts_down_disabled_acknowledged++;
hosts_down_acknowledged++;
} else {
if (temp_hoststatus->checks_enabled == TRUE)
hosts_down_active_unacknowledged++;
else if (temp_hoststatus->accept_passive_host_checks == TRUE)
hosts_down_passive_unacknowledged++;
else
hosts_down_disabled_unacknowledged++;
hosts_down_unacknowledged++;
}
if (temp_hoststatus->checks_enabled == TRUE)
hosts_down_active++;
else if (temp_hoststatus->accept_passive_host_checks == TRUE)
hosts_down_passive++;
else
hosts_down_disabled++;
hosts_down++;
}
else if (temp_hoststatus->status == HOST_UNREACHABLE) {
if (temp_hoststatus->scheduled_downtime_depth > 0) {
if (temp_hoststatus->checks_enabled == TRUE)
hosts_unreachable_active_scheduled++;
else if (temp_hoststatus->accept_passive_host_checks == TRUE)
hosts_unreachable_passive_scheduled++;
else
hosts_unreachable_disabled_scheduled++;
hosts_unreachable_scheduled++;
} else if (temp_hoststatus->problem_has_been_acknowledged == TRUE) {
if (temp_hoststatus->checks_enabled == TRUE)
hosts_unreachable_active_acknowledged++;
else if (temp_hoststatus->accept_passive_host_checks == TRUE)
hosts_unreachable_passive_acknowledged++;
else
hosts_unreachable_disabled_acknowledged++;
hosts_unreachable_acknowledged++;
} else {
if (temp_hoststatus->checks_enabled == TRUE)
hosts_unreachable_active_unacknowledged++;
else if (temp_hoststatus->accept_passive_host_checks == TRUE)
hosts_unreachable_passive_unacknowledged++;
else
hosts_unreachable_disabled_unacknowledged++;
hosts_unreachable_unacknowledged++;
}
if (temp_hoststatus->checks_enabled == TRUE)
hosts_unreachable_active++;
else if (temp_hoststatus->accept_passive_host_checks == TRUE)
hosts_unreachable_passive++;
else
hosts_unreachable_disabled++;
hosts_unreachable++;
}
else if (temp_hoststatus->status == HOST_PENDING) {
if (temp_hoststatus->checks_enabled == TRUE)
hosts_pending_active++;
else if (temp_hoststatus->accept_passive_host_checks == TRUE)
hosts_pending_passive++;
else
hosts_pending_disabled++;
hosts_pending++;
}
/* get health stats */
if (temp_hoststatus->status == HOST_UP)
total_host_health++;
if (temp_hoststatus->status != HOST_PENDING)
potential_host_health++;
/* check type stats */
if (temp_hoststatus->checks_enabled == TRUE) {
total_active_host_checks++;
if (temp_hoststatus->accept_passive_host_checks == FALSE)
total_active_host_checks_with_passive_disabled++;
if (min_host_latency == -1.0 || temp_hoststatus->latency < min_host_latency)
min_host_latency = temp_hoststatus->latency;
if (max_host_latency == -1.0 || temp_hoststatus->latency > max_host_latency)
max_host_latency = temp_hoststatus->latency;
if (min_host_execution_time == -1.0 || temp_hoststatus->execution_time < min_host_execution_time)
min_host_execution_time = temp_hoststatus->execution_time;
if (max_host_execution_time == -1.0 || temp_hoststatus->execution_time > max_host_execution_time)
max_host_execution_time = temp_hoststatus->execution_time;
total_host_latency += temp_hoststatus->latency;
total_host_execution_time += temp_hoststatus->execution_time;
} else if (temp_hoststatus->accept_passive_host_checks == TRUE)
total_passive_host_checks++;
else
total_disabled_host_checks++;
total_hosts++;
}
/* calculate service health */
if (potential_service_health == 0)
percent_service_health = 0.0;
else
percent_service_health = ((double)total_service_health / (double)potential_service_health) * 100.0;
/* calculate host health */
if (potential_host_health == 0)
percent_host_health = 0.0;
else
percent_host_health = ((double)total_host_health / (double)potential_host_health) * 100.0;
/* calculate service latency */
if (total_service_latency == 0L)
average_service_latency = 0.0;
else
average_service_latency = ((double)total_service_latency / (double)total_active_service_checks);
/* calculate host latency */
if (total_host_latency == 0L)
average_host_latency = 0.0;
else
average_host_latency = ((double)total_host_latency / (double)total_active_host_checks);
/* calculate service execution time */
if (total_service_execution_time == 0.0)
average_service_execution_time = 0.0;
else
average_service_execution_time = ((double)total_service_execution_time / (double)total_active_service_checks);
/* calculate host execution time */
if (total_host_execution_time == 0.0)
average_host_execution_time = 0.0;
else
average_host_execution_time = ((double)total_host_execution_time / (double)total_active_host_checks);
return;
}
/* determine what hosts are causing network outages */
void find_hosts_causing_outages(void) {
hoststatus *temp_hoststatus;
hostoutage *temp_hostoutage;
host *temp_host;
/* check all hosts */
for (temp_hoststatus = hoststatus_list; temp_hoststatus != NULL; temp_hoststatus = temp_hoststatus->next) {
/* check only hosts that are not up and not pending */
if (temp_hoststatus->status != HOST_UP && temp_hoststatus->status != HOST_PENDING) {
/* find the host entry */
temp_host = find_host(temp_hoststatus->host_name);
if (temp_host == NULL)
continue;
if (is_authorized_for_host(temp_host, ¤t_authdata) == FALSE)
continue;
/* if the route to this host is not blocked, it is a causing an outage */
if (is_route_to_host_blocked(temp_host) == FALSE)
add_hostoutage(temp_host);
}
}
/* check all hosts that are causing problems and calculate the extent of the problem */
for (temp_hostoutage = hostoutage_list; temp_hostoutage != NULL; temp_hostoutage = temp_hostoutage->next) {
/* calculate the outage effect of this particular hosts */
calculate_outage_effect_of_host(temp_hostoutage->hst, &temp_hostoutage->affected_child_hosts);
if (temp_hostoutage->affected_child_hosts > 1)
total_blocking_outages++;
else
total_nonblocking_outages++;
}
return;
}
/* adds a host outage entry */
void add_hostoutage(host *hst) {
hostoutage *new_hostoutage;
/* allocate memory for a new structure */
new_hostoutage = (hostoutage *)malloc(sizeof(hostoutage));
if (new_hostoutage == NULL)
return;
new_hostoutage->hst = hst;
new_hostoutage->affected_child_hosts = 0;
/* add the structure to the head of the list in memory */
new_hostoutage->next = hostoutage_list;
hostoutage_list = new_hostoutage;
return;
}
/* frees all memory allocated to the host outage list */
void free_hostoutage_list(void) {
hostoutage *this_hostoutage;
hostoutage *next_hostoutage;
for (this_hostoutage = hostoutage_list; this_hostoutage != NULL; this_hostoutage = next_hostoutage) {
next_hostoutage = this_hostoutage->next;
free(this_hostoutage);
}
return;
}
/* calculates network outage effect of a particular host being down or unreachable */
void calculate_outage_effect_of_host(host *hst, int *affected_hosts) {
int total_child_hosts_affected = 0;
int temp_child_hosts_affected = 0;
host *temp_host;
/* find all child hosts of this host */
for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
/* skip this host if it is not a child */
if (is_host_immediate_child_of_host(hst, temp_host) == FALSE)
continue;
/* calculate the outage effect of the child */
calculate_outage_effect_of_host(temp_host, &temp_child_hosts_affected);
/* keep a running total of outage effects */
total_child_hosts_affected += temp_child_hosts_affected;
}
*affected_hosts = total_child_hosts_affected + 1;
return;
}
/* tests whether or not a host is "blocked" by upstream parents (host is already assumed to be down or unreachable) */
int is_route_to_host_blocked(host *hst) {
hostsmember *temp_hostsmember;
hoststatus *temp_hoststatus;
/* if the host has no parents, it is not being blocked by anyone */
if (hst->parent_hosts == NULL)
return FALSE;
/* check all parent hosts */
for (temp_hostsmember = hst->parent_hosts; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
/* find the parent host's status */
temp_hoststatus = find_hoststatus(temp_hostsmember->host_name);
if (temp_hoststatus == NULL)
continue;
/* at least one parent it up (or pending), so this host is not blocked */
if (temp_hoststatus->status == HOST_UP || temp_hoststatus->status == HOST_PENDING)
return FALSE;
}
return TRUE;
}
void display_tac_overview(void) {
char host_health_image[16];
char service_health_image[16];
char *tacheader_color = NULL;
int handled_count = 0;
int problem_found = FALSE;
if (tac_header == TRUE && show_tac_header == FALSE) { // we want the top header, but not the tac version
printf("
", url_images_path, TAC_HEADER_DEFAULT_LOGO, TAC_HEADER_DEFAULT_LOGO_ALT);
return; //we're done here
} else if (tac_header == TRUE && show_tac_header == TRUE) { // we want the tac header
printf("
\n");
}
#ifndef DEBUG
/* check authorization... */
if (display_type == DISPLAY_HOST_TRENDS) {
temp_host = find_host(host_name);
if (is_authorized_for_host(temp_host, ¤t_authdata) == FALSE)
is_authorized = FALSE;
} else if (display_type == DISPLAY_SERVICE_TRENDS) {
temp_service = find_service(host_name, service_desc);
if (is_authorized_for_service(temp_service, ¤t_authdata) == FALSE)
is_authorized = FALSE;
}
if (is_authorized == FALSE) {
if (content_type == HTML_CONTENT) {
if (display_type == DISPLAY_HOST_TRENDS)
print_generic_error_message("It appears as though you are not authorized to view information for the specified host...", NULL, 0);
else
print_generic_error_message("It appears as though you are not authorized to view information for the specified service...", NULL, 0);
}
document_footer(CGI_ID);
free_memory();
return ERROR;
}
#endif
if (timeperiod_type == TIMEPERIOD_NEXTPROBLEM && problem_found == FALSE) {
print_generic_error_message("No problem found between end of display and end of recording.", NULL, 0);
document_footer(CGI_ID);
free_memory();
return ERROR;
}
/* set drawing parameters, etc */
if (small_image == TRUE) {
image_height = 20;
image_width = 500;
} else {
image_height = 300;
image_width = 900;
}
if (display_type == DISPLAY_HOST_TRENDS) {
if (small_image == TRUE) {
drawing_width = SMALL_HOST_DRAWING_WIDTH;
drawing_height = SMALL_HOST_DRAWING_HEIGHT;
drawing_x_offset = SMALL_HOST_DRAWING_X_OFFSET;
drawing_y_offset = SMALL_HOST_DRAWING_Y_OFFSET;
} else {
drawing_width = HOST_DRAWING_WIDTH;
drawing_height = HOST_DRAWING_HEIGHT;
drawing_x_offset = HOST_DRAWING_X_OFFSET;
drawing_y_offset = HOST_DRAWING_Y_OFFSET;
}
} else if (display_type == DISPLAY_SERVICE_TRENDS) {
if (small_image == TRUE) {
drawing_width = SMALL_SVC_DRAWING_WIDTH;
drawing_height = SMALL_SVC_DRAWING_HEIGHT;
drawing_x_offset = SMALL_SVC_DRAWING_X_OFFSET;
drawing_y_offset = SMALL_SVC_DRAWING_Y_OFFSET;
} else {
drawing_width = SVC_DRAWING_WIDTH;
drawing_height = SVC_DRAWING_HEIGHT;
drawing_x_offset = SVC_DRAWING_X_OFFSET;
drawing_y_offset = SVC_DRAWING_Y_OFFSET;
}
}
/* last known state should always be initially set to indeterminate! */
last_known_state = AS_NO_DATA;
/* initialize PNG image */
if (display_type != DISPLAY_NO_TRENDS && content_type == IMAGE_CONTENT) {
if (small_image == TRUE) {
trends_image = gdImageCreate(image_width, image_height);
if (trends_image == NULL) {
#ifdef DEBUG
printf("Error: Could not allocate memory for image\n");
#endif
return ERROR;
}
}
else {
if (display_type == DISPLAY_HOST_TRENDS)
snprintf(image_template, sizeof(image_template) - 1, "%s%s", physical_images_path, TRENDSHOSTS_IMAGE);
else
snprintf(image_template, sizeof(image_template) - 1, "%s%s", physical_images_path, TRENDSSERVICES_IMAGE);
image_template[sizeof(image_template)-1] = '\x0';
/* allocate buffer for storing image */
trends_image = NULL;
image_file = fopen(image_template, "r");
if (image_file != NULL) {
trends_image = gdImageCreateFromPng(image_file);
fclose(image_file);
}
if (trends_image == NULL)
trends_image = gdImageCreate(image_width, image_height);
if (trends_image == NULL) {
#ifdef DEBUG
printf("Error: Could not allocate memory for image\n");
#endif
return ERROR;
}
}
/* allocate colors used for drawing */
color_white = gdImageColorAllocate(trends_image, 255, 255, 255);
color_black = gdImageColorAllocate(trends_image, 0, 0, 0);
color_red = gdImageColorAllocate(trends_image, 255, 0, 0);
color_green = gdImageColorAllocate(trends_image, 0, 210, 0);
color_darkgreen = gdImageColorAllocate(trends_image, 0, 128, 0);
color_yellow = gdImageColorAllocate(trends_image, 176, 178, 20);
color_pink = gdImageColorAllocate(trends_image, 224, 102, 255);
color_darkpink = gdImageColorAllocate(trends_image, 166, 75, 189);
/* set transparency index */
gdImageColorTransparent(trends_image, color_white);
/* make sure the graphic is interlaced */
gdImageInterlace(trends_image, 1);
if (small_image == FALSE) {
/* find the host */
temp_host = find_host(host_name);
/* find the service */
temp_service = find_service(host_name, service_desc);
/* title */
snprintf(start_time, sizeof(start_time) - 1, "%s", ctime(&t1));
start_time[sizeof(start_time)-1] = '\x0';
start_time[strlen(start_time)-1] = '\x0';
snprintf(end_time, sizeof(end_time) - 1, "%s", ctime(&t2));
end_time[sizeof(end_time)-1] = '\x0';
end_time[strlen(end_time)-1] = '\x0';
string_height = gdFontSmall->h;
if (display_type == DISPLAY_HOST_TRENDS)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "State History For Host '%s'", (temp_host->display_name != NULL) ? temp_host->display_name : temp_host->name);
else
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "State History For Service '%s' On Host '%s'", (temp_service->display_name != NULL) ? temp_service->display_name : temp_service->description, (temp_host->display_name != NULL) ? temp_host->display_name : temp_host->name);
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
string_width = gdFontSmall->w * strlen(temp_buffer);
gdImageString(trends_image, gdFontSmall, (drawing_width / 2) - (string_width / 2) + drawing_x_offset, string_height, (unsigned char *)temp_buffer, color_black);
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%s to %s", start_time, end_time);
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
string_width = gdFontSmall->w * strlen(temp_buffer);
gdImageString(trends_image, gdFontSmall, (drawing_width / 2) - (string_width / 2) + drawing_x_offset, (string_height * 2) + 5, (unsigned char *)temp_buffer, color_black);
/* first time stamp */
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%s", start_time);
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
string_width = gdFontSmall->w * strlen(temp_buffer);
gdImageStringUp(trends_image, gdFontSmall, drawing_x_offset - (string_height / 2), drawing_y_offset + drawing_height + string_width + 5, (unsigned char *)temp_buffer, color_black);
}
}
if (display_type != DISPLAY_NO_TRENDS && input_type == GET_INPUT_NONE) {
if (content_type == IMAGE_CONTENT || (content_type == HTML_CONTENT && use_map == TRUE)) {
/* read in all necessary archived state data */
read_archived_state_data();
/* graph archived state trend data */
graph_all_trend_data();
}
/* print URL to image */
if (content_type == HTML_CONTENT) {
printf("
\n");
printf("
\n");
printf("\n", image_width);
printf("
\n");
}
if (content_type == IMAGE_CONTENT || (content_type == HTML_CONTENT && use_map == TRUE)) {
/* draw timestamps */
draw_timestamps();
/* draw horizontal lines */
draw_horizontal_grid_lines();
/* draw state time breakdowns */
draw_time_breakdowns();
}
if (content_type == IMAGE_CONTENT) {
/* use STDOUT for writing the image data... */
image_file = stdout;
#ifndef DEBUG
/* write the image to file */
gdImagePng(trends_image, image_file);
#endif
#ifdef DEBUG
if (display_type == DISPLAY_HOST_TRENDS)
snprintf(image_template, sizeof(image_template) - 1, "/tmp/%s", TRENDSHOSTS_IMAGE);
else
snprintf(image_template, sizeof(image_template) - 1, "/tmp/%s", TRENDSSERVICES_IMAGE);
image_template[sizeof(image_template)-1] = '\x0';
image_file = fopen(image_template, "w");
if (image_file == NULL)
printf("Could not open \"%s\" for writing!\n", image_template);
else {
gdImagePng(trends_image, image_file);
fclose(image_file);
}
#endif
/* free memory allocated to image */
gdImageDestroy(trends_image);
}
}
/* show user a selection of hosts and services to choose from... */
if (display_type == DISPLAY_NO_TRENDS || input_type != GET_INPUT_NONE) {
/* ask the user for what host they want a report for */
if (input_type == GET_INPUT_HOST_TARGET) {
printf("
Step 2: Select Host
\n");
printf("\n");
}
/* ask the user for what service they want a report for */
else if (input_type == GET_INPUT_SERVICE_TARGET) {
printf("
Step 2: Select Service
\n");
printf("\n");
}
/* ask the user for report range and options */
else if (input_type == GET_INPUT_OPTIONS) {
time(¤t_time);
t = localtime(¤t_time);
start_day = 1;
start_year = t->tm_year + 1900;
end_day = t->tm_mday;
end_year = t->tm_year + 1900;
printf("
Step 3: Select Report Options
\n");
printf("\n");
/*
printf("
\n");
printf("Note: Choosing the 'suppress image map' option will make the report run approximately twice as fast as it would otherwise, but it will prevent you from being able to zoom in on specific time periods.\n");
printf("
\n");
*/
}
/* as the user whether they want a graph for a host or service */
else {
printf("
Step 1: Select Report Type
\n");
printf("\n");
}
}
document_footer(CGI_ID);
/* free memory allocated to the archived state data list */
free_archived_state_list();
/* free all other allocated memory */
free_memory();
return OK;
}
int process_cgivars(void) {
char **variables;
char *temp_buffer = NULL;
int error = FALSE;
int x;
variables = getcgivars();
for (x = 0; variables[x] != NULL; x++) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */
if (strlen(variables[x]) >= MAX_INPUT_BUFFER - 1)
continue;
/* we found the host argument */
else if (!strcmp(variables[x], "host")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((host_name = (char *)strdup(variables[x])) == NULL)
host_name = "";
strip_html_brackets(host_name);
display_type = DISPLAY_HOST_TRENDS;
}
/* we found the node width argument */
else if (!strcmp(variables[x], "service")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if ((service_desc = (char *)strdup(variables[x])) == NULL)
service_desc = "";
strip_html_brackets(service_desc);
display_type = DISPLAY_SERVICE_TRENDS;
}
/* we found a combined host/service */
else if (!strcmp(variables[x], "hostservice")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
temp_buffer = strtok(variables[x], "^");
if ((host_name = (char *)strdup(temp_buffer)) == NULL)
host_name = "";
else
strip_html_brackets(host_name);
temp_buffer = strtok(NULL, "");
if ((service_desc = (char *)strdup(temp_buffer)) == NULL)
service_desc = "";
else
strip_html_brackets(service_desc);
display_type = DISPLAY_SERVICE_TRENDS;
}
/* we found first time argument */
else if (!strcmp(variables[x], "t1")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
t1 = (time_t)strtoul(variables[x], NULL, 10);
timeperiod_type = TIMEPERIOD_CUSTOM;
}
/* we found first time argument */
else if (!strcmp(variables[x], "t2")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
t2 = (time_t)strtoul(variables[x], NULL, 10);
timeperiod_type = TIMEPERIOD_CUSTOM;
}
/* we found the image creation option */
else if (!strcmp(variables[x], "createimage")) {
content_type = IMAGE_CONTENT;
}
/* we found the assume initial states option */
else if (!strcmp(variables[x], "assumeinitialstates")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "yes"))
assume_initial_states = TRUE;
else
assume_initial_states = FALSE;
}
/* we found the initial assumed host state option */
else if (!strcmp(variables[x], "initialassumedhoststate")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
initial_assumed_host_state = atoi(variables[x]);
}
/* we found the initial assumed service state option */
else if (!strcmp(variables[x], "initialassumedservicestate")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
initial_assumed_service_state = atoi(variables[x]);
}
/* we found the assume state during program not running option */
else if (!strcmp(variables[x], "assumestatesduringnotrunning")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "yes"))
assume_states_during_notrunning = TRUE;
else
assume_states_during_notrunning = FALSE;
}
/* we found the assume state retention option */
else if (!strcmp(variables[x], "assumestateretention")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "yes"))
assume_state_retention = TRUE;
else
assume_state_retention = FALSE;
}
/* we found the include soft states option */
else if (!strcmp(variables[x], "includesoftstates")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "yes"))
include_soft_states = TRUE;
else
include_soft_states = FALSE;
}
/* we found the zoom factor argument */
else if (!strcmp(variables[x], "zoom")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
zoom_factor = atoi(variables[x]);
if (zoom_factor == 0)
zoom_factor = 1;
}
/* we found the backtrack archives argument */
else if (!strcmp(variables[x], "backtrack")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
backtrack_archives = atoi(variables[x]);
if (backtrack_archives < 0)
backtrack_archives = 0;
if (backtrack_archives > MAX_ARCHIVE_BACKTRACKS)
backtrack_archives = MAX_ARCHIVE_BACKTRACKS;
}
/* we found the standard timeperiod argument */
else if (!strcmp(variables[x], "timeperiod")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "today"))
timeperiod_type = TIMEPERIOD_TODAY;
else if (!strcmp(variables[x], "yesterday"))
timeperiod_type = TIMEPERIOD_YESTERDAY;
else if (!strcmp(variables[x], "thisweek"))
timeperiod_type = TIMEPERIOD_THISWEEK;
else if (!strcmp(variables[x], "lastweek"))
timeperiod_type = TIMEPERIOD_LASTWEEK;
else if (!strcmp(variables[x], "thismonth"))
timeperiod_type = TIMEPERIOD_THISMONTH;
else if (!strcmp(variables[x], "lastmonth"))
timeperiod_type = TIMEPERIOD_LASTMONTH;
else if (!strcmp(variables[x], "thisquarter"))
timeperiod_type = TIMEPERIOD_THISQUARTER;
else if (!strcmp(variables[x], "lastquarter"))
timeperiod_type = TIMEPERIOD_LASTQUARTER;
else if (!strcmp(variables[x], "thisyear"))
timeperiod_type = TIMEPERIOD_THISYEAR;
else if (!strcmp(variables[x], "lastyear"))
timeperiod_type = TIMEPERIOD_LASTYEAR;
else if (!strcmp(variables[x], "nextproblem"))
timeperiod_type = TIMEPERIOD_NEXTPROBLEM;
else if (!strcmp(variables[x], "last24hours"))
timeperiod_type = TIMEPERIOD_LAST24HOURS;
else if (!strcmp(variables[x], "last7days"))
timeperiod_type = TIMEPERIOD_LAST7DAYS;
else if (!strcmp(variables[x], "last31days"))
timeperiod_type = TIMEPERIOD_LAST31DAYS;
else if (!strcmp(variables[x], "custom"))
timeperiod_type = TIMEPERIOD_CUSTOM;
else
continue;
convert_timeperiod_to_times(timeperiod_type, &t1, &t2);
}
/* we found time argument */
else if (!strcmp(variables[x], "smon")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
start_month = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "sday")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
start_day = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "syear")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
start_year = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "smin")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
start_minute = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "ssec")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
start_second = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "shour")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
start_hour = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "emon")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
end_month = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "eday")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
end_day = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "eyear")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
end_year = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "emin")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
end_minute = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "esec")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
end_second = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found time argument */
else if (!strcmp(variables[x], "ehour")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (timeperiod_type != TIMEPERIOD_CUSTOM)
continue;
end_hour = atoi(variables[x]);
timeperiod_type = TIMEPERIOD_CUSTOM;
compute_time_from_parts = TRUE;
}
/* we found the embed option */
else if (!strcmp(variables[x], "embedded"))
embedded = TRUE;
/* we found the noheader option */
else if (!strcmp(variables[x], "noheader"))
display_header = FALSE;
/* we found the nopopups option */
else if (!strcmp(variables[x], "nopopups"))
display_popups = FALSE;
/* we found the nomap option */
else if (!strcmp(variables[x], "nomap")) {
display_popups = FALSE;
use_map = FALSE;
}
/* we found the input option */
else if (!strcmp(variables[x], "input")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
if (!strcmp(variables[x], "gethost"))
input_type = GET_INPUT_HOST_TARGET;
else if (!strcmp(variables[x], "getservice"))
input_type = GET_INPUT_SERVICE_TARGET;
else if (!strcmp(variables[x], "getoptions"))
input_type = GET_INPUT_OPTIONS;
else
input_type = GET_INPUT_TARGET_TYPE;
}
/* we found the small image option */
else if (!strcmp(variables[x], "smallimage"))
small_image = TRUE;
/* we found the nodaemoncheck option */
else if (!strcmp(variables[x], "nodaemoncheck"))
daemon_check = FALSE;
else if (!strcmp(variables[x], "ignorerestart"))
ignore_daemon_restart = TRUE;
}
/* free memory allocated to the CGI variables */
free_cgivars(variables);
return error;
}
/* top level routine for graphic all trend data */
void graph_all_trend_data(void) {
archived_state *temp_as;
archived_state *last_as;
time_t a;
time_t b;
time_t current_time;
int current_state = AS_NO_DATA;
int have_some_real_data = FALSE;
hoststatus *hststatus = NULL;
servicestatus *svcstatus = NULL;
unsigned long wobble = 300;
// int first_real_state = AS_NO_DATA; <- unused, but why, FIXME
time_t initial_assumed_time;
int initial_assumed_state = AS_SVC_OK;
int error = FALSE;
time(¤t_time);
/* if left hand of graph is after current time, we can't do anything at all.... */
if (t1 > current_time)
return;
/* find current state for host or service */
if (display_type == DISPLAY_HOST_TRENDS)
hststatus = find_hoststatus(host_name);
else
svcstatus = find_servicestatus(host_name, service_desc);
/************************************/
/* INSERT CURRENT STATE (IF WE CAN) */
/************************************/
/* if current time DOES NOT fall within graph bounds, so we can't do anything as far as assuming current state */
/* the "wobble" value is necessary because when the CGI is called to do the PNG generation, t2 will actually be less that current_time by a bit */
/* if we don't have any data, assume current state (if possible) */
if (as_list == NULL && current_time > t1 && current_time < (t2 + wobble)) {
/* we don't have any historical information, but the current time falls within the reporting period, so use */
/* the current status of the host/service as the starting data */
if (display_type == DISPLAY_HOST_TRENDS) {
if (hststatus != NULL) {
if (hststatus->status == HOST_DOWN)
last_known_state = AS_HOST_DOWN;
else if (hststatus->status == HOST_UNREACHABLE)
last_known_state = AS_HOST_UNREACHABLE;
else
last_known_state = AS_HOST_UP;
/* add a dummy archived state item, so something can get graphed */
add_archived_state(last_known_state, AS_HARD_STATE, t1, "Current Host State Assumed (Faked Log Entry)");
/* use the current state as the last known real state */
// first_real_state = last_known_state;
}
} else {
if (svcstatus != NULL) {
if (svcstatus->status == SERVICE_OK)
last_known_state = AS_SVC_OK;
else if (svcstatus->status == SERVICE_WARNING)
last_known_state = AS_SVC_WARNING;
else if (svcstatus->status == SERVICE_CRITICAL)
last_known_state = AS_SVC_CRITICAL;
else if (svcstatus->status == SERVICE_UNKNOWN)
last_known_state = AS_SVC_UNKNOWN;
/* add a dummy archived state item, so something can get graphed */
add_archived_state(last_known_state, AS_HARD_STATE, t1, "Current Service State Assumed (Faked Log Entry)");
/* use the current state as the last known real state */
// first_real_state = last_known_state;
}
}
}
/******************************************/
/* INSERT FIRST ASSUMED STATE (IF WE CAN) */
/******************************************/
if ((display_type == DISPLAY_HOST_TRENDS && initial_assumed_host_state != AS_NO_DATA) || (display_type == DISPLAY_SERVICE_TRENDS && initial_assumed_service_state != AS_NO_DATA)) {
/* see if its okay to assume initial state for this subject */
error = FALSE;
if (display_type == DISPLAY_SERVICE_TRENDS) {
if (initial_assumed_service_state != AS_SVC_OK && initial_assumed_service_state != AS_SVC_WARNING && initial_assumed_service_state != AS_SVC_UNKNOWN && initial_assumed_service_state != AS_SVC_CRITICAL && initial_assumed_service_state != AS_CURRENT_STATE)
error = TRUE;
else
initial_assumed_state = initial_assumed_service_state;
if (initial_assumed_service_state == AS_CURRENT_STATE && svcstatus == NULL)
error = TRUE;
} else {
if (initial_assumed_host_state != AS_HOST_UP && initial_assumed_host_state != AS_HOST_DOWN && initial_assumed_host_state != AS_HOST_UNREACHABLE && initial_assumed_host_state != AS_CURRENT_STATE)
error = TRUE;
else
initial_assumed_state = initial_assumed_host_state;
if (initial_assumed_host_state == AS_CURRENT_STATE && hststatus == NULL)
error = TRUE;
}
/* get the current state if applicable */
if (((display_type == DISPLAY_HOST_TRENDS && initial_assumed_host_state == AS_CURRENT_STATE) || (display_type == DISPLAY_SERVICE_TRENDS && initial_assumed_service_state == AS_CURRENT_STATE)) && error == FALSE) {
if (display_type == DISPLAY_HOST_TRENDS) {
switch (hststatus->status) {
case HOST_DOWN:
initial_assumed_state = AS_HOST_DOWN;
break;
case HOST_UNREACHABLE:
initial_assumed_state = AS_HOST_UNREACHABLE;
break;
case HOST_UP:
initial_assumed_state = AS_HOST_UP;
break;
default:
error = TRUE;
break;
}
} else {
switch (svcstatus->status) {
case SERVICE_OK:
initial_assumed_state = AS_SVC_OK;
break;
case SERVICE_WARNING:
initial_assumed_state = AS_SVC_WARNING;
break;
case SERVICE_UNKNOWN:
initial_assumed_state = AS_SVC_UNKNOWN;
break;
case SERVICE_CRITICAL:
initial_assumed_state = AS_SVC_CRITICAL;
break;
default:
error = TRUE;
break;
}
}
}
if (error == FALSE) {
/* add this assumed state entry before any entries in the list and <= t1 */
if (as_list == NULL)
initial_assumed_time = t1;
else if (as_list->time_stamp > t1)
initial_assumed_time = t1;
else
initial_assumed_time = as_list->time_stamp - 1;
if (display_type == DISPLAY_HOST_TRENDS)
add_archived_state(initial_assumed_state, AS_HARD_STATE, initial_assumed_time, "First Host State Assumed (Faked Log Entry)");
else
add_archived_state(initial_assumed_state, AS_HARD_STATE, initial_assumed_time, "First Service State Assumed (Faked Log Entry)");
}
}
/**************************************/
/* BAIL OUT IF WE DON'T HAVE ANYTHING */
/**************************************/
have_some_real_data = FALSE;
for (temp_as = as_list; temp_as != NULL; temp_as = temp_as->next) {
if (temp_as->entry_type != AS_NO_DATA && temp_as->entry_type != AS_PROGRAM_START && temp_as->entry_type != AS_PROGRAM_END) {
have_some_real_data = TRUE;
break;
}
}
if (have_some_real_data == FALSE)
return;
/* if we're creating the HTML, start map code... */
if (content_type == HTML_CONTENT)
printf("\n");
return;
}
/* graphs trend data */
void graph_trend_data(int first_state, int last_state, time_t real_start_time, time_t start_time, time_t end_time, char *state_info) {
int start_state;
// int end_state; <- unused, but why, FIXME
int start_pixel = 0;
int end_pixel = 0;
int color_to_use = 0;
int height = 0;
double start_pixel_ratio;
double end_pixel_ratio;
char temp_buffer[MAX_INPUT_BUFFER];
char state_string[MAX_INPUT_BUFFER];
char end_timestring[MAX_INPUT_BUFFER];
char start_timestring[MAX_INPUT_BUFFER];
time_t center_time;
time_t next_start_time;
time_t next_end_time;
int days = 0;
int hours = 0;
int minutes = 0;
int seconds = 0;
/* can't graph if we don't have data... */
if (first_state == AS_NO_DATA || last_state == AS_NO_DATA)
return;
if (first_state == AS_PROGRAM_START && (last_state == AS_PROGRAM_END || last_state == AS_PROGRAM_START)) {
if (assume_initial_states == FALSE)
return;
}
if (first_state == AS_PROGRAM_END) {
if (assume_states_during_notrunning == TRUE)
first_state = last_known_state;
else
return;
}
/* special case if first entry was program start */
if (first_state == AS_PROGRAM_START) {
#ifdef DEBUG
printf("First state=program start!\n");
#endif
if (assume_initial_states == TRUE) {
#ifdef DEBUG
printf("\tWe are assuming initial states...\n");
#endif
if (assume_state_retention == TRUE) {
start_state = last_known_state;
#ifdef DEBUG
printf("\tWe are assuming state retention (%d)...\n", start_state);
#endif
} else {
#ifdef DEBUG
printf("\tWe are NOT assuming state retention...\n");
#endif
if (display_type == DISPLAY_HOST_TRENDS)
start_state = AS_HOST_UP;
else
start_state = AS_SVC_OK;
}
} else {
#ifdef DEBUG
printf("We ARE NOT assuming initial states!\n");
#endif
return;
}
} else {
start_state = first_state;
last_known_state = first_state;
}
/* special case if last entry was program stop */
// if (last_state == AS_PROGRAM_END)
// end_state = first_state;
// else
// end_state = last_state;
#ifdef DEBUG
printf("Graphing state %d\n", start_state);
printf("\tfrom %s", ctime(&start_time));
printf("\tto %s", ctime(&end_time));
#endif
if (start_time < t1)
start_time = t1;
if (end_time > t2)
end_time = t2;
if (end_time < t1 || start_time > t2)
return;
/* calculate the first and last pixels to use */
if (start_time == t1)
start_pixel = 0;
else {
start_pixel_ratio = ((double)(start_time - t1)) / ((double)(t2 - t1));
start_pixel = (int)(start_pixel_ratio * (drawing_width - 1));
}
if (end_time == t1)
end_pixel = 0;
else {
end_pixel_ratio = ((double)(end_time - t1)) / ((double)(t2 - t1));
end_pixel = (int)(end_pixel_ratio * (drawing_width - 1));
}
#ifdef DEBUG
printf("\tPixel %d to %d\n\n", start_pixel, end_pixel);
#endif
/* we're creating the image, so draw... */
if (content_type == IMAGE_CONTENT) {
/* figure out the color to use for drawing */
switch (start_state) {
case AS_HOST_UP:
color_to_use = color_green;
height = 60;
break;
case AS_HOST_DOWN:
color_to_use = color_red;
height = 40;
break;
case AS_HOST_UNREACHABLE:
color_to_use = color_pink;
height = 20;
break;
case AS_SVC_OK:
color_to_use = color_green;
height = 80;
break;
case AS_SVC_WARNING:
color_to_use = color_yellow;
height = 60;
break;
case AS_SVC_UNKNOWN:
color_to_use = color_pink;
height = 40;
break;
case AS_SVC_CRITICAL:
color_to_use = color_red;
height = 20;
break;
default:
color_to_use = color_black;
height = 0;
break;
}
/* draw a rectangle */
if (start_state != AS_NO_DATA)
gdImageFilledRectangle(trends_image, start_pixel + drawing_x_offset, drawing_height - height + drawing_y_offset, end_pixel + drawing_x_offset, drawing_height + drawing_y_offset, color_to_use);
}
/* else we're creating the HTML, so write map area code... */
else {
/* figure out the the state string to use */
switch (start_state) {
case AS_HOST_UP:
strcpy(state_string, "UP");
height = 60;
break;
case AS_HOST_DOWN:
strcpy(state_string, "DOWN");
height = 40;
break;
case AS_HOST_UNREACHABLE:
strcpy(state_string, "UNREACHABLE");
height = 20;
break;
case AS_SVC_OK:
strcpy(state_string, "OK");
height = 80;
break;
case AS_SVC_WARNING:
strcpy(state_string, "WARNING");
height = 60;
break;
case AS_SVC_UNKNOWN:
strcpy(state_string, "UNKNOWN");
height = 40;
break;
case AS_SVC_CRITICAL:
strcpy(state_string, "CRITICAL");
height = 20;
break;
default:
strcpy(state_string, "?");
height = 5;
break;
}
/* get the center of this time range */
center_time = start_time + ((end_time - start_time) / 2);
/* determine next start and end time range with zoom factor */
if (zoom_factor > 0) {
next_start_time = center_time - (((t2 - t1) / 2) / zoom_factor);
next_end_time = center_time + (((t2 - t1) / 2) / zoom_factor);
} else {
next_start_time = center_time + (((t2 - t1) / 2) * zoom_factor);
next_end_time = center_time - (((t2 - t1) / 2) * zoom_factor);
}
printf(" 0)
printf("&backtrack=%d", backtrack_archives);
printf("&zoom=%d", zoom_factor);
printf("' ");
/* display popup text */
if (display_popups == TRUE) {
snprintf(start_timestring, sizeof(start_timestring) - 1, "%s", ctime(&real_start_time));
start_timestring[sizeof(start_timestring)-1] = '\x0';
start_timestring[strlen(start_timestring)-1] = '\x0';
snprintf(end_timestring, sizeof(end_timestring) - 1, "%s", ctime(&end_time));
end_timestring[sizeof(end_timestring)-1] = '\x0';
end_timestring[strlen(end_timestring)-1] = '\x0';
/* calculate total time in this state */
get_time_breakdown((time_t)(end_time - start_time), &days, &hours, &minutes, &seconds);
/* sanitize plugin output */
sanitize_plugin_output(state_info);
printf("onMouseOver='showPopup(\"");
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%s Time Range: %s to %s Duration: %dd %dh %dm %ds State Info: %s", state_string, start_timestring, end_timestring, days, hours, minutes, seconds, (state_info == NULL) ? "N/A" : state_info);
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
printf("%s", temp_buffer);
printf("\",event)' onMouseOut='hidePopup()'");
}
printf(">\n");
}
/* calculate time in this state */
switch (start_state) {
case AS_HOST_UP:
time_up += (unsigned long)(end_time - start_time);
break;
case AS_HOST_DOWN:
time_down += (unsigned long)(end_time - start_time);
break;
case AS_HOST_UNREACHABLE:
time_unreachable += (unsigned long)(end_time - start_time);
break;
case AS_SVC_OK:
time_ok += (unsigned long)(end_time - start_time);
break;
case AS_SVC_WARNING:
time_warning += (unsigned long)(end_time - start_time);
break;
case AS_SVC_UNKNOWN:
time_unknown += (unsigned long)(end_time - start_time);
break;
case AS_SVC_CRITICAL:
time_critical += (unsigned long)(end_time - start_time);
break;
default:
break;
}
return;
}
/* convert current host state to archived state value */
int convert_host_state_to_archived_state(int current_status) {
if (current_status == HOST_UP)
return AS_HOST_UP;
if (current_status == HOST_DOWN)
return AS_HOST_DOWN;
if (current_status == HOST_UNREACHABLE)
return AS_HOST_UNREACHABLE;
return AS_NO_DATA;
}
/* convert current service state to archived state value */
int convert_service_state_to_archived_state(int current_status) {
if (current_status == SERVICE_OK)
return AS_SVC_OK;
if (current_status == SERVICE_UNKNOWN)
return AS_SVC_UNKNOWN;
if (current_status == SERVICE_WARNING)
return AS_SVC_WARNING;
if (current_status == SERVICE_CRITICAL)
return AS_SVC_CRITICAL;
return AS_NO_DATA;
}
/* adds an archived state entry */
void add_archived_state(int entry_type, int state_type, time_t time_stamp, char *state_info) {
archived_state *last_as = NULL;
archived_state *temp_as = NULL;
archived_state *new_as = NULL;
#ifdef DEBUG
printf("Added state %d @ %s", state_type, ctime(&time_stamp));
#endif
/* allocate memory for the new entry */
new_as = (archived_state *)malloc(sizeof(archived_state));
if (new_as == NULL)
return;
/* allocate memory fo the state info */
if (state_info != NULL) {
new_as->state_info = (char *)malloc(strlen(state_info) + 1);
if (new_as->state_info != NULL)
strcpy(new_as->state_info, state_info);
} else new_as->state_info = NULL;
new_as->entry_type = entry_type;
new_as->processed_state = entry_type;
new_as->state_type = state_type;
new_as->time_stamp = time_stamp;
/* add the new entry to the list in memory, sorted by time */
last_as = as_list;
for (temp_as = as_list; temp_as != NULL; temp_as = temp_as->next) {
if (new_as->time_stamp < temp_as->time_stamp) {
new_as->next = temp_as;
if (temp_as == as_list)
as_list = new_as;
else
last_as->next = new_as;
break;
} else
last_as = temp_as;
}
if (as_list == NULL) {
new_as->next = NULL;
as_list = new_as;
} else if (temp_as == NULL) {
new_as->next = NULL;
last_as->next = new_as;
}
return;
}
/* frees memory allocated to the archived state list */
void free_archived_state_list(void) {
archived_state *this_as = NULL;
archived_state *next_as = NULL;
for (this_as = as_list; this_as != NULL;) {
next_as = this_as->next;
if (this_as->state_info != NULL)
free(this_as->state_info);
free(this_as);
this_as = next_as;
}
as_list = NULL;
return;
}
/* reads log files for archived state data */
void read_archived_state_data(void) {
char entry_host_name[MAX_INPUT_BUFFER];
char entry_service_desc[MAX_INPUT_BUFFER];
char *plugin_output = NULL;
char *temp_buffer = NULL;
char *error_text = NULL;
logentry *temp_entry = NULL;
logentry *entry_list = NULL;
logfilter *filter_list = NULL;
int state_type = 0;
int status = READLOG_OK;
/* print something so browser doesn't time out */
if (content_type == HTML_CONTENT) {
printf(" ");
fflush(NULL);
}
/* Service filter */
add_log_filter(&filter_list, LOGENTRY_SERVICE_OK, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_WARNING, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_CRITICAL, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_UNKNOWN, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_RECOVERY, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_INITIAL_STATE, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_CURRENT_STATE, LOGFILTER_INCLUDE);
/* Host filter */
add_log_filter(&filter_list, LOGENTRY_HOST_UP, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_DOWN, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_UNREACHABLE, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_RECOVERY, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_INITIAL_STATE, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_HOST_CURRENT_STATE, LOGFILTER_INCLUDE);
if (ignore_daemon_restart == FALSE) {
add_log_filter(&filter_list, LOGENTRY_STARTUP, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_RESTART, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SHUTDOWN, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_BAILOUT, LOGFILTER_INCLUDE);
}
status = get_log_entries(&entry_list, &filter_list, &error_text, NULL, FALSE, t1 - get_backtrack_seconds(backtrack_archives), t2);
free_log_filters(&filter_list);
if (status != READLOG_ERROR_FATAL) {
for (temp_entry = entry_list; temp_entry != NULL; temp_entry = temp_entry->next) {
if (ignore_daemon_restart == FALSE) {
/* program starts/restarts */
if (temp_entry->type == LOGENTRY_STARTUP)
add_archived_state(AS_PROGRAM_START, AS_NO_DATA, temp_entry->timestamp, "Program start");
if (temp_entry->type == LOGENTRY_RESTART)
add_archived_state(AS_PROGRAM_START, AS_NO_DATA, temp_entry->timestamp, "Program restart");
/* program stops */
if (temp_entry->type == LOGENTRY_SHUTDOWN)
add_archived_state(AS_PROGRAM_END, AS_NO_DATA, temp_entry->timestamp, "Normal program termination");
if (temp_entry->type == LOGENTRY_BAILOUT)
add_archived_state(AS_PROGRAM_END, AS_NO_DATA, temp_entry->timestamp, "Abnormal program termination");
}
if (display_type == DISPLAY_HOST_TRENDS) {
switch (temp_entry->type) {
/* normal host alerts and initial/current states */
case LOGENTRY_HOST_DOWN:
case LOGENTRY_HOST_UNREACHABLE:
case LOGENTRY_HOST_RECOVERY:
case LOGENTRY_HOST_UP:
case LOGENTRY_HOST_INITIAL_STATE:
case LOGENTRY_HOST_CURRENT_STATE:
/* get host name */
temp_buffer = my_strtok(temp_entry->entry_text, ":");
temp_buffer = my_strtok(NULL, ";");
strncpy(entry_host_name, (temp_buffer == NULL) ? "" : temp_buffer + 1, sizeof(entry_host_name));
entry_host_name[sizeof(entry_host_name)-1] = '\x0';
if (strcmp(host_name, entry_host_name))
break;
/* state types */
if (strstr(temp_entry->entry_text, ";SOFT;")) {
if (include_soft_states == FALSE)
break;
state_type = AS_SOFT_STATE;
}
if (strstr(temp_entry->entry_text, ";HARD;"))
state_type = AS_HARD_STATE;
/* get the plugin output */
temp_buffer = my_strtok(NULL, ";");
temp_buffer = my_strtok(NULL, ";");
temp_buffer = my_strtok(NULL, ";");
plugin_output = my_strtok(NULL, "\n");
if (strstr(temp_entry->entry_text, ";DOWN;"))
add_archived_state(AS_HOST_DOWN, state_type, temp_entry->timestamp, plugin_output);
else if (strstr(temp_entry->entry_text, ";UNREACHABLE;"))
add_archived_state(AS_HOST_UNREACHABLE, state_type, temp_entry->timestamp, plugin_output);
else if (strstr(temp_entry->entry_text, ";RECOVERY;") || strstr(temp_entry->entry_text, ";UP;"))
add_archived_state(AS_HOST_UP, state_type, temp_entry->timestamp, plugin_output);
else
add_archived_state(AS_NO_DATA, AS_NO_DATA, temp_entry->timestamp, plugin_output);
break;
}
}
if (display_type == DISPLAY_SERVICE_TRENDS) {
switch (temp_entry->type) {
/* normal service alerts and initial/current states */
case LOGENTRY_SERVICE_CRITICAL:
case LOGENTRY_SERVICE_WARNING:
case LOGENTRY_SERVICE_UNKNOWN:
case LOGENTRY_SERVICE_RECOVERY:
case LOGENTRY_SERVICE_OK:
case LOGENTRY_SERVICE_INITIAL_STATE:
case LOGENTRY_SERVICE_CURRENT_STATE:
/* get host name */
temp_buffer = my_strtok(temp_entry->entry_text, ":");
temp_buffer = my_strtok(NULL, ";");
strncpy(entry_host_name, (temp_buffer == NULL) ? "" : temp_buffer + 1, sizeof(entry_host_name));
entry_host_name[sizeof(entry_host_name)-1] = '\x0';
if (strcmp(host_name, entry_host_name))
break;
/* get service description */
temp_buffer = my_strtok(NULL, ";");
strncpy(entry_service_desc, (temp_buffer == NULL) ? "" : temp_buffer, sizeof(entry_service_desc));
entry_service_desc[sizeof(entry_service_desc)-1] = '\x0';
if (strcmp(service_desc, entry_service_desc))
break;
/* state types */
if (strstr(temp_entry->entry_text, ";SOFT;")) {
if (include_soft_states == FALSE)
break;
state_type = AS_SOFT_STATE;
}
if (strstr(temp_entry->entry_text, ";HARD;"))
state_type = AS_HARD_STATE;
/* get the plugin output */
temp_buffer = my_strtok(NULL, ";");
temp_buffer = my_strtok(NULL, ";");
temp_buffer = my_strtok(NULL, ";");
plugin_output = my_strtok(NULL, "\n");
if (strstr(temp_entry->entry_text, ";CRITICAL;"))
add_archived_state(AS_SVC_CRITICAL, state_type, temp_entry->timestamp, plugin_output);
else if (strstr(temp_entry->entry_text, ";WARNING;"))
add_archived_state(AS_SVC_WARNING, state_type, temp_entry->timestamp, plugin_output);
else if (strstr(temp_entry->entry_text, ";UNKNOWN;"))
add_archived_state(AS_SVC_UNKNOWN, state_type, temp_entry->timestamp, plugin_output);
else if (strstr(temp_entry->entry_text, ";RECOVERY;") || strstr(temp_entry->entry_text, ";OK;"))
add_archived_state(AS_SVC_OK, state_type, temp_entry->timestamp, plugin_output);
else
add_archived_state(AS_NO_DATA, AS_NO_DATA, temp_entry->timestamp, plugin_output);
break;
}
}
}
free_log_entries(&entry_list);
}
return;
}
/* write timestamps */
void draw_timestamps(void) {
int last_timestamp = 0;
archived_state *temp_as;
double start_pixel_ratio;
int start_pixel;
if (content_type != IMAGE_CONTENT)
return;
/* draw first timestamp */
draw_timestamp(0, t1);
last_timestamp = 0;
for (temp_as = as_list; temp_as != NULL; temp_as = temp_as->next) {
if (temp_as->time_stamp < t1 || temp_as->time_stamp > t2)
continue;
start_pixel_ratio = ((double)(temp_as->time_stamp - t1)) / ((double)(t2 - t1));
start_pixel = (int)(start_pixel_ratio * (drawing_width - 1));
/* draw start timestamp if possible */
if ((start_pixel > last_timestamp + MIN_TIMESTAMP_SPACING) && (start_pixel < drawing_width - 1 - MIN_TIMESTAMP_SPACING)) {
draw_timestamp(start_pixel, temp_as->time_stamp);
last_timestamp = start_pixel;
}
}
/* draw last timestamp */
draw_timestamp(drawing_width - 1, t2);
return;
}
/* write timestamp below graph */
void draw_timestamp(int ts_pixel, time_t ts_time) {
char temp_buffer[MAX_INPUT_BUFFER];
int string_height;
int string_width;
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%s", ctime(&ts_time));
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
temp_buffer[strlen(temp_buffer)-1] = '\x0';
string_height = gdFontSmall->h;
string_width = gdFontSmall->w * strlen(temp_buffer);
if (small_image == FALSE)
gdImageStringUp(trends_image, gdFontSmall, ts_pixel + drawing_x_offset - (string_height / 2), drawing_y_offset + drawing_height + string_width + 5, (unsigned char *)temp_buffer, color_black);
/* draw a dashed vertical line at this point */
if (ts_pixel > 0 && ts_pixel < (drawing_width - 1))
draw_dashed_line(ts_pixel + drawing_x_offset, drawing_y_offset, ts_pixel + drawing_x_offset, drawing_y_offset + drawing_height, color_black);
return;
}
/* draw total state times */
void draw_time_breakdowns(void) {
char temp_buffer[MAX_INPUT_BUFFER];
unsigned long total_time = 0L;
unsigned long total_state_time;
unsigned long time_indeterminate = 0L;
if (content_type == HTML_CONTENT)
return;
if (small_image == TRUE)
return;
total_time = (unsigned long)(t2 - t1);
if (display_type == DISPLAY_HOST_TRENDS)
total_state_time = time_up + time_down + time_unreachable;
else
total_state_time = time_ok + time_warning + time_unknown + time_critical;
if (total_state_time >= total_time)
time_indeterminate = 0L;
else
time_indeterminate = total_time - total_state_time;
if (display_type == DISPLAY_HOST_TRENDS) {
get_time_breakdown_string(total_time, time_up, "Up", &temp_buffer[0], sizeof(temp_buffer));
gdImageString(trends_image, gdFontSmall, drawing_x_offset + drawing_width + 20, drawing_y_offset + 5, (unsigned char *)temp_buffer, color_darkgreen);
gdImageString(trends_image, gdFontSmall, drawing_x_offset - 10 - (gdFontSmall->w * 2), drawing_y_offset + 5, (unsigned char *)"Up", color_darkgreen);
get_time_breakdown_string(total_time, time_down, "Down", &temp_buffer[0], sizeof(temp_buffer));
gdImageString(trends_image, gdFontSmall, drawing_x_offset + drawing_width + 20, drawing_y_offset + 25, (unsigned char *)temp_buffer, color_red);
gdImageString(trends_image, gdFontSmall, drawing_x_offset - 10 - (gdFontSmall->w * 4), drawing_y_offset + 25, (unsigned char *)"Down", color_red);
get_time_breakdown_string(total_time, time_unreachable, "Unreachable", &temp_buffer[0], sizeof(temp_buffer));
gdImageString(trends_image, gdFontSmall, drawing_x_offset + drawing_width + 20, drawing_y_offset + 45, (unsigned char *)temp_buffer, color_darkpink);
gdImageString(trends_image, gdFontSmall, drawing_x_offset - 10 - (gdFontSmall->w * 11), drawing_y_offset + 45, (unsigned char *)"Unreachable", color_darkpink);
get_time_breakdown_string(total_time, time_indeterminate, "Indeterminate", &temp_buffer[0], sizeof(temp_buffer));
gdImageString(trends_image, gdFontSmall, drawing_x_offset + drawing_width + 20, drawing_y_offset + 65, (unsigned char *)temp_buffer, color_black);
gdImageString(trends_image, gdFontSmall, drawing_x_offset - 10 - (gdFontSmall->w * 13), drawing_y_offset + 65, (unsigned char *)"Indeterminate", color_black);
} else {
get_time_breakdown_string(total_time, time_ok, "Ok", &temp_buffer[0], sizeof(temp_buffer));
gdImageString(trends_image, gdFontSmall, drawing_x_offset + drawing_width + 20, drawing_y_offset + 5, (unsigned char *)temp_buffer, color_darkgreen);
gdImageString(trends_image, gdFontSmall, drawing_x_offset - 10 - (gdFontSmall->w * 2), drawing_y_offset + 5, (unsigned char *)"Ok", color_darkgreen);
get_time_breakdown_string(total_time, time_warning, "Warning", &temp_buffer[0], sizeof(temp_buffer));
gdImageString(trends_image, gdFontSmall, drawing_x_offset + drawing_width + 20, drawing_y_offset + 25, (unsigned char *)temp_buffer, color_yellow);
gdImageString(trends_image, gdFontSmall, drawing_x_offset - 10 - (gdFontSmall->w * 7), drawing_y_offset + 25, (unsigned char *)"Warning", color_yellow);
get_time_breakdown_string(total_time, time_unknown, "Unknown", &temp_buffer[0], sizeof(temp_buffer));
gdImageString(trends_image, gdFontSmall, drawing_x_offset + drawing_width + 20, drawing_y_offset + 45, (unsigned char *)temp_buffer, color_darkpink);
gdImageString(trends_image, gdFontSmall, drawing_x_offset - 10 - (gdFontSmall->w * 7), drawing_y_offset + 45, (unsigned char *)"Unknown", color_darkpink);
get_time_breakdown_string(total_time, time_critical, "Critical", &temp_buffer[0], sizeof(temp_buffer));
gdImageString(trends_image, gdFontSmall, drawing_x_offset + drawing_width + 20, drawing_y_offset + 65, (unsigned char *)temp_buffer, color_red);
gdImageString(trends_image, gdFontSmall, drawing_x_offset - 10 - (gdFontSmall->w * 8), drawing_y_offset + 65, (unsigned char *)"Critical", color_red);
get_time_breakdown_string(total_time, time_indeterminate, "Indeterminate", &temp_buffer[0], sizeof(temp_buffer));
gdImageString(trends_image, gdFontSmall, drawing_x_offset + drawing_width + 20, drawing_y_offset + 85, (unsigned char *)temp_buffer, color_black);
gdImageString(trends_image, gdFontSmall, drawing_x_offset - 10 - (gdFontSmall->w * 13), drawing_y_offset + 85, (unsigned char *)"Indeterminate", color_black);
}
return;
}
void get_time_breakdown_string(unsigned long total_time, unsigned long state_time, char *state_string, char *buffer, int buffer_length) {
int days;
int hours;
int minutes;
int seconds;
double percent_time;
get_time_breakdown(state_time, &days, &hours, &minutes, &seconds);
if (total_time == 0L)
percent_time = 0.0;
else
percent_time = ((double)state_time / total_time) * 100.0;
snprintf(buffer, buffer_length - 1, "%-13s: (%.3f%%) %dd %dh %dm %ds", state_string, percent_time, days, hours, minutes, seconds);
buffer[buffer_length-1] = '\x0';
return;
}
void compute_report_times(void) {
time_t current_time;
struct tm *st;
struct tm *et;
/* get the current time */
time(¤t_time);
st = localtime(¤t_time);
st->tm_sec = start_second;
st->tm_min = start_minute;
st->tm_hour = start_hour;
st->tm_mday = start_day;
st->tm_mon = start_month - 1;
st->tm_year = start_year - 1900;
st->tm_isdst = -1;
t1 = mktime(st);
et = localtime(¤t_time);
et->tm_sec = end_second;
et->tm_min = end_minute;
et->tm_hour = end_hour;
et->tm_mday = end_day;
et->tm_mon = end_month - 1;
et->tm_year = end_year - 1900;
et->tm_isdst = -1;
t2 = mktime(et);
}
/* draws a dashed line */
void draw_dashed_line(int x1, int y1, int x2, int y2, int color) {
int styleDashed[12];
styleDashed[0] = color;
styleDashed[1] = color;
styleDashed[2] = gdTransparent;
styleDashed[3] = gdTransparent;
styleDashed[4] = color;
styleDashed[5] = color;
styleDashed[6] = gdTransparent;
styleDashed[7] = gdTransparent;
styleDashed[8] = color;
styleDashed[9] = color;
styleDashed[10] = gdTransparent;
styleDashed[11] = gdTransparent;
/* sets current style to a dashed line */
gdImageSetStyle(trends_image, styleDashed, 12);
/* draws a line (dashed) */
gdImageLine(trends_image, x1, y1, x2, y2, gdStyled);
return;
}
/* draws horizontal grid lines */
void draw_horizontal_grid_lines(void) {
if (content_type == HTML_CONTENT)
return;
if (small_image == TRUE)
return;
draw_dashed_line(drawing_x_offset, drawing_y_offset + 10, drawing_x_offset + drawing_width, drawing_y_offset + 10, color_black);
draw_dashed_line(drawing_x_offset, drawing_y_offset + 30, drawing_x_offset + drawing_width, drawing_y_offset + 30, color_black);
draw_dashed_line(drawing_x_offset, drawing_y_offset + 50, drawing_x_offset + drawing_width, drawing_y_offset + 50, color_black);
if (display_type == DISPLAY_SERVICE_TRENDS)
draw_dashed_line(drawing_x_offset, drawing_y_offset + 70, drawing_x_offset + drawing_width, drawing_y_offset + 70, color_black);
return;
}
icinga-1.10.3/common/ 0000775 0000000 0000000 00000000000 12276402000 0014307 5 ustar 00root root 0000000 0000000 icinga-1.10.3/common/Makefile.in 0000664 0000000 0000000 00000001430 12276402000 0016352 0 ustar 00root root 0000000 0000000 ############################
# Makefile for Icinga
############################
# Source code directories
SRC_BASE=../common
SRC_CGI=../cgi
CC=@CC@
CFLAGS=@CFLAGS@ @DEFS@
LDFLAGS=@LDFLAGS@ @LIBS@
prefix=@prefix@
exec_prefix=@exec_prefix@
LOGDIR=@LOGDIR@
CFGDIR=@sysconfdir@
BINDIR=@bindir@
LIBDIR=@libdir@
CGIDIR=@sbindir@
HTMLDIR=@datarootdir@
INSTALL=@INSTALL@
INSTALL_OPTS=@INSTALL_OPTS@
COMMAND_OPTS=@COMMAND_OPTS@
CP=@CP@
###############################
# Debug
###############################
ENABLE_DEBUG=@ENABLE_DEBUG@
# Compiler flags for use with Valgrind - set when debug is enabled
ifeq ('$(ENABLE_DEBUG)', 'yes')
CFLAGS=-O0 -g -Wall -DHAVE_CONFIG_H -DNSCORE
endif
clean:
rm -f core *.o
rm -f *~
distclean: clean
rm -f Makefile
devclean: distclean
install:
icinga-1.10.3/common/comments.c 0000664 0000000 0000000 00000056002 12276402000 0016303 0 ustar 00root root 0000000 0000000 /*****************************************************************************
*
* COMMENTS.C - Comment functions for Icinga
*
* Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org)
* Copyright (c) 2009-2013 Nagios Core Development Team and Community Contributors
* Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*****************************************************************************/
#include "../include/config.h"
#include "../include/common.h"
#include "../include/comments.h"
#include "../include/objects.h"
/***** IMPLEMENTATION-SPECIFIC INCLUDES *****/
#ifdef USE_XCDDEFAULT
#include "../xdata/xcddefault.h"
#endif
#ifdef NSCORE
#include "../include/icinga.h"
#include "../include/broker.h"
#endif
#ifdef NSCGI
#include "../include/cgiutils.h"
#endif
comment *comment_list = NULL;
int defer_comment_sorting = 0;
comment **comment_hashlist = NULL;
#ifdef NSCORE
pthread_mutex_t icinga_comment_lock = PTHREAD_MUTEX_INITIALIZER;
/******************************************************************/
/**************** INITIALIZATION/CLEANUP FUNCTIONS ****************/
/******************************************************************/
/* initializes comment data */
int initialize_comment_data(char *config_file) {
int result = OK;
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XCDDEFAULT
result = xcddefault_initialize_comment_data(config_file);
#endif
return result;
}
/* removes old/invalid comments */
int cleanup_comment_data(char *config_file) {
int result = OK;
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XCDDEFAULT
result = xcddefault_cleanup_comment_data(config_file);
#endif
return result;
}
/******************************************************************/
/****************** COMMENT OUTPUT FUNCTIONS **********************/
/******************************************************************/
/* adds a new host or service comment */
int add_new_comment(int type, int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author_name, char *comment_data, int persistent, int source, int expires, time_t expire_time, unsigned long *comment_id) {
int result = OK;
unsigned long new_comment_id = 0L;
if (type == HOST_COMMENT)
result = add_new_host_comment(entry_type, host_name, entry_time, author_name, comment_data, persistent, source, expires, expire_time, &new_comment_id);
else
result = add_new_service_comment(entry_type, host_name, svc_description, entry_time, author_name, comment_data, persistent, source, expires, expire_time, &new_comment_id);
/* add an event to expire comment data if necessary... */
if (expires == TRUE)
schedule_new_event(EVENT_EXPIRE_COMMENT, FALSE, expire_time, FALSE, 0, NULL, TRUE, (void *)new_comment_id, NULL, 0);
/* save comment id */
if (comment_id != NULL)
*comment_id = new_comment_id;
return result;
}
/* adds a new host comment */
int add_new_host_comment(int entry_type, char *host_name, time_t entry_time, char *author_name, char *comment_data, int persistent, int source, int expires, time_t expire_time, unsigned long *comment_id) {
int result = OK;
unsigned long new_comment_id = 0L;
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XCDDEFAULT
result = xcddefault_add_new_host_comment(entry_type, host_name, entry_time, author_name, comment_data, persistent, source, expires, expire_time, &new_comment_id);
#endif
/* save comment id */
if (comment_id != NULL)
*comment_id = new_comment_id;
#ifdef USE_EVENT_BROKER
/* send data to event broker */
broker_comment_data(NEBTYPE_COMMENT_ADD, NEBFLAG_NONE, NEBATTR_NONE, HOST_COMMENT, entry_type, host_name, NULL, entry_time, author_name, comment_data, persistent, source, expires, expire_time, new_comment_id, NULL);
#endif
return result;
}
/* adds a new service comment */
int add_new_service_comment(int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author_name, char *comment_data, int persistent, int source, int expires, time_t expire_time, unsigned long *comment_id) {
int result = OK;
unsigned long new_comment_id = 0L;
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XCDDEFAULT
result = xcddefault_add_new_service_comment(entry_type, host_name, svc_description, entry_time, author_name, comment_data, persistent, source, expires, expire_time, &new_comment_id);
#endif
/* save comment id */
if (comment_id != NULL)
*comment_id = new_comment_id;
#ifdef USE_EVENT_BROKER
/* send data to event broker */
broker_comment_data(NEBTYPE_COMMENT_ADD, NEBFLAG_NONE, NEBATTR_NONE, SERVICE_COMMENT, entry_type, host_name, svc_description, entry_time, author_name, comment_data, persistent, source, expires, expire_time, new_comment_id, NULL);
#endif
return result;
}
/******************************************************************/
/***************** COMMENT DELETION FUNCTIONS *********************/
/******************************************************************/
/* deletes a host or service comment */
int delete_comment(int type, unsigned long comment_id) {
int result = OK;
comment *this_comment = NULL;
comment *last_comment = NULL;
comment *next_comment = NULL;
int hashslot = 0;
comment *this_hash = NULL;
comment *last_hash = NULL;
/* lock the comments so we can modify them safely */
#ifdef NSCORE
pthread_mutex_lock(&icinga_comment_lock);
#endif
/* find the comment we should remove */
for (this_comment = comment_list, last_comment = comment_list; this_comment != NULL; this_comment = next_comment) {
next_comment = this_comment->next;
/* we found the comment we should delete */
if (this_comment->comment_id == comment_id && this_comment->comment_type == type)
break;
last_comment = this_comment;
}
/* remove the comment from the list in memory */
if (this_comment != NULL) {
#ifdef USE_EVENT_BROKER
/* send data to event broker */
broker_comment_data(NEBTYPE_COMMENT_DELETE, NEBFLAG_NONE, NEBATTR_NONE, type, this_comment->entry_type, this_comment->host_name, this_comment->service_description, this_comment->entry_time, this_comment->author, this_comment->comment_data, this_comment->persistent, this_comment->source, this_comment->expires, this_comment->expire_time, comment_id, NULL);
#endif
/* first remove from chained hash list */
hashslot = hashfunc(this_comment->host_name, NULL, COMMENT_HASHSLOTS);
last_hash = NULL;
for (this_hash = comment_hashlist[hashslot]; this_hash; this_hash = this_hash->nexthash) {
if (this_hash == this_comment) {
if (last_hash) {
last_hash->nexthash = this_hash->nexthash;
} else {
if (this_hash->nexthash) {
comment_hashlist[hashslot] = this_hash->nexthash;
} else {
comment_hashlist[hashslot] = NULL;
}
}
break;
}
last_hash = this_hash;
}
/* then removed from linked list */
if (comment_list == this_comment)
comment_list = this_comment->next;
else
last_comment->next = next_comment;
/* free memory */
my_free(this_comment->host_name);
my_free(this_comment->service_description);
my_free(this_comment->author);
my_free(this_comment->comment_data);
my_free(this_comment);
result = OK;
} else
result = ERROR;
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XCDDEFAULT
if (type == HOST_COMMENT)
result = xcddefault_delete_host_comment(comment_id);
else
result = xcddefault_delete_service_comment(comment_id);
#endif
#ifdef NSCORE
pthread_mutex_unlock(&icinga_comment_lock);
#endif
return result;
}
/* deletes a host comment */
int delete_host_comment(unsigned long comment_id) {
int result = OK;
/* delete the comment from memory */
result = delete_comment(HOST_COMMENT, comment_id);
return result;
}
/* deletes a service comment */
int delete_service_comment(unsigned long comment_id) {
int result = OK;
/* delete the comment from memory */
result = delete_comment(SERVICE_COMMENT, comment_id);
return result;
}
/* deletes all comments for a particular host or service */
int delete_all_comments(int type, char *host_name, char *svc_description) {
int result = OK;
if (type == HOST_COMMENT)
result = delete_all_host_comments(host_name);
else
result = delete_all_service_comments(host_name, svc_description);
return result;
}
/* deletes all comments for a particular host */
int delete_all_host_comments(char *host_name) {
int result = OK;
comment *temp_comment = NULL;
comment *next_comment = NULL;
if (host_name == NULL)
return ERROR;
/* delete host comments from memory */
for (temp_comment = get_first_comment_by_host(host_name); temp_comment != NULL; temp_comment = next_comment) {
next_comment = get_next_comment_by_host(host_name, temp_comment);
if (temp_comment->comment_type == HOST_COMMENT)
delete_comment(HOST_COMMENT, temp_comment->comment_id);
}
return result;
}
/* deletes all non-persistent acknowledgement comments for a particular host */
int delete_host_acknowledgement_comments(host *hst) {
int result = OK;
comment *temp_comment = NULL;
comment *next_comment = NULL;
if (hst == NULL)
return ERROR;
/* delete comments from memory */
for (temp_comment = get_first_comment_by_host(hst->name); temp_comment != NULL; temp_comment = next_comment) {
next_comment = get_next_comment_by_host(hst->name, temp_comment);
if (temp_comment->comment_type == HOST_COMMENT && temp_comment->entry_type == ACKNOWLEDGEMENT_COMMENT && temp_comment->persistent == FALSE)
delete_comment(HOST_COMMENT, temp_comment->comment_id);
}
return result;
}
/* deletes all comments for a particular service */
int delete_all_service_comments(char *host_name, char *svc_description) {
int result = OK;
comment *temp_comment = NULL;
comment *next_comment = NULL;
if (host_name == NULL || svc_description == NULL)
return ERROR;
/* delete service comments from memory */
for (temp_comment = comment_list; temp_comment != NULL; temp_comment = next_comment) {
next_comment = temp_comment->next;
if (temp_comment->comment_type == SERVICE_COMMENT && !strcmp(temp_comment->host_name, host_name) && !strcmp(temp_comment->service_description, svc_description))
delete_comment(SERVICE_COMMENT, temp_comment->comment_id);
}
return result;
}
/* deletes all non-persistent acknowledgement comments for a particular service */
int delete_service_acknowledgement_comments(service *svc) {
int result = OK;
comment *temp_comment = NULL;
comment *next_comment = NULL;
if (svc == NULL)
return ERROR;
/* delete comments from memory */
for (temp_comment = comment_list; temp_comment != NULL; temp_comment = next_comment) {
next_comment = temp_comment->next;
if (temp_comment->comment_type == SERVICE_COMMENT && !strcmp(temp_comment->host_name, svc->host_name) && !strcmp(temp_comment->service_description, svc->description) && temp_comment->entry_type == ACKNOWLEDGEMENT_COMMENT && temp_comment->persistent == FALSE)
delete_comment(SERVICE_COMMENT, temp_comment->comment_id);
}
return result;
}
/* checks for an expired comment (and removes it) */
int check_for_expired_comment(unsigned long comment_id) {
comment *temp_comment = NULL;
comment *next_comment = NULL;
/* check all comments */
for (temp_comment = comment_list; temp_comment != NULL; temp_comment = next_comment) {
next_comment = temp_comment->next;
/* delete the now expired comment */
if (temp_comment->comment_id == comment_id && temp_comment->expires == TRUE && temp_comment->expire_time < time(NULL)) {
delete_comment(temp_comment->comment_type, comment_id);
break;
}
}
return OK;
}
#endif
/******************************************************************/
/****************** CHAINED HASH FUNCTIONS ************************/
/******************************************************************/
/* adds comment to hash list in memory */
int add_comment_to_hashlist(comment *new_comment) {
comment *temp_comment = NULL;
comment *lastpointer = NULL;
int hashslot = 0;
/* initialize hash list */
if (comment_hashlist == NULL) {
int i;
comment_hashlist = (comment **)malloc(sizeof(comment *) * COMMENT_HASHSLOTS);
if (comment_hashlist == NULL)
return 0;
for (i = 0; i < COMMENT_HASHSLOTS; i++)
comment_hashlist[i] = NULL;
}
if (!new_comment)
return 0;
hashslot = hashfunc(new_comment->host_name, NULL, COMMENT_HASHSLOTS);
lastpointer = NULL;
for (temp_comment = comment_hashlist[hashslot]; temp_comment && compare_hashdata(temp_comment->host_name, NULL, new_comment->host_name, NULL) < 0; temp_comment = temp_comment->nexthash) {
if (compare_hashdata(temp_comment->host_name, NULL, new_comment->host_name, NULL) >= 0)
break;
lastpointer = temp_comment;
}
/* multiples are allowed */
if (lastpointer)
lastpointer->nexthash = new_comment;
else
comment_hashlist[hashslot] = new_comment;
new_comment->nexthash = temp_comment;
return 1;
}
/******************************************************************/
/******************** ADDITION FUNCTIONS **************************/
/******************************************************************/
/* adds a host comment to the list in memory */
int add_host_comment(int entry_type, char *host_name, time_t entry_time, char *author, char *comment_data, unsigned long comment_id, int persistent, int expires, time_t expire_time, int source) {
int result = OK;
result = add_comment(HOST_COMMENT, entry_type, host_name, NULL, entry_time, author, comment_data, comment_id, persistent, expires, expire_time, source);
return result;
}
/* adds a service comment to the list in memory */
int add_service_comment(int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author, char *comment_data, unsigned long comment_id, int persistent, int expires, time_t expire_time, int source) {
int result = OK;
result = add_comment(SERVICE_COMMENT, entry_type, host_name, svc_description, entry_time, author, comment_data, comment_id, persistent, expires, expire_time, source);
return result;
}
/* adds a comment to the list in memory */
int add_comment(int comment_type, int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author, char *comment_data, unsigned long comment_id, int persistent, int expires, time_t expire_time, int source) {
comment *new_comment = NULL;
comment *last_comment = NULL;
comment *temp_comment = NULL;
int result = OK;
/* make sure we have the data we need */
if (host_name == NULL || author == NULL || comment_data == NULL || (comment_type == SERVICE_COMMENT && svc_description == NULL))
return ERROR;
/* allocate memory for the comment */
if ((new_comment = (comment *)calloc(1, sizeof(comment))) == NULL)
return ERROR;
/* duplicate vars */
if ((new_comment->host_name = (char *)strdup(host_name)) == NULL)
result = ERROR;
if (comment_type == SERVICE_COMMENT) {
if ((new_comment->service_description = (char *)strdup(svc_description)) == NULL)
result = ERROR;
}
if ((new_comment->author = (char *)strdup(author)) == NULL)
result = ERROR;
if ((new_comment->comment_data = (char *)strdup(comment_data)) == NULL)
result = ERROR;
new_comment->comment_type = comment_type;
new_comment->entry_type = entry_type;
new_comment->source = source;
new_comment->entry_time = entry_time;
new_comment->comment_id = comment_id;
new_comment->persistent = (persistent == TRUE) ? TRUE : FALSE;
new_comment->expires = (expires == TRUE) ? TRUE : FALSE;
new_comment->expire_time = expire_time;
/* add comment to hash list */
if (result == OK) {
if (!add_comment_to_hashlist(new_comment))
result = ERROR;
}
/* handle errors */
if (result == ERROR) {
my_free(new_comment->comment_data);
my_free(new_comment->author);
my_free(new_comment->service_description);
my_free(new_comment->host_name);
my_free(new_comment);
return ERROR;
}
if (defer_comment_sorting) {
new_comment->next = comment_list;
comment_list = new_comment;
} else {
/* add new comment to comment list, sorted by comment id,
* but lock the list first so broker threads doesn't crash
* out in case they're modifying this list too
*/
#ifdef NSCORE
pthread_mutex_lock(&icinga_comment_lock);
#endif
last_comment = comment_list;
for (temp_comment = comment_list; temp_comment != NULL; temp_comment = temp_comment->next) {
if (new_comment->comment_id < temp_comment->comment_id) {
new_comment->next = temp_comment;
if (temp_comment == comment_list)
comment_list = new_comment;
else
last_comment->next = new_comment;
break;
} else
last_comment = temp_comment;
}
if (comment_list == NULL) {
new_comment->next = NULL;
comment_list = new_comment;
} else if (temp_comment == NULL) {
new_comment->next = NULL;
last_comment->next = new_comment;
}
#ifdef NSCORE
pthread_mutex_unlock(&icinga_comment_lock);
#endif
}
#ifdef NSCORE
#ifdef USE_EVENT_BROKER
/* send data to event broker */
broker_comment_data(NEBTYPE_COMMENT_LOAD, NEBFLAG_NONE, NEBATTR_NONE, comment_type, entry_type, host_name, svc_description, entry_time, author, comment_data, persistent, source, expires, expire_time, comment_id, NULL);
#endif
#endif
return OK;
}
static int comment_compar(const void *p1, const void *p2) {
comment *c1 = *(comment **)p1;
comment *c2 = *(comment **)p2;
return (c1->comment_id < c2->comment_id) ? -1 : (c1->comment_id - c2->comment_id);
}
int sort_comments(void) {
comment **array, *temp_comment;
unsigned long i = 0, unsorted_comments = 0;
if (!defer_comment_sorting)
return OK;
defer_comment_sorting = 0;
temp_comment = comment_list;
while (temp_comment != NULL) {
temp_comment = temp_comment->next;
unsorted_comments++;
}
if (!unsorted_comments)
return OK;
if (!(array = malloc(sizeof(*array) * unsorted_comments)))
return ERROR;
while (comment_list) {
array[i++] = comment_list;
comment_list = comment_list->next;
}
qsort((void *)array, i, sizeof(*array), comment_compar);
comment_list = temp_comment = array[0];
for (i = 1; i < unsorted_comments; i++) {
temp_comment->next = array[i];
temp_comment = temp_comment->next;
}
temp_comment->next = NULL;
my_free(array);
return OK;
}
/******************************************************************/
/********************* CLEANUP FUNCTIONS **************************/
/******************************************************************/
/* frees memory allocated for the comment data */
void free_comment_data(void) {
comment *this_comment = NULL;
comment *next_comment = NULL;
/* free memory for the comment list */
for (this_comment = comment_list; this_comment != NULL; this_comment = next_comment) {
next_comment = this_comment->next;
my_free(this_comment->host_name);
my_free(this_comment->service_description);
my_free(this_comment->author);
my_free(this_comment->comment_data);
my_free(this_comment);
}
/* free hash list and reset list pointer */
my_free(comment_hashlist);
comment_hashlist = NULL;
comment_list = NULL;
return;
}
/******************************************************************/
/********************* UTILITY FUNCTIONS **************************/
/******************************************************************/
/* get the number of comments associated with a particular host */
int number_of_host_comments(char *host_name) {
comment *temp_comment = NULL;
int total_comments = 0;
if (host_name == NULL)
return 0;
for (temp_comment = get_first_comment_by_host(host_name); temp_comment != NULL; temp_comment = get_next_comment_by_host(host_name, temp_comment)) {
if (temp_comment->comment_type == HOST_COMMENT)
total_comments++;
}
return total_comments;
}
/* get the number of comments associated with a particular service */
int number_of_service_comments(char *host_name, char *svc_description) {
comment *temp_comment = NULL;
int total_comments = 0;
if (host_name == NULL || svc_description == NULL)
return 0;
for (temp_comment = get_first_comment_by_host(host_name); temp_comment != NULL; temp_comment = get_next_comment_by_host(host_name, temp_comment)) {
if (temp_comment->comment_type == SERVICE_COMMENT && !strcmp(temp_comment->service_description, svc_description))
total_comments++;
}
return total_comments;
}
/******************************************************************/
/********************* TRAVERSAL FUNCTIONS ************************/
/******************************************************************/
comment *get_first_comment_by_host(char *host_name) {
return get_next_comment_by_host(host_name, NULL);
}
comment *get_next_comment_by_host(char *host_name, comment *start) {
comment *temp_comment = NULL;
if (host_name == NULL || comment_hashlist == NULL)
return NULL;
if (start == NULL)
temp_comment = comment_hashlist[hashfunc(host_name, NULL, COMMENT_HASHSLOTS)];
else
temp_comment = start->nexthash;
for (; temp_comment && compare_hashdata(temp_comment->host_name, NULL, host_name, NULL) < 0; temp_comment = temp_comment->nexthash);
if (temp_comment && compare_hashdata(temp_comment->host_name, NULL, host_name, NULL) == 0)
return temp_comment;
return NULL;
}
/******************************************************************/
/********************** SEARCH FUNCTIONS **************************/
/******************************************************************/
/* find a service comment by id */
comment *find_service_comment(unsigned long comment_id) {
return find_comment(comment_id, SERVICE_COMMENT);
}
/* find a host comment by id */
comment *find_host_comment(unsigned long comment_id) {
return find_comment(comment_id, HOST_COMMENT);
}
/* find a comment by id */
comment *find_comment(unsigned long comment_id, int comment_type) {
comment *temp_comment = NULL;
for (temp_comment = comment_list; temp_comment != NULL; temp_comment = temp_comment->next) {
if (comment_type != ANY_COMMENT && temp_comment->comment_type != comment_type)
continue;
if (temp_comment->comment_id == comment_id)
return temp_comment;
}
return NULL;
}
/* find a comment by comment_type, host_name, service_desc (NULL if hostcomment), entry_time, author, comment_data */
comment *find_comment_by_similar_content(int comment_type, char *hostname, char *service_description, char *author, char *comment_data) {
comment *temp_comment = NULL;
for (temp_comment = comment_list; temp_comment != NULL; temp_comment = temp_comment->next) {
if (temp_comment->comment_type == comment_type
&& strcmp(temp_comment->host_name, hostname) == 0
&& (service_description == NULL || strcmp(temp_comment->service_description, service_description) == 0)
&& strcmp(temp_comment->author, author) == 0
&& strcmp(temp_comment->comment_data, comment_data) == 0)
return temp_comment;
}
return NULL;
}
icinga-1.10.3/common/downtime.c 0000664 0000000 0000000 00000131501 12276402000 0016302 0 ustar 00root root 0000000 0000000 /*****************************************************************************
*
* DOWNTIME.C - Scheduled downtime functions for Icinga
*
* Copyright (c) 2000-2008 Ethan Galstad (egalstad@nagios.org)
* Copyright (c) 2009-2013 Nagios Core Development Team and Community Contributors
* Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*****************************************************************************/
#include "../include/config.h"
#include "../include/common.h"
#include "../include/comments.h"
#include "../include/downtime.h"
#include "../include/objects.h"
#include "../include/statusdata.h"
/***** IMPLEMENTATION-SPECIFIC INCLUDES *****/
#ifdef USE_XDDDEFAULT
#include "../xdata/xdddefault.h"
#endif
#ifdef NSCORE
#include "../include/icinga.h"
#include "../include/broker.h"
#endif
#ifdef NSCGI
#include "../include/cgiutils.h"
#endif
scheduled_downtime *scheduled_downtime_list = NULL;
/*
* downtimes are not sorted by id, but starttime
* this leads into https://dev.icinga.org/issues/2688
* where child downtimes are considered invalid when
* looking up the parent
* setting this to 1 could cause unresolvable issues.
* the fix for child downtimes can be found in
* downtime_compar()
*/
int defer_downtime_sorting = 0;
#ifdef NSCORE
extern timed_event *event_list_high;
extern timed_event *event_list_high_tail;
pthread_mutex_t icinga_downtime_lock = PTHREAD_MUTEX_INITIALIZER;
#endif
#ifdef NSCORE
/******************************************************************/
/**************** INITIALIZATION/CLEANUP FUNCTIONS ****************/
/******************************************************************/
/* initializes scheduled downtime data */
int initialize_downtime_data(char *config_file) {
int result = OK;
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XDDDEFAULT
result = xdddefault_initialize_downtime_data(config_file);
#endif
return result;
}
/* cleans up scheduled downtime data */
int cleanup_downtime_data(char *config_file) {
int result = OK;
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XDDDEFAULT
result = xdddefault_cleanup_downtime_data(config_file);
#endif
/* free memory allocated to downtime data */
free_downtime_data();
return result;
}
/******************************************************************/
/********************** SCHEDULING FUNCTIONS **********************/
/******************************************************************/
/* schedules a host or service downtime */
int schedule_downtime(int type, char *host_name, char *service_description, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *new_downtime_id) {
unsigned long downtime_id = 0L;
time_t trigger_time = 0L;
log_debug_info(DEBUGL_FUNCTIONS, 0, "schedule_downtime()\n");
/* don't add old or invalid downtimes */
if (start_time >= end_time || end_time <= time(NULL))
return ERROR;
/* add a new downtime entry */
add_new_downtime(type, host_name, service_description, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, &downtime_id, FALSE, trigger_time);
/* register the scheduled downtime */
register_downtime(type, downtime_id);
/* return downtime id */
if (new_downtime_id != NULL)
*new_downtime_id = downtime_id;
return OK;
}
/* unschedules a host or service downtime */
int unschedule_downtime(int type, unsigned long downtime_id) {
scheduled_downtime *temp_downtime = NULL;
scheduled_downtime *next_downtime = NULL;
host *hst = NULL;
service *svc = NULL;
timed_event *temp_event = NULL;
#ifdef USE_EVENT_BROKER
int attr = 0;
#endif
log_debug_info(DEBUGL_FUNCTIONS, 0, "unschedule_downtime()\n");
/* find the downtime entry in the list in memory */
if ((temp_downtime = find_downtime(type, downtime_id)) == NULL)
return ERROR;
/* find the host or service associated with this downtime */
if (temp_downtime->type == HOST_DOWNTIME) {
if ((hst = find_host(temp_downtime->host_name)) == NULL)
return ERROR;
} else {
if ((svc = find_service(temp_downtime->host_name, temp_downtime->service_description)) == NULL)
return ERROR;
}
/* decrement pending flex downtime if necessary ... */
if (temp_downtime->fixed == FALSE && temp_downtime->incremented_pending_downtime == TRUE) {
if (temp_downtime->type == HOST_DOWNTIME)
hst->pending_flex_downtime--;
else
svc->pending_flex_downtime--;
}
log_debug_info(DEBUGL_DOWNTIME, 0, "Cancelling %s downtime (id=%lu)\n", temp_downtime->type == HOST_DOWNTIME ? "host" : "service", temp_downtime->downtime_id);
/* decrement the downtime depth variable and update status data if necessary */
if (temp_downtime->is_in_effect == TRUE) {
#ifdef USE_EVENT_BROKER
/* send data to event broker */
attr = NEBATTR_DOWNTIME_STOP_CANCELLED;
broker_downtime_data(NEBTYPE_DOWNTIME_STOP, NEBFLAG_NONE, attr, temp_downtime->type, temp_downtime->host_name, temp_downtime->service_description, temp_downtime->entry_time, temp_downtime->author, temp_downtime->comment, temp_downtime->start_time, temp_downtime->end_time, temp_downtime->fixed, temp_downtime->triggered_by, temp_downtime->duration, temp_downtime->downtime_id, NULL, temp_downtime->is_in_effect, temp_downtime->trigger_time);
#endif
if (temp_downtime->type == HOST_DOWNTIME) {
hst->scheduled_downtime_depth--;
update_host_status(hst, FALSE);
/* log a notice - this is parsed by the history CGI */
if (hst->scheduled_downtime_depth == 0) {
logit(NSLOG_INFO_MESSAGE, FALSE, "HOST DOWNTIME ALERT: %s;CANCELLED; Scheduled downtime for host has been cancelled.\n", hst->name);
/* send a notification */
host_notification(hst, NOTIFICATION_DOWNTIMECANCELLED, NULL, NULL, NOTIFICATION_OPTION_NONE);
}
}
else {
svc->scheduled_downtime_depth--;
update_service_status(svc, FALSE);
/* log a notice - this is parsed by the history CGI */
if (svc->scheduled_downtime_depth == 0) {
logit(NSLOG_INFO_MESSAGE, FALSE, "SERVICE DOWNTIME ALERT: %s;%s;CANCELLED; Scheduled downtime for service has been cancelled.\n", svc->host_name, svc->description);
/* send a notification */
service_notification(svc, NOTIFICATION_DOWNTIMECANCELLED, NULL, NULL, NOTIFICATION_OPTION_NONE);
}
}
}
/* remove scheduled entry from event queue */
for (temp_event = event_list_high; temp_event != NULL; temp_event = temp_event->next) {
if (temp_event->event_type != EVENT_SCHEDULED_DOWNTIME)
continue;
if (((unsigned long)temp_event->event_data) == downtime_id)
break;
}
if (temp_event != NULL) {
remove_event(temp_event, &event_list_high, &event_list_high_tail);
my_free(temp_event->event_data);
my_free(temp_event);
}
/* delete downtime entry */
if (temp_downtime->type == HOST_DOWNTIME)
delete_host_downtime(downtime_id);
else
delete_service_downtime(downtime_id);
/* unschedule all downtime entries that were triggered by this one */
while (1) {
for (temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = next_downtime) {
next_downtime = temp_downtime->next;
if (temp_downtime->triggered_by == downtime_id) {
unschedule_downtime(ANY_DOWNTIME, temp_downtime->downtime_id);
break;
}
}
if (temp_downtime == NULL)
break;
}
return OK;
}
/* registers scheduled downtime (schedules it, adds comments, etc.) */
int register_downtime(int type, unsigned long downtime_id) {
char *temp_buffer = NULL;
char start_time_string[MAX_DATETIME_LENGTH] = "";
char end_time_string[MAX_DATETIME_LENGTH] = "";
scheduled_downtime *temp_downtime = NULL;
host *hst = NULL;
service *svc = NULL;
char *type_string = NULL;
int hours = 0;
int minutes = 0;
int seconds = 0;
unsigned long *new_downtime_id = NULL;
log_debug_info(DEBUGL_FUNCTIONS, 0, "register_downtime()\n");
/* find the downtime entry in memory */
temp_downtime = find_downtime(type, downtime_id);
if (temp_downtime == NULL)
return ERROR;
/* find the host or service associated with this downtime */
if (temp_downtime->type == HOST_DOWNTIME) {
if ((hst = find_host(temp_downtime->host_name)) == NULL)
return ERROR;
} else {
if ((svc = find_service(temp_downtime->host_name, temp_downtime->service_description)) == NULL)
return ERROR;
}
/* create the comment */
get_datetime_string(&(temp_downtime->start_time), start_time_string, MAX_DATETIME_LENGTH, SHORT_DATE_TIME);
get_datetime_string(&(temp_downtime->end_time), end_time_string, MAX_DATETIME_LENGTH, SHORT_DATE_TIME);
hours = temp_downtime->duration / 3600;
minutes = ((temp_downtime->duration - (hours * 3600)) / 60);
seconds = temp_downtime->duration - (hours * 3600) - (minutes * 60);
if (temp_downtime->type == HOST_DOWNTIME)
type_string = "host";
else
type_string = "service";
if (temp_downtime->fixed == TRUE)
asprintf(&temp_buffer, "This %s has been scheduled for fixed downtime from %s to %s. Notifications for the %s will not be sent out during that time period.", type_string, start_time_string, end_time_string, type_string);
else
asprintf(&temp_buffer, "This %s has been scheduled for flexible downtime starting between %s and %s and lasting for a period of %d hours and %d minutes. Notifications for the %s will not be sent out during that time period.", type_string, start_time_string, end_time_string, hours, minutes, type_string);
log_debug_info(DEBUGL_DOWNTIME, 0, "Scheduled Downtime Details:\n");
if (temp_downtime->type == HOST_DOWNTIME) {
log_debug_info(DEBUGL_DOWNTIME, 0, " Type: Host Downtime\n");
log_debug_info(DEBUGL_DOWNTIME, 0, " Host: %s\n", hst->name);
} else {
log_debug_info(DEBUGL_DOWNTIME, 0, " Type: Service Downtime\n");
log_debug_info(DEBUGL_DOWNTIME, 0, " Host: %s\n", svc->host_name);
log_debug_info(DEBUGL_DOWNTIME, 0, " Service: %s\n", svc->description);
}
log_debug_info(DEBUGL_DOWNTIME, 0, " Fixed/Flex: %s\n", (temp_downtime->fixed == TRUE) ? "Fixed" : "Flexible");
log_debug_info(DEBUGL_DOWNTIME, 0, " Start: %s\n", start_time_string);
log_debug_info(DEBUGL_DOWNTIME, 0, " End: %s\n", end_time_string);
log_debug_info(DEBUGL_DOWNTIME, 0, " Duration: %dh %dm %ds\n", hours, minutes, seconds);
log_debug_info(DEBUGL_DOWNTIME, 0, " Downtime ID: %lu\n", temp_downtime->downtime_id);
log_debug_info(DEBUGL_DOWNTIME, 0, " Trigger ID: %lu\n", temp_downtime->triggered_by);
log_debug_info(DEBUGL_DOWNTIME, 0, " Author: %s\n", (temp_downtime->author != NULL ? temp_downtime->author : "(Icinga Process)"));
/* add a non-persistent comment to the host or service regarding the scheduled outage */
if (temp_downtime->type == SERVICE_DOWNTIME)
add_new_comment(SERVICE_COMMENT, DOWNTIME_COMMENT, svc->host_name, svc->description, time(NULL), (temp_downtime->author != NULL ? temp_downtime->author : "(Icinga Process)"), temp_buffer, 0, COMMENTSOURCE_INTERNAL, FALSE, (time_t)0, &(temp_downtime->comment_id));
else
add_new_comment(HOST_COMMENT, DOWNTIME_COMMENT, hst->name, NULL, time(NULL), (temp_downtime->author != NULL ? temp_downtime->author : "(Icinga Process)"), temp_buffer, 0, COMMENTSOURCE_INTERNAL, FALSE, (time_t)0, &(temp_downtime->comment_id));
/* free comment buffer */
my_free(temp_buffer);
/*** SCHEDULE DOWNTIME - FLEXIBLE (NON-FIXED) DOWNTIME IS HANDLED AT A LATER POINT ***/
/* only non-triggered downtime is scheduled... */
if (temp_downtime->triggered_by == 0) {
if ((new_downtime_id = (unsigned long *)malloc(sizeof(unsigned long *)))) {
*new_downtime_id = downtime_id;
schedule_new_event(EVENT_SCHEDULED_DOWNTIME, TRUE, temp_downtime->start_time, FALSE, 0, NULL, FALSE, (void *)new_downtime_id, NULL, 0);
}
}
#ifdef PROBABLY_NOT_NEEDED
/*** FLEXIBLE DOWNTIME SANITY CHECK - ADDED 02/17/2008 ****/
/* if host/service is in a non-OK/UP state right now, see if we should start flexible time immediately */
/* this is new logic added in 3.0rc3 */
if (temp_downtime->fixed == FALSE) {
if (temp_downtime->type == HOST_DOWNTIME)
check_pending_flex_host_downtime(hst);
else
check_pending_flex_service_downtime(svc);
}
#endif
return OK;
}
/* handles scheduled downtime (id passed from timed event queue) */
int handle_scheduled_downtime_by_id(unsigned long downtime_id) {
scheduled_downtime *temp_downtime = NULL;
/* find the downtime entry */
if ((temp_downtime = find_downtime(ANY_DOWNTIME, downtime_id)) == NULL)
return ERROR;
/* handle the downtime */
return handle_scheduled_downtime(temp_downtime);
}
/* handles scheduled host or service downtime */
int handle_scheduled_downtime(scheduled_downtime *temp_downtime) {
scheduled_downtime *this_downtime = NULL;
host *hst = NULL;
service *svc = NULL;
time_t event_time = 0L;
time_t current_time = 0L;
unsigned long *new_downtime_id = NULL;
#ifdef USE_EVENT_BROKER
int attr = 0;
#endif
log_debug_info(DEBUGL_FUNCTIONS, 0, "handle_scheduled_downtime()\n");
if (temp_downtime == NULL)
return ERROR;
/* find the host or service associated with this downtime */
if (temp_downtime->type == HOST_DOWNTIME) {
if ((hst = find_host(temp_downtime->host_name)) == NULL)
return ERROR;
} else {
if ((svc = find_service(temp_downtime->host_name, temp_downtime->service_description)) == NULL)
return ERROR;
}
/* if downtime if flexible and host/svc is in an ok state, don't do anything right now (wait for event handler to kick it off) */
/* start_flex_downtime variable is set to TRUE by event handler functions */
if (temp_downtime->fixed == FALSE) {
/* we're not supposed to force a start of flex downtime... */
if (temp_downtime->start_flex_downtime == FALSE) {
/* host is up or service is ok, so we don't really do anything right now */
if ((temp_downtime->type == HOST_DOWNTIME && hst->current_state == HOST_UP) || (temp_downtime->type == SERVICE_DOWNTIME && svc->current_state == STATE_OK)) {
/* increment pending flex downtime counter */
if (temp_downtime->type == HOST_DOWNTIME)
hst->pending_flex_downtime++;
else
svc->pending_flex_downtime++;
temp_downtime->incremented_pending_downtime = TRUE;
/*** SINCE THE FLEX DOWNTIME MAY NEVER START, WE HAVE TO PROVIDE A WAY OF EXPIRING UNUSED DOWNTIME... ***/
schedule_new_event(EVENT_EXPIRE_DOWNTIME, TRUE, (temp_downtime->end_time + 1), FALSE, 0, NULL, FALSE, NULL, NULL, 0);
return OK;
}
}
}
time(¤t_time);
/* have we come to the end of the scheduled downtime? */
if (temp_downtime->is_in_effect == TRUE && ( /* downtime needs to be in effect and ... */
(temp_downtime->fixed == TRUE && current_time >= temp_downtime->end_time) || /* fixed downtime, endtime means end of downtime */
(temp_downtime->fixed == FALSE && current_time >= (temp_downtime->trigger_time+temp_downtime->duration)) /* flexible downtime, endtime of downtime is trigger_time+duration */
)){
if (temp_downtime->type == HOST_DOWNTIME)
log_debug_info(DEBUGL_DOWNTIME, 0, "Host '%s' ending %s scheduled downtime (id=%lu) with depth=%d, starttime=%lu, entrytime=%lu, triggertime=%lu, endtime=%lu, duration=%lu.\n", hst->name, (temp_downtime->fixed == TRUE) ? "fixed" : "flexible", temp_downtime->downtime_id, hst->scheduled_downtime_depth, temp_downtime->start_time, temp_downtime->entry_time, temp_downtime->trigger_time, temp_downtime->end_time, temp_downtime->duration);
else
log_debug_info(DEBUGL_DOWNTIME, 0, "Service '%s' on host '%s' ending %s scheduled downtime (id=%lu) with depth=%d, starttime=%lu, entrytime=%lu, triggertime=%lu, endtime=%lu, duration=%lu.\n", svc->description, svc->host_name, (temp_downtime->fixed == TRUE) ? "fixed" : "flexible", temp_downtime->downtime_id, svc->scheduled_downtime_depth, temp_downtime->start_time, temp_downtime->entry_time, temp_downtime->trigger_time, temp_downtime->end_time, temp_downtime->duration);
#ifdef USE_EVENT_BROKER
/* send data to event broker */
attr = NEBATTR_DOWNTIME_STOP_NORMAL;
broker_downtime_data(NEBTYPE_DOWNTIME_STOP, NEBFLAG_NONE, attr, temp_downtime->type, temp_downtime->host_name, temp_downtime->service_description, temp_downtime->entry_time, temp_downtime->author, temp_downtime->comment, temp_downtime->start_time, temp_downtime->end_time, temp_downtime->fixed, temp_downtime->triggered_by, temp_downtime->duration, temp_downtime->downtime_id, NULL, temp_downtime->is_in_effect, temp_downtime->trigger_time);
#endif
/* decrement the downtime depth variable */
if (temp_downtime->type == HOST_DOWNTIME)
hst->scheduled_downtime_depth--;
else
svc->scheduled_downtime_depth--;
if (temp_downtime->type == HOST_DOWNTIME && hst->scheduled_downtime_depth == 0) {
log_debug_info(DEBUGL_DOWNTIME, 0, "Host '%s' has exited from a period of scheduled downtime (id=%lu).\n", hst->name, temp_downtime->downtime_id);
/* log a notice - this one is parsed by the history CGI */
logit(NSLOG_INFO_MESSAGE, FALSE, "HOST DOWNTIME ALERT: %s;STOPPED; Host has exited from a period of scheduled downtime", hst->name);
/* send a notification */
host_notification(hst, NOTIFICATION_DOWNTIMEEND, temp_downtime->author, temp_downtime->comment, NOTIFICATION_OPTION_NONE);
}
else if (temp_downtime->type == SERVICE_DOWNTIME && svc->scheduled_downtime_depth == 0) {
log_debug_info(DEBUGL_DOWNTIME, 0, "Service '%s' on host '%s' has exited from a period of scheduled downtime (id=%lu).\n", svc->description, svc->host_name, temp_downtime->downtime_id);
/* log a notice - this one is parsed by the history CGI */
logit(NSLOG_INFO_MESSAGE, FALSE, "SERVICE DOWNTIME ALERT: %s;%s;STOPPED; Service has exited from a period of scheduled downtime", svc->host_name, svc->description);
/* send a notification */
service_notification(svc, NOTIFICATION_DOWNTIMEEND, temp_downtime->author, temp_downtime->comment, NOTIFICATION_OPTION_NONE);
}
/* update the status data */
if (temp_downtime->type == HOST_DOWNTIME)
update_host_status(hst, FALSE);
else
update_service_status(svc, FALSE);
/* decrement pending flex downtime if necessary */
if (temp_downtime->fixed == FALSE && temp_downtime->incremented_pending_downtime == TRUE) {
if (temp_downtime->type == HOST_DOWNTIME) {
if (hst->pending_flex_downtime > 0)
hst->pending_flex_downtime--;
} else {
if (svc->pending_flex_downtime > 0)
svc->pending_flex_downtime--;
}
}
/* handle (stop) downtime that is triggered by this one */
while (1) {
/* list contents might change by recursive calls, so we use this inefficient method to prevent segfaults */
for (this_downtime = scheduled_downtime_list; this_downtime != NULL; this_downtime = this_downtime->next) {
if (this_downtime->triggered_by == temp_downtime->downtime_id) {
handle_scheduled_downtime(this_downtime);
break;
}
}
if (this_downtime == NULL)
break;
}
/* delete downtime entry */
if (temp_downtime->type == HOST_DOWNTIME)
delete_host_downtime(temp_downtime->downtime_id);
else
delete_service_downtime(temp_downtime->downtime_id);
}
/* else we are just starting the scheduled downtime */
else {
if (temp_downtime->type == HOST_DOWNTIME)
log_debug_info(DEBUGL_DOWNTIME, 0, "Host '%s' starting %s scheduled downtime (id=%lu) with depth=%d, starttime=%lu, entrytime=%lu, endtime=%lu, duration=%lu.\n", hst->name, (temp_downtime->fixed == TRUE) ? "fixed" : "flexible", temp_downtime->downtime_id, hst->scheduled_downtime_depth, temp_downtime->start_time, temp_downtime->entry_time, temp_downtime->end_time, temp_downtime->duration);
else
log_debug_info(DEBUGL_DOWNTIME, 0, "Service '%s' on host '%s' starting %s scheduled downtime (id=%lu) with depth=%d, starttime=%lu, entrytime=%lu, endtime=%lu, duration=%lu.\n", svc->description, svc->host_name, (temp_downtime->fixed == TRUE) ? "fixed" : "flexible", temp_downtime->downtime_id, svc->scheduled_downtime_depth, temp_downtime->start_time, temp_downtime->entry_time, temp_downtime->end_time, temp_downtime->duration);
/* this happens after restart of icinga */
if (temp_downtime->is_in_effect != TRUE) {
if (temp_downtime->type == HOST_DOWNTIME && hst->scheduled_downtime_depth == 0) {
/* set the trigger time, needed to detect the end of a flexible downtime */
temp_downtime->trigger_time = current_time;
log_debug_info(DEBUGL_DOWNTIME, 0, "Host '%s' has entered a period of scheduled downtime (id=%lu) at triggertime=%lu.\n", hst->name, temp_downtime->downtime_id, temp_downtime->trigger_time);
/* log a notice - this one is parsed by the history CGI */
logit(NSLOG_INFO_MESSAGE, FALSE, "HOST DOWNTIME ALERT: %s;STARTED; Host has entered a period of scheduled downtime", hst->name);
/* send a notification */
host_notification(hst, NOTIFICATION_DOWNTIMESTART, temp_downtime->author, temp_downtime->comment, NOTIFICATION_OPTION_NONE);
}
else if (temp_downtime->type == SERVICE_DOWNTIME && svc->scheduled_downtime_depth == 0) {
/* set the trigger time, needed to detect the end of a flexible downtime */
temp_downtime->trigger_time = current_time;
log_debug_info(DEBUGL_DOWNTIME, 0, "Service '%s' on host '%s' has entered a period of scheduled downtime (id=%lu) at triggertime=%lu.\n", svc->description, svc->host_name, temp_downtime->downtime_id, temp_downtime->trigger_time);
/* log a notice - this one is parsed by the history CGI */
logit(NSLOG_INFO_MESSAGE, FALSE, "SERVICE DOWNTIME ALERT: %s;%s;STARTED; Service has entered a period of scheduled downtime", svc->host_name, svc->description);
/* send a notification */
service_notification(svc, NOTIFICATION_DOWNTIMESTART, temp_downtime->author, temp_downtime->comment, NOTIFICATION_OPTION_NONE);
}
}
/* increment the downtime depth variable */
if (temp_downtime->type == HOST_DOWNTIME)
hst->scheduled_downtime_depth++;
else
svc->scheduled_downtime_depth++;
/* set the in effect flag */
temp_downtime->is_in_effect = TRUE;
#ifdef USE_EVENT_BROKER
/* send data to broker AFTER we know trigger_time, is_in_effect, and downtime_depth */
broker_downtime_data(NEBTYPE_DOWNTIME_START, NEBFLAG_NONE, NEBATTR_NONE, temp_downtime->type, temp_downtime->host_name, temp_downtime->service_description, temp_downtime->entry_time, temp_downtime->author, temp_downtime->comment, temp_downtime->start_time, temp_downtime->end_time, temp_downtime->fixed, temp_downtime->triggered_by, temp_downtime->duration, temp_downtime->downtime_id, NULL, temp_downtime->is_in_effect, temp_downtime->trigger_time);
#endif
/* update the status data */
if (temp_downtime->type == HOST_DOWNTIME)
update_host_status(hst, FALSE);
else
update_service_status(svc, FALSE);
/* schedule an event */
if (temp_downtime->fixed == FALSE)
event_time = (time_t)((unsigned long)time(NULL) + temp_downtime->duration);
else
event_time = temp_downtime->end_time;
if ((new_downtime_id = (unsigned long *)malloc(sizeof(unsigned long *)))) {
*new_downtime_id = temp_downtime->downtime_id;
schedule_new_event(EVENT_SCHEDULED_DOWNTIME, TRUE, event_time, FALSE, 0, NULL, FALSE, (void *)new_downtime_id, NULL, 0);
}
/* handle (start) downtime that is triggered by this one */
for (this_downtime = scheduled_downtime_list; this_downtime != NULL; this_downtime = this_downtime->next) {
if (this_downtime->triggered_by == temp_downtime->downtime_id)
handle_scheduled_downtime(this_downtime);
}
}
return OK;
}
/* checks for flexible (non-fixed) host downtime that should start now */
int check_pending_flex_host_downtime(host *hst) {
scheduled_downtime *temp_downtime = NULL;
time_t current_time = 0L;
log_debug_info(DEBUGL_FUNCTIONS, 0, "check_pending_flex_host_downtime()\n");
if (hst == NULL)
return ERROR;
time(¤t_time);
/* if host is currently up, nothing to do */
if (hst->current_state == HOST_UP)
return OK;
/* check all downtime entries */
for (temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
if (temp_downtime->type != HOST_DOWNTIME)
continue;
if (temp_downtime->fixed == TRUE)
continue;
if (temp_downtime->is_in_effect == TRUE)
continue;
/* triggered downtime entries should be ignored here */
if (temp_downtime->triggered_by != 0)
continue;
/* this entry matches our host! */
if (find_host(temp_downtime->host_name) == hst) {
/* if the time boundaries are okay, start this scheduled downtime */
if (temp_downtime->start_time <= current_time && current_time <= temp_downtime->end_time) {
log_debug_info(DEBUGL_DOWNTIME, 0, "Flexible downtime (id=%lu) for host '%s' starting now...\n", temp_downtime->downtime_id, hst->name);
temp_downtime->start_flex_downtime = TRUE;
handle_scheduled_downtime(temp_downtime);
}
}
}
return OK;
}
/* checks for flexible (non-fixed) service downtime that should start now */
int check_pending_flex_service_downtime(service *svc) {
scheduled_downtime *temp_downtime = NULL;
time_t current_time = 0L;
log_debug_info(DEBUGL_FUNCTIONS, 0, "check_pending_flex_service_downtime()\n");
if (svc == NULL)
return ERROR;
time(¤t_time);
/* if service is currently ok, nothing to do */
if (svc->current_state == STATE_OK)
return OK;
/* check all downtime entries */
for (temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
if (temp_downtime->type != SERVICE_DOWNTIME)
continue;
if (temp_downtime->fixed == TRUE)
continue;
if (temp_downtime->is_in_effect == TRUE)
continue;
/* triggered downtime entries should be ignored here */
if (temp_downtime->triggered_by != 0)
continue;
/* this entry matches our service! */
if (find_service(temp_downtime->host_name, temp_downtime->service_description) == svc) {
/* if the time boundaries are okay, start this scheduled downtime */
if (temp_downtime->start_time <= current_time && current_time <= temp_downtime->end_time) {
log_debug_info(DEBUGL_DOWNTIME, 0, "Flexible downtime (id=%lu) for service '%s' on host '%s' starting now...\n", temp_downtime->downtime_id, svc->description, svc->host_name);
temp_downtime->start_flex_downtime = TRUE;
handle_scheduled_downtime(temp_downtime);
}
}
}
return OK;
}
/* checks for (and removes) expired downtime entries */
int check_for_expired_downtime(void) {
scheduled_downtime *temp_downtime = NULL;
scheduled_downtime *next_downtime = NULL;
time_t current_time = 0L;
log_debug_info(DEBUGL_FUNCTIONS, 0, "check_for_expired_downtime()\n");
time(¤t_time);
/* check all downtime entries... */
for (temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = next_downtime) {
next_downtime = temp_downtime->next;
/* this entry should be removed */
if (temp_downtime->is_in_effect == FALSE && temp_downtime->end_time < current_time) {
log_debug_info(DEBUGL_DOWNTIME, 0, "Expiring %s downtime (id=%lu)...\n", (temp_downtime->type == HOST_DOWNTIME) ? "host" : "service", temp_downtime->downtime_id);
/* delete the downtime entry */
if (temp_downtime->type == HOST_DOWNTIME)
delete_host_downtime(temp_downtime->downtime_id);
else
delete_service_downtime(temp_downtime->downtime_id);
}
}
return OK;
}
/******************************************************************/
/************************* SAVE FUNCTIONS *************************/
/******************************************************************/
/* save a host or service downtime */
int add_new_downtime(int type, char *host_name, char *service_description, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *downtime_id, int is_in_effect, time_t trigger_time) {
int result = OK;
if (type == HOST_DOWNTIME)
result = add_new_host_downtime(host_name, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect, trigger_time);
else
result = add_new_service_downtime(host_name, service_description, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect, trigger_time);
return result;
}
/* saves a host downtime entry */
int add_new_host_downtime(char *host_name, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *downtime_id, int is_in_effect, time_t trigger_time) {
int result = OK;
unsigned long new_downtime_id = 0L;
if (host_name == NULL)
return ERROR;
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XDDDEFAULT
result = xdddefault_add_new_host_downtime(host_name, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, &new_downtime_id, is_in_effect, trigger_time);
#endif
/* save downtime id */
if (downtime_id != NULL)
*downtime_id = new_downtime_id;
#ifdef USE_EVENT_BROKER
/* send data to event broker */
broker_downtime_data(NEBTYPE_DOWNTIME_ADD, NEBFLAG_NONE, NEBATTR_NONE, HOST_DOWNTIME, host_name, NULL, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, new_downtime_id, NULL, is_in_effect, trigger_time);
#endif
return result;
}
/* saves a service downtime entry */
int add_new_service_downtime(char *host_name, char *service_description, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *downtime_id, int is_in_effect, time_t trigger_time) {
int result = OK;
unsigned long new_downtime_id = 0L;
if (host_name == NULL || service_description == NULL)
return ERROR;
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XDDDEFAULT
result = xdddefault_add_new_service_downtime(host_name, service_description, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, &new_downtime_id, is_in_effect, trigger_time);
#endif
/* save downtime id */
if (downtime_id != NULL)
*downtime_id = new_downtime_id;
#ifdef USE_EVENT_BROKER
/* send data to event broker */
broker_downtime_data(NEBTYPE_DOWNTIME_ADD, NEBFLAG_NONE, NEBATTR_NONE, SERVICE_DOWNTIME, host_name, service_description, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, new_downtime_id, NULL, is_in_effect, trigger_time);
#endif
return result;
}
/******************************************************************/
/*********************** DELETION FUNCTIONS ***********************/
/******************************************************************/
/* deletes a scheduled host or service downtime entry from the list in memory */
int delete_downtime(int type, unsigned long downtime_id) {
int result = OK;
scheduled_downtime *this_downtime = NULL;
scheduled_downtime *last_downtime = NULL;
scheduled_downtime *next_downtime = NULL;
#ifdef NSCORE
pthread_mutex_lock(&icinga_downtime_lock);
#endif
/* find the downtime we should remove */
for (this_downtime = scheduled_downtime_list, last_downtime = scheduled_downtime_list; this_downtime != NULL; this_downtime = next_downtime) {
next_downtime = this_downtime->next;
/* we found the downtime we should delete */
if (this_downtime->downtime_id == downtime_id && this_downtime->type == type)
break;
last_downtime = this_downtime;
}
/* remove the downtime from the list in memory */
if (this_downtime != NULL) {
/* first remove the comment associated with this downtime */
if (this_downtime->type == HOST_DOWNTIME)
delete_host_comment(this_downtime->comment_id);
else
delete_service_comment(this_downtime->comment_id);
#ifdef USE_EVENT_BROKER
/* send data to event broker */
broker_downtime_data(NEBTYPE_DOWNTIME_DELETE, NEBFLAG_NONE, NEBATTR_NONE, type, this_downtime->host_name, this_downtime->service_description, this_downtime->entry_time, this_downtime->author, this_downtime->comment, this_downtime->start_time, this_downtime->end_time, this_downtime->fixed, this_downtime->triggered_by, this_downtime->duration, downtime_id, NULL, this_downtime->is_in_effect, this_downtime->trigger_time);
#endif
if (scheduled_downtime_list == this_downtime)
scheduled_downtime_list = this_downtime->next;
else
last_downtime->next = next_downtime;
/* free memory */
my_free(this_downtime->host_name);
my_free(this_downtime->service_description);
my_free(this_downtime->author);
my_free(this_downtime->comment);
my_free(this_downtime);
result = OK;
} else
result = ERROR;
#ifdef NSCORE
pthread_mutex_unlock(&icinga_downtime_lock);
#endif
return result;
}
/* deletes a scheduled host downtime entry */
int delete_host_downtime(unsigned long downtime_id) {
int result = OK;
/* delete the downtime from memory */
delete_downtime(HOST_DOWNTIME, downtime_id);
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XDDDEFAULT
result = xdddefault_delete_host_downtime(downtime_id);
#endif
return result;
}
/* deletes a scheduled service downtime entry */
int delete_service_downtime(unsigned long downtime_id) {
int result = OK;
/* delete the downtime from memory */
delete_downtime(SERVICE_DOWNTIME, downtime_id);
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XDDDEFAULT
result = xdddefault_delete_service_downtime(downtime_id);
#endif
return result;
}
/*
Deletes all host and service downtimes on a host by hostname, optionally filtered by service description, start time and comment.
All char* must be set or NULL - "" will silently fail to match
Returns number deleted
*/
int delete_downtime_by_hostname_service_description_start_time_comment(char *hostname, char *service_description, time_t start_time, char *comment) {
scheduled_downtime *temp_downtime;
scheduled_downtime *next_downtime;
int deleted = 0;
/* Do not allow deletion of everything - must have at least 1 filter on */
if (hostname == NULL && service_description == NULL && start_time == 0 && comment == NULL)
return deleted;
/*
* lock while traversing the list
* so that other threads cannot modify
*/
#ifdef NSCORE
pthread_mutex_lock(&icinga_downtime_lock);
#endif
for (temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = next_downtime) {
next_downtime = temp_downtime->next;
if (start_time != 0 && temp_downtime->start_time != start_time) {
continue;
}
if (comment != NULL && strcmp(temp_downtime->comment, comment) != 0)
continue;
if (temp_downtime->type == HOST_DOWNTIME) {
/* If service is specified, then do not delete the host downtime */
if (service_description != NULL)
continue;
if (hostname != NULL && strcmp(temp_downtime->host_name, hostname) != 0)
continue;
} else if (temp_downtime->type == SERVICE_DOWNTIME) {
if (hostname != NULL && strcmp(temp_downtime->host_name, hostname) != 0)
continue;
if (service_description != NULL && strcmp(temp_downtime->service_description, service_description) != 0)
continue;
}
#ifdef NSCORE
/* unlock here, because delete_*_downtime will try to lock itsself */
pthread_mutex_unlock(&icinga_downtime_lock);
#endif
unschedule_downtime(temp_downtime->type, temp_downtime->downtime_id);
#ifdef NSCORE
pthread_mutex_lock(&icinga_downtime_lock);
#endif
deleted++;
}
#ifdef NSCORE
pthread_mutex_unlock(&icinga_downtime_lock);
#endif
return deleted;
}
#endif
/******************************************************************/
/******************** ADDITION FUNCTIONS **************************/
/******************************************************************/
/* adds a host downtime entry to the list in memory */
int add_host_downtime(char *host_name, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long downtime_id, int is_in_effect, time_t trigger_time) {
int result = OK;
result = add_downtime(HOST_DOWNTIME, host_name, NULL, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect, trigger_time);
return result;
}
/* adds a service downtime entry to the list in memory */
int add_service_downtime(char *host_name, char *svc_description, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long downtime_id, int is_in_effect, time_t trigger_time) {
int result = OK;
result = add_downtime(SERVICE_DOWNTIME, host_name, svc_description, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, downtime_id, is_in_effect, trigger_time);
return result;
}
/* adds a host or service downtime entry to the list in memory */
int add_downtime(int downtime_type, char *host_name, char *svc_description, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long downtime_id, int is_in_effect, time_t trigger_time) {
scheduled_downtime *new_downtime = NULL;
scheduled_downtime *last_downtime = NULL;
scheduled_downtime *temp_downtime = NULL;
int result = OK;
/* don't add triggered downtimes that don't have a valid parent */
if (triggered_by > 0 && find_downtime(ANY_DOWNTIME, triggered_by) == NULL)
return ERROR;
/* we don't have enough info */
if (host_name == NULL || (downtime_type == SERVICE_DOWNTIME && svc_description == NULL))
return ERROR;
/* allocate memory for the downtime */
if ((new_downtime = (scheduled_downtime *)calloc(1, sizeof(scheduled_downtime))) == NULL)
return ERROR;
/* duplicate vars */
if ((new_downtime->host_name = (char *)strdup(host_name)) == NULL)
result = ERROR;
if (downtime_type == SERVICE_DOWNTIME) {
if ((new_downtime->service_description = (char *)strdup(svc_description)) == NULL)
result = ERROR;
}
if (author) {
if ((new_downtime->author = (char *)strdup(author)) == NULL)
result = ERROR;
}
if (comment_data) {
if ((new_downtime->comment = (char *)strdup(comment_data)) == NULL)
result = ERROR;
}
/* handle errors */
if (result == ERROR) {
my_free(new_downtime->comment);
my_free(new_downtime->author);
my_free(new_downtime->service_description);
my_free(new_downtime->host_name);
my_free(new_downtime);
return ERROR;
}
new_downtime->type = downtime_type;
new_downtime->entry_time = entry_time;
new_downtime->start_time = start_time;
new_downtime->end_time = end_time;
new_downtime->fixed = (fixed > 0) ? TRUE : FALSE;
new_downtime->triggered_by = triggered_by;
new_downtime->duration = duration;
new_downtime->downtime_id = downtime_id;
new_downtime->is_in_effect = is_in_effect;
new_downtime->trigger_time = trigger_time;
if (defer_downtime_sorting) {
new_downtime->next = scheduled_downtime_list;
scheduled_downtime_list = new_downtime;
} else {
/*
* add new downtime to downtime list, sorted by start time,
* but lock the lists first so broker modules fiddling
* with them at the same time doesn't crash out.
*/
#ifdef NSCORE
pthread_mutex_lock(&icinga_downtime_lock);
#endif
last_downtime = scheduled_downtime_list;
for (temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
if (new_downtime->start_time < temp_downtime->start_time) {
new_downtime->next = temp_downtime;
if (temp_downtime == scheduled_downtime_list)
scheduled_downtime_list = new_downtime;
else
last_downtime->next = new_downtime;
break;
} else
last_downtime = temp_downtime;
}
if (scheduled_downtime_list == NULL) {
new_downtime->next = NULL;
scheduled_downtime_list = new_downtime;
} else if (temp_downtime == NULL) {
new_downtime->next = NULL;
last_downtime->next = new_downtime;
}
#ifdef NSCORE
pthread_mutex_unlock(&icinga_downtime_lock);
#endif
}
#ifdef NSCORE
#ifdef USE_EVENT_BROKER
/* send data to event broker */
broker_downtime_data(NEBTYPE_DOWNTIME_LOAD, NEBFLAG_NONE, NEBATTR_NONE, downtime_type, host_name, svc_description, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, downtime_id, NULL, is_in_effect, trigger_time);
#endif
#endif
return OK;
}
static int downtime_compar(const void *p1, const void *p2) {
scheduled_downtime *d1 = *(scheduled_downtime **)p1;
scheduled_downtime *d2 = *(scheduled_downtime **)p2;
/* if the valid parent is read from status/retention.dat
* after the child downtime, this comparison is considered
* invalid then.
* the fix assumes that:
* - parent and child downtimes have the same start time
* - downtime_id is ascending, and parent/trigger id before child id
*
return (d1->start_time < d2->start_time) ? -1 : (d1->start_time - d2->start_time);
*/
return (d1->start_time == d2->start_time) ? (d1->downtime_id - d2->downtime_id) : (d1->start_time - d2->start_time);
}
int sort_downtime(void) {
scheduled_downtime **array, *temp_downtime;
unsigned long i = 0, unsorted_downtimes = 0;
if (!defer_downtime_sorting)
return OK;
defer_downtime_sorting = 0;
temp_downtime = scheduled_downtime_list;
while (temp_downtime != NULL) {
temp_downtime = temp_downtime->next;
unsorted_downtimes++;
}
if (!unsorted_downtimes)
return OK;
if (!(array = malloc(sizeof(*array) * unsorted_downtimes)))
return ERROR;
while (scheduled_downtime_list) {
array[i++] = scheduled_downtime_list;
scheduled_downtime_list = scheduled_downtime_list->next;
}
qsort((void *)array, i, sizeof(*array), downtime_compar);
scheduled_downtime_list = temp_downtime = array[0];
for (i = 1; i < unsorted_downtimes; i++) {
temp_downtime->next = array[i];
temp_downtime = temp_downtime->next;
}
temp_downtime->next = NULL;
my_free(array);
return OK;
}
/******************************************************************/
/************************ SEARCH FUNCTIONS ************************/
/******************************************************************/
/* finds a specific downtime entry */
scheduled_downtime *find_downtime(int type, unsigned long downtime_id) {
scheduled_downtime *temp_downtime = NULL;
for (temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
if (type != ANY_DOWNTIME && temp_downtime->type != type)
continue;
if (temp_downtime->downtime_id == downtime_id)
return temp_downtime;
}
return NULL;
}
/* finds a specific host downtime entry */
scheduled_downtime *find_host_downtime(unsigned long downtime_id) {
return find_downtime(HOST_DOWNTIME, downtime_id);
}
/* finds a specific service downtime entry */
scheduled_downtime *find_service_downtime(unsigned long downtime_id) {
return find_downtime(SERVICE_DOWNTIME, downtime_id);
}
/* finds a specific downtime entry by similar content (in a distributed environment, downtime_ids are not synchronised) */
scheduled_downtime *find_downtime_by_similar_content(int type, char *host_name, char *service_description, char *author, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long duration) {
scheduled_downtime *temp_downtime = NULL;
if (service_description == NULL) {
if (type == ANY_DOWNTIME)
type = HOST_DOWNTIME;
/* Must specify a service_description if you are searching services - obviously! */
if (type == SERVICE_DOWNTIME)
return NULL;
}
for (temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
if (type != ANY_DOWNTIME && temp_downtime->type != type)
continue;
if (temp_downtime->start_time == start_time
&& temp_downtime->end_time == end_time
&& temp_downtime->fixed == fixed
&& temp_downtime->duration == duration
&& strcmp(temp_downtime->host_name, host_name) == 0
&& (service_description == NULL || (temp_downtime->type == SERVICE_DOWNTIME && strcmp(temp_downtime->service_description, service_description) == 0))
&& strcmp(temp_downtime->author, author) == 0
&& strcmp(temp_downtime->comment, comment_data) == 0)
return temp_downtime;
}
return NULL;
}
/******************************************************************/
/********************* CLEANUP FUNCTIONS **************************/
/******************************************************************/
/* frees memory allocated for the scheduled downtime data */
void free_downtime_data(void) {
scheduled_downtime *this_downtime = NULL;
scheduled_downtime *next_downtime = NULL;
/* free memory for the scheduled_downtime list */
for (this_downtime = scheduled_downtime_list; this_downtime != NULL; this_downtime = next_downtime) {
next_downtime = this_downtime->next;
my_free(this_downtime->host_name);
my_free(this_downtime->service_description);
my_free(this_downtime->author);
my_free(this_downtime->comment);
my_free(this_downtime);
}
/* reset list pointer */
scheduled_downtime_list = NULL;
return;
}
icinga-1.10.3/common/macros.c 0000664 0000000 0000000 00000317716 12276402000 0015756 0 ustar 00root root 0000000 0000000 /*****************************************************************************
*
* MACROS.C - Common macro functions for Icinga
*
* Copyright (c) 1999-2009 Ethan Galstad (egalstad@nagios.org)
* Copyright (c) 2009-2013 Nagios Core Development Team and Community Contributors
* Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*****************************************************************************/
#include "../include/macros.h"
#include "../include/config.h"
#include "../include/common.h"
#include "../include/objects.h"
#include "../include/statusdata.h"
#include "../include/comments.h"
#ifdef NSCORE
#include "../include/icinga.h"
#else
#include "../include/cgiutils.h"
#endif
#ifdef NSCORE
extern int use_large_installation_tweaks;
extern int enable_environment_macros;
extern int keep_unknown_macros;
#endif
extern char *illegal_output_chars;
extern char illegal_output_char_map[256];
extern contact *contact_list;
extern contactgroup *contactgroup_list;
extern host *host_list;
extern hostgroup *hostgroup_list;
extern service *service_list;
extern servicegroup *servicegroup_list;
extern command *command_list;
extern timeperiod *timeperiod_list;
char *macro_x_names[MACRO_X_COUNT]; /* the macro names */
char *macro_user[MAX_USER_MACROS]; /* $USERx$ macros */
struct macro_key_code {
char *name; /* macro key name */
int code; /* numeric macro code, usable in case statements */
int clean_options;
char *value;
};
struct macro_key_code macro_keys[MACRO_X_COUNT];
/**
* These point to their corresponding pointer arrays in global_macros
* AFTER macros have been initialized.
*
* They really only exist so that eventbroker modules that reference
* them won't need to be re-compiled, although modules that rely
* on their values after having run a certain command will require an
* update
*/
char **macro_x = NULL;
/**
* scoped to this file to prevent (unintentional) mischief,
* but see base/notifications.c for how to use it
*/
static icinga_macros global_macros;
icinga_macros *get_global_macros(void) {
return &global_macros;
}
/******************************************************************/
/************************ MACRO FUNCTIONS *************************/
/******************************************************************/
/*
* locate a macro key based on its name by using a binary search
* over all keys. O(log(n)) complexity and a vast improvement over
* the previous linear scan
*/
const struct macro_key_code *find_macro_key(const char *name) {
unsigned int high, low = 0;
int value;
struct macro_key_code *key;
high = MACRO_X_COUNT;
while (high - low > 0) {
unsigned int mid = low + ((high - low) / 2);
key = ¯o_keys[mid];
value = strcmp(name, key->name);
if (value == 0) {
return key;
}
if (value > 0)
low = mid + 1;
else
high = mid;
}
return NULL;
}
/**
* replace macros in notification commands with their values,
* the thread-safe version
*/
int process_macros_r(icinga_macros *mac, char *input_buffer, char **output_buffer, int options) {
char *temp_buffer = NULL;
char *save_buffer = NULL;
char *buf_ptr = NULL;
char *delim_ptr = NULL;
int in_macro = FALSE;
char *selected_macro = NULL;
char *original_macro = NULL;
char *cleaned_macro = NULL;
int clean_macro = FALSE;
int result = OK;
int clean_options = 0;
int free_macro = FALSE;
int macro_options = 0;
log_debug_info(DEBUGL_FUNCTIONS, 0, "process_macros_r()\n");
if (output_buffer == NULL)
return ERROR;
*output_buffer = (char *)strdup("");
if (input_buffer == NULL)
return ERROR;
in_macro = FALSE;
log_debug_info(DEBUGL_MACROS, 1, "**** BEGIN MACRO PROCESSING ***********\n");
log_debug_info(DEBUGL_MACROS, 1, "Processing: '%s'\n", input_buffer);
/* save original input_buffer ptr for later free'ing */
save_buffer = buf_ptr = (input_buffer ? strdup(input_buffer) : NULL);
while (buf_ptr) {
/* save pointer to this working part of buffer */
temp_buffer = buf_ptr;
/* find the next delimiter - terminate preceding string and advance buffer pointer for next run */
if ((delim_ptr = strchr(buf_ptr, '$'))) {
delim_ptr[0] = '\x0';
buf_ptr = (char *)delim_ptr + 1;
}
/* no delimiter found - we already have the last of the buffer */
else
buf_ptr = NULL;
log_debug_info(DEBUGL_MACROS, 2, " Processing part: '%s'\n", temp_buffer);
selected_macro = NULL;
clean_macro = FALSE;
/* we're in plain text... */
if (in_macro == FALSE) {
/* add the plain text to the end of the already processed buffer */
*output_buffer = (char *)realloc(*output_buffer, strlen(*output_buffer) + strlen(temp_buffer) + 1);
strcat(*output_buffer, temp_buffer);
log_debug_info(DEBUGL_MACROS, 2, " Not currently in macro. Running output (%lu): '%s'\n", (unsigned long)strlen(*output_buffer), *output_buffer);
in_macro = TRUE;
}
/* looks like we're in a macro, so process it... */
else {
/* reset clean options */
clean_options = 0;
/* grab the macro value */
result = grab_macro_value_r(mac, temp_buffer, &selected_macro, &clean_options, &free_macro);
log_debug_info(DEBUGL_MACROS, 2, " Processed '%s', Clean Options: %d, Free: %d\n, Value: '%s'", temp_buffer, clean_options, free_macro, selected_macro ? selected_macro : "");
/* an error occurred - we couldn't parse the macro, so continue on */
if (result == ERROR) {
/* empty string still could mean that we hit the escaped $, so log an error in all other cases */
/* the error tells the user that the macro is valid, but value fetching contained error*/
if(strcmp(temp_buffer, "")) {
log_debug_info(DEBUGL_MACROS, 2, " Warning: Error grabbing macro '%s' value '%s'! Maybe used in the wrong scope? Check the docs.\n", temp_buffer, selected_macro ? selected_macro : "" );
#ifdef NSCORE
if (keep_unknown_macros == FALSE) {
logit(NSLOG_RUNTIME_WARNING, TRUE, "Warning: Error grabbing macro '%s' value '%s'! Maybe used in the wrong scope? Check the docs.\n", temp_buffer, selected_macro ? selected_macro : "" );
}
#endif
}
if (free_macro == TRUE)
my_free(selected_macro);
}
/* we already have a macro... */
if (result == OK)
; /* do nothing special if things worked out ok */
/* an escaped $ is done by specifying two $$ next to each other */
else if (!strcmp(temp_buffer, "")) {
log_debug_info(DEBUGL_MACROS, 2, " Escaped $. Running output (%lu): '%s'\n", (unsigned long)strlen(*output_buffer), *output_buffer);
*output_buffer = (char *)realloc(*output_buffer, strlen(*output_buffer) + 2);
strcat(*output_buffer, "$");
}
/* a non-macro, just some user-defined string between two $s */
else {
log_debug_info(DEBUGL_MACROS, 2, " Non-macro. Running output (%lu): '%s'\n", (unsigned long)strlen(*output_buffer), *output_buffer);
#ifdef NSCORE
if (keep_unknown_macros == TRUE) {
#endif
/* add the plain text to the end of the already processed buffer */
*output_buffer = (char *)realloc(*output_buffer, strlen(*output_buffer) + strlen(temp_buffer) + 3);
strcat(*output_buffer, "$");
strcat(*output_buffer, temp_buffer);
if (buf_ptr != NULL)
strcat(*output_buffer, "$");
#ifdef NSCORE
} else {
/* do not process unknown macros */
logit(NSLOG_RUNTIME_WARNING, TRUE, "Warning: Skipping unknown macro '$%s$', removing it from output! Fix your config, or set keep_unknown_macros accordingly...\n", temp_buffer);
}
#endif
}
/* insert macro */
if (selected_macro != NULL) {
log_debug_info(DEBUGL_MACROS, 2, " Processed '%s', Clean Options: %d, Free: %d\n", temp_buffer, clean_options, free_macro);
/* include any cleaning options passed back to us */
macro_options = (options | clean_options);
log_debug_info(DEBUGL_MACROS, 2, " Cleaning options: global=%d, local=%d, effective=%d\n", options, clean_options, macro_options);
/* URL encode the macro if requested - this allocates new memory */
if (macro_options & URL_ENCODE_MACRO_CHARS) {
original_macro = selected_macro;
selected_macro = get_url_encoded_string(selected_macro);
if (free_macro == TRUE) {
my_free(original_macro);
}
free_macro = TRUE;
}
/* some macros are cleaned... */
if (clean_macro == TRUE || ((macro_options & STRIP_ILLEGAL_MACRO_CHARS) || (macro_options & ESCAPE_MACRO_CHARS))) {
/* add the (cleaned) processed macro to the end of the already processed buffer */
if (selected_macro != NULL && (cleaned_macro = clean_macro_chars(selected_macro, macro_options)) != NULL) {
*output_buffer = (char *)realloc(*output_buffer, strlen(*output_buffer) + strlen(cleaned_macro) + 1);
strcat(*output_buffer, cleaned_macro);
log_debug_info(DEBUGL_MACROS, 2, " Cleaned macro. Running output (%lu): '%s'\n", (unsigned long)strlen(*output_buffer), *output_buffer);
}
}
/* others are not cleaned */
else {
/* add the processed macro to the end of the already processed buffer */
if (selected_macro != NULL) {
*output_buffer = (char *)realloc(*output_buffer, strlen(*output_buffer) + strlen(selected_macro) + 1);
strcat(*output_buffer, selected_macro);
log_debug_info(DEBUGL_MACROS, 2, " Uncleaned macro. Running output (%lu): '%s'\n", (unsigned long)strlen(*output_buffer), *output_buffer);
}
}
/* free memory if necessary (if we URL encoded the macro or we were told to do so by grab_macro_value()) */
if (free_macro == TRUE)
my_free(selected_macro);
log_debug_info(DEBUGL_MACROS, 2, " Just finished macro. Running output (%lu): '%s'\n", (unsigned long)strlen(*output_buffer), *output_buffer);
}
in_macro = FALSE;
}
}
/* free copy of input buffer */
my_free(save_buffer);
log_debug_info(DEBUGL_MACROS, 1, " Done. Final output: '%s'\n", *output_buffer);
log_debug_info(DEBUGL_MACROS, 1, "**** END MACRO PROCESSING *************\n");
return OK;
}
int process_macros(char *input_buffer, char **output_buffer, int options) {
return process_macros_r(&global_macros, input_buffer, output_buffer, options);
}
/******************************************************************/
/********************** MACRO GRAB FUNCTIONS **********************/
/******************************************************************/
/**
* grab macros that are specific to a particular host
*/
int grab_host_macros_r(icinga_macros *mac, host *hst) {
/* clear host-related macros */
clear_host_macros_r(mac);
clear_hostgroup_macros_r(mac);
/* save pointer to host */
mac->host_ptr = hst;
mac->hostgroup_ptr = NULL;
if (hst == NULL)
return ERROR;
#ifdef NSCORE
/* save pointer to host's first/primary hostgroup */
if (hst->hostgroups_ptr)
mac->hostgroup_ptr = (hostgroup *)hst->hostgroups_ptr->object_ptr;
#endif
return OK;
}
int grab_host_macros(host *hst) {
return grab_host_macros_r(&global_macros, hst);
}
/**
* grab hostgroup macros
*/
int grab_hostgroup_macros_r(icinga_macros *mac, hostgroup *hg) {
/* clear hostgroup macros */
clear_hostgroup_macros_r(mac);
/* save the hostgroup pointer for later */
mac->hostgroup_ptr = hg;
if (hg == NULL)
return ERROR;
return OK;
}
int grab_hostgroup_macros(hostgroup *hg) {
return grab_hostgroup_macros_r(&global_macros, hg);
}
/**
* grab macros that are specific to a particular service
*/
int grab_service_macros_r(icinga_macros *mac, service *svc) {
/* clear service-related macros */
clear_service_macros_r(mac);
clear_servicegroup_macros_r(mac);
/* save pointer for later */
mac->service_ptr = svc;
mac->servicegroup_ptr = NULL;
if (svc == NULL)
return ERROR;
#ifdef NSCORE
/* save first/primary servicegroup pointer for later */
if (svc->servicegroups_ptr)
mac->servicegroup_ptr = (servicegroup *)svc->servicegroups_ptr->object_ptr;
#endif
return OK;
}
int grab_service_macros(service *svc) {
return grab_service_macros_r(&global_macros, svc);
}
/**
* grab macros that are specific to a particular servicegroup
*/
int grab_servicegroup_macros_r(icinga_macros *mac, servicegroup *sg) {
/* clear servicegroup macros */
clear_servicegroup_macros_r(mac);
/* save the pointer for later */
mac->servicegroup_ptr = sg;
if (sg == NULL)
return ERROR;
return OK;
}
int grab_servicegroup_macros(servicegroup *sg) {
return grab_servicegroup_macros_r(&global_macros, sg);
}
/**
* grab macros that are specific to a particular contact
*/
int grab_contact_macros_r(icinga_macros *mac, contact *cntct) {
/* clear contact-related macros */
clear_contact_macros_r(mac);
clear_contactgroup_macros_r(mac);
/* save pointer to contact for later */
mac->contact_ptr = cntct;
mac->contactgroup_ptr = NULL;
if (cntct == NULL)
return ERROR;
#ifdef NSCORE
/* save pointer to first/primary contactgroup for later */
if (cntct->contactgroups_ptr)
mac->contactgroup_ptr = (contactgroup *)cntct->contactgroups_ptr->object_ptr;
#endif
return OK;
}
int grab_contact_macros(contact *cntct) {
return grab_contact_macros_r(&global_macros, cntct);
}
/**
* grab contactgroup macros
*/
int grab_contactgroup_macros_r(icinga_macros *mac, contactgroup *cg) {
/* clear contactgroup macros */
clear_contactgroup_macros_r(mac);
/* save pointer to contactgroup for later */
mac->contactgroup_ptr = cg;
if (cg == NULL)
return ERROR;
return OK;
}
int grab_contactgroup_macros(contactgroup *cg) {
return grab_contactgroup_macros_r(&global_macros, cg);
}
/******************************************************************/
/******************* MACRO GENERATION FUNCTIONS *******************/
/******************************************************************/
/**
* this is the big one
*/
int grab_macro_value_r(icinga_macros *mac, char *macro_buffer, char **output, int *clean_options, int *free_macro) {
char *buf = NULL;
char *ptr = NULL;
char *macro_name = NULL;
char *arg[2] = {NULL, NULL};
contact *temp_contact = NULL;
contactgroup *temp_contactgroup = NULL;
contactsmember *temp_contactsmember = NULL;
char *temp_buffer = NULL;
int delimiter_len = 0;
int x, result = OK;
const struct macro_key_code *mkey;
/* for the early cases, this is the default */
*free_macro = FALSE;
if (output == NULL)
return ERROR;
/* clear the old macro value */
my_free(*output);
if (macro_buffer == NULL || clean_options == NULL || free_macro == NULL)
return ERROR;
/*
* Handle $ARGn$ and $USERn$ macros first, since those are the most
* common accessed ones per check. Since none of them requires to be
* copied from the original buffer, we can return early as well
*/
/***** ARGV MACROS *****/
if (strstr(macro_buffer, "ARG") == macro_buffer) {
/* which arg do we want? */
x = atoi(macro_buffer + 3);
if (x <= 0 || x > MAX_COMMAND_ARGUMENTS) {
return ERROR;
}
/* use a pre-computed macro value */
*output = mac->argv[x-1];
return OK;
}
/***** USER MACROS *****/
if (strstr(macro_buffer, "USER") == macro_buffer) {
/* which macro do we want? */
x = atoi(macro_buffer + 4);
if (x <= 0 || x > MAX_USER_MACROS) {
return ERROR;
}
/* use a pre-computed macro value */
*output = macro_user[x-1];
return OK;
}
/* most frequently used "x" macro gets a shortcut */
if (mac->host_ptr && !strcmp(macro_buffer, "HOSTADDRESS")) {
if (mac->host_ptr->address)
*output = mac->host_ptr->address;
return OK;
}
if (mac->host_ptr && !strcmp(macro_buffer, "HOSTADDRESS6")) {
if (mac->host_ptr->address6)
*output = mac->host_ptr->address6;
return OK;
}
/* work with a copy of the original buffer */
if ((buf = (char *)strdup(macro_buffer)) == NULL)
return ERROR;
/* BY DEFAULT, TELL CALLER TO FREE MACRO BUFFER WHEN DONE */
*free_macro = TRUE;
/* macro name is at start of buffer */
macro_name = buf;
/* see if there's an argument - if so, this is most likely an on-demand macro */
if ((ptr = strchr(buf, ':'))) {
ptr[0] = '\x0';
ptr++;
/* save the first argument - host name, hostgroup name, etc. */
arg[0] = ptr;
/* try and find a second argument */
if ((ptr = strchr(ptr, ':'))) {
ptr[0] = '\x0';
ptr++;
/* save second argument - service description or delimiter */
arg[1] = ptr;
}
}
/***** X MACROS *****/
if ((mkey = find_macro_key(macro_name))) {
log_debug_info(DEBUGL_MACROS, 2, " macros[%d] (%s) match.\n", mkey->code, macro_x_names[mkey->code]);
if (mkey->clean_options) {
*clean_options |= mkey->clean_options;
log_debug_info(DEBUGL_MACROS, 2, " New clean options: %d\n", *clean_options);
}
/* get the macro value */
result = grab_macrox_value_r(mac, mkey->code, arg[0], arg[1], output, free_macro);
}
/***** CONTACT ADDRESS MACROS *****/
/* NOTE: the code below should be broken out into a separate function */
else if (strstr(macro_name, "CONTACTADDRESS") == macro_name) {
/* which address do we want? */
x = atoi(macro_name + 14) - 1;
/* regular macro */
if (arg[0] == NULL) {
/* use the saved pointer */
if ((temp_contact = mac->contact_ptr) == NULL) {
my_free(buf);
return ERROR;
}
/* get the macro value */
result = grab_contact_address_macro_r(mac, x, temp_contact, output);
}
/* on-demand macro */
else {
/* on-demand contact macro with a contactgroup and a delimiter */
if (arg[1] != NULL) {
if ((temp_contactgroup = find_contactgroup(arg[0])) == NULL)
return ERROR;
delimiter_len = strlen(arg[1]);
/* concatenate macro values for all contactgroup members */
for (temp_contactsmember = temp_contactgroup->members; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) {
#ifdef NSCORE
if ((temp_contact = temp_contactsmember->contact_ptr) == NULL)
continue;
if ((temp_contact = find_contact(temp_contactsmember->contact_name)) == NULL)
continue;
#endif
/* get the macro value for this contact */
grab_contact_address_macro_r(mac, x, temp_contact, &temp_buffer);
if (temp_buffer == NULL)
continue;
/* add macro value to already running macro */
if (*output == NULL)
*output = (char *)strdup(temp_buffer);
else {
if ((*output = (char *)realloc(*output, strlen(*output) + strlen(temp_buffer) + delimiter_len + 1)) == NULL)
continue;
strcat(*output, arg[1]);
strcat(*output, temp_buffer);
}
my_free(temp_buffer);
}
}
/* else on-demand contact macro */
else {
/* find the contact */
if ((temp_contact = find_contact(arg[0])) == NULL) {
my_free(buf);
return ERROR;
}
/* get the macro value */
result = grab_contact_address_macro_r(mac, x, temp_contact, output);
}
}
}
/***** CUSTOM VARIABLE MACROS *****/
else if (macro_name[0] == '_') {
/* get the macro value */
result = grab_custom_macro_value_r(mac, macro_name, arg[0], arg[1], output);
}
/* no macro matched... */
else {
log_debug_info(DEBUGL_MACROS, 0, " WARNING: Could not find a macro matching '%s'!\n", macro_name);
result = ERROR;
}
/* free memory */
my_free(buf);
return result;
}
int grab_macro_value(char *macro_buffer, char **output, int *clean_options, int *free_macro) {
return grab_macro_value_r(&global_macros, macro_buffer, output, clean_options, free_macro);
}
/**
* grab macrox value
*/
int grab_macrox_value_r(icinga_macros *mac, int macro_type, char *arg1, char *arg2, char **output, int *free_macro) {
host *temp_host = NULL;
hostgroup *temp_hostgroup = NULL;
hostsmember *temp_hostsmember = NULL;
service *temp_service = NULL;
servicegroup *temp_servicegroup = NULL;
servicesmember *temp_servicesmember = NULL;
contact *temp_contact = NULL;
contactgroup *temp_contactgroup = NULL;
contactsmember *temp_contactsmember = NULL;
char *temp_buffer = NULL;
int result = OK;
int delimiter_len = 0;
int free_sub_macro = FALSE;
#ifdef NSCORE
register int x;
int authorized = TRUE;
int problem = TRUE;
int hosts_up = 0;
int hosts_down = 0;
int hosts_unreachable = 0;
int hosts_down_unhandled = 0;
int hosts_unreachable_unhandled = 0;
int host_problems = 0;
int host_problems_unhandled = 0;
int services_ok = 0;
int services_warning = 0;
int services_unknown = 0;
int services_critical = 0;
int services_warning_unhandled = 0;
int services_unknown_unhandled = 0;
int services_critical_unhandled = 0;
int service_problems = 0;
int service_problems_unhandled = 0;
#endif
if (output == NULL || free_macro == NULL)
return ERROR;
/* BY DEFAULT, TELL CALLER TO FREE MACRO BUFFER WHEN DONE */
*free_macro = TRUE;
/* handle the macro */
switch (macro_type) {
/***************/
/* HOST MACROS */
/***************/
case MACRO_HOSTNAME:
case MACRO_HOSTALIAS:
case MACRO_HOSTADDRESS:
case MACRO_HOSTADDRESS6:
case MACRO_LASTHOSTCHECK:
case MACRO_LASTHOSTSTATECHANGE:
case MACRO_HOSTOUTPUT:
case MACRO_HOSTPERFDATA:
case MACRO_HOSTSTATE:
case MACRO_HOSTSTATEID:
case MACRO_HOSTATTEMPT:
case MACRO_HOSTEXECUTIONTIME:
case MACRO_HOSTLATENCY:
case MACRO_HOSTDURATION:
case MACRO_HOSTDURATIONSEC:
case MACRO_HOSTDOWNTIME:
case MACRO_HOSTSTATETYPE:
case MACRO_HOSTPERCENTCHANGE:
case MACRO_HOSTACKAUTHOR:
case MACRO_HOSTACKCOMMENT:
case MACRO_LASTHOSTUP:
case MACRO_LASTHOSTDOWN:
case MACRO_LASTHOSTUNREACHABLE:
case MACRO_HOSTCHECKCOMMAND:
case MACRO_HOSTDISPLAYNAME:
case MACRO_HOSTACTIONURL:
case MACRO_HOSTNOTESURL:
case MACRO_HOSTNOTES:
case MACRO_HOSTCHECKTYPE:
case MACRO_LONGHOSTOUTPUT:
case MACRO_HOSTNOTIFICATIONNUMBER:
case MACRO_HOSTNOTIFICATIONID:
case MACRO_HOSTEVENTID:
case MACRO_LASTHOSTEVENTID:
case MACRO_HOSTGROUPNAMES:
case MACRO_HOSTACKAUTHORNAME:
case MACRO_HOSTACKAUTHORALIAS:
case MACRO_MAXHOSTATTEMPTS:
case MACRO_TOTALHOSTSERVICES:
case MACRO_TOTALHOSTSERVICESOK:
case MACRO_TOTALHOSTSERVICESWARNING:
case MACRO_TOTALHOSTSERVICESUNKNOWN:
case MACRO_TOTALHOSTSERVICESCRITICAL:
case MACRO_HOSTPROBLEMID:
case MACRO_LASTHOSTPROBLEMID:
case MACRO_LASTHOSTSTATE:
case MACRO_LASTHOSTSTATEID:
/* a standard host macro */
if (arg2 == NULL) {
/* find the host for on-demand macros */
if (arg1) {
if ((temp_host = find_host(arg1)) == NULL)
return ERROR;
}
/* else use saved host pointer */
else if ((temp_host = mac->host_ptr) == NULL)
return ERROR;
/* get the host macro value */
result = grab_standard_host_macro_r(mac, macro_type, temp_host, output, free_macro);
}
/* a host macro with a hostgroup name and delimiter */
else {
if ((temp_hostgroup = find_hostgroup(arg1)) == NULL)
return ERROR;
delimiter_len = strlen(arg2);
/* concatenate macro values for all hostgroup members */
for (temp_hostsmember = temp_hostgroup->members; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
#ifdef NSCORE
if ((temp_host = temp_hostsmember->host_ptr) == NULL)
continue;
#else
if ((temp_host = find_host(temp_hostsmember->host_name)) == NULL)
continue;
#endif
/* get the macro value for this host */
grab_standard_host_macro_r(mac, macro_type, temp_host, &temp_buffer, &free_sub_macro);
if (temp_buffer == NULL)
continue;
/* add macro value to already running macro */
if (*output == NULL)
*output = (char *)strdup(temp_buffer);
else {
if ((*output = (char *)realloc(*output, strlen(*output) + strlen(temp_buffer) + delimiter_len + 1)) == NULL)
continue;
strcat(*output, arg2);
strcat(*output, temp_buffer);
}
if (free_sub_macro == TRUE)
my_free(temp_buffer);
}
}
break;
/********************/
/* HOSTGROUP MACROS */
/********************/
case MACRO_HOSTGROUPNAME:
case MACRO_HOSTGROUPALIAS:
case MACRO_HOSTGROUPNOTES:
case MACRO_HOSTGROUPNOTESURL:
case MACRO_HOSTGROUPACTIONURL:
case MACRO_HOSTGROUPMEMBERS:
/* a standard hostgroup macro */
/* use the saved hostgroup pointer */
if (arg1 == NULL) {
if ((temp_hostgroup = mac->hostgroup_ptr) == NULL)
return ERROR;
}
/* else find the hostgroup for on-demand macros */
else {
if ((temp_hostgroup = find_hostgroup(arg1)) == NULL)
return ERROR;
}
/* get the hostgroup macro value */
result = grab_standard_hostgroup_macro_r(mac, macro_type, temp_hostgroup, output);
break;
/******************/
/* SERVICE MACROS */
/******************/
case MACRO_SERVICEDESC:
case MACRO_SERVICESTATE:
case MACRO_SERVICESTATEID:
case MACRO_SERVICEATTEMPT:
case MACRO_LASTSERVICECHECK:
case MACRO_LASTSERVICESTATECHANGE:
case MACRO_SERVICEOUTPUT:
case MACRO_SERVICEPERFDATA:
case MACRO_SERVICEEXECUTIONTIME:
case MACRO_SERVICELATENCY:
case MACRO_SERVICEDURATION:
case MACRO_SERVICEDURATIONSEC:
case MACRO_SERVICEDOWNTIME:
case MACRO_SERVICESTATETYPE:
case MACRO_SERVICEPERCENTCHANGE:
case MACRO_SERVICEACKAUTHOR:
case MACRO_SERVICEACKCOMMENT:
case MACRO_LASTSERVICEOK:
case MACRO_LASTSERVICEWARNING:
case MACRO_LASTSERVICEUNKNOWN:
case MACRO_LASTSERVICECRITICAL:
case MACRO_SERVICECHECKCOMMAND:
case MACRO_SERVICEDISPLAYNAME:
case MACRO_SERVICEACTIONURL:
case MACRO_SERVICENOTESURL:
case MACRO_SERVICENOTES:
case MACRO_SERVICECHECKTYPE:
case MACRO_LONGSERVICEOUTPUT:
case MACRO_SERVICENOTIFICATIONNUMBER:
case MACRO_SERVICENOTIFICATIONID:
case MACRO_SERVICEEVENTID:
case MACRO_LASTSERVICEEVENTID:
case MACRO_SERVICEGROUPNAMES:
case MACRO_SERVICEACKAUTHORNAME:
case MACRO_SERVICEACKAUTHORALIAS:
case MACRO_MAXSERVICEATTEMPTS:
case MACRO_SERVICEISVOLATILE:
case MACRO_SERVICEPROBLEMID:
case MACRO_LASTSERVICEPROBLEMID:
case MACRO_LASTSERVICESTATE:
case MACRO_LASTSERVICESTATEID:
/* use saved service pointer */
if (arg1 == NULL && arg2 == NULL) {
if ((temp_service = mac->service_ptr) == NULL)
return ERROR;
result = grab_standard_service_macro_r(mac, macro_type, temp_service, output, free_macro);
}
/* else and ondemand macro... */
else {
/* if first arg is blank, it means use the current host name */
if (arg1 == NULL || arg1[0] == '\x0') {
if (mac->host_ptr == NULL)
return ERROR;
if ((temp_service = find_service(mac->host_ptr->name, arg2))) {
/* get the service macro value */
result = grab_standard_service_macro_r(mac, macro_type, temp_service, output, free_macro);
}
}
/* on-demand macro with both host and service name */
else if ((temp_service = find_service(arg1, arg2))) {
/* get the service macro value */
result = grab_standard_service_macro_r(mac, macro_type, temp_service, output, free_macro);
}
/* else we have a service macro with a servicegroup name and a delimiter... */
else if (arg1 && arg2) {
if ((temp_servicegroup = find_servicegroup(arg1)) == NULL)
return ERROR;
delimiter_len = strlen(arg2);
/* concatenate macro values for all servicegroup members */
for (temp_servicesmember = temp_servicegroup->members; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) {
#ifdef NSCORE
if ((temp_service = temp_servicesmember->service_ptr) == NULL)
continue;
#else
if ((temp_service = find_service(temp_servicesmember->host_name, temp_servicesmember->service_description)) == NULL)
continue;
#endif
/* get the macro value for this service */
grab_standard_service_macro_r(mac, macro_type, temp_service, &temp_buffer, &free_sub_macro);
if (temp_buffer == NULL)
continue;
/* add macro value to already running macro */
if (*output == NULL)
*output = (char *)strdup(temp_buffer);
else {
if ((*output = (char *)realloc(*output, strlen(*output) + strlen(temp_buffer) + delimiter_len + 1)) == NULL)
continue;
strcat(*output, arg2);
strcat(*output, temp_buffer);
}
if (free_sub_macro == TRUE)
my_free(temp_buffer);
}
} else
return ERROR;
}
break;
/***********************/
/* SERVICEGROUP MACROS */
/***********************/
case MACRO_SERVICEGROUPNAME:
case MACRO_SERVICEGROUPALIAS:
case MACRO_SERVICEGROUPNOTES:
case MACRO_SERVICEGROUPNOTESURL:
case MACRO_SERVICEGROUPACTIONURL:
case MACRO_SERVICEGROUPMEMBERS:
/* a standard servicegroup macro */
/* use the saved servicegroup pointer */
if (arg1 == NULL) {
if ((temp_servicegroup = mac->servicegroup_ptr) == NULL)
return ERROR;
}
/* else find the servicegroup for on-demand macros */
else {
if ((temp_servicegroup = find_servicegroup(arg1)) == NULL)
return ERROR;
}
/* get the servicegroup macro value */
result = grab_standard_servicegroup_macro_r(mac, macro_type, temp_servicegroup, output);
break;
/******************/
/* CONTACT MACROS */
/******************/
case MACRO_CONTACTNAME:
case MACRO_CONTACTALIAS:
case MACRO_CONTACTEMAIL:
case MACRO_CONTACTPAGER:
case MACRO_CONTACTGROUPNAMES:
/* a standard contact macro */
if (arg2 == NULL) {
/* find the contact for on-demand macros */
if (arg1) {
if ((temp_contact = find_contact(arg1)) == NULL)
return ERROR;
}
/* else use saved contact pointer */
else if ((temp_contact = mac->contact_ptr) == NULL)
return ERROR;
/* get the contact macro value */
result = grab_standard_contact_macro_r(mac, macro_type, temp_contact, output);
}
/* a contact macro with a contactgroup name and delimiter */
else {
if ((temp_contactgroup = find_contactgroup(arg1)) == NULL)
return ERROR;
delimiter_len = strlen(arg2);
/* concatenate macro values for all contactgroup members */
for (temp_contactsmember = temp_contactgroup->members; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) {
#ifdef NSCORE
if ((temp_contact = temp_contactsmember->contact_ptr) == NULL)
continue;
#else
if ((temp_contact = find_contact(temp_contactsmember->contact_name)) == NULL)
continue;
#endif
/* get the macro value for this contact */
grab_standard_contact_macro_r(mac, macro_type, temp_contact, &temp_buffer);
if (temp_buffer == NULL)
continue;
/* add macro value to already running macro */
if (*output == NULL)
*output = (char *)strdup(temp_buffer);
else {
if ((*output = (char *)realloc(*output, strlen(*output) + strlen(temp_buffer) + delimiter_len + 1)) == NULL)
continue;
strcat(*output, arg2);
strcat(*output, temp_buffer);
}
my_free(temp_buffer);
}
}
break;
/***********************/
/* CONTACTGROUP MACROS */
/***********************/
case MACRO_CONTACTGROUPNAME:
case MACRO_CONTACTGROUPALIAS:
case MACRO_CONTACTGROUPMEMBERS:
/* a standard contactgroup macro */
/* use the saved contactgroup pointer */
if (arg1 == NULL) {
if ((temp_contactgroup = mac->contactgroup_ptr) == NULL)
return ERROR;
}
/* else find the contactgroup for on-demand macros */
else {
if ((temp_contactgroup = find_contactgroup(arg1)) == NULL)
return ERROR;
}
/* get the contactgroup macro value */
result = grab_standard_contactgroup_macro_r(mac, macro_type, temp_contactgroup, output);
break;
/***********************/
/* NOTIFICATION MACROS */
/***********************/
case MACRO_NOTIFICATIONTYPE:
case MACRO_NOTIFICATIONNUMBER:
case MACRO_NOTIFICATIONRECIPIENTS:
case MACRO_NOTIFICATIONISESCALATED:
case MACRO_NOTIFICATIONAUTHOR:
case MACRO_NOTIFICATIONAUTHORNAME:
case MACRO_NOTIFICATIONAUTHORALIAS:
case MACRO_NOTIFICATIONCOMMENT:
/* notification macros have already been pre-computed */
*output = mac->x[macro_type];
*free_macro = FALSE;
break;
/********************/
/* DATE/TIME MACROS */
/********************/
case MACRO_LONGDATETIME:
case MACRO_SHORTDATETIME:
case MACRO_DATE:
case MACRO_TIME:
case MACRO_TIMET:
case MACRO_ISVALIDTIME:
case MACRO_NEXTVALIDTIME:
/* calculate macros */
result = grab_datetime_macro_r(mac, macro_type, arg1, arg2, output);
break;
/*****************/
/* STATIC MACROS */
/*****************/
case MACRO_ADMINEMAIL:
case MACRO_ADMINPAGER:
case MACRO_MAINCONFIGFILE:
case MACRO_STATUSDATAFILE:
case MACRO_RETENTIONDATAFILE:
case MACRO_OBJECTCACHEFILE:
case MACRO_TEMPFILE:
case MACRO_LOGFILE:
case MACRO_RESOURCEFILE:
case MACRO_COMMANDFILE:
case MACRO_HOSTPERFDATAFILE:
case MACRO_SERVICEPERFDATAFILE:
case MACRO_PROCESSSTARTTIME:
case MACRO_TEMPPATH:
case MACRO_EVENTSTARTTIME:
/* no need to do any more work - these are already precomputed for us */
*output = global_macros.x[macro_type];
*free_macro = FALSE;
break;
/******************/
/* SUMMARY MACROS */
/******************/
case MACRO_TOTALHOSTSUP:
case MACRO_TOTALHOSTSDOWN:
case MACRO_TOTALHOSTSUNREACHABLE:
case MACRO_TOTALHOSTSDOWNUNHANDLED:
case MACRO_TOTALHOSTSUNREACHABLEUNHANDLED:
case MACRO_TOTALHOSTPROBLEMS:
case MACRO_TOTALHOSTPROBLEMSUNHANDLED:
case MACRO_TOTALSERVICESOK:
case MACRO_TOTALSERVICESWARNING:
case MACRO_TOTALSERVICESCRITICAL:
case MACRO_TOTALSERVICESUNKNOWN:
case MACRO_TOTALSERVICESWARNINGUNHANDLED:
case MACRO_TOTALSERVICESCRITICALUNHANDLED:
case MACRO_TOTALSERVICESUNKNOWNUNHANDLED:
case MACRO_TOTALSERVICEPROBLEMS:
case MACRO_TOTALSERVICEPROBLEMSUNHANDLED:
#ifdef NSCORE
/* generate summary macros if needed */
if (mac->x[MACRO_TOTALHOSTSUP] == NULL) {
/* get host totals */
for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
/* filter totals based on contact if necessary */
if (mac->contact_ptr != NULL)
authorized = is_contact_for_host(temp_host, mac->contact_ptr);
if (authorized == TRUE) {
problem = TRUE;
if (temp_host->current_state == HOST_UP && temp_host->has_been_checked == TRUE)
hosts_up++;
else if (temp_host->current_state == HOST_DOWN) {
if (temp_host->scheduled_downtime_depth > 0)
problem = FALSE;
if (temp_host->problem_has_been_acknowledged == TRUE)
problem = FALSE;
if (temp_host->checks_enabled == FALSE)
problem = FALSE;
if (problem == TRUE)
hosts_down_unhandled++;
hosts_down++;
} else if (temp_host->current_state == HOST_UNREACHABLE) {
if (temp_host->scheduled_downtime_depth > 0)
problem = FALSE;
if (temp_host->problem_has_been_acknowledged == TRUE)
problem = FALSE;
if (temp_host->checks_enabled == FALSE)
problem = FALSE;
if (problem == TRUE)
hosts_down_unhandled++;
hosts_unreachable++;
}
}
}
host_problems = hosts_down + hosts_unreachable;
host_problems_unhandled = hosts_down_unhandled + hosts_unreachable_unhandled;
/* get service totals */
for (temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) {
/* filter totals based on contact if necessary */
if (mac->contact_ptr != NULL)
authorized = is_contact_for_service(temp_service, mac->contact_ptr);
if (authorized == TRUE) {
problem = TRUE;
if (temp_service->current_state == STATE_OK && temp_service->has_been_checked == TRUE)
services_ok++;
else if (temp_service->current_state == STATE_WARNING) {
temp_host = find_host(temp_service->host_name);
if (temp_host != NULL && (temp_host->current_state == HOST_DOWN || temp_host->current_state == HOST_UNREACHABLE))
problem = FALSE;
if (temp_service->scheduled_downtime_depth > 0)
problem = FALSE;
if (temp_service->problem_has_been_acknowledged == TRUE)
problem = FALSE;
if (temp_service->checks_enabled == FALSE)
problem = FALSE;
if (problem == TRUE)
services_warning_unhandled++;
services_warning++;
} else if (temp_service->current_state == STATE_UNKNOWN) {
temp_host = find_host(temp_service->host_name);
if (temp_host != NULL && (temp_host->current_state == HOST_DOWN || temp_host->current_state == HOST_UNREACHABLE))
problem = FALSE;
if (temp_service->scheduled_downtime_depth > 0)
problem = FALSE;
if (temp_service->problem_has_been_acknowledged == TRUE)
problem = FALSE;
if (temp_service->checks_enabled == FALSE)
problem = FALSE;
if (problem == TRUE)
services_unknown_unhandled++;
services_unknown++;
} else if (temp_service->current_state == STATE_CRITICAL) {
temp_host = find_host(temp_service->host_name);
if (temp_host != NULL && (temp_host->current_state == HOST_DOWN || temp_host->current_state == HOST_UNREACHABLE))
problem = FALSE;
if (temp_service->scheduled_downtime_depth > 0)
problem = FALSE;
if (temp_service->problem_has_been_acknowledged == TRUE)
problem = FALSE;
if (temp_service->checks_enabled == FALSE)
problem = FALSE;
if (problem == TRUE)
services_critical_unhandled++;
services_critical++;
}
}
}
service_problems = services_warning + services_critical + services_unknown;
service_problems_unhandled = services_warning_unhandled + services_critical_unhandled + services_unknown_unhandled;
/* these macros are time-intensive to compute, and will likely be used together, so save them all for future use */
for (x = MACRO_TOTALHOSTSUP; x <= MACRO_TOTALSERVICEPROBLEMSUNHANDLED; x++)
my_free(mac->x[x]);
asprintf(&mac->x[MACRO_TOTALHOSTSUP], "%d", hosts_up);
asprintf(&mac->x[MACRO_TOTALHOSTSDOWN], "%d", hosts_down);
asprintf(&mac->x[MACRO_TOTALHOSTSUNREACHABLE], "%d", hosts_unreachable);
asprintf(&mac->x[MACRO_TOTALHOSTSDOWNUNHANDLED], "%d", hosts_down_unhandled);
asprintf(&mac->x[MACRO_TOTALHOSTSUNREACHABLEUNHANDLED], "%d", hosts_unreachable_unhandled);
asprintf(&mac->x[MACRO_TOTALHOSTPROBLEMS], "%d", host_problems);
asprintf(&mac->x[MACRO_TOTALHOSTPROBLEMSUNHANDLED], "%d", host_problems_unhandled);
asprintf(&mac->x[MACRO_TOTALSERVICESOK], "%d", services_ok);
asprintf(&mac->x[MACRO_TOTALSERVICESWARNING], "%d", services_warning);
asprintf(&mac->x[MACRO_TOTALSERVICESCRITICAL], "%d", services_critical);
asprintf(&mac->x[MACRO_TOTALSERVICESUNKNOWN], "%d", services_unknown);
asprintf(&mac->x[MACRO_TOTALSERVICESWARNINGUNHANDLED], "%d", services_warning_unhandled);
asprintf(&mac->x[MACRO_TOTALSERVICESCRITICALUNHANDLED], "%d", services_critical_unhandled);
asprintf(&mac->x[MACRO_TOTALSERVICESUNKNOWNUNHANDLED], "%d", services_unknown_unhandled);
asprintf(&mac->x[MACRO_TOTALSERVICEPROBLEMS], "%d", service_problems);
asprintf(&mac->x[MACRO_TOTALSERVICEPROBLEMSUNHANDLED], "%d", service_problems_unhandled);
}
/* return only the macro the user requested */
*output = mac->x[macro_type];
/* tell caller to NOT free memory when done */
*free_macro = FALSE;
#endif
break;
default:
log_debug_info(DEBUGL_MACROS, 0, "UNHANDLED MACRO #%d! THIS IS A BUG!\n", macro_type);
return ERROR;
}
return result;
}
int grab_macrox_value(int macro_type, char *arg1, char *arg2, char **output, int *free_macro) {
return grab_macrox_value_r(&global_macros, macro_type, arg1, arg2, output, free_macro);
}
/**
* calculates the value of a custom macro
*/
int grab_custom_macro_value_r(icinga_macros *mac, char *macro_name, char *arg1, char *arg2, char **output) {
host *temp_host = NULL;
hostgroup *temp_hostgroup = NULL;
hostsmember *temp_hostsmember = NULL;
service *temp_service = NULL;
servicegroup *temp_servicegroup = NULL;
servicesmember *temp_servicesmember = NULL;
contact *temp_contact = NULL;
contactgroup *temp_contactgroup = NULL;
contactsmember *temp_contactsmember = NULL;
int delimiter_len = 0;
char *temp_buffer = NULL;
int result = OK;
if (macro_name == NULL || output == NULL)
return ERROR;
/***** CUSTOM HOST MACRO *****/
if (strstr(macro_name, "_HOST") == macro_name) {
/* a standard host macro */
if (arg2 == NULL) {
/* find the host for on-demand macros */
if (arg1) {
if ((temp_host = find_host(arg1)) == NULL)
return ERROR;
}
/* else use saved host pointer */
else if ((temp_host = mac->host_ptr) == NULL)
return ERROR;
/* get the host macro value */
result = grab_custom_object_macro_r(mac, macro_name + 5, temp_host->custom_variables, output);
}
/* a host macro with a hostgroup name and delimiter */
else {
if ((temp_hostgroup = find_hostgroup(arg1)) == NULL)
return ERROR;
delimiter_len = strlen(arg2);
/* concatenate macro values for all hostgroup members */
for (temp_hostsmember = temp_hostgroup->members; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
#ifdef NSCORE
if ((temp_host = temp_hostsmember->host_ptr) == NULL)
continue;
#else
if ((temp_host = find_host(temp_hostsmember->host_name)) == NULL)
continue;
#endif
/* get the macro value for this host */
grab_custom_macro_value_r(mac, macro_name, temp_host->name, NULL, &temp_buffer);
if (temp_buffer == NULL)
continue;
/* add macro value to already running macro */
if (*output == NULL)
*output = (char *)strdup(temp_buffer);
else {
if ((*output = (char *)realloc(*output, strlen(*output) + strlen(temp_buffer) + delimiter_len + 1)) == NULL)
continue;
strcat(*output, arg2);
strcat(*output, temp_buffer);
}
my_free(temp_buffer);
}
}
}
/***** CUSTOM SERVICE MACRO *****/
else if (strstr(macro_name, "_SERVICE") == macro_name) {
/* use saved service pointer */
if (arg1 == NULL && arg2 == NULL) {
if ((temp_service = mac->service_ptr) == NULL)
return ERROR;
/* get the service macro value */
result = grab_custom_object_macro_r(mac, macro_name + 8, temp_service->custom_variables, output);
}
/* else and ondemand macro... */
else {
/* if first arg is blank, it means use the current host name */
if (mac->host_ptr == NULL)
return ERROR;
if ((temp_service = find_service((mac->host_ptr) ? mac->host_ptr->name : NULL, arg2))) {
/* get the service macro value */
result = grab_custom_object_macro_r(mac, macro_name + 8, temp_service->custom_variables, output);
}
/* else we have a service macro with a servicegroup name and a delimiter... */
else {
if ((temp_servicegroup = find_servicegroup(arg1)) == NULL)
return ERROR;
delimiter_len = strlen(arg2);
/* concatenate macro values for all servicegroup members */
for (temp_servicesmember = temp_servicegroup->members; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) {
#ifdef NSCORE
if ((temp_service = temp_servicesmember->service_ptr) == NULL)
continue;
#else
if ((temp_service = find_service(temp_servicesmember->host_name, temp_servicesmember->service_description)) == NULL)
continue;
#endif
/* get the macro value for this service */
grab_custom_macro_value_r(mac, macro_name, temp_service->host_name, temp_service->description, &temp_buffer);
if (temp_buffer == NULL)
continue;
/* add macro value to already running macro */
if (*output == NULL)
*output = (char *)strdup(temp_buffer);
else {
if ((*output = (char *)realloc(*output, strlen(*output) + strlen(temp_buffer) + delimiter_len + 1)) == NULL)
continue;
strcat(*output, arg2);
strcat(*output, temp_buffer);
}
my_free(temp_buffer);
}
}
}
}
/***** CUSTOM CONTACT VARIABLE *****/
else if (strstr(macro_name, "_CONTACT") == macro_name) {
/* a standard contact macro */
if (arg2 == NULL) {
/* find the contact for on-demand macros */
if (arg1) {
if ((temp_contact = find_contact(arg1)) == NULL)
return ERROR;
}
/* else use saved contact pointer */
else if ((temp_contact = mac->contact_ptr) == NULL)
return ERROR;
/* get the contact macro value */
result = grab_custom_object_macro_r(mac, macro_name + 8, temp_contact->custom_variables, output);
}
/* a contact macro with a contactgroup name and delimiter */
else {
if ((temp_contactgroup = find_contactgroup(arg1)) == NULL)
return ERROR;
delimiter_len = strlen(arg2);
/* concatenate macro values for all contactgroup members */
for (temp_contactsmember = temp_contactgroup->members; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) {
#ifdef NSCORE
if ((temp_contact = temp_contactsmember->contact_ptr) == NULL)
continue;
#else
if ((temp_contact = find_contact(temp_contactsmember->contact_name)) == NULL)
continue;
#endif
/* get the macro value for this contact */
grab_custom_macro_value_r(mac, macro_name, temp_contact->name, NULL, &temp_buffer);
if (temp_buffer == NULL)
continue;
/* add macro value to already running macro */
if (*output == NULL)
*output = (char *)strdup(temp_buffer);
else {
if ((*output = (char *)realloc(*output, strlen(*output) + strlen(temp_buffer) + delimiter_len + 1)) == NULL)
continue;
strcat(*output, arg2);
strcat(*output, temp_buffer);
}
my_free(temp_buffer);
}
}
}
else
return ERROR;
return result;
}
int grab_custom_macro_value(char *macro_name, char *arg1, char *arg2, char **output) {
return grab_custom_macro_value_r(&global_macros, macro_name, arg1, arg2, output);
}
/**
* calculates a date/time macro
*/
int grab_datetime_macro_r(icinga_macros *mac, int macro_type, char *arg1, char *arg2, char **output) {
time_t current_time = 0L;
#ifdef NSCORE
timeperiod *temp_timeperiod = NULL;
time_t test_time = 0L;
time_t next_valid_time = 0L;
#endif
if (output == NULL)
return ERROR;
/* get the current time */
time(¤t_time);
#ifdef NSCORE
/* parse args, do prep work */
switch (macro_type) {
case MACRO_ISVALIDTIME:
case MACRO_NEXTVALIDTIME:
/* find the timeperiod */
if ((temp_timeperiod = find_timeperiod(arg1)) == NULL)
return ERROR;
/* what timestamp should we use? */
if (arg2)
test_time = (time_t)strtoul(arg2, NULL, 0);
else
test_time = current_time;
break;
default:
break;
}
#endif
/* calculate the value */
switch (macro_type) {
case MACRO_LONGDATETIME:
if (*output == NULL)
*output = (char *)malloc(MAX_DATETIME_LENGTH);
if (*output)
get_datetime_string(¤t_time, *output, MAX_DATETIME_LENGTH, LONG_DATE_TIME);
break;
case MACRO_SHORTDATETIME:
if (*output == NULL)
*output = (char *)malloc(MAX_DATETIME_LENGTH);
if (*output)
get_datetime_string(¤t_time, *output, MAX_DATETIME_LENGTH, SHORT_DATE_TIME);
break;
case MACRO_DATE:
if (*output == NULL)
*output = (char *)malloc(MAX_DATETIME_LENGTH);
if (*output)
get_datetime_string(¤t_time, *output, MAX_DATETIME_LENGTH, SHORT_DATE);
break;
case MACRO_TIME:
if (*output == NULL)
*output = (char *)malloc(MAX_DATETIME_LENGTH);
if (*output)
get_datetime_string(¤t_time, *output, MAX_DATETIME_LENGTH, SHORT_TIME);
break;
case MACRO_TIMET:
asprintf(output, "%lu", (unsigned long)current_time);
break;
#ifdef NSCORE
case MACRO_ISVALIDTIME:
asprintf(output, "%d", (check_time_against_period(test_time, temp_timeperiod) == OK) ? 1 : 0);
break;
case MACRO_NEXTVALIDTIME:
get_next_valid_time(test_time, &next_valid_time, temp_timeperiod);
if (next_valid_time == test_time && check_time_against_period(test_time, temp_timeperiod) == ERROR)
next_valid_time = (time_t)0L;
asprintf(output, "%lu", (unsigned long)next_valid_time);
break;
#endif
default:
return ERROR;
break;
}
return OK;
}
int grab_datetime_macro(int macro_type, char *arg1, char *arg2, char **output) {
return grab_datetime_macro_r(&global_macros, macro_type, arg1, arg2, output);
}
/**
* calculates a host macro
*/
int grab_standard_host_macro_r(icinga_macros *mac, int macro_type, host *temp_host, char **output, int *free_macro) {
char *temp_buffer = NULL;
#ifdef NSCORE
hostgroup *temp_hostgroup = NULL;
servicesmember *temp_servicesmember = NULL;
service *temp_service = NULL;
objectlist *temp_objectlist = NULL;
time_t current_time = 0L;
unsigned long duration = 0L;
int days = 0;
int hours = 0;
int minutes = 0;
int seconds = 0;
char *buf1 = NULL;
char *buf2 = NULL;
int total_host_services = 0;
int total_host_services_ok = 0;
int total_host_services_warning = 0;
int total_host_services_unknown = 0;
int total_host_services_critical = 0;
#endif
if (temp_host == NULL || output == NULL || free_macro == NULL)
return ERROR;
/* BY DEFAULT TELL CALLER TO FREE MACRO BUFFER WHEN DONE */
*free_macro = TRUE;
/* get the macro */
switch (macro_type) {
case MACRO_HOSTNAME:
*output = (char *)strdup(temp_host->name);
break;
case MACRO_HOSTDISPLAYNAME:
if (temp_host->display_name)
*output = (char *)strdup(temp_host->display_name);
break;
case MACRO_HOSTALIAS:
*output = (char *)strdup(temp_host->alias);
break;
case MACRO_HOSTADDRESS:
*output = (char *)strdup(temp_host->address);
break;
case MACRO_HOSTADDRESS6:
*output = (char *)strdup(temp_host->address6);
break;
#ifdef NSCORE
case MACRO_HOSTSTATE:
if (temp_host->current_state == HOST_DOWN)
*output = (char *)strdup("DOWN");
else if (temp_host->current_state == HOST_UNREACHABLE)
*output = (char *)strdup("UNREACHABLE");
else
*output = (char *)strdup("UP");
break;
case MACRO_HOSTSTATEID:
asprintf(output, "%d", temp_host->current_state);
break;
case MACRO_LASTHOSTSTATE:
if (temp_host->last_state == HOST_DOWN)
*output = (char *)strdup("DOWN");
else if (temp_host->last_state == HOST_UNREACHABLE)
*output = (char *)strdup("UNREACHABLE");
else
*output = (char *)strdup("UP");
break;
case MACRO_LASTHOSTSTATEID:
asprintf(output, "%d", temp_host->last_state);
break;
case MACRO_HOSTCHECKTYPE:
asprintf(output, "%s", (temp_host->check_type == HOST_CHECK_PASSIVE) ? "PASSIVE" : "ACTIVE");
break;
case MACRO_HOSTSTATETYPE:
asprintf(output, "%s", (temp_host->state_type == HARD_STATE) ? "HARD" : "SOFT");
break;
case MACRO_HOSTOUTPUT:
if (temp_host->plugin_output)
*output = (char *)strdup(temp_host->plugin_output);
break;
case MACRO_LONGHOSTOUTPUT:
if (temp_host->long_plugin_output)
*output = (char *)strdup(temp_host->long_plugin_output);
break;
case MACRO_HOSTPERFDATA:
if (temp_host->perf_data)
*output = (char *)strdup(temp_host->perf_data);
break;
#endif
case MACRO_HOSTCHECKCOMMAND:
if (temp_host->host_check_command)
*output = (char *)strdup(temp_host->host_check_command);
break;
#ifdef NSCORE
case MACRO_HOSTATTEMPT:
asprintf(output, "%d", temp_host->current_attempt);
break;
case MACRO_MAXHOSTATTEMPTS:
asprintf(output, "%d", temp_host->max_attempts);
break;
case MACRO_HOSTDOWNTIME:
asprintf(output, "%d", temp_host->scheduled_downtime_depth);
break;
case MACRO_HOSTPERCENTCHANGE:
asprintf(output, "%.2f", temp_host->percent_state_change);
break;
case MACRO_HOSTDURATIONSEC:
case MACRO_HOSTDURATION:
time(¤t_time);
duration = (unsigned long)(current_time - temp_host->last_state_change);
if (macro_type == MACRO_HOSTDURATIONSEC)
asprintf(output, "%lu", duration);
else {
days = duration / 86400;
duration -= (days * 86400);
hours = duration / 3600;
duration -= (hours * 3600);
minutes = duration / 60;
duration -= (minutes * 60);
seconds = duration;
asprintf(output, "%dd %dh %dm %ds", days, hours, minutes, seconds);
}
break;
case MACRO_HOSTEXECUTIONTIME:
asprintf(output, "%.3f", temp_host->execution_time);
break;
case MACRO_HOSTLATENCY:
asprintf(output, "%.3f", temp_host->latency);
break;
case MACRO_LASTHOSTCHECK:
asprintf(output, "%lu", (unsigned long)temp_host->last_check);
break;
case MACRO_LASTHOSTSTATECHANGE:
asprintf(output, "%lu", (unsigned long)temp_host->last_state_change);
break;
case MACRO_LASTHOSTUP:
asprintf(output, "%lu", (unsigned long)temp_host->last_time_up);
break;
case MACRO_LASTHOSTDOWN:
asprintf(output, "%lu", (unsigned long)temp_host->last_time_down);
break;
case MACRO_LASTHOSTUNREACHABLE:
asprintf(output, "%lu", (unsigned long)temp_host->last_time_unreachable);
break;
case MACRO_HOSTNOTIFICATIONNUMBER:
asprintf(output, "%d", temp_host->current_notification_number);
break;
case MACRO_HOSTNOTIFICATIONID:
asprintf(output, "%lu", temp_host->current_notification_id);
break;
case MACRO_HOSTEVENTID:
asprintf(output, "%lu", temp_host->current_event_id);
break;
case MACRO_LASTHOSTEVENTID:
asprintf(output, "%lu", temp_host->last_event_id);
break;
case MACRO_HOSTPROBLEMID:
asprintf(output, "%lu", temp_host->current_problem_id);
break;
case MACRO_LASTHOSTPROBLEMID:
asprintf(output, "%lu", temp_host->last_problem_id);
break;
#endif
case MACRO_HOSTACTIONURL:
if (temp_host->action_url)
*output = (char *)strdup(temp_host->action_url);
break;
case MACRO_HOSTNOTESURL:
if (temp_host->notes_url)
*output = (char *)strdup(temp_host->notes_url);
break;
case MACRO_HOSTNOTES:
if (temp_host->notes)
*output = (char *)strdup(temp_host->notes);
break;
#ifdef NSCORE
case MACRO_HOSTGROUPNAMES:
/* find all hostgroups this host is associated with */
for (temp_objectlist = temp_host->hostgroups_ptr; temp_objectlist != NULL; temp_objectlist = temp_objectlist->next) {
if ((temp_hostgroup = (hostgroup *)temp_objectlist->object_ptr) == NULL)
continue;
asprintf(&buf1, "%s%s%s", (buf2) ? buf2 : "", (buf2) ? "," : "", temp_hostgroup->group_name);
my_free(buf2);
buf2 = buf1;
}
if (buf2) {
*output = (char *)strdup(buf2);
my_free(buf2);
}
break;
case MACRO_TOTALHOSTSERVICES:
case MACRO_TOTALHOSTSERVICESOK:
case MACRO_TOTALHOSTSERVICESWARNING:
case MACRO_TOTALHOSTSERVICESUNKNOWN:
case MACRO_TOTALHOSTSERVICESCRITICAL:
/* generate host service summary macros (if they haven't already been computed) */
if (mac->x[MACRO_TOTALHOSTSERVICES] == NULL) {
for (temp_servicesmember = temp_host->services; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) {
if ((temp_service = temp_servicesmember->service_ptr) == NULL)
continue;
total_host_services++;
switch (temp_service->current_state) {
case STATE_OK:
total_host_services_ok++;
break;
case STATE_WARNING:
total_host_services_warning++;
break;
case STATE_UNKNOWN:
total_host_services_unknown++;
break;
case STATE_CRITICAL:
total_host_services_critical++;
break;
default:
break;
}
}
/* these macros are time-intensive to compute, and will likely be used together, so save them all for future use */
my_free(mac->x[MACRO_TOTALHOSTSERVICES]);
asprintf(&mac->x[MACRO_TOTALHOSTSERVICES], "%d", total_host_services);
my_free(mac->x[MACRO_TOTALHOSTSERVICESOK]);
asprintf(&mac->x[MACRO_TOTALHOSTSERVICESOK], "%d", total_host_services_ok);
my_free(mac->x[MACRO_TOTALHOSTSERVICESWARNING]);
asprintf(&mac->x[MACRO_TOTALHOSTSERVICESWARNING], "%d", total_host_services_warning);
my_free(mac->x[MACRO_TOTALHOSTSERVICESUNKNOWN]);
asprintf(&mac->x[MACRO_TOTALHOSTSERVICESUNKNOWN], "%d", total_host_services_unknown);
my_free(mac->x[MACRO_TOTALHOSTSERVICESCRITICAL]);
asprintf(&mac->x[MACRO_TOTALHOSTSERVICESCRITICAL], "%d", total_host_services_critical);
}
/* return only the macro the user requested */
*output = mac->x[macro_type];
/* tell caller to NOT free memory when done */
*free_macro = FALSE;
break;
#endif
/***************/
/* MISC MACROS */
/***************/
case MACRO_HOSTACKAUTHOR:
case MACRO_HOSTACKAUTHORNAME:
case MACRO_HOSTACKAUTHORALIAS:
case MACRO_HOSTACKCOMMENT:
/* no need to do any more work - these are already precomputed elsewhere */
/* NOTE: these macros won't work as on-demand macros */
*output = mac->x[macro_type];
*free_macro = FALSE;
break;
default:
log_debug_info(DEBUGL_MACROS, 0, "UNHANDLED HOST MACRO #%d! THIS IS A BUG!\n", macro_type);
return ERROR;
}
/* post-processing */
/* notes, notes URL and action URL macros may themselves contain macros, so process them... */
switch (macro_type) {
case MACRO_HOSTACTIONURL:
case MACRO_HOSTNOTESURL:
process_macros_r(mac, *output, &temp_buffer, URL_ENCODE_MACRO_CHARS);
my_free(*output);
*output = temp_buffer;
break;
case MACRO_HOSTNOTES:
process_macros_r(mac, *output, &temp_buffer, 0);
my_free(*output);
*output = temp_buffer;
break;
default:
break;
}
return OK;
}
int grab_standard_host_macro(int macro_type, host *temp_host, char **output, int *free_macro) {
return grab_standard_host_macro_r(&global_macros, macro_type, temp_host, output, free_macro);
}
/**
* computes a hostgroup macro
*/
int grab_standard_hostgroup_macro_r(icinga_macros *mac, int macro_type, hostgroup *temp_hostgroup, char **output) {
hostsmember *temp_hostsmember = NULL;
char *temp_buffer = NULL;
unsigned int temp_len = 0;
unsigned int init_len = 0;
if (temp_hostgroup == NULL || output == NULL)
return ERROR;
/* get the macro value */
switch (macro_type) {
case MACRO_HOSTGROUPNAME:
*output = (char *)strdup(temp_hostgroup->group_name);
break;
case MACRO_HOSTGROUPALIAS:
if (temp_hostgroup->alias)
*output = (char *)strdup(temp_hostgroup->alias);
break;
case MACRO_HOSTGROUPMEMBERS:
/* make the calculations for total string length */
for (temp_hostsmember = temp_hostgroup->members; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
if (temp_hostsmember->host_name == NULL)
continue;
if (temp_len == 0) {
temp_len += strlen(temp_hostsmember->host_name) + 1;
} else {
temp_len += strlen(temp_hostsmember->host_name) + 2;
}
}
/* if there no hostgroups members, we need to malloc at least an empty string for future calls of this function */
if (!temp_len) {
*output = calloc(1, 1);
return OK;
}
/* allocate or reallocate the memory buffer */
if (*output == NULL) {
*output = (char *)malloc(temp_len);
} else {
init_len = strlen(*output);
temp_len += init_len;
*output = (char *)realloc(*output, temp_len);
}
/* now fill in the string with the member names */
for (temp_hostsmember = temp_hostgroup->members; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
if (temp_hostsmember->host_name == NULL)
continue;
temp_buffer = *output + init_len;
if (init_len == 0) { /* If our buffer didn't contain anything, we just need to write "%s,%s" */
init_len += sprintf(temp_buffer, "%s", temp_hostsmember->host_name);
} else {
init_len += sprintf(temp_buffer, ",%s", temp_hostsmember->host_name);
}
}
break;
case MACRO_HOSTGROUPACTIONURL:
if (temp_hostgroup->action_url)
*output = (char *)strdup(temp_hostgroup->action_url);
break;
case MACRO_HOSTGROUPNOTESURL:
if (temp_hostgroup->notes_url)
*output = (char *)strdup(temp_hostgroup->notes_url);
break;
case MACRO_HOSTGROUPNOTES:
if (temp_hostgroup->notes)
*output = (char *)strdup(temp_hostgroup->notes);
break;
default:
log_debug_info(DEBUGL_MACROS, 0, "UNHANDLED HOSTGROUP MACRO #%d! THIS IS A BUG!\n", macro_type);
return ERROR;
}
/* post-processing */
/* notes, notes URL and action URL macros may themselves contain macros, so process them... */
switch (macro_type) {
case MACRO_HOSTGROUPACTIONURL:
case MACRO_HOSTGROUPNOTESURL:
process_macros_r(mac, *output, &temp_buffer, URL_ENCODE_MACRO_CHARS);
my_free(*output);
*output = temp_buffer;
break;
case MACRO_HOSTGROUPNOTES:
process_macros_r(mac, *output, &temp_buffer, 0);
my_free(*output);
*output = temp_buffer;
break;
default:
break;
}
return OK;
}
int grab_standard_hostgroup_macro(int macro_type, hostgroup *temp_hostgroup, char **output) {
return grab_standard_hostgroup_macro_r(&global_macros, macro_type, temp_hostgroup, output);
}
/**
* computes a service macro
*/
int grab_standard_service_macro_r(icinga_macros *mac, int macro_type, service *temp_service, char **output, int *free_macro) {
char *temp_buffer = NULL;
#ifdef NSCORE
servicegroup *temp_servicegroup = NULL;
objectlist *temp_objectlist = NULL;
time_t current_time = 0L;
unsigned long duration = 0L;
int days = 0;
int hours = 0;
int minutes = 0;
int seconds = 0;
char *buf1 = NULL;
char *buf2 = NULL;
#endif
if (temp_service == NULL || output == NULL)
return ERROR;
/* BY DEFAULT TELL CALLER TO FREE MACRO BUFFER WHEN DONE */
*free_macro = TRUE;
/* get the macro value */
switch (macro_type) {
case MACRO_SERVICEDESC:
*output = (char *)strdup(temp_service->description);
break;
case MACRO_SERVICEDISPLAYNAME:
if (temp_service->display_name)
*output = (char *)strdup(temp_service->display_name);
break;
#ifdef NSCORE
case MACRO_SERVICEOUTPUT:
if (temp_service->plugin_output)
*output = (char *)strdup(temp_service->plugin_output);
break;
case MACRO_LONGSERVICEOUTPUT:
if (temp_service->long_plugin_output)
*output = (char *)strdup(temp_service->long_plugin_output);
break;
case MACRO_SERVICEPERFDATA:
if (temp_service->perf_data)
*output = (char *)strdup(temp_service->perf_data);
break;
#endif
case MACRO_SERVICECHECKCOMMAND:
if (temp_service->service_check_command)
*output = (char *)strdup(temp_service->service_check_command);
break;
#ifdef NSCORE
case MACRO_SERVICECHECKTYPE:
*output = (char *)strdup((temp_service->check_type == SERVICE_CHECK_PASSIVE) ? "PASSIVE" : "ACTIVE");
break;
case MACRO_SERVICESTATETYPE:
*output = (char *)strdup((temp_service->state_type == HARD_STATE) ? "HARD" : "SOFT");
break;
case MACRO_SERVICESTATE:
if (temp_service->current_state == STATE_OK)
*output = (char *)strdup("OK");
else if (temp_service->current_state == STATE_WARNING)
*output = (char *)strdup("WARNING");
else if (temp_service->current_state == STATE_CRITICAL)
*output = (char *)strdup("CRITICAL");
else
*output = (char *)strdup("UNKNOWN");
break;
case MACRO_SERVICESTATEID:
asprintf(output, "%d", temp_service->current_state);
break;
case MACRO_LASTSERVICESTATE:
if (temp_service->last_state == STATE_OK)
*output = (char *)strdup("OK");
else if (temp_service->last_state == STATE_WARNING)
*output = (char *)strdup("WARNING");
else if (temp_service->last_state == STATE_CRITICAL)
*output = (char *)strdup("CRITICAL");
else
*output = (char *)strdup("UNKNOWN");
break;
case MACRO_LASTSERVICESTATEID:
asprintf(output, "%d", temp_service->last_state);
break;
#endif
case MACRO_SERVICEISVOLATILE:
asprintf(output, "%d", temp_service->is_volatile);
break;
#ifdef NSCORE
case MACRO_SERVICEATTEMPT:
asprintf(output, "%d", temp_service->current_attempt);
break;
case MACRO_MAXSERVICEATTEMPTS:
asprintf(output, "%d", temp_service->max_attempts);
break;
case MACRO_SERVICEEXECUTIONTIME:
asprintf(output, "%.3f", temp_service->execution_time);
break;
case MACRO_SERVICELATENCY:
asprintf(output, "%.3f", temp_service->latency);
break;
case MACRO_LASTSERVICECHECK:
asprintf(output, "%lu", (unsigned long)temp_service->last_check);
break;
case MACRO_LASTSERVICESTATECHANGE:
asprintf(output, "%lu", (unsigned long)temp_service->last_state_change);
break;
case MACRO_LASTSERVICEOK:
asprintf(output, "%lu", (unsigned long)temp_service->last_time_ok);
break;
case MACRO_LASTSERVICEWARNING:
asprintf(output, "%lu", (unsigned long)temp_service->last_time_warning);
break;
case MACRO_LASTSERVICEUNKNOWN:
asprintf(output, "%lu", (unsigned long)temp_service->last_time_unknown);
break;
case MACRO_LASTSERVICECRITICAL:
asprintf(output, "%lu", (unsigned long)temp_service->last_time_critical);
break;
case MACRO_SERVICEDOWNTIME:
asprintf(output, "%d", temp_service->scheduled_downtime_depth);
break;
case MACRO_SERVICEPERCENTCHANGE:
asprintf(output, "%.2f", temp_service->percent_state_change);
break;
case MACRO_SERVICEDURATIONSEC:
case MACRO_SERVICEDURATION:
time(¤t_time);
duration = (unsigned long)(current_time - temp_service->last_state_change);
/* get the state duration in seconds */
if (macro_type == MACRO_SERVICEDURATIONSEC)
asprintf(output, "%lu", duration);
/* get the state duration */
else {
days = duration / 86400;
duration -= (days * 86400);
hours = duration / 3600;
duration -= (hours * 3600);
minutes = duration / 60;
duration -= (minutes * 60);
seconds = duration;
asprintf(output, "%dd %dh %dm %ds", days, hours, minutes, seconds);
}
break;
case MACRO_SERVICENOTIFICATIONNUMBER:
asprintf(output, "%d", temp_service->current_notification_number);
break;
case MACRO_SERVICENOTIFICATIONID:
asprintf(output, "%lu", temp_service->current_notification_id);
break;
case MACRO_SERVICEEVENTID:
asprintf(output, "%lu", temp_service->current_event_id);
break;
case MACRO_LASTSERVICEEVENTID:
asprintf(output, "%lu", temp_service->last_event_id);
break;
case MACRO_SERVICEPROBLEMID:
asprintf(output, "%lu", temp_service->current_problem_id);
break;
case MACRO_LASTSERVICEPROBLEMID:
asprintf(output, "%lu", temp_service->last_problem_id);
break;
#endif
case MACRO_SERVICEACTIONURL:
if (temp_service->action_url)
*output = (char *)strdup(temp_service->action_url);
break;
case MACRO_SERVICENOTESURL:
if (temp_service->notes_url)
*output = (char *)strdup(temp_service->notes_url);
break;
case MACRO_SERVICENOTES:
if (temp_service->notes)
*output = (char *)strdup(temp_service->notes);
break;
#ifdef NSCORE
case MACRO_SERVICEGROUPNAMES:
/* find all servicegroups this service is associated with */
for (temp_objectlist = temp_service->servicegroups_ptr; temp_objectlist != NULL; temp_objectlist = temp_objectlist->next) {
if ((temp_servicegroup = (servicegroup *)temp_objectlist->object_ptr) == NULL)
continue;
asprintf(&buf1, "%s%s%s", (buf2) ? buf2 : "", (buf2) ? "," : "", temp_servicegroup->group_name);
my_free(buf2);
buf2 = buf1;
}
if (buf2) {
*output = (char *)strdup(buf2);
my_free(buf2);
}
break;
#endif
/***************/
/* MISC MACROS */
/***************/
case MACRO_SERVICEACKAUTHOR:
case MACRO_SERVICEACKAUTHORNAME:
case MACRO_SERVICEACKAUTHORALIAS:
case MACRO_SERVICEACKCOMMENT:
/* no need to do any more work - these are already precomputed elsewhere */
/* NOTE: these macros won't work as on-demand macros */
*output = mac->x[macro_type];
*free_macro = FALSE;
break;
default:
log_debug_info(DEBUGL_MACROS, 0, "UNHANDLED SERVICE MACRO #%d! THIS IS A BUG!\n", macro_type);
return ERROR;
}
/* post-processing */
/* notes, notes URL and action URL macros may themselves contain macros, so process them... */
switch (macro_type) {
case MACRO_SERVICEACTIONURL:
case MACRO_SERVICENOTESURL:
process_macros_r(mac, *output, &temp_buffer, URL_ENCODE_MACRO_CHARS);
my_free(*output);
*output = temp_buffer;
break;
case MACRO_SERVICENOTES:
process_macros_r(mac, *output, &temp_buffer, 0);
my_free(*output);
*output = temp_buffer;
break;
default:
break;
}
return OK;
}
int grab_standard_service_macro(int macro_type, service *temp_service, char **output, int *free_macro) {
return grab_standard_service_macro_r(&global_macros, macro_type, temp_service, output, free_macro);
}
/**
* computes a servicegroup macro
*/
int grab_standard_servicegroup_macro_r(icinga_macros *mac, int macro_type, servicegroup *temp_servicegroup, char **output) {
servicesmember *temp_servicesmember = NULL;
char *temp_buffer = NULL;
unsigned int temp_len = 0;
unsigned int init_len = 0;
if (temp_servicegroup == NULL || output == NULL)
return ERROR;
/* get the macro value */
switch (macro_type) {
case MACRO_SERVICEGROUPNAME:
*output = (char *)strdup(temp_servicegroup->group_name);
break;
case MACRO_SERVICEGROUPALIAS:
if (temp_servicegroup->alias)
*output = (char *)strdup(temp_servicegroup->alias);
break;
case MACRO_SERVICEGROUPMEMBERS:
/* make the calculations for total string length */
for (temp_servicesmember = temp_servicegroup->members; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) {
if (temp_servicesmember->host_name == NULL || temp_servicesmember->service_description == NULL)
continue;
if (temp_len == 0) {
temp_len += strlen(temp_servicesmember->host_name) + strlen(temp_servicesmember->service_description) + 2;
} else {
temp_len += strlen(temp_servicesmember->host_name) + strlen(temp_servicesmember->service_description) + 3;
}
}
/* if there no servicegroups members, we need to malloc at least an empty string for future calls of this function */
if (!temp_len) {
*output = calloc(1, 1);
return OK;
}
/* allocate or reallocate the memory buffer */
if (*output == NULL) {
*output = (char *)malloc(temp_len);
} else {
init_len = strlen(*output);
temp_len += init_len;
*output = (char *)realloc(*output, temp_len);
}
/* now fill in the string with the group members */
for (temp_servicesmember = temp_servicegroup->members; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) {
if (temp_servicesmember->host_name == NULL || temp_servicesmember->service_description == NULL)
continue;
temp_buffer = *output + init_len;
if (init_len == 0) { /* If our buffer didn't contain anything, we just need to write "%s,%s" */
init_len += sprintf(temp_buffer, "%s,%s", temp_servicesmember->host_name, temp_servicesmember->service_description);
} else { /* Now we need to write ",%s,%s" */
init_len += sprintf(temp_buffer, ",%s,%s", temp_servicesmember->host_name, temp_servicesmember->service_description);
}
}
break;
case MACRO_SERVICEGROUPACTIONURL:
if (temp_servicegroup->action_url)
*output = (char *)strdup(temp_servicegroup->action_url);
break;
case MACRO_SERVICEGROUPNOTESURL:
if (temp_servicegroup->notes_url)
*output = (char *)strdup(temp_servicegroup->notes_url);
break;
case MACRO_SERVICEGROUPNOTES:
if (temp_servicegroup->notes)
*output = (char *)strdup(temp_servicegroup->notes);
break;
default:
log_debug_info(DEBUGL_MACROS, 0, "UNHANDLED SERVICEGROUP MACRO #%d! THIS IS A BUG!\n", macro_type);
return ERROR;
}
/* post-processing */
/* notes, notes URL and action URL macros may themselves contain macros, so process them... */
switch (macro_type) {
case MACRO_SERVICEGROUPACTIONURL:
case MACRO_SERVICEGROUPNOTESURL:
process_macros_r(mac, *output, &temp_buffer, URL_ENCODE_MACRO_CHARS);
my_free(*output);
*output = temp_buffer;
break;
case MACRO_SERVICEGROUPNOTES:
process_macros_r(mac, *output, &temp_buffer, 0);
my_free(*output);
*output = temp_buffer;
break;
default:
break;
}
return OK;
}
int grab_standard_servicegroup_macro(int macro_type, servicegroup *temp_servicegroup, char **output) {
return grab_standard_servicegroup_macro_r(&global_macros, macro_type, temp_servicegroup, output);
}
/**
* computes a contact macro
*/
int grab_standard_contact_macro_r(icinga_macros *mac, int macro_type, contact *temp_contact, char **output) {
#ifdef NSCORE
contactgroup *temp_contactgroup = NULL;
objectlist *temp_objectlist = NULL;
char *buf1 = NULL;
char *buf2 = NULL;
#endif
if (temp_contact == NULL || output == NULL)
return ERROR;
/* get the macro value */
switch (macro_type) {
case MACRO_CONTACTNAME:
*output = (char *)strdup(temp_contact->name);
break;
case MACRO_CONTACTALIAS:
*output = (char *)strdup(temp_contact->alias);
break;
case MACRO_CONTACTEMAIL:
if (temp_contact->email)
*output = (char *)strdup(temp_contact->email);
break;
case MACRO_CONTACTPAGER:
if (temp_contact->pager)
*output = (char *)strdup(temp_contact->pager);
break;
#ifdef NSCORE
case MACRO_CONTACTGROUPNAMES:
/* get the contactgroup names */
/* find all contactgroups this contact is a member of */
for (temp_objectlist = temp_contact->contactgroups_ptr; temp_objectlist != NULL; temp_objectlist = temp_objectlist->next) {
if ((temp_contactgroup = (contactgroup *)temp_objectlist->object_ptr) == NULL)
continue;
asprintf(&buf1, "%s%s%s", (buf2) ? buf2 : "", (buf2) ? "," : "", temp_contactgroup->group_name);
my_free(buf2);
buf2 = buf1;
}
if (buf2) {
*output = (char *)strdup(buf2);
my_free(buf2);
}
break;
#endif
default:
log_debug_info(DEBUGL_MACROS, 0, "UNHANDLED CONTACT MACRO #%d! THIS IS A BUG!\n", macro_type);
return ERROR;
}
return OK;
}
int grab_standard_contact_macro(int macro_type, contact *temp_contact, char **output) {
return grab_standard_contact_macro_r(&global_macros, macro_type, temp_contact, output);
}
/**
* computes a contact address macro
*/
int grab_contact_address_macro_r(icinga_macros *mac, int macro_num, contact *temp_contact, char **output) {
if (macro_num < 0 || macro_num >= MAX_CONTACT_ADDRESSES)
return ERROR;
if (temp_contact == NULL || output == NULL)
return ERROR;
/* get the macro */
if (temp_contact->address[macro_num])
*output = (char *)strdup(temp_contact->address[macro_num]);
return OK;
}
int grab_contact_address_macro(int macro_num, contact *temp_contact, char **output) {
return grab_contact_address_macro_r(&global_macros, macro_num, temp_contact, output);
}
/**
* computes a contactgroup macro
*/
int grab_standard_contactgroup_macro_r(icinga_macros *mac, int macro_type, contactgroup *temp_contactgroup, char **output) {
contactsmember *temp_contactsmember = NULL;
if (temp_contactgroup == NULL || output == NULL)
return ERROR;
/* get the macro value */
switch (macro_type) {
case MACRO_CONTACTGROUPNAME:
*output = (char *)strdup(temp_contactgroup->group_name);
break;
case MACRO_CONTACTGROUPALIAS:
if (temp_contactgroup->alias)
*output = (char *)strdup(temp_contactgroup->alias);
break;
case MACRO_CONTACTGROUPMEMBERS:
/* get the member list */
for (temp_contactsmember = temp_contactgroup->members; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) {
if (temp_contactsmember->contact_name == NULL)
continue;
if (*output == NULL)
*output = (char *)strdup(temp_contactsmember->contact_name);
else if ((*output = (char *)realloc(*output, strlen(*output) + strlen(temp_contactsmember->contact_name) + 2))) {
strcat(*output, ",");
strcat(*output, temp_contactsmember->contact_name);
}
}
break;
default:
log_debug_info(DEBUGL_MACROS, 0, "UNHANDLED CONTACTGROUP MACRO #%d! THIS IS A BUG!\n", macro_type);
return ERROR;
}
return OK;
}
int grab_standard_contactgroup_macro(int macro_type, contactgroup *temp_contactgroup, char **output) {
return grab_standard_contactgroup_macro_r(&global_macros, macro_type, temp_contactgroup, output);
}
/**
* computes a custom object macro
*/
int grab_custom_object_macro_r(icinga_macros *mac, char *macro_name, customvariablesmember *vars, char **output) {
customvariablesmember *temp_customvariablesmember = NULL;
int result = ERROR;
if (macro_name == NULL || vars == NULL || output == NULL)
return ERROR;
/* get the custom variable */
for (temp_customvariablesmember = vars; temp_customvariablesmember != NULL; temp_customvariablesmember = temp_customvariablesmember->next) {
if (temp_customvariablesmember->variable_name == NULL)
continue;
if (!strcmp(macro_name, temp_customvariablesmember->variable_name)) {
if (temp_customvariablesmember->variable_value)
*output = (char *)strdup(temp_customvariablesmember->variable_value);
result = OK;
break;
}
}
return result;
}
int grab_custom_object_macro(char *macro_name, customvariablesmember *vars, char **output) {
return grab_custom_object_macro_r(&global_macros, macro_name, vars, output);
}
/******************************************************************/
/********************* MACRO STRING FUNCTIONS *********************/
/******************************************************************/
/**
* cleans illegal characters in macros before output
*/
char *clean_macro_chars(char *macro, int options) {
register int x = 0;
register int y = 0;
register int ch = 0;
register int len = 0;
if (macro == NULL)
return "";
len = (int)strlen(macro);
/* strip illegal characters out of macro */
if (options & STRIP_ILLEGAL_MACRO_CHARS) {
for (y = 0, x = 0; x < len; x++) {
ch = macro[x] & 0xff;
/* illegal chars are skipped */
if (!illegal_output_char_map[ch])
macro[y++] = macro[x];
}
macro[y++] = '\x0';
}
#ifdef ON_HOLD_FOR_NOW
/* escape nasty character in macro */
if (options & ESCAPE_MACRO_CHARS) {
}
#endif
return macro;
}
/**
* encodes a string in proper URL format
*/
char *get_url_encoded_string(char *input) {
register int x = 0;
register int y = 0;
char *encoded_url_string = NULL;
char temp_expansion[6] = "";
/* bail if no input */
if (input == NULL)
return NULL;
/* allocate enough memory to escape all characters if necessary */
if ((encoded_url_string = (char *)malloc((strlen(input) * 3) + 1)) == NULL)
return NULL;
/* check/encode all characters */
for (x = 0, y = 0; input[x] != (char)'\x0'; x++) {
/* alpha-numeric characters and a few other characters don't get encoded */
if (((char)input[x] >= '0' && (char)input[x] <= '9') || ((char)input[x] >= 'A' && (char)input[x] <= 'Z') || ((char)input[x] >= (char)'a' && (char)input[x] <= (char)'z') || (char)input[x] == (char)'.' || (char)input[x] == (char)'-' || (char)input[x] == (char)'_' || (char)input[x] == (char)':' || (char)input[x] == (char)'/' || (char)input[x] == (char)'?' || (char)input[x] == (char)'=' || (char)input[x] == (char)'&') {
encoded_url_string[y] = input[x];
y++;
}
/* spaces are pluses */
else if ((char)input[x] <= (char)' ') {
encoded_url_string[y] = '+';
y++;
}
/* anything else gets represented by its hex value */
else {
encoded_url_string[y] = '\x0';
sprintf(temp_expansion, "%%%02X", (unsigned int)(input[x] & 0xFF));
strcat(encoded_url_string, temp_expansion);
y += 3;
}
}
/* terminate encoded string */
encoded_url_string[y] = '\x0';
return encoded_url_string;
}
static int macro_key_cmp(const void *a_, const void *b_) {
struct macro_key_code *a = (struct macro_key_code *)a_;
struct macro_key_code *b = (struct macro_key_code *)b_;
return strcmp(a->name, b->name);
}
/******************************************************************/
/***************** MACRO INITIALIZATION FUNCTIONS *****************/
/******************************************************************/
/**
* initializes global macros
*/
int init_macros(void) {
int x;
init_macrox_names();
for (x = 0; x < 32; x++)
illegal_output_char_map[x] = 1;
illegal_output_char_map[127] = 1;
/*
* non-volatile macros are free()'d when they're set.
* We must do this in order to not lose the constant
* ones when we get SIGHUP or a RESTART_PROGRAM event
* from the command fifo. Otherwise a memset() would
* have been better.
*/
clear_volatile_macros_r(&global_macros);
/* backwards compatibility hack */
macro_x = global_macros.x;
/*
* Now build an ordered list of X macro names so we can
* do binary lookups later and avoid a ton of strcmp()'s
* for each and every check that gets run. A hash table
* is actually slower, since the most frequently used
* keys are so long and a binary lookup is completed in
* 7 steps for up to ~200 keys, worst case.
*/
for (x = 0; x < MACRO_X_COUNT; x++) {
macro_keys[x].code = x;
macro_keys[x].name = macro_x_names[x];
switch (x) {
/* host/service output/perfdata and author/comment macros should get cleaned */
case MACRO_HOSTOUTPUT:
case MACRO_SERVICEOUTPUT:
case MACRO_HOSTPERFDATA:
case MACRO_SERVICEPERFDATA:
case MACRO_HOSTACKAUTHOR:
case MACRO_HOSTACKCOMMENT:
case MACRO_SERVICEACKAUTHOR:
case MACRO_SERVICEACKCOMMENT:
case MACRO_LONGHOSTOUTPUT:
case MACRO_LONGSERVICEOUTPUT:
case MACRO_HOSTGROUPNOTES:
case MACRO_SERVICEGROUPNOTES:
macro_keys[x].clean_options = (STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS);
break;
/* url macros should get cleaned */
case MACRO_HOSTACTIONURL:
case MACRO_HOSTNOTESURL:
case MACRO_SERVICEACTIONURL:
case MACRO_SERVICENOTESURL:
case MACRO_HOSTGROUPNOTESURL:
case MACRO_HOSTGROUPACTIONURL:
case MACRO_SERVICEGROUPNOTESURL:
case MACRO_SERVICEGROUPACTIONURL:
macro_keys[x].clean_options = URL_ENCODE_MACRO_CHARS;
break;
/* by default, we do not clean anything */
default:
macro_keys[x].clean_options = 0;
break;
}
}
qsort(macro_keys, x, sizeof(struct macro_key_code), macro_key_cmp);
return OK;
}
/**
* initializes the names of macros, using this nifty little macro
* which ensures we never add any typos to the list
* \#\#name appends as astring, \#name makes sure that param is trated as string
*/
#define add_macrox_name(name) macro_x_names[MACRO_##name] = strdup(#name)
int init_macrox_names(void) {
register int x = 0;
/* initialize macro names */
for (x = 0; x < MACRO_X_COUNT; x++)
macro_x_names[x] = NULL;
/* initialize each macro name */
add_macrox_name(HOSTNAME);
add_macrox_name(HOSTALIAS);
add_macrox_name(HOSTADDRESS);
add_macrox_name(HOSTADDRESS6);
add_macrox_name(SERVICEDESC);
add_macrox_name(SERVICESTATE);
add_macrox_name(SERVICESTATEID);
add_macrox_name(SERVICEATTEMPT);
add_macrox_name(SERVICEISVOLATILE);
add_macrox_name(LONGDATETIME);
add_macrox_name(SHORTDATETIME);
add_macrox_name(DATE);
add_macrox_name(TIME);
add_macrox_name(TIMET);
add_macrox_name(LASTHOSTCHECK);
add_macrox_name(LASTSERVICECHECK);
add_macrox_name(LASTHOSTSTATECHANGE);
add_macrox_name(LASTSERVICESTATECHANGE);
add_macrox_name(HOSTOUTPUT);
add_macrox_name(SERVICEOUTPUT);
add_macrox_name(HOSTPERFDATA);
add_macrox_name(SERVICEPERFDATA);
add_macrox_name(CONTACTNAME);
add_macrox_name(CONTACTALIAS);
add_macrox_name(CONTACTEMAIL);
add_macrox_name(CONTACTPAGER);
add_macrox_name(ADMINEMAIL);
add_macrox_name(ADMINPAGER);
add_macrox_name(HOSTSTATE);
add_macrox_name(HOSTSTATEID);
add_macrox_name(HOSTATTEMPT);
add_macrox_name(NOTIFICATIONTYPE);
add_macrox_name(NOTIFICATIONNUMBER);
add_macrox_name(NOTIFICATIONISESCALATED);
add_macrox_name(HOSTEXECUTIONTIME);
add_macrox_name(SERVICEEXECUTIONTIME);
add_macrox_name(HOSTLATENCY);
add_macrox_name(SERVICELATENCY);
add_macrox_name(HOSTDURATION);
add_macrox_name(SERVICEDURATION);
add_macrox_name(HOSTDURATIONSEC);
add_macrox_name(SERVICEDURATIONSEC);
add_macrox_name(HOSTDOWNTIME);
add_macrox_name(SERVICEDOWNTIME);
add_macrox_name(HOSTSTATETYPE);
add_macrox_name(SERVICESTATETYPE);
add_macrox_name(HOSTPERCENTCHANGE);
add_macrox_name(SERVICEPERCENTCHANGE);
add_macrox_name(HOSTGROUPNAME);
add_macrox_name(HOSTGROUPALIAS);
add_macrox_name(SERVICEGROUPNAME);
add_macrox_name(SERVICEGROUPALIAS);
add_macrox_name(HOSTACKAUTHOR);
add_macrox_name(HOSTACKCOMMENT);
add_macrox_name(SERVICEACKAUTHOR);
add_macrox_name(SERVICEACKCOMMENT);
add_macrox_name(LASTSERVICEOK);
add_macrox_name(LASTSERVICEWARNING);
add_macrox_name(LASTSERVICEUNKNOWN);
add_macrox_name(LASTSERVICECRITICAL);
add_macrox_name(LASTHOSTUP);
add_macrox_name(LASTHOSTDOWN);
add_macrox_name(LASTHOSTUNREACHABLE);
add_macrox_name(SERVICECHECKCOMMAND);
add_macrox_name(HOSTCHECKCOMMAND);
add_macrox_name(MAINCONFIGFILE);
add_macrox_name(STATUSDATAFILE);
add_macrox_name(HOSTDISPLAYNAME);
add_macrox_name(SERVICEDISPLAYNAME);
add_macrox_name(RETENTIONDATAFILE);
add_macrox_name(OBJECTCACHEFILE);
add_macrox_name(TEMPFILE);
add_macrox_name(LOGFILE);
add_macrox_name(RESOURCEFILE);
add_macrox_name(COMMANDFILE);
add_macrox_name(HOSTPERFDATAFILE);
add_macrox_name(SERVICEPERFDATAFILE);
add_macrox_name(HOSTACTIONURL);
add_macrox_name(HOSTNOTESURL);
add_macrox_name(HOSTNOTES);
add_macrox_name(SERVICEACTIONURL);
add_macrox_name(SERVICENOTESURL);
add_macrox_name(SERVICENOTES);
add_macrox_name(TOTALHOSTSUP);
add_macrox_name(TOTALHOSTSDOWN);
add_macrox_name(TOTALHOSTSUNREACHABLE);
add_macrox_name(TOTALHOSTSDOWNUNHANDLED);
add_macrox_name(TOTALHOSTSUNREACHABLEUNHANDLED);
add_macrox_name(TOTALHOSTPROBLEMS);
add_macrox_name(TOTALHOSTPROBLEMSUNHANDLED);
add_macrox_name(TOTALSERVICESOK);
add_macrox_name(TOTALSERVICESWARNING);
add_macrox_name(TOTALSERVICESCRITICAL);
add_macrox_name(TOTALSERVICESUNKNOWN);
add_macrox_name(TOTALSERVICESWARNINGUNHANDLED);
add_macrox_name(TOTALSERVICESCRITICALUNHANDLED);
add_macrox_name(TOTALSERVICESUNKNOWNUNHANDLED);
add_macrox_name(TOTALSERVICEPROBLEMS);
add_macrox_name(TOTALSERVICEPROBLEMSUNHANDLED);
add_macrox_name(PROCESSSTARTTIME);
add_macrox_name(HOSTCHECKTYPE);
add_macrox_name(SERVICECHECKTYPE);
add_macrox_name(LONGHOSTOUTPUT);
add_macrox_name(LONGSERVICEOUTPUT);
add_macrox_name(TEMPPATH);
add_macrox_name(HOSTNOTIFICATIONNUMBER);
add_macrox_name(SERVICENOTIFICATIONNUMBER);
add_macrox_name(HOSTNOTIFICATIONID);
add_macrox_name(SERVICENOTIFICATIONID);
add_macrox_name(HOSTEVENTID);
add_macrox_name(LASTHOSTEVENTID);
add_macrox_name(SERVICEEVENTID);
add_macrox_name(LASTSERVICEEVENTID);
add_macrox_name(HOSTGROUPNAMES);
add_macrox_name(SERVICEGROUPNAMES);
add_macrox_name(HOSTACKAUTHORNAME);
add_macrox_name(HOSTACKAUTHORALIAS);
add_macrox_name(SERVICEACKAUTHORNAME);
add_macrox_name(SERVICEACKAUTHORALIAS);
add_macrox_name(MAXHOSTATTEMPTS);
add_macrox_name(MAXSERVICEATTEMPTS);
add_macrox_name(TOTALHOSTSERVICES);
add_macrox_name(TOTALHOSTSERVICESOK);
add_macrox_name(TOTALHOSTSERVICESWARNING);
add_macrox_name(TOTALHOSTSERVICESUNKNOWN);
add_macrox_name(TOTALHOSTSERVICESCRITICAL);
add_macrox_name(HOSTGROUPNOTES);
add_macrox_name(HOSTGROUPNOTESURL);
add_macrox_name(HOSTGROUPACTIONURL);
add_macrox_name(SERVICEGROUPNOTES);
add_macrox_name(SERVICEGROUPNOTESURL);
add_macrox_name(SERVICEGROUPACTIONURL);
add_macrox_name(HOSTGROUPMEMBERS);
add_macrox_name(SERVICEGROUPMEMBERS);
add_macrox_name(CONTACTGROUPNAME);
add_macrox_name(CONTACTGROUPALIAS);
add_macrox_name(CONTACTGROUPMEMBERS);
add_macrox_name(CONTACTGROUPNAMES);
add_macrox_name(NOTIFICATIONRECIPIENTS);
add_macrox_name(NOTIFICATIONAUTHOR);
add_macrox_name(NOTIFICATIONAUTHORNAME);
add_macrox_name(NOTIFICATIONAUTHORALIAS);
add_macrox_name(NOTIFICATIONCOMMENT);
add_macrox_name(EVENTSTARTTIME);
add_macrox_name(HOSTPROBLEMID);
add_macrox_name(LASTHOSTPROBLEMID);
add_macrox_name(SERVICEPROBLEMID);
add_macrox_name(LASTSERVICEPROBLEMID);
add_macrox_name(ISVALIDTIME);
add_macrox_name(NEXTVALIDTIME);
add_macrox_name(LASTHOSTSTATE);
add_macrox_name(LASTHOSTSTATEID);
add_macrox_name(LASTSERVICESTATE);
add_macrox_name(LASTSERVICESTATEID);
return OK;
}
/******************************************************************/
/********************* MACRO CLEANUP FUNCTIONS ********************/
/******************************************************************/
/**
* free memory associated with the macrox names
*/
int free_macrox_names(void) {
register int x = 0;
/* free each macro name */
for (x = 0; x < MACRO_X_COUNT; x++)
my_free(macro_x_names[x]);
return OK;
}
/**
* clear argv macros - used in commands
*/
int clear_argv_macros_r(icinga_macros *mac) {
register int x = 0;
/* command argument macros */
for (x = 0; x < MAX_COMMAND_ARGUMENTS; x++)
my_free(mac->argv[x]);
return OK;
}
int clear_argv_macros(void) {
return clear_argv_macros_r(&global_macros);
}
/**
* copies non-volatile macros from global macro_x to **dest, which
* must be large enough to hold at least MACRO_X_COUNT entries.
* We use a shortlived macro to save up on typing
*/
#define cp_macro(name) dest[MACRO_##name] = global_macros.x[MACRO_##name]
void copy_constant_macros(char **dest) {
cp_macro(ADMINEMAIL);
cp_macro(ADMINPAGER);
cp_macro(MAINCONFIGFILE);
cp_macro(STATUSDATAFILE);
cp_macro(RETENTIONDATAFILE);
cp_macro(OBJECTCACHEFILE);
cp_macro(TEMPFILE);
cp_macro(LOGFILE);
cp_macro(RESOURCEFILE);
cp_macro(COMMANDFILE);
cp_macro(HOSTPERFDATAFILE);
cp_macro(SERVICEPERFDATAFILE);
cp_macro(PROCESSSTARTTIME);
cp_macro(TEMPPATH);
cp_macro(EVENTSTARTTIME);
}
#undef cp_macro
/**
* clear all macros that are not "constant" (i.e. they change throughout the course of monitoring)
* the thread-safe version
*/
int clear_volatile_macros_r(icinga_macros *mac) {
customvariablesmember *this_customvariablesmember = NULL;
customvariablesmember *next_customvariablesmember = NULL;
register int x = 0;
for (x = 0; x < MACRO_X_COUNT; x++) {
switch (x) {
case MACRO_ADMINEMAIL:
case MACRO_ADMINPAGER:
case MACRO_MAINCONFIGFILE:
case MACRO_STATUSDATAFILE:
case MACRO_RETENTIONDATAFILE:
case MACRO_OBJECTCACHEFILE:
case MACRO_TEMPFILE:
case MACRO_LOGFILE:
case MACRO_RESOURCEFILE:
case MACRO_COMMANDFILE:
case MACRO_HOSTPERFDATAFILE:
case MACRO_SERVICEPERFDATAFILE:
case MACRO_PROCESSSTARTTIME:
case MACRO_TEMPPATH:
case MACRO_EVENTSTARTTIME:
/* these don't change during the course of monitoring, so no need to free them */
break;
default:
my_free(mac->x[x]);
break;
}
}
/* contact address macros */
for (x = 0; x < MAX_CONTACT_ADDRESSES; x++)
my_free(mac->contactaddress[x]);
/* clear macro pointers */
mac->host_ptr = NULL;
mac->hostgroup_ptr = NULL;
mac->service_ptr = NULL;
mac->servicegroup_ptr = NULL;
mac->contact_ptr = NULL;
mac->contactgroup_ptr = NULL;
/* clear on-demand macro */
my_free(mac->ondemand);
/* clear ARGx macros */
clear_argv_macros_r(mac);
/* clear custom host variables */
for (this_customvariablesmember = mac->custom_host_vars; this_customvariablesmember != NULL; this_customvariablesmember = next_customvariablesmember) {
next_customvariablesmember = this_customvariablesmember->next;
my_free(this_customvariablesmember->variable_name);
my_free(this_customvariablesmember->variable_value);
my_free(this_customvariablesmember);
}
mac->custom_host_vars = NULL;
/* clear custom service variables */
for (this_customvariablesmember = mac->custom_service_vars; this_customvariablesmember != NULL; this_customvariablesmember = next_customvariablesmember) {
next_customvariablesmember = this_customvariablesmember->next;
my_free(this_customvariablesmember->variable_name);
my_free(this_customvariablesmember->variable_value);
my_free(this_customvariablesmember);
}
mac->custom_service_vars = NULL;
/* clear custom contact variables */
for (this_customvariablesmember = mac->custom_contact_vars; this_customvariablesmember != NULL; this_customvariablesmember = next_customvariablesmember) {
next_customvariablesmember = this_customvariablesmember->next;
my_free(this_customvariablesmember->variable_name);
my_free(this_customvariablesmember->variable_value);
my_free(this_customvariablesmember);
}
mac->custom_contact_vars = NULL;
return OK;
}
int clear_volatile_macros(void) {
return clear_volatile_macros_r(&global_macros);
}
/**
* clear service macros
* the thread-safe version
*/
int clear_service_macros_r(icinga_macros *mac) {
customvariablesmember *this_customvariablesmember = NULL;
customvariablesmember *next_customvariablesmember = NULL;
/* these are strings */
my_free(mac->x[MACRO_SERVICEDESC]);
my_free(mac->x[MACRO_SERVICEDISPLAYNAME]);
my_free(mac->x[MACRO_SERVICEOUTPUT]);
my_free(mac->x[MACRO_LONGSERVICEOUTPUT]);
my_free(mac->x[MACRO_SERVICEPERFDATA]);
/* recursive, but persistent */
my_free(mac->x[MACRO_SERVICECHECKCOMMAND]);
my_free(mac->x[MACRO_SERVICEACTIONURL]);
my_free(mac->x[MACRO_SERVICENOTESURL]);
my_free(mac->x[MACRO_SERVICENOTES]);
/* numbers or necessarily autogenerated string */
my_free(mac->x[MACRO_SERVICECHECKTYPE]);
my_free(mac->x[MACRO_SERVICESTATETYPE]);
my_free(mac->x[MACRO_SERVICESTATE]);
my_free(mac->x[MACRO_SERVICEISVOLATILE]);
my_free(mac->x[MACRO_SERVICESTATEID]);
my_free(mac->x[MACRO_SERVICEATTEMPT]);
my_free(mac->x[MACRO_MAXSERVICEATTEMPTS]);
my_free(mac->x[MACRO_SERVICEEXECUTIONTIME]);
my_free(mac->x[MACRO_SERVICELATENCY]);
my_free(mac->x[MACRO_LASTSERVICECHECK]);
my_free(mac->x[MACRO_LASTSERVICESTATECHANGE]);
my_free(mac->x[MACRO_LASTSERVICEOK]);
my_free(mac->x[MACRO_LASTSERVICEWARNING]);
my_free(mac->x[MACRO_LASTSERVICEUNKNOWN]);
my_free(mac->x[MACRO_LASTSERVICECRITICAL]);
my_free(mac->x[MACRO_SERVICEDOWNTIME]);
my_free(mac->x[MACRO_SERVICEPERCENTCHANGE]);
my_free(mac->x[MACRO_SERVICEDURATIONSEC]);
my_free(mac->x[MACRO_SERVICEDURATION]);
my_free(mac->x[MACRO_SERVICENOTIFICATIONNUMBER]);
my_free(mac->x[MACRO_SERVICENOTIFICATIONID]);
my_free(mac->x[MACRO_SERVICEEVENTID]);
my_free(mac->x[MACRO_LASTSERVICEEVENTID]);
my_free(mac->x[MACRO_SERVICEGROUPNAMES]);
my_free(mac->x[MACRO_SERVICEPROBLEMID]);
my_free(mac->x[MACRO_LASTSERVICEPROBLEMID]);
/* clear custom service variables */
for (this_customvariablesmember = mac->custom_service_vars; this_customvariablesmember != NULL; this_customvariablesmember = next_customvariablesmember) {
next_customvariablesmember = this_customvariablesmember->next;
my_free(this_customvariablesmember->variable_name);
my_free(this_customvariablesmember->variable_value);
my_free(this_customvariablesmember);
}
mac->custom_service_vars = NULL;
/* clear pointers */
mac->service_ptr = NULL;
return OK;
}
int clear_service_macros(void) {
return clear_service_macros_r(&global_macros);
}
/**
* clear host macros
* the thread-safe version
*/
int clear_host_macros_r(icinga_macros *mac) {
customvariablesmember *this_customvariablesmember = NULL;
customvariablesmember *next_customvariablesmember = NULL;
/* these are strings */
my_free(mac->x[MACRO_HOSTNAME]);
my_free(mac->x[MACRO_HOSTDISPLAYNAME]);
my_free(mac->x[MACRO_HOSTALIAS]);
my_free(mac->x[MACRO_HOSTADDRESS]);
my_free(mac->x[MACRO_HOSTADDRESS6]);
my_free(mac->x[MACRO_HOSTOUTPUT]);
my_free(mac->x[MACRO_LONGHOSTOUTPUT]);
my_free(mac->x[MACRO_HOSTPERFDATA]);
/* recursive, but persistent */
my_free(mac->x[MACRO_HOSTCHECKCOMMAND]);
my_free(mac->x[MACRO_HOSTACTIONURL]);
my_free(mac->x[MACRO_HOSTNOTESURL]);
my_free(mac->x[MACRO_HOSTNOTES]);
/* numbers or necessarily autogenerated string */
my_free(mac->x[MACRO_HOSTSTATE]);
my_free(mac->x[MACRO_HOSTSTATEID]);
my_free(mac->x[MACRO_HOSTCHECKTYPE]);
my_free(mac->x[MACRO_HOSTSTATETYPE]);
my_free(mac->x[MACRO_HOSTATTEMPT]);
my_free(mac->x[MACRO_MAXHOSTATTEMPTS]);
my_free(mac->x[MACRO_HOSTDOWNTIME]);
my_free(mac->x[MACRO_HOSTPERCENTCHANGE]);
my_free(mac->x[MACRO_HOSTDURATIONSEC]);
my_free(mac->x[MACRO_HOSTDURATION]);
my_free(mac->x[MACRO_HOSTEXECUTIONTIME]);
my_free(mac->x[MACRO_HOSTLATENCY]);
my_free(mac->x[MACRO_LASTHOSTCHECK]);
my_free(mac->x[MACRO_LASTHOSTSTATECHANGE]);
my_free(mac->x[MACRO_LASTHOSTUP]);
my_free(mac->x[MACRO_LASTHOSTDOWN]);
my_free(mac->x[MACRO_LASTHOSTUNREACHABLE]);
my_free(mac->x[MACRO_HOSTNOTIFICATIONNUMBER]);
my_free(mac->x[MACRO_HOSTNOTIFICATIONID]);
my_free(mac->x[MACRO_HOSTEVENTID]);
my_free(mac->x[MACRO_LASTHOSTEVENTID]);
my_free(mac->x[MACRO_HOSTGROUPNAMES]);
my_free(mac->x[MACRO_TOTALHOSTSERVICES]);
my_free(mac->x[MACRO_TOTALHOSTSERVICESOK]);
my_free(mac->x[MACRO_TOTALHOSTSERVICESWARNING]);
my_free(mac->x[MACRO_TOTALHOSTSERVICESUNKNOWN]);
my_free(mac->x[MACRO_TOTALHOSTSERVICESCRITICAL]);
my_free(mac->x[MACRO_HOSTPROBLEMID]);
my_free(mac->x[MACRO_LASTHOSTPROBLEMID]);
/* clear custom host variables */
for (this_customvariablesmember = mac->custom_host_vars; this_customvariablesmember != NULL; this_customvariablesmember = next_customvariablesmember) {
next_customvariablesmember = this_customvariablesmember->next;
my_free(this_customvariablesmember->variable_name);
my_free(this_customvariablesmember->variable_value);
my_free(this_customvariablesmember);
}
mac->custom_host_vars = NULL;
/* clear pointers */
mac->host_ptr = NULL;
return OK;
}
int clear_host_macros(void) {
return clear_host_macros_r(&global_macros);
}
/**
* clear hostgroup macros
* the thread-safe version
*/
int clear_hostgroup_macros_r(icinga_macros *mac) {
/* these are strings */
my_free(mac->x[MACRO_HOSTGROUPNAME]);
my_free(mac->x[MACRO_HOSTGROUPALIAS]);
/* generated */
my_free(mac->x[MACRO_HOSTGROUPMEMBERS]);
/* generated but persistent */
my_free(mac->x[MACRO_HOSTGROUPACTIONURL]);
my_free(mac->x[MACRO_HOSTGROUPNOTESURL]);
my_free(mac->x[MACRO_HOSTGROUPNOTES]);
/* clear pointers */
mac->hostgroup_ptr = NULL;
return OK;
}
int clear_hostgroup_macros(void) {
return clear_hostgroup_macros_r(&global_macros);
}
/**
* clear servicegroup macros
* the thread-safe version
*/
int clear_servicegroup_macros_r(icinga_macros *mac) {
/* these are strings */
my_free(mac->x[MACRO_SERVICEGROUPNAME]);
my_free(mac->x[MACRO_SERVICEGROUPALIAS]);
/* generated */
my_free(mac->x[MACRO_SERVICEGROUPMEMBERS]);
/* generated but persistent */
my_free(mac->x[MACRO_SERVICEGROUPACTIONURL]);
my_free(mac->x[MACRO_SERVICEGROUPNOTESURL]);
my_free(mac->x[MACRO_SERVICEGROUPNOTES]);
/* clear pointers */
mac->servicegroup_ptr = NULL;
return OK;
}
int clear_servicegroup_macros(void) {
return clear_servicegroup_macros_r(&global_macros);
}
/**
* clear contact macros
* the thread-safe version
*/
int clear_contact_macros_r(icinga_macros *mac) {
register int x;
customvariablesmember *this_customvariablesmember = NULL;
customvariablesmember *next_customvariablesmember = NULL;
/* these are strings */
my_free(mac->x[MACRO_CONTACTNAME]);
my_free(mac->x[MACRO_CONTACTALIAS]);
my_free(mac->x[MACRO_CONTACTEMAIL]);
my_free(mac->x[MACRO_CONTACTPAGER]);
/* generated per contact */
my_free(mac->x[MACRO_CONTACTGROUPNAMES]);
/* clear contact addresses */
for (x = 0; x < MAX_CONTACT_ADDRESSES; x++)
my_free(mac->contactaddress[x]);
/* clear custom contact variables */
for (this_customvariablesmember = mac->custom_contact_vars; this_customvariablesmember != NULL; this_customvariablesmember = next_customvariablesmember) {
next_customvariablesmember = this_customvariablesmember->next;
my_free(this_customvariablesmember->variable_name);
my_free(this_customvariablesmember->variable_value);
my_free(this_customvariablesmember);
}
mac->custom_contact_vars = NULL;
/* clear pointers */
mac->contact_ptr = NULL;
return OK;
}
int clear_contact_macros(void) {
return clear_contact_macros_r(&global_macros);
}
/**
* clear contactgroup macros
* the thread-safe version
*/
int clear_contactgroup_macros_r(icinga_macros *mac) {
/* these are strings */
my_free(mac->x[MACRO_CONTACTGROUPNAME]);
my_free(mac->x[MACRO_CONTACTGROUPALIAS]);
/* generated */
my_free(mac->x[MACRO_CONTACTGROUPMEMBERS]);
/* clear pointers */
mac->contactgroup_ptr = NULL;
return OK;
}
int clear_contactgroup_macros(void) {
return clear_contactgroup_macros_r(&global_macros);
}
/**
* clear summary macros
* the thread-safe version
*/
int clear_summary_macros_r(icinga_macros *mac) {
register int x;
for (x = MACRO_TOTALHOSTSUP; x <= MACRO_TOTALSERVICEPROBLEMSUNHANDLED; x++)
my_free(mac->x[x]);
return OK;
}
int clear_summary_macros(void) {
return clear_summary_macros_r(&global_macros);
}
/******************************************************************/
/****************** ENVIRONMENT MACRO FUNCTIONS *******************/
/******************************************************************/
#ifdef NSCORE
/**
* sets or unsets all macro environment variables
*/
int set_all_macro_environment_vars_r(icinga_macros *mac, int set) {
if (enable_environment_macros == FALSE)
return ERROR;
set_macrox_environment_vars_r(mac, set);
set_argv_macro_environment_vars_r(mac, set);
set_custom_macro_environment_vars_r(mac, set);
set_contact_address_environment_vars_r(mac, set);
return OK;
}
int set_all_macro_environment_vars(int set) {
return set_all_macro_environment_vars_r(&global_macros, set);
}
/**
* sets or unsets macrox environment variables
*/
int set_macrox_environment_vars_r(icinga_macros *mac, int set) {
register int x = 0;
int free_macro = FALSE;
/* set each of the macrox environment variables */
for (x = 0; x < MACRO_X_COUNT; x++) {
free_macro = FALSE;
if (use_large_installation_tweaks == TRUE) {
/* skip summary macro generation if large installation tweaks are enabled */
if (x >= MACRO_TOTALHOSTSUP && x <= MACRO_TOTALSERVICEPROBLEMSUNHANDLED)
continue;
/* skip groupmembers macro generation
* if large installation tweaks are enabled
* they may break environment macros, check
* https://dev.icinga.org/issues/3859
*/
if (x == MACRO_HOSTGROUPMEMBERS || x == MACRO_SERVICEGROUPMEMBERS)
continue;
}
/* generate the macro value if it hasn't already been done */
/* THIS IS EXPENSIVE */
if (set == TRUE) {
if (mac->x[x] == NULL)
grab_macrox_value_r(mac, x, NULL, NULL, &mac->x[x], &free_macro);
}
/* set the value */
set_macro_environment_var(macro_x_names[x], mac->x[x], set);
}
return OK;
}
int set_macrox_environment_vars(int set) {
return set_macrox_environment_vars_r(&global_macros, set);
}
/**
* sets or unsets argv macro environment variables
*/
int set_argv_macro_environment_vars_r(icinga_macros *mac, int set) {
char *macro_name = NULL;
register int x = 0;
/* set each of the argv macro environment variables */
for (x = 0; x < MAX_COMMAND_ARGUMENTS; x++) {
asprintf(¯o_name, "ARG%d", x + 1);
set_macro_environment_var(macro_name, mac->argv[x], set);
my_free(macro_name);
}
return OK;
}
int set_argv_macro_environment_vars(int set) {
return set_argv_macro_environment_vars_r(&global_macros, set);
}
/**
* sets or unsets custom host/service/contact macro environment variables
*/
int set_custom_macro_environment_vars_r(icinga_macros *mac, int set) {
customvariablesmember *temp_customvariablesmember = NULL;
host *temp_host = NULL;
service *temp_service = NULL;
contact *temp_contact = NULL;
char *customvarname = NULL;
/***** CUSTOM HOST VARIABLES *****/
/* generate variables and save them for later */
if ((temp_host = mac->host_ptr) && set == TRUE) {
for (temp_customvariablesmember = temp_host->custom_variables; temp_customvariablesmember != NULL; temp_customvariablesmember = temp_customvariablesmember->next) {
asprintf(&customvarname, "_HOST%s", temp_customvariablesmember->variable_name);
add_custom_variable_to_object(&mac->custom_host_vars, customvarname, temp_customvariablesmember->variable_value);
my_free(customvarname);
}
}
/* set variables */
for (temp_customvariablesmember = mac->custom_host_vars; temp_customvariablesmember != NULL; temp_customvariablesmember = temp_customvariablesmember->next) {
set_macro_environment_var(temp_customvariablesmember->variable_name, clean_macro_chars(temp_customvariablesmember->variable_value, STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS), set);
}
/***** CUSTOM SERVICE VARIABLES *****/
/* generate variables and save them for later */
if ((temp_service = mac->service_ptr) && set == TRUE) {
for (temp_customvariablesmember = temp_service->custom_variables; temp_customvariablesmember != NULL; temp_customvariablesmember = temp_customvariablesmember->next) {
asprintf(&customvarname, "_SERVICE%s", temp_customvariablesmember->variable_name);
add_custom_variable_to_object(&mac->custom_service_vars, customvarname, temp_customvariablesmember->variable_value);
my_free(customvarname);
}
}
/* set variables */
for (temp_customvariablesmember = mac->custom_service_vars; temp_customvariablesmember != NULL; temp_customvariablesmember = temp_customvariablesmember->next)
set_macro_environment_var(temp_customvariablesmember->variable_name, clean_macro_chars(temp_customvariablesmember->variable_value, STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS), set);
/***** CUSTOM CONTACT VARIABLES *****/
/* generate variables and save them for later */
if ((temp_contact = mac->contact_ptr) && set == TRUE) {
for (temp_customvariablesmember = temp_contact->custom_variables; temp_customvariablesmember != NULL; temp_customvariablesmember = temp_customvariablesmember->next) {
asprintf(&customvarname, "_CONTACT%s", temp_customvariablesmember->variable_name);
add_custom_variable_to_object(&mac->custom_contact_vars, customvarname, temp_customvariablesmember->variable_value);
my_free(customvarname);
}
}
/* set variables */
for (temp_customvariablesmember = mac->custom_contact_vars; temp_customvariablesmember != NULL; temp_customvariablesmember = temp_customvariablesmember->next)
set_macro_environment_var(temp_customvariablesmember->variable_name, clean_macro_chars(temp_customvariablesmember->variable_value, STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS), set);
return OK;
}
int set_custom_macro_environment_vars(int set) {
return set_custom_macro_environment_vars_r(&global_macros, set);
}
/**
* sets or unsets contact address environment variables
*/
int set_contact_address_environment_vars_r(icinga_macros *mac, int set) {
char *varname = NULL;
register int x;
/* these only get set during notifications */
if (mac->contact_ptr == NULL)
return OK;
for (x = 0; x < MAX_CONTACT_ADDRESSES; x++) {
asprintf(&varname, "CONTACTADDRESS%d", x);
set_macro_environment_var(varname, mac->contact_ptr->address[x], set);
my_free(varname);
}
return OK;
}
int set_contact_address_environment_vars(int set) {
return set_contact_address_environment_vars_r(&global_macros, set);
}
/**
* sets or unsets a macro environment variable
*/
int set_macro_environment_var(char *name, char *value, int set) {
char *env_macro_name = NULL;
/* we won't mess with null variable names */
if (name == NULL)
return ERROR;
/* create environment var name */
asprintf(&env_macro_name, "%s%s", MACRO_ENV_VAR_PREFIX, name);
/* set or unset the environment variable */
set_environment_var(env_macro_name, value, set);
/* free allocated memory */
my_free(env_macro_name);
return OK;
}
#endif
icinga-1.10.3/common/objects.c 0000664 0000000 0000000 00000370443 12276402000 0016117 0 ustar 00root root 0000000 0000000 /*****************************************************************************
*
* OBJECTS.C - Object addition and search functions for Icinga
*
* Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org)
* Copyright (c) 2009-2013 Nagios Core Development Team and Community Contributors
* Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*****************************************************************************/
#include "../include/config.h"
#include "../include/common.h"
#include "../include/objects.h"
#include "../include/skiplist.h"
#ifdef NSCORE
#ifdef USE_EVENT_BROKER
#include "../include/nebmods.h"
#endif
#include "../include/icinga.h"
#endif
#ifdef NSCGI
#include "../include/cgiutils.h"
#endif
/**** IMPLEMENTATION-SPECIFIC HEADER FILES ****/
#ifdef USE_XODTEMPLATE /* template-based routines */
#include "../xdata/xodtemplate.h"
#endif
host *host_list = NULL, *host_list_tail = NULL;
service *service_list = NULL, *service_list_tail = NULL;
contact *contact_list = NULL, *contact_list_tail = NULL;
contactgroup *contactgroup_list = NULL, *contactgroup_list_tail = NULL;
hostgroup *hostgroup_list = NULL, *hostgroup_list_tail = NULL;
servicegroup *servicegroup_list = NULL, *servicegroup_list_tail = NULL;
command *command_list = NULL, *command_list_tail = NULL;
timeperiod *timeperiod_list = NULL, *timeperiod_list_tail = NULL;
serviceescalation *serviceescalation_list = NULL, *serviceescalation_list_tail = NULL;
servicedependency *servicedependency_list = NULL, *servicedependency_list_tail = NULL;
hostdependency *hostdependency_list = NULL, *hostdependency_list_tail = NULL;
hostescalation *hostescalation_list = NULL, *hostescalation_list_tail = NULL;
module *module_list = NULL, *module_list_tail = NULL;
skiplist *object_skiplists[NUM_OBJECT_SKIPLISTS];
static int object_skiplists_valid = 0;
#ifdef NSCORE
/* keep this for compatibility */
int __nagios_object_structure_version = CURRENT_OBJECT_STRUCTURE_VERSION;
/* this will be used for IDOUtils, Michael Friedrich, 05-19-2010 */
int __icinga_object_structure_version = CURRENT_OBJECT_STRUCTURE_VERSION;
extern int use_precached_objects;
#endif
/******************************************************************/
/******* TOP-LEVEL HOST CONFIGURATION DATA INPUT FUNCTION *********/
/******************************************************************/
/* read all host configuration data from external source */
int read_object_config_data(char *main_config_file, int options, int cache, int precache) {
int result = OK;
/* initialize object skiplists */
init_object_skiplists();
/********* IMPLEMENTATION-SPECIFIC INPUT FUNCTION ********/
#ifdef USE_XODTEMPLATE
/* read in data from all text host config files (template-based) */
result = xodtemplate_read_config_data(main_config_file, options, cache, precache);
if (result != OK)
return ERROR;
#endif
return result;
}
/******************************************************************/
/******************** SKIPLIST FUNCTIONS **************************/
/******************************************************************/
int init_object_skiplists(void) {
if (object_skiplists_valid)
free_object_skiplists();
object_skiplists[HOST_SKIPLIST] = skiplist_new(15, 0.5, FALSE, FALSE, skiplist_compare_host);
object_skiplists[SERVICE_SKIPLIST] = skiplist_new(15, 0.5, FALSE, FALSE, skiplist_compare_service);
object_skiplists[COMMAND_SKIPLIST] = skiplist_new(10, 0.5, FALSE, FALSE, skiplist_compare_command);
object_skiplists[TIMEPERIOD_SKIPLIST] = skiplist_new(10, 0.5, FALSE, FALSE, skiplist_compare_timeperiod);
object_skiplists[CONTACT_SKIPLIST] = skiplist_new(10, 0.5, FALSE, FALSE, skiplist_compare_contact);
object_skiplists[CONTACTGROUP_SKIPLIST] = skiplist_new(10, 0.5, FALSE, FALSE, skiplist_compare_contactgroup);
object_skiplists[HOSTGROUP_SKIPLIST] = skiplist_new(10, 0.5, FALSE, FALSE, skiplist_compare_hostgroup);
object_skiplists[SERVICEGROUP_SKIPLIST] = skiplist_new(10, 0.5, FALSE, FALSE, skiplist_compare_servicegroup);
object_skiplists[HOSTESCALATION_SKIPLIST] = skiplist_new(15, 0.5, TRUE, FALSE, skiplist_compare_hostescalation);
object_skiplists[SERVICEESCALATION_SKIPLIST] = skiplist_new(15, 0.5, TRUE, FALSE, skiplist_compare_serviceescalation);
object_skiplists[HOSTDEPENDENCY_SKIPLIST] = skiplist_new(15, 0.5, TRUE, FALSE, skiplist_compare_hostdependency);
object_skiplists[SERVICEDEPENDENCY_SKIPLIST] = skiplist_new(15, 0.5, TRUE, FALSE, skiplist_compare_servicedependency);
object_skiplists[MODULE_SKIPLIST] = skiplist_new(10, 0.5, FALSE, FALSE, skiplist_compare_module);
object_skiplists_valid = 1;
return OK;
}
int free_object_skiplists(void) {
int x = 0;
for (x = 0; x < NUM_OBJECT_SKIPLISTS; x++)
skiplist_free(&object_skiplists[x]);
object_skiplists_valid = 0;
return OK;
}
int skiplist_compare_text(const char *val1a, const char *val1b, const char *val2a, const char *val2b) {
int result = 0;
/* check first name */
if (val1a == NULL && val2a == NULL)
result = 0;
else if (val1a == NULL)
result = 1;
else if (val2a == NULL)
result = -1;
else
result = strcmp(val1a, val2a);
/* check second name if necessary */
if (result == 0) {
if (val1b == NULL && val2b == NULL)
result = 0;
else if (val1b == NULL)
result = 1;
else if (val2b == NULL)
result = -1;
else
result = strcmp(val1b, val2b);
}
return result;
}
int skiplist_compare_host(void *a, void *b) {
host *oa = NULL;
host *ob = NULL;
oa = (host *)a;
ob = (host *)b;
if (oa == NULL && ob == NULL)
return 0;
if (oa == NULL)
return 1;
if (ob == NULL)
return -1;
return skiplist_compare_text(oa->name, NULL, ob->name, NULL);
}
int skiplist_compare_service(void *a, void *b) {
service *oa = NULL;
service *ob = NULL;
oa = (service *)a;
ob = (service *)b;
if (oa == NULL && ob == NULL)
return 0;
if (oa == NULL)
return 1;
if (ob == NULL)
return -1;
return skiplist_compare_text(oa->host_name, oa->description, ob->host_name, ob->description);
}
int skiplist_compare_command(void *a, void *b) {
command *oa = NULL;
command *ob = NULL;
oa = (command *)a;
ob = (command *)b;
if (oa == NULL && ob == NULL)
return 0;
if (oa == NULL)
return 1;
if (ob == NULL)
return -1;
return skiplist_compare_text(oa->name, NULL, ob->name, NULL);
}
int skiplist_compare_timeperiod(void *a, void *b) {
timeperiod *oa = NULL;
timeperiod *ob = NULL;
oa = (timeperiod *)a;
ob = (timeperiod *)b;
if (oa == NULL && ob == NULL)
return 0;
if (oa == NULL)
return 1;
if (ob == NULL)
return -1;
return skiplist_compare_text(oa->name, NULL, ob->name, NULL);
}
int skiplist_compare_contact(void *a, void *b) {
contact *oa = NULL;
contact *ob = NULL;
oa = (contact *)a;
ob = (contact *)b;
if (oa == NULL && ob == NULL)
return 0;
if (oa == NULL)
return 1;
if (ob == NULL)
return -1;
return skiplist_compare_text(oa->name, NULL, ob->name, NULL);
}
int skiplist_compare_contactgroup(void *a, void *b) {
contactgroup *oa = NULL;
contactgroup *ob = NULL;
oa = (contactgroup *)a;
ob = (contactgroup *)b;
if (oa == NULL && ob == NULL)
return 0;
if (oa == NULL)
return 1;
if (ob == NULL)
return -1;
return skiplist_compare_text(oa->group_name, NULL, ob->group_name, NULL);
}
int skiplist_compare_hostgroup(void *a, void *b) {
hostgroup *oa = NULL;
hostgroup *ob = NULL;
oa = (hostgroup *)a;
ob = (hostgroup *)b;
if (oa == NULL && ob == NULL)
return 0;
if (oa == NULL)
return 1;
if (ob == NULL)
return -1;
return skiplist_compare_text(oa->group_name, NULL, ob->group_name, NULL);
}
int skiplist_compare_servicegroup(void *a, void *b) {
servicegroup *oa = NULL;
servicegroup *ob = NULL;
oa = (servicegroup *)a;
ob = (servicegroup *)b;
if (oa == NULL && ob == NULL)
return 0;
if (oa == NULL)
return 1;
if (ob == NULL)
return -1;
return skiplist_compare_text(oa->group_name, NULL, ob->group_name, NULL);
}
int skiplist_compare_hostescalation(void *a, void *b) {
hostescalation *oa = NULL;
hostescalation *ob = NULL;
oa = (hostescalation *)a;
ob = (hostescalation *)b;
if (oa == NULL && ob == NULL)
return 0;
if (oa == NULL)
return 1;
if (ob == NULL)
return -1;
return skiplist_compare_text(oa->host_name, NULL, ob->host_name, NULL);
}
int skiplist_compare_serviceescalation(void *a, void *b) {
serviceescalation *oa = NULL;
serviceescalation *ob = NULL;
oa = (serviceescalation *)a;
ob = (serviceescalation *)b;
if (oa == NULL && ob == NULL)
return 0;
if (oa == NULL)
return 1;
if (ob == NULL)
return -1;
return skiplist_compare_text(oa->host_name, oa->description, ob->host_name, ob->description);
}
int skiplist_compare_hostdependency(void *a, void *b) {
hostdependency *oa = NULL;
hostdependency *ob = NULL;
oa = (hostdependency *)a;
ob = (hostdependency *)b;
if (oa == NULL && ob == NULL)
return 0;
if (oa == NULL)
return 1;
if (ob == NULL)
return -1;
return skiplist_compare_text(oa->dependent_host_name, NULL, ob->dependent_host_name, NULL);
}
int skiplist_compare_servicedependency(void *a, void *b) {
servicedependency *oa = NULL;
servicedependency *ob = NULL;
oa = (servicedependency *)a;
ob = (servicedependency *)b;
if (oa == NULL && ob == NULL)
return 0;
if (oa == NULL)
return 1;
if (ob == NULL)
return -1;
return skiplist_compare_text(oa->dependent_host_name, oa->dependent_service_description, ob->dependent_host_name, ob->dependent_service_description);
}
int skiplist_compare_module(void *a, void *b) {
module *oa = NULL;
module *ob = NULL;
oa = (module *)a;
ob = (module *)b;
if (oa == NULL && ob == NULL)
return 0;
if (oa == NULL)
return 1;
if (ob == NULL)
return -1;
return skiplist_compare_text(oa->name, NULL, ob->name, NULL);
}
int get_host_count(void) {
if (object_skiplists[HOST_SKIPLIST])
return object_skiplists[HOST_SKIPLIST]->items;
return 0;
}
int get_service_count(void) {
if (object_skiplists[SERVICE_SKIPLIST])
return object_skiplists[SERVICE_SKIPLIST]->items;
return 0;
}
/******************************************************************/
/**************** OBJECT ADDITION FUNCTIONS ***********************/
/******************************************************************/
/* add a new timeperiod to the list in memory */
timeperiod *add_timeperiod(char *name, char *alias) {
timeperiod *new_timeperiod = NULL;
int result = OK;
/* make sure we have the data we need */
if ((name == NULL || !strcmp(name, "")) || (alias == NULL || !strcmp(alias, ""))) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Name or alias for timeperiod is NULL\n");
return NULL;
}
/* allocate memory for the new timeperiod */
if ((new_timeperiod = calloc(1, sizeof(timeperiod))) == NULL)
return NULL;
/* copy string vars */
if ((new_timeperiod->name = (char *)strdup(name)) == NULL)
result = ERROR;
if ((new_timeperiod->alias = (char *)strdup(alias)) == NULL)
result = ERROR;
/* add new timeperiod to skiplist */
if (result == OK) {
result = skiplist_insert(object_skiplists[TIMEPERIOD_SKIPLIST], (void *)new_timeperiod);
switch (result) {
case SKIPLIST_ERROR_DUPLICATE:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Timeperiod '%s' has already been defined\n", name);
result = ERROR;
break;
case SKIPLIST_OK:
result = OK;
break;
default:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not add timeperiod '%s' to skiplist\n", name);
result = ERROR;
break;
}
}
/* handle errors */
if (result == ERROR) {
my_free(new_timeperiod->alias);
my_free(new_timeperiod->name);
my_free(new_timeperiod);
return NULL;
}
/* timeperiods are registered alphabetically, so add new items to tail of list */
if (timeperiod_list == NULL) {
timeperiod_list = new_timeperiod;
timeperiod_list_tail = timeperiod_list;
} else {
timeperiod_list_tail->next = new_timeperiod;
timeperiod_list_tail = new_timeperiod;
}
return new_timeperiod;
}
/* adds a new exclusion to a timeperiod */
timeperiodexclusion *add_exclusion_to_timeperiod(timeperiod *period, char *name) {
timeperiodexclusion *new_timeperiodexclusion = NULL;
/* make sure we have enough data */
if (period == NULL || name == NULL)
return NULL;
if ((new_timeperiodexclusion = (timeperiodexclusion *)malloc(sizeof(timeperiodexclusion))) == NULL)
return NULL;
new_timeperiodexclusion->timeperiod_name = (char *)strdup(name);
new_timeperiodexclusion->next = period->exclusions;
period->exclusions = new_timeperiodexclusion;
return new_timeperiodexclusion;
}
/* add a new timerange to a timeperiod */
timerange *add_timerange_to_timeperiod(timeperiod *period, int day, unsigned long start_time, unsigned long end_time) {
timerange *new_timerange = NULL;
/* make sure we have the data we need */
if (period == NULL)
return NULL;
if (day < 0 || day > 6) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Day %d is not valid for timeperiod '%s'\n", day, period->name);
return NULL;
}
if (start_time > 86400) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Start time %lu on day %d is not valid for timeperiod '%s'\n", start_time, day, period->name);
return NULL;
}
if (end_time > 86400) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: End time %lu on day %d is not value for timeperiod '%s'\n", end_time, day, period->name);
return NULL;
}
/* allocate memory for the new time range */
if ((new_timerange = malloc(sizeof(timerange))) == NULL)
return NULL;
new_timerange->range_start = start_time;
new_timerange->range_end = end_time;
/* add the new time range to the head of the range list for this day */
new_timerange->next = period->days[day];
period->days[day] = new_timerange;
return new_timerange;
}
/* add a new exception to a timeperiod */
daterange *add_exception_to_timeperiod(timeperiod *period, int type, int syear, int smon, int smday, int swday, int swday_offset, int eyear, int emon, int emday, int ewday, int ewday_offset, int skip_interval) {
daterange *new_daterange = NULL;
/* make sure we have the data we need */
if (period == NULL)
return NULL;
/* allocate memory for the date range range */
if ((new_daterange = malloc(sizeof(daterange))) == NULL)
return NULL;
new_daterange->times = NULL;
new_daterange->next = NULL;
new_daterange->type = type;
new_daterange->syear = syear;
new_daterange->smon = smon;
new_daterange->smday = smday;
new_daterange->swday = swday;
new_daterange->swday_offset = swday_offset;
new_daterange->eyear = eyear;
new_daterange->emon = emon;
new_daterange->emday = emday;
new_daterange->ewday = ewday;
new_daterange->ewday_offset = ewday_offset;
new_daterange->skip_interval = skip_interval;
/* add the new date range to the head of the range list for this exception type */
new_daterange->next = period->exceptions[type];
period->exceptions[type] = new_daterange;
return new_daterange;
}
/* add a new timerange to a daterange */
timerange *add_timerange_to_daterange(daterange *drange, unsigned long start_time, unsigned long end_time) {
timerange *new_timerange = NULL;
/* make sure we have the data we need */
if (drange == NULL)
return NULL;
if (start_time > 86400) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Start time %lu is not valid for timeperiod\n", start_time);
return NULL;
}
if (end_time > 86400) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: End time %lu is not value for timeperiod\n", end_time);
return NULL;
}
/* allocate memory for the new time range */
if ((new_timerange = malloc(sizeof(timerange))) == NULL)
return NULL;
new_timerange->range_start = start_time;
new_timerange->range_end = end_time;
/* add the new time range to the head of the range list for this date range */
new_timerange->next = drange->times;
drange->times = new_timerange;
return new_timerange;
}
/* add a new host definition */
host *add_host(char *name, char *display_name, char *alias, char *address, char *address6, char *check_period, int initial_state, double check_interval, double retry_interval, int max_attempts, int notify_up, int notify_down, int notify_unreachable, int notify_flapping, int notify_downtime, double notification_interval, double first_notification_delay, char *notification_period, int notifications_enabled, char *check_command, int checks_enabled, int accept_passive_checks, char *event_handler, int event_handler_enabled, int flap_detection_enabled, double low_flap_threshold, double high_flap_threshold, int flap_detection_on_up, int flap_detection_on_down, int flap_detection_on_unreachable, int stalk_on_up, int stalk_on_down, int stalk_on_unreachable, int process_perfdata, int failure_prediction_enabled, char *failure_prediction_options, int check_freshness, int freshness_threshold, char *notes, char *notes_url, char *action_url, char *icon_image, char *icon_image_alt, char *vrml_image, char *statusmap_image, int x_2d, int y_2d, int have_2d_coords, double x_3d, double y_3d, double z_3d, int have_3d_coords, int should_be_drawn, int retain_status_information, int retain_nonstatus_information, int obsess_over_host) {
host *new_host = NULL;
int result = OK;
#ifdef NSCORE
int x = 0;
#endif
/* make sure we have the data we need */
if ((name == NULL || !strcmp(name, "")) || (address == NULL || !strcmp(address, ""))) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Host name or address is NULL\n");
return NULL;
}
/* check values */
if (max_attempts <= 0) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Invalid max_check_attempts value for host '%s'\n", name);
return NULL;
}
if (check_interval < 0) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Invalid check_interval value for host '%s'\n", name);
return NULL;
}
if (notification_interval < 0) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Invalid notification_interval value for host '%s'\n", name);
return NULL;
}
if (first_notification_delay < 0) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Invalid first_notification_delay value for host '%s'\n", name);
return NULL;
}
if (freshness_threshold < 0) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Invalid freshness_threshold value for host '%s'\n", name);
return NULL;
}
/* allocate memory for a new host */
if ((new_host = (host *)calloc(1, sizeof(host))) == NULL)
return NULL;
/* duplicate string vars */
if ((new_host->name = (char *)strdup(name)) == NULL)
result = ERROR;
FILL_HASH(new_host->name);
if ((new_host->display_name = (char *)strdup((display_name == NULL) ? name : display_name)) == NULL)
result = ERROR;
if ((new_host->alias = (char *)strdup((alias == NULL) ? name : alias)) == NULL)
result = ERROR;
if ((new_host->address = (char *)strdup(address)) == NULL)
result = ERROR;
if ((new_host->address6 = (char *)strdup(address6)) == NULL)
result = ERROR;
if (check_period) {
if ((new_host->check_period = (char *)strdup(check_period)) == NULL)
result = ERROR;
}
if (notification_period) {
if ((new_host->notification_period = (char *)strdup(notification_period)) == NULL)
result = ERROR;
}
if (check_command) {
if ((new_host->host_check_command = (char *)strdup(check_command)) == NULL)
result = ERROR;
}
if (event_handler) {
if ((new_host->event_handler = (char *)strdup(event_handler)) == NULL)
result = ERROR;
}
if (failure_prediction_options) {
if ((new_host->failure_prediction_options = (char *)strdup(failure_prediction_options)) == NULL)
result = ERROR;
}
if (notes) {
if ((new_host->notes = (char *)strdup(notes)) == NULL)
result = ERROR;
}
if (notes_url) {
if ((new_host->notes_url = (char *)strdup(notes_url)) == NULL)
result = ERROR;
}
if (action_url) {
if ((new_host->action_url = (char *)strdup(action_url)) == NULL)
result = ERROR;
}
if (icon_image) {
if ((new_host->icon_image = (char *)strdup(icon_image)) == NULL)
result = ERROR;
}
if (icon_image_alt) {
if ((new_host->icon_image_alt = (char *)strdup(icon_image_alt)) == NULL)
result = ERROR;
}
if (vrml_image) {
if ((new_host->vrml_image = (char *)strdup(vrml_image)) == NULL)
result = ERROR;
}
if (statusmap_image) {
if ((new_host->statusmap_image = (char *)strdup(statusmap_image)) == NULL)
result = ERROR;
}
/* duplicate non-string vars */
new_host->max_attempts = max_attempts;
new_host->check_interval = check_interval;
new_host->retry_interval = retry_interval;
new_host->notification_interval = notification_interval;
new_host->first_notification_delay = first_notification_delay;
new_host->notify_on_recovery = (notify_up > 0) ? TRUE : FALSE;
new_host->notify_on_down = (notify_down > 0) ? TRUE : FALSE;
new_host->notify_on_unreachable = (notify_unreachable > 0) ? TRUE : FALSE;
new_host->notify_on_flapping = (notify_flapping > 0) ? TRUE : FALSE;
new_host->notify_on_downtime = (notify_downtime > 0) ? TRUE : FALSE;
new_host->flap_detection_enabled = (flap_detection_enabled > 0) ? TRUE : FALSE;
new_host->low_flap_threshold = low_flap_threshold;
new_host->high_flap_threshold = high_flap_threshold;
new_host->flap_detection_on_up = (flap_detection_on_up > 0) ? TRUE : FALSE;
new_host->flap_detection_on_down = (flap_detection_on_down > 0) ? TRUE : FALSE;
new_host->flap_detection_on_unreachable = (flap_detection_on_unreachable > 0) ? TRUE : FALSE;
new_host->stalk_on_up = (stalk_on_up > 0) ? TRUE : FALSE;
new_host->stalk_on_down = (stalk_on_down > 0) ? TRUE : FALSE;
new_host->stalk_on_unreachable = (stalk_on_unreachable > 0) ? TRUE : FALSE;
new_host->process_performance_data = (process_perfdata > 0) ? TRUE : FALSE;
new_host->check_freshness = (check_freshness > 0) ? TRUE : FALSE;
new_host->freshness_threshold = freshness_threshold;
new_host->checks_enabled = (checks_enabled > 0) ? TRUE : FALSE;
new_host->accept_passive_host_checks = (accept_passive_checks > 0) ? TRUE : FALSE;
new_host->event_handler_enabled = (event_handler_enabled > 0) ? TRUE : FALSE;
new_host->failure_prediction_enabled = (failure_prediction_enabled > 0) ? TRUE : FALSE;
new_host->x_2d = x_2d;
new_host->y_2d = y_2d;
new_host->have_2d_coords = (have_2d_coords > 0) ? TRUE : FALSE;
new_host->x_3d = x_3d;
new_host->y_3d = y_3d;
new_host->z_3d = z_3d;
new_host->have_3d_coords = (have_3d_coords > 0) ? TRUE : FALSE;
new_host->should_be_drawn = (should_be_drawn > 0) ? TRUE : FALSE;
new_host->obsess_over_host = (obsess_over_host > 0) ? TRUE : FALSE;
new_host->retain_status_information = (retain_status_information > 0) ? TRUE : FALSE;
new_host->retain_nonstatus_information = (retain_nonstatus_information > 0) ? TRUE : FALSE;
#ifdef NSCORE
new_host->current_state = initial_state;
new_host->current_event_id = 0L;
new_host->last_event_id = 0L;
new_host->current_problem_id = 0L;
new_host->last_problem_id = 0L;
new_host->last_state = initial_state;
new_host->last_hard_state = initial_state;
new_host->check_type = HOST_CHECK_ACTIVE;
new_host->last_host_notification = (time_t)0;
new_host->next_host_notification = (time_t)0;
new_host->next_check = (time_t)0;
new_host->should_be_scheduled = TRUE;
new_host->last_check = (time_t)0;
new_host->current_attempt = (initial_state == HOST_UP) ? 1 : max_attempts;
new_host->state_type = HARD_STATE;
new_host->execution_time = 0.0;
new_host->is_executing = FALSE;
new_host->latency = 0.0;
new_host->last_state_change = (time_t)0;
new_host->last_hard_state_change = (time_t)0;
new_host->last_time_up = (time_t)0;
new_host->last_time_down = (time_t)0;
new_host->last_time_unreachable = (time_t)0;
new_host->has_been_checked = FALSE;
new_host->is_being_freshened = FALSE;
new_host->problem_has_been_acknowledged = FALSE;
new_host->acknowledgement_type = ACKNOWLEDGEMENT_NONE;
new_host->acknowledgement_end_time = (time_t)0;
new_host->notifications_enabled = (notifications_enabled > 0) ? TRUE : FALSE;
new_host->notified_on_down = FALSE;
new_host->notified_on_unreachable = FALSE;
new_host->current_notification_number = 0;
/* state based escalation ranges */
new_host->current_down_notification_number = 0;
new_host->current_unreachable_notification_number = 0;
new_host->current_notification_id = 0L;
new_host->no_more_notifications = FALSE;
new_host->check_flapping_recovery_notification = FALSE;
new_host->scheduled_downtime_depth = 0;
new_host->check_options = CHECK_OPTION_NONE;
new_host->pending_flex_downtime = 0;
for (x = 0; x < MAX_STATE_HISTORY_ENTRIES; x++)
new_host->state_history[x] = STATE_OK;
new_host->state_history_index = 0;
new_host->last_state_history_update = (time_t)0;
new_host->is_flapping = FALSE;
new_host->flapping_comment_id = 0;
new_host->percent_state_change = 0.0;
new_host->total_services = 0;
new_host->total_service_check_interval = 0L;
new_host->modified_attributes = MODATTR_NONE;
new_host->circular_path_checked = FALSE;
new_host->contains_circular_path = FALSE;
#endif
/* add new host to skiplist */
if (result == OK) {
result = skiplist_insert(object_skiplists[HOST_SKIPLIST], (void *)new_host);
switch (result) {
case SKIPLIST_ERROR_DUPLICATE:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Host '%s' has already been defined\n", name);
result = ERROR;
break;
case SKIPLIST_OK:
result = OK;
break;
default:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not add host '%s' to skiplist\n", name);
result = ERROR;
break;
}
}
/* handle errors */
if (result == ERROR) {
#ifdef NSCORE
my_free(new_host->plugin_output);
my_free(new_host->long_plugin_output);
my_free(new_host->perf_data);
#endif
my_free(new_host->statusmap_image);
my_free(new_host->vrml_image);
my_free(new_host->icon_image_alt);
my_free(new_host->icon_image);
my_free(new_host->action_url);
my_free(new_host->notes_url);
my_free(new_host->notes);
my_free(new_host->failure_prediction_options);
my_free(new_host->event_handler);
my_free(new_host->host_check_command);
my_free(new_host->notification_period);
my_free(new_host->check_period);
my_free(new_host->address);
my_free(new_host->address6);
my_free(new_host->alias);
my_free(new_host->display_name);
my_free(new_host->name);
my_free(new_host);
return NULL;
}
/* hosts are sorted alphabetically, so add new items to tail of list */
if (host_list == NULL) {
host_list = new_host;
host_list_tail = host_list;
} else {
host_list_tail->next = new_host;
host_list_tail = new_host;
}
return new_host;
}
hostsmember *add_parent_host_to_host(host *hst, char *host_name) {
hostsmember *new_hostsmember = NULL;
/* make sure we have the data we need */
if (hst == NULL || host_name == NULL || !strcmp(host_name, "")) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Host is NULL or parent host name is NULL\n");
return NULL;
}
/* a host cannot be a parent/child of itself */
if (!strcmp(host_name, hst->name)) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Host '%s' cannot be a child/parent of itself\n", hst->name);
return NULL;
}
/* allocate memory */
if ((new_hostsmember = (hostsmember *)calloc(1, sizeof(hostsmember))) == NULL)
return NULL;
/* duplicate string vars */
if ((new_hostsmember->host_name = (char *)strdup(host_name)) == NULL) {
my_free(new_hostsmember->host_name);
my_free(new_hostsmember);
return NULL;
}
FILL_HASH(new_hostsmember->host_name);
/* add the parent host entry to the host definition */
new_hostsmember->next = hst->parent_hosts;
hst->parent_hosts = new_hostsmember;
return new_hostsmember;
}
hostsmember *add_child_link_to_host(host *hst, host *child_ptr) {
hostsmember *new_hostsmember = NULL;
/* make sure we have the data we need */
if (hst == NULL || child_ptr == NULL)
return NULL;
/* allocate memory */
if ((new_hostsmember = (hostsmember *)malloc(sizeof(hostsmember))) == NULL)
return NULL;
/* initialize values */
new_hostsmember->host_name = NULL;
#ifdef NSCORE
new_hostsmember->host_ptr = child_ptr;
#endif
/* add the child entry to the host definition */
new_hostsmember->next = hst->child_hosts;
hst->child_hosts = new_hostsmember;
return new_hostsmember;
}
servicesmember *add_service_link_to_host(host *hst, service *service_ptr) {
servicesmember *new_servicesmember = NULL;
/* make sure we have the data we need */
if (hst == NULL || service_ptr == NULL)
return NULL;
/* allocate memory */
if ((new_servicesmember = (servicesmember *)calloc(1, sizeof(servicesmember))) == NULL)
return NULL;
/* initialize values */
#ifdef NSCORE
new_servicesmember->service_ptr = service_ptr;
/* increment host->service counter for later processing */
hst->total_services++;
/* calculate check interval total for flapping */
hst->total_service_check_interval += service_ptr->check_interval;
#endif
/* add the child entry to the host definition */
new_servicesmember->next = hst->services;
hst->services = new_servicesmember;
return new_servicesmember;
}
/* add a new contactgroup to a host */
contactgroupsmember *add_contactgroup_to_host(host *hst, char *group_name) {
contactgroupsmember *new_contactgroupsmember = NULL;
/* make sure we have the data we need */
if (hst == NULL || (group_name == NULL || !strcmp(group_name, ""))) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Host or contactgroup member is NULL\n");
return NULL;
}
/* allocate memory for a new member */
if ((new_contactgroupsmember = calloc(1, sizeof(contactgroupsmember))) == NULL)
return NULL;
/* duplicate string vars */
if ((new_contactgroupsmember->group_name = (char *)strdup(group_name)) == NULL) {
my_free(new_contactgroupsmember->group_name);
my_free(new_contactgroupsmember);
return NULL;
}
/* add the new member to the head of the member list */
new_contactgroupsmember->next = hst->contact_groups;
hst->contact_groups = new_contactgroupsmember;;
return new_contactgroupsmember;
}
/* adds a contact to a host */
contactsmember *add_contact_to_host(host *hst, char *contact_name) {
return add_contact_to_object(&hst->contacts, contact_name);
}
/* adds a custom variable to a host */
customvariablesmember *add_custom_variable_to_host(host *hst, char *varname, char *varvalue) {
return add_custom_variable_to_object(&hst->custom_variables, varname, varvalue);
}
/* add a new host group to the list in memory */
hostgroup *add_hostgroup(char *name, char *alias, char *notes, char *notes_url, char *action_url) {
hostgroup *new_hostgroup = NULL;
int result = OK;
/* make sure we have the data we need */
if (name == NULL || !strcmp(name, "")) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Hostgroup name is NULL\n");
return NULL;
}
/* allocate memory */
if ((new_hostgroup = (hostgroup *)calloc(1, sizeof(hostgroup))) == NULL)
return NULL;
/* duplicate vars */
if ((new_hostgroup->group_name = (char *)strdup(name)) == NULL)
result = ERROR;
if ((new_hostgroup->alias = (char *)strdup((alias == NULL) ? name : alias)) == NULL)
result = ERROR;
if (notes) {
if ((new_hostgroup->notes = (char *)strdup(notes)) == NULL)
result = ERROR;
}
if (notes_url) {
if ((new_hostgroup->notes_url = (char *)strdup(notes_url)) == NULL)
result = ERROR;
}
if (action_url) {
if ((new_hostgroup->action_url = (char *)strdup(action_url)) == NULL)
result = ERROR;
}
/* add new host group to skiplist */
if (result == OK) {
result = skiplist_insert(object_skiplists[HOSTGROUP_SKIPLIST], (void *)new_hostgroup);
switch (result) {
case SKIPLIST_ERROR_DUPLICATE:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Hostgroup '%s' has already been defined\n", name);
result = ERROR;
break;
case SKIPLIST_OK:
result = OK;
break;
default:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not add hostgroup '%s' to skiplist\n", name);
result = ERROR;
break;
}
}
/* handle errors */
if (result == ERROR) {
my_free(new_hostgroup->alias);
my_free(new_hostgroup->group_name);
my_free(new_hostgroup);
return NULL;
}
/* hostgroups are sorted alphabetically, so add new items to tail of list */
if (hostgroup_list == NULL) {
hostgroup_list = new_hostgroup;
hostgroup_list_tail = hostgroup_list;
} else {
hostgroup_list_tail->next = new_hostgroup;
hostgroup_list_tail = new_hostgroup;
}
return new_hostgroup;
}
/* add a new host to a host group */
hostsmember *add_host_to_hostgroup(hostgroup *temp_hostgroup, char *host_name) {
hostsmember *new_member = NULL;
hostsmember *last_member = NULL;
hostsmember *temp_member = NULL;
/* make sure we have the data we need */
if (temp_hostgroup == NULL || (host_name == NULL || !strcmp(host_name, ""))) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Hostgroup or group member is NULL\n");
return NULL;
}
/* allocate memory for a new member */
if ((new_member = calloc(1, sizeof(hostsmember))) == NULL)
return NULL;
/* duplicate vars */
if ((new_member->host_name = (char *)strdup(host_name)) == NULL) {
my_free(new_member->host_name);
my_free(new_member);
return NULL;
}
FILL_HASH(new_member->host_name);
/* add the new member to the member list, sorted by host name */
last_member = temp_hostgroup->members;
for (temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
if (strcmp(new_member->host_name, temp_member->host_name) < 0) {
new_member->next = temp_member;
if (temp_member == temp_hostgroup->members)
temp_hostgroup->members = new_member;
else
last_member->next = new_member;
break;
} else
last_member = temp_member;
}
if (temp_hostgroup->members == NULL) {
new_member->next = NULL;
temp_hostgroup->members = new_member;
} else if (temp_member == NULL) {
new_member->next = NULL;
last_member->next = new_member;
}
return new_member;
}
/* add a new service group to the list in memory */
servicegroup *add_servicegroup(char *name, char *alias, char *notes, char *notes_url, char *action_url) {
servicegroup *new_servicegroup = NULL;
int result = OK;
/* make sure we have the data we need */
if (name == NULL || !strcmp(name, "")) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Servicegroup name is NULL\n");
return NULL;
}
/* allocate memory */
if ((new_servicegroup = (servicegroup *)calloc(1, sizeof(servicegroup))) == NULL)
return NULL;
/* duplicate vars */
if ((new_servicegroup->group_name = (char *)strdup(name)) == NULL)
result = ERROR;
if ((new_servicegroup->alias = (char *)strdup((alias == NULL) ? name : alias)) == NULL)
result = ERROR;
if (notes) {
if ((new_servicegroup->notes = (char *)strdup(notes)) == NULL)
result = ERROR;
}
if (notes_url) {
if ((new_servicegroup->notes_url = (char *)strdup(notes_url)) == NULL)
result = ERROR;
}
if (action_url) {
if ((new_servicegroup->action_url = (char *)strdup(action_url)) == NULL)
result = ERROR;
}
/* add new service group to skiplist */
if (result == OK) {
result = skiplist_insert(object_skiplists[SERVICEGROUP_SKIPLIST], (void *)new_servicegroup);
switch (result) {
case SKIPLIST_ERROR_DUPLICATE:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Servicegroup '%s' has already been defined\n", name);
result = ERROR;
break;
case SKIPLIST_OK:
result = OK;
break;
default:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not add servicegroup '%s' to skiplist\n", name);
result = ERROR;
break;
}
}
/* handle errors */
if (result == ERROR) {
my_free(new_servicegroup->alias);
my_free(new_servicegroup->group_name);
my_free(new_servicegroup);
return NULL;
}
/* servicegroups are sorted alphabetically, so add new items to tail of list */
if (servicegroup_list == NULL) {
servicegroup_list = new_servicegroup;
servicegroup_list_tail = servicegroup_list;
} else {
servicegroup_list_tail->next = new_servicegroup;
servicegroup_list_tail = new_servicegroup;
}
return new_servicegroup;
}
/* add a new service to a service group */
servicesmember *add_service_to_servicegroup(servicegroup *temp_servicegroup, char *host_name, char *svc_description) {
servicesmember *new_member = NULL;
servicesmember *last_member = NULL;
servicesmember *temp_member = NULL;
int result = OK;
/* make sure we have the data we need */
if (temp_servicegroup == NULL || (host_name == NULL || !strcmp(host_name, "")) || (svc_description == NULL || !strcmp(svc_description, ""))) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Servicegroup or group member is NULL\n");
return NULL;
}
/* allocate memory for a new member */
if ((new_member = calloc(1, sizeof(servicesmember))) == NULL)
return NULL;
/* duplicate vars */
if ((new_member->host_name = (char *)strdup(host_name)) == NULL)
result = ERROR;
if ((new_member->service_description = (char *)strdup(svc_description)) == NULL)
result = ERROR;
/* handle errors */
if (result == ERROR) {
my_free(new_member->service_description);
my_free(new_member->host_name);
my_free(new_member);
return NULL;
}
FILL_HASH(new_member->host_name);
FILL_HASH(new_member->service_description);
/* add new member to member list, sorted by host name then service description */
last_member = temp_servicegroup->members;
for (temp_member = temp_servicegroup->members; temp_member != NULL; temp_member = temp_member->next) {
int host_name_cmp = strcmp(new_member->host_name, temp_member->host_name);
if (host_name_cmp < 0) {
new_member->next = temp_member;
if (temp_member == temp_servicegroup->members)
temp_servicegroup->members = new_member;
else
last_member->next = new_member;
break;
}
else if (host_name_cmp == 0 && strcmp(new_member->service_description, temp_member->service_description) < 0) {
new_member->next = temp_member;
if (temp_member == temp_servicegroup->members)
temp_servicegroup->members = new_member;
else
last_member->next = new_member;
break;
}
else
last_member = temp_member;
}
if (temp_servicegroup->members == NULL) {
new_member->next = NULL;
temp_servicegroup->members = new_member;
} else if (temp_member == NULL) {
new_member->next = NULL;
last_member->next = new_member;
}
return new_member;
}
/* add a new contact to the list in memory */
contact *add_contact(char *name, char *alias, char *email, char *pager, char **addresses, char *svc_notification_period, char *host_notification_period, int notify_service_ok, int notify_service_critical, int notify_service_warning, int notify_service_unknown, int notify_service_flapping, int notify_service_downtime, int notify_host_up, int notify_host_down, int notify_host_unreachable, int notify_host_flapping, int notify_host_downtime, int host_notifications_enabled, int service_notifications_enabled, int can_submit_commands, int retain_status_information, int retain_nonstatus_information) {
contact *new_contact = NULL;
int x = 0;
int result = OK;
/* make sure we have the data we need */
if (name == NULL || !strcmp(name, "")) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Contact name is NULL\n");
return NULL;
}
/* allocate memory for a new contact */
if ((new_contact = (contact *)calloc(1, sizeof(contact))) == NULL)
return NULL;
/* duplicate vars */
if ((new_contact->name = (char *)strdup(name)) == NULL)
result = ERROR;
if ((new_contact->alias = (char *)strdup((alias == NULL) ? name : alias)) == NULL)
result = ERROR;
if (email) {
if ((new_contact->email = (char *)strdup(email)) == NULL)
result = ERROR;
}
if (pager) {
if ((new_contact->pager = (char *)strdup(pager)) == NULL)
result = ERROR;
}
if (svc_notification_period) {
if ((new_contact->service_notification_period = (char *)strdup(svc_notification_period)) == NULL)
result = ERROR;
}
if (host_notification_period) {
if ((new_contact->host_notification_period = (char *)strdup(host_notification_period)) == NULL)
result = ERROR;
}
if (addresses) {
for (x = 0; x < MAX_CONTACT_ADDRESSES; x++) {
if (addresses[x]) {
if ((new_contact->address[x] = (char *)strdup(addresses[x])) == NULL)
result = ERROR;
}
}
}
new_contact->notify_on_service_recovery = (notify_service_ok > 0) ? TRUE : FALSE;
new_contact->notify_on_service_critical = (notify_service_critical > 0) ? TRUE : FALSE;
new_contact->notify_on_service_warning = (notify_service_warning > 0) ? TRUE : FALSE;
new_contact->notify_on_service_unknown = (notify_service_unknown > 0) ? TRUE : FALSE;
new_contact->notify_on_service_flapping = (notify_service_flapping > 0) ? TRUE : FALSE;
new_contact->notify_on_service_downtime = (notify_service_downtime > 0) ? TRUE : FALSE;
new_contact->notify_on_host_recovery = (notify_host_up > 0) ? TRUE : FALSE;
new_contact->notify_on_host_down = (notify_host_down > 0) ? TRUE : FALSE;
new_contact->notify_on_host_unreachable = (notify_host_unreachable > 0) ? TRUE : FALSE;
new_contact->notify_on_host_flapping = (notify_host_flapping > 0) ? TRUE : FALSE;
new_contact->notify_on_host_downtime = (notify_host_downtime > 0) ? TRUE : FALSE;
new_contact->host_notifications_enabled = (host_notifications_enabled > 0) ? TRUE : FALSE;
new_contact->service_notifications_enabled = (service_notifications_enabled > 0) ? TRUE : FALSE;
new_contact->can_submit_commands = (can_submit_commands > 0) ? TRUE : FALSE;
new_contact->retain_status_information = (retain_status_information > 0) ? TRUE : FALSE;
new_contact->retain_nonstatus_information = (retain_nonstatus_information > 0) ? TRUE : FALSE;
#ifdef NSCORE
new_contact->last_host_notification = (time_t)0L;
new_contact->last_service_notification = (time_t)0L;
new_contact->modified_attributes = MODATTR_NONE;
new_contact->modified_host_attributes = MODATTR_NONE;
new_contact->modified_service_attributes = MODATTR_NONE;
new_contact->host_notification_period_ptr = NULL;
new_contact->service_notification_period_ptr = NULL;
new_contact->contactgroups_ptr = NULL;
#endif
/* add new contact to skiplist */
if (result == OK) {
result = skiplist_insert(object_skiplists[CONTACT_SKIPLIST], (void *)new_contact);
switch (result) {
case SKIPLIST_ERROR_DUPLICATE:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Contact '%s' has already been defined\n", name);
result = ERROR;
break;
case SKIPLIST_OK:
result = OK;
break;
default:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not add contact '%s' to skiplist\n", name);
result = ERROR;
break;
}
}
/* handle errors */
if (result == ERROR) {
for (x = 0; x < MAX_CONTACT_ADDRESSES; x++)
my_free(new_contact->address[x]);
my_free(new_contact->name);
my_free(new_contact->alias);
my_free(new_contact->email);
my_free(new_contact->pager);
my_free(new_contact->service_notification_period);
my_free(new_contact->host_notification_period);
my_free(new_contact);
return NULL;
}
/* contacts are sorted alphabetically, so add new items to tail of list */
if (contact_list == NULL) {
contact_list = new_contact;
contact_list_tail = contact_list;
} else {
contact_list_tail->next = new_contact;
contact_list_tail = new_contact;
}
return new_contact;
}
/* adds a host notification command to a contact definition */
commandsmember *add_host_notification_command_to_contact(contact *cntct, char *command_name) {
commandsmember *new_commandsmember = NULL;
/* make sure we have the data we need */
if (cntct == NULL || (command_name == NULL || !strcmp(command_name, ""))) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Contact or host notification command is NULL\n");
return NULL;
}
/* allocate memory */
if ((new_commandsmember = calloc(1, sizeof(commandsmember))) == NULL)
return NULL;
/* duplicate vars */
if ((new_commandsmember->command = (char *)strdup(command_name)) == NULL) {
my_free(new_commandsmember->command);
my_free(new_commandsmember);
return NULL;
}
/* add the notification command */
new_commandsmember->next = cntct->host_notification_commands;
cntct->host_notification_commands = new_commandsmember;
return new_commandsmember;
}
/* adds a service notification command to a contact definition */
commandsmember *add_service_notification_command_to_contact(contact *cntct, char *command_name) {
commandsmember *new_commandsmember = NULL;
/* make sure we have the data we need */
if (cntct == NULL || (command_name == NULL || !strcmp(command_name, ""))) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Contact or service notification command is NULL\n");
return NULL;
}
/* allocate memory */
if ((new_commandsmember = calloc(1, sizeof(commandsmember))) == NULL)
return NULL;
/* duplicate vars */
if ((new_commandsmember->command = (char *)strdup(command_name)) == NULL) {
my_free(new_commandsmember->command);
my_free(new_commandsmember);
return NULL;
}
/* add the notification command */
new_commandsmember->next = cntct->service_notification_commands;
cntct->service_notification_commands = new_commandsmember;
return new_commandsmember;
}
/* adds a custom variable to a contact */
customvariablesmember *add_custom_variable_to_contact(contact *cntct, char *varname, char *varvalue) {
return add_custom_variable_to_object(&cntct->custom_variables, varname, varvalue);
}
/* add a new contact group to the list in memory */
contactgroup *add_contactgroup(char *name, char *alias) {
contactgroup *new_contactgroup = NULL;
int result = OK;
/* make sure we have the data we need */
if (name == NULL || !strcmp(name, "")) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Contactgroup name is NULL\n");
return NULL;
}
/* allocate memory for a new contactgroup entry */
if ((new_contactgroup = calloc(1, sizeof(contactgroup))) == NULL)
return NULL;
/* duplicate vars */
if ((new_contactgroup->group_name = (char *)strdup(name)) == NULL)
result = ERROR;
if ((new_contactgroup->alias = (char *)strdup((alias == NULL) ? name : alias)) == NULL)
result = ERROR;
/* add new contact group to skiplist */
if (result == OK) {
result = skiplist_insert(object_skiplists[CONTACTGROUP_SKIPLIST], (void *)new_contactgroup);
switch (result) {
case SKIPLIST_ERROR_DUPLICATE:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Contactgroup '%s' has already been defined\n", name);
result = ERROR;
break;
case SKIPLIST_OK:
result = OK;
break;
default:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not add contactgroup '%s' to skiplist\n", name);
result = ERROR;
break;
}
}
/* handle errors */
if (result == ERROR) {
my_free(new_contactgroup->alias);
my_free(new_contactgroup->group_name);
my_free(new_contactgroup);
return NULL;
}
/* contactgroups are sorted alphabetically, so add new items to tail of list */
if (contactgroup_list == NULL) {
contactgroup_list = new_contactgroup;
contactgroup_list_tail = contactgroup_list;
} else {
contactgroup_list_tail->next = new_contactgroup;
contactgroup_list_tail = new_contactgroup;
}
return new_contactgroup;
}
/* add a new member to a contact group */
contactsmember *add_contact_to_contactgroup(contactgroup *grp, char *contact_name) {
contactsmember *new_contactsmember = NULL;
/* make sure we have the data we need */
if (grp == NULL || (contact_name == NULL || !strcmp(contact_name, ""))) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Contactgroup or contact name is NULL\n");
return NULL;
}
/* allocate memory for a new member */
if ((new_contactsmember = calloc(1, sizeof(contactsmember))) == NULL)
return NULL;
/* duplicate vars */
if ((new_contactsmember->contact_name = (char *)strdup(contact_name)) == NULL) {
my_free(new_contactsmember->contact_name);
my_free(new_contactsmember);
return NULL;
}
/* add the new member to the head of the member list */
new_contactsmember->next = grp->members;
grp->members = new_contactsmember;
return new_contactsmember;
}
/* add a new service to the list in memory */
service *add_service(char *host_name, char *description, char *display_name, char *check_period, int initial_state, int max_attempts, int parallelize, int accept_passive_checks, double check_interval, double retry_interval, double notification_interval, double first_notification_delay, char *notification_period, int notify_recovery, int notify_unknown, int notify_warning, int notify_critical, int notify_flapping, int notify_downtime, int notifications_enabled, int is_volatile, char *event_handler, int event_handler_enabled, char *check_command, int checks_enabled, int flap_detection_enabled, double low_flap_threshold, double high_flap_threshold, int flap_detection_on_ok, int flap_detection_on_warning, int flap_detection_on_unknown, int flap_detection_on_critical, int stalk_on_ok, int stalk_on_warning, int stalk_on_unknown, int stalk_on_critical, int process_perfdata, int failure_prediction_enabled, char *failure_prediction_options, int check_freshness, int freshness_threshold, char *notes, char *notes_url, char *action_url, char *icon_image, char *icon_image_alt, int retain_status_information, int retain_nonstatus_information, int obsess_over_service) {
service *new_service = NULL;
int result = OK;
#ifdef NSCORE
int x = 0;
#endif
/* make sure we have everything we need */
if ((host_name == NULL || !strcmp(host_name, "")) || (description == NULL || !strcmp(description, "")) || (check_command == NULL || !strcmp(check_command, ""))) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Service description, host name, or check command is NULL\n");
return NULL;
}
/* check values */
if (max_attempts <= 0 || check_interval < 0 || retry_interval <= 0 || notification_interval < 0) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Invalid max_check_attempts, check_interval, retry_interval, or notification_interval value for service '%s' on host '%s'\n", description, host_name);
return NULL;
}
if (first_notification_delay < 0) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Invalid first_notification_delay value for service '%s' on host '%s'\n", description, host_name);
return NULL;
}
/* allocate memory */
if ((new_service = (service *)calloc(1, sizeof(service))) == NULL)
return NULL;
/* duplicate vars */
if ((new_service->host_name = (char *)strdup(host_name)) == NULL)
result = ERROR;
FILL_HASH(new_service->host_name);
if ((new_service->description = (char *)strdup(description)) == NULL)
result = ERROR;
FILL_HASH(new_service->description);
if ((new_service->display_name = (char *)strdup((display_name == NULL) ? description : display_name)) == NULL)
result = ERROR;
if ((new_service->service_check_command = (char *)strdup(check_command)) == NULL)
result = ERROR;
if (event_handler) {
if ((new_service->event_handler = (char *)strdup(event_handler)) == NULL)
result = ERROR;
}
if (notification_period) {
if ((new_service->notification_period = (char *)strdup(notification_period)) == NULL)
result = ERROR;
}
if (check_period) {
if ((new_service->check_period = (char *)strdup(check_period)) == NULL)
result = ERROR;
}
if (failure_prediction_options) {
if ((new_service->failure_prediction_options = (char *)strdup(failure_prediction_options)) == NULL)
result = ERROR;
}
if (notes) {
if ((new_service->notes = (char *)strdup(notes)) == NULL)
result = ERROR;
}
if (notes_url) {
if ((new_service->notes_url = (char *)strdup(notes_url)) == NULL)
result = ERROR;
}
if (action_url) {
if ((new_service->action_url = (char *)strdup(action_url)) == NULL)
result = ERROR;
}
if (icon_image) {
if ((new_service->icon_image = (char *)strdup(icon_image)) == NULL)
result = ERROR;
}
if (icon_image_alt) {
if ((new_service->icon_image_alt = (char *)strdup(icon_image_alt)) == NULL)
result = ERROR;
}
new_service->check_interval = check_interval;
new_service->retry_interval = retry_interval;
new_service->max_attempts = max_attempts;
new_service->parallelize = (parallelize > 0) ? TRUE : FALSE;
new_service->notification_interval = notification_interval;
new_service->first_notification_delay = first_notification_delay;
new_service->notify_on_unknown = (notify_unknown > 0) ? TRUE : FALSE;
new_service->notify_on_warning = (notify_warning > 0) ? TRUE : FALSE;
new_service->notify_on_critical = (notify_critical > 0) ? TRUE : FALSE;
new_service->notify_on_recovery = (notify_recovery > 0) ? TRUE : FALSE;
new_service->notify_on_flapping = (notify_flapping > 0) ? TRUE : FALSE;
new_service->notify_on_downtime = (notify_downtime > 0) ? TRUE : FALSE;
new_service->is_volatile = (is_volatile > 0) ? ((is_volatile == 2) ? VOLATILE_WITH_RENOTIFICATION_INTERVAL : TRUE) : FALSE;
new_service->flap_detection_enabled = (flap_detection_enabled > 0) ? TRUE : FALSE;
new_service->low_flap_threshold = low_flap_threshold;
new_service->high_flap_threshold = high_flap_threshold;
new_service->flap_detection_on_ok = (flap_detection_on_ok > 0) ? TRUE : FALSE;
new_service->flap_detection_on_warning = (flap_detection_on_warning > 0) ? TRUE : FALSE;
new_service->flap_detection_on_unknown = (flap_detection_on_unknown > 0) ? TRUE : FALSE;
new_service->flap_detection_on_critical = (flap_detection_on_critical > 0) ? TRUE : FALSE;
new_service->stalk_on_ok = (stalk_on_ok > 0) ? TRUE : FALSE;
new_service->stalk_on_warning = (stalk_on_warning > 0) ? TRUE : FALSE;
new_service->stalk_on_unknown = (stalk_on_unknown > 0) ? TRUE : FALSE;
new_service->stalk_on_critical = (stalk_on_critical > 0) ? TRUE : FALSE;
new_service->process_performance_data = (process_perfdata > 0) ? TRUE : FALSE;
new_service->check_freshness = (check_freshness > 0) ? TRUE : FALSE;
new_service->freshness_threshold = freshness_threshold;
new_service->accept_passive_service_checks = (accept_passive_checks > 0) ? TRUE : FALSE;
new_service->event_handler_enabled = (event_handler_enabled > 0) ? TRUE : FALSE;
new_service->checks_enabled = (checks_enabled > 0) ? TRUE : FALSE;
new_service->retain_status_information = (retain_status_information > 0) ? TRUE : FALSE;
new_service->retain_nonstatus_information = (retain_nonstatus_information > 0) ? TRUE : FALSE;
new_service->notifications_enabled = (notifications_enabled > 0) ? TRUE : FALSE;
new_service->obsess_over_service = (obsess_over_service > 0) ? TRUE : FALSE;
new_service->failure_prediction_enabled = (failure_prediction_enabled > 0) ? TRUE : FALSE;
#ifdef NSCORE
new_service->problem_has_been_acknowledged = FALSE;
new_service->acknowledgement_type = ACKNOWLEDGEMENT_NONE;
new_service->acknowledgement_end_time = (time_t)0;
new_service->check_type = SERVICE_CHECK_ACTIVE;
new_service->current_attempt = (initial_state == STATE_OK) ? 1 : max_attempts;
new_service->current_state = initial_state;
new_service->current_event_id = 0L;
new_service->last_event_id = 0L;
new_service->current_problem_id = 0L;
new_service->last_problem_id = 0L;
new_service->last_state = initial_state;
new_service->last_hard_state = initial_state;
new_service->state_type = HARD_STATE;
new_service->host_problem_at_last_check = FALSE;
new_service->check_flapping_recovery_notification = FALSE;
new_service->next_check = (time_t)0;
new_service->should_be_scheduled = TRUE;
new_service->last_check = (time_t)0;
new_service->last_notification = (time_t)0;
new_service->next_notification = (time_t)0;
new_service->no_more_notifications = FALSE;
new_service->last_state_change = (time_t)0;
new_service->last_hard_state_change = (time_t)0;
new_service->last_time_ok = (time_t)0;
new_service->last_time_warning = (time_t)0;
new_service->last_time_unknown = (time_t)0;
new_service->last_time_critical = (time_t)0;
new_service->has_been_checked = FALSE;
new_service->is_being_freshened = FALSE;
new_service->notified_on_unknown = FALSE;
new_service->notified_on_warning = FALSE;
new_service->notified_on_critical = FALSE;
new_service->current_notification_number = 0;
/* state based escalation ranges */
new_service->current_warning_notification_number = 0;
new_service->current_critical_notification_number = 0;
new_service->current_unknown_notification_number = 0;
new_service->current_notification_id = 0L;
new_service->latency = 0.0;
new_service->execution_time = 0.0;
new_service->is_executing = FALSE;
new_service->check_options = CHECK_OPTION_NONE;
new_service->scheduled_downtime_depth = 0;
new_service->pending_flex_downtime = 0;
for (x = 0; x < MAX_STATE_HISTORY_ENTRIES; x++)
new_service->state_history[x] = STATE_OK;
new_service->state_history_index = 0;
new_service->is_flapping = FALSE;
new_service->flapping_comment_id = 0;
new_service->percent_state_change = 0.0;
new_service->modified_attributes = MODATTR_NONE;
#endif
/* add new service to skiplist */
if (result == OK) {
result = skiplist_insert(object_skiplists[SERVICE_SKIPLIST], (void *)new_service);
switch (result) {
case SKIPLIST_ERROR_DUPLICATE:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Service '%s' on host '%s' has already been defined\n", description, host_name);
result = ERROR;
break;
case SKIPLIST_OK:
result = OK;
break;
default:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not add service '%s' on host '%s' to skiplist\n", description, host_name);
result = ERROR;
break;
}
}
/* handle errors */
if (result == ERROR) {
#ifdef NSCORE
my_free(new_service->perf_data);
my_free(new_service->plugin_output);
my_free(new_service->long_plugin_output);
#endif
my_free(new_service->failure_prediction_options);
my_free(new_service->notification_period);
my_free(new_service->event_handler);
my_free(new_service->service_check_command);
my_free(new_service->description);
my_free(new_service->display_name);
my_free(new_service->host_name);
my_free(new_service);
return NULL;
}
/* services are sorted alphabetically, so add new items to tail of list */
if (service_list == NULL) {
service_list = new_service;
service_list_tail = service_list;
} else {
service_list_tail->next = new_service;
service_list_tail = new_service;
}
return new_service;
}
/* adds a contact group to a service */
contactgroupsmember *add_contactgroup_to_service(service *svc, char *group_name) {
contactgroupsmember *new_contactgroupsmember = NULL;
/* bail out if we weren't given the data we need */
if (svc == NULL || (group_name == NULL || !strcmp(group_name, ""))) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Service or contactgroup name is NULL\n");
return NULL;
}
/* allocate memory for the contactgroups member */
if ((new_contactgroupsmember = calloc(1, sizeof(contactgroupsmember))) == NULL)
return NULL;
/* duplicate vars */
if ((new_contactgroupsmember->group_name = (char *)strdup(group_name)) == NULL) {
my_free(new_contactgroupsmember->group_name);
my_free(new_contactgroupsmember);
return NULL;
}
/* add this contactgroup to the service */
new_contactgroupsmember->next = svc->contact_groups;
svc->contact_groups = new_contactgroupsmember;
return new_contactgroupsmember;
}
/* adds a contact to a service */
contactsmember *add_contact_to_service(service *svc, char *contact_name) {
return add_contact_to_object(&svc->contacts, contact_name);
}
/* adds a custom variable to a service */
customvariablesmember *add_custom_variable_to_service(service *svc, char *varname, char *varvalue) {
return add_custom_variable_to_object(&svc->custom_variables, varname, varvalue);
}
/* add a new command to the list in memory */
command *add_command(char *name, char *value) {
command *new_command = NULL;
int result = OK;
/* make sure we have the data we need */
if ((name == NULL || !strcmp(name, "")) || (value == NULL || !strcmp(value, ""))) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Command name of command line is NULL\n");
return NULL;
}
/* allocate memory for the new command */
if ((new_command = (command *)calloc(1, sizeof(command))) == NULL)
return NULL;
/* duplicate vars */
if ((new_command->name = (char *)strdup(name)) == NULL)
result = ERROR;
if ((new_command->command_line = (char *)strdup(value)) == NULL)
result = ERROR;
/* add new command to skiplist */
if (result == OK) {
result = skiplist_insert(object_skiplists[COMMAND_SKIPLIST], (void *)new_command);
switch (result) {
case SKIPLIST_ERROR_DUPLICATE:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Command '%s' has already been defined\n", name);
result = ERROR;
break;
case SKIPLIST_OK:
result = OK;
break;
default:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not add command '%s' to skiplist\n", name);
result = ERROR;
break;
}
}
/* handle errors */
if (result == ERROR) {
my_free(new_command->command_line);
my_free(new_command->name);
my_free(new_command);
return NULL;
}
/* commands are sorted alphabetically, so add new items to tail of list */
if (command_list == NULL) {
command_list = new_command;
command_list_tail = command_list;
} else {
command_list_tail->next = new_command;
command_list_tail = new_command;
}
return new_command;
}
/* add a new service escalation to the list in memory */
serviceescalation *add_serviceescalation(char *host_name, char *description, int first_notification, int last_notification, int first_warning_notification, int last_warning_notification, int first_critical_notification, int last_critical_notification, int first_unknown_notification, int last_unknown_notification, double notification_interval, char *escalation_period, int escalate_on_warning, int escalate_on_unknown, int escalate_on_critical, int escalate_on_recovery) {
serviceescalation *new_serviceescalation = NULL;
int result = OK;
/* make sure we have the data we need */
if ((host_name == NULL || !strcmp(host_name, "")) || (description == NULL || !strcmp(description, ""))) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Service escalation host name or description is NULL\n");
return NULL;
}
#ifdef TEST
printf("NEW SVC ESCALATION: %s/%s = %d/%d/%.3f\n", host_name, description, first_notification, last_notification, notification_interval);
#endif
/* allocate memory for a new service escalation entry */
if ((new_serviceescalation = calloc(1, sizeof(serviceescalation))) == NULL)
return NULL;
/* duplicate vars */
if ((new_serviceescalation->host_name = (char *)strdup(host_name)) == NULL)
result = ERROR;
if ((new_serviceescalation->description = (char *)strdup(description)) == NULL)
result = ERROR;
if (escalation_period) {
if ((new_serviceescalation->escalation_period = (char *)strdup(escalation_period)) == NULL)
result = ERROR;
}
new_serviceescalation->first_notification = first_notification;
new_serviceescalation->last_notification = last_notification;
/* state based escalation ranges */
new_serviceescalation->first_warning_notification = first_warning_notification;
new_serviceescalation->last_warning_notification = last_warning_notification;
new_serviceescalation->first_critical_notification = first_critical_notification;
new_serviceescalation->last_critical_notification = last_critical_notification;
new_serviceescalation->first_unknown_notification = first_unknown_notification;
new_serviceescalation->last_unknown_notification = last_unknown_notification;
new_serviceescalation->notification_interval = (notification_interval <= 0) ? 0 : notification_interval;
new_serviceescalation->escalate_on_recovery = (escalate_on_recovery > 0) ? TRUE : FALSE;
new_serviceescalation->escalate_on_warning = (escalate_on_warning > 0) ? TRUE : FALSE;
new_serviceescalation->escalate_on_unknown = (escalate_on_unknown > 0) ? TRUE : FALSE;
new_serviceescalation->escalate_on_critical = (escalate_on_critical > 0) ? TRUE : FALSE;
/* add new serviceescalation to skiplist */
if (result == OK) {
result = skiplist_insert(object_skiplists[SERVICEESCALATION_SKIPLIST], (void *)new_serviceescalation);
switch (result) {
case SKIPLIST_OK:
result = OK;
break;
default:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not add escalation for service '%s' on host '%s' to skiplist\n", description, host_name);
result = ERROR;
break;
}
}
/* handle errors */
if (result == ERROR) {
my_free(new_serviceescalation->host_name);
my_free(new_serviceescalation->description);
my_free(new_serviceescalation->escalation_period);
my_free(new_serviceescalation);
return NULL;
}
/* service escalations are sorted alphabetically, so add new items to tail of list */
if (serviceescalation_list == NULL) {
serviceescalation_list = new_serviceescalation;
serviceescalation_list_tail = serviceescalation_list;
} else {
serviceescalation_list_tail->next = new_serviceescalation;
serviceescalation_list_tail = new_serviceescalation;
}
return new_serviceescalation;
}
/* adds a contact group to a service escalation */
contactgroupsmember *add_contactgroup_to_serviceescalation(serviceescalation *se, char *group_name) {
contactgroupsmember *new_contactgroupsmember = NULL;
/* bail out if we weren't given the data we need */
if (se == NULL || (group_name == NULL || !strcmp(group_name, ""))) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Service escalation or contactgroup name is NULL\n");
return NULL;
}
/* allocate memory for the contactgroups member */
if ((new_contactgroupsmember = (contactgroupsmember *)calloc(1, sizeof(contactgroupsmember))) == NULL)
return NULL;
/* duplicate vars */
if ((new_contactgroupsmember->group_name = (char *)strdup(group_name)) == NULL) {
my_free(new_contactgroupsmember->group_name);
my_free(new_contactgroupsmember);
return NULL;
}
/* add this contactgroup to the service escalation */
new_contactgroupsmember->next = se->contact_groups;
se->contact_groups = new_contactgroupsmember;
return new_contactgroupsmember;
}
/* adds a contact to a service escalation */
contactsmember *add_contact_to_serviceescalation(serviceescalation *se, char *contact_name) {
return add_contact_to_object(&se->contacts, contact_name);
}
/* adds a service dependency definition */
servicedependency *add_service_dependency(char *dependent_host_name, char *dependent_service_description, char *host_name, char *service_description, int dependency_type, int inherits_parent, int fail_on_ok, int fail_on_warning, int fail_on_unknown, int fail_on_critical, int fail_on_pending, char *dependency_period) {
servicedependency *new_servicedependency = NULL;
int result = OK;
/* make sure we have what we need */
if ((host_name == NULL || !strcmp(host_name, "")) || (service_description == NULL || !strcmp(service_description, ""))) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: NULL master service description/host name in service dependency definition\n");
return NULL;
}
if ((dependent_host_name == NULL || !strcmp(dependent_host_name, "")) || (dependent_service_description == NULL || !strcmp(dependent_service_description, ""))) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: NULL dependent service description/host name in service dependency definition\n");
return NULL;
}
/* allocate memory for a new service dependency entry */
if ((new_servicedependency = (servicedependency *)calloc(1, sizeof(servicedependency))) == NULL)
return NULL;
/* duplicate vars */
if ((new_servicedependency->dependent_host_name = (char *)strdup(dependent_host_name)) == NULL)
result = ERROR;
if ((new_servicedependency->dependent_service_description = (char *)strdup(dependent_service_description)) == NULL)
result = ERROR;
if ((new_servicedependency->host_name = (char *)strdup(host_name)) == NULL)
result = ERROR;
if ((new_servicedependency->service_description = (char *)strdup(service_description)) == NULL)
result = ERROR;
if (dependency_period) {
if ((new_servicedependency->dependency_period = (char *)strdup(dependency_period)) == NULL)
result = ERROR;
}
new_servicedependency->dependency_type = (dependency_type == EXECUTION_DEPENDENCY) ? EXECUTION_DEPENDENCY : NOTIFICATION_DEPENDENCY;
new_servicedependency->inherits_parent = (inherits_parent > 0) ? TRUE : FALSE;
new_servicedependency->fail_on_ok = (fail_on_ok == 1) ? TRUE : FALSE;
new_servicedependency->fail_on_warning = (fail_on_warning == 1) ? TRUE : FALSE;
new_servicedependency->fail_on_unknown = (fail_on_unknown == 1) ? TRUE : FALSE;
new_servicedependency->fail_on_critical = (fail_on_critical == 1) ? TRUE : FALSE;
new_servicedependency->fail_on_pending = (fail_on_pending == 1) ? TRUE : FALSE;
#ifdef NSCORE
new_servicedependency->circular_path_checked = FALSE;
new_servicedependency->contains_circular_path = FALSE;
#endif
/* add new service dependency to skiplist */
if (result == OK) {
result = skiplist_insert(object_skiplists[SERVICEDEPENDENCY_SKIPLIST], (void *)new_servicedependency);
switch (result) {
case SKIPLIST_OK:
result = OK;
break;
default:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not add service dependency to skiplist\n");
result = ERROR;
break;
}
}
/* handle errors */
if (result == ERROR) {
my_free(new_servicedependency->host_name);
my_free(new_servicedependency->service_description);
my_free(new_servicedependency->dependent_host_name);
my_free(new_servicedependency->dependent_service_description);
my_free(new_servicedependency);
return NULL;
}
/* service dependencies are sorted alphabetically, so add new items to tail of list */
if (servicedependency_list == NULL) {
servicedependency_list = new_servicedependency;
servicedependency_list_tail = servicedependency_list;
} else {
servicedependency_list_tail->next = new_servicedependency;
servicedependency_list_tail = new_servicedependency;
}
return new_servicedependency;
}
/* adds a host dependency definition */
hostdependency *add_host_dependency(char *dependent_host_name, char *host_name, int dependency_type, int inherits_parent, int fail_on_up, int fail_on_down, int fail_on_unreachable, int fail_on_pending, char *dependency_period) {
hostdependency *new_hostdependency = NULL;
int result = OK;
/* make sure we have what we need */
if ((dependent_host_name == NULL || !strcmp(dependent_host_name, "")) || (host_name == NULL || !strcmp(host_name, ""))) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: NULL host name in host dependency definition\n");
return NULL;
}
/* allocate memory for a new host dependency entry */
if ((new_hostdependency = (hostdependency *)calloc(1, sizeof(hostdependency))) == NULL)
return NULL;
/* duplicate vars */
if ((new_hostdependency->dependent_host_name = (char *)strdup(dependent_host_name)) == NULL)
result = ERROR;
if ((new_hostdependency->host_name = (char *)strdup(host_name)) == NULL)
result = ERROR;
if (dependency_period) {
if ((new_hostdependency->dependency_period = (char *)strdup(dependency_period)) == NULL)
result = ERROR;
}
new_hostdependency->dependency_type = (dependency_type == EXECUTION_DEPENDENCY) ? EXECUTION_DEPENDENCY : NOTIFICATION_DEPENDENCY;
new_hostdependency->inherits_parent = (inherits_parent > 0) ? TRUE : FALSE;
new_hostdependency->fail_on_up = (fail_on_up == 1) ? TRUE : FALSE;
new_hostdependency->fail_on_down = (fail_on_down == 1) ? TRUE : FALSE;
new_hostdependency->fail_on_unreachable = (fail_on_unreachable == 1) ? TRUE : FALSE;
new_hostdependency->fail_on_pending = (fail_on_pending == 1) ? TRUE : FALSE;
#ifdef NSCORE
new_hostdependency->circular_path_checked = FALSE;
new_hostdependency->contains_circular_path = FALSE;
#endif
/* add new host dependency to skiplist */
if (result == OK) {
result = skiplist_insert(object_skiplists[HOSTDEPENDENCY_SKIPLIST], (void *)new_hostdependency);
switch (result) {
case SKIPLIST_OK:
result = OK;
break;
default:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not add host dependency to skiplist\n");
result = ERROR;
break;
}
}
/* handle errors */
if (result == ERROR) {
my_free(new_hostdependency->host_name);
my_free(new_hostdependency->dependent_host_name);
my_free(new_hostdependency);
return NULL;
}
/* host dependencies are sorted alphabetically, so add new items to tail of list */
if (hostdependency_list == NULL) {
hostdependency_list = new_hostdependency;
hostdependency_list_tail = hostdependency_list;
} else {
hostdependency_list_tail->next = new_hostdependency;
hostdependency_list_tail = new_hostdependency;
}
return new_hostdependency;
}
/* add a new host escalation to the list in memory */
hostescalation *add_hostescalation(char *host_name, int first_notification, int last_notification, int first_down_notification, int last_down_notification, int first_unreachable_notification, int last_unreachable_notification, double notification_interval, char *escalation_period, int escalate_on_down, int escalate_on_unreachable, int escalate_on_recovery) {
hostescalation *new_hostescalation = NULL;
int result = OK;
/* make sure we have the data we need */
if (host_name == NULL || !strcmp(host_name, "")) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Host escalation host name is NULL\n");
return NULL;
}
#ifdef TEST
printf("NEW HST ESCALATION: %s = %d/%d/%.3f\n", host_name, first_notification, last_notification, notification_interval);
#endif
/* allocate memory for a new host escalation entry */
if ((new_hostescalation = calloc(1, sizeof(hostescalation))) == NULL)
return NULL;
/* duplicate vars */
if ((new_hostescalation->host_name = (char *)strdup(host_name)) == NULL)
result = ERROR;
if (escalation_period) {
if ((new_hostescalation->escalation_period = (char *)strdup(escalation_period)) == NULL)
result = ERROR;
}
new_hostescalation->first_notification = first_notification;
new_hostescalation->last_notification = last_notification;
/* state based escalation ranges */
new_hostescalation->first_down_notification = first_down_notification;
new_hostescalation->last_down_notification = last_down_notification;
new_hostescalation->first_unreachable_notification = first_unreachable_notification;
new_hostescalation->last_unreachable_notification = last_unreachable_notification;
new_hostescalation->notification_interval = (notification_interval <= 0) ? 0 : notification_interval;
new_hostescalation->escalate_on_recovery = (escalate_on_recovery > 0) ? TRUE : FALSE;
new_hostescalation->escalate_on_down = (escalate_on_down > 0) ? TRUE : FALSE;
new_hostescalation->escalate_on_unreachable = (escalate_on_unreachable > 0) ? TRUE : FALSE;
/* add new hostescalation to skiplist */
if (result == OK) {
result = skiplist_insert(object_skiplists[HOSTESCALATION_SKIPLIST], (void *)new_hostescalation);
switch (result) {
case SKIPLIST_OK:
result = OK;
break;
default:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not add hostescalation '%s' to skiplist\n", host_name);
result = ERROR;
break;
}
}
/* handle errors */
if (result == ERROR) {
my_free(new_hostescalation->host_name);
my_free(new_hostescalation->escalation_period);
my_free(new_hostescalation);
return NULL;
}
/* host escalations are sorted alphabetically, so add new items to tail of list */
if (hostescalation_list == NULL) {
hostescalation_list = new_hostescalation;
hostescalation_list_tail = hostescalation_list;
} else {
hostescalation_list_tail->next = new_hostescalation;
hostescalation_list_tail = new_hostescalation;
}
return new_hostescalation;
}
/* add a condition to a (host or service) escalation in memory */
escalation_condition *add_host_service_escalation_condition(hostescalation *my_hostescalation, serviceescalation *my_serviceescalation, escalation_condition *last_condition, char *host_name, char *service_description, int connector, int escalate_on_down, int escalate_on_unreachable, int escalate_on_warning, int escalate_on_unknown, int escalate_on_critical, int escalate_on_ok) {
escalation_condition *new_escalation_condition = NULL;
int result = OK;
/* make sure we have the data we need */
if (host_name == NULL || !strcmp(host_name, "")) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: escalation condition: host name is NULL\n");
return NULL;
}
#ifdef TEST
printf("NEW ESCALATION CONDITION: host = %s; service = %s; connector = %d/\n", host_name, service_description, connector);
#endif
/* remove whitespaces */
strip(host_name);
strip(service_description);
/* allocate memory for a new escalation_condition entry */
if ((new_escalation_condition = malloc(sizeof(escalation_condition))) == NULL)
return NULL;
/* initialize vars */
new_escalation_condition->host_name = NULL;
new_escalation_condition->service_description = NULL;
new_escalation_condition->next = NULL;
new_escalation_condition->escalate_on_warning = FALSE;
new_escalation_condition->escalate_on_unknown = FALSE;
new_escalation_condition->escalate_on_critical = FALSE;
new_escalation_condition->escalate_on_ok = FALSE;
new_escalation_condition->escalate_on_down = FALSE;
new_escalation_condition->escalate_on_unreachable = FALSE;
/* service condition */
if (service_description != NULL && strcmp(service_description, "")
&& host_name != NULL && strcmp(host_name, "")) {
if ((new_escalation_condition->host_name = (char *)strdup(host_name)) == NULL)
result = ERROR;
if ((new_escalation_condition->service_description = (char *)strdup(service_description)) == NULL)
result = ERROR;
new_escalation_condition->escalate_on_warning = (escalate_on_warning > 0) ? TRUE : FALSE;
new_escalation_condition->escalate_on_unknown = (escalate_on_unknown > 0) ? TRUE : FALSE;
new_escalation_condition->escalate_on_critical = (escalate_on_critical > 0) ? TRUE : FALSE;
new_escalation_condition->escalate_on_ok = (escalate_on_ok > 0) ? TRUE : FALSE;
}
/* host condition */
else if (host_name != NULL && strcmp(host_name, "")) {
if ((new_escalation_condition->host_name = (char *)strdup(host_name)) == NULL)
result = ERROR;
new_escalation_condition->escalate_on_down = (escalate_on_down > 0) ? TRUE : FALSE;
new_escalation_condition->escalate_on_unreachable = (escalate_on_unreachable > 0) ? TRUE : FALSE;
new_escalation_condition->escalate_on_ok = (escalate_on_ok > 0) ? TRUE : FALSE;
}
/* connector to next condition */
new_escalation_condition->connector = (connector >= 0 && connector <= 2) ? connector : EC_CONNECTOR_NO;
/* handle errors */
if (result == ERROR) {
my_free(new_escalation_condition->host_name);
my_free(new_escalation_condition->service_description);
my_free(new_escalation_condition);
return NULL;
}
/* if head of escalation condition is NULL set it to new condition */
if (my_serviceescalation != NULL && my_serviceescalation->condition == NULL) {
my_serviceescalation->condition = new_escalation_condition;
} else if (my_hostescalation != NULL && my_hostescalation->condition == NULL) {
my_hostescalation->condition = new_escalation_condition;
}
/* else add new condition to the tail of condition list */
else {
last_condition->next = new_escalation_condition;
}
return new_escalation_condition;
}
/* add a condition to a host escalation in memory */
escalation_condition *add_hostescalation_condition(hostescalation *my_hostescalation, escalation_condition *last_condition, char *host_name, char *service_description, int connector, int escalate_on_down, int escalate_on_unreachable, int escalate_on_warning, int escalate_on_unknown, int escalate_on_critical, int escalate_on_ok) {
return add_host_service_escalation_condition(my_hostescalation, NULL, last_condition, host_name, service_description, connector, escalate_on_down, escalate_on_unreachable, escalate_on_warning, escalate_on_unknown, escalate_on_critical, escalate_on_ok);
}
/* add a condition to a service escalation in memory */
escalation_condition *add_serviceescalation_condition(serviceescalation *my_serviceescalation, escalation_condition *last_condition, char *host_name, char *service_description, int connector, int escalate_on_down, int escalate_on_unreachable, int escalate_on_warning, int escalate_on_unknown, int escalate_on_critical, int escalate_on_ok) {
return add_host_service_escalation_condition(NULL, my_serviceescalation, last_condition, host_name, service_description, connector, escalate_on_down, escalate_on_unreachable, escalate_on_warning, escalate_on_unknown, escalate_on_critical, escalate_on_ok);
}
/* adds a contact group to a host escalation */
contactgroupsmember *add_contactgroup_to_hostescalation(hostescalation *he, char *group_name) {
contactgroupsmember *new_contactgroupsmember = NULL;
/* bail out if we weren't given the data we need */
if (he == NULL || (group_name == NULL || !strcmp(group_name, ""))) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Host escalation or contactgroup name is NULL\n");
return NULL;
}
/* allocate memory for the contactgroups member */
if ((new_contactgroupsmember = (contactgroupsmember *)calloc(1, sizeof(contactgroupsmember))) == NULL)
return NULL;
/* duplicate vars */
if ((new_contactgroupsmember->group_name = (char *)strdup(group_name)) == NULL) {
my_free(new_contactgroupsmember->group_name);
my_free(new_contactgroupsmember);
return NULL;
}
/* add this contactgroup to the host escalation */
new_contactgroupsmember->next = he->contact_groups;
he->contact_groups = new_contactgroupsmember;
return new_contactgroupsmember;
}
/* adds a contact to a host escalation */
contactsmember *add_contact_to_hostescalation(hostescalation *he, char *contact_name) {
return add_contact_to_object(&he->contacts, contact_name);
}
/* adds a contact to an object */
contactsmember *add_contact_to_object(contactsmember **object_ptr, char *contactname) {
contactsmember *new_contactsmember = NULL;
/* make sure we have the data we need */
if (object_ptr == NULL) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Contact object is NULL\n");
return NULL;
}
if (contactname == NULL || !strcmp(contactname, "")) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Contact name is NULL\n");
return NULL;
}
/* allocate memory for a new member */
if ((new_contactsmember = malloc(sizeof(contactsmember))) == NULL) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not allocate memory for contact\n");
return NULL;
}
if ((new_contactsmember->contact_name = (char *)strdup(contactname)) == NULL) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not allocate memory for contact name\n");
my_free(new_contactsmember);
return NULL;
}
/* set initial values */
#ifdef NSCORE
new_contactsmember->contact_ptr = NULL;
#endif
/* add the new contact to the head of the contact list */
new_contactsmember->next = *object_ptr;
*object_ptr = new_contactsmember;
return new_contactsmember;
}
/* adds a custom variable to an object */
customvariablesmember *add_custom_variable_to_object(customvariablesmember **object_ptr, char *varname, char *varvalue) {
customvariablesmember *new_customvariablesmember = NULL;
/* make sure we have the data we need */
if (object_ptr == NULL) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Custom variable object is NULL\n");
return NULL;
}
if (varname == NULL || !strcmp(varname, "")) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Custom variable name is NULL\n");
return NULL;
}
/* allocate memory for a new member */
if ((new_customvariablesmember = malloc(sizeof(customvariablesmember))) == NULL) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not allocate memory for custom variable\n");
return NULL;
}
if ((new_customvariablesmember->variable_name = (char *)strdup(varname)) == NULL) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not allocate memory for custom variable name\n");
my_free(new_customvariablesmember);
return NULL;
}
if (varvalue) {
if ((new_customvariablesmember->variable_value = (char *)strdup(varvalue)) == NULL) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not allocate memory for custom variable value\n");
my_free(new_customvariablesmember->variable_name);
my_free(new_customvariablesmember);
return NULL;
}
} else
new_customvariablesmember->variable_value = NULL;
/* set initial values */
new_customvariablesmember->has_been_modified = FALSE;
/* add the new member to the head of the member list */
new_customvariablesmember->next = *object_ptr;
*object_ptr = new_customvariablesmember;
return new_customvariablesmember;
}
/* add a new module to the list in memory */
module *add_module(char *name, char *type, char *path, char *args) {
module *new_module = NULL;
int result = OK;
/* make sure we have the data we need */
if ((name == NULL || !strcmp(name, "")) || (path == NULL || !strcmp(path, ""))) {
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Module name or path is NULL\n");
return NULL;
}
/* allocate memory for the new module */
if ((new_module = (module *)calloc(1, sizeof(module))) == NULL)
return NULL;
/* duplicate vars */
if ((new_module->name = (char *)strdup(name)) == NULL)
result = ERROR;
if ((new_module->type = (char *)strdup(type)) == NULL)
result = ERROR;
if ((new_module->path = (char *)strdup(path)) == NULL)
result = ERROR;
if ((new_module->args = (char *)strdup(args)) == NULL)
result = ERROR;
/* add new command to skiplist */
if (result == OK) {
result = skiplist_insert(object_skiplists[MODULE_SKIPLIST], (void *)new_module);
switch (result) {
case SKIPLIST_ERROR_DUPLICATE:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Module '%s' has already been defined\n", name);
result = ERROR;
break;
case SKIPLIST_OK:
result = OK;
break;
default:
logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not add module '%s' to skiplist\n", name);
result = ERROR;
break;
}
}
/* handle errors */
if (result == ERROR) {
my_free(new_module->args);
my_free(new_module->path);
my_free(new_module->type);
my_free(new_module->name);
my_free(new_module);
return NULL;
}
/* modules are sorted alphabetically, so add new items to tail of list */
if (module_list == NULL) {
module_list = new_module;
module_list_tail = module_list;
} else {
module_list_tail->next = new_module;
module_list_tail = new_module;
}
return new_module;
}
#ifdef NSCORE
int add_module_objects_to_neb(void) {
module *temp_module;
int total_objects = 0;
for (temp_module = module_list, total_objects = 0; temp_module != NULL; temp_module = temp_module->next, total_objects++) {
/* just an idea to re-use the type a bit better - MF 2011-04-30 FIXME */
//if!strcmp(temp_module->module_type,"neb"){
#ifdef USE_EVENT_BROKER
neb_add_module(temp_module->path, temp_module->args, TRUE);
#endif
//}
}
return OK;
}
#endif
/******************************************************************/
/******************** OBJECT SEARCH FUNCTIONS *********************/
/******************************************************************/
/* given a timeperiod name and a starting point, find a timeperiod from the list in memory */
timeperiod * find_timeperiod(char *name) {
timeperiod temp_timeperiod;
if (name == NULL)
return NULL;
temp_timeperiod.name = name;
return skiplist_find_first(object_skiplists[TIMEPERIOD_SKIPLIST], &temp_timeperiod, NULL);
}
/* given a host name, find it in the list in memory */
host * find_host(char *name) {
host temp_host;
if (name == NULL)
return NULL;
temp_host.name = name;
return skiplist_find_first(object_skiplists[HOST_SKIPLIST], &temp_host, NULL);
}
/* find a hostgroup from the list in memory */
hostgroup * find_hostgroup(char *name) {
hostgroup temp_hostgroup;
if (name == NULL)
return NULL;
temp_hostgroup.group_name = name;
return skiplist_find_first(object_skiplists[HOSTGROUP_SKIPLIST], &temp_hostgroup, NULL);
}
/* find a servicegroup from the list in memory */
servicegroup * find_servicegroup(char *name) {
servicegroup temp_servicegroup;
if (name == NULL)
return NULL;
temp_servicegroup.group_name = name;
return skiplist_find_first(object_skiplists[SERVICEGROUP_SKIPLIST], &temp_servicegroup, NULL);
}
/* find a contact from the list in memory */
contact * find_contact(char *name) {
contact temp_contact;
if (name == NULL)
return NULL;
temp_contact.name = name;
return skiplist_find_first(object_skiplists[CONTACT_SKIPLIST], &temp_contact, NULL);
}
/* find a contact group from the list in memory */
contactgroup * find_contactgroup(char *name) {
contactgroup temp_contactgroup;
if (name == NULL)
return NULL;
temp_contactgroup.group_name = name;
return skiplist_find_first(object_skiplists[CONTACTGROUP_SKIPLIST], &temp_contactgroup, NULL);
}
/* given a command name, find a command from the list in memory */
command * find_command(char *name) {
command temp_command;
if (name == NULL)
return NULL;
temp_command.name = name;
return skiplist_find_first(object_skiplists[COMMAND_SKIPLIST], &temp_command, NULL);
}
/* given a host/service name, find the service in the list in memory */
service * find_service(char *host_name, char *svc_desc) {
service temp_service;
if (host_name == NULL || svc_desc == NULL)
return NULL;
temp_service.host_name = host_name;
temp_service.description = svc_desc;
return skiplist_find_first(object_skiplists[SERVICE_SKIPLIST], &temp_service, NULL);
}
/* given a module name, find a module from the list in memory */
module * find_module(char *name) {
module temp_module;
if (name == NULL)
return NULL;
temp_module.name = name;
return skiplist_find_first(object_skiplists[MODULE_SKIPLIST], &temp_module, NULL);
}
/******************************************************************/
/******************* OBJECT TRAVERSAL FUNCTIONS *******************/
/******************************************************************/
hostescalation *get_first_hostescalation_by_host(char *host_name, void **ptr) {
hostescalation temp_hostescalation;
if (host_name == NULL)
return NULL;
temp_hostescalation.host_name = host_name;
return skiplist_find_first(object_skiplists[HOSTESCALATION_SKIPLIST], &temp_hostescalation, ptr);
}
hostescalation *get_next_hostescalation_by_host(char *host_name, void **ptr) {
hostescalation temp_hostescalation;
if (host_name == NULL)
return NULL;
temp_hostescalation.host_name = host_name;
return skiplist_find_next(object_skiplists[HOSTESCALATION_SKIPLIST], &temp_hostescalation, ptr);
}
serviceescalation *get_first_serviceescalation_by_service(char *host_name, char *svc_description, void **ptr) {
serviceescalation temp_serviceescalation;
if (host_name == NULL || svc_description == NULL)
return NULL;
temp_serviceescalation.host_name = host_name;
temp_serviceescalation.description = svc_description;
return skiplist_find_first(object_skiplists[SERVICEESCALATION_SKIPLIST], &temp_serviceescalation, ptr);
}
serviceescalation *get_next_serviceescalation_by_service(char *host_name, char *svc_description, void **ptr) {
serviceescalation temp_serviceescalation;
if (host_name == NULL || svc_description == NULL)
return NULL;
temp_serviceescalation.host_name = host_name;
temp_serviceescalation.description = svc_description;
return skiplist_find_next(object_skiplists[SERVICEESCALATION_SKIPLIST], &temp_serviceescalation, ptr);
}
hostdependency *get_first_hostdependency_by_dependent_host(char *host_name, void **ptr) {
hostdependency temp_hostdependency;
if (host_name == NULL)
return NULL;
temp_hostdependency.dependent_host_name = host_name;
return skiplist_find_first(object_skiplists[HOSTDEPENDENCY_SKIPLIST], &temp_hostdependency, ptr);
}
hostdependency *get_next_hostdependency_by_dependent_host(char *host_name, void **ptr) {
hostdependency temp_hostdependency;
if (host_name == NULL || ptr == NULL)
return NULL;
temp_hostdependency.dependent_host_name = host_name;
return skiplist_find_next(object_skiplists[HOSTDEPENDENCY_SKIPLIST], &temp_hostdependency, ptr);
}
servicedependency *get_first_servicedependency_by_dependent_service(char *host_name, char *svc_description, void **ptr) {
servicedependency temp_servicedependency;
if (host_name == NULL || svc_description == NULL)
return NULL;
temp_servicedependency.dependent_host_name = host_name;
temp_servicedependency.dependent_service_description = svc_description;
return skiplist_find_first(object_skiplists[SERVICEDEPENDENCY_SKIPLIST], &temp_servicedependency, ptr);
}
servicedependency *get_next_servicedependency_by_dependent_service(char *host_name, char *svc_description, void **ptr) {
servicedependency temp_servicedependency;
if (host_name == NULL || svc_description == NULL || ptr == NULL)
return NULL;
temp_servicedependency.dependent_host_name = host_name;
temp_servicedependency.dependent_service_description = svc_description;
return skiplist_find_next(object_skiplists[SERVICEDEPENDENCY_SKIPLIST], &temp_servicedependency, ptr);
return NULL;
}
#ifdef NSCORE
/* adds a object to a list of objects */
int add_object_to_objectlist(objectlist **list, void *object_ptr) {
objectlist *temp_item = NULL;
objectlist *new_item = NULL;
if (list == NULL || object_ptr == NULL)
return ERROR;
/* skip this object if its already in the list */
for (temp_item = *list; temp_item; temp_item = temp_item->next) {
if (temp_item->object_ptr == object_ptr)
break;
}
if (temp_item)
return OK;
/* allocate memory for a new list item */
if ((new_item = (objectlist *)malloc(sizeof(objectlist))) == NULL)
return ERROR;
/* initialize vars */
new_item->object_ptr = object_ptr;
/* add new item to head of list */
new_item->next = *list;
*list = new_item;
return OK;
}
/* frees memory allocated to a temporary object list */
int free_objectlist(objectlist **temp_list) {
objectlist *this_objectlist = NULL;
objectlist *next_objectlist = NULL;
if (temp_list == NULL)
return ERROR;
/* free memory allocated to object list */
for (this_objectlist = *temp_list; this_objectlist != NULL; this_objectlist = next_objectlist) {
next_objectlist = this_objectlist->next;
my_free(this_objectlist);
}
*temp_list = NULL;
return OK;
}
#endif
/******************************************************************/
/********************* OBJECT QUERY FUNCTIONS *********************/
/******************************************************************/
/* determines whether or not a specific host is an immediate child of another host */
int is_host_immediate_child_of_host(host *parent_host, host *child_host) {
hostsmember *temp_hostsmember = NULL;
/* not enough data */
if (child_host == NULL)
return FALSE;
/* root/top-level hosts */
if (parent_host == NULL) {
if (child_host->parent_hosts == NULL)
return TRUE;
}
/* mid-level/bottom hosts */
else {
for (temp_hostsmember = child_host->parent_hosts; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
#ifdef NSCORE
if (temp_hostsmember->host_ptr == parent_host)
return TRUE;
#else
if (!CMP_HASH(temp_hostsmember->host_name, parent_host->name))
return TRUE;
#endif
}
}
return FALSE;
}
/* determines whether or not a specific host is an immediate parent of another host */
int is_host_immediate_parent_of_host(host *child_host, host *parent_host) {
if (is_host_immediate_child_of_host(parent_host, child_host) == TRUE)
return TRUE;
return FALSE;
}
/* returns a count of the immediate children for a given host */
/* NOTE: This function is only used by the CGIS */
int number_of_immediate_child_hosts(host *hst) {
int children = 0;
host *temp_host = NULL;
for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
if (is_host_immediate_child_of_host(hst, temp_host) == TRUE)
children++;
}
return children;
}
/* returns a count of the total children for a given host */
/* NOTE: This function is only used by the CGIS */
int number_of_total_child_hosts(host *hst) {
int children = 0;
host *temp_host = NULL;
for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
if (is_host_immediate_child_of_host(hst, temp_host) == TRUE)
children += number_of_total_child_hosts(temp_host) + 1;
}
return children;
}
/* get the number of immediate parent hosts for a given host */
/* NOTE: This function is only used by the CGIS */
int number_of_immediate_parent_hosts(host *hst) {
int parents = 0;
host *temp_host = NULL;
for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
if (is_host_immediate_parent_of_host(hst, temp_host) == TRUE) {
parents++;
}
}
return parents;
}
/* get the total number of parent hosts for a given host */
/* NOTE: This function is only used by the CGIS */
int number_of_total_parent_hosts(host *hst) {
int parents = 0;
host *temp_host = NULL;
for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
if (is_host_immediate_parent_of_host(hst, temp_host) == TRUE) {
parents += number_of_total_parent_hosts(temp_host) + 1;
}
}
return parents;
}
/* tests whether a host is a member of a particular hostgroup */
/* NOTE: This function is only used by the CGIS */
int is_host_member_of_hostgroup(hostgroup *group, host *hst) {
hostsmember *temp_hostsmember = NULL;
if (group == NULL || hst == NULL)
return FALSE;
for (temp_hostsmember = group->members; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
#ifdef NSCORE
if (temp_hostsmember->host_ptr == hst)
return TRUE;
#else
if (!CMP_HASH(temp_hostsmember->host_name, hst->name))
return TRUE;
#endif
}
return FALSE;
}
/* tests whether a host is a member of a particular servicegroup */
/* NOTE: This function is only used by the CGIS */
int is_host_member_of_servicegroup(servicegroup *group, host *hst) {
servicesmember *temp_servicesmember = NULL;
if (group == NULL || hst == NULL)
return FALSE;
for (temp_servicesmember = group->members; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) {
#ifdef NSCORE
if (temp_servicesmember->service_ptr != NULL && temp_servicesmember->service_ptr->host_ptr == hst)
return TRUE;
#else
if (!CMP_HASH(temp_servicesmember->host_name, hst->name))
return TRUE;
#endif
}
return FALSE;
}
/* tests whether a service is a member of a particular servicegroup */
/* NOTE: This function is only used by the CGIS */
int is_service_member_of_servicegroup(servicegroup *group, service *svc) {
servicesmember *temp_servicesmember = NULL;
if (group == NULL || svc == NULL)
return FALSE;
for (temp_servicesmember = group->members; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) {
#ifdef NSCORE
if (temp_servicesmember->service_ptr == svc)
return TRUE;
#else
if (!CMP_HASH(temp_servicesmember->host_name, svc->host_name) && !CMP_HASH(temp_servicesmember->service_description, svc->description))
return TRUE;
#endif
}
return FALSE;
}
/* 06/14/10 MF all 3 functions mandatory for mk_livestatus */
/* tests whether a contact is a member of a particular contactgroup - used only by the CGIs */
int is_contact_member_of_contactgroup(contactgroup *group, contact *cntct) {
contactsmember *member;
contact *temp_contact = NULL;
if (!group || !cntct)
return FALSE;
/* search all contacts in this contact group */
for (member = group->members; member; member = member->next) {
#ifdef NSCORE
temp_contact = member->contact_ptr;
#else
temp_contact = find_contact(member->contact_name);
#endif
if (temp_contact == NULL)
continue;
if (temp_contact == cntct)
return TRUE;
}
return FALSE;
}
/* tests whether a contact is a contact for a particular host */
int is_contact_for_host(host *hst, contact *cntct) {
contactsmember *temp_contactsmember = NULL;
contact *temp_contact = NULL;
contactgroupsmember *temp_contactgroupsmember = NULL;
contactgroup *temp_contactgroup = NULL;
if (hst == NULL || cntct == NULL) {
return FALSE;
}
/* search all individual contacts of this host */
for (temp_contactsmember = hst->contacts; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) {
#ifdef NSCORE
temp_contact = temp_contactsmember->contact_ptr;
#else
temp_contact = find_contact(temp_contactsmember->contact_name);
#endif
if (temp_contact == NULL)
continue;
if (temp_contact == cntct)
return TRUE;
}
/* search all contactgroups of this host */
for (temp_contactgroupsmember = hst->contact_groups; temp_contactgroupsmember != NULL; temp_contactgroupsmember = temp_contactgroupsmember->next) {
#ifdef NSCORE
temp_contactgroup = temp_contactgroupsmember->group_ptr;
#else
temp_contactgroup = find_contactgroup(temp_contactgroupsmember->group_name);
#endif
if (temp_contactgroup == NULL)
continue;
if (is_contact_member_of_contactgroup(temp_contactgroup, cntct))
return TRUE;
}
return FALSE;
}
/* tests whether or not a contact is an escalated contact for a particular host */
int is_escalated_contact_for_host(host *hst, contact *cntct) {
contactsmember *temp_contactsmember = NULL;
contact *temp_contact = NULL;
hostescalation *temp_hostescalation = NULL;
contactgroupsmember *temp_contactgroupsmember = NULL;
contactgroup *temp_contactgroup = NULL;
void *ptr = NULL;
/* search all host escalations */
for (temp_hostescalation = get_first_hostescalation_by_host(hst->name, &ptr); temp_hostescalation != NULL; temp_hostescalation = get_next_hostescalation_by_host(hst->name, &ptr)) {
/* search all contacts of this host escalation */
for (temp_contactsmember = temp_hostescalation->contacts; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) {
#ifdef NSCORE
temp_contact = temp_contactsmember->contact_ptr;
#else
temp_contact = find_contact(temp_contactsmember->contact_name);
#endif
if (temp_contact == NULL)
continue;
if (temp_contact == cntct)
return TRUE;
}
/* search all contactgroups of this host escalation */
for (temp_contactgroupsmember = temp_hostescalation->contact_groups; temp_contactgroupsmember != NULL; temp_contactgroupsmember = temp_contactgroupsmember->next) {
#ifdef NSCORE
temp_contactgroup = temp_contactgroupsmember->group_ptr;
#else
temp_contactgroup = find_contactgroup(temp_contactgroupsmember->group_name);
#endif
if (temp_contactgroup == NULL)
continue;
if (is_contact_member_of_contactgroup(temp_contactgroup, cntct))
return TRUE;
}
}
return FALSE;
}
/* tests whether a contact is a contact for a particular service */
int is_contact_for_service(service *svc, contact *cntct) {
contactsmember *temp_contactsmember = NULL;
contact *temp_contact = NULL;
contactgroupsmember *temp_contactgroupsmember = NULL;
contactgroup *temp_contactgroup = NULL;
if (svc == NULL || cntct == NULL)
return FALSE;
/* search all individual contacts of this service */
for (temp_contactsmember = svc->contacts; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) {
#ifdef NSCORE
temp_contact = temp_contactsmember->contact_ptr;
#else
temp_contact = find_contact(temp_contactsmember->contact_name);
#endif
if (temp_contact == cntct)
return TRUE;
}
/* search all contactgroups of this service */
for (temp_contactgroupsmember = svc->contact_groups; temp_contactgroupsmember != NULL; temp_contactgroupsmember = temp_contactgroupsmember->next) {
#ifdef NSCORE
temp_contactgroup = temp_contactgroupsmember->group_ptr;
#else
temp_contactgroup = find_contactgroup(temp_contactgroupsmember->group_name);
#endif
if (temp_contactgroup == NULL)
continue;
if (is_contact_member_of_contactgroup(temp_contactgroup, cntct))
return TRUE;
}
return FALSE;
}
/* tests whether or not a contact is an escalated contact for a particular service */
int is_escalated_contact_for_service(service *svc, contact *cntct) {
serviceescalation *temp_serviceescalation = NULL;
contactsmember *temp_contactsmember = NULL;
contact *temp_contact = NULL;
contactgroupsmember *temp_contactgroupsmember = NULL;
contactgroup *temp_contactgroup = NULL;
void *ptr = NULL;
/* search all the service escalations */
for (temp_serviceescalation = get_first_serviceescalation_by_service(svc->host_name, svc->description, &ptr); temp_serviceescalation != NULL; temp_serviceescalation = get_next_serviceescalation_by_service(svc->host_name, svc->description, &ptr)) {
/* search all contacts of this service escalation */
for (temp_contactsmember = temp_serviceescalation->contacts; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) {
#ifdef NSCORE
temp_contact = temp_contactsmember->contact_ptr;
#else
temp_contact = find_contact(temp_contactsmember->contact_name);
#endif
if (temp_contact == NULL)
continue;
if (temp_contact == cntct)
return TRUE;
}
/* search all contactgroups of this service escalation */
for (temp_contactgroupsmember = temp_serviceescalation->contact_groups; temp_contactgroupsmember != NULL; temp_contactgroupsmember = temp_contactgroupsmember->next) {
#ifdef NSCORE
temp_contactgroup = temp_contactgroupsmember->group_ptr;
#else
temp_contactgroup = find_contactgroup(temp_contactgroupsmember->group_name);
#endif
if (temp_contactgroup == NULL)
continue;
if (is_contact_member_of_contactgroup(temp_contactgroup, cntct))
return TRUE;
}
}
return FALSE;
}
#ifdef NSCORE
/* checks to see if there exists a circular dependency for a service */
int check_for_circular_servicedependency_path(servicedependency *root_dep, servicedependency *dep, int dependency_type) {
servicedependency *temp_sd = NULL;
if (root_dep == NULL || dep == NULL)
return FALSE;
/* this is not the proper dependency type */
if (root_dep->dependency_type != dependency_type || dep->dependency_type != dependency_type)
return FALSE;
/* don't go into a loop, don't bother checking anymore if we know this dependency already has a loop */
if (root_dep->contains_circular_path == TRUE)
return TRUE;
/* dependency has already been checked - there is a path somewhere, but it may not be for this particular dep... */
/* this should speed up detection for some loops */
if (dep->circular_path_checked == TRUE)
return FALSE;
/* set the check flag so we don't get into an infinite loop */
dep->circular_path_checked = TRUE;
/* is this service dependent on the root service? */
if (dep != root_dep) {
if (root_dep->dependent_service_ptr == dep->master_service_ptr) {
root_dep->contains_circular_path = TRUE;
dep->contains_circular_path = TRUE;
return TRUE;
}
}
/* notification dependencies are ok at this point as long as they don't inherit */
if (dependency_type == NOTIFICATION_DEPENDENCY && dep->inherits_parent == FALSE)
return FALSE;
/* check all parent dependencies */
for (temp_sd = servicedependency_list; temp_sd != NULL; temp_sd = temp_sd->next) {
/* only check parent dependencies */
if (dep->master_service_ptr != temp_sd->dependent_service_ptr)
continue;
if (check_for_circular_servicedependency_path(root_dep, temp_sd, dependency_type) == TRUE)
return TRUE;
}
return FALSE;
}
/* checks to see if there exists a circular dependency for a host */
int check_for_circular_hostdependency_path(hostdependency *root_dep, hostdependency *dep, int dependency_type) {
hostdependency *temp_hd = NULL;
if (root_dep == NULL || dep == NULL)
return FALSE;
/* this is not the proper dependency type */
if (root_dep->dependency_type != dependency_type || dep->dependency_type != dependency_type)
return FALSE;
/* don't go into a loop, don't bother checking anymore if we know this dependency already has a loop */
if (root_dep->contains_circular_path == TRUE)
return TRUE;
/* dependency has already been checked - there is a path somewhere, but it may not be for this particular dep... */
/* this should speed up detection for some loops */
if (dep->circular_path_checked == TRUE)
return FALSE;
/* set the check flag so we don't get into an infinite loop */
dep->circular_path_checked = TRUE;
/* is this host dependent on the root host? */
if (dep != root_dep) {
if (root_dep->dependent_host_ptr == dep->master_host_ptr) {
root_dep->contains_circular_path = TRUE;
dep->contains_circular_path = TRUE;
return TRUE;
}
}
/* notification dependencies are ok at this point as long as they don't inherit */
if (dependency_type == NOTIFICATION_DEPENDENCY && dep->inherits_parent == FALSE)
return FALSE;
/* check all parent dependencies */
for (temp_hd = hostdependency_list; temp_hd != NULL; temp_hd = temp_hd->next) {
/* only check parent dependencies */
if (dep->master_host_ptr != temp_hd->dependent_host_ptr)
continue;
if (check_for_circular_hostdependency_path(root_dep, temp_hd, dependency_type) == TRUE)
return TRUE;
}
return FALSE;
}
#endif
/******************************************************************/
/******************* OBJECT DELETION FUNCTIONS ********************/
/******************************************************************/
/* free all allocated memory for objects */
int free_object_data(void) {
timeperiod *this_timeperiod = NULL;
timeperiod *next_timeperiod = NULL;
daterange *this_daterange = NULL;
daterange *next_daterange = NULL;
timerange *this_timerange = NULL;
timerange *next_timerange = NULL;
timeperiodexclusion *this_timeperiodexclusion = NULL;
timeperiodexclusion *next_timeperiodexclusion = NULL;
host *this_host = NULL;
host *next_host = NULL;
hostsmember *this_hostsmember = NULL;
hostsmember *next_hostsmember = NULL;
hostgroup *this_hostgroup = NULL;
hostgroup *next_hostgroup = NULL;
servicegroup *this_servicegroup = NULL;
servicegroup *next_servicegroup = NULL;
servicesmember *this_servicesmember = NULL;
servicesmember *next_servicesmember = NULL;
contact *this_contact = NULL;
contact *next_contact = NULL;
contactgroup *this_contactgroup = NULL;
contactgroup *next_contactgroup = NULL;
contactsmember *this_contactsmember = NULL;
contactsmember *next_contactsmember = NULL;
contactgroupsmember *this_contactgroupsmember = NULL;
contactgroupsmember *next_contactgroupsmember = NULL;
customvariablesmember *this_customvariablesmember = NULL;
customvariablesmember *next_customvariablesmember = NULL;
service *this_service = NULL;
service *next_service = NULL;
command *this_command = NULL;
command *next_command = NULL;
commandsmember *this_commandsmember = NULL;
commandsmember *next_commandsmember = NULL;
serviceescalation *this_serviceescalation = NULL;
serviceescalation *next_serviceescalation = NULL;
servicedependency *this_servicedependency = NULL;
servicedependency *next_servicedependency = NULL;
hostdependency *this_hostdependency = NULL;
hostdependency *next_hostdependency = NULL;
hostescalation *this_hostescalation = NULL;
hostescalation *next_hostescalation = NULL;
escalation_condition *this_escalation_condition = NULL;
escalation_condition *next_escalation_condition = NULL;
module *this_module = NULL;
module *next_module = NULL;
register int x = 0;
register int i = 0;
/**** free memory for the timeperiod list ****/
this_timeperiod = timeperiod_list;
while (this_timeperiod != NULL) {
/* free the exception time ranges contained in this timeperiod */
for (x = 0; x < DATERANGE_TYPES; x++) {
for (this_daterange = this_timeperiod->exceptions[x]; this_daterange != NULL; this_daterange = next_daterange) {
next_daterange = this_daterange->next;
for (this_timerange = this_daterange->times; this_timerange != NULL; this_timerange = next_timerange) {
next_timerange = this_timerange->next;
my_free(this_timerange);
}
my_free(this_daterange);
}
}
/* free the day time ranges contained in this timeperiod */
for (x = 0; x < 7; x++) {
for (this_timerange = this_timeperiod->days[x]; this_timerange != NULL; this_timerange = next_timerange) {
next_timerange = this_timerange->next;
my_free(this_timerange);
}
}
/* free exclusions */
for (this_timeperiodexclusion = this_timeperiod->exclusions; this_timeperiodexclusion != NULL; this_timeperiodexclusion = next_timeperiodexclusion) {
next_timeperiodexclusion = this_timeperiodexclusion->next;
my_free(this_timeperiodexclusion->timeperiod_name);
my_free(this_timeperiodexclusion);
}
next_timeperiod = this_timeperiod->next;
my_free(this_timeperiod->name);
my_free(this_timeperiod->alias);
my_free(this_timeperiod);
this_timeperiod = next_timeperiod;
}
/* reset pointers */
timeperiod_list = NULL;
/**** free memory for the host list ****/
this_host = host_list;
while (this_host != NULL) {
next_host = this_host->next;
/* free memory for parent hosts */
this_hostsmember = this_host->parent_hosts;
while (this_hostsmember != NULL) {
next_hostsmember = this_hostsmember->next;
my_free(this_hostsmember->host_name);
my_free(this_hostsmember);
this_hostsmember = next_hostsmember;
}
/* free memory for child host links */
this_hostsmember = this_host->child_hosts;
while (this_hostsmember != NULL) {
next_hostsmember = this_hostsmember->next;
my_free(this_hostsmember->host_name);
my_free(this_hostsmember);
this_hostsmember = next_hostsmember;
}
/* free memory for service links */
this_servicesmember = this_host->services;
while (this_servicesmember != NULL) {
next_servicesmember = this_servicesmember->next;
my_free(this_servicesmember->host_name);
my_free(this_servicesmember->service_description);
my_free(this_servicesmember);
this_servicesmember = next_servicesmember;
}
/* free memory for contact groups */
this_contactgroupsmember = this_host->contact_groups;
while (this_contactgroupsmember != NULL) {
next_contactgroupsmember = this_contactgroupsmember->next;
my_free(this_contactgroupsmember->group_name);
my_free(this_contactgroupsmember);
this_contactgroupsmember = next_contactgroupsmember;
}
/* free memory for contacts */
this_contactsmember = this_host->contacts;
while (this_contactsmember != NULL) {
next_contactsmember = this_contactsmember->next;
my_free(this_contactsmember->contact_name);
my_free(this_contactsmember);
this_contactsmember = next_contactsmember;
}
/* free memory for custom variables */
this_customvariablesmember = this_host->custom_variables;
while (this_customvariablesmember != NULL) {
next_customvariablesmember = this_customvariablesmember->next;
my_free(this_customvariablesmember->variable_name);
my_free(this_customvariablesmember->variable_value);
my_free(this_customvariablesmember);
this_customvariablesmember = next_customvariablesmember;
}
my_free(this_host->name);
my_free(this_host->display_name);
my_free(this_host->alias);
my_free(this_host->address);
my_free(this_host->address6);
#ifdef NSCORE
my_free(this_host->plugin_output);
my_free(this_host->long_plugin_output);
my_free(this_host->perf_data);
my_free(this_host->processed_command);
free_objectlist(&this_host->hostgroups_ptr);
#endif
my_free(this_host->check_period);
my_free(this_host->host_check_command);
my_free(this_host->event_handler);
my_free(this_host->failure_prediction_options);
my_free(this_host->notification_period);
my_free(this_host->notes);
my_free(this_host->notes_url);
my_free(this_host->action_url);
my_free(this_host->icon_image);
my_free(this_host->icon_image_alt);
my_free(this_host->vrml_image);
my_free(this_host->statusmap_image);
my_free(this_host);
this_host = next_host;
}
/* reset pointers */
host_list = NULL;
/**** free memory for the host group list ****/
this_hostgroup = hostgroup_list;
while (this_hostgroup != NULL) {
/* free memory for the group members */
this_hostsmember = this_hostgroup->members;
while (this_hostsmember != NULL) {
next_hostsmember = this_hostsmember->next;
my_free(this_hostsmember->host_name);
my_free(this_hostsmember);
this_hostsmember = next_hostsmember;
}
next_hostgroup = this_hostgroup->next;
my_free(this_hostgroup->group_name);
my_free(this_hostgroup->alias);
my_free(this_hostgroup->notes);
my_free(this_hostgroup->notes_url);
my_free(this_hostgroup->action_url);
my_free(this_hostgroup);
this_hostgroup = next_hostgroup;
}
/* reset pointers */
hostgroup_list = NULL;
/**** free memory for the service group list ****/
this_servicegroup = servicegroup_list;
while (this_servicegroup != NULL) {
/* free memory for the group members */
this_servicesmember = this_servicegroup->members;
while (this_servicesmember != NULL) {
next_servicesmember = this_servicesmember->next;
my_free(this_servicesmember->host_name);
my_free(this_servicesmember->service_description);
my_free(this_servicesmember);
this_servicesmember = next_servicesmember;
}
next_servicegroup = this_servicegroup->next;
my_free(this_servicegroup->group_name);
my_free(this_servicegroup->alias);
my_free(this_servicegroup->notes);
my_free(this_servicegroup->notes_url);
my_free(this_servicegroup->action_url);
my_free(this_servicegroup);
this_servicegroup = next_servicegroup;
}
/* reset pointers */
servicegroup_list = NULL;
/**** free memory for the contact list ****/
this_contact = contact_list;
while (this_contact != NULL) {
/* free memory for the host notification commands */
this_commandsmember = this_contact->host_notification_commands;
while (this_commandsmember != NULL) {
next_commandsmember = this_commandsmember->next;
if (this_commandsmember->command != NULL)
my_free(this_commandsmember->command);
my_free(this_commandsmember);
this_commandsmember = next_commandsmember;
}
/* free memory for the service notification commands */
this_commandsmember = this_contact->service_notification_commands;
while (this_commandsmember != NULL) {
next_commandsmember = this_commandsmember->next;
if (this_commandsmember->command != NULL)
my_free(this_commandsmember->command);
my_free(this_commandsmember);
this_commandsmember = next_commandsmember;
}
/* free memory for custom variables */
this_customvariablesmember = this_contact->custom_variables;
while (this_customvariablesmember != NULL) {
next_customvariablesmember = this_customvariablesmember->next;
my_free(this_customvariablesmember->variable_name);
my_free(this_customvariablesmember->variable_value);
my_free(this_customvariablesmember);
this_customvariablesmember = next_customvariablesmember;
}
next_contact = this_contact->next;
my_free(this_contact->name);
my_free(this_contact->alias);
my_free(this_contact->email);
my_free(this_contact->pager);
for (i = 0; i < MAX_CONTACT_ADDRESSES; i++)
my_free(this_contact->address[i]);
my_free(this_contact->host_notification_period);
my_free(this_contact->service_notification_period);
#ifdef NSCORE
free_objectlist(&this_contact->contactgroups_ptr);
#endif
my_free(this_contact);
this_contact = next_contact;
}
/* reset pointers */
contact_list = NULL;
/**** free memory for the contact group list ****/
this_contactgroup = contactgroup_list;
while (this_contactgroup != NULL) {
/* free memory for the group members */
this_contactsmember = this_contactgroup->members;
while (this_contactsmember != NULL) {
next_contactsmember = this_contactsmember->next;
my_free(this_contactsmember->contact_name);
my_free(this_contactsmember);
this_contactsmember = next_contactsmember;
}
next_contactgroup = this_contactgroup->next;
my_free(this_contactgroup->group_name);
my_free(this_contactgroup->alias);
my_free(this_contactgroup);
this_contactgroup = next_contactgroup;
}
/* reset pointers */
contactgroup_list = NULL;
/**** free memory for the service list ****/
this_service = service_list;
while (this_service != NULL) {
next_service = this_service->next;
/* free memory for contact groups */
this_contactgroupsmember = this_service->contact_groups;
while (this_contactgroupsmember != NULL) {
next_contactgroupsmember = this_contactgroupsmember->next;
my_free(this_contactgroupsmember->group_name);
my_free(this_contactgroupsmember);
this_contactgroupsmember = next_contactgroupsmember;
}
/* free memory for contacts */
this_contactsmember = this_service->contacts;
while (this_contactsmember != NULL) {
next_contactsmember = this_contactsmember->next;
my_free(this_contactsmember->contact_name);
my_free(this_contactsmember);
this_contactsmember = next_contactsmember;
}
/* free memory for custom variables */
this_customvariablesmember = this_service->custom_variables;
while (this_customvariablesmember != NULL) {
next_customvariablesmember = this_customvariablesmember->next;
my_free(this_customvariablesmember->variable_name);
my_free(this_customvariablesmember->variable_value);
my_free(this_customvariablesmember);
this_customvariablesmember = next_customvariablesmember;
}
my_free(this_service->host_name);
my_free(this_service->description);
my_free(this_service->display_name);
my_free(this_service->service_check_command);
#ifdef NSCORE
my_free(this_service->plugin_output);
my_free(this_service->long_plugin_output);
my_free(this_service->perf_data);
my_free(this_service->processed_command);
my_free(this_service->event_handler_args);
my_free(this_service->check_command_args);
free_objectlist(&this_service->servicegroups_ptr);
#endif
my_free(this_service->notification_period);
my_free(this_service->check_period);
my_free(this_service->event_handler);
my_free(this_service->failure_prediction_options);
my_free(this_service->notes);
my_free(this_service->notes_url);
my_free(this_service->action_url);
my_free(this_service->icon_image);
my_free(this_service->icon_image_alt);
my_free(this_service);
this_service = next_service;
}
/* reset pointers */
service_list = NULL;
/**** free memory for the command list ****/
this_command = command_list;
while (this_command != NULL) {
next_command = this_command->next;
my_free(this_command->name);
my_free(this_command->command_line);
my_free(this_command);
this_command = next_command;
}
/* reset pointers */
command_list = NULL;
/**** free memory for the service escalation list ****/
this_serviceescalation = serviceescalation_list;
while (this_serviceescalation != NULL) {
/* free memory for the contact group members */
this_contactgroupsmember = this_serviceescalation->contact_groups;
while (this_contactgroupsmember != NULL) {
next_contactgroupsmember = this_contactgroupsmember->next;
my_free(this_contactgroupsmember->group_name);
my_free(this_contactgroupsmember);
this_contactgroupsmember = next_contactgroupsmember;
}
/* free memory for contacts */
this_contactsmember = this_serviceescalation->contacts;
while (this_contactsmember != NULL) {
next_contactsmember = this_contactsmember->next;
my_free(this_contactsmember->contact_name);
my_free(this_contactsmember);
this_contactsmember = next_contactsmember;
}
/* free memory for escalation_conditions */
this_escalation_condition = this_serviceescalation->condition;
while (this_escalation_condition != NULL) {
next_escalation_condition = this_escalation_condition->next;
my_free(this_escalation_condition->host_name);
my_free(this_escalation_condition->service_description);
my_free(this_escalation_condition);
this_escalation_condition = next_escalation_condition;
}
next_serviceescalation = this_serviceescalation->next;
my_free(this_serviceescalation->host_name);
my_free(this_serviceescalation->description);
my_free(this_serviceescalation->escalation_period);
my_free(this_serviceescalation);
this_serviceescalation = next_serviceescalation;
}
/* reset pointers */
serviceescalation_list = NULL;
/**** free memory for the service dependency list ****/
this_servicedependency = servicedependency_list;
while (this_servicedependency != NULL) {
next_servicedependency = this_servicedependency->next;
my_free(this_servicedependency->dependency_period);
my_free(this_servicedependency->dependent_host_name);
my_free(this_servicedependency->dependent_service_description);
my_free(this_servicedependency->host_name);
my_free(this_servicedependency->service_description);
my_free(this_servicedependency);
this_servicedependency = next_servicedependency;
}
/* reset pointers */
servicedependency_list = NULL;
/**** free memory for the host dependency list ****/
this_hostdependency = hostdependency_list;
while (this_hostdependency != NULL) {
next_hostdependency = this_hostdependency->next;
my_free(this_hostdependency->dependency_period);
my_free(this_hostdependency->dependent_host_name);
my_free(this_hostdependency->host_name);
my_free(this_hostdependency);
this_hostdependency = next_hostdependency;
}
/* reset pointers */
hostdependency_list = NULL;
/**** free memory for the host escalation list ****/
this_hostescalation = hostescalation_list;
while (this_hostescalation != NULL) {
/* free memory for the contact group members */
this_contactgroupsmember = this_hostescalation->contact_groups;
while (this_contactgroupsmember != NULL) {
next_contactgroupsmember = this_contactgroupsmember->next;
my_free(this_contactgroupsmember->group_name);
my_free(this_contactgroupsmember);
this_contactgroupsmember = next_contactgroupsmember;
}
/* free memory for contacts */
this_contactsmember = this_hostescalation->contacts;
while (this_contactsmember != NULL) {
next_contactsmember = this_contactsmember->next;
my_free(this_contactsmember->contact_name);
my_free(this_contactsmember);
this_contactsmember = next_contactsmember;
}
/* free memory for escalation_conditions */
this_escalation_condition = this_hostescalation->condition;
while (this_escalation_condition != NULL) {
next_escalation_condition = this_escalation_condition->next;
my_free(this_escalation_condition->host_name);
my_free(this_escalation_condition->service_description);
my_free(this_escalation_condition);
this_escalation_condition = next_escalation_condition;
}
next_hostescalation = this_hostescalation->next;
my_free(this_hostescalation->host_name);
my_free(this_hostescalation->escalation_period);
my_free(this_hostescalation);
this_hostescalation = next_hostescalation;
}
/* reset pointers */
hostescalation_list = NULL;
/**** free memory for the module list ****/
this_module = module_list;
while (this_module != NULL) {
next_module = this_module->next;
my_free(this_module->name);
my_free(this_module->type);
my_free(this_module->path);
my_free(this_module->args);
my_free(this_module);
this_module = next_module;
}
/* reset pointers */
module_list = NULL;
/* free object skiplists */
free_object_skiplists();
return OK;
}
icinga-1.10.3/common/shared.c 0000664 0000000 0000000 00000032202 12276402000 0015720 0 ustar 00root root 0000000 0000000 /*****************************************************************************
*
* SHARED.C - Random utility function for Icinga shared by CGIs and Core
*
* Copyright (c) 2010-2011 Nagios Core Development Team and Community Contributors
* Copyright (c) 2010-2011 Icinga Development Team (http://www.icinga.org)
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*****************************************************************************/
#include "../include/config.h"
#include "../include/common.h"
extern int date_format;
/* fix the problem with strtok() skipping empty options between tokens */
char *my_strtok(char *buffer, char *tokens) {
char *token_position = NULL;
char *sequence_head = NULL;
static char *my_strtok_buffer = NULL;
static char *original_my_strtok_buffer = NULL;
if (buffer != NULL) {
my_free(original_my_strtok_buffer);
if ((my_strtok_buffer = (char *)strdup(buffer)) == NULL)
return NULL;
original_my_strtok_buffer = my_strtok_buffer;
}
sequence_head = my_strtok_buffer;
if (sequence_head[0] == '\x0')
return NULL;
token_position = strchr(my_strtok_buffer, tokens[0]);
if (token_position == NULL) {
my_strtok_buffer = strchr(my_strtok_buffer, '\x0');
return sequence_head;
}
token_position[0] = '\x0';
my_strtok_buffer = token_position + 1;
return sequence_head;
}
/* fixes compiler problems under Solaris, since strsep() isn't included */
/* this code is taken from the glibc source */
char *my_strsep(char **stringp, const char *delim) {
char *begin, *end;
begin = *stringp;
if (begin == NULL)
return NULL;
/* A frequent case is when the delimiter string contains only one
* character. Here we don't need to call the expensive `strpbrk'
* function and instead work using `strchr'. */
if (delim[0] == '\0' || delim[1] == '\0') {
char ch = delim[0];
if (ch == '\0' || begin[0] == '\0')
end = NULL;
else {
if (*begin == ch)
end = begin;
else
end = strchr(begin + 1, ch);
}
} else {
/* find the end of the token. */
end = strpbrk(begin, delim);
}
if (end) {
/* terminate the token and set *STRINGP past NUL character. */
*end++ = '\0';
*stringp = end;
} else
/* no more delimiters; this is the last token. */
*stringp = NULL;
return begin;
}
/* open a file read-only via mmap() */
mmapfile *mmap_fopen(char *filename) {
mmapfile *new_mmapfile = NULL;
int fd = 0;
void *mmap_buf = NULL;
struct stat statbuf;
int mode = O_RDONLY;
unsigned long file_size = 0L;
if (filename == NULL)
return NULL;
/* allocate memory */
if ((new_mmapfile = (mmapfile *) malloc(sizeof(mmapfile))) == NULL)
return NULL;
/* open the file */
if ((fd = open(filename, mode)) == -1) {
my_free(new_mmapfile);
return NULL;
}
/* get file info */
if ((fstat(fd, &statbuf)) == -1) {
close(fd);
my_free(new_mmapfile);
return NULL;
}
/* get file size */
file_size = (unsigned long)statbuf.st_size;
/* only mmap() if we have a file greater than 0 bytes */
if (file_size > 0) {
/* mmap() the file - allocate one extra byte for processing zero-byte files */
if ((mmap_buf =
(void *)mmap(0, file_size, PROT_READ, MAP_PRIVATE, fd,
0)) == MAP_FAILED) {
close(fd);
my_free(new_mmapfile);
return NULL;
}
} else
mmap_buf = NULL;
/* populate struct info for later use */
new_mmapfile->path = (char *)strdup(filename);
new_mmapfile->fd = fd;
new_mmapfile->file_size = (unsigned long)file_size;
new_mmapfile->current_position = 0L;
new_mmapfile->current_line = 0L;
new_mmapfile->mmap_buf = mmap_buf;
return new_mmapfile;
}
/* close a file originally opened via mmap() */
int mmap_fclose(mmapfile * temp_mmapfile) {
if (temp_mmapfile == NULL)
return ERROR;
/* un-mmap() the file */
if (temp_mmapfile->file_size > 0L)
munmap(temp_mmapfile->mmap_buf, temp_mmapfile->file_size);
/* close the file */
close(temp_mmapfile->fd);
/* free memory */
my_free(temp_mmapfile->path);
my_free(temp_mmapfile);
return OK;
}
/* gets one line of input from an mmap()'ed file */
char *mmap_fgets(mmapfile * temp_mmapfile) {
char *buf = NULL;
unsigned long x = 0L;
int len = 0;
if (temp_mmapfile == NULL)
return NULL;
/* size of file is 0 bytes */
if (temp_mmapfile->file_size == 0L)
return NULL;
/* we've reached the end of the file */
if (temp_mmapfile->current_position >= temp_mmapfile->file_size)
return NULL;
/* find the end of the string (or buffer) */
for (x = temp_mmapfile->current_position; x < temp_mmapfile->file_size;
x++) {
if (*((char *)(temp_mmapfile->mmap_buf) + x) == '\n') {
x++;
break;
}
}
/* calculate length of line we just read */
len = (int)(x - temp_mmapfile->current_position);
/* allocate memory for the new line */
if ((buf = (char *)malloc(len + 1)) == NULL)
return NULL;
/* copy string to newly allocated memory and terminate the string */
memcpy(buf,
((char *)(temp_mmapfile->mmap_buf) +
temp_mmapfile->current_position), len);
buf[len] = '\x0';
/* update the current position */
temp_mmapfile->current_position = x;
/* increment the current line */
temp_mmapfile->current_line++;
return buf;
}
/* gets one line of input from an mmap()'ed file (may be contained on more than one line in the source file) */
char *mmap_fgets_multiline(mmapfile * temp_mmapfile) {
char *buf = NULL;
char *tempbuf = NULL;
char *stripped = NULL;
int len = 0;
int len2 = 0;
int end = 0;
if (temp_mmapfile == NULL)
return NULL;
while (1) {
my_free(tempbuf);
if ((tempbuf = mmap_fgets(temp_mmapfile)) == NULL)
break;
if (buf == NULL) {
len = strlen(tempbuf);
if ((buf = (char *)malloc(len + 1)) == NULL)
break;
memcpy(buf, tempbuf, len);
buf[len] = '\x0';
} else {
/* strip leading white space from continuation lines */
stripped = tempbuf;
while (*stripped == ' ' || *stripped == '\t')
stripped++;
len = strlen(stripped);
len2 = strlen(buf);
if ((buf =
(char *)realloc(buf, len + len2 + 1)) == NULL)
break;
strcat(buf, stripped);
len += len2;
buf[len] = '\x0';
}
if (len == 0)
break;
/* handle Windows/DOS CR/LF */
if (len >= 2 && buf[len - 2] == '\r')
end = len - 3;
/* normal Unix LF */
else if (len >= 1 && buf[len - 1] == '\n')
end = len - 2;
else
end = len - 1;
/* two backslashes found. unescape first backslash first and break */
if (end >= 1 && buf[end - 1] == '\\' && buf[end] == '\\') {
buf[end] = '\n';
buf[end + 1] = '\x0';
break;
}
/* one backslash found. continue reading the next line */
else if (end > 0 && buf[end] == '\\')
buf[end] = '\x0';
/* no continuation marker was found, so break */
else
break;
}
my_free(tempbuf);
return buf;
}
/* strip newline, carriage return, and tab characters from beginning and end of a string */
void strip(char *buffer) {
register int x, z;
int len;
if (buffer == NULL || buffer[0] == '\x0')
return;
/* strip end of string */
len = (int)strlen(buffer);
for (x = len - 1; x >= 0; x--) {
switch (buffer[x]) {
case ' ':
case '\n':
case '\r':
case '\t':
buffer[x] = '\x0';
continue;
}
break;
}
/* if we stripped all of it, just return */
if (!x)
return;
/* save last position for later... */
z = x;
/* strip beginning of string (by shifting) */
/* NOTE: this is very expensive to do, so avoid it whenever possible */
for (x = 0;; x++) {
switch (buffer[x]) {
case ' ':
case '\n':
case '\r':
case '\t':
continue;
}
break;
}
if (x > 0 && z > 0) {
/* new length of the string after we stripped the end */
len = z + 1;
/* shift chars towards beginning of string to remove leading whitespace */
for (z = x; z < len; z++)
buffer[z - x] = buffer[z];
buffer[len - x] = '\x0';
}
}
/**************************************************
*************** HASH FUNCTIONS *******************
**************************************************/
unsigned long sdbm(const char *str) {
unsigned long hash = 0;
int c;
while ((c = *str++) != '\0')
hash = c + (hash << 6) + (hash << 16) - hash;
return hash;
}
/* dual hash function */
int hashfunc(const char *name1, const char *name2, int hashslots) {
unsigned int result = 0;
if (name1)
result += sdbm(name1);
if (name2)
result += sdbm(name2);
result = result % hashslots;
return result;
}
int hc_compare(const char *field1, unsigned long hash1,
const char *field2, unsigned long hash2)
{
if (field1 == field2)
return 0;
if (hash1 == hash2)
return strcmp(field1, field2);
else
return hash2 - hash1;
}
/* dual hash data comparison */
int compare_hashdata(const char *val1a, const char *val1b, const char *val2a,
const char *val2b) {
int result = 0;
/* NOTE: If hash calculation changes, update the compare_strings() function! */
/* check first name */
if (val1a == NULL && val2a == NULL)
result = 0;
else if (val1a == NULL)
result = 1;
else if (val2a == NULL)
result = -1;
else
result = strcmp(val1a, val2a);
/* check second name if necessary */
if (result == 0) {
if (val1b == NULL && val2b == NULL)
result = 0;
else if (val1b == NULL)
result = 1;
else if (val2b == NULL)
result = -1;
else
result = strcmp(val1b, val2b);
}
return result;
}
/*
* given a date/time in time_t format, produce a corresponding
* date/time string, including timezone
*/
void get_datetime_string(time_t * raw_time, char *buffer, int buffer_length,
int type) {
time_t t;
struct tm *tm_ptr, tm_s;
int hour;
int minute;
int second;
int month;
int day;
int year;
char *weekdays[7] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
char *months[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept",
"Oct", "Nov", "Dec"
};
char *tzone = "";
if (raw_time == NULL)
time(&t);
else
t = *raw_time;
if (type == HTTP_DATE_TIME)
tm_ptr = gmtime_r(&t, &tm_s);
else
tm_ptr = localtime_r(&t, &tm_s);
hour = tm_ptr->tm_hour;
minute = tm_ptr->tm_min;
second = tm_ptr->tm_sec;
month = tm_ptr->tm_mon + 1;
day = tm_ptr->tm_mday;
year = tm_ptr->tm_year + 1900;
#ifdef HAVE_TM_ZONE
tzone = (char *)(tm_ptr->tm_zone);
#else
tzone = (tm_ptr->tm_isdst) ? tzname[1] : tzname[0];
#endif
/* ctime() style date/time */
if (type == LONG_DATE_TIME)
snprintf(buffer, buffer_length, "%s %s %d %02d:%02d:%02d %s %d",
weekdays[tm_ptr->tm_wday], months[tm_ptr->tm_mon], day,
hour, minute, second, tzone, year);
/* short date/time */
else if (type == SHORT_DATE_TIME) {
if (date_format == DATE_FORMAT_EURO)
snprintf(buffer, buffer_length,
"%02d-%02d-%04d %02d:%02d:%02d", day, month,
year, hour, minute, second);
else if (date_format == DATE_FORMAT_ISO8601
|| date_format == DATE_FORMAT_STRICT_ISO8601)
snprintf(buffer, buffer_length,
"%04d-%02d-%02d%c%02d:%02d:%02d", year, month,
day,
(date_format ==
DATE_FORMAT_STRICT_ISO8601) ? 'T' : ' ', hour,
minute, second);
else
snprintf(buffer, buffer_length,
"%02d-%02d-%04d %02d:%02d:%02d", month, day,
year, hour, minute, second);
}
/* short date */
else if (type == SHORT_DATE) {
if (date_format == DATE_FORMAT_EURO)
snprintf(buffer, buffer_length, "%02d-%02d-%04d", day,
month, year);
else if (date_format == DATE_FORMAT_ISO8601
|| date_format == DATE_FORMAT_STRICT_ISO8601)
snprintf(buffer, buffer_length, "%04d-%02d-%02d", year,
month, day);
else
snprintf(buffer, buffer_length, "%02d-%02d-%04d", month,
day, year);
}
/* expiration date/time for HTTP headers */
else if (type == HTTP_DATE_TIME)
snprintf(buffer, buffer_length,
"%s, %02d %s %d %02d:%02d:%02d GMT",
weekdays[tm_ptr->tm_wday], day, months[tm_ptr->tm_mon],
year, hour, minute, second);
/* short time */
else
snprintf(buffer, buffer_length, "%02d:%02d:%02d", hour, minute,
second);
buffer[buffer_length - 1] = '\x0';
}
/* get days, hours, minutes, and seconds from a raw time_t format or total seconds */
void get_time_breakdown(unsigned long raw_time, int *days, int *hours,
int *minutes, int *seconds) {
unsigned long temp_time;
int temp_days;
int temp_hours;
int temp_minutes;
int temp_seconds;
temp_time = raw_time;
temp_days = temp_time / 86400;
temp_time -= (temp_days * 86400);
temp_hours = temp_time / 3600;
temp_time -= (temp_hours * 3600);
temp_minutes = temp_time / 60;
temp_time -= (temp_minutes * 60);
temp_seconds = (int)temp_time;
*days = temp_days;
*hours = temp_hours;
*minutes = temp_minutes;
*seconds = temp_seconds;
}
icinga-1.10.3/common/skiplist.c 0000664 0000000 0000000 00000031327 12276402000 0016323 0 ustar 00root root 0000000 0000000 /************************************************************************
*
* SKIPLIST.C - Skiplist functions for use in Icinga event/object lists
*
* Copyright (c) 2008 Ethan Galstad
* Copyright (c) 2009-2013 Nagios Core Development Team and Community Contributors
* Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
*
* Notes:
*
* These function implement a slightly modified skiplist from that
* described by William Pugh (ftp://ftp.cs.umd.edu/pub/skipLists/skiplists.pdf).
* The structures and function were modified to allow the list to act
* like a priority queue for the Icinga event list/queue(s). Multiple nodes with
* the same key value are allowed on the list to accomodate multiple events
* occurring at the same (second) point in time. Implemented peek() and pop()
* functions to allow for quick event queue processing, and a method to delete
* a specific list item, based on its pointer, rather than its data value. Again,
* this is useful for the Icinga event queue.
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
************************************************************************/
#include "../include/config.h"
#include "../include/common.h"
#include "../include/skiplist.h"
skiplist *skiplist_new(int max_levels, float level_probability, int allow_duplicates, int append_duplicates, int (*compare_function)(void *, void *)) {
skiplist *newlist = NULL;
/* alloc memory for new list structure */
if ((newlist = (skiplist *)malloc(sizeof(skiplist)))) {
/* initialize levels, etc. */
newlist->current_level = 0;
newlist->max_levels = max_levels;
newlist->level_probability = level_probability;
newlist->allow_duplicates = allow_duplicates;
newlist->append_duplicates = append_duplicates;
newlist->items = 0;
newlist->compare_function = compare_function;
/* initialize head node */
newlist->head = skiplist_new_node(newlist, max_levels);
}
return newlist;
}
int skiplist_insert(skiplist *list, void *data) {
skiplistnode **update = NULL;
skiplistnode *thisnode = NULL;
skiplistnode *nextnode = NULL;
skiplistnode *newnode = NULL;
int level = 0;
if (list == NULL || data == NULL) {
return SKIPLIST_ERROR_ARGS;
}
/* check to make sure we don't have duplicates */
/* NOTE: this could made be more efficient */
if (list->allow_duplicates == FALSE) {
if (skiplist_find_first(list, data, NULL))
return SKIPLIST_ERROR_DUPLICATE;
}
/* initialize update vector */
if ((update = (skiplistnode **)calloc(list->max_levels, sizeof(skiplistnode *))) == NULL)
return SKIPLIST_ERROR_MEMORY;
/* find proper position for insert, remember pointers with an update vector */
thisnode = list->head;
for (level = list->current_level; level >= 0; level--) {
while ((nextnode = thisnode->forward[level])) {
if (list->append_duplicates == TRUE) {
if (list->compare_function(nextnode->data, data) > 0)
break;
} else {
if (list->compare_function(nextnode->data, data) >= 0)
break;
}
thisnode = nextnode;
}
update[level] = thisnode;
}
/* get a random level the new node should be inserted at */
level = skiplist_random_level(list);
/*printf("INSERTION LEVEL: %d\n",level);*/
/* we're adding a new level... */
if (level > list->current_level) {
/*printf("NEW LEVEL!\n");*/
list->current_level++;
level = list->current_level;
update[level] = list->head;
}
/* create a new node */
if ((newnode = skiplist_new_node(list, level)) == NULL) {
/*printf("NODE ERROR\n");*/
free(update);
return SKIPLIST_ERROR_MEMORY;
}
newnode->data = data;
/* update pointers to insert node at proper location */
do {
thisnode = update[level];
newnode->forward[level] = thisnode->forward[level];
thisnode->forward[level] = newnode;
} while (--level >= 0);
/* update counters */
list->items++;
/* free memory */
free(update);
return SKIPLIST_OK;
}
skiplistnode *skiplist_new_node(skiplist *list, int node_levels) {
skiplistnode *newnode = NULL;
register int x = 0;
if (list == NULL)
return NULL;
if (node_levels < 0 || node_levels > list->max_levels)
return NULL;
/* allocate memory for node + variable number of level pointers */
if ((newnode = (skiplistnode *)malloc(sizeof(skiplistnode) + (node_levels * sizeof(skiplistnode *))))) {
/* initialize forward pointers */
for (x = 0; x < node_levels; x++)
newnode->forward[x] = NULL;
/* initialize data pointer */
newnode->data = NULL;
}
return newnode;
}
int skiplist_random_level(skiplist *list) {
int level = 0;
float r = 0.0;
if (list == NULL)
return -1;
for (level = 0; level < list->max_levels; level++) {
r = ((float)rand() / (float)RAND_MAX);
if (r > list->level_probability)
break;
}
return (level >= list->max_levels) ? list->max_levels - 1 : level;
}
int skiplist_empty(skiplist *list) {
skiplistnode *this = NULL;
skiplistnode *next = NULL;
int level = 0;
if (list == NULL)
return ERROR;
/* free all list nodes (but not header) */
for (this = list->head->forward[0]; this != NULL; this = next) {
next = this->forward[0];
free(this);
}
/* reset level pointers */
for (level = list->current_level; level >= 0; level--)
list->head->forward[level] = NULL;
/* reset list level */
list->current_level = 0;
/* reset items */
list->items = 0;
return OK;
}
int skiplist_free(skiplist **list) {
skiplistnode *this = NULL;
skiplistnode *next = NULL;
if (list == NULL)
return ERROR;
if (*list == NULL)
return OK;
/* free header and all list nodes */
for (this = (*list)->head; this != NULL; this = next) {
next = this->forward[0];
free(this);
}
/* free list structure */
free(*list);
*list = NULL;
return OK;
}
/* get first item in list */
void *skiplist_peek(skiplist *list) {
if (list == NULL)
return NULL;
/* return first item */
return list->head->forward[0]->data;
}
/* get/remove first item in list */
void *skiplist_pop(skiplist *list) {
skiplistnode *thisnode = NULL;
void *data = NULL;
int level = 0;
if (list == NULL)
return NULL;
/* get first item */
thisnode = list->head->forward[0];
if (thisnode == NULL)
return NULL;
/* get data for first item */
data = thisnode->data;
/* remove first item from queue - update forward links from head to first node */
for (level = 0; level <= list->current_level; level++) {
if (list->head->forward[level] == thisnode)
list->head->forward[level] = thisnode->forward[level];
}
/* free deleted node */
free(thisnode);
/* adjust items */
list->items--;
return data;
}
/* get first item in list */
void *skiplist_get_first(skiplist *list, void **node_ptr) {
skiplistnode *thisnode = NULL;
if (list == NULL)
return NULL;
/* get first node */
thisnode = list->head->forward[0];
/* return pointer to node */
if (node_ptr)
*node_ptr = (void *)thisnode;
if (thisnode)
return thisnode->data;
else
return NULL;
}
/* get next item in list */
void *skiplist_get_next(void **node_ptr) {
skiplistnode *thisnode = NULL;
skiplistnode *nextnode = NULL;
if (node_ptr == NULL || *node_ptr == NULL)
return NULL;
thisnode = (skiplistnode *)(*node_ptr);
nextnode = thisnode->forward[0];
*node_ptr = (void *)nextnode;
if (nextnode)
return nextnode->data;
else
return NULL;
}
/* first first item in list */
void *skiplist_find_first(skiplist *list, void *data, void **node_ptr) {
skiplistnode *thisnode = NULL;
skiplistnode *nextnode = NULL;
int level = 0;
if (list == NULL || data == NULL)
return NULL;
thisnode = list->head;
for (level = list->current_level; level >= 0; level--) {
while ((nextnode = thisnode->forward[level])) {
if (list->compare_function(nextnode->data, data) >= 0)
break;
thisnode = nextnode;
}
}
/* we found it! */
if (nextnode && list->compare_function(nextnode->data, data) == 0) {
if (node_ptr)
*node_ptr = (void *)nextnode;
return nextnode->data;
} else {
if (node_ptr)
*node_ptr = NULL;
}
return NULL;
}
/* find next match */
void *skiplist_find_next(skiplist *list, void *data, void **node_ptr) {
skiplistnode *thisnode = NULL;
skiplistnode *nextnode = NULL;
if (list == NULL || data == NULL || node_ptr == NULL)
return NULL;
if (*node_ptr == NULL)
return NULL;
thisnode = (skiplistnode *)(*node_ptr);
nextnode = thisnode->forward[0];
if (nextnode) {
if (list->compare_function(nextnode->data, data) == 0) {
*node_ptr = (void *)nextnode;
return nextnode->data;
}
}
*node_ptr = NULL;
return NULL;
}
/* delete (all) matching item(s) from list */
int skiplist_delete(skiplist *list, void *data) {
return skiplist_delete_all(list, data);
}
/* delete first matching item from list */
int skiplist_delete_first(skiplist *list, void *data) {
skiplistnode **update = NULL;
skiplistnode *thisnode = NULL;
skiplistnode *nextnode = NULL;
int level = 0;
int top_level = 0;
int deleted = FALSE;
int x = 0;
if (list == NULL || data == NULL)
return ERROR;
/* initialize update vector */
if ((update = (skiplistnode **)malloc(sizeof(skiplistnode *) * list->max_levels)) == NULL)
return ERROR;
for (x = 0; x < list->max_levels; x++)
update[x] = NULL;
/* find location in list */
thisnode = list->head;
for (top_level = level = list->current_level; level >= 0; level--) {
while ((nextnode = thisnode->forward[level])) {
if (list->compare_function(nextnode->data, data) >= 0)
break;
thisnode = nextnode;
}
update[level] = thisnode;
}
/* we found a match! */
if (list->compare_function(nextnode->data, data) == 0) {
/* adjust level pointers to bypass (soon to be) removed node */
for (level = 0; level <= top_level; level++) {
thisnode = update[level];
if (thisnode->forward[level] != nextnode)
break;
thisnode->forward[level] = nextnode->forward[level];
}
/* free node memory */
free(nextnode);
/* adjust top/current level of list is necessary */
while (list->head->forward[top_level] == NULL && top_level > 0)
top_level--;
list->current_level = top_level;
/* adjust items */
list->items--;
deleted = TRUE;
}
/* free memory */
free(update);
return deleted;
}
/* delete all matching items from list */
int skiplist_delete_all(skiplist *list, void *data) {
int deleted = 0;
int total_deleted = 0;
/* NOTE: there is a more efficient way to do this... */
while ((deleted = skiplist_delete_first(list, data)) == 1)
total_deleted++;
return total_deleted;
}
/* delete specific node from list */
int skiplist_delete_node(skiplist *list, void *node_ptr) {
void *data = NULL;
skiplistnode **update = NULL;
skiplistnode *thenode = NULL;
skiplistnode *thisnode = NULL;
skiplistnode *nextnode = NULL;
int level = 0;
int top_level = 0;
int deleted = FALSE;
int x = 0;
if (list == NULL || node_ptr == NULL)
return ERROR;
/* we'll need the data from the node to first find the node */
thenode = (skiplistnode *)node_ptr;
data = thenode->data;
/* initialize update vector */
if ((update = (skiplistnode **)malloc(sizeof(skiplistnode *) * list->max_levels)) == NULL)
return ERROR;
for (x = 0; x < list->max_levels; x++)
update[x] = NULL;
/* find location in list */
thisnode = list->head;
for (top_level = level = list->current_level; level >= 0; level--) {
while ((nextnode = thisnode->forward[level])) {
/* next node would be too far */
if (list->compare_function(nextnode->data, data) > 0)
break;
/* this is the exact node we want */
if (list->compare_function(nextnode->data, data) == 0 && nextnode == thenode)
break;
thisnode = nextnode;
}
update[level] = thisnode;
}
/* we found a match! (value + pointers match) */
if (nextnode && list->compare_function(nextnode->data, data) == 0 && nextnode == thenode) {
/* adjust level pointers to bypass (soon to be) removed node */
for (level = 0; level <= top_level; level++) {
thisnode = update[level];
if (thisnode->forward[level] != nextnode)
break;
thisnode->forward[level] = nextnode->forward[level];
}
/* free node memory */
free(nextnode);
/* adjust top/current level of list is necessary */
while (list->head->forward[top_level] == NULL && top_level > 0)
top_level--;
list->current_level = top_level;
/* adjust items */
list->items--;
deleted = TRUE;
}
/* free memory */
free(update);
return deleted;
}
icinga-1.10.3/common/snprintf.c 0000664 0000000 0000000 00000104010 12276402000 0016312 0 ustar 00root root 0000000 0000000 /*
* NOTE: If you change this file, please merge it into rsync, samba, etc.
*/
/*
* Copyright Patrick Powell 1995
* This code is based on code written by Patrick Powell (papowell@astart.com)
* It may be used for any purpose as long as this notice remains intact
* on all source code distributions
*/
/**************************************************************
* Original:
* Patrick Powell Tue Apr 11 09:48:21 PDT 1995
* A bombproof version of doprnt (dopr) included.
* Sigh. This sort of thing is always nasty do deal with. Note that
* the version here does not include floating point...
*
* snprintf() is used instead of sprintf() as it does limit checks
* for string length. This covers a nasty loophole.
*
* The other functions are there to prevent NULL pointers from
* causing nast effects.
*
* More Recently:
* Brandon Long 9/15/96 for mutt 0.43
* This was ugly. It is still ugly. I opted out of floating point
* numbers, but the formatter understands just about everything
* from the normal C string format, at least as far as I can tell from
* the Solaris 2.5 printf(3S) man page.
*
* Brandon Long 10/22/97 for mutt 0.87.1
* Ok, added some minimal floating point support, which means this
* probably requires libm on most operating systems. Don't yet
* support the exponent (e,E) and sigfig (g,G). Also, fmtint()
* was pretty badly broken, it just wasn't being exercised in ways
* which showed it, so that's been fixed. Also, formated the code
* to mutt conventions, and removed dead code left over from the
* original. Also, there is now a builtin-test, just compile with:
* gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm
* and run snprintf for results.
*
* Thomas Roessler 01/27/98 for mutt 0.89i
* The PGP code was using unsigned hexadecimal formats.
* Unfortunately, unsigned formats simply didn't work.
*
* Michael Elkins 03/05/98 for mutt 0.90.8
* The original code assumed that both snprintf() and vsnprintf() were
* missing. Some systems only have snprintf() but not vsnprintf(), so
* the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF.
*
* Andrew Tridgell (tridge@samba.org) Oct 1998
* fixed handling of %.0f
* added test for HAVE_LONG_DOUBLE
*
* tridge@samba.org, idra@samba.org, April 2001
* got rid of fcvt code (twas buggy and made testing harder)
* added C99 semantics
*
* date: 2002/12/19 19:56:31; author: herb; state: Exp; lines: +2 -0
* actually print args for %g and %e
*
* date: 2002/06/03 13:37:52; author: jmcd; state: Exp; lines: +8 -0
* Since includes.h isn't included here, VA_COPY has to be defined here. I don't
* see any include file that is guaranteed to be here, so I'm defining it
* locally. Fixes AIX and Solaris builds.
*
* date: 2002/06/03 03:07:24; author: tridge; state: Exp; lines: +5 -13
* put the ifdef for HAVE_VA_COPY in one place rather than in lots of
* functions
*
* date: 2002/05/17 14:51:22; author: jmcd; state: Exp; lines: +21 -4
* Fix usage of va_list passed as an arg. Use __va_copy before using it
* when it exists.
*
* date: 2002/04/16 22:38:04; author: idra; state: Exp; lines: +20 -14
* Fix incorrect zpadlen handling in fmtfp.
* Thanks to Ollie Oldham for spotting it.
* few mods to make it easier to compile the tests.
* addedd the "Ollie" test to the floating point ones.
*
* Martin Pool (mbp@samba.org) April 2003
* Remove NO_CONFIG_H so that the test case can be built within a source
* tree with less trouble.
* Remove unnecessary SAFE_FREE() definition.
*
* Martin Pool (mbp@samba.org) May 2003
* Put in a prototype for dummy_snprintf() to quiet compiler warnings.
*
* Move #endif to make sure VA_COPY, LDOUBLE, etc are defined even
* if the C library has some snprintf functions already.
*
* Darren Tucker (dtucker@zip.com.au) 2005
* Fix bug allowing read overruns of the source string with "%.*s"
* Usually harmless unless the read runs outside the process' allocation
* (eg if your malloc does guard pages) in which case it will segfault.
* From OpenSSH. Also added test for same.
*
* Simo Sorce (idra@samba.org) Jan 2006
*
* Add support for position independent parameters
* fix fmtstr now it conforms to sprintf wrt min.max
*
**************************************************************/
#ifndef NO_CONFIG_H
/* 02/28/2006 EG changed path to config.h to match Icinga distro */
#include "../include/config.h"
#else
#define NULL 0
#endif
#ifdef TEST_SNPRINTF /* need math library headers for testing */
/* In test mode, we pretend that this system doesn't have any snprintf
* functions, regardless of what config.h says. */
# undef HAVE_SNPRINTF
# undef HAVE_VSNPRINTF
# undef HAVE_C99_VSNPRINTF
# undef HAVE_ASPRINTF
# undef HAVE_VASPRINTF
# include
#endif /* TEST_SNPRINTF */
#ifdef SNPRINTF_BROKEN
/* snprintf and friends are known broken at least in solaris
* we assume functions are not there to take local one
*/
#undef HAVE_SNPRINTF
#undef HAVE_VSNPRINTF
#undef HAVE_C99_VSNPRINTF
#undef HAVE_ASPRINTF
#undef HAVE_VASPRINTF
#undef HAVE_VA_COPY
#endif
#ifdef HAVE_STRING_H
#include
#endif
#ifdef HAVE_STRINGS_H
#include
#endif
#ifdef HAVE_CTYPE_H
#include
#endif
#include
#include
#ifdef HAVE_STDLIB_H
#include
#endif
#if defined(HAVE_SNPRINTF) && defined(HAVE_VSNPRINTF) && defined(HAVE_C99_VSNPRINTF)
/* only include stdio.h if we are not re-defining snprintf or vsnprintf */
#include
/* make the compiler happy with an empty file */
void dummy_snprintf(void);
void dummy_snprintf(void) {}
#endif /* HAVE_SNPRINTF, etc */
#ifdef HAVE_LONG_DOUBLE
#define LDOUBLE long double
#else
#define LDOUBLE double
#endif
#ifdef HAVE_LONG_LONG
#define LLONG long long
#else
#define LLONG long
#endif
#ifndef VA_COPY
#ifdef HAVE_VA_COPY
#define VA_COPY(dest, src) va_copy(dest, src)
#else
#ifdef HAVE___VA_COPY
#define VA_COPY(dest, src) __va_copy(dest, src)
#else
#define VA_COPY(dest, src) (dest) = (src)
#endif
#endif
/*
* dopr(): poor man's version of doprintf
*/
/* format read states */
#define DP_S_DEFAULT 0
#define DP_S_FLAGS 1
#define DP_S_MIN 2
#define DP_S_DOT 3
#define DP_S_MAX 4
#define DP_S_MOD 5
#define DP_S_CONV 6
#define DP_S_DONE 7
/* format flags - Bits */
#define DP_F_MINUS (1 << 0)
#define DP_F_PLUS (1 << 1)
#define DP_F_SPACE (1 << 2)
#define DP_F_NUM (1 << 3)
#define DP_F_ZERO (1 << 4)
#define DP_F_UP (1 << 5)
#define DP_F_UNSIGNED (1 << 6)
/* Conversion Flags */
#define DP_C_CHAR 1
#define DP_C_SHORT 2
#define DP_C_LONG 3
#define DP_C_LDOUBLE 4
#define DP_C_LLONG 5
/* Chunk types */
#define CNK_FMT_STR 0
#define CNK_INT 1
#define CNK_OCTAL 2
#define CNK_UINT 3
#define CNK_HEX 4
#define CNK_FLOAT 5
#define CNK_CHAR 6
#define CNK_STRING 7
#define CNK_PTR 8
#define CNK_NUM 9
#define CNK_PRCNT 10
#define char_to_int(p) ((p)- '0')
#ifndef MAX
#define MAX(p,q) (((p) >= (q)) ? (p) : (q))
#endif
/* yes this really must be a ||. Don't muck with this (tridge) */
#if !defined(HAVE_VSNPRINTF) || !defined(HAVE_C99_VSNPRINTF)
struct pr_chunk {
int type; /* chunk type */
int num; /* parameter number */
int min;
int max;
int flags;
int cflags;
int start;
int len;
LLONG value;
LDOUBLE fvalue;
char *strvalue;
void *pnum;
struct pr_chunk *min_star;
struct pr_chunk *max_star;
struct pr_chunk *next;
};
struct pr_chunk_x {
struct pr_chunk **chunks;
int num;
};
static size_t dopr(char *buffer, size_t maxlen, const char *format,
va_list args_in);
static void fmtstr(char *buffer, size_t *currlen, size_t maxlen,
char *value, int flags, int min, int max);
static void fmtint(char *buffer, size_t *currlen, size_t maxlen,
long value, int base, int min, int max, int flags);
static void fmtfp(char *buffer, size_t *currlen, size_t maxlen,
LDOUBLE fvalue, int min, int max, int flags);
static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c);
static struct pr_chunk *new_chunk(void);
static int add_cnk_list_entry(struct pr_chunk_x **list,
int max_num, struct pr_chunk *chunk);
static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) {
char ch;
int state;
int pflag;
int pnum;
int pfirst;
size_t currlen;
va_list args;
const char *base;
struct pr_chunk *chunks = NULL;
struct pr_chunk *cnk = NULL;
struct pr_chunk_x *clist = NULL;
int max_pos;
size_t ret = -1;
VA_COPY(args, args_in);
state = DP_S_DEFAULT;
pfirst = 1;
pflag = 0;
pnum = 0;
max_pos = 0;
base = format;
ch = *format++;
/* retrieve the string structure as chunks */
while (state != DP_S_DONE) {
if (ch == '\0')
state = DP_S_DONE;
switch (state) {
case DP_S_DEFAULT:
if (cnk) {
cnk->next = new_chunk();
cnk = cnk->next;
} else {
cnk = new_chunk();
}
if (!cnk) goto done;
if (!chunks) chunks = cnk;
if (ch == '%') {
state = DP_S_FLAGS;
ch = *format++;
} else {
cnk->type = CNK_FMT_STR;
cnk->start = format - base - 1;
while ((ch != '\0') && (ch != '%')) ch = *format++;
cnk->len = format - base - cnk->start - 1;
}
break;
case DP_S_FLAGS:
switch (ch) {
case '-':
cnk->flags |= DP_F_MINUS;
ch = *format++;
break;
case '+':
cnk->flags |= DP_F_PLUS;
ch = *format++;
break;
case ' ':
cnk->flags |= DP_F_SPACE;
ch = *format++;
break;
case '#':
cnk->flags |= DP_F_NUM;
ch = *format++;
break;
case '0':
cnk->flags |= DP_F_ZERO;
ch = *format++;
break;
case 'I':
/* internationalization not supported yet */
ch = *format++;
break;
default:
state = DP_S_MIN;
break;
}
break;
case DP_S_MIN:
if (isdigit((unsigned char)ch)) {
cnk->min = 10 * cnk->min + char_to_int(ch);
ch = *format++;
} else if (ch == '$') {
if (!pfirst && !pflag) {
/* parameters must be all positioned or none */
goto done;
}
if (pfirst) {
pfirst = 0;
pflag = 1;
}
if (cnk->min == 0) /* what ?? */
goto done;
cnk->num = cnk->min;
cnk->min = 0;
ch = *format++;
} else if (ch == '*') {
if (pfirst) pfirst = 0;
cnk->min_star = new_chunk();
if (!cnk->min_star) /* out of memory :-( */
goto done;
cnk->min_star->type = CNK_INT;
if (pflag) {
int num;
ch = *format++;
if (!isdigit((unsigned char)ch)) {
/* parameters must be all positioned or none */
goto done;
}
for (num = 0; isdigit((unsigned char)ch); ch = *format++) {
num = 10 * num + char_to_int(ch);
}
cnk->min_star->num = num;
if (ch != '$') /* what ?? */
goto done;
} else {
cnk->min_star->num = ++pnum;
}
max_pos = add_cnk_list_entry(&clist, max_pos, cnk->min_star);
if (max_pos == 0) /* out of memory :-( */
goto done;
ch = *format++;
state = DP_S_DOT;
} else {
if (pfirst) pfirst = 0;
state = DP_S_DOT;
}
break;
case DP_S_DOT:
if (ch == '.') {
state = DP_S_MAX;
ch = *format++;
} else {
state = DP_S_MOD;
}
break;
case DP_S_MAX:
if (isdigit((unsigned char)ch)) {
if (cnk->max < 0)
cnk->max = 0;
cnk->max = 10 * cnk->max + char_to_int(ch);
ch = *format++;
} else if (ch == '$') {
if (!pfirst && !pflag) {
/* parameters must be all positioned or none */
goto done;
}
if (cnk->max <= 0) /* what ?? */
goto done;
cnk->num = cnk->max;
cnk->max = -1;
ch = *format++;
} else if (ch == '*') {
cnk->max_star = new_chunk();
if (!cnk->max_star) /* out of memory :-( */
goto done;
cnk->max_star->type = CNK_INT;
if (pflag) {
int num;
ch = *format++;
if (!isdigit((unsigned char)ch)) {
/* parameters must be all positioned or none */
goto done;
}
for (num = 0; isdigit((unsigned char)ch); ch = *format++) {
num = 10 * num + char_to_int(ch);
}
cnk->max_star->num = num;
if (ch != '$') /* what ?? */
goto done;
} else {
cnk->max_star->num = ++pnum;
}
max_pos = add_cnk_list_entry(&clist, max_pos, cnk->max_star);
if (max_pos == 0) /* out of memory :-( */
goto done;
ch = *format++;
state = DP_S_MOD;
} else {
state = DP_S_MOD;
}
break;
case DP_S_MOD:
switch (ch) {
case 'h':
cnk->cflags = DP_C_SHORT;
ch = *format++;
if (ch == 'h') {
cnk->cflags = DP_C_CHAR;
ch = *format++;
}
break;
case 'l':
cnk->cflags = DP_C_LONG;
ch = *format++;
if (ch == 'l') { /* It's a long long */
cnk->cflags = DP_C_LLONG;
ch = *format++;
}
break;
case 'L':
cnk->cflags = DP_C_LDOUBLE;
ch = *format++;
break;
default:
break;
}
state = DP_S_CONV;
break;
case DP_S_CONV:
if (cnk->num == 0) cnk->num = ++pnum;
max_pos = add_cnk_list_entry(&clist, max_pos, cnk);
if (max_pos == 0) /* out of memory :-( */
goto done;
switch (ch) {
case 'd':
case 'i':
cnk->type = CNK_INT;
break;
case 'o':
cnk->type = CNK_OCTAL;
cnk->flags |= DP_F_UNSIGNED;
break;
case 'u':
cnk->type = CNK_UINT;
cnk->flags |= DP_F_UNSIGNED;
break;
case 'X':
cnk->flags |= DP_F_UP;
case 'x':
cnk->type = CNK_HEX;
cnk->flags |= DP_F_UNSIGNED;
break;
case 'A':
/* hex float not supported yet */
case 'E':
case 'G':
case 'F':
cnk->flags |= DP_F_UP;
case 'a':
/* hex float not supported yet */
case 'e':
case 'f':
case 'g':
cnk->type = CNK_FLOAT;
break;
case 'c':
cnk->type = CNK_CHAR;
break;
case 's':
cnk->type = CNK_STRING;
break;
case 'p':
cnk->type = CNK_PTR;
break;
case 'n':
cnk->type = CNK_NUM;
break;
case '%':
cnk->type = CNK_PRCNT;
break;
default:
/* Unknown, bail out*/
goto done;
}
ch = *format++;
state = DP_S_DEFAULT;
break;
case DP_S_DONE:
break;
default:
/* hmm? */
break; /* some picky compilers need this */
}
}
/* retieve the format arguments */
for (pnum = 0; pnum < max_pos; pnum++) {
int i;
if (clist[pnum].num == 0) {
/* ignoring a parameter should not be permitted
* all parameters must be matched at least once
* BUT seem some system ignore this rule ...
* at least my glibc based system does --SSS
*/
#ifdef DEBUG_SNPRINTF
printf("parameter at position %d not used\n", pnum + 1);
#endif
/* eat the parameter */
va_arg(args, int);
continue;
}
for (i = 1; i < clist[pnum].num; i++) {
if (clist[pnum].chunks[0]->type != clist[pnum].chunks[i]->type) {
/* nooo noo no!
* all the references to a parameter
* must be of the same type
*/
goto done;
}
}
cnk = clist[pnum].chunks[0];
switch (cnk->type) {
case CNK_INT:
if (cnk->cflags == DP_C_SHORT)
cnk->value = va_arg(args, int);
else if (cnk->cflags == DP_C_LONG)
cnk->value = va_arg(args, long int);
else if (cnk->cflags == DP_C_LLONG)
cnk->value = va_arg(args, LLONG);
else
cnk->value = va_arg(args, int);
for (i = 1; i < clist[pnum].num; i++) {
clist[pnum].chunks[i]->value = cnk->value;
}
break;
case CNK_OCTAL:
case CNK_UINT:
case CNK_HEX:
if (cnk->cflags == DP_C_SHORT)
cnk->value = va_arg(args, unsigned int);
else if (cnk->cflags == DP_C_LONG)
cnk->value = (long)va_arg(args, unsigned long int);
else if (cnk->cflags == DP_C_LLONG)
cnk->value = (LLONG)va_arg(args, unsigned LLONG);
else
cnk->value = (long)va_arg(args, unsigned int);
for (i = 1; i < clist[pnum].num; i++) {
clist[pnum].chunks[i]->value = cnk->value;
}
break;
case CNK_FLOAT:
if (cnk->cflags == DP_C_LDOUBLE)
cnk->fvalue = va_arg(args, LDOUBLE);
else
cnk->fvalue = va_arg(args, double);
for (i = 1; i < clist[pnum].num; i++) {
clist[pnum].chunks[i]->fvalue = cnk->fvalue;
}
break;
case CNK_CHAR:
cnk->value = va_arg(args, int);
for (i = 1; i < clist[pnum].num; i++) {
clist[pnum].chunks[i]->value = cnk->value;
}
break;
case CNK_STRING:
cnk->strvalue = va_arg(args, char *);
if (!cnk->strvalue) cnk->strvalue = "(NULL)";
for (i = 1; i < clist[pnum].num; i++) {
clist[pnum].chunks[i]->strvalue = cnk->strvalue;
}
break;
case CNK_PTR:
cnk->strvalue = va_arg(args, void *);
for (i = 1; i < clist[pnum].num; i++) {
clist[pnum].chunks[i]->strvalue = cnk->strvalue;
}
break;
case CNK_NUM:
if (cnk->cflags == DP_C_CHAR)
cnk->pnum = va_arg(args, char *);
else if (cnk->cflags == DP_C_SHORT)
cnk->pnum = va_arg(args, short int *);
else if (cnk->cflags == DP_C_LONG)
cnk->pnum = va_arg(args, long int *);
else if (cnk->cflags == DP_C_LLONG)
cnk->pnum = va_arg(args, LLONG *);
else
cnk->pnum = va_arg(args, int *);
for (i = 1; i < clist[pnum].num; i++) {
clist[pnum].chunks[i]->pnum = cnk->pnum;
}
break;
case CNK_PRCNT:
break;
default:
/* what ?? */
goto done;
}
}
/* print out the actual string from chunks */
currlen = 0;
cnk = chunks;
while (cnk) {
int len, min, max;
if (cnk->min_star) min = cnk->min_star->value;
else min = cnk->min;
if (cnk->max_star) max = cnk->max_star->value;
else max = cnk->max;
switch (cnk->type) {
case CNK_FMT_STR:
if (maxlen != 0 && maxlen > currlen) {
if (maxlen > (currlen + cnk->len)) len = cnk->len;
else len = maxlen - currlen;
memcpy(&(buffer[currlen]), &(base[cnk->start]), len);
}
currlen += cnk->len;
break;
case CNK_INT:
case CNK_UINT:
fmtint(buffer, &currlen, maxlen, cnk->value, 10, min, max, cnk->flags);
break;
case CNK_OCTAL:
fmtint(buffer, &currlen, maxlen, cnk->value, 8, min, max, cnk->flags);
break;
case CNK_HEX:
fmtint(buffer, &currlen, maxlen, cnk->value, 16, min, max, cnk->flags);
break;
case CNK_FLOAT:
fmtfp(buffer, &currlen, maxlen, cnk->fvalue, min, max, cnk->flags);
break;
case CNK_CHAR:
dopr_outch(buffer, &currlen, maxlen, cnk->value);
break;
case CNK_STRING:
if (max == -1) {
max = strlen(cnk->strvalue);
}
fmtstr(buffer, &currlen, maxlen, cnk->strvalue, cnk->flags, min, max);
break;
case CNK_PTR:
fmtint(buffer, &currlen, maxlen, (long)(cnk->strvalue), 16, min, max, cnk->flags);
break;
case CNK_NUM:
if (cnk->cflags == DP_C_CHAR)
*((char *)(cnk->pnum)) = (char)currlen;
else if (cnk->cflags == DP_C_SHORT)
*((short int *)(cnk->pnum)) = (short int)currlen;
else if (cnk->cflags == DP_C_LONG)
*((long int *)(cnk->pnum)) = (long int)currlen;
else if (cnk->cflags == DP_C_LLONG)
*((LLONG *)(cnk->pnum)) = (LLONG)currlen;
else
*((int *)(cnk->pnum)) = (int)currlen;
break;
case CNK_PRCNT:
dopr_outch(buffer, &currlen, maxlen, '%');
break;
default:
/* what ?? */
goto done;
}
cnk = cnk->next;
}
if (maxlen != 0) {
if (currlen < maxlen - 1)
buffer[currlen] = '\0';
else if (maxlen > 0)
buffer[maxlen - 1] = '\0';
}
ret = currlen;
done:
while (chunks) {
cnk = chunks->next;
free(chunks);
chunks = cnk;
}
if (clist) {
for (pnum = 0; pnum < max_pos; pnum++) {
if (clist[pnum].chunks) free(clist[pnum].chunks);
}
free(clist);
}
return ret;
}
static void fmtstr(char *buffer, size_t *currlen, size_t maxlen,
char *value, int flags, int min, int max) {
int padlen, strln; /* amount to pad */
int cnt = 0;
#ifdef DEBUG_SNPRINTF
printf("fmtstr min=%d max=%d s=[%s]\n", min, max, value);
#endif
if (value == 0) {
value = "";
}
for (strln = 0; strln < max && value[strln]; ++strln); /* strlen */
padlen = min - strln;
if (padlen < 0)
padlen = 0;
if (flags & DP_F_MINUS)
padlen = -padlen; /* Left Justify */
while (padlen > 0) {
dopr_outch(buffer, currlen, maxlen, ' ');
--padlen;
}
while (*value && (cnt < max)) {
dopr_outch(buffer, currlen, maxlen, *value++);
++cnt;
}
while (padlen < 0) {
dopr_outch(buffer, currlen, maxlen, ' ');
++padlen;
}
}
/* Have to handle DP_F_NUM (ie 0x and 0 alternates) */
static void fmtint(char *buffer, size_t *currlen, size_t maxlen,
long value, int base, int min, int max, int flags) {
int signvalue = 0;
unsigned long uvalue;
char convert[20];
int place = 0;
int spadlen = 0; /* amount to space pad */
int zpadlen = 0; /* amount to zero pad */
int caps = 0;
if (max < 0)
max = 0;
uvalue = value;
if (!(flags & DP_F_UNSIGNED)) {
if (value < 0) {
signvalue = '-';
uvalue = -value;
} else {
if (flags & DP_F_PLUS) /* Do a sign (+/i) */
signvalue = '+';
else if (flags & DP_F_SPACE)
signvalue = ' ';
}
}
if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */
do {
convert[place++] =
(caps ? "0123456789ABCDEF" : "0123456789abcdef")
[uvalue % (unsigned)base ];
uvalue = (uvalue / (unsigned)base);
} while (uvalue && (place < 20));
if (place == 20) place--;
convert[place] = 0;
zpadlen = max - place;
spadlen = min - MAX(max, place) - (signvalue ? 1 : 0);
if (zpadlen < 0) zpadlen = 0;
if (spadlen < 0) spadlen = 0;
if (flags & DP_F_ZERO) {
zpadlen = MAX(zpadlen, spadlen);
spadlen = 0;
}
if (flags & DP_F_MINUS)
spadlen = -spadlen; /* Left Justifty */
#ifdef DEBUG_SNPRINTF
printf("zpad: %d, spad: %d, min: %d, max: %d, place: %d\n",
zpadlen, spadlen, min, max, place);
#endif
/* Spaces */
while (spadlen > 0) {
dopr_outch(buffer, currlen, maxlen, ' ');
--spadlen;
}
/* Sign */
if (signvalue)
dopr_outch(buffer, currlen, maxlen, signvalue);
/* Zeros */
if (zpadlen > 0) {
while (zpadlen > 0) {
dopr_outch(buffer, currlen, maxlen, '0');
--zpadlen;
}
}
/* Digits */
while (place > 0)
dopr_outch(buffer, currlen, maxlen, convert[--place]);
/* Left Justified spaces */
while (spadlen < 0) {
dopr_outch(buffer, currlen, maxlen, ' ');
++spadlen;
}
}
static LDOUBLE abs_val(LDOUBLE value) {
LDOUBLE result = value;
if (value < 0)
result = -value;
return result;
}
static LDOUBLE POW10(int exp) {
LDOUBLE result = 1;
while (exp) {
result *= 10;
exp--;
}
return result;
}
static LLONG ROUND(LDOUBLE value) {
LLONG intpart;
intpart = (LLONG)value;
value = value - intpart;
if (value >= 0.5) intpart++;
return intpart;
}
/* a replacement for modf that doesn't need the math library. Should
be portable, but slow */
static double my_modf(double x0, double *iptr) {
int i;
long l;
double x = x0;
double f = 1.0;
for (i = 0; i < 100; i++) {
l = (long)x;
if (l <= (x + 1) && l >= (x - 1)) break;
x *= 0.1;
f *= 10.0;
}
if (i == 100) {
/* yikes! the number is beyond what we can handle. What do we do? */
(*iptr) = 0;
return 0;
}
if (i != 0) {
double i2;
double ret;
ret = my_modf(x0 - l * f, &i2);
(*iptr) = l * f + i2;
return ret;
}
(*iptr) = l;
return x - (*iptr);
}
static void fmtfp(char *buffer, size_t *currlen, size_t maxlen,
LDOUBLE fvalue, int min, int max, int flags) {
int signvalue = 0;
double ufvalue;
char iconvert[311];
char fconvert[311];
int iplace = 0;
int fplace = 0;
int padlen = 0; /* amount to pad */
int zpadlen = 0;
int caps = 0;
int idx;
double intpart;
double fracpart;
double temp;
/*
* AIX manpage says the default is 0, but Solaris says the default
* is 6, and sprintf on AIX defaults to 6
*/
if (max < 0)
max = 6;
ufvalue = abs_val(fvalue);
if (fvalue < 0) {
signvalue = '-';
} else {
if (flags & DP_F_PLUS) { /* Do a sign (+/i) */
signvalue = '+';
} else {
if (flags & DP_F_SPACE)
signvalue = ' ';
}
}
#if 0
if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */
#endif
#if 0
if (max == 0) ufvalue += 0.5; /* if max = 0 we must round */
#endif
/*
* Sorry, we only support 9 digits past the decimal because of our
* conversion method
*/
if (max > 9)
max = 9;
/* We "cheat" by converting the fractional part to integer by
* multiplying by a factor of 10
*/
temp = ufvalue;
my_modf(temp, &intpart);
fracpart = ROUND((POW10(max)) * (ufvalue - intpart));
if (fracpart >= POW10(max)) {
intpart++;
fracpart -= POW10(max);
}
/* Convert integer part */
do {
temp = intpart * 0.1;
my_modf(temp, &intpart);
idx = (int)((temp - intpart + 0.05) * 10.0);
/* idx = (int) (((double)(temp*0.1) -intpart +0.05) *10.0); */
/* printf ("%llf, %f, %x\n", temp, intpart, idx); */
iconvert[iplace++] =
(caps ? "0123456789ABCDEF" : "0123456789abcdef")[idx];
} while (intpart && (iplace < 311));
if (iplace == 311) iplace--;
iconvert[iplace] = 0;
/* Convert fractional part */
if (fracpart) {
do {
temp = fracpart * 0.1;
my_modf(temp, &fracpart);
idx = (int)((temp - fracpart + 0.05) * 10.0);
/* idx = (int) ((((temp/10) -fracpart) +0.05) *10); */
/* printf ("%lf, %lf, %ld\n", temp, fracpart, idx ); */
fconvert[fplace++] =
(caps ? "0123456789ABCDEF" : "0123456789abcdef")[idx];
} while (fracpart && (fplace < 311));
if (fplace == 311) fplace--;
}
fconvert[fplace] = 0;
/* -1 for decimal point, another -1 if we are printing a sign */
padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
zpadlen = max - fplace;
if (zpadlen < 0) zpadlen = 0;
if (padlen < 0)
padlen = 0;
if (flags & DP_F_MINUS)
padlen = -padlen; /* Left Justifty */
if ((flags & DP_F_ZERO) && (padlen > 0)) {
if (signvalue) {
dopr_outch(buffer, currlen, maxlen, signvalue);
--padlen;
signvalue = 0;
}
while (padlen > 0) {
dopr_outch(buffer, currlen, maxlen, '0');
--padlen;
}
}
while (padlen > 0) {
dopr_outch(buffer, currlen, maxlen, ' ');
--padlen;
}
if (signvalue)
dopr_outch(buffer, currlen, maxlen, signvalue);
while (iplace > 0)
dopr_outch(buffer, currlen, maxlen, iconvert[--iplace]);
#ifdef DEBUG_SNPRINTF
printf("fmtfp: fplace=%d zpadlen=%d\n", fplace, zpadlen);
#endif
/*
* Decimal point. This should probably use locale to find the correct
* char to print out.
*/
if (max > 0) {
dopr_outch(buffer, currlen, maxlen, '.');
while (zpadlen > 0) {
dopr_outch(buffer, currlen, maxlen, '0');
--zpadlen;
}
while (fplace > 0)
dopr_outch(buffer, currlen, maxlen, fconvert[--fplace]);
}
while (padlen < 0) {
dopr_outch(buffer, currlen, maxlen, ' ');
++padlen;
}
}
static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) {
if (*currlen < maxlen) {
buffer[(*currlen)] = c;
}
(*currlen)++;
}
static struct pr_chunk *new_chunk(void) {
struct pr_chunk *new_c = (struct pr_chunk *)malloc(sizeof(struct pr_chunk));
if (!new_c)
return NULL;
new_c->type = 0;
new_c->num = 0;
new_c->min = 0;
new_c->min_star = NULL;
new_c->max = -1;
new_c->max_star = NULL;
new_c->flags = 0;
new_c->cflags = 0;
new_c->start = 0;
new_c->len = 0;
new_c->value = 0;
new_c->fvalue = 0;
new_c->strvalue = NULL;
new_c->pnum = NULL;
new_c->next = NULL;
return new_c;
}
static int add_cnk_list_entry(struct pr_chunk_x **list,
int max_num, struct pr_chunk *chunk) {
struct pr_chunk_x *l;
struct pr_chunk **c;
int max;
int cnum;
int i, pos;
if (chunk->num > max_num) {
max = chunk->num;
if (*list == NULL) {
l = (struct pr_chunk_x *)malloc(sizeof(struct pr_chunk_x) * max);
pos = 0;
} else {
l = (struct pr_chunk_x *)realloc(*list, sizeof(struct pr_chunk_x) * max);
pos = max_num;
}
if (l == NULL) {
for (i = 0; i < max; i++) {
if ((*list)[i].chunks) free((*list)[i].chunks);
}
return 0;
}
for (i = pos; i < max; i++) {
l[i].chunks = NULL;
l[i].num = 0;
}
} else {
l = *list;
max = max_num;
}
i = chunk->num - 1;
cnum = l[i].num + 1;
if (l[i].chunks == NULL) {
c = (struct pr_chunk **)malloc(sizeof(struct pr_chunk *) * cnum);
} else {
c = (struct pr_chunk **)realloc(l[i].chunks, sizeof(struct pr_chunk *) * cnum);
}
if (c == NULL) {
for (i = 0; i < max; i++) {
if (l[i].chunks) free(l[i].chunks);
}
return 0;
}
c[l[i].num] = chunk;
l[i].chunks = c;
l[i].num = cnum;
*list = l;
return max;
}
int smb_vsnprintf(char *str, size_t count, const char *fmt, va_list args) {
return dopr(str, count, fmt, args);
}
#define vsnprintf smb_vsnprintf
#endif
/* yes this really must be a ||. Don't muck with this (tridge)
*
* The logic for these two is that we need our own definition if the
* OS *either* has no definition of *sprintf, or if it does have one
* that doesn't work properly according to the autoconf test.
*/
#if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_VSNPRINTF)
int smb_snprintf(char *str, size_t count, const char *fmt, ...) {
size_t ret;
va_list ap;
va_start(ap, fmt);
ret = vsnprintf(str, count, fmt, ap);
va_end(ap);
return ret;
}
#define snprintf smb_snprintf
#endif
#endif
#ifndef HAVE_VASPRINTF
int vasprintf(char **ptr, const char *format, va_list ap) {
int ret;
va_list ap2;
VA_COPY(ap2, ap);
ret = vsnprintf(NULL, 0, format, ap2);
if (ret <= 0) return ret;
(*ptr) = (char *)malloc(ret + 1);
if (!*ptr) return -1;
VA_COPY(ap2, ap);
ret = vsnprintf(*ptr, ret + 1, format, ap2);
return ret;
}
#endif
#ifndef HAVE_ASPRINTF
int asprintf(char **ptr, const char *format, ...) {
va_list ap;
int ret;
*ptr = NULL;
va_start(ap, format);
ret = vasprintf(ptr, format, ap);
va_end(ap);
return ret;
}
#endif
#ifdef TEST_SNPRINTF
int sprintf(char *str, const char *fmt, ...);
int main(void) {
char buf1[1024];
char buf2[1024];
char *buf3;
char *fp_fmt[] = {
"%1.1f",
"%-1.5f",
"%1.5f",
"%123.9f",
"%10.5f",
"% 10.5f",
"%+22.9f",
"%+4.9f",
"%01.3f",
"%4f",
"%3.1f",
"%3.2f",
"%.0f",
"%f",
"%-8.8f",
"%-9.9f",
NULL
};
double fp_nums[] = { 6442452944.1234, -1.5, 134.21, 91340.2, 341.1234, 203.9, 0.96, 0.996,
0.9996, 1.996, 4.136, 5.030201, 0.00205,
/* END LIST */ 0
};
char *int_fmt[] = {
"%-1.5d",
"%1.5d",
"%123.9d",
"%5.5d",
"%10.5d",
"% 10.5d",
"%+22.33d",
"%01.3d",
"%4d",
"%d",
NULL
};
long int_nums[] = { -1, 134, 91340, 341, 0203, 0, 1234567890};
char *str_fmt[] = {
"%10.5s",
"%-10.5s",
"%5.10s",
"%-5.10s",
"%10.1s",
"%0.10s",
"%10.0s",
"%1.10s",
"%s",
"%.1s",
"%.10s",
"%10s",
NULL
};
char *str_vals[] = {"hello", "a", "", "a longer string", NULL};
int x, y;
int fail = 0;
int num = 0;
int l1, l2;
printf("Testing snprintf format codes against system sprintf...\n");
for (x = 0; fp_fmt[x] ; x++) {
for (y = 0; fp_nums[y] != 0 ; y++) {
buf1[0] = buf2[0] = '\0';
l1 = snprintf(NULL, 0, fp_fmt[x], fp_nums[y]);
l2 = snprintf(buf1, sizeof(buf1), fp_fmt[x], fp_nums[y]);
sprintf(buf2, fp_fmt[x], fp_nums[y]);
buf1[1023] = buf1[1023] = '\0';
if (strcmp(buf1, buf2) || (l1 != l2)) {
printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n",
fp_fmt[x], l1, buf1, l2, buf2);
fail++;
}
num++;
}
}
for (x = 0; int_fmt[x] ; x++) {
for (y = 0; int_nums[y] != 0 ; y++) {
buf1[0] = buf2[0] = '\0';
l1 = snprintf(NULL, 0, int_fmt[x], int_nums[y]);
l2 = snprintf(buf1, sizeof(buf1), int_fmt[x], int_nums[y]);
sprintf(buf2, int_fmt[x], int_nums[y]);
buf1[1023] = buf1[1023] = '\0';
if (strcmp(buf1, buf2) || (l1 != l2)) {
printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n",
int_fmt[x], l1, buf1, l2, buf2);
fail++;
}
num++;
}
}
for (x = 0; str_fmt[x] ; x++) {
for (y = 0; str_vals[y] != 0 ; y++) {
buf1[0] = buf2[0] = '\0';
l1 = snprintf(NULL, 0, str_fmt[x], str_vals[y]);
l2 = snprintf(buf1, sizeof(buf1), str_fmt[x], str_vals[y]);
sprintf(buf2, str_fmt[x], str_vals[y]);
buf1[1023] = buf1[1023] = '\0';
if (strcmp(buf1, buf2) || (l1 != l2)) {
printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n",
str_fmt[x], l1, buf1, l2, buf2);
fail++;
}
num++;
}
}
#define BUFSZ 2048
buf1[0] = buf2[0] = '\0';
if ((buf3 = malloc(BUFSZ)) == NULL) {
fail++;
} else {
num++;
memset(buf3, 'a', BUFSZ);
snprintf(buf1, sizeof(buf1), "%.*s", 1, buf3);
buf1[1023] = '\0';
if (strcmp(buf1, "a") != 0) {
printf("length limit buf1 '%s' expected 'a'\n", buf1);
fail++;
}
}
buf1[0] = buf2[0] = '\0';
l1 = snprintf(buf1, sizeof(buf1), "%4$*1$d %2$s %3$*1$.*1$f", 3, "pos test", 12.3456, 9);
l2 = sprintf(buf2, "%4$*1$d %2$s %3$*1$.*1$f", 3, "pos test", 12.3456, 9);
buf1[1023] = buf1[1023] = '\0';
if (strcmp(buf1, buf2) || (l1 != l2)) {
printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n",
"%4$*1$d %2$s %3$*1$.*1$f", l1, buf1, l2, buf2);
fail++;
}
buf1[0] = buf2[0] = '\0';
l1 = snprintf(buf1, sizeof(buf1), "%4$*4$d %2$s %3$*4$.*4$f", 3, "pos test", 12.3456, 9);
l2 = sprintf(buf2, "%4$*4$d %2$s %3$*4$.*4$f", 3, "pos test", 12.3456, 9);
buf1[1023] = buf1[1023] = '\0';
if (strcmp(buf1, buf2)) {
printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n",
"%4$*1$d %2$s %3$*1$.*1$f", l1, buf1, l2, buf2);
fail++;
}
#if 0
buf1[0] = buf2[0] = '\0';
l1 = snprintf(buf1, sizeof(buf1), "%lld", (LLONG)1234567890);
l2 = sprintf(buf2, "%lld", (LLONG)1234567890);
buf1[1023] = buf1[1023] = '\0';
if (strcmp(buf1, buf2)) {
printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n",
"%lld", l1, buf1, l2, buf2);
fail++;
}
buf1[0] = buf2[0] = '\0';
l1 = snprintf(buf1, sizeof(buf1), "%Lf", (LDOUBLE)890.1234567890123);
l2 = sprintf(buf2, "%Lf", (LDOUBLE)890.1234567890123);
buf1[1023] = buf1[1023] = '\0';
if (strcmp(buf1, buf2)) {
printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n",
"%Lf", l1, buf1, l2, buf2);
fail++;
}
#endif
printf("%d tests failed out of %d.\n", fail, num);
printf("seeing how many digits we support\n");
{
double v0 = 0.12345678901234567890123456789012345678901;
for (x = 0; x < 100; x++) {
double p = pow(10, x);
double r = v0 * p;
snprintf(buf1, sizeof(buf1), "%1.1f", r);
sprintf(buf2, "%1.1f", r);
if (strcmp(buf1, buf2)) {
printf("we seem to support %d digits\n", x - 1);
break;
}
}
}
return 0;
}
#endif /* TEST_SNPRINTF */
icinga-1.10.3/common/statusdata.c 0000664 0000000 0000000 00000041160 12276402000 0016632 0 ustar 00root root 0000000 0000000 /*****************************************************************************
*
* STATUSDATA.C - External status data for Icinga CGIs
*
* Copyright (c) 2000-2008 Ethan Galstad (egalstad@nagios.org)
* Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*****************************************************************************/
/*********** COMMON HEADER FILES ***********/
#include "../include/config.h"
#include "../include/common.h"
#include "../include/objects.h"
#include "../include/statusdata.h"
#ifdef NSCORE
#include "../include/icinga.h"
#include "../include/broker.h"
#endif
#ifdef NSCGI
#include "../include/cgiutils.h"
#endif
/**** IMPLEMENTATION SPECIFIC HEADER FILES ****/
#ifdef USE_XSDDEFAULT
#include "../xdata/xsddefault.h" /* default routines */
#endif
#ifdef NSCORE
extern int aggregate_status_updates;
#endif
#ifdef NSCGI
hoststatus *hoststatus_list = NULL;
hoststatus *hoststatus_list_tail = NULL;
servicestatus *servicestatus_list = NULL;
servicestatus *servicestatus_list_tail = NULL;
hoststatus **hoststatus_hashlist = NULL;
servicestatus **servicestatus_hashlist = NULL;
extern int use_pending_states;
#endif
#ifdef NSCORE
/******************************************************************/
/****************** TOP-LEVEL OUTPUT FUNCTIONS ********************/
/******************************************************************/
/* initializes status data at program start */
int initialize_status_data(char *config_file) {
int result = OK;
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XSDDEFAULT
result = xsddefault_initialize_status_data(config_file);
#endif
return result;
}
/* update all status data (aggregated dump) */
int update_all_status_data(void) {
int result = OK;
#ifdef USE_EVENT_BROKER
/* send data to event broker */
broker_aggregated_status_data(NEBTYPE_AGGREGATEDSTATUS_STARTDUMP, NEBFLAG_NONE, NEBATTR_NONE, NULL);
#endif
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XSDDEFAULT
result = xsddefault_save_status_data();
#endif
#ifdef USE_EVENT_BROKER
/* send data to event broker */
broker_aggregated_status_data(NEBTYPE_AGGREGATEDSTATUS_ENDDUMP, NEBFLAG_NONE, NEBATTR_NONE, NULL);
#endif
if (result != OK)
return ERROR;
return OK;
}
/* cleans up status data before program termination */
int cleanup_status_data(char *config_file, int delete_status_data) {
int result = OK;
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XSDDEFAULT
result = xsddefault_cleanup_status_data(config_file, delete_status_data);
#endif
return result;
}
/* updates program status info */
int update_program_status(int aggregated_dump) {
#ifdef USE_EVENT_BROKER
/* send data to event broker (non-aggregated dumps only) */
if (aggregated_dump == FALSE)
broker_program_status(NEBTYPE_PROGRAMSTATUS_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, NULL);
#endif
/* currently a noop if aggregated updates is TRUE */
/* update all status data if we're not aggregating updates */
if (aggregate_status_updates == FALSE)
update_all_status_data();
return OK;
}
/* updates host status info */
int update_host_status(host *hst, int aggregated_dump) {
#ifdef USE_EVENT_BROKER
/* send data to event broker (non-aggregated dumps only) */
if (aggregated_dump == FALSE)
broker_host_status(NEBTYPE_HOSTSTATUS_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, NULL);
#endif
/* currently a noop if aggregated updates is TRUE */
/* update all status data if we're not aggregating updates */
if (aggregate_status_updates == FALSE)
update_all_status_data();
return OK;
}
/* updates service status info */
int update_service_status(service *svc, int aggregated_dump) {
#ifdef USE_EVENT_BROKER
/* send data to event broker (non-aggregated dumps only) */
if (aggregated_dump == FALSE)
broker_service_status(NEBTYPE_SERVICESTATUS_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, NULL);
#endif
/* currently a noop if aggregated updates is TRUE */
/* update all status data if we're not aggregating updates */
if (aggregate_status_updates == FALSE)
update_all_status_data();
return OK;
}
/* updates contact status info */
int update_contact_status(contact *cntct, int aggregated_dump) {
#ifdef USE_EVENT_BROKER
/* send data to event broker (non-aggregated dumps only) */
if (aggregated_dump == FALSE)
broker_contact_status(NEBTYPE_CONTACTSTATUS_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, cntct, NULL);
#endif
/* currently a noop if aggregated updates is TRUE */
/* update all status data if we're not aggregating updates */
if (aggregate_status_updates == FALSE)
update_all_status_data();
return OK;
}
#endif
#ifdef NSCGI
/******************************************************************/
/******************* TOP-LEVEL INPUT FUNCTIONS ********************/
/******************************************************************/
/* reads in all status data */
int read_status_data(char *main_config_file, int options) {
int result = OK;
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XSDDEFAULT
result = xsddefault_read_status_data(main_config_file, options);
#endif
return result;
}
/******************************************************************/
/****************** CHAINED HASH FUNCTIONS ************************/
/******************************************************************/
/* adds hoststatus to hash list in memory */
int add_hoststatus_to_hashlist(hoststatus *new_hoststatus) {
hoststatus *temp_hoststatus = NULL;
hoststatus *lastpointer = NULL;
int hashslot = 0;
int i = 0;
/* initialize hash list */
if (hoststatus_hashlist == NULL) {
hoststatus_hashlist = (hoststatus **)malloc(sizeof(hoststatus *) * HOSTSTATUS_HASHSLOTS);
if (hoststatus_hashlist == NULL)
return 0;
for (i = 0; i < HOSTSTATUS_HASHSLOTS; i++)
hoststatus_hashlist[i] = NULL;
}
if (!new_hoststatus)
return 0;
hashslot = hashfunc(new_hoststatus->host_name, NULL, HOSTSTATUS_HASHSLOTS);
lastpointer = NULL;
for (temp_hoststatus = hoststatus_hashlist[hashslot]; temp_hoststatus && compare_hashdata(temp_hoststatus->host_name, NULL, new_hoststatus->host_name, NULL) < 0; temp_hoststatus = temp_hoststatus->nexthash)
lastpointer = temp_hoststatus;
if (!temp_hoststatus || (compare_hashdata(temp_hoststatus->host_name, NULL, new_hoststatus->host_name, NULL) != 0)) {
if (lastpointer)
lastpointer->nexthash = new_hoststatus;
else
hoststatus_hashlist[hashslot] = new_hoststatus;
new_hoststatus->nexthash = temp_hoststatus;
return 1;
}
/* else already exists */
return 0;
}
int add_servicestatus_to_hashlist(servicestatus *new_servicestatus) {
servicestatus *temp_servicestatus = NULL, *lastpointer = NULL;
int hashslot = 0;
int i = 0;
/* initialize hash list */
if (servicestatus_hashlist == NULL) {
servicestatus_hashlist = (servicestatus **)malloc(sizeof(servicestatus *) * SERVICESTATUS_HASHSLOTS);
if (servicestatus_hashlist == NULL)
return 0;
for (i = 0; i < SERVICESTATUS_HASHSLOTS; i++)
servicestatus_hashlist[i] = NULL;
}
if (!new_servicestatus)
return 0;
hashslot = hashfunc(new_servicestatus->host_name, new_servicestatus->description, SERVICESTATUS_HASHSLOTS);
lastpointer = NULL;
for (temp_servicestatus = servicestatus_hashlist[hashslot]; temp_servicestatus && compare_hashdata(temp_servicestatus->host_name, temp_servicestatus->description, new_servicestatus->host_name, new_servicestatus->description) < 0; temp_servicestatus = temp_servicestatus->nexthash)
lastpointer = temp_servicestatus;
if (!temp_servicestatus || (compare_hashdata(temp_servicestatus->host_name, temp_servicestatus->description, new_servicestatus->host_name, new_servicestatus->description) != 0)) {
if (lastpointer)
lastpointer->nexthash = new_servicestatus;
else
servicestatus_hashlist[hashslot] = new_servicestatus;
new_servicestatus->nexthash = temp_servicestatus;
return 1;
}
/* else already exists */
return 0;
}
/******************************************************************/
/********************** ADDITION FUNCTIONS ************************/
/******************************************************************/
/* adds a host status entry to the list in memory */
int add_host_status(hoststatus *new_hoststatus) {
char date_string[MAX_DATETIME_LENGTH];
/* make sure we have what we need */
if (new_hoststatus == NULL)
return ERROR;
if (new_hoststatus->host_name == NULL)
return ERROR;
/* massage host status a bit */
if (new_hoststatus != NULL) {
switch (new_hoststatus->status) {
case 0:
new_hoststatus->status = HOST_UP;
break;
case 1:
new_hoststatus->status = HOST_DOWN;
break;
case 2:
new_hoststatus->status = HOST_UNREACHABLE;
break;
default:
new_hoststatus->status = HOST_UP;
break;
}
if (new_hoststatus->has_been_checked == FALSE) {
if (use_pending_states == TRUE)
new_hoststatus->status = HOST_PENDING;
my_free(new_hoststatus->plugin_output);
if (new_hoststatus->should_be_scheduled == TRUE) {
get_time_string(&new_hoststatus->next_check, date_string, sizeof(date_string), LONG_DATE_TIME);
asprintf(&new_hoststatus->plugin_output, "Host check scheduled for %s", date_string);
} else {
/* passive-only hosts that have just been scheduled for a forced check */
if (new_hoststatus->checks_enabled == FALSE && new_hoststatus->next_check != (time_t)0L && (new_hoststatus->check_options & CHECK_OPTION_FORCE_EXECUTION)) {
get_time_string(&new_hoststatus->next_check, date_string, sizeof(date_string), LONG_DATE_TIME);
asprintf(&new_hoststatus->plugin_output, "Forced host check scheduled for %s", date_string);
}
/* passive-only hosts not scheduled to be checked */
else
new_hoststatus->plugin_output = (char *)strdup("Host is not scheduled to be checked...");
}
}
}
new_hoststatus->next = NULL;
new_hoststatus->nexthash = NULL;
/* add new hoststatus to hoststatus chained hash list */
if (!add_hoststatus_to_hashlist(new_hoststatus))
return ERROR;
/* object cache file is already sorted, so just add new items to end of list */
if (hoststatus_list == NULL) {
hoststatus_list = new_hoststatus;
hoststatus_list_tail = new_hoststatus;
} else {
hoststatus_list_tail->next = new_hoststatus;
hoststatus_list_tail = new_hoststatus;
}
return OK;
}
/* adds a service status entry to the list in memory */
int add_service_status(servicestatus *new_svcstatus) {
char date_string[MAX_DATETIME_LENGTH];
/* make sure we have what we need */
if (new_svcstatus == NULL)
return ERROR;
if (new_svcstatus->host_name == NULL || new_svcstatus->description == NULL)
return ERROR;
/* massage service status a bit */
if (new_svcstatus != NULL) {
switch (new_svcstatus->status) {
case 0:
new_svcstatus->status = SERVICE_OK;
break;
case 1:
new_svcstatus->status = SERVICE_WARNING;
break;
case 2:
new_svcstatus->status = SERVICE_CRITICAL;
break;
case 3:
new_svcstatus->status = SERVICE_UNKNOWN;
break;
default:
new_svcstatus->status = SERVICE_OK;
break;
}
if (new_svcstatus->has_been_checked == FALSE) {
if (use_pending_states == TRUE)
new_svcstatus->status = SERVICE_PENDING;
my_free(new_svcstatus->plugin_output);
if (new_svcstatus->should_be_scheduled == TRUE) {
get_time_string(&new_svcstatus->next_check, date_string, sizeof(date_string), LONG_DATE_TIME);
asprintf(&new_svcstatus->plugin_output, "Service check scheduled for %s", date_string);
} else {
/* passive-only services that have just been scheduled for a forced check */
if (new_svcstatus->checks_enabled == FALSE && new_svcstatus->next_check != (time_t)0L && (new_svcstatus->check_options & CHECK_OPTION_FORCE_EXECUTION)) {
get_time_string(&new_svcstatus->next_check, date_string, sizeof(date_string), LONG_DATE_TIME);
asprintf(&new_svcstatus->plugin_output, "Forced service check scheduled for %s", date_string);
}
/* passive-only services not scheduled to be checked */
else
new_svcstatus->plugin_output = (char *)strdup("Service is not scheduled to be checked...");
}
}
}
new_svcstatus->next = NULL;
new_svcstatus->nexthash = NULL;
/* add new servicestatus to servicestatus chained hash list */
if (!add_servicestatus_to_hashlist(new_svcstatus))
return ERROR;
/* object cache file is already sorted, so just add new items to end of list */
if (servicestatus_list == NULL) {
servicestatus_list = new_svcstatus;
servicestatus_list_tail = new_svcstatus;
} else {
servicestatus_list_tail->next = new_svcstatus;
servicestatus_list_tail = new_svcstatus;
}
return OK;
}
/******************************************************************/
/*********************** CLEANUP FUNCTIONS ************************/
/******************************************************************/
/* free all memory for status data */
void free_status_data(void) {
hoststatus *this_hoststatus = NULL;
hoststatus *next_hoststatus = NULL;
servicestatus *this_svcstatus = NULL;
servicestatus *next_svcstatus = NULL;
/* free memory for the host status list */
for (this_hoststatus = hoststatus_list; this_hoststatus != NULL; this_hoststatus = next_hoststatus) {
next_hoststatus = this_hoststatus->next;
my_free(this_hoststatus->host_name);
my_free(this_hoststatus->plugin_output);
my_free(this_hoststatus->long_plugin_output);
my_free(this_hoststatus->perf_data);
my_free(this_hoststatus->check_source);
my_free(this_hoststatus);
}
/* free memory for the service status list */
for (this_svcstatus = servicestatus_list; this_svcstatus != NULL; this_svcstatus = next_svcstatus) {
next_svcstatus = this_svcstatus->next;
my_free(this_svcstatus->host_name);
my_free(this_svcstatus->description);
my_free(this_svcstatus->plugin_output);
my_free(this_svcstatus->long_plugin_output);
my_free(this_svcstatus->perf_data);
my_free(this_svcstatus->check_source);
my_free(this_svcstatus);
}
/* free hash lists reset list pointers */
my_free(hoststatus_hashlist);
my_free(servicestatus_hashlist);
hoststatus_list = NULL;
servicestatus_list = NULL;
return;
}
/******************************************************************/
/************************ SEARCH FUNCTIONS ************************/
/******************************************************************/
/* find a host status entry */
hoststatus *find_hoststatus(char *host_name) {
hoststatus *temp_hoststatus = NULL;
if (host_name == NULL || hoststatus_hashlist == NULL)
return NULL;
for (temp_hoststatus = hoststatus_hashlist[hashfunc(host_name, NULL, HOSTSTATUS_HASHSLOTS)]; temp_hoststatus && compare_hashdata(temp_hoststatus->host_name, NULL, host_name, NULL) < 0; temp_hoststatus = temp_hoststatus->nexthash);
if (temp_hoststatus && (compare_hashdata(temp_hoststatus->host_name, NULL, host_name, NULL) == 0))
return temp_hoststatus;
return NULL;
}
/* find a service status entry */
servicestatus *find_servicestatus(char *host_name, char *svc_desc) {
servicestatus *temp_servicestatus = NULL;
if (host_name == NULL || svc_desc == NULL || servicestatus_hashlist == NULL)
return NULL;
for (temp_servicestatus = servicestatus_hashlist[hashfunc(host_name, svc_desc, SERVICESTATUS_HASHSLOTS)]; temp_servicestatus && compare_hashdata(temp_servicestatus->host_name, temp_servicestatus->description, host_name, svc_desc) < 0; temp_servicestatus = temp_servicestatus->nexthash);
if (temp_servicestatus && (compare_hashdata(temp_servicestatus->host_name, temp_servicestatus->description, host_name, svc_desc) == 0))
return temp_servicestatus;
return NULL;
}
/******************************************************************/
/*********************** UTILITY FUNCTIONS ************************/
/******************************************************************/
/* gets the total number of services of a certain state for a specific host */
int get_servicestatus_count(char *host_name, int type) {
servicestatus *temp_status = NULL;
int count = 0;
if (host_name == NULL)
return 0;
for (temp_status = servicestatus_list; temp_status != NULL; temp_status = temp_status->next) {
if (temp_status->status & type) {
if (!strcmp(host_name, temp_status->host_name))
count++;
}
}
return count;
}
#endif
icinga-1.10.3/config.guess 0000775 0000000 0000000 00000126703 12276402000 0015350 0 ustar 00root root 0000000 0000000 #! /bin/sh
# Attempt to guess a canonical system name.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
# Inc.
timestamp='2006-12-08'
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# Originally written by Per Bothner .
# Please send patches to . Submit a context
# diff and a properly formatted ChangeLog entry.
#
# This script attempts to guess a canonical system name similar to
# config.sub. If it succeeds, it prints the system name on stdout, and
# exits with 0. Otherwise, it exits with 1.
#
# The plan is that this can be called by configure scripts if you
# don't specify an explicit build system type.
me=`echo "$0" | sed -e 's,.*/,,'`
usage="\
Usage: $0 [OPTION]
Output the configuration name of the system \`$me' is run on.
Operation modes:
-h, --help print this help, then exit
-t, --time-stamp print date of last modification, then exit
-v, --version print version number, then exit
Report bugs and patches to ."
version="\
GNU config.guess ($timestamp)
Originally written by Per Bothner.
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
help="
Try \`$me --help' for more information."
# Parse command line
while test $# -gt 0 ; do
case $1 in
--time-stamp | --time* | -t )
echo "$timestamp" ; exit ;;
--version | -v )
echo "$version" ; exit ;;
--help | --h* | -h )
echo "$usage"; exit ;;
-- ) # Stop option processing
shift; break ;;
- ) # Use stdin as input.
break ;;
-* )
echo "$me: invalid option $1$help" >&2
exit 1 ;;
* )
break ;;
esac
done
if test $# != 0; then
echo "$me: too many arguments$help" >&2
exit 1
fi
trap 'exit 1' 1 2 15
# CC_FOR_BUILD -- compiler used by this script. Note that the use of a
# compiler to aid in system detection is discouraged as it requires
# temporary files to be created and, as you can see below, it is a
# headache to deal with in a portable fashion.
# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
# use `HOST_CC' if defined, but it is deprecated.
# Portable tmp directory creation inspired by the Autoconf team.
set_cc_for_build='
trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
: ${TMPDIR=/tmp} ;
{ tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
{ test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
{ tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
{ echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
dummy=$tmp/dummy ;
tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
case $CC_FOR_BUILD,$HOST_CC,$CC in
,,) echo "int x;" > $dummy.c ;
for c in cc gcc c89 c99 ; do
if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
CC_FOR_BUILD="$c"; break ;
fi ;
done ;
if test x"$CC_FOR_BUILD" = x ; then
CC_FOR_BUILD=no_compiler_found ;
fi
;;
,,*) CC_FOR_BUILD=$CC ;;
,*,*) CC_FOR_BUILD=$HOST_CC ;;
esac ; set_cc_for_build= ;'
# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
# (ghazi@noc.rutgers.edu 1994-08-24)
if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
PATH=$PATH:/.attbin ; export PATH
fi
UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
# Note: order is significant - the case branches are not exclusive.
case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
*:NetBSD:*:*)
# NetBSD (nbsd) targets should (where applicable) match one or
# more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*,
# *-*-netbsdecoff* and *-*-netbsd*. For targets that recently
# switched to ELF, *-*-netbsd* would select the old
# object file format. This provides both forward
# compatibility and a consistent mechanism for selecting the
# object file format.
#
# Note: NetBSD doesn't particularly care about the vendor
# portion of the name. We always set it to "unknown".
sysctl="sysctl -n hw.machine_arch"
UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \
/usr/sbin/$sysctl 2>/dev/null || echo unknown)`
case "${UNAME_MACHINE_ARCH}" in
armeb) machine=armeb-unknown ;;
arm*) machine=arm-unknown ;;
sh3el) machine=shl-unknown ;;
sh3eb) machine=sh-unknown ;;
sh5el) machine=sh5le-unknown ;;
*) machine=${UNAME_MACHINE_ARCH}-unknown ;;
esac
# The Operating System including object format, if it has switched
# to ELF recently, or will in the future.
case "${UNAME_MACHINE_ARCH}" in
arm*|i386|m68k|ns32k|sh3*|sparc|vax)
eval $set_cc_for_build
if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
| grep __ELF__ >/dev/null
then
# Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
# Return netbsd for either. FIX?
os=netbsd
else
os=netbsdelf
fi
;;
*)
os=netbsd
;;
esac
# The OS release
# Debian GNU/NetBSD machines have a different userland, and
# thus, need a distinct triplet. However, they do not need
# kernel version information, so it can be replaced with a
# suitable tag, in the style of linux-gnu.
case "${UNAME_VERSION}" in
Debian*)
release='-gnu'
;;
*)
release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
;;
esac
# Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
# contains redundant information, the shorter form:
# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
echo "${machine}-${os}${release}"
exit ;;
*:OpenBSD:*:*)
UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
exit ;;
*:ekkoBSD:*:*)
echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
exit ;;
*:SolidBSD:*:*)
echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE}
exit ;;
macppc:MirBSD:*:*)
echo powerpc-unknown-mirbsd${UNAME_RELEASE}
exit ;;
*:MirBSD:*:*)
echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}
exit ;;
alpha:OSF1:*:*)
case $UNAME_RELEASE in
*4.0)
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
;;
*5.*)
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
;;
esac
# According to Compaq, /usr/sbin/psrinfo has been available on
# OSF/1 and Tru64 systems produced since 1995. I hope that
# covers most systems running today. This code pipes the CPU
# types through head -n 1, so we only detect the type of CPU 0.
ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1`
case "$ALPHA_CPU_TYPE" in
"EV4 (21064)")
UNAME_MACHINE="alpha" ;;
"EV4.5 (21064)")
UNAME_MACHINE="alpha" ;;
"LCA4 (21066/21068)")
UNAME_MACHINE="alpha" ;;
"EV5 (21164)")
UNAME_MACHINE="alphaev5" ;;
"EV5.6 (21164A)")
UNAME_MACHINE="alphaev56" ;;
"EV5.6 (21164PC)")
UNAME_MACHINE="alphapca56" ;;
"EV5.7 (21164PC)")
UNAME_MACHINE="alphapca57" ;;
"EV6 (21264)")
UNAME_MACHINE="alphaev6" ;;
"EV6.7 (21264A)")
UNAME_MACHINE="alphaev67" ;;
"EV6.8CB (21264C)")
UNAME_MACHINE="alphaev68" ;;
"EV6.8AL (21264B)")
UNAME_MACHINE="alphaev68" ;;
"EV6.8CX (21264D)")
UNAME_MACHINE="alphaev68" ;;
"EV6.9A (21264/EV69A)")
UNAME_MACHINE="alphaev69" ;;
"EV7 (21364)")
UNAME_MACHINE="alphaev7" ;;
"EV7.9 (21364A)")
UNAME_MACHINE="alphaev79" ;;
esac
# A Pn.n version is a patched version.
# A Vn.n version is a released version.
# A Tn.n version is a released field test version.
# A Xn.n version is an unreleased experimental baselevel.
# 1.2 uses "1.2" for uname -r.
echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
exit ;;
Alpha\ *:Windows_NT*:*)
# How do we know it's Interix rather than the generic POSIX subsystem?
# Should we change UNAME_MACHINE based on the output of uname instead
# of the specific Alpha model?
echo alpha-pc-interix
exit ;;
21064:Windows_NT:50:3)
echo alpha-dec-winnt3.5
exit ;;
Amiga*:UNIX_System_V:4.0:*)
echo m68k-unknown-sysv4
exit ;;
*:[Aa]miga[Oo][Ss]:*:*)
echo ${UNAME_MACHINE}-unknown-amigaos
exit ;;
*:[Mm]orph[Oo][Ss]:*:*)
echo ${UNAME_MACHINE}-unknown-morphos
exit ;;
*:OS/390:*:*)
echo i370-ibm-openedition
exit ;;
*:z/VM:*:*)
echo s390-ibm-zvmoe
exit ;;
*:OS400:*:*)
echo powerpc-ibm-os400
exit ;;
arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
echo arm-acorn-riscix${UNAME_RELEASE}
exit ;;
arm:riscos:*:*|arm:RISCOS:*:*)
echo arm-unknown-riscos
exit ;;
SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
echo hppa1.1-hitachi-hiuxmpp
exit ;;
Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
# akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
if test "`(/bin/universe) 2>/dev/null`" = att ; then
echo pyramid-pyramid-sysv3
else
echo pyramid-pyramid-bsd
fi
exit ;;
NILE*:*:*:dcosx)
echo pyramid-pyramid-svr4
exit ;;
DRS?6000:unix:4.0:6*)
echo sparc-icl-nx6
exit ;;
DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
case `/usr/bin/uname -p` in
sparc) echo sparc-icl-nx7; exit ;;
esac ;;
sun4H:SunOS:5.*:*)
echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit ;;
sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit ;;
i86pc:SunOS:5.*:*)
echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit ;;
sun4*:SunOS:6*:*)
# According to config.sub, this is the proper way to canonicalize
# SunOS6. Hard to guess exactly what SunOS6 will be like, but
# it's likely to be more like Solaris than SunOS4.
echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit ;;
sun4*:SunOS:*:*)
case "`/usr/bin/arch -k`" in
Series*|S4*)
UNAME_RELEASE=`uname -v`
;;
esac
# Japanese Language versions have a version number like `4.1.3-JL'.
echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
exit ;;
sun3*:SunOS:*:*)
echo m68k-sun-sunos${UNAME_RELEASE}
exit ;;
sun*:*:4.2BSD:*)
UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
case "`/bin/arch`" in
sun3)
echo m68k-sun-sunos${UNAME_RELEASE}
;;
sun4)
echo sparc-sun-sunos${UNAME_RELEASE}
;;
esac
exit ;;
aushp:SunOS:*:*)
echo sparc-auspex-sunos${UNAME_RELEASE}
exit ;;
# The situation for MiNT is a little confusing. The machine name
# can be virtually everything (everything which is not
# "atarist" or "atariste" at least should have a processor
# > m68000). The system name ranges from "MiNT" over "FreeMiNT"
# to the lowercase version "mint" (or "freemint"). Finally
# the system name "TOS" denotes a system which is actually not
# MiNT. But MiNT is downward compatible to TOS, so this should
# be no problem.
atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
echo m68k-atari-mint${UNAME_RELEASE}
exit ;;
atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
echo m68k-atari-mint${UNAME_RELEASE}
exit ;;
*falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
echo m68k-atari-mint${UNAME_RELEASE}
exit ;;
milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
echo m68k-milan-mint${UNAME_RELEASE}
exit ;;
hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
echo m68k-hades-mint${UNAME_RELEASE}
exit ;;
*:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
echo m68k-unknown-mint${UNAME_RELEASE}
exit ;;
m68k:machten:*:*)
echo m68k-apple-machten${UNAME_RELEASE}
exit ;;
powerpc:machten:*:*)
echo powerpc-apple-machten${UNAME_RELEASE}
exit ;;
RISC*:Mach:*:*)
echo mips-dec-mach_bsd4.3
exit ;;
RISC*:ULTRIX:*:*)
echo mips-dec-ultrix${UNAME_RELEASE}
exit ;;
VAX*:ULTRIX*:*:*)
echo vax-dec-ultrix${UNAME_RELEASE}
exit ;;
2020:CLIX:*:* | 2430:CLIX:*:*)
echo clipper-intergraph-clix${UNAME_RELEASE}
exit ;;
mips:*:*:UMIPS | mips:*:*:RISCos)
eval $set_cc_for_build
sed 's/^ //' << EOF >$dummy.c
#ifdef __cplusplus
#include /* for printf() prototype */
int main (int argc, char *argv[]) {
#else
int main (argc, argv) int argc; char *argv[]; {
#endif
#if defined (host_mips) && defined (MIPSEB)
#if defined (SYSTYPE_SYSV)
printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0);
#endif
#if defined (SYSTYPE_SVR4)
printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0);
#endif
#if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0);
#endif
#endif
exit (-1);
}
EOF
$CC_FOR_BUILD -o $dummy $dummy.c &&
dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` &&
SYSTEM_NAME=`$dummy $dummyarg` &&
{ echo "$SYSTEM_NAME"; exit; }
echo mips-mips-riscos${UNAME_RELEASE}
exit ;;
Motorola:PowerMAX_OS:*:*)
echo powerpc-motorola-powermax
exit ;;
Motorola:*:4.3:PL8-*)
echo powerpc-harris-powermax
exit ;;
Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
echo powerpc-harris-powermax
exit ;;
Night_Hawk:Power_UNIX:*:*)
echo powerpc-harris-powerunix
exit ;;
m88k:CX/UX:7*:*)
echo m88k-harris-cxux7
exit ;;
m88k:*:4*:R4*)
echo m88k-motorola-sysv4
exit ;;
m88k:*:3*:R3*)
echo m88k-motorola-sysv3
exit ;;
AViiON:dgux:*:*)
# DG/UX returns AViiON for all architectures
UNAME_PROCESSOR=`/usr/bin/uname -p`
if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
then
if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
[ ${TARGET_BINARY_INTERFACE}x = x ]
then
echo m88k-dg-dgux${UNAME_RELEASE}
else
echo m88k-dg-dguxbcs${UNAME_RELEASE}
fi
else
echo i586-dg-dgux${UNAME_RELEASE}
fi
exit ;;
M88*:DolphinOS:*:*) # DolphinOS (SVR3)
echo m88k-dolphin-sysv3
exit ;;
M88*:*:R3*:*)
# Delta 88k system running SVR3
echo m88k-motorola-sysv3
exit ;;
XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
echo m88k-tektronix-sysv3
exit ;;
Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
echo m68k-tektronix-bsd
exit ;;
*:IRIX*:*:*)
echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
exit ;;
????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id
exit ;; # Note that: echo "'`uname -s`'" gives 'AIX '
i*86:AIX:*:*)
echo i386-ibm-aix
exit ;;
ia64:AIX:*:*)
if [ -x /usr/bin/oslevel ] ; then
IBM_REV=`/usr/bin/oslevel`
else
IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
fi
echo ${UNAME_MACHINE}-ibm-aix${IBM_REV}
exit ;;
*:AIX:2:3)
if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
eval $set_cc_for_build
sed 's/^ //' << EOF >$dummy.c
#include
main()
{
if (!__power_pc())
exit(1);
puts("powerpc-ibm-aix3.2.5");
exit(0);
}
EOF
if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy`
then
echo "$SYSTEM_NAME"
else
echo rs6000-ibm-aix3.2.5
fi
elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
echo rs6000-ibm-aix3.2.4
else
echo rs6000-ibm-aix3.2
fi
exit ;;
*:AIX:*:[45])
IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
IBM_ARCH=rs6000
else
IBM_ARCH=powerpc
fi
if [ -x /usr/bin/oslevel ] ; then
IBM_REV=`/usr/bin/oslevel`
else
IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
fi
echo ${IBM_ARCH}-ibm-aix${IBM_REV}
exit ;;
*:AIX:*:*)
echo rs6000-ibm-aix
exit ;;
ibmrt:4.4BSD:*|romp-ibm:BSD:*)
echo romp-ibm-bsd4.4
exit ;;
ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and
echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to
exit ;; # report: romp-ibm BSD 4.3
*:BOSX:*:*)
echo rs6000-bull-bosx
exit ;;
DPX/2?00:B.O.S.:*:*)
echo m68k-bull-sysv3
exit ;;
9000/[34]??:4.3bsd:1.*:*)
echo m68k-hp-bsd
exit ;;
hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
echo m68k-hp-bsd4.4
exit ;;
9000/[34678]??:HP-UX:*:*)
HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
case "${UNAME_MACHINE}" in
9000/31? ) HP_ARCH=m68000 ;;
9000/[34]?? ) HP_ARCH=m68k ;;
9000/[678][0-9][0-9])
if [ -x /usr/bin/getconf ]; then
sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
case "${sc_cpu_version}" in
523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
532) # CPU_PA_RISC2_0
case "${sc_kernel_bits}" in
32) HP_ARCH="hppa2.0n" ;;
64) HP_ARCH="hppa2.0w" ;;
'') HP_ARCH="hppa2.0" ;; # HP-UX 10.20
esac ;;
esac
fi
if [ "${HP_ARCH}" = "" ]; then
eval $set_cc_for_build
sed 's/^ //' << EOF >$dummy.c
#define _HPUX_SOURCE
#include
#include
int main ()
{
#if defined(_SC_KERNEL_BITS)
long bits = sysconf(_SC_KERNEL_BITS);
#endif
long cpu = sysconf (_SC_CPU_VERSION);
switch (cpu)
{
case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
case CPU_PA_RISC2_0:
#if defined(_SC_KERNEL_BITS)
switch (bits)
{
case 64: puts ("hppa2.0w"); break;
case 32: puts ("hppa2.0n"); break;
default: puts ("hppa2.0"); break;
} break;
#else /* !defined(_SC_KERNEL_BITS) */
puts ("hppa2.0"); break;
#endif
default: puts ("hppa1.0"); break;
}
exit (0);
}
EOF
(CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
test -z "$HP_ARCH" && HP_ARCH=hppa
fi ;;
esac
if [ ${HP_ARCH} = "hppa2.0w" ]
then
eval $set_cc_for_build
# hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
# 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler
# generating 64-bit code. GNU and HP use different nomenclature:
#
# $ CC_FOR_BUILD=cc ./config.guess
# => hppa2.0w-hp-hpux11.23
# $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess
# => hppa64-hp-hpux11.23
if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) |
grep __LP64__ >/dev/null
then
HP_ARCH="hppa2.0w"
else
HP_ARCH="hppa64"
fi
fi
echo ${HP_ARCH}-hp-hpux${HPUX_REV}
exit ;;
ia64:HP-UX:*:*)
HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
echo ia64-hp-hpux${HPUX_REV}
exit ;;
3050*:HI-UX:*:*)
eval $set_cc_for_build
sed 's/^ //' << EOF >$dummy.c
#include
int
main ()
{
long cpu = sysconf (_SC_CPU_VERSION);
/* The order matters, because CPU_IS_HP_MC68K erroneously returns
true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct
results, however. */
if (CPU_IS_PA_RISC (cpu))
{
switch (cpu)
{
case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
default: puts ("hppa-hitachi-hiuxwe2"); break;
}
}
else if (CPU_IS_HP_MC68K (cpu))
puts ("m68k-hitachi-hiuxwe2");
else puts ("unknown-hitachi-hiuxwe2");
exit (0);
}
EOF
$CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` &&
{ echo "$SYSTEM_NAME"; exit; }
echo unknown-hitachi-hiuxwe2
exit ;;
9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
echo hppa1.1-hp-bsd
exit ;;
9000/8??:4.3bsd:*:*)
echo hppa1.0-hp-bsd
exit ;;
*9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
echo hppa1.0-hp-mpeix
exit ;;
hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
echo hppa1.1-hp-osf
exit ;;
hp8??:OSF1:*:*)
echo hppa1.0-hp-osf
exit ;;
i*86:OSF1:*:*)
if [ -x /usr/sbin/sysversion ] ; then
echo ${UNAME_MACHINE}-unknown-osf1mk
else
echo ${UNAME_MACHINE}-unknown-osf1
fi
exit ;;
parisc*:Lites*:*:*)
echo hppa1.1-hp-lites
exit ;;
C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
echo c1-convex-bsd
exit ;;
C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
if getsysinfo -f scalar_acc
then echo c32-convex-bsd
else echo c2-convex-bsd
fi
exit ;;
C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
echo c34-convex-bsd
exit ;;
C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
echo c38-convex-bsd
exit ;;
C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
echo c4-convex-bsd
exit ;;
CRAY*Y-MP:*:*:*)
echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
exit ;;
CRAY*[A-Z]90:*:*:*)
echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
| sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
-e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
-e 's/\.[^.]*$/.X/'
exit ;;
CRAY*TS:*:*:*)
echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
exit ;;
CRAY*T3E:*:*:*)
echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
exit ;;
CRAY*SV1:*:*:*)
echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
exit ;;
*:UNICOS/mp:*:*)
echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
exit ;;
F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
exit ;;
5000:UNIX_System_V:4.*:*)
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
exit ;;
i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
exit ;;
sparc*:BSD/OS:*:*)
echo sparc-unknown-bsdi${UNAME_RELEASE}
exit ;;
*:BSD/OS:*:*)
echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
exit ;;
*:FreeBSD:*:*)
case ${UNAME_MACHINE} in
pc98)
echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
amd64)
echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
*)
echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
esac
exit ;;
i*:CYGWIN*:*)
echo ${UNAME_MACHINE}-pc-cygwin
exit ;;
i*:MINGW*:*)
echo ${UNAME_MACHINE}-pc-mingw32
exit ;;
i*:windows32*:*)
# uname -m includes "-pc" on this system.
echo ${UNAME_MACHINE}-mingw32
exit ;;
i*:PW*:*)
echo ${UNAME_MACHINE}-pc-pw32
exit ;;
x86:Interix*:[3456]*)
echo i586-pc-interix${UNAME_RELEASE}
exit ;;
EM64T:Interix*:[3456]* | authenticamd:Interix*:[3456]*)
echo x86_64-unknown-interix${UNAME_RELEASE}
exit ;;
[345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
echo i${UNAME_MACHINE}-pc-mks
exit ;;
i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
# How do we know it's Interix rather than the generic POSIX subsystem?
# It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
# UNAME_MACHINE based on the output of uname instead of i386?
echo i586-pc-interix
exit ;;
i*:UWIN*:*)
echo ${UNAME_MACHINE}-pc-uwin
exit ;;
amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
echo x86_64-unknown-cygwin
exit ;;
p*:CYGWIN*:*)
echo powerpcle-unknown-cygwin
exit ;;
prep*:SunOS:5.*:*)
echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit ;;
*:GNU:*:*)
# the GNU system
echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
exit ;;
*:GNU/*:*:*)
# other systems with GNU libc and userland
echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
exit ;;
i*86:Minix:*:*)
echo ${UNAME_MACHINE}-pc-minix
exit ;;
arm*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
avr32*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
cris:Linux:*:*)
echo cris-axis-linux-gnu
exit ;;
crisv32:Linux:*:*)
echo crisv32-axis-linux-gnu
exit ;;
frv:Linux:*:*)
echo frv-unknown-linux-gnu
exit ;;
ia64:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
m32r*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
m68*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
mips:Linux:*:*)
eval $set_cc_for_build
sed 's/^ //' << EOF >$dummy.c
#undef CPU
#undef mips
#undef mipsel
#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
CPU=mipsel
#else
#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
CPU=mips
#else
CPU=
#endif
#endif
EOF
eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
/^CPU/{
s: ::g
p
}'`"
test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
;;
mips64:Linux:*:*)
eval $set_cc_for_build
sed 's/^ //' << EOF >$dummy.c
#undef CPU
#undef mips64
#undef mips64el
#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
CPU=mips64el
#else
#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
CPU=mips64
#else
CPU=
#endif
#endif
EOF
eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
/^CPU/{
s: ::g
p
}'`"
test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
;;
or32:Linux:*:*)
echo or32-unknown-linux-gnu
exit ;;
ppc:Linux:*:*)
echo powerpc-unknown-linux-gnu
exit ;;
ppc64:Linux:*:*)
echo powerpc64-unknown-linux-gnu
exit ;;
alpha:Linux:*:*)
case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
EV5) UNAME_MACHINE=alphaev5 ;;
EV56) UNAME_MACHINE=alphaev56 ;;
PCA56) UNAME_MACHINE=alphapca56 ;;
PCA57) UNAME_MACHINE=alphapca56 ;;
EV6) UNAME_MACHINE=alphaev6 ;;
EV67) UNAME_MACHINE=alphaev67 ;;
EV68*) UNAME_MACHINE=alphaev68 ;;
esac
objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null
if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
exit ;;
parisc:Linux:*:* | hppa:Linux:*:*)
# Look for CPU level
case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
PA7*) echo hppa1.1-unknown-linux-gnu ;;
PA8*) echo hppa2.0-unknown-linux-gnu ;;
*) echo hppa-unknown-linux-gnu ;;
esac
exit ;;
parisc64:Linux:*:* | hppa64:Linux:*:*)
echo hppa64-unknown-linux-gnu
exit ;;
s390:Linux:*:* | s390x:Linux:*:*)
echo ${UNAME_MACHINE}-ibm-linux
exit ;;
sh64*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
sh*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
sparc:Linux:*:* | sparc64:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
vax:Linux:*:*)
echo ${UNAME_MACHINE}-dec-linux-gnu
exit ;;
x86_64:Linux:*:*)
echo x86_64-unknown-linux-gnu
exit ;;
xtensa:Linux:*:*)
echo xtensa-unknown-linux-gnu
exit ;;
i*86:Linux:*:*)
# The BFD linker knows what the default object file format is, so
# first see if it will tell us. cd to the root directory to prevent
# problems with other programs or directories called `ld' in the path.
# Set LC_ALL=C to ensure ld outputs messages in English.
ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \
| sed -ne '/supported targets:/!d
s/[ ][ ]*/ /g
s/.*supported targets: *//
s/ .*//
p'`
case "$ld_supported_targets" in
elf32-i386)
TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu"
;;
a.out-i386-linux)
echo "${UNAME_MACHINE}-pc-linux-gnuaout"
exit ;;
coff-i386)
echo "${UNAME_MACHINE}-pc-linux-gnucoff"
exit ;;
"")
# Either a pre-BFD a.out linker (linux-gnuoldld) or
# one that does not give us useful --help.
echo "${UNAME_MACHINE}-pc-linux-gnuoldld"
exit ;;
esac
# Determine whether the default compiler is a.out or elf
eval $set_cc_for_build
sed 's/^ //' << EOF >$dummy.c
#include
#ifdef __ELF__
# ifdef __GLIBC__
# if __GLIBC__ >= 2
LIBC=gnu
# else
LIBC=gnulibc1
# endif
# else
LIBC=gnulibc1
# endif
#else
#if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
LIBC=gnu
#else
LIBC=gnuaout
#endif
#endif
#ifdef __dietlibc__
LIBC=dietlibc
#endif
EOF
eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
/^LIBC/{
s: ::g
p
}'`"
test x"${LIBC}" != x && {
echo "${UNAME_MACHINE}-pc-linux-${LIBC}"
exit
}
test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; }
;;
i*86:DYNIX/ptx:4*:*)
# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
# earlier versions are messed up and put the nodename in both
# sysname and nodename.
echo i386-sequent-sysv4
exit ;;
i*86:UNIX_SV:4.2MP:2.*)
# Unixware is an offshoot of SVR4, but it has its own version
# number series starting with 2...
# I am not positive that other SVR4 systems won't match this,
# I just have to hope. -- rms.
# Use sysv4.2uw... so that sysv4* matches it.
echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
exit ;;
i*86:OS/2:*:*)
# If we were able to find `uname', then EMX Unix compatibility
# is probably installed.
echo ${UNAME_MACHINE}-pc-os2-emx
exit ;;
i*86:XTS-300:*:STOP)
echo ${UNAME_MACHINE}-unknown-stop
exit ;;
i*86:atheos:*:*)
echo ${UNAME_MACHINE}-unknown-atheos
exit ;;
i*86:syllable:*:*)
echo ${UNAME_MACHINE}-pc-syllable
exit ;;
i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
echo i386-unknown-lynxos${UNAME_RELEASE}
exit ;;
i*86:*DOS:*:*)
echo ${UNAME_MACHINE}-pc-msdosdjgpp
exit ;;
i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL}
else
echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}
fi
exit ;;
i*86:*:5:[678]*)
# UnixWare 7.x, OpenUNIX and OpenServer 6.
case `/bin/uname -X | grep "^Machine"` in
*486*) UNAME_MACHINE=i486 ;;
*Pentium) UNAME_MACHINE=i586 ;;
*Pent*|*Celeron) UNAME_MACHINE=i686 ;;
esac
echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
exit ;;
i*86:*:3.2:*)
if test -f /usr/options/cb.name; then
UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then
UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
(/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
(/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
&& UNAME_MACHINE=i586
(/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
&& UNAME_MACHINE=i686
(/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
&& UNAME_MACHINE=i686
echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
else
echo ${UNAME_MACHINE}-pc-sysv32
fi
exit ;;
pc:*:*:*)
# Left here for compatibility:
# uname -m prints for DJGPP always 'pc', but it prints nothing about
# the processor, so we play safe by assuming i386.
echo i386-pc-msdosdjgpp
exit ;;
Intel:Mach:3*:*)
echo i386-pc-mach3
exit ;;
paragon:*:*:*)
echo i860-intel-osf1
exit ;;
i860:*:4.*:*) # i860-SVR4
if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
else # Add other i860-SVR4 vendors below as they are discovered.
echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4
fi
exit ;;
mini*:CTIX:SYS*5:*)
# "miniframe"
echo m68010-convergent-sysv
exit ;;
mc68k:UNIX:SYSTEM5:3.51m)
echo m68k-convergent-sysv
exit ;;
M680?0:D-NIX:5.3:*)
echo m68k-diab-dnix
exit ;;
M68*:*:R3V[5678]*:*)
test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;
3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0)
OS_REL=''
test -r /etc/.relid \
&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
&& { echo i486-ncr-sysv4.3${OS_REL}; exit; }
/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
&& { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
&& { echo i486-ncr-sysv4; exit; } ;;
m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
echo m68k-unknown-lynxos${UNAME_RELEASE}
exit ;;
mc68030:UNIX_System_V:4.*:*)
echo m68k-atari-sysv4
exit ;;
TSUNAMI:LynxOS:2.*:*)
echo sparc-unknown-lynxos${UNAME_RELEASE}
exit ;;
rs6000:LynxOS:2.*:*)
echo rs6000-unknown-lynxos${UNAME_RELEASE}
exit ;;
PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*)
echo powerpc-unknown-lynxos${UNAME_RELEASE}
exit ;;
SM[BE]S:UNIX_SV:*:*)
echo mips-dde-sysv${UNAME_RELEASE}
exit ;;
RM*:ReliantUNIX-*:*:*)
echo mips-sni-sysv4
exit ;;
RM*:SINIX-*:*:*)
echo mips-sni-sysv4
exit ;;
*:SINIX-*:*:*)
if uname -p 2>/dev/null >/dev/null ; then
UNAME_MACHINE=`(uname -p) 2>/dev/null`
echo ${UNAME_MACHINE}-sni-sysv4
else
echo ns32k-sni-sysv
fi
exit ;;
PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
# says
echo i586-unisys-sysv4
exit ;;
*:UNIX_System_V:4*:FTX*)
# From Gerald Hewes .
# How about differentiating between stratus architectures? -djm
echo hppa1.1-stratus-sysv4
exit ;;
*:*:*:FTX*)
# From seanf@swdc.stratus.com.
echo i860-stratus-sysv4
exit ;;
i*86:VOS:*:*)
# From Paul.Green@stratus.com.
echo ${UNAME_MACHINE}-stratus-vos
exit ;;
*:VOS:*:*)
# From Paul.Green@stratus.com.
echo hppa1.1-stratus-vos
exit ;;
mc68*:A/UX:*:*)
echo m68k-apple-aux${UNAME_RELEASE}
exit ;;
news*:NEWS-OS:6*:*)
echo mips-sony-newsos6
exit ;;
R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
if [ -d /usr/nec ]; then
echo mips-nec-sysv${UNAME_RELEASE}
else
echo mips-unknown-sysv${UNAME_RELEASE}
fi
exit ;;
BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only.
echo powerpc-be-beos
exit ;;
BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only.
echo powerpc-apple-beos
exit ;;
BePC:BeOS:*:*) # BeOS running on Intel PC compatible.
echo i586-pc-beos
exit ;;
SX-4:SUPER-UX:*:*)
echo sx4-nec-superux${UNAME_RELEASE}
exit ;;
SX-5:SUPER-UX:*:*)
echo sx5-nec-superux${UNAME_RELEASE}
exit ;;
SX-6:SUPER-UX:*:*)
echo sx6-nec-superux${UNAME_RELEASE}
exit ;;
SX-7:SUPER-UX:*:*)
echo sx7-nec-superux${UNAME_RELEASE}
exit ;;
SX-8:SUPER-UX:*:*)
echo sx8-nec-superux${UNAME_RELEASE}
exit ;;
Power*:Rhapsody:*:*)
echo powerpc-apple-rhapsody${UNAME_RELEASE}
exit ;;
*:Rhapsody:*:*)
echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
exit ;;
*:Darwin:*:*)
UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
case $UNAME_PROCESSOR in
unknown) UNAME_PROCESSOR=powerpc ;;
esac
echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
exit ;;
*:procnto*:*:* | *:QNX:[0123456789]*:*)
UNAME_PROCESSOR=`uname -p`
if test "$UNAME_PROCESSOR" = "x86"; then
UNAME_PROCESSOR=i386
UNAME_MACHINE=pc
fi
echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}
exit ;;
*:QNX:*:4*)
echo i386-pc-qnx
exit ;;
NSE-?:NONSTOP_KERNEL:*:*)
echo nse-tandem-nsk${UNAME_RELEASE}
exit ;;
NSR-?:NONSTOP_KERNEL:*:*)
echo nsr-tandem-nsk${UNAME_RELEASE}
exit ;;
*:NonStop-UX:*:*)
echo mips-compaq-nonstopux
exit ;;
BS2000:POSIX*:*:*)
echo bs2000-siemens-sysv
exit ;;
DS/*:UNIX_System_V:*:*)
echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}
exit ;;
*:Plan9:*:*)
# "uname -m" is not consistent, so use $cputype instead. 386
# is converted to i386 for consistency with other x86
# operating systems.
if test "$cputype" = "386"; then
UNAME_MACHINE=i386
else
UNAME_MACHINE="$cputype"
fi
echo ${UNAME_MACHINE}-unknown-plan9
exit ;;
*:TOPS-10:*:*)
echo pdp10-unknown-tops10
exit ;;
*:TENEX:*:*)
echo pdp10-unknown-tenex
exit ;;
KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
echo pdp10-dec-tops20
exit ;;
XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
echo pdp10-xkl-tops20
exit ;;
*:TOPS-20:*:*)
echo pdp10-unknown-tops20
exit ;;
*:ITS:*:*)
echo pdp10-unknown-its
exit ;;
SEI:*:*:SEIUX)
echo mips-sei-seiux${UNAME_RELEASE}
exit ;;
*:DragonFly:*:*)
echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
exit ;;
*:*VMS:*:*)
UNAME_MACHINE=`(uname -p) 2>/dev/null`
case "${UNAME_MACHINE}" in
A*) echo alpha-dec-vms ; exit ;;
I*) echo ia64-dec-vms ; exit ;;
V*) echo vax-dec-vms ; exit ;;
esac ;;
*:XENIX:*:SysV)
echo i386-pc-xenix
exit ;;
i*86:skyos:*:*)
echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//'
exit ;;
i*86:rdos:*:*)
echo ${UNAME_MACHINE}-pc-rdos
exit ;;
esac
#echo '(No uname command or uname output not recognized.)' 1>&2
#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
eval $set_cc_for_build
cat >$dummy.c <
# include
#endif
main ()
{
#if defined (sony)
#if defined (MIPSEB)
/* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed,
I don't know.... */
printf ("mips-sony-bsd\n"); exit (0);
#else
#include
printf ("m68k-sony-newsos%s\n",
#ifdef NEWSOS4
"4"
#else
""
#endif
); exit (0);
#endif
#endif
#if defined (__arm) && defined (__acorn) && defined (__unix)
printf ("arm-acorn-riscix\n"); exit (0);
#endif
#if defined (hp300) && !defined (hpux)
printf ("m68k-hp-bsd\n"); exit (0);
#endif
#if defined (NeXT)
#if !defined (__ARCHITECTURE__)
#define __ARCHITECTURE__ "m68k"
#endif
int version;
version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
if (version < 4)
printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
else
printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version);
exit (0);
#endif
#if defined (MULTIMAX) || defined (n16)
#if defined (UMAXV)
printf ("ns32k-encore-sysv\n"); exit (0);
#else
#if defined (CMU)
printf ("ns32k-encore-mach\n"); exit (0);
#else
printf ("ns32k-encore-bsd\n"); exit (0);
#endif
#endif
#endif
#if defined (__386BSD__)
printf ("i386-pc-bsd\n"); exit (0);
#endif
#if defined (sequent)
#if defined (i386)
printf ("i386-sequent-dynix\n"); exit (0);
#endif
#if defined (ns32000)
printf ("ns32k-sequent-dynix\n"); exit (0);
#endif
#endif
#if defined (_SEQUENT_)
struct utsname un;
uname(&un);
if (strncmp(un.version, "V2", 2) == 0) {
printf ("i386-sequent-ptx2\n"); exit (0);
}
if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
printf ("i386-sequent-ptx1\n"); exit (0);
}
printf ("i386-sequent-ptx\n"); exit (0);
#endif
#if defined (vax)
# if !defined (ultrix)
# include
# if defined (BSD)
# if BSD == 43
printf ("vax-dec-bsd4.3\n"); exit (0);
# else
# if BSD == 199006
printf ("vax-dec-bsd4.3reno\n"); exit (0);
# else
printf ("vax-dec-bsd\n"); exit (0);
# endif
# endif
# else
printf ("vax-dec-bsd\n"); exit (0);
# endif
# else
printf ("vax-dec-ultrix\n"); exit (0);
# endif
#endif
#if defined (alliant) && defined (i860)
printf ("i860-alliant-bsd\n"); exit (0);
#endif
exit (1);
}
EOF
$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` &&
{ echo "$SYSTEM_NAME"; exit; }
# Apollos put the system type in the environment.
test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; }
# Convex versions that predate uname can use getsysinfo(1)
if [ -x /usr/convex/getsysinfo ]
then
case `getsysinfo -f cpu_type` in
c1*)
echo c1-convex-bsd
exit ;;
c2*)
if getsysinfo -f scalar_acc
then echo c32-convex-bsd
else echo c2-convex-bsd
fi
exit ;;
c34*)
echo c34-convex-bsd
exit ;;
c38*)
echo c38-convex-bsd
exit ;;
c4*)
echo c4-convex-bsd
exit ;;
esac
fi
cat >&2 < in order to provide the needed
information to handle your system.
config.guess timestamp = $timestamp
uname -m = `(uname -m) 2>/dev/null || echo unknown`
uname -r = `(uname -r) 2>/dev/null || echo unknown`
uname -s = `(uname -s) 2>/dev/null || echo unknown`
uname -v = `(uname -v) 2>/dev/null || echo unknown`
/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null`
/bin/uname -X = `(/bin/uname -X) 2>/dev/null`
hostinfo = `(hostinfo) 2>/dev/null`
/bin/universe = `(/bin/universe) 2>/dev/null`
/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null`
/bin/arch = `(/bin/arch) 2>/dev/null`
/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null`
/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null`
UNAME_MACHINE = ${UNAME_MACHINE}
UNAME_RELEASE = ${UNAME_RELEASE}
UNAME_SYSTEM = ${UNAME_SYSTEM}
UNAME_VERSION = ${UNAME_VERSION}
EOF
exit 1
# Local variables:
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "timestamp='"
# time-stamp-format: "%:y-%02m-%02d"
# time-stamp-end: "'"
# End:
icinga-1.10.3/config.sub 0000775 0000000 0000000 00000077553 12276402000 0015023 0 ustar 00root root 0000000 0000000 #! /bin/sh
# Configuration validation subroutine script.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
# Inc.
timestamp='2006-12-08'
# This file is (in principle) common to ALL GNU software.
# The presence of a machine in this file suggests that SOME GNU software
# can handle that machine. It does not imply ALL GNU software can.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# Please send patches to . Submit a context
# diff and a properly formatted ChangeLog entry.
#
# Configuration subroutine to validate and canonicalize a configuration type.
# Supply the specified configuration type as an argument.
# If it is invalid, we print an error message on stderr and exit with code 1.
# Otherwise, we print the canonical config type on stdout and succeed.
# This file is supposed to be the same for all GNU packages
# and recognize all the CPU types, system types and aliases
# that are meaningful with *any* GNU software.
# Each package is responsible for reporting which valid configurations
# it does not support. The user should be able to distinguish
# a failure to support a valid configuration from a meaningless
# configuration.
# The goal of this file is to map all the various variations of a given
# machine specification into a single specification in the form:
# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
# or in some cases, the newer four-part form:
# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
# It is wrong to echo any other type of specification.
me=`echo "$0" | sed -e 's,.*/,,'`
usage="\
Usage: $0 [OPTION] CPU-MFR-OPSYS
$0 [OPTION] ALIAS
Canonicalize a configuration name.
Operation modes:
-h, --help print this help, then exit
-t, --time-stamp print date of last modification, then exit
-v, --version print version number, then exit
Report bugs and patches to ."
version="\
GNU config.sub ($timestamp)
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
help="
Try \`$me --help' for more information."
# Parse command line
while test $# -gt 0 ; do
case $1 in
--time-stamp | --time* | -t )
echo "$timestamp" ; exit ;;
--version | -v )
echo "$version" ; exit ;;
--help | --h* | -h )
echo "$usage"; exit ;;
-- ) # Stop option processing
shift; break ;;
- ) # Use stdin as input.
break ;;
-* )
echo "$me: invalid option $1$help"
exit 1 ;;
*local*)
# First pass through any local machine types.
echo $1
exit ;;
* )
break ;;
esac
done
case $# in
0) echo "$me: missing argument$help" >&2
exit 1;;
1) ;;
*) echo "$me: too many arguments$help" >&2
exit 1;;
esac
# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
# Here we must recognize all the valid KERNEL-OS combinations.
maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
case $maybe_os in
nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \
uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \
storm-chaos* | os2-emx* | rtmk-nova*)
os=-$maybe_os
basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
;;
*)
basic_machine=`echo $1 | sed 's/-[^-]*$//'`
if [ $basic_machine != $1 ]
then os=`echo $1 | sed 's/.*-/-/'`
else os=; fi
;;
esac
### Let's recognize common machines as not being operating systems so
### that things like config.sub decstation-3100 work. We also
### recognize some manufacturers as not being operating systems, so we
### can provide default operating systems below.
case $os in
-sun*os*)
# Prevent following clause from handling this invalid input.
;;
-dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
-att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
-unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
-apple | -axis | -knuth | -cray)
os=
basic_machine=$1
;;
-sim | -cisco | -oki | -wec | -winbond)
os=
basic_machine=$1
;;
-scout)
;;
-wrs)
os=-vxworks
basic_machine=$1
;;
-chorusos*)
os=-chorusos
basic_machine=$1
;;
-chorusrdb)
os=-chorusrdb
basic_machine=$1
;;
-hiux*)
os=-hiuxwe2
;;
-sco6)
os=-sco5v6
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco5)
os=-sco3.2v5
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco4)
os=-sco3.2v4
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco3.2.[4-9]*)
os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco3.2v[4-9]*)
# Don't forget version if it is 3.2v4 or newer.
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco5v6*)
# Don't forget version if it is 3.2v4 or newer.
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco*)
os=-sco3.2v2
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-udk*)
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-isc)
os=-isc2.2
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-clix*)
basic_machine=clipper-intergraph
;;
-isc*)
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-lynx*)
os=-lynxos
;;
-ptx*)
basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
;;
-windowsnt*)
os=`echo $os | sed -e 's/windowsnt/winnt/'`
;;
-psos*)
os=-psos
;;
-mint | -mint[0-9]*)
basic_machine=m68k-atari
os=-mint
;;
esac
# Decode aliases for certain CPU-COMPANY combinations.
case $basic_machine in
# Recognize the basic CPU types without company name.
# Some are omitted here because they have special meanings below.
1750a | 580 \
| a29k \
| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
| am33_2.0 \
| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \
| bfin \
| c4x | clipper \
| d10v | d30v | dlx | dsp16xx \
| fido | fr30 | frv \
| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
| i370 | i860 | i960 | ia64 \
| ip2k | iq2000 \
| m32c | m32r | m32rle | m68000 | m68k | m88k \
| maxq | mb | microblaze | mcore \
| mips | mipsbe | mipseb | mipsel | mipsle \
| mips16 \
| mips64 | mips64el \
| mips64vr | mips64vrel \
| mips64orion | mips64orionel \
| mips64vr4100 | mips64vr4100el \
| mips64vr4300 | mips64vr4300el \
| mips64vr5000 | mips64vr5000el \
| mips64vr5900 | mips64vr5900el \
| mipsisa32 | mipsisa32el \
| mipsisa32r2 | mipsisa32r2el \
| mipsisa64 | mipsisa64el \
| mipsisa64r2 | mipsisa64r2el \
| mipsisa64sb1 | mipsisa64sb1el \
| mipsisa64sr71k | mipsisa64sr71kel \
| mipstx39 | mipstx39el \
| mn10200 | mn10300 \
| mt \
| msp430 \
| nios | nios2 \
| ns16k | ns32k \
| or32 \
| pdp10 | pdp11 | pj | pjl \
| powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
| pyramid \
| score \
| sh | sh[1234] | sh[24]a | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
| sh64 | sh64le \
| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
| spu | strongarm \
| tahoe | thumb | tic4x | tic80 | tron \
| v850 | v850e \
| we32k \
| x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \
| z8k)
basic_machine=$basic_machine-unknown
;;
m6811 | m68hc11 | m6812 | m68hc12)
# Motorola 68HC11/12.
basic_machine=$basic_machine-unknown
os=-none
;;
m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
;;
ms1)
basic_machine=mt-unknown
;;
# We use `pc' rather than `unknown'
# because (1) that's what they normally are, and
# (2) the word "unknown" tends to confuse beginning users.
i*86 | x86_64)
basic_machine=$basic_machine-pc
;;
# Object if more than one company name word.
*-*-*)
echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
exit 1
;;
# Recognize the basic CPU types with company name.
580-* \
| a29k-* \
| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
| alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
| arm-* | armbe-* | armle-* | armeb-* | armv*-* \
| avr-* | avr32-* \
| bfin-* | bs2000-* \
| c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
| clipper-* | craynv-* | cydra-* \
| d10v-* | d30v-* | dlx-* \
| elxsi-* \
| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
| h8300-* | h8500-* \
| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
| i*86-* | i860-* | i960-* | ia64-* \
| ip2k-* | iq2000-* \
| m32c-* | m32r-* | m32rle-* \
| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
| m88110-* | m88k-* | maxq-* | mcore-* \
| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
| mips16-* \
| mips64-* | mips64el-* \
| mips64vr-* | mips64vrel-* \
| mips64orion-* | mips64orionel-* \
| mips64vr4100-* | mips64vr4100el-* \
| mips64vr4300-* | mips64vr4300el-* \
| mips64vr5000-* | mips64vr5000el-* \
| mips64vr5900-* | mips64vr5900el-* \
| mipsisa32-* | mipsisa32el-* \
| mipsisa32r2-* | mipsisa32r2el-* \
| mipsisa64-* | mipsisa64el-* \
| mipsisa64r2-* | mipsisa64r2el-* \
| mipsisa64sb1-* | mipsisa64sb1el-* \
| mipsisa64sr71k-* | mipsisa64sr71kel-* \
| mipstx39-* | mipstx39el-* \
| mmix-* \
| mt-* \
| msp430-* \
| nios-* | nios2-* \
| none-* | np1-* | ns16k-* | ns32k-* \
| orion-* \
| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
| pyramid-* \
| romp-* | rs6000-* \
| sh-* | sh[1234]-* | sh[24]a-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
| sparclite-* \
| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \
| tahoe-* | thumb-* \
| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
| tron-* \
| v850-* | v850e-* | vax-* \
| we32k-* \
| x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \
| xstormy16-* | xtensa-* \
| ymp-* \
| z8k-*)
;;
# Recognize the various machine names and aliases which stand
# for a CPU type and a company and sometimes even an OS.
386bsd)
basic_machine=i386-unknown
os=-bsd
;;
3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
basic_machine=m68000-att
;;
3b*)
basic_machine=we32k-att
;;
a29khif)
basic_machine=a29k-amd
os=-udi
;;
abacus)
basic_machine=abacus-unknown
;;
adobe68k)
basic_machine=m68010-adobe
os=-scout
;;
alliant | fx80)
basic_machine=fx80-alliant
;;
altos | altos3068)
basic_machine=m68k-altos
;;
am29k)
basic_machine=a29k-none
os=-bsd
;;
amd64)
basic_machine=x86_64-pc
;;
amd64-*)
basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
amdahl)
basic_machine=580-amdahl
os=-sysv
;;
amiga | amiga-*)
basic_machine=m68k-unknown
;;
amigaos | amigados)
basic_machine=m68k-unknown
os=-amigaos
;;
amigaunix | amix)
basic_machine=m68k-unknown
os=-sysv4
;;
apollo68)
basic_machine=m68k-apollo
os=-sysv
;;
apollo68bsd)
basic_machine=m68k-apollo
os=-bsd
;;
aux)
basic_machine=m68k-apple
os=-aux
;;
balance)
basic_machine=ns32k-sequent
os=-dynix
;;
c90)
basic_machine=c90-cray
os=-unicos
;;
convex-c1)
basic_machine=c1-convex
os=-bsd
;;
convex-c2)
basic_machine=c2-convex
os=-bsd
;;
convex-c32)
basic_machine=c32-convex
os=-bsd
;;
convex-c34)
basic_machine=c34-convex
os=-bsd
;;
convex-c38)
basic_machine=c38-convex
os=-bsd
;;
cray | j90)
basic_machine=j90-cray
os=-unicos
;;
craynv)
basic_machine=craynv-cray
os=-unicosmp
;;
cr16c)
basic_machine=cr16c-unknown
os=-elf
;;
crds | unos)
basic_machine=m68k-crds
;;
crisv32 | crisv32-* | etraxfs*)
basic_machine=crisv32-axis
;;
cris | cris-* | etrax*)
basic_machine=cris-axis
;;
crx)
basic_machine=crx-unknown
os=-elf
;;
da30 | da30-*)
basic_machine=m68k-da30
;;
decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
basic_machine=mips-dec
;;
decsystem10* | dec10*)
basic_machine=pdp10-dec
os=-tops10
;;
decsystem20* | dec20*)
basic_machine=pdp10-dec
os=-tops20
;;
delta | 3300 | motorola-3300 | motorola-delta \
| 3300-motorola | delta-motorola)
basic_machine=m68k-motorola
;;
delta88)
basic_machine=m88k-motorola
os=-sysv3
;;
djgpp)
basic_machine=i586-pc
os=-msdosdjgpp
;;
dpx20 | dpx20-*)
basic_machine=rs6000-bull
os=-bosx
;;
dpx2* | dpx2*-bull)
basic_machine=m68k-bull
os=-sysv3
;;
ebmon29k)
basic_machine=a29k-amd
os=-ebmon
;;
elxsi)
basic_machine=elxsi-elxsi
os=-bsd
;;
encore | umax | mmax)
basic_machine=ns32k-encore
;;
es1800 | OSE68k | ose68k | ose | OSE)
basic_machine=m68k-ericsson
os=-ose
;;
fx2800)
basic_machine=i860-alliant
;;
genix)
basic_machine=ns32k-ns
;;
gmicro)
basic_machine=tron-gmicro
os=-sysv
;;
go32)
basic_machine=i386-pc
os=-go32
;;
h3050r* | hiux*)
basic_machine=hppa1.1-hitachi
os=-hiuxwe2
;;
h8300hms)
basic_machine=h8300-hitachi
os=-hms
;;
h8300xray)
basic_machine=h8300-hitachi
os=-xray
;;
h8500hms)
basic_machine=h8500-hitachi
os=-hms
;;
harris)
basic_machine=m88k-harris
os=-sysv3
;;
hp300-*)
basic_machine=m68k-hp
;;
hp300bsd)
basic_machine=m68k-hp
os=-bsd
;;
hp300hpux)
basic_machine=m68k-hp
os=-hpux
;;
hp3k9[0-9][0-9] | hp9[0-9][0-9])
basic_machine=hppa1.0-hp
;;
hp9k2[0-9][0-9] | hp9k31[0-9])
basic_machine=m68000-hp
;;
hp9k3[2-9][0-9])
basic_machine=m68k-hp
;;
hp9k6[0-9][0-9] | hp6[0-9][0-9])
basic_machine=hppa1.0-hp
;;
hp9k7[0-79][0-9] | hp7[0-79][0-9])
basic_machine=hppa1.1-hp
;;
hp9k78[0-9] | hp78[0-9])
# FIXME: really hppa2.0-hp
basic_machine=hppa1.1-hp
;;
hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
# FIXME: really hppa2.0-hp
basic_machine=hppa1.1-hp
;;
hp9k8[0-9][13679] | hp8[0-9][13679])
basic_machine=hppa1.1-hp
;;
hp9k8[0-9][0-9] | hp8[0-9][0-9])
basic_machine=hppa1.0-hp
;;
hppa-next)
os=-nextstep3
;;
hppaosf)
basic_machine=hppa1.1-hp
os=-osf
;;
hppro)
basic_machine=hppa1.1-hp
os=-proelf
;;
i370-ibm* | ibm*)
basic_machine=i370-ibm
;;
# I'm not sure what "Sysv32" means. Should this be sysv3.2?
i*86v32)
basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
os=-sysv32
;;
i*86v4*)
basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
os=-sysv4
;;
i*86v)
basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
os=-sysv
;;
i*86sol2)
basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
os=-solaris2
;;
i386mach)
basic_machine=i386-mach
os=-mach
;;
i386-vsta | vsta)
basic_machine=i386-unknown
os=-vsta
;;
iris | iris4d)
basic_machine=mips-sgi
case $os in
-irix*)
;;
*)
os=-irix4
;;
esac
;;
isi68 | isi)
basic_machine=m68k-isi
os=-sysv
;;
m88k-omron*)
basic_machine=m88k-omron
;;
magnum | m3230)
basic_machine=mips-mips
os=-sysv
;;
merlin)
basic_machine=ns32k-utek
os=-sysv
;;
mingw32)
basic_machine=i386-pc
os=-mingw32
;;
miniframe)
basic_machine=m68000-convergent
;;
*mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
basic_machine=m68k-atari
os=-mint
;;
mips3*-*)
basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
;;
mips3*)
basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
;;
monitor)
basic_machine=m68k-rom68k
os=-coff
;;
morphos)
basic_machine=powerpc-unknown
os=-morphos
;;
msdos)
basic_machine=i386-pc
os=-msdos
;;
ms1-*)
basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
;;
mvs)
basic_machine=i370-ibm
os=-mvs
;;
ncr3000)
basic_machine=i486-ncr
os=-sysv4
;;
netbsd386)
basic_machine=i386-unknown
os=-netbsd
;;
netwinder)
basic_machine=armv4l-rebel
os=-linux
;;
news | news700 | news800 | news900)
basic_machine=m68k-sony
os=-newsos
;;
news1000)
basic_machine=m68030-sony
os=-newsos
;;
news-3600 | risc-news)
basic_machine=mips-sony
os=-newsos
;;
necv70)
basic_machine=v70-nec
os=-sysv
;;
next | m*-next )
basic_machine=m68k-next
case $os in
-nextstep* )
;;
-ns2*)
os=-nextstep2
;;
*)
os=-nextstep3
;;
esac
;;
nh3000)
basic_machine=m68k-harris
os=-cxux
;;
nh[45]000)
basic_machine=m88k-harris
os=-cxux
;;
nindy960)
basic_machine=i960-intel
os=-nindy
;;
mon960)
basic_machine=i960-intel
os=-mon960
;;
nonstopux)
basic_machine=mips-compaq
os=-nonstopux
;;
np1)
basic_machine=np1-gould
;;
nsr-tandem)
basic_machine=nsr-tandem
;;
op50n-* | op60c-*)
basic_machine=hppa1.1-oki
os=-proelf
;;
openrisc | openrisc-*)
basic_machine=or32-unknown
;;
os400)
basic_machine=powerpc-ibm
os=-os400
;;
OSE68000 | ose68000)
basic_machine=m68000-ericsson
os=-ose
;;
os68k)
basic_machine=m68k-none
os=-os68k
;;
pa-hitachi)
basic_machine=hppa1.1-hitachi
os=-hiuxwe2
;;
paragon)
basic_machine=i860-intel
os=-osf
;;
pbd)
basic_machine=sparc-tti
;;
pbb)
basic_machine=m68k-tti
;;
pc532 | pc532-*)
basic_machine=ns32k-pc532
;;
pc98)
basic_machine=i386-pc
;;
pc98-*)
basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pentium | p5 | k5 | k6 | nexgen | viac3)
basic_machine=i586-pc
;;
pentiumpro | p6 | 6x86 | athlon | athlon_*)
basic_machine=i686-pc
;;
pentiumii | pentium2 | pentiumiii | pentium3)
basic_machine=i686-pc
;;
pentium4)
basic_machine=i786-pc
;;
pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pentiumpro-* | p6-* | 6x86-* | athlon-*)
basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pentium4-*)
basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pn)
basic_machine=pn-gould
;;
power) basic_machine=power-ibm
;;
ppc) basic_machine=powerpc-unknown
;;
ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
ppcle | powerpclittle | ppc-le | powerpc-little)
basic_machine=powerpcle-unknown
;;
ppcle-* | powerpclittle-*)
basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
ppc64) basic_machine=powerpc64-unknown
;;
ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
ppc64le | powerpc64little | ppc64-le | powerpc64-little)
basic_machine=powerpc64le-unknown
;;
ppc64le-* | powerpc64little-*)
basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
ps2)
basic_machine=i386-ibm
;;
pw32)
basic_machine=i586-unknown
os=-pw32
;;
rdos)
basic_machine=i386-pc
os=-rdos
;;
rom68k)
basic_machine=m68k-rom68k
os=-coff
;;
rm[46]00)
basic_machine=mips-siemens
;;
rtpc | rtpc-*)
basic_machine=romp-ibm
;;
s390 | s390-*)
basic_machine=s390-ibm
;;
s390x | s390x-*)
basic_machine=s390x-ibm
;;
sa29200)
basic_machine=a29k-amd
os=-udi
;;
sb1)
basic_machine=mipsisa64sb1-unknown
;;
sb1el)
basic_machine=mipsisa64sb1el-unknown
;;
sde)
basic_machine=mipsisa32-sde
os=-elf
;;
sei)
basic_machine=mips-sei
os=-seiux
;;
sequent)
basic_machine=i386-sequent
;;
sh)
basic_machine=sh-hitachi
os=-hms
;;
sh5el)
basic_machine=sh5le-unknown
;;
sh64)
basic_machine=sh64-unknown
;;
sparclite-wrs | simso-wrs)
basic_machine=sparclite-wrs
os=-vxworks
;;
sps7)
basic_machine=m68k-bull
os=-sysv2
;;
spur)
basic_machine=spur-unknown
;;
st2000)
basic_machine=m68k-tandem
;;
stratus)
basic_machine=i860-stratus
os=-sysv4
;;
sun2)
basic_machine=m68000-sun
;;
sun2os3)
basic_machine=m68000-sun
os=-sunos3
;;
sun2os4)
basic_machine=m68000-sun
os=-sunos4
;;
sun3os3)
basic_machine=m68k-sun
os=-sunos3
;;
sun3os4)
basic_machine=m68k-sun
os=-sunos4
;;
sun4os3)
basic_machine=sparc-sun
os=-sunos3
;;
sun4os4)
basic_machine=sparc-sun
os=-sunos4
;;
sun4sol2)
basic_machine=sparc-sun
os=-solaris2
;;
sun3 | sun3-*)
basic_machine=m68k-sun
;;
sun4)
basic_machine=sparc-sun
;;
sun386 | sun386i | roadrunner)
basic_machine=i386-sun
;;
sv1)
basic_machine=sv1-cray
os=-unicos
;;
symmetry)
basic_machine=i386-sequent
os=-dynix
;;
t3e)
basic_machine=alphaev5-cray
os=-unicos
;;
t90)
basic_machine=t90-cray
os=-unicos
;;
tic54x | c54x*)
basic_machine=tic54x-unknown
os=-coff
;;
tic55x | c55x*)
basic_machine=tic55x-unknown
os=-coff
;;
tic6x | c6x*)
basic_machine=tic6x-unknown
os=-coff
;;
tx39)
basic_machine=mipstx39-unknown
;;
tx39el)
basic_machine=mipstx39el-unknown
;;
toad1)
basic_machine=pdp10-xkl
os=-tops20
;;
tower | tower-32)
basic_machine=m68k-ncr
;;
tpf)
basic_machine=s390x-ibm
os=-tpf
;;
udi29k)
basic_machine=a29k-amd
os=-udi
;;
ultra3)
basic_machine=a29k-nyu
os=-sym1
;;
v810 | necv810)
basic_machine=v810-nec
os=-none
;;
vaxv)
basic_machine=vax-dec
os=-sysv
;;
vms)
basic_machine=vax-dec
os=-vms
;;
vpp*|vx|vx-*)
basic_machine=f301-fujitsu
;;
vxworks960)
basic_machine=i960-wrs
os=-vxworks
;;
vxworks68)
basic_machine=m68k-wrs
os=-vxworks
;;
vxworks29k)
basic_machine=a29k-wrs
os=-vxworks
;;
w65*)
basic_machine=w65-wdc
os=-none
;;
w89k-*)
basic_machine=hppa1.1-winbond
os=-proelf
;;
xbox)
basic_machine=i686-pc
os=-mingw32
;;
xps | xps100)
basic_machine=xps100-honeywell
;;
ymp)
basic_machine=ymp-cray
os=-unicos
;;
z8k-*-coff)
basic_machine=z8k-unknown
os=-sim
;;
none)
basic_machine=none-none
os=-none
;;
# Here we handle the default manufacturer of certain CPU types. It is in
# some cases the only manufacturer, in others, it is the most popular.
w89k)
basic_machine=hppa1.1-winbond
;;
op50n)
basic_machine=hppa1.1-oki
;;
op60c)
basic_machine=hppa1.1-oki
;;
romp)
basic_machine=romp-ibm
;;
mmix)
basic_machine=mmix-knuth
;;
rs6000)
basic_machine=rs6000-ibm
;;
vax)
basic_machine=vax-dec
;;
pdp10)
# there are many clones, so DEC is not a safe bet
basic_machine=pdp10-unknown
;;
pdp11)
basic_machine=pdp11-dec
;;
we32k)
basic_machine=we32k-att
;;
sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele)
basic_machine=sh-unknown
;;
sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)
basic_machine=sparc-sun
;;
cydra)
basic_machine=cydra-cydrome
;;
orion)
basic_machine=orion-highlevel
;;
orion105)
basic_machine=clipper-highlevel
;;
mac | mpw | mac-mpw)
basic_machine=m68k-apple
;;
pmac | pmac-mpw)
basic_machine=powerpc-apple
;;
*-unknown)
# Make sure to match an already-canonicalized machine name.
;;
*)
echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
exit 1
;;
esac
# Here we canonicalize certain aliases for manufacturers.
case $basic_machine in
*-digital*)
basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
;;
*-commodore*)
basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
;;
*)
;;
esac
# Decode manufacturer-specific aliases for certain operating systems.
if [ x"$os" != x"" ]
then
case $os in
# First match some system type aliases
# that might get confused with valid system types.
# -solaris* is a basic system type, with this one exception.
-solaris1 | -solaris1.*)
os=`echo $os | sed -e 's|solaris1|sunos4|'`
;;
-solaris)
os=-solaris2
;;
-svr4*)
os=-sysv4
;;
-unixware*)
os=-sysv4.2uw
;;
-gnu/linux*)
os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
;;
# First accept the basic system types.
# The portable systems comes first.
# Each alternative MUST END IN A *, to match a version number.
# -sysv* is not here because it comes later, after sysvr4.
-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
| -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\
| -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \
| -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
| -aos* \
| -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
| -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
| -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
| -openbsd* | -solidbsd* \
| -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
| -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
| -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
| -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
| -chorusos* | -chorusrdb* \
| -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
| -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \
| -uxpv* | -beos* | -mpeix* | -udk* \
| -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
| -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
| -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
| -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
| -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
| -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
| -skyos* | -haiku* | -rdos* | -toppers*)
# Remember, each alternative MUST END IN *, to match a version number.
;;
-qnx*)
case $basic_machine in
x86-* | i*86-*)
;;
*)
os=-nto$os
;;
esac
;;
-nto-qnx*)
;;
-nto*)
os=`echo $os | sed -e 's|nto|nto-qnx|'`
;;
-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
| -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \
| -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
;;
-mac*)
os=`echo $os | sed -e 's|mac|macos|'`
;;
-linux-dietlibc)
os=-linux-dietlibc
;;
-linux*)
os=`echo $os | sed -e 's|linux|linux-gnu|'`
;;
-sunos5*)
os=`echo $os | sed -e 's|sunos5|solaris2|'`
;;
-sunos6*)
os=`echo $os | sed -e 's|sunos6|solaris3|'`
;;
-opened*)
os=-openedition
;;
-os400*)
os=-os400
;;
-wince*)
os=-wince
;;
-osfrose*)
os=-osfrose
;;
-osf*)
os=-osf
;;
-utek*)
os=-bsd
;;
-dynix*)
os=-bsd
;;
-acis*)
os=-aos
;;
-atheos*)
os=-atheos
;;
-syllable*)
os=-syllable
;;
-386bsd)
os=-bsd
;;
-ctix* | -uts*)
os=-sysv
;;
-nova*)
os=-rtmk-nova
;;
-ns2 )
os=-nextstep2
;;
-nsk*)
os=-nsk
;;
# Preserve the version number of sinix5.
-sinix5.*)
os=`echo $os | sed -e 's|sinix|sysv|'`
;;
-sinix*)
os=-sysv4
;;
-tpf*)
os=-tpf
;;
-triton*)
os=-sysv3
;;
-oss*)
os=-sysv3
;;
-svr4)
os=-sysv4
;;
-svr3)
os=-sysv3
;;
-sysvr4)
os=-sysv4
;;
# This must come after -sysvr4.
-sysv*)
;;
-ose*)
os=-ose
;;
-es1800*)
os=-ose
;;
-xenix)
os=-xenix
;;
-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
os=-mint
;;
-aros*)
os=-aros
;;
-kaos*)
os=-kaos
;;
-zvmoe)
os=-zvmoe
;;
-none)
;;
*)
# Get rid of the `-' at the beginning of $os.
os=`echo $os | sed 's/[^-]*-//'`
echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
exit 1
;;
esac
else
# Here we handle the default operating systems that come with various machines.
# The value should be what the vendor currently ships out the door with their
# machine or put another way, the most popular os provided with the machine.
# Note that if you're going to try to match "-MANUFACTURER" here (say,
# "-sun"), then you have to tell the case statement up towards the top
# that MANUFACTURER isn't an operating system. Otherwise, code above
# will signal an error saying that MANUFACTURER isn't an operating
# system, and we'll never get to this point.
case $basic_machine in
score-*)
os=-elf
;;
spu-*)
os=-elf
;;
*-acorn)
os=-riscix1.2
;;
arm*-rebel)
os=-linux
;;
arm*-semi)
os=-aout
;;
c4x-* | tic4x-*)
os=-coff
;;
# This must come before the *-dec entry.
pdp10-*)
os=-tops20
;;
pdp11-*)
os=-none
;;
*-dec | vax-*)
os=-ultrix4.2
;;
m68*-apollo)
os=-domain
;;
i386-sun)
os=-sunos4.0.2
;;
m68000-sun)
os=-sunos3
# This also exists in the configure program, but was not the
# default.
# os=-sunos4
;;
m68*-cisco)
os=-aout
;;
mips*-cisco)
os=-elf
;;
mips*-*)
os=-elf
;;
or32-*)
os=-coff
;;
*-tti) # must be before sparc entry or we get the wrong os.
os=-sysv3
;;
sparc-* | *-sun)
os=-sunos4.1.1
;;
*-be)
os=-beos
;;
*-haiku)
os=-haiku
;;
*-ibm)
os=-aix
;;
*-knuth)
os=-mmixware
;;
*-wec)
os=-proelf
;;
*-winbond)
os=-proelf
;;
*-oki)
os=-proelf
;;
*-hp)
os=-hpux
;;
*-hitachi)
os=-hiux
;;
i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
os=-sysv
;;
*-cbm)
os=-amigaos
;;
*-dg)
os=-dgux
;;
*-dolphin)
os=-sysv3
;;
m68k-ccur)
os=-rtu
;;
m88k-omron*)
os=-luna
;;
*-next )
os=-nextstep
;;
*-sequent)
os=-ptx
;;
*-crds)
os=-unos
;;
*-ns)
os=-genix
;;
i370-*)
os=-mvs
;;
*-next)
os=-nextstep3
;;
*-gould)
os=-sysv
;;
*-highlevel)
os=-bsd
;;
*-encore)
os=-bsd
;;
*-sgi)
os=-irix
;;
*-siemens)
os=-sysv4
;;
*-masscomp)
os=-rtu
;;
f30[01]-fujitsu | f700-fujitsu)
os=-uxpv
;;
*-rom68k)
os=-coff
;;
*-*bug)
os=-coff
;;
*-apple)
os=-macos
;;
*-atari*)
os=-mint
;;
*)
os=-none
;;
esac
fi
# Here we handle the case where we know the os, and the CPU type, but not the
# manufacturer. We pick the logical manufacturer.
vendor=unknown
case $basic_machine in
*-unknown)
case $os in
-riscix*)
vendor=acorn
;;
-sunos*)
vendor=sun
;;
-aix*)
vendor=ibm
;;
-beos*)
vendor=be
;;
-hpux*)
vendor=hp
;;
-mpeix*)
vendor=hp
;;
-hiux*)
vendor=hitachi
;;
-unos*)
vendor=crds
;;
-dgux*)
vendor=dg
;;
-luna*)
vendor=omron
;;
-genix*)
vendor=ns
;;
-mvs* | -opened*)
vendor=ibm
;;
-os400*)
vendor=ibm
;;
-ptx*)
vendor=sequent
;;
-tpf*)
vendor=ibm
;;
-vxsim* | -vxworks* | -windiss*)
vendor=wrs
;;
-aux*)
vendor=apple
;;
-hms*)
vendor=hitachi
;;
-mpw* | -macos*)
vendor=apple
;;
-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
vendor=atari
;;
-vos*)
vendor=stratus
;;
esac
basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
;;
esac
echo $basic_machine$os
exit
# Local variables:
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "timestamp='"
# time-stamp-format: "%:y-%02m-%02d"
# time-stamp-end: "'"
# End:
icinga-1.10.3/configure 0000775 0000000 0000000 00000723213 12276402000 0014736 0 ustar 00root root 0000000 0000000 #! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69.
#
#
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
#
#
# This configure script is free software; the Free Software Foundation
# gives unlimited permission to copy, distribute and modify it.
## -------------------- ##
## M4sh Initialization. ##
## -------------------- ##
# Be more Bourne compatible
DUALCASE=1; export DUALCASE # for MKS sh
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
emulate sh
NULLCMD=:
# Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
# is contrary to our usage. Disable this feature.
alias -g '${1+"$@"}'='"$@"'
setopt NO_GLOB_SUBST
else
case `(set -o) 2>/dev/null` in #(
*posix*) :
set -o posix ;; #(
*) :
;;
esac
fi
as_nl='
'
export as_nl
# Printing a long string crashes Solaris 7 /usr/bin/printf.
as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
# Prefer a ksh shell builtin over an external printf program on Solaris,
# but without wasting forks for bash or zsh.
if test -z "$BASH_VERSION$ZSH_VERSION" \
&& (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
as_echo='print -r --'
as_echo_n='print -rn --'
elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
as_echo='printf %s\n'
as_echo_n='printf %s'
else
if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
as_echo_n='/usr/ucb/echo -n'
else
as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
as_echo_n_body='eval
arg=$1;
case $arg in #(
*"$as_nl"*)
expr "X$arg" : "X\\(.*\\)$as_nl";
arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
esac;
expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
'
export as_echo_n_body
as_echo_n='sh -c $as_echo_n_body as_echo'
fi
export as_echo_body
as_echo='sh -c $as_echo_body as_echo'
fi
# The user is always right.
if test "${PATH_SEPARATOR+set}" != set; then
PATH_SEPARATOR=:
(PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
(PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
PATH_SEPARATOR=';'
}
fi
# IFS
# We need space, tab and new line, in precisely that order. Quoting is
# there to prevent editors from complaining about space-tab.
# (If _AS_PATH_WALK were called with IFS unset, it would disable word
# splitting by setting IFS to empty value.)
IFS=" "" $as_nl"
# Find who we are. Look in the path if we contain no directory separator.
as_myself=
case $0 in #((
*[\\/]* ) as_myself=$0 ;;
*) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
done
IFS=$as_save_IFS
;;
esac
# We did not find ourselves, most probably we were run as `sh COMMAND'
# in which case we are not to be found in the path.
if test "x$as_myself" = x; then
as_myself=$0
fi
if test ! -f "$as_myself"; then
$as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
exit 1
fi
# Unset variables that we do not need and which cause bugs (e.g. in
# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1"
# suppresses any "Segmentation fault" message there. '((' could
# trigger a bug in pdksh 5.2.14.
for as_var in BASH_ENV ENV MAIL MAILPATH
do eval test x\${$as_var+set} = xset \
&& ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
done
PS1='$ '
PS2='> '
PS4='+ '
# NLS nuisances.
LC_ALL=C
export LC_ALL
LANGUAGE=C
export LANGUAGE
# CDPATH.
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
# Use a proper internal environment variable to ensure we don't fall
# into an infinite loop, continuously re-executing ourselves.
if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then
_as_can_reexec=no; export _as_can_reexec;
# We cannot yet assume a decent shell, so we have to provide a
# neutralization value for shells without unset; and this also
# works around shells that cannot unset nonexistent variables.
# Preserve -v and -x to the replacement shell.
BASH_ENV=/dev/null
ENV=/dev/null
(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
case $- in # ((((
*v*x* | *x*v* ) as_opts=-vx ;;
*v* ) as_opts=-v ;;
*x* ) as_opts=-x ;;
* ) as_opts= ;;
esac
exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
# Admittedly, this is quite paranoid, since all the known shells bail
# out after a failed `exec'.
$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
as_fn_exit 255
fi
# We don't want this to propagate to other subprocesses.
{ _as_can_reexec=; unset _as_can_reexec;}
if test "x$CONFIG_SHELL" = x; then
as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :
emulate sh
NULLCMD=:
# Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which
# is contrary to our usage. Disable this feature.
alias -g '\${1+\"\$@\"}'='\"\$@\"'
setopt NO_GLOB_SUBST
else
case \`(set -o) 2>/dev/null\` in #(
*posix*) :
set -o posix ;; #(
*) :
;;
esac
fi
"
as_required="as_fn_return () { (exit \$1); }
as_fn_success () { as_fn_return 0; }
as_fn_failure () { as_fn_return 1; }
as_fn_ret_success () { return 0; }
as_fn_ret_failure () { return 1; }
exitcode=0
as_fn_success || { exitcode=1; echo as_fn_success failed.; }
as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; }
as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; }
as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; }
if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then :
else
exitcode=1; echo positional parameters were not saved.
fi
test x\$exitcode = x0 || exit 1
test -x / || exit 1"
as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1
test \$(( 1 + 1 )) = 2 || exit 1"
if (eval "$as_required") 2>/dev/null; then :
as_have_required=yes
else
as_have_required=no
fi
if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then :
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
as_found=false
for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
as_found=:
case $as_dir in #(
/*)
for as_base in sh bash ksh sh5; do
# Try only shells that exist, to save several forks.
as_shell=$as_dir/$as_base
if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
{ $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then :
CONFIG_SHELL=$as_shell as_have_required=yes
if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then :
break 2
fi
fi
done;;
esac
as_found=false
done
$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } &&
{ $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then :
CONFIG_SHELL=$SHELL as_have_required=yes
fi; }
IFS=$as_save_IFS
if test "x$CONFIG_SHELL" != x; then :
export CONFIG_SHELL
# We cannot yet assume a decent shell, so we have to provide a
# neutralization value for shells without unset; and this also
# works around shells that cannot unset nonexistent variables.
# Preserve -v and -x to the replacement shell.
BASH_ENV=/dev/null
ENV=/dev/null
(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
case $- in # ((((
*v*x* | *x*v* ) as_opts=-vx ;;
*v* ) as_opts=-v ;;
*x* ) as_opts=-x ;;
* ) as_opts= ;;
esac
exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
# Admittedly, this is quite paranoid, since all the known shells bail
# out after a failed `exec'.
$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
exit 255
fi
if test x$as_have_required = xno; then :
$as_echo "$0: This script requires a shell more modern than all"
$as_echo "$0: the shells that I found on your system."
if test x${ZSH_VERSION+set} = xset ; then
$as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should"
$as_echo "$0: be upgraded to zsh 4.3.4 or later."
else
$as_echo "$0: Please tell bug-autoconf@gnu.org about your system,
$0: including any error possibly output before this
$0: message. Then install a modern shell, or manually run
$0: the script under such a shell if you do have one."
fi
exit 1
fi
fi
fi
SHELL=${CONFIG_SHELL-/bin/sh}
export SHELL
# Unset more variables known to interfere with behavior of common tools.
CLICOLOR_FORCE= GREP_OPTIONS=
unset CLICOLOR_FORCE GREP_OPTIONS
## --------------------- ##
## M4sh Shell Functions. ##
## --------------------- ##
# as_fn_unset VAR
# ---------------
# Portably unset VAR.
as_fn_unset ()
{
{ eval $1=; unset $1;}
}
as_unset=as_fn_unset
# as_fn_set_status STATUS
# -----------------------
# Set $? to STATUS, without forking.
as_fn_set_status ()
{
return $1
} # as_fn_set_status
# as_fn_exit STATUS
# -----------------
# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
as_fn_exit ()
{
set +e
as_fn_set_status $1
exit $1
} # as_fn_exit
# as_fn_mkdir_p
# -------------
# Create "$as_dir" as a directory, including parents if necessary.
as_fn_mkdir_p ()
{
case $as_dir in #(
-*) as_dir=./$as_dir;;
esac
test -d "$as_dir" || eval $as_mkdir_p || {
as_dirs=
while :; do
case $as_dir in #(
*\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
*) as_qdir=$as_dir;;
esac
as_dirs="'$as_qdir' $as_dirs"
as_dir=`$as_dirname -- "$as_dir" ||
$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
X"$as_dir" : 'X\(//\)[^/]' \| \
X"$as_dir" : 'X\(//\)$' \| \
X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
$as_echo X"$as_dir" |
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
s//\1/
q
}
/^X\(\/\/\)[^/].*/{
s//\1/
q
}
/^X\(\/\/\)$/{
s//\1/
q
}
/^X\(\/\).*/{
s//\1/
q
}
s/.*/./; q'`
test -d "$as_dir" && break
done
test -z "$as_dirs" || eval "mkdir $as_dirs"
} || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
} # as_fn_mkdir_p
# as_fn_executable_p FILE
# -----------------------
# Test if FILE is an executable regular file.
as_fn_executable_p ()
{
test -f "$1" && test -x "$1"
} # as_fn_executable_p
# as_fn_append VAR VALUE
# ----------------------
# Append the text in VALUE to the end of the definition contained in VAR. Take
# advantage of any shell optimizations that allow amortized linear growth over
# repeated appends, instead of the typical quadratic growth present in naive
# implementations.
if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
eval 'as_fn_append ()
{
eval $1+=\$2
}'
else
as_fn_append ()
{
eval $1=\$$1\$2
}
fi # as_fn_append
# as_fn_arith ARG...
# ------------------
# Perform arithmetic evaluation on the ARGs, and store the result in the
# global $as_val. Take advantage of shells that can avoid forks. The arguments
# must be portable across $(()) and expr.
if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
eval 'as_fn_arith ()
{
as_val=$(( $* ))
}'
else
as_fn_arith ()
{
as_val=`expr "$@" || test $? -eq 1`
}
fi # as_fn_arith
# as_fn_error STATUS ERROR [LINENO LOG_FD]
# ----------------------------------------
# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
# script with STATUS, using 1 if that was 0.
as_fn_error ()
{
as_status=$1; test $as_status -eq 0 && as_status=1
if test "$4"; then
as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
$as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
fi
$as_echo "$as_me: error: $2" >&2
as_fn_exit $as_status
} # as_fn_error
if expr a : '\(a\)' >/dev/null 2>&1 &&
test "X`expr 00001 : '.*\(...\)'`" = X001; then
as_expr=expr
else
as_expr=false
fi
if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
as_basename=basename
else
as_basename=false
fi
if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
as_dirname=dirname
else
as_dirname=false
fi
as_me=`$as_basename -- "$0" ||
$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
X"$0" : 'X\(//\)$' \| \
X"$0" : 'X\(/\)' \| . 2>/dev/null ||
$as_echo X/"$0" |
sed '/^.*\/\([^/][^/]*\)\/*$/{
s//\1/
q
}
/^X\/\(\/\/\)$/{
s//\1/
q
}
/^X\/\(\/\).*/{
s//\1/
q
}
s/.*/./; q'`
# Avoid depending upon Character Ranges.
as_cr_letters='abcdefghijklmnopqrstuvwxyz'
as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
as_cr_Letters=$as_cr_letters$as_cr_LETTERS
as_cr_digits='0123456789'
as_cr_alnum=$as_cr_Letters$as_cr_digits
as_lineno_1=$LINENO as_lineno_1a=$LINENO
as_lineno_2=$LINENO as_lineno_2a=$LINENO
eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" &&
test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || {
# Blame Lee E. McMahon (1931-1989) for sed's syntax. :-)
sed -n '
p
/[$]LINENO/=
' <$as_myself |
sed '
s/[$]LINENO.*/&-/
t lineno
b
:lineno
N
:loop
s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
t loop
s/-\n.*//
' >$as_me.lineno &&
chmod +x "$as_me.lineno" ||
{ $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }
# If we had to re-execute with $CONFIG_SHELL, we're ensured to have
# already done that, so ensure we don't try to do so again and fall
# in an infinite loop. This has already happened in practice.
_as_can_reexec=no; export _as_can_reexec
# Don't try to exec as it changes $[0], causing all sort of problems
# (the dirname of $[0] is not the place where we might find the
# original and so on. Autoconf is especially sensitive to this).
. "./$as_me.lineno"
# Exit status is that of the last command.
exit
}
ECHO_C= ECHO_N= ECHO_T=
case `echo -n x` in #(((((
-n*)
case `echo 'xy\c'` in
*c*) ECHO_T=' ';; # ECHO_T is single tab character.
xy) ECHO_C='\c';;
*) echo `echo ksh88 bug on AIX 6.1` > /dev/null
ECHO_T=' ';;
esac;;
*)
ECHO_N='-n';;
esac
rm -f conf$$ conf$$.exe conf$$.file
if test -d conf$$.dir; then
rm -f conf$$.dir/conf$$.file
else
rm -f conf$$.dir
mkdir conf$$.dir 2>/dev/null
fi
if (echo >conf$$.file) 2>/dev/null; then
if ln -s conf$$.file conf$$ 2>/dev/null; then
as_ln_s='ln -s'
# ... but there are two gotchas:
# 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
# 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
# In both cases, we have to default to `cp -pR'.
ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
as_ln_s='cp -pR'
elif ln conf$$.file conf$$ 2>/dev/null; then
as_ln_s=ln
else
as_ln_s='cp -pR'
fi
else
as_ln_s='cp -pR'
fi
rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
rmdir conf$$.dir 2>/dev/null
if mkdir -p . 2>/dev/null; then
as_mkdir_p='mkdir -p "$as_dir"'
else
test -d ./-p && rmdir ./-p
as_mkdir_p=false
fi
as_test_x='test -x'
as_executable_p=as_fn_executable_p
# Sed expression to map a string onto a valid CPP name.
as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
# Sed expression to map a string onto a valid variable name.
as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
test -n "$DJDIR" || exec 7<&0 &1
# Name of the host.
# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status,
# so uname gets run too.
ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
#
# Initializations.
#
ac_default_prefix=/usr/local
ac_clean_files=
ac_config_libobj_dir=.
LIBOBJS=
cross_compiling=no
subdirs=
MFLAGS=
MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME=
PACKAGE_TARNAME=
PACKAGE_VERSION=
PACKAGE_STRING=
PACKAGE_BUGREPORT=
PACKAGE_URL=
ac_unique_file="base/icinga.c"
ac_default_prefix=/usr/local/icinga
# Factoring default headers for most tests.
ac_includes_default="\
#include
#ifdef HAVE_SYS_TYPES_H
# include
#endif
#ifdef HAVE_SYS_STAT_H
# include
#endif
#ifdef STDC_HEADERS
# include
# include
#else
# ifdef HAVE_STDLIB_H
# include
# endif
#endif
#ifdef HAVE_STRING_H
# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
# include
# endif
# include
#endif
#ifdef HAVE_STRINGS_H
# include
#endif
#ifdef HAVE_INTTYPES_H
# include
#endif
#ifdef HAVE_STDINT_H
# include
#endif
#ifdef HAVE_UNISTD_H
# include
#endif"
ac_subst_vars='LTLIBOBJS
LIBOBJS
TESTS_CFLAGS
HAVE_SSL
ido2db_perl
PERL
ENABLE_DEBUG
USE_IDOUTILS_ORACLE
USE_IDOUTILS
USE_EVENTBROKER
INSTALLPERLSTUFF
INIT_OPTS
INITDIR
BASEEXTRALIBS
PERLXSI_O
PERLDIR
PERLLIBS
GDLIBS
CGIEXTRAS
SOL_PKG_NAME
ARCH
VERSION
PACKDIR
ido2db_runtime
ido2db_name
icingastats_name
icinga_name
LIBDBIDRIVERDIR
DBLIBS
IDO_INSTANCE_NAME
CLASSICUI_STANDALONE_FLAG
BROKER_H
BROKER_O
MOD_LDFLAGS
MOD_CFLAGS
BROKERLIBS
BROKER_LDFLAGS
mainurl
htmurl
cgiurl
XDDH
XDDC
XPDH
XPDC
XODH
XODC
XRDH
XRDC
XCDH
XCDC
XSDH
XSDC
IDOMODTMPFILE
IDOSOCKFILE
IDO2DBLOCKFILE
ICINGACHKFILE
lockfile
systemd_sysconfig_dir
systemd_unit_dir
init_dir
P1FILELOC
PHPAPIEXTCMDDIR
EXTCMDFILEDIR
CGILOGDIR
ENABLECGILOG
LOGDIR
ENABLEPERFDATA
EVENTHANDLERDIR
PLUGINDIR
HTTPDCONFFILE
HTTPAUTHFILE
STATEDIR
TMPFILE
TMPDIR
CHECKRESULTDIR
APACHE24_DEBIAN
HTTPD_CONF
MAIL_PROG
INSTALL_OPTS_WEB
web_group
web_user
COMMAND_OPTS
command_grp
command_user
INSTALL_OPTS
icinga_grp
icinga_user
THREADLIBS
OTHERLIBS
SOCKETLIBS
SNPRINTF_O_IDO
SNPRINTF_O
EGREP
GREP
CPP
STRIP
SET_MAKE
OBJEXT
EXEEXT
ac_ct_CC
CPPFLAGS
LDFLAGS
CFLAGS
CC
host_os
host_vendor
host_cpu
host
build_os
build_vendor
build_cpu
build
INSTALL
INSTALL_DATA
INSTALL_SCRIPT
INSTALL_PROGRAM
target_alias
host_alias
build_alias
LIBS
ECHO_T
ECHO_N
ECHO_C
DEFS
mandir
localedir
libdir
psdir
pdfdir
dvidir
htmldir
infodir
docdir
oldincludedir
includedir
localstatedir
sharedstatedir
sysconfdir
datadir
datarootdir
libexecdir
sbindir
bindir
program_transform_name
prefix
exec_prefix
PACKAGE_URL
PACKAGE_BUGREPORT
PACKAGE_STRING
PACKAGE_VERSION
PACKAGE_TARNAME
PACKAGE_NAME
PATH_SEPARATOR
SHELL'
ac_subst_files=''
ac_user_opts='
enable_option_checking
with_icinga_user
with_icinga_group
with_command_user
with_command_group
with_web_user
with_web_group
with_mail
with_httpd_conf
with_checkresult_dir
with_temp_dir
with_temp_file
with_state_dir
with_http_auth_file
with_httpd_conf_file
with_plugin_dir
with_eventhandler_dir
enable_perfdata
with_log_dir
enable_cgi_log
with_cgi_log_dir
with_ext_cmd_file_dir
with_p1_file_dir
with_init_dir
with_systemd_unit_dir
with_systemd_sysconfig_dir
with_lockfile
with_icinga_chkfile
with_ido2db_lockfile
with_ido_sockfile
with_idomod_tmpfile
with_gd_lib
with_gd_inc
enable_statusmap
enable_debug
with_cgiurl
with_htmurl
with_mainurl
enable_nanosleep
enable_event_broker
enable_classicui_standalone
enable_idoutils
with_ido_instance_name
enable_oracle
enable_pgsql
with_ocilib_lib
with_ocilib_inc
with_oracle_lib
with_pgsql_lib
with_psql_inc
with_dbi_lib
with_dbi_inc
with_libdbi_driver_dir
enable_embedded_perl
with_perlcache
enable_cygwin
enable_libtap
enable_nagiosenv
enable_ssl
with_ssl
with_ssl_inc
with_ssl_lib
with_kerberos_inc
'
ac_precious_vars='build_alias
host_alias
target_alias
CC
CFLAGS
LDFLAGS
LIBS
CPPFLAGS
CPP'
# Initialize some variables set by options.
ac_init_help=
ac_init_version=false
ac_unrecognized_opts=
ac_unrecognized_sep=
# The variables have the same names as the options, with
# dashes changed to underlines.
cache_file=/dev/null
exec_prefix=NONE
no_create=
no_recursion=
prefix=NONE
program_prefix=NONE
program_suffix=NONE
program_transform_name=s,x,x,
silent=
site=
srcdir=
verbose=
x_includes=NONE
x_libraries=NONE
# Installation directory options.
# These are left unexpanded so users can "make install exec_prefix=/foo"
# and all the variables that are supposed to be based on exec_prefix
# by default will actually change.
# Use braces instead of parens because sh, perl, etc. also accept them.
# (The list follows the same order as the GNU Coding Standards.)
bindir='${exec_prefix}/bin'
sbindir='${exec_prefix}/sbin'
libexecdir='${exec_prefix}/libexec'
datarootdir='${prefix}/share'
datadir='${datarootdir}'
sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var'
includedir='${prefix}/include'
oldincludedir='/usr/include'
docdir='${datarootdir}/doc/${PACKAGE}'
infodir='${datarootdir}/info'
htmldir='${docdir}'
dvidir='${docdir}'
pdfdir='${docdir}'
psdir='${docdir}'
libdir='${exec_prefix}/lib'
localedir='${datarootdir}/locale'
mandir='${datarootdir}/man'
ac_prev=
ac_dashdash=
for ac_option
do
# If the previous option needs an argument, assign it.
if test -n "$ac_prev"; then
eval $ac_prev=\$ac_option
ac_prev=
continue
fi
case $ac_option in
*=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;;
*=) ac_optarg= ;;
*) ac_optarg=yes ;;
esac
# Accept the important Cygnus configure options, so we can diagnose typos.
case $ac_dashdash$ac_option in
--)
ac_dashdash=yes ;;
-bindir | --bindir | --bindi | --bind | --bin | --bi)
ac_prev=bindir ;;
-bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
bindir=$ac_optarg ;;
-build | --build | --buil | --bui | --bu)
ac_prev=build_alias ;;
-build=* | --build=* | --buil=* | --bui=* | --bu=*)
build_alias=$ac_optarg ;;
-cache-file | --cache-file | --cache-fil | --cache-fi \
| --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
ac_prev=cache_file ;;
-cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
| --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
cache_file=$ac_optarg ;;
--config-cache | -C)
cache_file=config.cache ;;
-datadir | --datadir | --datadi | --datad)
ac_prev=datadir ;;
-datadir=* | --datadir=* | --datadi=* | --datad=*)
datadir=$ac_optarg ;;
-datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \
| --dataroo | --dataro | --datar)
ac_prev=datarootdir ;;
-datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \
| --dataroot=* | --dataroo=* | --dataro=* | --datar=*)
datarootdir=$ac_optarg ;;
-disable-* | --disable-*)
ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
# Reject names that are not valid shell variable names.
expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
as_fn_error $? "invalid feature name: $ac_useropt"
ac_useropt_orig=$ac_useropt
ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
case $ac_user_opts in
*"
"enable_$ac_useropt"
"*) ;;
*) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig"
ac_unrecognized_sep=', ';;
esac
eval enable_$ac_useropt=no ;;
-docdir | --docdir | --docdi | --doc | --do)
ac_prev=docdir ;;
-docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*)
docdir=$ac_optarg ;;
-dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv)
ac_prev=dvidir ;;
-dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*)
dvidir=$ac_optarg ;;
-enable-* | --enable-*)
ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
# Reject names that are not valid shell variable names.
expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
as_fn_error $? "invalid feature name: $ac_useropt"
ac_useropt_orig=$ac_useropt
ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
case $ac_user_opts in
*"
"enable_$ac_useropt"
"*) ;;
*) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig"
ac_unrecognized_sep=', ';;
esac
eval enable_$ac_useropt=\$ac_optarg ;;
-exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
| --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
| --exec | --exe | --ex)
ac_prev=exec_prefix ;;
-exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
| --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
| --exec=* | --exe=* | --ex=*)
exec_prefix=$ac_optarg ;;
-gas | --gas | --ga | --g)
# Obsolete; use --with-gas.
with_gas=yes ;;
-help | --help | --hel | --he | -h)
ac_init_help=long ;;
-help=r* | --help=r* | --hel=r* | --he=r* | -hr*)
ac_init_help=recursive ;;
-help=s* | --help=s* | --hel=s* | --he=s* | -hs*)
ac_init_help=short ;;
-host | --host | --hos | --ho)
ac_prev=host_alias ;;
-host=* | --host=* | --hos=* | --ho=*)
host_alias=$ac_optarg ;;
-htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht)
ac_prev=htmldir ;;
-htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \
| --ht=*)
htmldir=$ac_optarg ;;
-includedir | --includedir | --includedi | --included | --include \
| --includ | --inclu | --incl | --inc)
ac_prev=includedir ;;
-includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
| --includ=* | --inclu=* | --incl=* | --inc=*)
includedir=$ac_optarg ;;
-infodir | --infodir | --infodi | --infod | --info | --inf)
ac_prev=infodir ;;
-infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
infodir=$ac_optarg ;;
-libdir | --libdir | --libdi | --libd)
ac_prev=libdir ;;
-libdir=* | --libdir=* | --libdi=* | --libd=*)
libdir=$ac_optarg ;;
-libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
| --libexe | --libex | --libe)
ac_prev=libexecdir ;;
-libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
| --libexe=* | --libex=* | --libe=*)
libexecdir=$ac_optarg ;;
-localedir | --localedir | --localedi | --localed | --locale)
ac_prev=localedir ;;
-localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*)
localedir=$ac_optarg ;;
-localstatedir | --localstatedir | --localstatedi | --localstated \
| --localstate | --localstat | --localsta | --localst | --locals)
ac_prev=localstatedir ;;
-localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
| --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*)
localstatedir=$ac_optarg ;;
-mandir | --mandir | --mandi | --mand | --man | --ma | --m)
ac_prev=mandir ;;
-mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
mandir=$ac_optarg ;;
-nfp | --nfp | --nf)
# Obsolete; use --without-fp.
with_fp=no ;;
-no-create | --no-create | --no-creat | --no-crea | --no-cre \
| --no-cr | --no-c | -n)
no_create=yes ;;
-no-recursion | --no-recursion | --no-recursio | --no-recursi \
| --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
no_recursion=yes ;;
-oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
| --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
| --oldin | --oldi | --old | --ol | --o)
ac_prev=oldincludedir ;;
-oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
| --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
| --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
oldincludedir=$ac_optarg ;;
-prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
ac_prev=prefix ;;
-prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
prefix=$ac_optarg ;;
-program-prefix | --program-prefix | --program-prefi | --program-pref \
| --program-pre | --program-pr | --program-p)
ac_prev=program_prefix ;;
-program-prefix=* | --program-prefix=* | --program-prefi=* \
| --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
program_prefix=$ac_optarg ;;
-program-suffix | --program-suffix | --program-suffi | --program-suff \
| --program-suf | --program-su | --program-s)
ac_prev=program_suffix ;;
-program-suffix=* | --program-suffix=* | --program-suffi=* \
| --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
program_suffix=$ac_optarg ;;
-program-transform-name | --program-transform-name \
| --program-transform-nam | --program-transform-na \
| --program-transform-n | --program-transform- \
| --program-transform | --program-transfor \
| --program-transfo | --program-transf \
| --program-trans | --program-tran \
| --progr-tra | --program-tr | --program-t)
ac_prev=program_transform_name ;;
-program-transform-name=* | --program-transform-name=* \
| --program-transform-nam=* | --program-transform-na=* \
| --program-transform-n=* | --program-transform-=* \
| --program-transform=* | --program-transfor=* \
| --program-transfo=* | --program-transf=* \
| --program-trans=* | --program-tran=* \
| --progr-tra=* | --program-tr=* | --program-t=*)
program_transform_name=$ac_optarg ;;
-pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd)
ac_prev=pdfdir ;;
-pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*)
pdfdir=$ac_optarg ;;
-psdir | --psdir | --psdi | --psd | --ps)
ac_prev=psdir ;;
-psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*)
psdir=$ac_optarg ;;
-q | -quiet | --quiet | --quie | --qui | --qu | --q \
| -silent | --silent | --silen | --sile | --sil)
silent=yes ;;
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
ac_prev=sbindir ;;
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
| --sbi=* | --sb=*)
sbindir=$ac_optarg ;;
-sharedstatedir | --sharedstatedir | --sharedstatedi \
| --sharedstated | --sharedstate | --sharedstat | --sharedsta \
| --sharedst | --shareds | --shared | --share | --shar \
| --sha | --sh)
ac_prev=sharedstatedir ;;
-sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
| --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
| --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
| --sha=* | --sh=*)
sharedstatedir=$ac_optarg ;;
-site | --site | --sit)
ac_prev=site ;;
-site=* | --site=* | --sit=*)
site=$ac_optarg ;;
-srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
ac_prev=srcdir ;;
-srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
srcdir=$ac_optarg ;;
-sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
| --syscon | --sysco | --sysc | --sys | --sy)
ac_prev=sysconfdir ;;
-sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
| --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
sysconfdir=$ac_optarg ;;
-target | --target | --targe | --targ | --tar | --ta | --t)
ac_prev=target_alias ;;
-target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
target_alias=$ac_optarg ;;
-v | -verbose | --verbose | --verbos | --verbo | --verb)
verbose=yes ;;
-version | --version | --versio | --versi | --vers | -V)
ac_init_version=: ;;
-with-* | --with-*)
ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
# Reject names that are not valid shell variable names.
expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
as_fn_error $? "invalid package name: $ac_useropt"
ac_useropt_orig=$ac_useropt
ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
case $ac_user_opts in
*"
"with_$ac_useropt"
"*) ;;
*) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig"
ac_unrecognized_sep=', ';;
esac
eval with_$ac_useropt=\$ac_optarg ;;
-without-* | --without-*)
ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'`
# Reject names that are not valid shell variable names.
expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
as_fn_error $? "invalid package name: $ac_useropt"
ac_useropt_orig=$ac_useropt
ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
case $ac_user_opts in
*"
"with_$ac_useropt"
"*) ;;
*) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig"
ac_unrecognized_sep=', ';;
esac
eval with_$ac_useropt=no ;;
--x)
# Obsolete; use --with-x.
with_x=yes ;;
-x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
| --x-incl | --x-inc | --x-in | --x-i)
ac_prev=x_includes ;;
-x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
| --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
x_includes=$ac_optarg ;;
-x-libraries | --x-libraries | --x-librarie | --x-librari \
| --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
ac_prev=x_libraries ;;
-x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
| --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
x_libraries=$ac_optarg ;;
-*) as_fn_error $? "unrecognized option: \`$ac_option'
Try \`$0 --help' for more information"
;;
*=*)
ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
# Reject names that are not valid shell variable names.
case $ac_envvar in #(
'' | [0-9]* | *[!_$as_cr_alnum]* )
as_fn_error $? "invalid variable name: \`$ac_envvar'" ;;
esac
eval $ac_envvar=\$ac_optarg
export $ac_envvar ;;
*)
# FIXME: should be removed in autoconf 3.0.
$as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2
expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
$as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2
: "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}"
;;
esac
done
if test -n "$ac_prev"; then
ac_option=--`echo $ac_prev | sed 's/_/-/g'`
as_fn_error $? "missing argument to $ac_option"
fi
if test -n "$ac_unrecognized_opts"; then
case $enable_option_checking in
no) ;;
fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;;
*) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
esac
fi
# Check all directory arguments for consistency.
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
datadir sysconfdir sharedstatedir localstatedir includedir \
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
libdir localedir mandir
do
eval ac_val=\$$ac_var
# Remove trailing slashes.
case $ac_val in
*/ )
ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'`
eval $ac_var=\$ac_val;;
esac
# Be sure to have absolute directory names.
case $ac_val in
[\\/$]* | ?:[\\/]* ) continue;;
NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
esac
as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val"
done
# There might be people who depend on the old broken behavior: `$host'
# used to hold the argument of --host etc.
# FIXME: To remove some day.
build=$build_alias
host=$host_alias
target=$target_alias
# FIXME: To remove some day.
if test "x$host_alias" != x; then
if test "x$build_alias" = x; then
cross_compiling=maybe
elif test "x$build_alias" != "x$host_alias"; then
cross_compiling=yes
fi
fi
ac_tool_prefix=
test -n "$host_alias" && ac_tool_prefix=$host_alias-
test "$silent" = yes && exec 6>/dev/null
ac_pwd=`pwd` && test -n "$ac_pwd" &&
ac_ls_di=`ls -di .` &&
ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` ||
as_fn_error $? "working directory cannot be determined"
test "X$ac_ls_di" = "X$ac_pwd_ls_di" ||
as_fn_error $? "pwd does not report name of working directory"
# Find the source files, if location was not specified.
if test -z "$srcdir"; then
ac_srcdir_defaulted=yes
# Try the directory containing this script, then the parent directory.
ac_confdir=`$as_dirname -- "$as_myself" ||
$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
X"$as_myself" : 'X\(//\)[^/]' \| \
X"$as_myself" : 'X\(//\)$' \| \
X"$as_myself" : 'X\(/\)' \| . 2>/dev/null ||
$as_echo X"$as_myself" |
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
s//\1/
q
}
/^X\(\/\/\)[^/].*/{
s//\1/
q
}
/^X\(\/\/\)$/{
s//\1/
q
}
/^X\(\/\).*/{
s//\1/
q
}
s/.*/./; q'`
srcdir=$ac_confdir
if test ! -r "$srcdir/$ac_unique_file"; then
srcdir=..
fi
else
ac_srcdir_defaulted=no
fi
if test ! -r "$srcdir/$ac_unique_file"; then
test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .."
as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir"
fi
ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work"
ac_abs_confdir=`(
cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg"
pwd)`
# When building in place, set srcdir=.
if test "$ac_abs_confdir" = "$ac_pwd"; then
srcdir=.
fi
# Remove unnecessary trailing slashes from srcdir.
# Double slashes in file names in object file debugging info
# mess up M-x gdb in Emacs.
case $srcdir in
*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;;
esac
for ac_var in $ac_precious_vars; do
eval ac_env_${ac_var}_set=\${${ac_var}+set}
eval ac_env_${ac_var}_value=\$${ac_var}
eval ac_cv_env_${ac_var}_set=\${${ac_var}+set}
eval ac_cv_env_${ac_var}_value=\$${ac_var}
done
#
# Report the --help message.
#
if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures this package to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
-q, --quiet, --silent do not print \`checking ...' messages
--cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for \`--cache-file=config.cache'
-n, --no-create do not create output files
--srcdir=DIR find the sources in DIR [configure dir or \`..']
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[$ac_default_prefix]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
By default, \`make install' will install all the files in
\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify
an installation prefix other than \`$ac_default_prefix' using \`--prefix',
for instance \`--prefix=\$HOME'.
For better control, use the options below.
Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system admin executables [EPREFIX/sbin]
--libexecdir=DIR program executables [EPREFIX/libexec]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
--datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
--datadir=DIR read-only architecture-independent data [DATAROOTDIR]
--infodir=DIR info documentation [DATAROOTDIR/info]
--localedir=DIR locale-dependent data [DATAROOTDIR/locale]
--mandir=DIR man documentation [DATAROOTDIR/man]
--docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE]
--htmldir=DIR html documentation [DOCDIR]
--dvidir=DIR dvi documentation [DOCDIR]
--pdfdir=DIR pdf documentation [DOCDIR]
--psdir=DIR ps documentation [DOCDIR]
_ACEOF
cat <<\_ACEOF
System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD]
_ACEOF
fi
if test -n "$ac_init_help"; then
cat <<\_ACEOF
Optional Features:
--disable-option-checking ignore unrecognized --enable/--with options
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--enable-perfdata enables perfdata in icinga.cfg
--enable-cgi-log enables cgi logging - experimental!!
--disable-statusmap disables compilation of statusmap CGI
--enable-debug enables debug mode
--enable-nanosleep enables use of nanosleep (instead sleep) in event
timing
--enable-event-broker enables integration of event broker routines
--enable-classicui-standalone
enables standalone Classic UI (default: disabled)
--enable-idoutils enables database connectivity using idoutils
(default: enabled)
--enable-oracle enables idoutils with ocilib and oracle
--enable-pgsql !use libdbis pgsql support instead, libpq not yet
implemented! enables idoutils with libpq and pgsql
--enable-embedded-perl will enable embedded Perl interpreter
--enable-cygwin enables building under the CYGWIN environment
--enable-libtap this is deprecated, libtap is built with make test
--enable-nagiosenv expose Icinga Environment variables as NAGIOS_*)
--enable-ssl enables native SSL support
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-icinga-user=
sets user name to run icinga
--with-icinga-group=
sets group name to run icinga
--with-command-user=
sets user name for command access
--with-command-group=
sets group name for command access
--with-web-user=USER username for web writable files (default www-data)
--with-web-group=GROUP group for web writable files (default www-data)
--with-mail=
sets path to equivalent program to mail
--with-httpd-conf=
sets path to Apache conf.d directory
--with-checkresult-dir=
sets path to check results spool directory
--with-temp-dir= sets path to temp directory path where Icinga can
create temp files for service/host check results
--with-temp-file=
sets path to an Icinga exclusive update temp file
i.e. /tmp/icinga.tmp
--with-state-dir=
sets path to custom localstate dir e.g.
/var/spool/icinga
--with-http-auth-file=
sets path to an Icinga HTTP auth file
--with-httpd-conf-file=
sets path to Icinga HTTPD config file
--with-plugin-dir=
sets path to plugins directory path i.e.
$prefix/libexec
--with-eventhandler-dir=
sets path to eventhandlers directory path i.e.
$prefix/libexec/eventhandlers
--with-log-dir= sets path to logging directory
--with-cgi-log-dir=
sets path to cgi logging directory
--with-ext-cmd-file-dir=
sets path to external command file directory
--with-p1-file-dir=
sets path to embedded perl p1.pl directory
--with-init-dir= sets directory to place init script into
--with-systemd-unitdir=
sets directory to place systemd service file into
--with-systemd-sysconfigdir=
sets directory to place systemd service
configuration file
--with-lockfile= sets path and file name for lock file
--with-icinga-chkfile=
sets path and file name for icinga initscript error
file
--with-ido2db-lockfile=
sets path and file name for ido2db lock file
--with-ido-sockfile=
sets path and file name for ido sock file
--with-idomod-tmpfile=
sets path and file name for idomod tmp file
--with-gd-lib=DIR sets location of the gd library
--with-gd-inc=DIR sets location of the gd include files
--with-cgiurl=
sets URL for cgi programs (do not use a trailing
slash)
--with-htmurl=
sets URL for public html
--with-mainurl=
sets URL for default main frame in index.html (use
quotes if special chars like & used)
--with-ido-instance-name=
sets instance_name for IDOUtils in idomod.cfg
--with-ocilib-lib=DIR sets location of the ocilib library
--with-ocilib-inc=DIR sets location of the ocilib include files,
--with-oracle-lib=DIR sets location of the oracle library
--with-pgsql-lib=DIR !use libdbis pgsql support instead, libpq not yet
implemented! sets location of the pgsql library
--with-pgsql-inc=DIR !use libdbis pgsql support instead, libpq not yet
implemented! sets location of the pgsql include
files,
--with-dbi-lib=DIR sets location of the libdbi library
--with-dbi-inc=DIR sets location of the libdbi include files,
--with-libdbi-driver-dir=
sets path to libdbi driver directory path (only
valid with libdbi, not oracle ocilib)
--with-perlcache turns on cacheing of internally compiled Perl
scripts
--with-ssl=DIR sets location of the SSL installation
--with-ssl-inc=DIR sets location of the SSL include files
--with-ssl-lib=DIR sets location of the SSL libraries
--with-kerberos-inc=DIR sets location of the Kerberos include files
Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L if you have libraries in a
nonstandard directory
LIBS libraries to pass to the linker, e.g. -l
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if
you have headers in a nonstandard directory
CPP C preprocessor
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
Report bugs to the package provider.
_ACEOF
ac_status=$?
fi
if test "$ac_init_help" = "recursive"; then
# If there are subdirs, report their specific --help.
for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
test -d "$ac_dir" ||
{ cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } ||
continue
ac_builddir=.
case "$ac_dir" in
.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
*)
ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
# A ".." for each directory in $ac_dir_suffix.
ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
case $ac_top_builddir_sub in
"") ac_top_builddir_sub=. ac_top_build_prefix= ;;
*) ac_top_build_prefix=$ac_top_builddir_sub/ ;;
esac ;;
esac
ac_abs_top_builddir=$ac_pwd
ac_abs_builddir=$ac_pwd$ac_dir_suffix
# for backward compatibility:
ac_top_builddir=$ac_top_build_prefix
case $srcdir in
.) # We are building in place.
ac_srcdir=.
ac_top_srcdir=$ac_top_builddir_sub
ac_abs_top_srcdir=$ac_pwd ;;
[\\/]* | ?:[\\/]* ) # Absolute name.
ac_srcdir=$srcdir$ac_dir_suffix;
ac_top_srcdir=$srcdir
ac_abs_top_srcdir=$srcdir ;;
*) # Relative name.
ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
ac_top_srcdir=$ac_top_build_prefix$srcdir
ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
esac
ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
cd "$ac_dir" || { ac_status=$?; continue; }
# Check for guested configure.
if test -f "$ac_srcdir/configure.gnu"; then
echo &&
$SHELL "$ac_srcdir/configure.gnu" --help=recursive
elif test -f "$ac_srcdir/configure"; then
echo &&
$SHELL "$ac_srcdir/configure" --help=recursive
else
$as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
fi || ac_status=$?
cd "$ac_pwd" || { ac_status=$?; break; }
done
fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
configure
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
This configure script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it.
_ACEOF
exit
fi
## ------------------------ ##
## Autoconf initialization. ##
## ------------------------ ##
# ac_fn_c_try_compile LINENO
# --------------------------
# Try to compile conftest.$ac_ext, and return whether this succeeded.
ac_fn_c_try_compile ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
rm -f conftest.$ac_objext
if { { ac_try="$ac_compile"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
(eval "$ac_compile") 2>conftest.err
ac_status=$?
if test -s conftest.err; then
grep -v '^ *+' conftest.err >conftest.er1
cat conftest.er1 >&5
mv -f conftest.er1 conftest.err
fi
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; } && {
test -z "$ac_c_werror_flag" ||
test ! -s conftest.err
} && test -s conftest.$ac_objext; then :
ac_retval=0
else
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_retval=1
fi
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
as_fn_set_status $ac_retval
} # ac_fn_c_try_compile
# ac_fn_c_try_cpp LINENO
# ----------------------
# Try to preprocess conftest.$ac_ext, and return whether this succeeded.
ac_fn_c_try_cpp ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
if { { ac_try="$ac_cpp conftest.$ac_ext"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
(eval "$ac_cpp conftest.$ac_ext") 2>conftest.err
ac_status=$?
if test -s conftest.err; then
grep -v '^ *+' conftest.err >conftest.er1
cat conftest.er1 >&5
mv -f conftest.er1 conftest.err
fi
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; } > conftest.i && {
test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
test ! -s conftest.err
}; then :
ac_retval=0
else
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_retval=1
fi
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
as_fn_set_status $ac_retval
} # ac_fn_c_try_cpp
# ac_fn_c_try_run LINENO
# ----------------------
# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
# that executables *can* be run.
ac_fn_c_try_run ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
if { { ac_try="$ac_link"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
(eval "$ac_link") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
{ { case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
(eval "$ac_try") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; }; then :
ac_retval=0
else
$as_echo "$as_me: program exited with status $ac_status" >&5
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_retval=$ac_status
fi
rm -rf conftest.dSYM conftest_ipa8_conftest.oo
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
as_fn_set_status $ac_retval
} # ac_fn_c_try_run
# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES
# -------------------------------------------------------
# Tests whether HEADER exists, giving a warning if it cannot be compiled using
# the include files in INCLUDES and setting the cache variable VAR
# accordingly.
ac_fn_c_check_header_mongrel ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
if eval \${$3+:} false; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
$as_echo_n "checking for $2... " >&6; }
if eval \${$3+:} false; then :
$as_echo_n "(cached) " >&6
fi
eval ac_res=\$$3
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
else
# Is the header compilable?
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5
$as_echo_n "checking $2 usability... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
$4
#include <$2>
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
ac_header_compiler=yes
else
ac_header_compiler=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5
$as_echo "$ac_header_compiler" >&6; }
# Is the header present?
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5
$as_echo_n "checking $2 presence... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <$2>
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :
ac_header_preproc=yes
else
ac_header_preproc=no
fi
rm -f conftest.err conftest.i conftest.$ac_ext
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5
$as_echo "$ac_header_preproc" >&6; }
# So? What about this header?
case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #((
yes:no: )
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5
$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
;;
no:yes:* )
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5
$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5
$as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5
$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5
$as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
;;
esac
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
$as_echo_n "checking for $2... " >&6; }
if eval \${$3+:} false; then :
$as_echo_n "(cached) " >&6
else
eval "$3=\$ac_header_compiler"
fi
eval ac_res=\$$3
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
fi
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
} # ac_fn_c_check_header_mongrel
# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES
# -------------------------------------------------------
# Tests whether HEADER exists and can be compiled using the include files in
# INCLUDES, setting the cache variable VAR accordingly.
ac_fn_c_check_header_compile ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
$as_echo_n "checking for $2... " >&6; }
if eval \${$3+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
$4
#include <$2>
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
eval "$3=yes"
else
eval "$3=no"
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
eval ac_res=\$$3
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
} # ac_fn_c_check_header_compile
# ac_fn_c_check_member LINENO AGGR MEMBER VAR INCLUDES
# ----------------------------------------------------
# Tries to find if the field MEMBER exists in type AGGR, after including
# INCLUDES, setting cache variable VAR accordingly.
ac_fn_c_check_member ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5
$as_echo_n "checking for $2.$3... " >&6; }
if eval \${$4+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
$5
int
main ()
{
static $2 ac_aggr;
if (ac_aggr.$3)
return 0;
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
eval "$4=yes"
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
$5
int
main ()
{
static $2 ac_aggr;
if (sizeof ac_aggr.$3)
return 0;
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
eval "$4=yes"
else
eval "$4=no"
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
eval ac_res=\$$4
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
} # ac_fn_c_check_member
# ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES
# ---------------------------------------------
# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR
# accordingly.
ac_fn_c_check_decl ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
as_decl_name=`echo $2|sed 's/ *(.*//'`
as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5
$as_echo_n "checking whether $as_decl_name is declared... " >&6; }
if eval \${$3+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
$4
int
main ()
{
#ifndef $as_decl_name
#ifdef __cplusplus
(void) $as_decl_use;
#else
(void) $as_decl_name;
#endif
#endif
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
eval "$3=yes"
else
eval "$3=no"
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
eval ac_res=\$$3
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
} # ac_fn_c_check_decl
# ac_fn_c_try_link LINENO
# -----------------------
# Try to link conftest.$ac_ext, and return whether this succeeded.
ac_fn_c_try_link ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
rm -f conftest.$ac_objext conftest$ac_exeext
if { { ac_try="$ac_link"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
(eval "$ac_link") 2>conftest.err
ac_status=$?
if test -s conftest.err; then
grep -v '^ *+' conftest.err >conftest.er1
cat conftest.er1 >&5
mv -f conftest.er1 conftest.err
fi
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; } && {
test -z "$ac_c_werror_flag" ||
test ! -s conftest.err
} && test -s conftest$ac_exeext && {
test "$cross_compiling" = yes ||
test -x conftest$ac_exeext
}; then :
ac_retval=0
else
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_retval=1
fi
# Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
# created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
# interfere with the next link command; also delete a directory that is
# left behind by Apple's compiler. We do this before executing the actions.
rm -rf conftest.dSYM conftest_ipa8_conftest.oo
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
as_fn_set_status $ac_retval
} # ac_fn_c_try_link
# ac_fn_c_check_type LINENO TYPE VAR INCLUDES
# -------------------------------------------
# Tests whether TYPE exists after having included INCLUDES, setting cache
# variable VAR accordingly.
ac_fn_c_check_type ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
$as_echo_n "checking for $2... " >&6; }
if eval \${$3+:} false; then :
$as_echo_n "(cached) " >&6
else
eval "$3=no"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
$4
int
main ()
{
if (sizeof ($2))
return 0;
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
$4
int
main ()
{
if (sizeof (($2)))
return 0;
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
else
eval "$3=yes"
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
eval ac_res=\$$3
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
} # ac_fn_c_check_type
# ac_fn_c_check_func LINENO FUNC VAR
# ----------------------------------
# Tests whether FUNC exists, setting the cache variable VAR accordingly
ac_fn_c_check_func ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
$as_echo_n "checking for $2... " >&6; }
if eval \${$3+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Define $2 to an innocuous variant, in case declares $2.
For example, HP-UX 11i declares gettimeofday. */
#define $2 innocuous_$2
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $2 (); below.
Prefer to if __STDC__ is defined, since
exists even on freestanding compilers. */
#ifdef __STDC__
# include
#else
# include
#endif
#undef $2
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char $2 ();
/* The GNU C library defines this for functions which it implements
to always fail with ENOSYS. Some functions are actually named
something starting with __ and the normal name is an alias. */
#if defined __stub_$2 || defined __stub___$2
choke me
#endif
int
main ()
{
return $2 ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
eval "$3=yes"
else
eval "$3=no"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
fi
eval ac_res=\$$3
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
} # ac_fn_c_check_func
cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by $as_me, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
_ACEOF
exec 5>>config.log
{
cat <<_ASUNAME
## --------- ##
## Platform. ##
## --------- ##
hostname = `(hostname || uname -n) 2>/dev/null | sed 1q`
uname -m = `(uname -m) 2>/dev/null || echo unknown`
uname -r = `(uname -r) 2>/dev/null || echo unknown`
uname -s = `(uname -s) 2>/dev/null || echo unknown`
uname -v = `(uname -v) 2>/dev/null || echo unknown`
/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`
/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown`
/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown`
/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown`
/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`
/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown`
/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown`
/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown`
/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown`
_ASUNAME
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
$as_echo "PATH: $as_dir"
done
IFS=$as_save_IFS
} >&5
cat >&5 <<_ACEOF
## ----------- ##
## Core tests. ##
## ----------- ##
_ACEOF
# Keep a trace of the command line.
# Strip out --no-create and --no-recursion so they do not pile up.
# Strip out --silent because we don't want to record it for future runs.
# Also quote any args containing shell meta-characters.
# Make two passes to allow for proper duplicate-argument suppression.
ac_configure_args=
ac_configure_args0=
ac_configure_args1=
ac_must_keep_next=false
for ac_pass in 1 2
do
for ac_arg
do
case $ac_arg in
-no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;
-q | -quiet | --quiet | --quie | --qui | --qu | --q \
| -silent | --silent | --silen | --sile | --sil)
continue ;;
*\'*)
ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
esac
case $ac_pass in
1) as_fn_append ac_configure_args0 " '$ac_arg'" ;;
2)
as_fn_append ac_configure_args1 " '$ac_arg'"
if test $ac_must_keep_next = true; then
ac_must_keep_next=false # Got value, back to normal.
else
case $ac_arg in
*=* | --config-cache | -C | -disable-* | --disable-* \
| -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \
| -q | -quiet | --q* | -silent | --sil* | -v | -verb* \
| -with-* | --with-* | -without-* | --without-* | --x)
case "$ac_configure_args0 " in
"$ac_configure_args1"*" '$ac_arg' "* ) continue ;;
esac
;;
-* ) ac_must_keep_next=true ;;
esac
fi
as_fn_append ac_configure_args " '$ac_arg'"
;;
esac
done
done
{ ac_configure_args0=; unset ac_configure_args0;}
{ ac_configure_args1=; unset ac_configure_args1;}
# When interrupted or exit'd, cleanup temporary files, and complete
# config.log. We remove comments because anyway the quotes in there
# would cause problems or look ugly.
# WARNING: Use '\'' to represent an apostrophe within the trap.
# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug.
trap 'exit_status=$?
# Save into config.log some information that might help in debugging.
{
echo
$as_echo "## ---------------- ##
## Cache variables. ##
## ---------------- ##"
echo
# The following way of writing the cache mishandles newlines in values,
(
for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do
eval ac_val=\$$ac_var
case $ac_val in #(
*${as_nl}*)
case $ac_var in #(
*_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
esac
case $ac_var in #(
_ | IFS | as_nl) ;; #(
BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
*) { eval $ac_var=; unset $ac_var;} ;;
esac ;;
esac
done
(set) 2>&1 |
case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #(
*${as_nl}ac_space=\ *)
sed -n \
"s/'\''/'\''\\\\'\'''\''/g;
s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p"
;; #(
*)
sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
;;
esac |
sort
)
echo
$as_echo "## ----------------- ##
## Output variables. ##
## ----------------- ##"
echo
for ac_var in $ac_subst_vars
do
eval ac_val=\$$ac_var
case $ac_val in
*\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
esac
$as_echo "$ac_var='\''$ac_val'\''"
done | sort
echo
if test -n "$ac_subst_files"; then
$as_echo "## ------------------- ##
## File substitutions. ##
## ------------------- ##"
echo
for ac_var in $ac_subst_files
do
eval ac_val=\$$ac_var
case $ac_val in
*\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
esac
$as_echo "$ac_var='\''$ac_val'\''"
done | sort
echo
fi
if test -s confdefs.h; then
$as_echo "## ----------- ##
## confdefs.h. ##
## ----------- ##"
echo
cat confdefs.h
echo
fi
test "$ac_signal" != 0 &&
$as_echo "$as_me: caught signal $ac_signal"
$as_echo "$as_me: exit $exit_status"
} >&5
rm -f core *.core core.conftest.* &&
rm -f -r conftest* confdefs* conf$$* $ac_clean_files &&
exit $exit_status
' 0
for ac_signal in 1 2 13 15; do
trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal
done
ac_signal=0
# confdefs.h avoids OS command line length limits that DEFS can exceed.
rm -f -r conftest* confdefs.h
$as_echo "/* confdefs.h */" > confdefs.h
# Predefined preprocessor variables.
cat >>confdefs.h <<_ACEOF
#define PACKAGE_NAME "$PACKAGE_NAME"
_ACEOF
cat >>confdefs.h <<_ACEOF
#define PACKAGE_TARNAME "$PACKAGE_TARNAME"
_ACEOF
cat >>confdefs.h <<_ACEOF
#define PACKAGE_VERSION "$PACKAGE_VERSION"
_ACEOF
cat >>confdefs.h <<_ACEOF
#define PACKAGE_STRING "$PACKAGE_STRING"
_ACEOF
cat >>confdefs.h <<_ACEOF
#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
_ACEOF
cat >>confdefs.h <<_ACEOF
#define PACKAGE_URL "$PACKAGE_URL"
_ACEOF
# Let the site file select an alternate cache file if it wants to.
# Prefer an explicitly selected file to automatically selected ones.
ac_site_file1=NONE
ac_site_file2=NONE
if test -n "$CONFIG_SITE"; then
# We do not want a PATH search for config.site.
case $CONFIG_SITE in #((
-*) ac_site_file1=./$CONFIG_SITE;;
*/*) ac_site_file1=$CONFIG_SITE;;
*) ac_site_file1=./$CONFIG_SITE;;
esac
elif test "x$prefix" != xNONE; then
ac_site_file1=$prefix/share/config.site
ac_site_file2=$prefix/etc/config.site
else
ac_site_file1=$ac_default_prefix/share/config.site
ac_site_file2=$ac_default_prefix/etc/config.site
fi
for ac_site_file in "$ac_site_file1" "$ac_site_file2"
do
test "x$ac_site_file" = xNONE && continue
if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
$as_echo "$as_me: loading site script $ac_site_file" >&6;}
sed 's/^/| /' "$ac_site_file" >&5
. "$ac_site_file" \
|| { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "failed to load site script $ac_site_file
See \`config.log' for more details" "$LINENO" 5; }
fi
done
# Check that the precious variables saved in the cache have kept the same
# value.
ac_cache_corrupted=false
for ac_var in $ac_precious_vars; do
eval ac_old_set=\$ac_cv_env_${ac_var}_set
eval ac_new_set=\$ac_env_${ac_var}_set
eval ac_old_val=\$ac_cv_env_${ac_var}_value
eval ac_new_val=\$ac_env_${ac_var}_value
case $ac_old_set,$ac_new_set in
set,)
{ $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
ac_cache_corrupted=: ;;
,set)
{ $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5
$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
ac_cache_corrupted=: ;;
,);;
*)
if test "x$ac_old_val" != "x$ac_new_val"; then
# differences in whitespace do not lead to failure.
ac_old_val_w=`echo x $ac_old_val`
ac_new_val_w=`echo x $ac_new_val`
if test "$ac_old_val_w" != "$ac_new_val_w"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5
$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
ac_cache_corrupted=:
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5
$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;}
eval $ac_var=\$ac_old_val
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5
$as_echo "$as_me: former value: \`$ac_old_val'" >&2;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5
$as_echo "$as_me: current value: \`$ac_new_val'" >&2;}
fi;;
esac
# Pass precious variables to config.status.
if test "$ac_new_set" = set; then
case $ac_new_val in
*\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
*) ac_arg=$ac_var=$ac_new_val ;;
esac
case " $ac_configure_args " in
*" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy.
*) as_fn_append ac_configure_args " '$ac_arg'" ;;
esac
fi
done
if $ac_cache_corrupted; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5
$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;}
as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5
fi
## -------------------- ##
## Main body of script. ##
## -------------------- ##
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
ac_config_headers="$ac_config_headers include/config.h"
PKG_NAME=icinga-core
PKG_VERSION="1.10.3"
PKG_HOME_URL="http://www.icinga.org/"
PKG_REL_DATE="02-11-2014"
ac_aux_dir=
for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do
if test -f "$ac_dir/install-sh"; then
ac_aux_dir=$ac_dir
ac_install_sh="$ac_aux_dir/install-sh -c"
break
elif test -f "$ac_dir/install.sh"; then
ac_aux_dir=$ac_dir
ac_install_sh="$ac_aux_dir/install.sh -c"
break
elif test -f "$ac_dir/shtool"; then
ac_aux_dir=$ac_dir
ac_install_sh="$ac_aux_dir/shtool install -c"
break
fi
done
if test -z "$ac_aux_dir"; then
as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5
fi
# These three variables are undocumented and unsupported,
# and are intended to be withdrawn in a future Autoconf release.
# They can cause serious problems if a builder's source tree is in a directory
# whose full name contains unusual characters.
ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var.
ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var.
ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var.
# Find a good install program. We prefer a C program (faster),
# so one script is as good as another. But avoid the broken or
# incompatible versions:
# SysV /etc/install, /usr/sbin/install
# SunOS /usr/etc/install
# IRIX /sbin/install
# AIX /bin/install
# AmigaOS /C/install, which installs bootblocks on floppy discs
# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
# AFS /usr/afsws/bin/install, which mishandles nonexistent args
# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
# OS/2's system install, which has a completely different semantic
# ./install, which can be erroneously created by make from ./install.sh.
# Reject install programs that cannot install multiple files.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5
$as_echo_n "checking for a BSD-compatible install... " >&6; }
if test -z "$INSTALL"; then
if ${ac_cv_path_install+:} false; then :
$as_echo_n "(cached) " >&6
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
# Account for people who put trailing slashes in PATH elements.
case $as_dir/ in #((
./ | .// | /[cC]/* | \
/etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \
?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \
/usr/ucb/* ) ;;
*)
# OSF1 and SCO ODT 3.0 have their own names for install.
# Don't use installbsd from OSF since it installs stuff as root
# by default.
for ac_prog in ginstall scoinst install; do
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then
if test $ac_prog = install &&
grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
# AIX install. It has an incompatible calling convention.
:
elif test $ac_prog = install &&
grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
# program-specific install script used by HP pwplus--don't use.
:
else
rm -rf conftest.one conftest.two conftest.dir
echo one > conftest.one
echo two > conftest.two
mkdir conftest.dir
if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" &&
test -s conftest.one && test -s conftest.two &&
test -s conftest.dir/conftest.one &&
test -s conftest.dir/conftest.two
then
ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c"
break 3
fi
fi
fi
done
done
;;
esac
done
IFS=$as_save_IFS
rm -rf conftest.one conftest.two conftest.dir
fi
if test "${ac_cv_path_install+set}" = set; then
INSTALL=$ac_cv_path_install
else
# As a last resort, use the slow shell script. Don't cache a
# value for INSTALL within a source directory, because that will
# break other packages using the cache if that directory is
# removed, or if the value is a relative name.
INSTALL=$ac_install_sh
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5
$as_echo "$INSTALL" >&6; }
# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
# It thinks the first close brace ends the variable substitution.
test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'
test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
# Make sure we can run config.sub.
$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5
$as_echo_n "checking build system type... " >&6; }
if ${ac_cv_build+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_build_alias=$build_alias
test "x$ac_build_alias" = x &&
ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"`
test "x$ac_build_alias" = x &&
as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5
ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` ||
as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5
$as_echo "$ac_cv_build" >&6; }
case $ac_cv_build in
*-*-*) ;;
*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;;
esac
build=$ac_cv_build
ac_save_IFS=$IFS; IFS='-'
set x $ac_cv_build
shift
build_cpu=$1
build_vendor=$2
shift; shift
# Remember, the first character of IFS is used to create $*,
# except with old shells:
build_os=$*
IFS=$ac_save_IFS
case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5
$as_echo_n "checking host system type... " >&6; }
if ${ac_cv_host+:} false; then :
$as_echo_n "(cached) " >&6
else
if test "x$host_alias" = x; then
ac_cv_host=$ac_cv_build
else
ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` ||
as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5
$as_echo "$ac_cv_host" >&6; }
case $ac_cv_host in
*-*-*) ;;
*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;;
esac
host=$ac_cv_host
ac_save_IFS=$IFS; IFS='-'
set x $ac_cv_host
shift
host_cpu=$1
host_vendor=$2
shift; shift
# Remember, the first character of IFS is used to create $*,
# except with old shells:
host_os=$*
IFS=$ac_save_IFS
case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
if test -n "$ac_tool_prefix"; then
# Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
set dummy ${ac_tool_prefix}gcc; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CC+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -n "$CC"; then
ac_cv_prog_CC="$CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_CC="${ac_tool_prefix}gcc"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS
fi
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
$as_echo "$CC" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
fi
if test -z "$ac_cv_prog_CC"; then
ac_ct_CC=$CC
# Extract the first word of "gcc", so it can be a program name with args.
set dummy gcc; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_CC+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -n "$ac_ct_CC"; then
ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_ac_ct_CC="gcc"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS
fi
fi
ac_ct_CC=$ac_cv_prog_ac_ct_CC
if test -n "$ac_ct_CC"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
$as_echo "$ac_ct_CC" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
if test "x$ac_ct_CC" = x; then
CC=""
else
case $cross_compiling:$ac_tool_warned in
yes:)
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
CC=$ac_ct_CC
fi
else
CC="$ac_cv_prog_CC"
fi
if test -z "$CC"; then
if test -n "$ac_tool_prefix"; then
# Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
set dummy ${ac_tool_prefix}cc; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CC+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -n "$CC"; then
ac_cv_prog_CC="$CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_CC="${ac_tool_prefix}cc"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS
fi
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
$as_echo "$CC" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
fi
fi
if test -z "$CC"; then
# Extract the first word of "cc", so it can be a program name with args.
set dummy cc; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CC+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -n "$CC"; then
ac_cv_prog_CC="$CC" # Let the user override the test.
else
ac_prog_rejected=no
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
ac_prog_rejected=yes
continue
fi
ac_cv_prog_CC="cc"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS
if test $ac_prog_rejected = yes; then
# We found a bogon in the path, so make sure we never use it.
set dummy $ac_cv_prog_CC
shift
if test $# != 0; then
# We chose a different compiler from the bogus one.
# However, it has the same basename, so the bogon will be chosen
# first if we set CC to just the basename; use the full file name.
shift
ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@"
fi
fi
fi
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
$as_echo "$CC" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
fi
if test -z "$CC"; then
if test -n "$ac_tool_prefix"; then
for ac_prog in cl.exe
do
# Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
set dummy $ac_tool_prefix$ac_prog; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CC+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -n "$CC"; then
ac_cv_prog_CC="$CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS
fi
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
$as_echo "$CC" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
test -n "$CC" && break
done
fi
if test -z "$CC"; then
ac_ct_CC=$CC
for ac_prog in cl.exe
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_CC+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -n "$ac_ct_CC"; then
ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_ac_ct_CC="$ac_prog"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS
fi
fi
ac_ct_CC=$ac_cv_prog_ac_ct_CC
if test -n "$ac_ct_CC"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
$as_echo "$ac_ct_CC" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
test -n "$ac_ct_CC" && break
done
if test "x$ac_ct_CC" = x; then
CC=""
else
case $cross_compiling:$ac_tool_warned in
yes:)
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
CC=$ac_ct_CC
fi
fi
fi
test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "no acceptable C compiler found in \$PATH
See \`config.log' for more details" "$LINENO" 5; }
# Provide some information about the compiler.
$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
set X $ac_compile
ac_compiler=$2
for ac_option in --version -v -V -qversion; do
{ { ac_try="$ac_compiler $ac_option >&5"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
(eval "$ac_compiler $ac_option >&5") 2>conftest.err
ac_status=$?
if test -s conftest.err; then
sed '10a\
... rest of stderr output deleted ...
10q' conftest.err >conftest.er1
cat conftest.er1 >&5
fi
rm -f conftest.er1 conftest.err
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }
done
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
ac_clean_files_save=$ac_clean_files
ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out"
# Try to create an executable without -o first, disregard a.out.
# It will help us diagnose broken compilers, and finding out an intuition
# of exeext.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5
$as_echo_n "checking whether the C compiler works... " >&6; }
ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
# The possible output files:
ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*"
ac_rmfiles=
for ac_file in $ac_files
do
case $ac_file in
*.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
* ) ac_rmfiles="$ac_rmfiles $ac_file";;
esac
done
rm -f $ac_rmfiles
if { { ac_try="$ac_link_default"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
(eval "$ac_link_default") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then :
# Autoconf-2.13 could set the ac_cv_exeext variable to `no'.
# So ignore a value of `no', otherwise this would lead to `EXEEXT = no'
# in a Makefile. We should not override ac_cv_exeext if it was cached,
# so that the user can short-circuit this test for compilers unknown to
# Autoconf.
for ac_file in $ac_files ''
do
test -f "$ac_file" || continue
case $ac_file in
*.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj )
;;
[ab].out )
# We found the default executable, but exeext='' is most
# certainly right.
break;;
*.* )
if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
then :; else
ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
fi
# We set ac_cv_exeext here because the later test for it is not
# safe: cross compilers may not add the suffix if given an `-o'
# argument, so we may need to know it at that point already.
# Even if this section looks crufty: it has the advantage of
# actually working.
break;;
* )
break;;
esac
done
test "$ac_cv_exeext" = no && ac_cv_exeext=
else
ac_file=''
fi
if test -z "$ac_file"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error 77 "C compiler cannot create executables
See \`config.log' for more details" "$LINENO" 5; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5
$as_echo_n "checking for C compiler default output file name... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
$as_echo "$ac_file" >&6; }
ac_exeext=$ac_cv_exeext
rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out
ac_clean_files=$ac_clean_files_save
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5
$as_echo_n "checking for suffix of executables... " >&6; }
if { { ac_try="$ac_link"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
(eval "$ac_link") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then :
# If both `conftest.exe' and `conftest' are `present' (well, observable)
# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will
# work properly (i.e., refer to `conftest.exe'), while it won't with
# `rm'.
for ac_file in conftest.exe conftest conftest.*; do
test -f "$ac_file" || continue
case $ac_file in
*.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
*.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
break;;
* ) break;;
esac
done
else
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "cannot compute suffix of executables: cannot compile and link
See \`config.log' for more details" "$LINENO" 5; }
fi
rm -f conftest conftest$ac_cv_exeext
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
$as_echo "$ac_cv_exeext" >&6; }
rm -f conftest.$ac_ext
EXEEXT=$ac_cv_exeext
ac_exeext=$EXEEXT
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include
int
main ()
{
FILE *f = fopen ("conftest.out", "w");
return ferror (f) || fclose (f) != 0;
;
return 0;
}
_ACEOF
ac_clean_files="$ac_clean_files conftest.out"
# Check that the compiler produces executables we can run. If not, either
# the compiler is broken, or we cross compile.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5
$as_echo_n "checking whether we are cross compiling... " >&6; }
if test "$cross_compiling" != yes; then
{ { ac_try="$ac_link"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
(eval "$ac_link") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }
if { ac_try='./conftest$ac_cv_exeext'
{ { case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
(eval "$ac_try") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; }; then
cross_compiling=no
else
if test "$cross_compiling" = maybe; then
cross_compiling=yes
else
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "cannot run C compiled programs.
If you meant to cross compile, use \`--host'.
See \`config.log' for more details" "$LINENO" 5; }
fi
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5
$as_echo "$cross_compiling" >&6; }
rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out
ac_clean_files=$ac_clean_files_save
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
$as_echo_n "checking for suffix of object files... " >&6; }
if ${ac_cv_objext+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
rm -f conftest.o conftest.obj
if { { ac_try="$ac_compile"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
(eval "$ac_compile") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then :
for ac_file in conftest.o conftest.obj conftest.*; do
test -f "$ac_file" || continue;
case $ac_file in
*.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;;
*) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
break;;
esac
done
else
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "cannot compute suffix of object files: cannot compile
See \`config.log' for more details" "$LINENO" 5; }
fi
rm -f conftest.$ac_cv_objext conftest.$ac_ext
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5
$as_echo "$ac_cv_objext" >&6; }
OBJEXT=$ac_cv_objext
ac_objext=$OBJEXT
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5
$as_echo_n "checking whether we are using the GNU C compiler... " >&6; }
if ${ac_cv_c_compiler_gnu+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
#ifndef __GNUC__
choke me
#endif
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
ac_compiler_gnu=yes
else
ac_compiler_gnu=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
ac_cv_c_compiler_gnu=$ac_compiler_gnu
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
$as_echo "$ac_cv_c_compiler_gnu" >&6; }
if test $ac_compiler_gnu = yes; then
GCC=yes
else
GCC=
fi
ac_test_CFLAGS=${CFLAGS+set}
ac_save_CFLAGS=$CFLAGS
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
$as_echo_n "checking whether $CC accepts -g... " >&6; }
if ${ac_cv_prog_cc_g+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_save_c_werror_flag=$ac_c_werror_flag
ac_c_werror_flag=yes
ac_cv_prog_cc_g=no
CFLAGS="-g"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
ac_cv_prog_cc_g=yes
else
CFLAGS=""
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
else
ac_c_werror_flag=$ac_save_c_werror_flag
CFLAGS="-g"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
ac_cv_prog_cc_g=yes
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
ac_c_werror_flag=$ac_save_c_werror_flag
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
$as_echo "$ac_cv_prog_cc_g" >&6; }
if test "$ac_test_CFLAGS" = set; then
CFLAGS=$ac_save_CFLAGS
elif test $ac_cv_prog_cc_g = yes; then
if test "$GCC" = yes; then
CFLAGS="-g -O2"
else
CFLAGS="-g"
fi
else
if test "$GCC" = yes; then
CFLAGS="-O2"
else
CFLAGS=
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5
$as_echo_n "checking for $CC option to accept ISO C89... " >&6; }
if ${ac_cv_prog_cc_c89+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_cv_prog_cc_c89=no
ac_save_CC=$CC
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include
#include
struct stat;
/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */
struct buf { int x; };
FILE * (*rcsopen) (struct buf *, struct stat *, int);
static char *e (p, i)
char **p;
int i;
{
return p[i];
}
static char *f (char * (*g) (char **, int), char **p, ...)
{
char *s;
va_list v;
va_start (v,p);
s = g (p, va_arg (v,int));
va_end (v);
return s;
}
/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has
function prototypes and stuff, but not '\xHH' hex character constants.
These don't provoke an error unfortunately, instead are silently treated
as 'x'. The following induces an error, until -std is added to get
proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an
array size at least. It's necessary to write '\x00'==0 to get something
that's true only with -std. */
int osf4_cc_array ['\x00' == 0 ? 1 : -1];
/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
inside strings and character constants. */
#define FOO(x) 'x'
int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
int test (int i, double x);
struct s1 {int (*f) (int a);};
struct s2 {int (*f) (double a);};
int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
int argc;
char **argv;
int
main ()
{
return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1];
;
return 0;
}
_ACEOF
for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \
-Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
do
CC="$ac_save_CC $ac_arg"
if ac_fn_c_try_compile "$LINENO"; then :
ac_cv_prog_cc_c89=$ac_arg
fi
rm -f core conftest.err conftest.$ac_objext
test "x$ac_cv_prog_cc_c89" != "xno" && break
done
rm -f conftest.$ac_ext
CC=$ac_save_CC
fi
# AC_CACHE_VAL
case "x$ac_cv_prog_cc_c89" in
x)
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
$as_echo "none needed" >&6; } ;;
xno)
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
$as_echo "unsupported" >&6; } ;;
*)
CC="$CC $ac_cv_prog_cc_c89"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5
$as_echo "$ac_cv_prog_cc_c89" >&6; } ;;
esac
if test "x$ac_cv_prog_cc_c89" != xno; then :
fi
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5
$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; }
set x ${MAKE-make}
ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'`
if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then :
$as_echo_n "(cached) " >&6
else
cat >conftest.make <<\_ACEOF
SHELL = /bin/sh
all:
@echo '@@@%%%=$(MAKE)=@@@%%%'
_ACEOF
# GNU make sometimes prints "make[1]: Entering ...", which would confuse us.
case `${MAKE-make} -f conftest.make 2>/dev/null` in
*@@@%%%=?*=@@@%%%*)
eval ac_cv_prog_make_${ac_make}_set=yes;;
*)
eval ac_cv_prog_make_${ac_make}_set=no;;
esac
rm -f conftest.make
fi
if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
SET_MAKE=
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
SET_MAKE="MAKE=${MAKE-make}"
fi
# Extract the first word of "strip", so it can be a program name with args.
set dummy strip; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_path_STRIP+:} false; then :
$as_echo_n "(cached) " >&6
else
case $STRIP in
[\\/]* | ?:[\\/]*)
ac_cv_path_STRIP="$STRIP" # Let the user override the test with a path.
;;
*)
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_path_STRIP="$as_dir/$ac_word$ac_exec_ext"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS
test -z "$ac_cv_path_STRIP" && ac_cv_path_STRIP="true"
;;
esac
fi
STRIP=$ac_cv_path_STRIP
if test -n "$STRIP"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5
$as_echo "$STRIP" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5
$as_echo_n "checking how to run the C preprocessor... " >&6; }
# On Suns, sometimes $CPP names a directory.
if test -n "$CPP" && test -d "$CPP"; then
CPP=
fi
if test -z "$CPP"; then
if ${ac_cv_prog_CPP+:} false; then :
$as_echo_n "(cached) " >&6
else
# Double quotes because CPP needs to be expanded
for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
do
ac_preproc_ok=false
for ac_c_preproc_warn_flag in '' yes
do
# Use a header file that comes with gcc, so configuring glibc
# with a fresh cross-compiler works.
# Prefer to if __STDC__ is defined, since
# exists even on freestanding compilers.
# On the NeXT, cc -E runs the code through the compiler's parser,
# not just through cpp. "Syntax error" is here to catch this case.
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#ifdef __STDC__
# include
#else
# include
#endif
Syntax error
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :
else
# Broken: fails on valid input.
continue
fi
rm -f conftest.err conftest.i conftest.$ac_ext
# OK, works on sane cases. Now check whether nonexistent headers
# can be detected and how.
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :
# Broken: success on invalid input.
continue
else
# Passes both tests.
ac_preproc_ok=:
break
fi
rm -f conftest.err conftest.i conftest.$ac_ext
done
# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
rm -f conftest.i conftest.err conftest.$ac_ext
if $ac_preproc_ok; then :
break
fi
done
ac_cv_prog_CPP=$CPP
fi
CPP=$ac_cv_prog_CPP
else
ac_cv_prog_CPP=$CPP
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5
$as_echo "$CPP" >&6; }
ac_preproc_ok=false
for ac_c_preproc_warn_flag in '' yes
do
# Use a header file that comes with gcc, so configuring glibc
# with a fresh cross-compiler works.
# Prefer to if __STDC__ is defined, since
# exists even on freestanding compilers.
# On the NeXT, cc -E runs the code through the compiler's parser,
# not just through cpp. "Syntax error" is here to catch this case.
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#ifdef __STDC__
# include
#else
# include
#endif
Syntax error
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :
else
# Broken: fails on valid input.
continue
fi
rm -f conftest.err conftest.i conftest.$ac_ext
# OK, works on sane cases. Now check whether nonexistent headers
# can be detected and how.
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :
# Broken: success on invalid input.
continue
else
# Passes both tests.
ac_preproc_ok=:
break
fi
rm -f conftest.err conftest.i conftest.$ac_ext
done
# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
rm -f conftest.i conftest.err conftest.$ac_ext
if $ac_preproc_ok; then :
else
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "C preprocessor \"$CPP\" fails sanity check
See \`config.log' for more details" "$LINENO" 5; }
fi
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5
$as_echo_n "checking for grep that handles long lines and -e... " >&6; }
if ${ac_cv_path_GREP+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -z "$GREP"; then
ac_path_GREP_found=false
# Loop through the user's path and test for each of PROGNAME-LIST
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_prog in grep ggrep; do
for ac_exec_ext in '' $ac_executable_extensions; do
ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
as_fn_executable_p "$ac_path_GREP" || continue
# Check for GNU ac_path_GREP and select it if it is found.
# Check for GNU $ac_path_GREP
case `"$ac_path_GREP" --version 2>&1` in
*GNU*)
ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;;
*)
ac_count=0
$as_echo_n 0123456789 >"conftest.in"
while :
do
cat "conftest.in" "conftest.in" >"conftest.tmp"
mv "conftest.tmp" "conftest.in"
cp "conftest.in" "conftest.nl"
$as_echo 'GREP' >> "conftest.nl"
"$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break
diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
as_fn_arith $ac_count + 1 && ac_count=$as_val
if test $ac_count -gt ${ac_path_GREP_max-0}; then
# Best one so far, save it but keep looking for a better one
ac_cv_path_GREP="$ac_path_GREP"
ac_path_GREP_max=$ac_count
fi
# 10*(2^10) chars as input seems more than enough
test $ac_count -gt 10 && break
done
rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
esac
$ac_path_GREP_found && break 3
done
done
done
IFS=$as_save_IFS
if test -z "$ac_cv_path_GREP"; then
as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
fi
else
ac_cv_path_GREP=$GREP
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5
$as_echo "$ac_cv_path_GREP" >&6; }
GREP="$ac_cv_path_GREP"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5
$as_echo_n "checking for egrep... " >&6; }
if ${ac_cv_path_EGREP+:} false; then :
$as_echo_n "(cached) " >&6
else
if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
then ac_cv_path_EGREP="$GREP -E"
else
if test -z "$EGREP"; then
ac_path_EGREP_found=false
# Loop through the user's path and test for each of PROGNAME-LIST
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_prog in egrep; do
for ac_exec_ext in '' $ac_executable_extensions; do
ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
as_fn_executable_p "$ac_path_EGREP" || continue
# Check for GNU ac_path_EGREP and select it if it is found.
# Check for GNU $ac_path_EGREP
case `"$ac_path_EGREP" --version 2>&1` in
*GNU*)
ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;;
*)
ac_count=0
$as_echo_n 0123456789 >"conftest.in"
while :
do
cat "conftest.in" "conftest.in" >"conftest.tmp"
mv "conftest.tmp" "conftest.in"
cp "conftest.in" "conftest.nl"
$as_echo 'EGREP' >> "conftest.nl"
"$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
as_fn_arith $ac_count + 1 && ac_count=$as_val
if test $ac_count -gt ${ac_path_EGREP_max-0}; then
# Best one so far, save it but keep looking for a better one
ac_cv_path_EGREP="$ac_path_EGREP"
ac_path_EGREP_max=$ac_count
fi
# 10*(2^10) chars as input seems more than enough
test $ac_count -gt 10 && break
done
rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
esac
$ac_path_EGREP_found && break 3
done
done
done
IFS=$as_save_IFS
if test -z "$ac_cv_path_EGREP"; then
as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
fi
else
ac_cv_path_EGREP=$EGREP
fi
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5
$as_echo "$ac_cv_path_EGREP" >&6; }
EGREP="$ac_cv_path_EGREP"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
$as_echo_n "checking for ANSI C header files... " >&6; }
if ${ac_cv_header_stdc+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include
#include
#include
#include
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
ac_cv_header_stdc=yes
else
ac_cv_header_stdc=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
if test $ac_cv_header_stdc = yes; then
# SunOS 4.x string.h does not declare mem*, contrary to ANSI.
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include
_ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
$EGREP "memchr" >/dev/null 2>&1; then :
else
ac_cv_header_stdc=no
fi
rm -f conftest*
fi
if test $ac_cv_header_stdc = yes; then
# ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include
_ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
$EGREP "free" >/dev/null 2>&1; then :
else
ac_cv_header_stdc=no
fi
rm -f conftest*
fi
if test $ac_cv_header_stdc = yes; then
# /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
if test "$cross_compiling" = yes; then :
:
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include
#include
#if ((' ' & 0x0FF) == 0x020)
# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
#else
# define ISLOWER(c) \
(('a' <= (c) && (c) <= 'i') \
|| ('j' <= (c) && (c) <= 'r') \
|| ('s' <= (c) && (c) <= 'z'))
# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
#endif
#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
int
main ()
{
int i;
for (i = 0; i < 256; i++)
if (XOR (islower (i), ISLOWER (i))
|| toupper (i) != TOUPPER (i))
return 2;
return 0;
}
_ACEOF
if ac_fn_c_try_run "$LINENO"; then :
else
ac_cv_header_stdc=no
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
conftest.$ac_objext conftest.beam conftest.$ac_ext
fi
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5
$as_echo "$ac_cv_header_stdc" >&6; }
if test $ac_cv_header_stdc = yes; then
$as_echo "#define STDC_HEADERS 1" >>confdefs.h
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether time.h and sys/time.h may both be included" >&5
$as_echo_n "checking whether time.h and sys/time.h may both be included... " >&6; }
if ${ac_cv_header_time+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include
#include
#include
int
main ()
{
if ((struct tm *) 0)
return 0;
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
ac_cv_header_time=yes
else
ac_cv_header_time=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_time" >&5
$as_echo "$ac_cv_header_time" >&6; }
if test $ac_cv_header_time = yes; then
$as_echo "#define TIME_WITH_SYS_TIME 1" >>confdefs.h
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sys/wait.h that is POSIX.1 compatible" >&5
$as_echo_n "checking for sys/wait.h that is POSIX.1 compatible... " >&6; }
if ${ac_cv_header_sys_wait_h+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include
#include
#ifndef WEXITSTATUS
# define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
#endif
#ifndef WIFEXITED
# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
#endif
int
main ()
{
int s;
wait (&s);
s = WIFEXITED (s) ? WEXITSTATUS (s) : 1;
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
ac_cv_header_sys_wait_h=yes
else
ac_cv_header_sys_wait_h=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_sys_wait_h" >&5
$as_echo "$ac_cv_header_sys_wait_h" >&6; }
if test $ac_cv_header_sys_wait_h = yes; then
$as_echo "#define HAVE_SYS_WAIT_H 1" >>confdefs.h
fi
# On IRIX 5.3, sys/types and inttypes.h are conflicting.
for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
inttypes.h stdint.h unistd.h
do :
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default
"
if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
_ACEOF
fi
done
for ac_header in arpa/inet.h ctype.h dirent.h errno.h fcntl.h getopt.h grp.h libgen.h limits.h math.h netdb.h netinet/in.h pthread.h pthreads.h pwd.h regex.h signal.h socket.h stdarg.h string.h strings.h sys/mman.h sys/types.h sys/time.h sys/resource.h sys/wait.h sys/socket.h sys/stat.h sys/timeb.h sys/un.h sys/ipc.h sys/msg.h sys/poll.h syslog.h uio.h unistd.h sys/select.h
do :
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
_ACEOF
fi
done
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5
$as_echo_n "checking for an ANSI C-conforming const... " >&6; }
if ${ac_cv_c_const+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
#ifndef __cplusplus
/* Ultrix mips cc rejects this sort of thing. */
typedef int charset[2];
const charset cs = { 0, 0 };
/* SunOS 4.1.1 cc rejects this. */
char const *const *pcpcc;
char **ppc;
/* NEC SVR4.0.2 mips cc rejects this. */
struct point {int x, y;};
static struct point const zero = {0,0};
/* AIX XL C 1.02.0.0 rejects this.
It does not let you subtract one const X* pointer from another in
an arm of an if-expression whose if-part is not a constant
expression */
const char *g = "string";
pcpcc = &g + (g ? g-g : 0);
/* HPUX 7.0 cc rejects these. */
++pcpcc;
ppc = (char**) pcpcc;
pcpcc = (char const *const *) ppc;
{ /* SCO 3.2v4 cc rejects this sort of thing. */
char tx;
char *t = &tx;
char const *s = 0 ? (char *) 0 : (char const *) 0;
*t++ = 0;
if (s) return 0;
}
{ /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */
int x[] = {25, 17};
const int *foo = &x[0];
++foo;
}
{ /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
typedef const int *iptr;
iptr p = 0;
++p;
}
{ /* AIX XL C 1.02.0.0 rejects this sort of thing, saying
"k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
struct s { int j; const int *ap[3]; } bx;
struct s *b = &bx; b->j = 5;
}
{ /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
const int foo = 10;
if (!foo) return 0;
}
return !cs[0] && !zero.x;
#endif
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
ac_cv_c_const=yes
else
ac_cv_c_const=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5
$as_echo "$ac_cv_c_const" >&6; }
if test $ac_cv_c_const = no; then
$as_echo "#define const /**/" >>confdefs.h
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether struct tm is in sys/time.h or time.h" >&5
$as_echo_n "checking whether struct tm is in sys/time.h or time.h... " >&6; }
if ${ac_cv_struct_tm+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include
#include
int
main ()
{
struct tm tm;
int *p = &tm.tm_sec;
return !p;
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
ac_cv_struct_tm=time.h
else
ac_cv_struct_tm=sys/time.h
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_struct_tm" >&5
$as_echo "$ac_cv_struct_tm" >&6; }
if test $ac_cv_struct_tm = sys/time.h; then
$as_echo "#define TM_IN_SYS_TIME 1" >>confdefs.h
fi
ac_fn_c_check_member "$LINENO" "struct tm" "tm_zone" "ac_cv_member_struct_tm_tm_zone" "#include
#include <$ac_cv_struct_tm>
"
if test "x$ac_cv_member_struct_tm_tm_zone" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_STRUCT_TM_TM_ZONE 1
_ACEOF
fi
if test "$ac_cv_member_struct_tm_tm_zone" = yes; then
$as_echo "#define HAVE_TM_ZONE 1" >>confdefs.h
else
ac_fn_c_check_decl "$LINENO" "tzname" "ac_cv_have_decl_tzname" "#include
"
if test "x$ac_cv_have_decl_tzname" = xyes; then :
ac_have_decl=1
else
ac_have_decl=0
fi
cat >>confdefs.h <<_ACEOF
#define HAVE_DECL_TZNAME $ac_have_decl
_ACEOF
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for tzname" >&5
$as_echo_n "checking for tzname... " >&6; }
if ${ac_cv_var_tzname+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include
#if !HAVE_DECL_TZNAME
extern char *tzname[];
#endif
int
main ()
{
return tzname[0][0];
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_var_tzname=yes
else
ac_cv_var_tzname=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_var_tzname" >&5
$as_echo "$ac_cv_var_tzname" >&6; }
if test $ac_cv_var_tzname = yes; then
$as_echo "#define HAVE_TZNAME 1" >>confdefs.h
fi
fi
ac_fn_c_check_type "$LINENO" "mode_t" "ac_cv_type_mode_t" "$ac_includes_default"
if test "x$ac_cv_type_mode_t" = xyes; then :
else
cat >>confdefs.h <<_ACEOF
#define mode_t int
_ACEOF
fi
ac_fn_c_check_type "$LINENO" "pid_t" "ac_cv_type_pid_t" "$ac_includes_default"
if test "x$ac_cv_type_pid_t" = xyes; then :
else
cat >>confdefs.h <<_ACEOF
#define pid_t int
_ACEOF
fi
ac_fn_c_check_type "$LINENO" "size_t" "ac_cv_type_size_t" "$ac_includes_default"
if test "x$ac_cv_type_size_t" = xyes; then :
else
cat >>confdefs.h <<_ACEOF
#define size_t unsigned int
_ACEOF
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking return type of signal handlers" >&5
$as_echo_n "checking return type of signal handlers... " >&6; }
if ${ac_cv_type_signal+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include
#include
int
main ()
{
return *(signal (0, 0)) (0) == 1;
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
ac_cv_type_signal=int
else
ac_cv_type_signal=void
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_signal" >&5
$as_echo "$ac_cv_type_signal" >&6; }
cat >>confdefs.h <<_ACEOF
#define RETSIGTYPE $ac_cv_type_signal
_ACEOF
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for uid_t in sys/types.h" >&5
$as_echo_n "checking for uid_t in sys/types.h... " >&6; }
if ${ac_cv_type_uid_t+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include
_ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
$EGREP "uid_t" >/dev/null 2>&1; then :
ac_cv_type_uid_t=yes
else
ac_cv_type_uid_t=no
fi
rm -f conftest*
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_uid_t" >&5
$as_echo "$ac_cv_type_uid_t" >&6; }
if test $ac_cv_type_uid_t = no; then
$as_echo "#define uid_t int" >>confdefs.h
$as_echo "#define gid_t int" >>confdefs.h
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking type of array argument to getgroups" >&5
$as_echo_n "checking type of array argument to getgroups... " >&6; }
if ${ac_cv_type_getgroups+:} false; then :
$as_echo_n "(cached) " >&6
else
if test "$cross_compiling" = yes; then :
ac_cv_type_getgroups=cross
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Thanks to Mike Rendell for this test. */
$ac_includes_default
#define NGID 256
#undef MAX
#define MAX(x, y) ((x) > (y) ? (x) : (y))
int
main ()
{
gid_t gidset[NGID];
int i, n;
union { gid_t gval; long int lval; } val;
val.lval = -1;
for (i = 0; i < NGID; i++)
gidset[i] = val.gval;
n = getgroups (sizeof (gidset) / MAX (sizeof (int), sizeof (gid_t)) - 1,
gidset);
/* Exit non-zero if getgroups seems to require an array of ints. This
happens when gid_t is short int but getgroups modifies an array
of ints. */
return n > 0 && gidset[n] != val.gval;
}
_ACEOF
if ac_fn_c_try_run "$LINENO"; then :
ac_cv_type_getgroups=gid_t
else
ac_cv_type_getgroups=int
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
conftest.$ac_objext conftest.beam conftest.$ac_ext
fi
if test $ac_cv_type_getgroups = cross; then
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include
_ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
$EGREP "getgroups.*int.*gid_t" >/dev/null 2>&1; then :
ac_cv_type_getgroups=gid_t
else
ac_cv_type_getgroups=int
fi
rm -f conftest*
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_getgroups" >&5
$as_echo "$ac_cv_type_getgroups" >&6; }
cat >>confdefs.h <<_ACEOF
#define GETGROUPS_T $ac_cv_type_getgroups
_ACEOF
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for va_copy" >&5
$as_echo_n "checking for va_copy... " >&6; }
if ${ac_cv_HAVE_VA_COPY+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include
va_list ap1,ap2;
int
main ()
{
va_copy(ap1,ap2);
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_HAVE_VA_COPY=yes
else
ac_cv_HAVE_VA_COPY=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_HAVE_VA_COPY" >&5
$as_echo "$ac_cv_HAVE_VA_COPY" >&6; }
if test x"$ac_cv_HAVE_VA_COPY" = x"yes"; then
$as_echo "#define HAVE_VA_COPY 1" >>confdefs.h
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __va_copy" >&5
$as_echo_n "checking for __va_copy... " >&6; }
if ${ac_cv_HAVE___VA_COPY+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include
va_list ap1,ap2;
int
main ()
{
__va_copy(ap1,ap2);
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_HAVE___VA_COPY=yes
else
ac_cv_HAVE___VA_COPY=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_HAVE___VA_COPY" >&5
$as_echo "$ac_cv_HAVE___VA_COPY" >&6; }
if test x"$ac_cv_HAVE___VA_COPY" = x"yes"; then
$as_echo "#define HAVE___VA_COPY 1" >>confdefs.h
fi
fi
ac_fn_c_check_func "$LINENO" "vsnprintf" "ac_cv_func_vsnprintf"
if test "x$ac_cv_func_vsnprintf" = xyes; then :
else
SNPRINTF_O=../common/snprintf.o
fi
ac_fn_c_check_func "$LINENO" "snprintf" "ac_cv_func_snprintf"
if test "x$ac_cv_func_snprintf" = xyes; then :
else
SNPRINTF_O=../common/snprintf.o
fi
ac_fn_c_check_func "$LINENO" "asprintf" "ac_cv_func_asprintf"
if test "x$ac_cv_func_asprintf" = xyes; then :
else
SNPRINTF_O=../common/snprintf.o
fi
ac_fn_c_check_func "$LINENO" "vasprintf" "ac_cv_func_vasprintf"
if test "x$ac_cv_func_vasprintf" = xyes; then :
else
SNPRINTF_O=../common/snprintf.o
fi
ac_fn_c_check_func "$LINENO" "vsnprintf" "ac_cv_func_vsnprintf"
if test "x$ac_cv_func_vsnprintf" = xyes; then :
else
SNPRINTF_O_IDO=snprintf.o
fi
ac_fn_c_check_func "$LINENO" "snprintf" "ac_cv_func_snprintf"
if test "x$ac_cv_func_snprintf" = xyes; then :
else
SNPRINTF_O_IDO=snprintf.o
fi
ac_fn_c_check_func "$LINENO" "asprintf" "ac_cv_func_asprintf"
if test "x$ac_cv_func_asprintf" = xyes; then :
else
SNPRINTF_O_IDO=snprintf.o
fi
ac_fn_c_check_func "$LINENO" "vasprintf" "ac_cv_func_vasprintf"
if test "x$ac_cv_func_vasprintf" = xyes; then :
else
SNPRINTF_O_IDO=snprintf.o
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C99 vsnprintf" >&5
$as_echo_n "checking for C99 vsnprintf... " >&6; }
if ${ac_cv_HAVE_C99_VSNPRINTF+:} false; then :
$as_echo_n "(cached) " >&6
else
if test "$cross_compiling" = yes; then :
ac_cv_HAVE_C99_VSNPRINTF=cross
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include
#include
void foo(const char *format, ...) {
va_list ap;
int len;
char buf[5];
va_start(ap, format);
len = vsnprintf(buf, 0, format, ap);
va_end(ap);
if (len != 5) exit(1);
va_start(ap, format);
len = vsnprintf(0, 0, format, ap);
va_end(ap);
if (len != 5) exit(1);
if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(1);
exit(0);
}
main() { foo("hello"); }
_ACEOF
if ac_fn_c_try_run "$LINENO"; then :
ac_cv_HAVE_C99_VSNPRINTF=yes
else
ac_cv_HAVE_C99_VSNPRINTF=no
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
conftest.$ac_objext conftest.beam conftest.$ac_ext
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_HAVE_C99_VSNPRINTF" >&5
$as_echo "$ac_cv_HAVE_C99_VSNPRINTF" >&6; }
if test x"$ac_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
$as_echo "#define HAVE_C99_VSNPRINTF 1" >>confdefs.h
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing getservbyname" >&5
$as_echo_n "checking for library containing getservbyname... " >&6; }
if ${ac_cv_search_getservbyname+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_func_search_save_LIBS=$LIBS
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char getservbyname ();
int
main ()
{
return getservbyname ();
;
return 0;
}
_ACEOF
for ac_lib in '' nsl; do
if test -z "$ac_lib"; then
ac_res="none required"
else
ac_res=-l$ac_lib
LIBS="-l$ac_lib $ac_func_search_save_LIBS"
fi
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_search_getservbyname=$ac_res
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext
if ${ac_cv_search_getservbyname+:} false; then :
break
fi
done
if ${ac_cv_search_getservbyname+:} false; then :
else
ac_cv_search_getservbyname=no
fi
rm conftest.$ac_ext
LIBS=$ac_func_search_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_getservbyname" >&5
$as_echo "$ac_cv_search_getservbyname" >&6; }
ac_res=$ac_cv_search_getservbyname
if test "$ac_res" != no; then :
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
if test "$ac_cv_search_getservbyname" != "none required"; then
SOCKETLIBS="$SOCKETLIBS -lnsl"
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing connect" >&5
$as_echo_n "checking for library containing connect... " >&6; }
if ${ac_cv_search_connect+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_func_search_save_LIBS=$LIBS
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char connect ();
int
main ()
{
return connect ();
;
return 0;
}
_ACEOF
for ac_lib in '' socket; do
if test -z "$ac_lib"; then
ac_res="none required"
else
ac_res=-l$ac_lib
LIBS="-l$ac_lib $ac_func_search_save_LIBS"
fi
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_search_connect=$ac_res
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext
if ${ac_cv_search_connect+:} false; then :
break
fi
done
if ${ac_cv_search_connect+:} false; then :
else
ac_cv_search_connect=no
fi
rm conftest.$ac_ext
LIBS=$ac_func_search_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_connect" >&5
$as_echo "$ac_cv_search_connect" >&6; }
ac_res=$ac_cv_search_connect
if test "$ac_res" != no; then :
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
if test "$ac_cv_search_connect" != "none required"; then
SOCKETLIBS="$SOCKETLIBS -lsocket"
fi
fi
for ac_func in initgroups setenv strdup strstr strtoul unsetenv
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF
fi
done
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing gethostbyname" >&5
$as_echo_n "checking for library containing gethostbyname... " >&6; }
if ${ac_cv_search_gethostbyname+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_func_search_save_LIBS=$LIBS
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char gethostbyname ();
int
main ()
{
return gethostbyname ();
;
return 0;
}
_ACEOF
for ac_lib in '' nsl; do
if test -z "$ac_lib"; then
ac_res="none required"
else
ac_res=-l$ac_lib
LIBS="-l$ac_lib $ac_func_search_save_LIBS"
fi
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_search_gethostbyname=$ac_res
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext
if ${ac_cv_search_gethostbyname+:} false; then :
break
fi
done
if ${ac_cv_search_gethostbyname+:} false; then :
else
ac_cv_search_gethostbyname=no
fi
rm conftest.$ac_ext
LIBS=$ac_func_search_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_gethostbyname" >&5
$as_echo "$ac_cv_search_gethostbyname" >&6; }
ac_res=$ac_cv_search_gethostbyname
if test "$ac_res" != no; then :
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
if test "$ac_cv_search_gethostbyname" != "none required"; then
SOCKETLIBS="$SOCKETLIBS -lnsl"
fi
fi
for ac_func in getopt_long
do :
ac_fn_c_check_func "$LINENO" "getopt_long" "ac_cv_func_getopt_long"
if test "x$ac_cv_func_getopt_long" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_GETOPT_LONG 1
_ACEOF
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for getopt_long in -liberty" >&5
$as_echo_n "checking for getopt_long in -liberty... " >&6; }
if ${ac_cv_lib_iberty_getopt_long+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-liberty $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char getopt_long ();
int
main ()
{
return getopt_long ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_iberty_getopt_long=yes
else
ac_cv_lib_iberty_getopt_long=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_iberty_getopt_long" >&5
$as_echo "$ac_cv_lib_iberty_getopt_long" >&6; }
if test "x$ac_cv_lib_iberty_getopt_long" = xyes; then :
OTHERLIBS="$OTHERLIBS -liberty"
fi
fi
done
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for type of socket size" >&5
$as_echo_n "checking for type of socket size... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include
#include
#include
int
main ()
{
int a = send(1, (const void *) 0, (size_t) 0, (int) 0);
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
$as_echo "#define SOCKET_SIZE_TYPE size_t" >>confdefs.h
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: size_t" >&5
$as_echo "size_t" >&6; }
else
$as_echo "#define SOCKET_SIZE_TYPE int" >>confdefs.h
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: int" >&5
$as_echo "int" >&6; }
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
THREADLIBS=""
have_pthreads="no"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lcma" >&5
$as_echo_n "checking for pthread_create in -lcma... " >&6; }
if ${ac_cv_lib_cma_pthread_create+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lcma $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char pthread_create ();
int
main ()
{
return pthread_create ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_cma_pthread_create=yes
else
ac_cv_lib_cma_pthread_create=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_cma_pthread_create" >&5
$as_echo "$ac_cv_lib_cma_pthread_create" >&6; }
if test "x$ac_cv_lib_cma_pthread_create" = xyes; then :
THREADLIBS="$THREADLIBS -lpthread"
fi
if test $ac_cv_lib_cma_pthread_create = yes; then
have_pthreads="yes"
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lpthread" >&5
$as_echo_n "checking for pthread_create in -lpthread... " >&6; }
if ${ac_cv_lib_pthread_pthread_create+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lpthread $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char pthread_create ();
int
main ()
{
return pthread_create ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_pthread_pthread_create=yes
else
ac_cv_lib_pthread_pthread_create=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_create" >&5
$as_echo "$ac_cv_lib_pthread_pthread_create" >&6; }
if test "x$ac_cv_lib_pthread_pthread_create" = xyes; then :
THREADLIBS="$THREADLIBS -lpthread"
fi
if test $ac_cv_lib_pthread_pthread_create = yes; then
have_pthreads="yes"
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_init in -lpthread" >&5
$as_echo_n "checking for pthread_mutex_init in -lpthread... " >&6; }
if ${ac_cv_lib_pthread_pthread_mutex_init+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lpthread $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char pthread_mutex_init ();
int
main ()
{
return pthread_mutex_init ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_pthread_pthread_mutex_init=yes
else
ac_cv_lib_pthread_pthread_mutex_init=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_mutex_init" >&5
$as_echo "$ac_cv_lib_pthread_pthread_mutex_init" >&6; }
if test "x$ac_cv_lib_pthread_pthread_mutex_init" = xyes; then :
THREADLIBS="$THREADLIBS -lpthread"
fi
if test $ac_cv_lib_pthread_pthread_mutex_init = yes; then
have_pthreads="yes"
fi
fi
if test $have_pthreads = "no"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lpthreads" >&5
$as_echo_n "checking for pthread_create in -lpthreads... " >&6; }
if ${ac_cv_lib_pthreads_pthread_create+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lpthreads $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char pthread_create ();
int
main ()
{
return pthread_create ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_pthreads_pthread_create=yes
else
ac_cv_lib_pthreads_pthread_create=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthreads_pthread_create" >&5
$as_echo "$ac_cv_lib_pthreads_pthread_create" >&6; }
if test "x$ac_cv_lib_pthreads_pthread_create" = xyes; then :
THREADLIBS="$THREADLIBS -lpthreads"
fi
if test $ac_cv_lib_pthreads_pthread_create = yes; then
have_pthreads="yes"
fi
fi
if test $have_pthreads = "no"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -llthread" >&5
$as_echo_n "checking for pthread_create in -llthread... " >&6; }
if ${ac_cv_lib_lthread_pthread_create+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-llthread -L/usr/local/lib $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char pthread_create ();
int
main ()
{
return pthread_create ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_lthread_pthread_create=yes
else
ac_cv_lib_lthread_pthread_create=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_lthread_pthread_create" >&5
$as_echo "$ac_cv_lib_lthread_pthread_create" >&6; }
if test "x$ac_cv_lib_lthread_pthread_create" = xyes; then :
CFLAGS="-D_THREAD_SAFE -I/usr/local/include/pthread/linuxthreads -I/usr/include $CFLAGS"
THREADLIBS="-L/usr/local/lib -llthread -llgcc_r"
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if we need -pthread for threads" >&5
$as_echo_n "checking if we need -pthread for threads... " >&6; }
if ${ac_cv_ldflag_pthread+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_save_LDFLAGS="$LDFLAGS"
LDFLAGS="-pthread $LDFLAGS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
char pthread_create();
int
main ()
{
pthread_create();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
eval "ac_cv_ldflag_pthread=yes"
else
eval "ac_cv_ldflag_pthread=no"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext,
THREADLIBS="$ac_save_LDFLAGS"
fi
if eval "test \"`echo $ac_cv_ldflag_pthread`\" = yes"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing nanosleep" >&5
$as_echo_n "checking for library containing nanosleep... " >&6; }
if ${ac_cv_search_nanosleep+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_func_search_save_LIBS=$LIBS
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char nanosleep ();
int
main ()
{
return nanosleep ();
;
return 0;
}
_ACEOF
for ac_lib in '' rt posix4; do
if test -z "$ac_lib"; then
ac_res="none required"
else
ac_res=-l$ac_lib
LIBS="-l$ac_lib $ac_func_search_save_LIBS"
fi
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_search_nanosleep=$ac_res
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext
if ${ac_cv_search_nanosleep+:} false; then :
break
fi
done
if ${ac_cv_search_nanosleep+:} false; then :
else
ac_cv_search_nanosleep=no
fi
rm conftest.$ac_ext
LIBS=$ac_func_search_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_nanosleep" >&5
$as_echo "$ac_cv_search_nanosleep" >&6; }
ac_res=$ac_cv_search_nanosleep
if test "$ac_res" != no; then :
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
else
echo "Error: nanosleep() needed for timing operations."
exit 1
fi
# Check whether --with-icinga_user was given.
if test "${with_icinga_user+set}" = set; then :
withval=$with_icinga_user; icinga_user=$withval
else
icinga_user=icinga
fi
# Check whether --with-icinga_group was given.
if test "${with_icinga_group+set}" = set; then :
withval=$with_icinga_group; icinga_grp=$withval
else
icinga_grp=icinga
fi
cat >>confdefs.h <<_ACEOF
#define DEFAULT_ICINGA_USER "$icinga_user"
_ACEOF
cat >>confdefs.h <<_ACEOF
#define DEFAULT_NAGIOS_USER "$icinga_user"
_ACEOF
cat >>confdefs.h <<_ACEOF
#define DEFAULT_ICINGA_GROUP "$icinga_grp"
_ACEOF
cat >>confdefs.h <<_ACEOF
#define DEFAULT_NAGIOS_GROUP "$icinga_grp"
_ACEOF
INSTALL_OPTS="-o $icinga_user -g $icinga_grp"
# Check whether --with-command_user was given.
if test "${with_command_user+set}" = set; then :
withval=$with_command_user; command_user=$withval
else
command_user=$icinga_user
fi
# Check whether --with-command_group was given.
if test "${with_command_group+set}" = set; then :
withval=$with_command_group; command_grp=$withval
else
command_grp=$icinga_grp
fi
COMMAND_OPTS="-o $command_user -g $command_grp"
# Users for webfiles
# Check whether --with-web_user was given.
if test "${with_web_user+set}" = set; then :
withval=$with_web_user; web_user=$withval
else
web_user=www-data
for x in www wwwrun www-data apache httpd nobody; do
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if user $x exists" >&5
$as_echo_n "checking if user $x exists... " >&6; }
if $GREP -q "^$x:" /etc/passwd ; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: found" >&5
$as_echo "found" >&6; }; web_user=$x ; break
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5
$as_echo "not found" >&6; }
fi
done
fi
# Check whether --with-web_group was given.
if test "${with_web_group+set}" = set; then :
withval=$with_web_group; web_group=$withval
else
web_group=www-data
for x in www www-data apache httpd nogroup nobody; do
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if group $x exists" >&5
$as_echo_n "checking if group $x exists... " >&6; }
if $GREP -q "^$x:" /etc/group ; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: found" >&5
$as_echo "found" >&6; }; web_group=$x ; break
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5
$as_echo "not found" >&6; }
fi
done
fi
INSTALL_OPTS_WEB="-o $web_user -g $web_group"
MAIL_PROG=no
# Check whether --with-mail was given.
if test "${with_mail+set}" = set; then :
withval=$with_mail; MAIL_PROG=$withval
else
MAIL_PROG=no
fi
if test x$MAIL_PROG = xno; then
# Extract the first word of "mail", so it can be a program name with args.
set dummy mail; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_path_MAIL_PROG+:} false; then :
$as_echo_n "(cached) " >&6
else
case $MAIL_PROG in
[\\/]* | ?:[\\/]*)
ac_cv_path_MAIL_PROG="$MAIL_PROG" # Let the user override the test with a path.
;;
*)
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_path_MAIL_PROG="$as_dir/$ac_word$ac_exec_ext"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS
;;
esac
fi
MAIL_PROG=$ac_cv_path_MAIL_PROG
if test -n "$MAIL_PROG"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAIL_PROG" >&5
$as_echo "$MAIL_PROG" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
fi
if test x$MAIL_PROG = x; then
MAIL_PROG="/bin/mail"
fi
HTTPD_CONF=no
APACHE24_DEBIAN=no
# Check whether --with-httpd_conf was given.
if test "${with_httpd_conf+set}" = set; then :
withval=$with_httpd_conf; HTTPD_CONF=$withval
else
HTTPD_CONF=no
fi
if test x$HTTPD_CONF = xno; then
if test -d /etc/httpd/conf.d; then
HTTPD_CONF="/etc/httpd/conf.d"
elif test -d /etc/apache2/conf-available; then
HTTPD_CONF="/etc/apache2/conf-available"
APACHE24_DEBIAN=yes
elif test -d /etc/apache2/conf.d; then
HTTPD_CONF="/etc/apache2/conf.d"
elif test -d /etc/apache/conf.d; then
HTTPD_CONF="/etc/apache/conf.d"
else
HTTPD_CONF="/etc/httpd/conf.d"
fi
fi
CHECKRESULTDIR=no
# Check whether --with-checkresult-dir was given.
if test "${with_checkresult_dir+set}" = set; then :
withval=$with_checkresult_dir; CHECKRESULTDIR=$withval
else
CHECKRESULTDIR=no
fi
if test x$CHECKRESULTDIR = xno; then
CHECKRESULTDIR="$localstatedir/spool/checkresults"
fi
TMPDIR=no
# Check whether --with-temp-dir was given.
if test "${with_temp_dir+set}" = set; then :
withval=$with_temp_dir; TMPDIR=$withval
else
TMPDIR=no
fi
if test x$TMPDIR = xno; then
TMPDIR="/tmp"
fi
TMPFILE=no
# Check whether --with-temp-file was given.
if test "${with_temp_file+set}" = set; then :
withval=$with_temp_file; TMPFILE=$withval
else
TMPFILE=no
fi
if test x$TMPFILE = xno; then
TMPFILE="/tmp/icinga.tmp"
fi
STATEDIR=no
# Check whether --with-state-dir was given.
if test "${with_state_dir+set}" = set; then :
withval=$with_state_dir; STATEDIR=$withval
else
STATEDIR=no
fi
if test x$STATEDIR = xno; then
STATEDIR="$localstatedir"
fi
HTTPAUTHFILE=no
# Check whether --with-http-auth-file was given.
if test "${with_http_auth_file+set}" = set; then :
withval=$with_http_auth_file; HTTPAUTHFILE=$withval
else
HTTPAUTHFILE=no
fi
if test x$HTTPAUTHFILE = xno; then
HTTPAUTHFILE="$sysconfdir/htpasswd.users"
fi
HTTPDCONFFILE=no
# Check whether --with-httpd-conf-file was given.
if test "${with_httpd_conf_file+set}" = set; then :
withval=$with_httpd_conf_file; HTTPDCONFFILE=$withval
else
HTTPDCONFFILE=no
fi
if test x$HTTPDCONFFILE = xno; then
HTTPDCONFFILE="$HTTPD_CONF/icinga.conf"
fi
PLUGINDIR=no
# Check whether --with-plugin-dir was given.
if test "${with_plugin_dir+set}" = set; then :
withval=$with_plugin_dir; PLUGINDIR=$withval
else
PLUGINDIR=no
fi
if test x$PLUGINDIR = xno; then
PLUGINDIR="$libexecdir"
fi
EVENTHANDLERDIR=no
# Check whether --with-eventhandler-dir was given.
if test "${with_eventhandler_dir+set}" = set; then :
withval=$with_eventhandler_dir; EVENTHANDLERDIR=$withval
else
EVENTHANDLERDIR=no
fi
if test x$EVENTHANDLERDIR = xno; then
EVENTHANDLERDIR="$libexecdir/eventhandlers"
fi
ENABLE_PERFDATA=no
# Check whether --enable-perfdata was given.
if test "${enable_perfdata+set}" = set; then :
enableval=$enable_perfdata;
if test x$enableval = xyes; then
ENABLE_PERFDATA=yes
fi
else
ENABLE_PERFDATA=no
fi
if test x$ENABLE_PERFDATA = xyes; then
ENABLEPERFDATA=1
else
ENABLEPERFDATA=0
fi
LOGDIR=no
# Check whether --with-log-dir was given.
if test "${with_log_dir+set}" = set; then :
withval=$with_log_dir; LOGDIR=$withval
else
LOGDIR=no
fi
if test x$LOGDIR = xno; then
LOGDIR="$localstatedir"
fi
ENABLE_CGILOG=no
# Check whether --enable-cgi-log was given.
if test "${enable_cgi_log+set}" = set; then :
enableval=$enable_cgi_log;
if test x$enableval = xyes; then
ENABLE_CGILOG=yes
fi
else
ENABLE_CGILOG=no
fi
if test x$ENABLE_CGILOG = xyes; then
ENABLECGILOG=1
else
ENABLECGILOG=0
fi
CGILOGDIR=no
# Check whether --with-cgi-log-dir was given.
if test "${with_cgi_log_dir+set}" = set; then :
withval=$with_cgi_log_dir; CGILOGDIR=$withval
else
CGILOGDIR=no
fi
if test x$CGILOGDIR = xno; then
CGILOGDIR="$datarootdir/log"
fi
EXTCMDFILEDIR=no
PHPAPIEXTCMDDIR=no
# Check whether --with-ext-cmd-file-dir was given.
if test "${with_ext_cmd_file_dir+set}" = set; then :
withval=$with_ext_cmd_file_dir; EXTCMDFILEDIR=$withval
else
EXTCMDFILEDIR=no
fi
if test x$EXTCMDFILEDIR = xno; then
EXTCMDFILEDIR="$localstatedir/rw"
fi
PHPAPIEXTCMDDIR="$EXTCMDFILEDIR"
P1FILELOC=no
# Check whether --with-p1-file-dir was given.
if test "${with_p1_file_dir+set}" = set; then :
withval=$with_p1_file_dir; P1FILELOC=$withval
else
P1FILELOC=no
fi
if test x$P1FILELOC = xno; then
P1FILELOC="$libdir"
fi
init_dir=/etc/rc.d/init.d
if test -d /etc/rc.d/init.d; then
init_dir="/etc/rc.d/init.d"
elif test -d /usr/local/etc/rc.d; then
init_dir="/usr/local/etc/rc.d"
elif test -d /etc/rc.d; then
init_dir="/etc/rc.d"
elif test -d /etc/init.d; then
init_dir="/etc/init.d"
elif test -d /sbin/init.d; then
init_dir="/sbin/init.d"
fi
# Check whether --with-init_dir was given.
if test "${with_init_dir+set}" = set; then :
withval=$with_init_dir; init_dir=$withval
fi
systemd_unit_dir=/usr/lib/systemd/system
if test -d /usr/lib/systemd/system; then
systemd_unit_dir=/usr/lib/systemd/system
elif test -d /lib/systemd/system; then
systemd_unit_dir=/lib/systemd/system
fi
systemd_sysconfig_dir=/etc/sysconfig
# Check whether --with-systemd_unit_dir was given.
if test "${with_systemd_unit_dir+set}" = set; then :
withval=$with_systemd_unit_dir; systemd_unit_dir=$withval
fi
# Check whether --with-systemd_sysconfig_dir was given.
if test "${with_systemd_sysconfig_dir+set}" = set; then :
withval=$with_systemd_sysconfig_dir; systemd_sysconfig_dir=$withval
fi
# Check whether --with-lockfile was given.
if test "${with_lockfile+set}" = set; then :
withval=$with_lockfile; lockfile=$withval
else
lockfile=$localstatedir/icinga.lock
fi
ICINGACHKFILE=no
# Check whether --with-icinga-chkfile was given.
if test "${with_icinga_chkfile+set}" = set; then :
withval=$with_icinga_chkfile; ICINGACHKFILE=$withval
else
ICINGACHKFILE=no
fi
if test x$ICINGACHKFILE = xno; then
ICINGACHKFILE="$localstatedir/icinga.chk"
fi
IDO2DBLOCKFILE=no
# Check whether --with-ido2db-lockfile was given.
if test "${with_ido2db_lockfile+set}" = set; then :
withval=$with_ido2db_lockfile; IDO2DBLOCKFILE=$withval
else
IDO2DBLOCKFILE=no
fi
if test x$IDO2DBLOCKFILE = xno; then
IDO2DBLOCKFILE="$localstatedir/ido2db.lock"
fi
IDOSOCKFILE=no
# Check whether --with-ido-sockfile was given.
if test "${with_ido_sockfile+set}" = set; then :
withval=$with_ido_sockfile; IDOSOCKFILE=$withval
else
IDOSOCKFILE=no
fi
if test x$IDOSOCKFILE = xno; then
IDOSOCKFILE="$localstatedir/ido.sock"
fi
IDOMODTMPFILE=no
# Check whether --with-idomod-tmpfile was given.
if test "${with_idomod_tmpfile+set}" = set; then :
withval=$with_idomod_tmpfile; IDOMODTMPFILE=$withval
else
IDOMODTMPFILE=no
fi
if test x$IDOMODTMPFILE = xno; then
IDOMODTMPFILE="$localstatedir/idomod.tmp"
fi
XSDTYPE=default
XCDTYPE=default
XRDTYPE=default
XODTYPE=template
XPDTYPE=default
XDDTYPE=default
XSDCOMMENT=
XCDCOMMENT=
XRDCOMMENT=
XODCOMMENT=
XPDCOMMENT=
XDDCOMMENT=
USE_MYSQL=no
USE_PGSQL=no
cat >>confdefs.h <<_ACEOF
#define USE_XSDDEFAULT /**/
_ACEOF
XSDC="xsddefault.c"
XSDH="xsddefault.h"
XSDCOMMENT="Default (text file)"
echo "We'll use default routines (in xdata/xsddefault.*) for status data I/O..."
cat >>confdefs.h <<_ACEOF
#define USE_XCDDEFAULT /**/
_ACEOF
XCDC="xcddefault.c"
XCDH="xcddefault.h"
XCDCOMMENT="Default (text file)"
echo "We'll use default routines (in xdata/xcddefault.*) for comment data I/O..."
cat >>confdefs.h <<_ACEOF
#define USE_XRDDEFAULT /**/
_ACEOF
XRDC="xrddefault.c"
XRDH="xrddefault.h"
XRDCOMMENT="Default (text file)"
echo "We'll use default routines (in xdata/xrddefault.*) for retention data I/O..."
cat >>confdefs.h <<_ACEOF
#define USE_XODTEMPLATE /**/
_ACEOF
XODC="xodtemplate.c"
XODH="xodtemplate.h"
XODCOMMENT="Template-based (text file)"
echo "We'll use template-based routines (in xdata/xodtemplate.*) for object data I/O..."
cat >>confdefs.h <<_ACEOF
#define USE_XPDDEFAULT /**/
_ACEOF
XPDC="xpddefault.c"
XPDH="xpddefault.h"
XPDCOMMENT="Default (external commands)"
echo "We'll use default routines (in xdata/xpddefault.*) for performance data I/O..."
cat >>confdefs.h <<_ACEOF
#define USE_XDDDEFAULT /**/
_ACEOF
XDDC="xdddefault.c"
XDDH="xdddefault.h"
XDDCOMMENT="Default (text file)"
echo "We'll use default routines (in xdata/xdddefault.*) for scheduled downtime data I/O..."
# Check whether --with-gd-lib was given.
if test "${with_gd_lib+set}" = set; then :
withval=$with_gd_lib;
LDFLAGS="${LDFLAGS} -L${withval}"
LD_RUN_PATH="${withval}${LD_RUN_PATH:+:}${LD_RUN_PATH}"
fi
# Check whether --with-gd-inc was given.
if test "${with_gd_inc+set}" = set; then :
withval=$with_gd_inc;
CFLAGS="${CFLAGS} -I${withval}"
fi
TRYGD=yep
TRYSTATUSMAP=yep
# Check whether --enable-statusmap was given.
if test "${enable_statusmap+set}" = set; then :
enableval=$enable_statusmap; TRYSTATUSMAP=nope
fi
if test x$TRYGD = xyep; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -liconv" >&5
$as_echo_n "checking for main in -liconv... " >&6; }
if ${ac_cv_lib_iconv_main+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-liconv $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
return main ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_iconv_main=yes
else
ac_cv_lib_iconv_main=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_iconv_main" >&5
$as_echo "$ac_cv_lib_iconv_main" >&6; }
if test "x$ac_cv_lib_iconv_main" = xyes; then :
ICONV=-liconv
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gdImagePng in -lgd (order 1)" >&5
$as_echo_n "checking for gdImagePng in -lgd (order 1)... " >&6; }
ac_lib_var=`echo gd'_'gdImagePng'_'1 | sed 'y%./+-%__p_%'`
if eval \${ac_cv_lib_$ac_lib_var+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_save_LIBS="$LIBS"
LIBS="-lgd -lttf -lpng -ljpeg -lz -lm $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char gdImagePng();
int
main ()
{
gdImagePng()
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
eval "ac_cv_lib_$ac_lib_var=yes"
else
eval "ac_cv_lib_$ac_lib_var=no"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS="$ac_save_LIBS"
fi
if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
GDLIBFOUND=yep
GDLIBS="-lgd -lttf -lpng -ljpeg -lz -lm"
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
:
fi
if test x$GDLIBFOUND = x; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gdImagePng in -lgd (order 2)" >&5
$as_echo_n "checking for gdImagePng in -lgd (order 2)... " >&6; }
ac_lib_var=`echo gd'_'gdImagePng'_'2 | sed 'y%./+-%__p_%'`
if eval \${ac_cv_lib_$ac_lib_var+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_save_LIBS="$LIBS"
LIBS="-lgd $ICONV -lpng -ljpeg -lz -lm $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char gdImagePng();
int
main ()
{
gdImagePng()
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
eval "ac_cv_lib_$ac_lib_var=yes"
else
eval "ac_cv_lib_$ac_lib_var=no"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS="$ac_save_LIBS"
fi
if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
GDLIBFOUND=yep
GDLIBS="-lgd $ICONV -lpng -ljpeg -lz -lm"
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
:
fi
fi
if test x$GDLIBFOUND = x; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gdImagePng in -lgd (order 3)" >&5
$as_echo_n "checking for gdImagePng in -lgd (order 3)... " >&6; }
ac_lib_var=`echo gd'_'gdImagePng'_'3 | sed 'y%./+-%__p_%'`
if eval \${ac_cv_lib_$ac_lib_var+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_save_LIBS="$LIBS"
LIBS="-lgd $ICONV -lz -lm -lpng $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char gdImagePng();
int
main ()
{
gdImagePng()
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
eval "ac_cv_lib_$ac_lib_var=yes"
else
eval "ac_cv_lib_$ac_lib_var=no"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS="$ac_save_LIBS"
fi
if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
GDLIBFOUND=yep
GDLIBS="-lgd $ICONV -lz -lm -lpng"
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
:
fi
fi
if test x$GDLIBFOUND = x; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gdImagePng in -lgd (order 4)" >&5
$as_echo_n "checking for gdImagePng in -lgd (order 4)... " >&6; }
ac_lib_var=`echo gd'_'gdImagePng'_'4 | sed 'y%./+-%__p_%'`
if eval \${ac_cv_lib_$ac_lib_var+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_save_LIBS="$LIBS"
LIBS="-lgd $ICONV -lpng -lz -lm $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char gdImagePng();
int
main ()
{
gdImagePng()
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
eval "ac_cv_lib_$ac_lib_var=yes"
else
eval "ac_cv_lib_$ac_lib_var=no"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS="$ac_save_LIBS"
fi
if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
GDLIBFOUND=yep
GDLIBS="-lgd $ICONV -lpng -lz -lm"
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
:
fi
fi
if test x$GDLIBFOUND = x; then
echo ""
echo ""
echo "*** GD, PNG, and/or JPEG libraries could not be located... *********"
echo ""
echo "Boutell's GD library is required to compile the statusmap, trends"
echo "and histogram CGIs. Get it from http://www.boutell.com/gd/, compile"
echo "it, and use the --with-gd-lib and --with-gd-inc arguments to specify"
echo "the locations of the GD library and include files."
echo ""
echo "NOTE: In addition to the gd-devel library, you'll also need to make"
echo " sure you have the png-devel and jpeg-devel libraries installed"
echo " on your system."
echo ""
echo "NOTE: After you install the necessary libraries on your system:"
echo " 1. Make sure /etc/ld.so.conf has an entry for the directory in"
echo " which the GD, PNG, and JPEG libraries are installed."
echo " 2. Run 'ldconfig' to update the run-time linker options."
echo " 3. Run 'make clean' in the Icinga distribution to clean out"
echo " any old references to your previous compile."
echo " 4. Rerun the configure script."
echo ""
echo "NOTE: If you can't get the configure script to recognize the GD libs"
echo " on your system, get over it and move on to other things. The"
echo " CGIs that use the GD libs are just a small part of the entire"
echo " Icinga package. Get everything else working first and then"
echo " revisit the problem. Make sure to check the icinga-users"
echo " mailing list archives for possible solutions to GD library"
echo " problems when you resume your troubleshooting."
echo ""
echo "********************************************************************"
echo ""
echo ""
else
echo "GD library was found!"
if test x$TRYSTATUSMAP = xyep; then
cat >>confdefs.h <<_ACEOF
#define USE_STATUSMAP /**/
_ACEOF
CGIEXTRAS="$CGIEXTRAS statusmap.cgi"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gdImageCreateTrueColor in -lgd" >&5
$as_echo_n "checking for gdImageCreateTrueColor in -lgd... " >&6; }
if ${ac_cv_lib_gd_gdImageCreateTrueColor+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lgd $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char gdImageCreateTrueColor ();
int
main ()
{
return gdImageCreateTrueColor ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_gd_gdImageCreateTrueColor=yes
else
ac_cv_lib_gd_gdImageCreateTrueColor=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gd_gdImageCreateTrueColor" >&5
$as_echo "$ac_cv_lib_gd_gdImageCreateTrueColor" >&6; }
if test "x$ac_cv_lib_gd_gdImageCreateTrueColor" = xyes; then :
$as_echo "#define HAVE_GDIMAGECREATETRUECOLOR 1" >>confdefs.h
fi
fi
cat >>confdefs.h <<_ACEOF
#define USE_TRENDS /**/
_ACEOF
CGIEXTRAS="$CGIEXTRAS trends.cgi"
cat >>confdefs.h <<_ACEOF
#define USE_HISTOGRAM /**/
_ACEOF
CGIEXTRAS="$CGIEXTRAS histogram.cgi"
fi
fi
ENABLE_DEBUG=no
# Check whether --enable-debug was given.
if test "${enable_debug+set}" = set; then :
enableval=$enable_debug; ENABLE_DEBUG=$enableval
else
ENABLE_DEBUG=no
fi
if test x$ENABLE_DEBUG = xyes; then
cat >>confdefs.h <<_ACEOF
#define ENABLE_DEBUG /**/
_ACEOF
fi
# Check whether --with-cgiurl was given.
if test "${with_cgiurl+set}" = set; then :
withval=$with_cgiurl; cgiurl=$withval
else
cgiurl=/icinga/cgi-bin
fi
# Check whether --with-htmurl was given.
if test "${with_htmurl+set}" = set; then :
withval=$with_htmurl; htmurl=$withval
else
htmurl=/icinga
fi
# Check whether --with-mainurl was given.
if test "${with_mainurl+set}" = set; then :
withval=$with_mainurl; mainurl=$withval
else
mainurl=$cgiurl/tac.cgi
fi
USE_NANOSLEEP=yes
# Check whether --enable-nanosleep was given.
if test "${enable_nanosleep+set}" = set; then :
enableval=$enable_nanosleep; USE_NANOSLEEP=$enableval
else
USE_NANOSLEEP=yes
fi
if test x$USE_NANOSLEEP = xyes; then
cat >>confdefs.h <<_ACEOF
#define USE_NANOSLEEP /**/
_ACEOF
fi
USE_EVENTBROKER=yes
# Check whether --enable-event-broker was given.
if test "${enable_event_broker+set}" = set; then :
enableval=$enable_event_broker; USE_EVENTBROKER=$enableval
else
USE_EVENTBROKER=yes
fi
BROKER_LDFLAGS=""
BROKERLIBS="";
some_dl_found="no";
if test x$USE_EVENTBROKER = xyes; then
ac_fn_c_check_header_mongrel "$LINENO" "ltdl.h" "ac_cv_header_ltdl_h" "$ac_includes_default"
if test "x$ac_cv_header_ltdl_h" = xyes; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for lt_dlinit in -lltdl" >&5
$as_echo_n "checking for lt_dlinit in -lltdl... " >&6; }
if ${ac_cv_lib_ltdl_lt_dlinit+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lltdl $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char lt_dlinit ();
int
main ()
{
return lt_dlinit ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_ltdl_lt_dlinit=yes
else
ac_cv_lib_ltdl_lt_dlinit=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ltdl_lt_dlinit" >&5
$as_echo "$ac_cv_lib_ltdl_lt_dlinit" >&6; }
if test "x$ac_cv_lib_ltdl_lt_dlinit" = xyes; then :
$as_echo "#define HAVE_LTDL_H /**/" >>confdefs.h
some_dl_found="yes"
BROKERLIBS="$BROKERLIBS -lltdl"
fi
fi
if test "x$some_dl_found" != xyes; then
ac_fn_c_check_header_mongrel "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default"
if test "x$ac_cv_header_dlfcn_h" = xyes; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5
$as_echo_n "checking for dlopen in -ldl... " >&6; }
if ${ac_cv_lib_dl_dlopen+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-ldl $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char dlopen ();
int
main ()
{
return dlopen ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_dl_dlopen=yes
else
ac_cv_lib_dl_dlopen=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5
$as_echo "$ac_cv_lib_dl_dlopen" >&6; }
if test "x$ac_cv_lib_dl_dlopen" = xyes; then :
$as_echo "#define HAVE_DLFCN_H /**/" >>confdefs.h
some_dl_found="yes"
BROKERLIBS="$BROKERLIBS -ldl"
fi
fi
fi
# Check how to export functions from the broker executable, needed
# when dynamically loaded drivers are loaded (so that they can find
# broker functions).
# OS'es with ELF executables using the GNU linker (Linux and recent *BSD,
# in rare cases Solaris) typically need '-Wl,-export-dynamic' (i.e. pass
# -export-dynamic to the linker - also known as -rdynamic and some other
# variants); some sysVr4 system(s) instead need(s) '-Wl,-Bexport'.
# AIX 4.x (perhaps only for x>=2) wants -Wl,-bexpall,-brtl and doesn't
# reliably return an error for others, thus we separate it out.
# Otherwise we assume that if the linker accepts the flag, it is needed.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for extra flags needed to export symbols" >&5
$as_echo_n "checking for extra flags needed to export symbols... " >&6; }
case $host_os in
aix4*|aix5*|aix6*|aix7*)
BROKER_LDFLAGS="$BROKER_LDFLAGS -Wl,-bexpall,-brtl"
;;
bsdi*)
BROKER_LDFLAGS="$BROKER_LDFLAGS -rdynamic"
;;
*)
save_ldflags="$LDFLAGS"
LDFLAGS=-Wl,-export-dynamic
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
BROKER_LDFLAGS="$BROKER_LDFLAGS -Wl,-export-dynamic"
else
LDFLAGS=-Wl,-Bexport
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
BROKER_LDFLAGS="$BROKER_LDFLAGS -Wl,-Bexport"
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5
$as_echo "none" >&6; }
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LDFLAGS="$save_ldflags"
;;
esac
test "x$BROKER_LDFLAGS" != x && { $as_echo "$as_me:${as_lineno-$LINENO}: result: $BROKER_LDFLAGS" >&5
$as_echo "$BROKER_LDFLAGS" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker flags for loadable modules" >&5
$as_echo_n "checking for linker flags for loadable modules... " >&6; }
case $host_os in
solaris2*|sysv4*)
MOD_LDFLAGS="-G -fPIC"
MOD_CFLAGS="-fPIC"
INIT_OPTS="-o root -g root"
SNPRINTF_BROKEN="yes"
;;
aix4*|aix5*|aix6*|aix7*)
#MOD_LDFLAGS="-G -bnoentry -bexpall"
MOD_LDFLAGS="-G -bM:SRE -bnoentry -bexpall"
INIT_OPTS="-o root -g root"
;;
freebsd2*)
# Non-ELF GNU linker
MOD_LDFLAGS="-Bshareable"
INIT_OPTS="-o root -g wheel"
;;
darwin*)
# Mach-O linker, a shared lib and a loadable
# object file is not the same thing.
MOD_LDFLAGS="-bundle -flat_namespace -undefined suppress"
MOD_CFLAGS="$MOD_CFLAGS -fno-common"
INIT_OPTS="-o root -g root"
;;
linux* | k*bsd*-gnu*)
# assume GNU linker and ELF
MOD_LDFLAGS="-shared"
MOD_CFLAGS="-fPIC"
INIT_OPTS="-o root -g root"
;;
freebsd*)
MOD_LDFLAGS="-shared"
MOD_CFLAGS="-fPIC"
INIT_OPTS="-o root -g wheel"
;;
*)
# assume GNU linker and ELF
MOD_LDFLAGS="-shared"
INIT_OPTS="-o root -g root"
;;
esac
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MOD_LDFLAGS" >&5
$as_echo "$MOD_LDFLAGS" >&6; }
cat >>confdefs.h <<_ACEOF
#define USE_EVENT_BROKER /**/
_ACEOF
BROKER_O="broker.o nebmods.o"
BROKER_H="../include/broker.h ../include/nebmods.h ../include/nebmodules.h ../include/nebcallbacks.h ../include/neberrors.h"
fi
if test x$SNPRINTF_BROKEN = xyes; then
$as_echo "#define SNPRINTF_BROKEN \"1\"" >>confdefs.h
SNPRINTF_O=../common/snprintf.o
SNPRINTF_O_IDO=snprintf.o
fi
CLASSICUI_STANDALONE=no
# Check whether --enable-classicui-standalone was given.
if test "${enable_classicui_standalone+set}" = set; then :
enableval=$enable_classicui_standalone; CLASSICUI_STANDALONE=$enableval
else
CLASSICUI_STANDALONE=no
fi
if test x$CLASSICUI_STANDALONE = xyes; then
CLASSICUI_STANDALONE_FLAG="1"
fi
if test x$CLASSICUI_STANDALONE = xno; then
CLASSICUI_STANDALONE_FLAG="0"
fi
if test x$CLASSICUI_STANDALONE = xno; then
OCILIB_LIB=""
USE_IDOUTILS=yes
USE_IDOUTILS_ORACLE=no
# Check whether --enable-idoutils was given.
if test "${enable_idoutils+set}" = set; then :
enableval=$enable_idoutils; USE_IDOUTILS=$enableval
else
USE_IDOUTILS=yes
fi
if test x$USE_IDOUTILS = xyes; then
if test x$USE_EVENTBROKER = xno; then
as_fn_error $? "--enable-idoutils needs also --enable-event-broker" "$LINENO" 5
fi
IDO_INSTANCE_NAME=no
# Check whether --with-ido-instance-name was given.
if test "${with_ido_instance_name+set}" = set; then :
withval=$with_ido_instance_name; IDO_INSTANCE_NAME=$withval
else
IDO_INSTANCE_NAME=no
fi
if test x$IDO_INSTANCE_NAME = xno; then
IDO_INSTANCE_NAME="default"
fi
USE_OCILIB=no
USE_LIBPQ=no
# Check whether --enable-oracle was given.
if test "${enable_oracle+set}" = set; then :
enableval=$enable_oracle; USE_OCILIB=$enableval
else
USE_OCILIB=no
fi
# Check whether --enable-pgsql was given.
if test "${enable_pgsql+set}" = set; then :
enableval=$enable_pgsql; USE_LIBPQ=$enableval
else
USE_LIBPQ=no
fi
if test x$USE_OCILIB = xyes; then
USE_IDOUTILS_ORACLE=yes
OCILIB_INC="/usr/local/include"
OCILIB_LIB="/usr/local/lib"
# Check whether --with-ocilib-lib was given.
if test "${with_ocilib_lib+set}" = set; then :
withval=$with_ocilib_lib;
OCILIB_LIB="${withval}"
fi
# Check whether --with-ocilib-inc was given.
if test "${with_ocilib_inc+set}" = set; then :
withval=$with_ocilib_inc;
OCILIB_INC="${withval}"
fi
ORACLE_LIB=""
# Check whether --with-oracle-lib was given.
if test "${with_oracle_lib+set}" = set; then :
withval=$with_oracle_lib;
ORACLE_LIB="${withval}"
fi
if test "$ORACLE_LIB" = ""; then
IDO2DB_RUNTIME="$OCILIB_LIB"
else
IDO2DB_RUNTIME="$OCILIB_LIB:$ORACLE_LIB"
fi
CFLAGS="$CFLAGS -I$OCILIB_INC -DOCI_IMPORT_RUNTIME -DOCI_CHARSET_ANSI"
LDFLAGS="$LDFLAGS -L$OCILIB_LIB"
for ac_header in ocilib.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "ocilib.h" "ac_cv_header_ocilib_h" "$ac_includes_default"
if test "x$ac_cv_header_ocilib_h" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_OCILIB_H 1
_ACEOF
fi
done
$as_echo "#define HAVE_OCILIB_H \"1\"" >>confdefs.h
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ocilib" >&5
$as_echo_n "checking for ocilib... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -locilib" >&5
$as_echo_n "checking for main in -locilib... " >&6; }
if ${ac_cv_lib_ocilib_main+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-locilib $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
return main ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_ocilib_main=yes
else
ac_cv_lib_ocilib_main=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ocilib_main" >&5
$as_echo "$ac_cv_lib_ocilib_main" >&6; }
if test "x$ac_cv_lib_ocilib_main" = xyes; then :
DBLIBS_OCI="${DBCFLAGS} -locilib"
else
as_fn_error $? "ERROR - We really need a ocilib to link against" "$LINENO" 5
fi
DBLIBS="${DBLIBS} ${DBLIBS_OCI}"
cat >>confdefs.h <<_ACEOF
#define USE_ORACLE 1
_ACEOF
fi
if test x$USE_LIBPQ = xyes; then
LIBPQ_INC=""
LIBPQ_LIB=""
# Check whether --with-pgsql-lib was given.
if test "${with_pgsql_lib+set}" = set; then :
withval=$with_pgsql_lib;
LIBPQ_LIB="-L${withval}"
fi
# Check whether --with-psql-inc was given.
if test "${with_psql_inc+set}" = set; then :
withval=$with_psql_inc;
LIBPQ_INC="-I${withval}"
fi
CFLAGS="$CFLAGS $LIBPQ_INC"
LDFLAGS="$LDFLAGS $LIBPQ_LIB"
for ac_header in libpq-fe.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "libpq-fe.h" "ac_cv_header_libpq_fe_h" "$ac_includes_default"
if test "x$ac_cv_header_libpq_fe_h" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_LIBPQ_FE_H 1
_ACEOF
fi
done
$as_echo "#define HAVE_LIBPQ_FE_H \"1\"" >>confdefs.h
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for lpq" >&5
$as_echo_n "checking for lpq... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -lpq" >&5
$as_echo_n "checking for main in -lpq... " >&6; }
if ${ac_cv_lib_pq_main+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lpq $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
return main ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_pq_main=yes
else
ac_cv_lib_pq_main=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pq_main" >&5
$as_echo "$ac_cv_lib_pq_main" >&6; }
if test "x$ac_cv_lib_pq_main" = xyes; then :
DBLIBS_PQ="${DBCFLAGS} -lpq"
else
as_fn_error $? "ERROR - We really need a libpq to link against" "$LINENO" 5
fi
DBLIBS="${DBLIBS} ${DBLIBS_PQ}"
cat >>confdefs.h <<_ACEOF
#define USE_PGSQL 1
_ACEOF
fi
if test x$USE_LIBPQ = xno && test x$USE_OCILIB = xno; then
LIBDBI_INC=""
LIBDBI_LIB=""
# Check whether --with-dbi-lib was given.
if test "${with_dbi_lib+set}" = set; then :
withval=$with_dbi_lib;
LIBDBI_LIB="-L${withval}"
fi
# Check whether --with-dbi-inc was given.
if test "${with_dbi_inc+set}" = set; then :
withval=$with_dbi_inc;
LIBDBI_INC="-I${withval}"
fi
CFLAGS="$CFLAGS $LIBDBI_INC"
LDFLAGS="$LDFLAGS $LIBDBI_LIB"
for ac_header in dbi/dbi.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "dbi/dbi.h" "ac_cv_header_dbi_dbi_h" "$ac_includes_default"
if test "x$ac_cv_header_dbi_dbi_h" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_DBI_DBI_H 1
_ACEOF
fi
done
$as_echo "#define HAVE_DBI_DBI_H \"1\"" >>confdefs.h
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for libdbi" >&5
$as_echo_n "checking for libdbi... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -ldbi" >&5
$as_echo_n "checking for main in -ldbi... " >&6; }
if ${ac_cv_lib_dbi_main+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-ldbi $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
return main ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_dbi_main=yes
else
ac_cv_lib_dbi_main=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dbi_main" >&5
$as_echo "$ac_cv_lib_dbi_main" >&6; }
if test "x$ac_cv_lib_dbi_main" = xyes; then :
DBLIBS_DBI="${DBCFLAGS} -ldbi"
else
as_fn_error $? "ERROR - We really need a libdbi to link against" "$LINENO" 5
fi
DBLIBS="${DBLIBS} ${DBLIBS_DBI}"
cat >>confdefs.h <<_ACEOF
#define USE_LIBDBI 1
_ACEOF
fi
fi
fi
LIBDBIDRIVERDIR=no
# Check whether --with-libdbi-driver-dir was given.
if test "${with_libdbi_driver_dir+set}" = set; then :
withval=$with_libdbi_driver_dir; LIBDBIDRIVERDIR=$withval
else
LIBDBIDRIVERDIR=no
fi
if test x$LIBDBIDRIVERDIR = xno; then
LIBDBIDRIVERDIR="/usr/local/lib/dbd"
fi
USEPERL=no;
INSTALLPERLSTUFF=no;
# Check whether --enable-embedded-perl was given.
if test "${enable_embedded_perl+set}" = set; then :
enableval=$enable_embedded_perl;
USEPERL=$enableval
else
USEPERL=no
fi
PERLCACHE=yes;
# Check whether --with-perlcache was given.
if test "${with_perlcache+set}" = set; then :
withval=$with_perlcache;
PERLCACHE=$withval
else
$as_echo "#define DO_CLEAN \"1\"" >>confdefs.h
PERLCACHE=yes;
fi
if test x$USEPERL = xyes; then
cat >>confdefs.h <<_ACEOF
#define EMBEDDEDPERL /**/
_ACEOF
PERLLIBS="`perl -MExtUtils::Embed -e ldopts`"
PERLDIR="`perl -MConfig -e 'print $Config{installsitearch}'`"
CFLAGS="${CFLAGS} `perl -MExtUtils::Embed -e ccopts`"
USEPERL=yes
INSTALLPERLSTUFF=yes;
PERLXSI_O=perlxsi.o
OBJS="${OBJS} ${PERLXSI_O}"
echo "creating base/perlxsi.c"
perl -MExtUtils::Embed -e xsinit -- -o base/perlxsi.c
echo "Embedded Perl interpreter will be compiled in..."
if test x$PERLCACHE = xyes; then
$as_echo "#define DO_CLEAN \"0\"" >>confdefs.h
PERLCACHE=yes;
echo "Internally compiled Perl scripts will be cached..."
else
$as_echo "#define DO_CLEAN \"1\"" >>confdefs.h
echo "Internally compiled Perl scripts will NOT be cached..."
fi
fi
if test x$USEPERL = xyes; then
if (perl -e 'use Config;exit -1 unless ($Config{'usethreads'});'); then
echo "Using threaded perl"
cat >>confdefs.h <<_ACEOF
#define THREADEDPERL /**/
_ACEOF
fi
fi
icinga_name=icinga
icingastats_name=icingastats
ido2db_name=ido2db
cygwin=no
# Check whether --enable-cygwin was given.
if test "${enable_cygwin+set}" = set; then :
enableval=$enable_cygwin;
cygwin=$enableval
fi
if test x$cygwin = xyes; then
CFLAGS="${CFLAGS} -DCYGWIN"
icinga_name=icinga.exe;
icingastats_name=icingastats.exe;
fi
ido2db_runtime="$IDO2DB_RUNTIME"
VERSION=$PKG_VERSION
PACKDIR=`pwd`/solaris_pkg
SOL_PKG_NAME=Icinga
ARCH=`uname -p`
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for type va_list" >&5
$as_echo_n "checking for type va_list... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#ifdef __STDC__
#include
#include
#include
#else
#include
#include
#include
#endif
int
main ()
{
va_list args;
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
else
$as_echo "#define NEED_VA_LIST /**/" >>confdefs.h
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
# Check whether --enable-libtap was given.
if test "${enable_libtap+set}" = set; then :
enableval=$enable_libtap; enable_libtap=$enableval
else
enable_libtap=yes
fi
env_prefix="ICINGA_"
# Check whether --enable-nagiosenv was given.
if test "${enable_nagiosenv+set}" = set; then :
enableval=$enable_nagiosenv;
fi
if test "x$enable_nagiosenv" = "xyes"; then :
env_prefix="NAGIOS_"
$as_echo "#define USE_NAGIOS_ENV \"1\"" >>confdefs.h
fi
# Extract the first word of "perl", so it can be a program name with args.
set dummy perl; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_path_PERL+:} false; then :
$as_echo_n "(cached) " >&6
else
case $PERL in
[\\/]* | ?:[\\/]*)
ac_cv_path_PERL="$PERL" # Let the user override the test with a path.
;;
*)
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_path_PERL="$as_dir/$ac_word$ac_exec_ext"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS
;;
esac
fi
PERL=$ac_cv_path_PERL
if test -n "$PERL"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PERL" >&5
$as_echo "$PERL" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
ido2db_perl="$PERL"
# Check whether --enable-ssl was given.
if test "${enable_ssl+set}" = set; then :
enableval=$enable_ssl;
if test x$enableval = xyes; then
check_for_ssl=yes
else
check_for_ssl=no
fi
else
check_for_ssl=no
fi
ssl_dir=
ssl_inc_dir=
ssl_lib_dir=
# Check whether --with-ssl was given.
if test "${with_ssl+set}" = set; then :
withval=$with_ssl;
ssl_dir=$withval
fi
# Check whether --with-ssl-inc was given.
if test "${with_ssl_inc+set}" = set; then :
withval=$with_ssl_inc;
ssl_inc_dir=$withval
fi
# Check whether --with-ssl-lib was given.
if test "${with_ssl_lib+set}" = set; then :
withval=$with_ssl_lib;
ssl_lib_dir=$withval
fi
# Check whether --with-kerberos-inc was given.
if test "${with_kerberos_inc+set}" = set; then :
withval=$with_kerberos_inc;
kerberos_inc_dir=$withval
fi
if test x$check_for_ssl = xyes; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SSL headers" >&5
$as_echo_n "checking for SSL headers... " >&6; }
found_ssl=no
for dir in $ssl_inc_dir $ssl_dir /usr/local/openssl /usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr /usr/freeware/lib/openssl; do
ssldir="$dir"
if test -f "$dir/include/openssl/ssl.h"; then
found_ssl=yes
CFLAGS="$CFLAGS -I$dir/include/openssl -I$ssldir/include"
sslincdir="$dir/include/openssl"
break
fi
if test -f "$dir/include/ssl.h"; then
found_ssl=yes
CFLAGS="$CFLAGS -I$dir/include"
sslincdir="$dir/include"
break
fi
if test -f "$dir/ssl.h"; then
found_ssl=yes
CFLAGS="$CFLAGS -I$dir"
sslincdir="$dir"
ssldir="$dir/.."
break
fi
if test -f "$dir/openssl/ssl.h"; then
found_ssl=yes
CFLAGS="$CFLAGS -I$dir/openssl"
sslincdir="$dir/openssl"
ssldir="$dir/.."
break
fi
done
if test x_$found_ssl != x_yes; then
as_fn_error $? "Cannot find ssl headers" "$LINENO" 5
else
printf "SSL headers found in $ssldir\n";
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SSL libraries" >&5
$as_echo_n "checking for SSL libraries... " >&6; }
found_ssl=no
for dir in $ssl_lib_dir $ssl_dir /usr/lib/*-linux-gnu /usr/lib64 /usr/lib /usr/local/lib /usr/lib/ssl /usr/ssl/lib /usr/openssl/lib /usr/pkg/lib /usr/freeware/lib/openssl; do
ssllibdir="$dir"
if test -f "$dir/libssl.so"; then
found_ssl=yes
break
fi
if test -f "$dir/lib/libssl.so"; then
found_ssl=yes
ssllibdir="$dir/lib"
break
fi
done
if test x_$found_ssl != x_yes; then
as_fn_error $? "Cannot find ssl libraries" "$LINENO" 5
else
printf "SSL libraries found in $ssllibdir\n";
LDFLAGS="$LDFLAGS -L$ssllibdir";
LIBS="$LIBS -lssl -lcrypto";
cat >>confdefs.h <<_ACEOF
#define HAVE_SSL 1
_ACEOF
if test "ssl_dir" != ""; then
ssldir="$ssl_dir"
fi
echo ""
echo "*** Generating DH Parameters for SSL/TLS ***"
if test -f "$ssldir/sbin/openssl"; then
sslbin=$ssldir/sbin/openssl
else
if test -f "$ssldir/bin/openssl"; then
sslbin=$ssldir/bin/openssl
else
sslbin=openssl
fi
fi
# awk to strip off meta data at bottom of dhparam output
$sslbin dhparam -C 512 | awk '/^-----/ {exit} {print}' > include/dh.h
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Kerberos include files" >&5
$as_echo_n "checking for Kerberos include files... " >&6; }
found_kerberos=no
for dir in $kerberos_inc_dir /usr/kerberos/include; do
kerbdir="$dir"
if test -f "$dir/krb5.h"; then
found_kerberos=yes
CFLAGS="$CFLAGS -I$kerbdir"
cat >>confdefs.h <<_ACEOF
#define HAVE_KRB5_H 1
_ACEOF
break
fi
done
if test x_$found_kerberos != x_yes; then
printf "could not find include files\n";
else
printf "found Kerberos include files in $kerbdir\n";
fi
fi
TESTS_CFLAGS="$CFLAGS"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -Wall based on os/compiler" >&5
$as_echo_n "checking for -Wall based on os/compiler... " >&6; }
case $host_os in
solaris2*|sysv4*)
;;
aix4*|aix5*|aix6*|aix7*)
CFLAGS="-Wall $CFLAGS"
;;
freebsd2*)
;;
darwin*)
;;
linux* | k*bsd*-gnu*)
CFLAGS="-Wall $CFLAGS"
;;
freebsd*)
CFLAGS="-Wall $CFLAGS"
;;
*)
;;
esac
ac_config_files="$ac_config_files Makefile subst solaris/pkginfo solaris/icinga.xml base/Makefile common/Makefile contrib/Makefile cgi/Makefile html/Makefile module/Makefile module/idoutils/Makefile xdata/Makefile daemon-init rc.ido2db icinga-systemd sysconfig-env ido2db-systemd module/idoutils/src/Makefile t-tap/Makefile t/Makefile module/idoutils/db/scripts/installdb module/idoutils/db/scripts/upgradedb module/idoutils/db/scripts/prepsql p1.pl"
test "x$prefix" = xNONE && prefix=$ac_default_prefix
# Let make expand exec_prefix.
test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
DEFS=-DHAVE_CONFIG_H
ac_libobjs=
ac_ltlibobjs=
U=
for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
# 1. Remove the extension, and $U if already installed.
ac_script='s/\$U\././;s/\.o$//;s/\.obj$//'
ac_i=`$as_echo "$ac_i" | sed "$ac_script"`
# 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR
# will be set to the directory where LIBOBJS objects are built.
as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext"
as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo'
done
LIBOBJS=$ac_libobjs
LTLIBOBJS=$ac_ltlibobjs
: "${CONFIG_STATUS=./config.status}"
ac_write_fail=0
ac_clean_files_save=$ac_clean_files
ac_clean_files="$ac_clean_files $CONFIG_STATUS"
{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5
$as_echo "$as_me: creating $CONFIG_STATUS" >&6;}
as_write_fail=0
cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1
#! $SHELL
# Generated by $as_me.
# Run this file to recreate the current configuration.
# Compiler output produced by configure, useful for debugging
# configure, is in config.log if it exists.
debug=false
ac_cs_recheck=false
ac_cs_silent=false
SHELL=\${CONFIG_SHELL-$SHELL}
export SHELL
_ASEOF
cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1
## -------------------- ##
## M4sh Initialization. ##
## -------------------- ##
# Be more Bourne compatible
DUALCASE=1; export DUALCASE # for MKS sh
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
emulate sh
NULLCMD=:
# Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
# is contrary to our usage. Disable this feature.
alias -g '${1+"$@"}'='"$@"'
setopt NO_GLOB_SUBST
else
case `(set -o) 2>/dev/null` in #(
*posix*) :
set -o posix ;; #(
*) :
;;
esac
fi
as_nl='
'
export as_nl
# Printing a long string crashes Solaris 7 /usr/bin/printf.
as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
# Prefer a ksh shell builtin over an external printf program on Solaris,
# but without wasting forks for bash or zsh.
if test -z "$BASH_VERSION$ZSH_VERSION" \
&& (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
as_echo='print -r --'
as_echo_n='print -rn --'
elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
as_echo='printf %s\n'
as_echo_n='printf %s'
else
if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
as_echo_n='/usr/ucb/echo -n'
else
as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
as_echo_n_body='eval
arg=$1;
case $arg in #(
*"$as_nl"*)
expr "X$arg" : "X\\(.*\\)$as_nl";
arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
esac;
expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
'
export as_echo_n_body
as_echo_n='sh -c $as_echo_n_body as_echo'
fi
export as_echo_body
as_echo='sh -c $as_echo_body as_echo'
fi
# The user is always right.
if test "${PATH_SEPARATOR+set}" != set; then
PATH_SEPARATOR=:
(PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
(PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
PATH_SEPARATOR=';'
}
fi
# IFS
# We need space, tab and new line, in precisely that order. Quoting is
# there to prevent editors from complaining about space-tab.
# (If _AS_PATH_WALK were called with IFS unset, it would disable word
# splitting by setting IFS to empty value.)
IFS=" "" $as_nl"
# Find who we are. Look in the path if we contain no directory separator.
as_myself=
case $0 in #((
*[\\/]* ) as_myself=$0 ;;
*) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
done
IFS=$as_save_IFS
;;
esac
# We did not find ourselves, most probably we were run as `sh COMMAND'
# in which case we are not to be found in the path.
if test "x$as_myself" = x; then
as_myself=$0
fi
if test ! -f "$as_myself"; then
$as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
exit 1
fi
# Unset variables that we do not need and which cause bugs (e.g. in
# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1"
# suppresses any "Segmentation fault" message there. '((' could
# trigger a bug in pdksh 5.2.14.
for as_var in BASH_ENV ENV MAIL MAILPATH
do eval test x\${$as_var+set} = xset \
&& ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
done
PS1='$ '
PS2='> '
PS4='+ '
# NLS nuisances.
LC_ALL=C
export LC_ALL
LANGUAGE=C
export LANGUAGE
# CDPATH.
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
# as_fn_error STATUS ERROR [LINENO LOG_FD]
# ----------------------------------------
# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
# script with STATUS, using 1 if that was 0.
as_fn_error ()
{
as_status=$1; test $as_status -eq 0 && as_status=1
if test "$4"; then
as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
$as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
fi
$as_echo "$as_me: error: $2" >&2
as_fn_exit $as_status
} # as_fn_error
# as_fn_set_status STATUS
# -----------------------
# Set $? to STATUS, without forking.
as_fn_set_status ()
{
return $1
} # as_fn_set_status
# as_fn_exit STATUS
# -----------------
# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
as_fn_exit ()
{
set +e
as_fn_set_status $1
exit $1
} # as_fn_exit
# as_fn_unset VAR
# ---------------
# Portably unset VAR.
as_fn_unset ()
{
{ eval $1=; unset $1;}
}
as_unset=as_fn_unset
# as_fn_append VAR VALUE
# ----------------------
# Append the text in VALUE to the end of the definition contained in VAR. Take
# advantage of any shell optimizations that allow amortized linear growth over
# repeated appends, instead of the typical quadratic growth present in naive
# implementations.
if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
eval 'as_fn_append ()
{
eval $1+=\$2
}'
else
as_fn_append ()
{
eval $1=\$$1\$2
}
fi # as_fn_append
# as_fn_arith ARG...
# ------------------
# Perform arithmetic evaluation on the ARGs, and store the result in the
# global $as_val. Take advantage of shells that can avoid forks. The arguments
# must be portable across $(()) and expr.
if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
eval 'as_fn_arith ()
{
as_val=$(( $* ))
}'
else
as_fn_arith ()
{
as_val=`expr "$@" || test $? -eq 1`
}
fi # as_fn_arith
if expr a : '\(a\)' >/dev/null 2>&1 &&
test "X`expr 00001 : '.*\(...\)'`" = X001; then
as_expr=expr
else
as_expr=false
fi
if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
as_basename=basename
else
as_basename=false
fi
if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
as_dirname=dirname
else
as_dirname=false
fi
as_me=`$as_basename -- "$0" ||
$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
X"$0" : 'X\(//\)$' \| \
X"$0" : 'X\(/\)' \| . 2>/dev/null ||
$as_echo X/"$0" |
sed '/^.*\/\([^/][^/]*\)\/*$/{
s//\1/
q
}
/^X\/\(\/\/\)$/{
s//\1/
q
}
/^X\/\(\/\).*/{
s//\1/
q
}
s/.*/./; q'`
# Avoid depending upon Character Ranges.
as_cr_letters='abcdefghijklmnopqrstuvwxyz'
as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
as_cr_Letters=$as_cr_letters$as_cr_LETTERS
as_cr_digits='0123456789'
as_cr_alnum=$as_cr_Letters$as_cr_digits
ECHO_C= ECHO_N= ECHO_T=
case `echo -n x` in #(((((
-n*)
case `echo 'xy\c'` in
*c*) ECHO_T=' ';; # ECHO_T is single tab character.
xy) ECHO_C='\c';;
*) echo `echo ksh88 bug on AIX 6.1` > /dev/null
ECHO_T=' ';;
esac;;
*)
ECHO_N='-n';;
esac
rm -f conf$$ conf$$.exe conf$$.file
if test -d conf$$.dir; then
rm -f conf$$.dir/conf$$.file
else
rm -f conf$$.dir
mkdir conf$$.dir 2>/dev/null
fi
if (echo >conf$$.file) 2>/dev/null; then
if ln -s conf$$.file conf$$ 2>/dev/null; then
as_ln_s='ln -s'
# ... but there are two gotchas:
# 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
# 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
# In both cases, we have to default to `cp -pR'.
ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
as_ln_s='cp -pR'
elif ln conf$$.file conf$$ 2>/dev/null; then
as_ln_s=ln
else
as_ln_s='cp -pR'
fi
else
as_ln_s='cp -pR'
fi
rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
rmdir conf$$.dir 2>/dev/null
# as_fn_mkdir_p
# -------------
# Create "$as_dir" as a directory, including parents if necessary.
as_fn_mkdir_p ()
{
case $as_dir in #(
-*) as_dir=./$as_dir;;
esac
test -d "$as_dir" || eval $as_mkdir_p || {
as_dirs=
while :; do
case $as_dir in #(
*\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
*) as_qdir=$as_dir;;
esac
as_dirs="'$as_qdir' $as_dirs"
as_dir=`$as_dirname -- "$as_dir" ||
$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
X"$as_dir" : 'X\(//\)[^/]' \| \
X"$as_dir" : 'X\(//\)$' \| \
X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
$as_echo X"$as_dir" |
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
s//\1/
q
}
/^X\(\/\/\)[^/].*/{
s//\1/
q
}
/^X\(\/\/\)$/{
s//\1/
q
}
/^X\(\/\).*/{
s//\1/
q
}
s/.*/./; q'`
test -d "$as_dir" && break
done
test -z "$as_dirs" || eval "mkdir $as_dirs"
} || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
} # as_fn_mkdir_p
if mkdir -p . 2>/dev/null; then
as_mkdir_p='mkdir -p "$as_dir"'
else
test -d ./-p && rmdir ./-p
as_mkdir_p=false
fi
# as_fn_executable_p FILE
# -----------------------
# Test if FILE is an executable regular file.
as_fn_executable_p ()
{
test -f "$1" && test -x "$1"
} # as_fn_executable_p
as_test_x='test -x'
as_executable_p=as_fn_executable_p
# Sed expression to map a string onto a valid CPP name.
as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
# Sed expression to map a string onto a valid variable name.
as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
exec 6>&1
## ----------------------------------- ##
## Main body of $CONFIG_STATUS script. ##
## ----------------------------------- ##
_ASEOF
test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# Save the log message, to keep $0 and so on meaningful, and to
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by $as_me, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
CONFIG_HEADERS = $CONFIG_HEADERS
CONFIG_LINKS = $CONFIG_LINKS
CONFIG_COMMANDS = $CONFIG_COMMANDS
$ $0 $@
on `(hostname || uname -n) 2>/dev/null | sed 1q`
"
_ACEOF
case $ac_config_files in *"
"*) set x $ac_config_files; shift; ac_config_files=$*;;
esac
case $ac_config_headers in *"
"*) set x $ac_config_headers; shift; ac_config_headers=$*;;
esac
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
# Files that config.status was made for.
config_files="$ac_config_files"
config_headers="$ac_config_headers"
_ACEOF
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
ac_cs_usage="\
\`$as_me' instantiates files and other configuration actions
from templates according to the current configuration. Unless the files
and actions are specified as TAGs, all are instantiated by default.
Usage: $0 [OPTION]... [TAG]...
-h, --help print this help, then exit
-V, --version print version number and configuration settings, then exit
--config print configuration, then exit
-q, --quiet, --silent
do not print progress messages
-d, --debug don't remove temporary files
--recheck update $as_me by reconfiguring in the same conditions
--file=FILE[:TEMPLATE]
instantiate the configuration file FILE
--header=FILE[:TEMPLATE]
instantiate the configuration header FILE
Configuration files:
$config_files
Configuration headers:
$config_headers
Report bugs to the package provider."
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
config.status
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
Copyright (C) 2012 Free Software Foundation, Inc.
This config.status script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it."
ac_pwd='$ac_pwd'
srcdir='$srcdir'
INSTALL='$INSTALL'
test -n "\$AWK" || AWK=awk
_ACEOF
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# The default lists apply if the user does not specify any file.
ac_need_defaults=:
while test $# != 0
do
case $1 in
--*=?*)
ac_option=`expr "X$1" : 'X\([^=]*\)='`
ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'`
ac_shift=:
;;
--*=)
ac_option=`expr "X$1" : 'X\([^=]*\)='`
ac_optarg=
ac_shift=:
;;
*)
ac_option=$1
ac_optarg=$2
ac_shift=shift
;;
esac
case $ac_option in
# Handling of the options.
-recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
ac_cs_recheck=: ;;
--version | --versio | --versi | --vers | --ver | --ve | --v | -V )
$as_echo "$ac_cs_version"; exit ;;
--config | --confi | --conf | --con | --co | --c )
$as_echo "$ac_cs_config"; exit ;;
--debug | --debu | --deb | --de | --d | -d )
debug=: ;;
--file | --fil | --fi | --f )
$ac_shift
case $ac_optarg in
*\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
'') as_fn_error $? "missing file argument" ;;
esac
as_fn_append CONFIG_FILES " '$ac_optarg'"
ac_need_defaults=false;;
--header | --heade | --head | --hea )
$ac_shift
case $ac_optarg in
*\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
esac
as_fn_append CONFIG_HEADERS " '$ac_optarg'"
ac_need_defaults=false;;
--he | --h)
# Conflict between --help and --header
as_fn_error $? "ambiguous option: \`$1'
Try \`$0 --help' for more information.";;
--help | --hel | -h )
$as_echo "$ac_cs_usage"; exit ;;
-q | -quiet | --quiet | --quie | --qui | --qu | --q \
| -silent | --silent | --silen | --sile | --sil | --si | --s)
ac_cs_silent=: ;;
# This is an error.
-*) as_fn_error $? "unrecognized option: \`$1'
Try \`$0 --help' for more information." ;;
*) as_fn_append ac_config_targets " $1"
ac_need_defaults=false ;;
esac
shift
done
ac_configure_extra_args=
if $ac_cs_silent; then
exec 6>/dev/null
ac_configure_extra_args="$ac_configure_extra_args --silent"
fi
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
if \$ac_cs_recheck; then
set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
shift
\$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
CONFIG_SHELL='$SHELL'
export CONFIG_SHELL
exec "\$@"
fi
_ACEOF
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
exec 5>>config.log
{
echo
sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
## Running $as_me. ##
_ASBOX
$as_echo "$ac_log"
} >&5
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
_ACEOF
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# Handling of arguments.
for ac_config_target in $ac_config_targets
do
case $ac_config_target in
"include/config.h") CONFIG_HEADERS="$CONFIG_HEADERS include/config.h" ;;
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
"subst") CONFIG_FILES="$CONFIG_FILES subst" ;;
"solaris/pkginfo") CONFIG_FILES="$CONFIG_FILES solaris/pkginfo" ;;
"solaris/icinga.xml") CONFIG_FILES="$CONFIG_FILES solaris/icinga.xml" ;;
"base/Makefile") CONFIG_FILES="$CONFIG_FILES base/Makefile" ;;
"common/Makefile") CONFIG_FILES="$CONFIG_FILES common/Makefile" ;;
"contrib/Makefile") CONFIG_FILES="$CONFIG_FILES contrib/Makefile" ;;
"cgi/Makefile") CONFIG_FILES="$CONFIG_FILES cgi/Makefile" ;;
"html/Makefile") CONFIG_FILES="$CONFIG_FILES html/Makefile" ;;
"module/Makefile") CONFIG_FILES="$CONFIG_FILES module/Makefile" ;;
"module/idoutils/Makefile") CONFIG_FILES="$CONFIG_FILES module/idoutils/Makefile" ;;
"xdata/Makefile") CONFIG_FILES="$CONFIG_FILES xdata/Makefile" ;;
"daemon-init") CONFIG_FILES="$CONFIG_FILES daemon-init" ;;
"rc.ido2db") CONFIG_FILES="$CONFIG_FILES rc.ido2db" ;;
"icinga-systemd") CONFIG_FILES="$CONFIG_FILES icinga-systemd" ;;
"sysconfig-env") CONFIG_FILES="$CONFIG_FILES sysconfig-env" ;;
"ido2db-systemd") CONFIG_FILES="$CONFIG_FILES ido2db-systemd" ;;
"module/idoutils/src/Makefile") CONFIG_FILES="$CONFIG_FILES module/idoutils/src/Makefile" ;;
"t-tap/Makefile") CONFIG_FILES="$CONFIG_FILES t-tap/Makefile" ;;
"t/Makefile") CONFIG_FILES="$CONFIG_FILES t/Makefile" ;;
"module/idoutils/db/scripts/installdb") CONFIG_FILES="$CONFIG_FILES module/idoutils/db/scripts/installdb" ;;
"module/idoutils/db/scripts/upgradedb") CONFIG_FILES="$CONFIG_FILES module/idoutils/db/scripts/upgradedb" ;;
"module/idoutils/db/scripts/prepsql") CONFIG_FILES="$CONFIG_FILES module/idoutils/db/scripts/prepsql" ;;
"p1.pl") CONFIG_FILES="$CONFIG_FILES p1.pl" ;;
*) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
esac
done
# If the user did not use the arguments to specify the items to instantiate,
# then the envvar interface is used. Set only those that are not.
# We use the long form for the default assignment because of an extremely
# bizarre bug on SunOS 4.1.3.
if $ac_need_defaults; then
test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers
fi
# Have a temporary directory for convenience. Make it in the build tree
# simply because there is no reason against having it here, and in addition,
# creating and moving files from /tmp can sometimes cause problems.
# Hook for its removal unless debugging.
# Note that there is a small window in which the directory will not be cleaned:
# after its creation but before its name has been assigned to `$tmp'.
$debug ||
{
tmp= ac_tmp=
trap 'exit_status=$?
: "${ac_tmp:=$tmp}"
{ test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status
' 0
trap 'as_fn_exit 1' 1 2 13 15
}
# Create a (secure) tmp directory for tmp files.
{
tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
test -d "$tmp"
} ||
{
tmp=./conf$$-$RANDOM
(umask 077 && mkdir "$tmp")
} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5
ac_tmp=$tmp
# Set up the scripts for CONFIG_FILES section.
# No need to generate them if there are no CONFIG_FILES.
# This happens for instance with `./config.status config.h'.
if test -n "$CONFIG_FILES"; then
ac_cr=`echo X | tr X '\015'`
# On cygwin, bash can eat \r inside `` if the user requested igncr.
# But we know of no other shell where ac_cr would be empty at this
# point, so we can use a bashism as a fallback.
if test "x$ac_cr" = x; then
eval ac_cr=\$\'\\r\'
fi
ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null`
if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then
ac_cs_awk_cr='\\r'
else
ac_cs_awk_cr=$ac_cr
fi
echo 'BEGIN {' >"$ac_tmp/subs1.awk" &&
_ACEOF
{
echo "cat >conf$$subs.awk <<_ACEOF" &&
echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' &&
echo "_ACEOF"
} >conf$$subs.sh ||
as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'`
ac_delim='%!_!# '
for ac_last_try in false false false false false :; do
. ./conf$$subs.sh ||
as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X`
if test $ac_delim_n = $ac_delim_num; then
break
elif $ac_last_try; then
as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
else
ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
fi
done
rm -f conf$$subs.sh
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK &&
_ACEOF
sed -n '
h
s/^/S["/; s/!.*/"]=/
p
g
s/^[^!]*!//
:repl
t repl
s/'"$ac_delim"'$//
t delim
:nl
h
s/\(.\{148\}\)..*/\1/
t more1
s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/
p
n
b repl
:more1
s/["\\]/\\&/g; s/^/"/; s/$/"\\/
p
g
s/.\{148\}//
t nl
:delim
h
s/\(.\{148\}\)..*/\1/
t more2
s/["\\]/\\&/g; s/^/"/; s/$/"/
p
b
:more2
s/["\\]/\\&/g; s/^/"/; s/$/"\\/
p
g
s/.\{148\}//
t delim
' >$CONFIG_STATUS || ac_write_fail=1
rm -f conf$$subs.awk
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
_ACAWK
cat >>"\$ac_tmp/subs1.awk" <<_ACAWK &&
for (key in S) S_is_set[key] = 1
FS = ""
}
{
line = $ 0
nfields = split(line, field, "@")
substed = 0
len = length(field[1])
for (i = 2; i < nfields; i++) {
key = field[i]
keylen = length(key)
if (S_is_set[key]) {
value = S[key]
line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3)
len += length(value) + length(field[++i])
substed = 1
} else
len += 1 + keylen
}
print line
}
_ACAWK
_ACEOF
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then
sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g"
else
cat
fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \
|| as_fn_error $? "could not setup config files machinery" "$LINENO" 5
_ACEOF
# VPATH may cause trouble with some makes, so we remove sole $(srcdir),
# ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and
# trailing colons and then remove the whole line if VPATH becomes empty
# (actually we leave an empty line to preserve line numbers).
if test "x$srcdir" = x.; then
ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{
h
s///
s/^/:/
s/[ ]*$/:/
s/:\$(srcdir):/:/g
s/:\${srcdir}:/:/g
s/:@srcdir@:/:/g
s/^:*//
s/:*$//
x
s/\(=[ ]*\).*/\1/
G
s/\n//
s/^[^=]*=[ ]*$//
}'
fi
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
fi # test -n "$CONFIG_FILES"
# Set up the scripts for CONFIG_HEADERS section.
# No need to generate them if there are no CONFIG_HEADERS.
# This happens for instance with `./config.status Makefile'.
if test -n "$CONFIG_HEADERS"; then
cat >"$ac_tmp/defines.awk" <<\_ACAWK ||
BEGIN {
_ACEOF
# Transform confdefs.h into an awk script `defines.awk', embedded as
# here-document in config.status, that substitutes the proper values into
# config.h.in to produce config.h.
# Create a delimiter string that does not exist in confdefs.h, to ease
# handling of long lines.
ac_delim='%!_!# '
for ac_last_try in false false :; do
ac_tt=`sed -n "/$ac_delim/p" confdefs.h`
if test -z "$ac_tt"; then
break
elif $ac_last_try; then
as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5
else
ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
fi
done
# For the awk script, D is an array of macro values keyed by name,
# likewise P contains macro parameters if any. Preserve backslash
# newline sequences.
ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]*
sed -n '
s/.\{148\}/&'"$ac_delim"'/g
t rset
:rset
s/^[ ]*#[ ]*define[ ][ ]*/ /
t def
d
:def
s/\\$//
t bsnl
s/["\\]/\\&/g
s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\
D["\1"]=" \3"/p
s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p
d
:bsnl
s/["\\]/\\&/g
s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\
D["\1"]=" \3\\\\\\n"\\/p
t cont
s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p
t cont
d
:cont
n
s/.\{148\}/&'"$ac_delim"'/g
t clear
:clear
s/\\$//
t bsnlc
s/["\\]/\\&/g; s/^/"/; s/$/"/p
d
:bsnlc
s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p
b cont
' >$CONFIG_STATUS || ac_write_fail=1
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
for (key in D) D_is_set[key] = 1
FS = ""
}
/^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ {
line = \$ 0
split(line, arg, " ")
if (arg[1] == "#") {
defundef = arg[2]
mac1 = arg[3]
} else {
defundef = substr(arg[1], 2)
mac1 = arg[2]
}
split(mac1, mac2, "(") #)
macro = mac2[1]
prefix = substr(line, 1, index(line, defundef) - 1)
if (D_is_set[macro]) {
# Preserve the white space surrounding the "#".
print prefix "define", macro P[macro] D[macro]
next
} else {
# Replace #undef with comments. This is necessary, for example,
# in the case of _POSIX_SOURCE, which is predefined and required
# on some systems where configure will not decide to define it.
if (defundef == "undef") {
print "/*", prefix defundef, macro, "*/"
next
}
}
}
{ print }
_ACAWK
_ACEOF
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
as_fn_error $? "could not setup config headers machinery" "$LINENO" 5
fi # test -n "$CONFIG_HEADERS"
eval set X " :F $CONFIG_FILES :H $CONFIG_HEADERS "
shift
for ac_tag
do
case $ac_tag in
:[FHLC]) ac_mode=$ac_tag; continue;;
esac
case $ac_mode$ac_tag in
:[FHL]*:*);;
:L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;;
:[FH]-) ac_tag=-:-;;
:[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
esac
ac_save_IFS=$IFS
IFS=:
set x $ac_tag
IFS=$ac_save_IFS
shift
ac_file=$1
shift
case $ac_mode in
:L) ac_source=$1;;
:[FH])
ac_file_inputs=
for ac_f
do
case $ac_f in
-) ac_f="$ac_tmp/stdin";;
*) # Look for the file first in the build tree, then in the source tree
# (if the path is not absolute). The absolute path cannot be DOS-style,
# because $ac_f cannot contain `:'.
test -f "$ac_f" ||
case $ac_f in
[\\/$]*) false;;
*) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
esac ||
as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;;
esac
case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
as_fn_append ac_file_inputs " '$ac_f'"
done
# Let's still pretend it is `configure' which instantiates (i.e., don't
# use $as_me), people would be surprised to read:
# /* config.h. Generated by config.status. */
configure_input='Generated from '`
$as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'
`' by configure.'
if test x"$ac_file" != x-; then
configure_input="$ac_file. $configure_input"
{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5
$as_echo "$as_me: creating $ac_file" >&6;}
fi
# Neutralize special characters interpreted by sed in replacement strings.
case $configure_input in #(
*\&* | *\|* | *\\* )
ac_sed_conf_input=`$as_echo "$configure_input" |
sed 's/[\\\\&|]/\\\\&/g'`;; #(
*) ac_sed_conf_input=$configure_input;;
esac
case $ac_tag in
*:-:* | *:-) cat >"$ac_tmp/stdin" \
|| as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;;
esac
;;
esac
ac_dir=`$as_dirname -- "$ac_file" ||
$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
X"$ac_file" : 'X\(//\)[^/]' \| \
X"$ac_file" : 'X\(//\)$' \| \
X"$ac_file" : 'X\(/\)' \| . 2>/dev/null ||
$as_echo X"$ac_file" |
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
s//\1/
q
}
/^X\(\/\/\)[^/].*/{
s//\1/
q
}
/^X\(\/\/\)$/{
s//\1/
q
}
/^X\(\/\).*/{
s//\1/
q
}
s/.*/./; q'`
as_dir="$ac_dir"; as_fn_mkdir_p
ac_builddir=.
case "$ac_dir" in
.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
*)
ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
# A ".." for each directory in $ac_dir_suffix.
ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
case $ac_top_builddir_sub in
"") ac_top_builddir_sub=. ac_top_build_prefix= ;;
*) ac_top_build_prefix=$ac_top_builddir_sub/ ;;
esac ;;
esac
ac_abs_top_builddir=$ac_pwd
ac_abs_builddir=$ac_pwd$ac_dir_suffix
# for backward compatibility:
ac_top_builddir=$ac_top_build_prefix
case $srcdir in
.) # We are building in place.
ac_srcdir=.
ac_top_srcdir=$ac_top_builddir_sub
ac_abs_top_srcdir=$ac_pwd ;;
[\\/]* | ?:[\\/]* ) # Absolute name.
ac_srcdir=$srcdir$ac_dir_suffix;
ac_top_srcdir=$srcdir
ac_abs_top_srcdir=$srcdir ;;
*) # Relative name.
ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
ac_top_srcdir=$ac_top_build_prefix$srcdir
ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
esac
ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
case $ac_mode in
:F)
#
# CONFIG_FILE
#
case $INSTALL in
[\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;;
*) ac_INSTALL=$ac_top_build_prefix$INSTALL ;;
esac
_ACEOF
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# If the template does not know about datarootdir, expand it.
# FIXME: This hack should be removed a few years after 2.60.
ac_datarootdir_hack=; ac_datarootdir_seen=
ac_sed_dataroot='
/datarootdir/ {
p
q
}
/@datadir@/p
/@docdir@/p
/@infodir@/p
/@localedir@/p
/@mandir@/p'
case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in
*datarootdir*) ac_datarootdir_seen=yes;;
*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*)
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_datarootdir_hack='
s&@datadir@&$datadir&g
s&@docdir@&$docdir&g
s&@infodir@&$infodir&g
s&@localedir@&$localedir&g
s&@mandir@&$mandir&g
s&\\\${datarootdir}&$datarootdir&g' ;;
esac
_ACEOF
# Neutralize VPATH when `$srcdir' = `.'.
# Shell code in configure.ac might set extrasub.
# FIXME: do we really want to maintain this feature?
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_sed_extra="$ac_vpsub
$extrasub
_ACEOF
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
:t
/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
s|@configure_input@|$ac_sed_conf_input|;t t
s&@top_builddir@&$ac_top_builddir_sub&;t t
s&@top_build_prefix@&$ac_top_build_prefix&;t t
s&@srcdir@&$ac_srcdir&;t t
s&@abs_srcdir@&$ac_abs_srcdir&;t t
s&@top_srcdir@&$ac_top_srcdir&;t t
s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t
s&@builddir@&$ac_builddir&;t t
s&@abs_builddir@&$ac_abs_builddir&;t t
s&@abs_top_builddir@&$ac_abs_top_builddir&;t t
s&@INSTALL@&$ac_INSTALL&;t t
$ac_datarootdir_hack
"
eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \
>$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5
test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
{ ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } &&
{ ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \
"$ac_tmp/out"`; test -z "$ac_out"; } &&
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir'
which seems to be undefined. Please make sure it is defined" >&5
$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
which seems to be undefined. Please make sure it is defined" >&2;}
rm -f "$ac_tmp/stdin"
case $ac_file in
-) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";;
*) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";;
esac \
|| as_fn_error $? "could not create $ac_file" "$LINENO" 5
;;
:H)
#
# CONFIG_HEADER
#
if test x"$ac_file" != x-; then
{
$as_echo "/* $configure_input */" \
&& eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs"
} >"$ac_tmp/config.h" \
|| as_fn_error $? "could not create $ac_file" "$LINENO" 5
if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5
$as_echo "$as_me: $ac_file is unchanged" >&6;}
else
rm -f "$ac_file"
mv "$ac_tmp/config.h" "$ac_file" \
|| as_fn_error $? "could not create $ac_file" "$LINENO" 5
fi
else
$as_echo "/* $configure_input */" \
&& eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \
|| as_fn_error $? "could not create -" "$LINENO" 5
fi
;;
esac
done # for ac_tag
as_fn_exit 0
_ACEOF
ac_clean_files=$ac_clean_files_save
test $ac_write_fail = 0 ||
as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5
# configure is writing to config.log, and then calls config.status.
# config.status does its own redirection, appending to config.log.
# Unfortunately, on DOS this fails, as config.log is still kept open
# by configure, so config.status won't be able to write to it; its
# output is simply discarded. So we exec the FD to /dev/null,
# effectively closing config.log, so it can be properly (re)opened and
# appended to by config.status. When coming back to configure, we
# need to make the FD available again.
if test "$no_create" != yes; then
ac_cs_success=:
ac_config_status_args=
test "$silent" = yes &&
ac_config_status_args="$ac_config_status_args --quiet"
exec 5>/dev/null
$SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
exec 5>>config.log
# Use ||, not &&, to avoid exiting from the if with $? = 1, which
# would make configure fail if this is the last instruction.
$ac_cs_success || as_fn_exit 1
fi
if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
fi
perl subst $srcdir/include/locations.h
perl subst $srcdir/contrib/eventhandlers/submit_check_result
perl subst $srcdir/contrib/eventhandlers/disable_active_service_checks
perl subst $srcdir/contrib/eventhandlers/disable_notifications
perl subst $srcdir/contrib/eventhandlers/enable_active_service_checks
perl subst $srcdir/contrib/eventhandlers/enable_notifications
perl subst $srcdir/html/index.html
perl subst $srcdir/html/menu.html
perl subst $srcdir/html/js/autocomplete.js
echo ""
echo "Creating sample config files in sample-config/ ..."
perl subst $srcdir/sample-config/icinga.cfg
perl subst $srcdir/sample-config/cgi.cfg
perl subst $srcdir/sample-config/cgiauth.cfg
perl subst $srcdir/sample-config/resource.cfg
perl subst $srcdir/sample-config/httpd.conf
perl subst $srcdir/sample-config/mrtg.cfg
perl subst $srcdir/sample-config/template-object/templates.cfg
perl subst $srcdir/sample-config/template-object/commands.cfg
perl subst $srcdir/sample-config/template-object/timeperiods.cfg
perl subst $srcdir/sample-config/template-object/contacts.cfg
perl subst $srcdir/sample-config/template-object/notifications.cfg
perl subst $srcdir/sample-config/template-object/localhost.cfg
perl subst $srcdir/sample-config/template-object/windows.cfg
perl subst $srcdir/sample-config/template-object/printer.cfg
perl subst $srcdir/sample-config/template-object/switch.cfg
echo ""
echo "Creating sample config files in module/idoutils/config/ ..."
perl subst $srcdir/module/idoutils/config/idoutils.cfg-sample
perl subst $srcdir/module/idoutils/config/ido2db.cfg-sample
perl subst $srcdir/module/idoutils/config/idomod.cfg-sample
echo ""
echo ""
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: *** Configuration summary for $PKG_NAME $PKG_VERSION $PKG_REL_DATE ***:" >&5
$as_echo "*** Configuration summary for $PKG_NAME $PKG_VERSION $PKG_REL_DATE ***:" >&6; }
echo ""
echo " General Options:"
echo " -------------------------"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Icinga executable: $icinga_name" >&5
$as_echo " Icinga executable: $icinga_name" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Icinga user/group: $icinga_user,$icinga_grp" >&5
$as_echo " Icinga user/group: $icinga_user,$icinga_grp" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Command user/group: $command_user,$command_grp" >&5
$as_echo " Command user/group: $command_user,$command_grp" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Apache user/group: $web_user,$web_group" >&5
$as_echo " Apache user/group: $web_user,$web_group" >&6; }
if test x$ENABLE_DEBUG = xyes; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Debug Mode: yes" >&5
$as_echo " Debug Mode: yes" >&6; }
fi
if test x$USEPERL = xyes; then
if test x$PERLCACHE = xyes; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Embedded Perl: yes, with caching" >&5
$as_echo " Embedded Perl: yes, with caching" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Embedded Perl: yes, without caching" >&5
$as_echo " Embedded Perl: yes, without caching" >&6; }
fi
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Embedded Perl: no" >&5
$as_echo " Embedded Perl: no" >&6; }
fi
if test x$USE_EVENTBROKER = xyes; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Event Broker: yes" >&5
$as_echo " Event Broker: yes" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Event Broker: no" >&5
$as_echo " Event Broker: no" >&6; }
fi
if test x$ENABLE_PERFDATA = xyes; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Enable Performance Data: yes" >&5
$as_echo " Enable Performance Data: yes" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Enable Performance Data: no" >&5
$as_echo " Enable Performance Data: no" >&6; }
fi
if test x$USE_IDOUTILS = xyes; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ido2db lockfile: $IDO2DBLOCKFILE" >&5
$as_echo " ido2db lockfile: $IDO2DBLOCKFILE" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ido sockfile: $IDOSOCKFILE" >&5
$as_echo " ido sockfile: $IDOSOCKFILE" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: idomod tempfile: $IDOMODTMPFILE" >&5
$as_echo " idomod tempfile: $IDOMODTMPFILE" >&6; }
if test x$USE_IDOUTILS_ORACLE = xyes; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Build IDOUtils: ocilib, instance_name=$IDO_INSTANCE_NAME" >&5
$as_echo " Build IDOUtils: ocilib, instance_name=$IDO_INSTANCE_NAME" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Build IDOUtils: libdbi, instance_name=$IDO_INSTANCE_NAME" >&5
$as_echo " Build IDOUtils: libdbi, instance_name=$IDO_INSTANCE_NAME" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: libdbi driver dir: $LIBDBIDRIVERDIR" >&5
$as_echo " libdbi driver dir: $LIBDBIDRIVERDIR" >&6; }
fi
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Build IDOUtils: no" >&5
$as_echo " Build IDOUtils: no" >&6; }
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Install \${prefix}: $prefix" >&5
$as_echo " Install \${prefix}: $prefix" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Lock file: $lockfile" >&5
$as_echo " Lock file: $lockfile" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Temp file: $TMPFILE" >&5
$as_echo " Temp file: $TMPFILE" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Chk file: $ICINGACHKFILE" >&5
$as_echo " Chk file: $ICINGACHKFILE" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: HTTP auth file: $HTTPAUTHFILE" >&5
$as_echo " HTTP auth file: $HTTPAUTHFILE" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Lib directory: $libdir" >&5
$as_echo " Lib directory: $libdir" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Bin directory: $bindir" >&5
$as_echo " Bin directory: $bindir" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Plugin directory: $PLUGINDIR" >&5
$as_echo " Plugin directory: $PLUGINDIR" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Eventhandler directory: $EVENTHANDLERDIR" >&5
$as_echo " Eventhandler directory: $EVENTHANDLERDIR" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Log directory: $LOGDIR" >&5
$as_echo " Log directory: $LOGDIR" >&6; }
if test x$ENABLE_CGILOG = xyes; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: cgi log directory: $CGILOGDIR" >&5
$as_echo " cgi log directory: $CGILOGDIR" >&6; }
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Check result directory: $CHECKRESULTDIR" >&5
$as_echo " Check result directory: $CHECKRESULTDIR" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Temp directory: $TMPDIR" >&5
$as_echo " Temp directory: $TMPDIR" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: State directory: $STATEDIR" >&5
$as_echo " State directory: $STATEDIR" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Ext Cmd file directory: $EXTCMDFILEDIR" >&5
$as_echo " Ext Cmd file directory: $EXTCMDFILEDIR" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Init directory: $init_dir" >&5
$as_echo " Init directory: $init_dir" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Apache conf.d directory: $HTTPD_CONF" >&5
$as_echo " Apache conf.d directory: $HTTPD_CONF" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Apache config file: $HTTPDCONFFILE" >&5
$as_echo " Apache config file: $HTTPDCONFFILE" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Mail program: $MAIL_PROG" >&5
$as_echo " Mail program: $MAIL_PROG" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Host OS: $host_os" >&5
$as_echo " Host OS: $host_os" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Environment Prefix: $env_prefix" >&5
$as_echo " Environment Prefix: $env_prefix" >&6; }
echo ""
echo " Web Interface Options:"
echo " ------------------------"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: HTML URL: http://localhost$htmurl/" >&5
$as_echo " HTML URL: http://localhost$htmurl/" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: CGI URL: http://localhost$cgiurl/" >&5
$as_echo " CGI URL: http://localhost$cgiurl/" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Main URL: http://localhost$mainurl" >&5
$as_echo " Main URL: http://localhost$mainurl" >&6; }
echo ""
echo ""
echo "Review the options above for accuracy. If they look okay,"
echo "type 'make all' to compile the main program and CGIs."
echo ""
echo ""
echo "!!! Please take care about the upgrade documentation !!!"
echo ""
icinga-1.10.3/configure.in 0000664 0000000 0000000 00000144057 12276402000 0015343 0 ustar 00root root 0000000 0000000 dnl Process this -*-m4-*- file with autoconf to produce a configure script.
dnl Disable caching
define([AC_CACHE_LOAD],)
define([AC_CACHE_SAVE],)
AC_INIT(base/icinga.c)
AC_CONFIG_HEADER(include/config.h)
AC_PREFIX_DEFAULT(/usr/local/icinga)
PKG_NAME=icinga-core
PKG_VERSION="1.10.3"
PKG_HOME_URL="http://www.icinga.org/"
PKG_REL_DATE="02-11-2014"
dnl Figure out how to invoke "install" and what install options to use.
AC_PROG_INSTALL
AC_SUBST(INSTALL)
dnl What OS are we running?
AC_CANONICAL_HOST
dnl Checks for programs.
AC_PROG_CC
AC_PROG_MAKE_SET
AC_PATH_PROG([STRIP],[strip],[true])
dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_TIME
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(arpa/inet.h ctype.h dirent.h errno.h fcntl.h getopt.h grp.h libgen.h limits.h math.h netdb.h netinet/in.h pthread.h pthreads.h pwd.h regex.h signal.h socket.h stdarg.h string.h strings.h sys/mman.h sys/types.h sys/time.h sys/resource.h sys/wait.h sys/socket.h sys/stat.h sys/timeb.h sys/un.h sys/ipc.h sys/msg.h sys/poll.h syslog.h uio.h unistd.h sys/select.h)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_STRUCT_TM
AC_STRUCT_TIMEZONE
AC_TYPE_MODE_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_SIGNAL
AC_TYPE_GETGROUPS
dnl Check for asprintf() and friends...
AC_CACHE_CHECK([for va_copy],ac_cv_HAVE_VA_COPY,[
AC_TRY_LINK([#include
va_list ap1,ap2;], [va_copy(ap1,ap2);],
ac_cv_HAVE_VA_COPY=yes,
ac_cv_HAVE_VA_COPY=no)])
if test x"$ac_cv_HAVE_VA_COPY" = x"yes"; then
AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
else
AC_CACHE_CHECK([for __va_copy],ac_cv_HAVE___VA_COPY,[
AC_TRY_LINK([#include
va_list ap1,ap2;], [__va_copy(ap1,ap2);],
ac_cv_HAVE___VA_COPY=yes,
ac_cv_HAVE___VA_COPY=no)])
if test x"$ac_cv_HAVE___VA_COPY" = x"yes"; then
AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
fi
fi
dnl base/Makefile.in
AC_CHECK_FUNC(vsnprintf,,SNPRINTF_O=../common/snprintf.o)
AC_CHECK_FUNC(snprintf,,SNPRINTF_O=../common/snprintf.o)
AC_CHECK_FUNC(asprintf,,SNPRINTF_O=../common/snprintf.o)
AC_CHECK_FUNC(vasprintf,,SNPRINTF_O=../common/snprintf.o)
dnl module/idoutils/src/Makefile.in
AC_CHECK_FUNC(vsnprintf,,SNPRINTF_O_IDO=snprintf.o)
AC_CHECK_FUNC(snprintf,,SNPRINTF_O_IDO=snprintf.o)
AC_CHECK_FUNC(asprintf,,SNPRINTF_O_IDO=snprintf.o)
AC_CHECK_FUNC(vasprintf,,SNPRINTF_O_IDO=snprintf.o)
AC_CACHE_CHECK([for C99 vsnprintf],ac_cv_HAVE_C99_VSNPRINTF,[
AC_TRY_RUN([
#include
#include
void foo(const char *format, ...) {
va_list ap;
int len;
char buf[5];
va_start(ap, format);
len = vsnprintf(buf, 0, format, ap);
va_end(ap);
if (len != 5) exit(1);
va_start(ap, format);
len = vsnprintf(0, 0, format, ap);
va_end(ap);
if (len != 5) exit(1);
if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(1);
exit(0);
}
main() { foo("hello"); }
],
ac_cv_HAVE_C99_VSNPRINTF=yes,ac_cv_HAVE_C99_VSNPRINTF=no,ac_cv_HAVE_C99_VSNPRINTF=cross)])
if test x"$ac_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Define if system has C99 compatible vsnprintf])
fi
dnl AC_CHECK_FUNC(snprintf,AC_DEFINE(HAVE_SNPRINTF),SNPRINTF_O=../common/snprintf.o)
AC_SUBST(SNPRINTF_O)
AC_SUBST(SNPRINTF_O_IDO)
dnl Checks for library functions.
AC_SEARCH_LIBS([getservbyname],[nsl],
[if test "$ac_cv_search_getservbyname" != "none required"; then
SOCKETLIBS="$SOCKETLIBS -lnsl"
fi])
AC_SEARCH_LIBS([connect],[socket],
[if test "$ac_cv_search_connect" != "none required"; then
SOCKETLIBS="$SOCKETLIBS -lsocket"
fi])
AC_SUBST(SOCKETLIBS)
AC_CHECK_FUNCS(initgroups setenv strdup strstr strtoul unsetenv)
dnl Check for gethostbyname (requires libnsl on Solaris)
AC_SEARCH_LIBS([gethostbyname], [nsl],
[if test "$ac_cv_search_gethostbyname" != "none required"; then
SOCKETLIBS="$SOCKETLIBS -lnsl"
fi])
dnl Check for getopt_long (Solaris)
AC_CHECK_FUNCS([getopt_long],,AC_CHECK_LIB([iberty],[getopt_long],OTHERLIBS="$OTHERLIBS -liberty"))
AC_SUBST(OTHERLIBS)
AC_MSG_CHECKING(for type of socket size)
AC_TRY_COMPILE([#include
#include
#include
],
[int a = send(1, (const void *) 0, (size_t) 0, (int) 0);],
[AC_DEFINE(SOCKET_SIZE_TYPE, size_t, [typedef for socket size]) AC_MSG_RESULT(size_t)],
[AC_DEFINE(SOCKET_SIZE_TYPE, int, [typedef for socket size]) AC_MSG_RESULT(int)])
dnl Test for pthreads support - taken from ICU FreeBSD Port configure script
THREADLIBS=""
have_pthreads="no"
dnl FreeBSD: Try ports/linuxthreads first - Mammad Zadeh
dnl FreeBSD -pthread check - Jonathan McDowell
AC_DEFUN([AC_PTHREAD_FREEBSD],[
AC_CHECK_LIB(lthread,pthread_create,[
CFLAGS="-D_THREAD_SAFE -I/usr/local/include/pthread/linuxthreads -I/usr/include $CFLAGS"
THREADLIBS="-L/usr/local/lib -llthread -llgcc_r"
],[
AC_MSG_CHECKING([if we need -pthread for threads])
AC_CACHE_VAL(ac_cv_ldflag_pthread,[
ac_save_LDFLAGS="$LDFLAGS"
LDFLAGS="-pthread $LDFLAGS"
AC_TRY_LINK([
char pthread_create();
],
pthread_create();,
eval "ac_cv_ldflag_pthread=yes",
eval "ac_cv_ldflag_pthread=no"
),
THREADLIBS="$ac_save_LDFLAGS"
])
if eval "test \"`echo $ac_cv_ldflag_pthread`\" = yes"; then
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
fi
],-L/usr/local/lib)
])
dnl Test for HPUX cma threads first..
AC_CHECK_LIB(cma,pthread_create,THREADLIBS="$THREADLIBS -lpthread")
if test $ac_cv_lib_cma_pthread_create = yes; then
have_pthreads="yes"
fi
dnl special pthread handling
dnl AIX uses pthreads instead of pthread, and HP/UX uses cma
dnl FreeBSD users -pthread
AC_CHECK_LIB(pthread,pthread_create,THREADLIBS="$THREADLIBS -lpthread")
if test $ac_cv_lib_pthread_pthread_create = yes; then
have_pthreads="yes"
else
dnl For HP 11
AC_CHECK_LIB(pthread,pthread_mutex_init,THREADLIBS="$THREADLIBS -lpthread")
if test $ac_cv_lib_pthread_pthread_mutex_init = yes; then
have_pthreads="yes"
fi
fi
dnl AIX uses pthreads instead of pthread
if test $have_pthreads = "no"; then
AC_CHECK_LIB(pthreads,pthread_create,THREADLIBS="$THREADLIBS -lpthreads")
if test $ac_cv_lib_pthreads_pthread_create = yes; then
have_pthreads="yes"
fi
fi
dnl all other thread tests fail, try BSD's -pthread
if test $have_pthreads = "no"; then
AC_PTHREAD_FREEBSD
fi
AC_SUBST(THREADLIBS)
dnl Solaris needs rt or posix4 libraries for nanosleep()
AC_SEARCH_LIBS(nanosleep,[rt posix4],,[
echo "Error: nanosleep() needed for timing operations."
exit 1
])
AC_ARG_WITH(icinga_user,AC_HELP_STRING([--with-icinga-user=],[sets user name to run icinga]),icinga_user=$withval,icinga_user=icinga)
AC_ARG_WITH(icinga_group,AC_HELP_STRING([--with-icinga-group=],[sets group name to run icinga]),icinga_grp=$withval,icinga_grp=icinga)
AC_SUBST(icinga_user)
AC_SUBST(icinga_grp)
AC_DEFINE_UNQUOTED(DEFAULT_ICINGA_USER,"$icinga_user",[user name to run nagios])
AC_DEFINE_UNQUOTED(DEFAULT_NAGIOS_USER,"$icinga_user",[user name to run nagios])
AC_DEFINE_UNQUOTED(DEFAULT_ICINGA_GROUP,"$icinga_grp",[group name to run nagios])
AC_DEFINE_UNQUOTED(DEFAULT_NAGIOS_GROUP,"$icinga_grp",[group name to run nagios])
INSTALL_OPTS="-o $icinga_user -g $icinga_grp"
AC_SUBST(INSTALL_OPTS)
AC_ARG_WITH(command_user,AC_HELP_STRING([--with-command-user=],[sets user name for command access]),command_user=$withval,command_user=$icinga_user)
AC_ARG_WITH(command_group,AC_HELP_STRING([--with-command-group=] ,[sets group name for command access]),command_grp=$withval,command_grp=$icinga_grp)
AC_SUBST(command_user)
AC_SUBST(command_grp)
COMMAND_OPTS="-o $command_user -g $command_grp"
AC_SUBST(COMMAND_OPTS)
# Users for webfiles
AC_DEFUN([ACICINGA_USER_GUESS],[
$2=$3
for x in $1; do
AC_MSG_CHECKING([if user $x exists])
AS_IF([ $GREP -q "^$x:" /etc/passwd ],
[ AC_MSG_RESULT([found]); $2=$x ; break],
[ AC_MSG_RESULT([not found]) ])
done
])
AC_DEFUN([ACICINGA_GROUP_GUESS],[
$2=$3
for x in $1; do
AC_MSG_CHECKING([if group $x exists])
AS_IF([ $GREP -q "^$x:" /etc/group ],
[ AC_MSG_RESULT([found]); $2=$x ; break],
[ AC_MSG_RESULT([not found]) ])
done
])
AC_ARG_WITH([web_user],
AS_HELP_STRING([--with-web-user=USER], [username for web writable files (default www-data)]),
web_user=$withval,
ACICINGA_USER_GUESS([www wwwrun www-data apache httpd nobody],[web_user],[www-data])
)
AC_ARG_WITH([web_group],
AS_HELP_STRING([--with-web-group=GROUP], [group for web writable files (default www-data)]),
web_group=$withval,
ACICINGA_GROUP_GUESS([www www-data apache httpd nogroup nobody],[web_group], [www-data])
)
AC_SUBST(web_user)
AC_SUBST(web_group)
INSTALL_OPTS_WEB="-o $web_user -g $web_group"
AC_SUBST(INSTALL_OPTS_WEB)
dnl Check for location of mail program
MAIL_PROG=no
AC_ARG_WITH(mail,AC_HELP_STRING([--with-mail=],[sets path to equivalent program to mail]),MAIL_PROG=$withval,MAIL_PROG=no)
if test x$MAIL_PROG = xno; then
AC_PATH_PROG(MAIL_PROG,mail)
fi
dnl Fix for systems that don't (yet) have mail/mailx installed...
if test x$MAIL_PROG = x; then
MAIL_PROG="/bin/mail"
fi
AC_SUBST(MAIL_PROG)
dnl Check for location of Apache conf.d directory
HTTPD_CONF=no
APACHE24_DEBIAN=no
AC_ARG_WITH(httpd_conf,AC_HELP_STRING([--with-httpd-conf=],[sets path to Apache conf.d directory]),HTTPD_CONF=$withval,HTTPD_CONF=no)
if test x$HTTPD_CONF = xno; then
if test -d /etc/httpd/conf.d; then
HTTPD_CONF="/etc/httpd/conf.d"
elif test -d /etc/apache2/conf-available; then
dnl debian apache 2.4
HTTPD_CONF="/etc/apache2/conf-available"
APACHE24_DEBIAN=yes
elif test -d /etc/apache2/conf.d; then
HTTPD_CONF="/etc/apache2/conf.d"
elif test -d /etc/apache/conf.d; then
HTTPD_CONF="/etc/apache/conf.d"
else
HTTPD_CONF="/etc/httpd/conf.d"
fi
fi
AC_SUBST(HTTPD_CONF)
AC_SUBST(APACHE24_DEBIAN)
dnl Location of check result path
CHECKRESULTDIR=no
AC_ARG_WITH(checkresult-dir,AC_HELP_STRING([--with-checkresult-dir=],[sets path to check results spool directory]),CHECKRESULTDIR=$withval,CHECKRESULTDIR=no)
if test x$CHECKRESULTDIR = xno; then
CHECKRESULTDIR="$localstatedir/spool/checkresults"
fi
AC_SUBST(CHECKRESULTDIR)
dnl Location of temp path
TMPDIR=no
AC_ARG_WITH(temp-dir,AC_HELP_STRING([--with-temp-dir=],[sets path to temp directory path where Icinga can create temp files for service/host check results]),TMPDIR=$withval,TMPDIR=no)
if test x$TMPDIR = xno; then
TMPDIR="/tmp"
fi
AC_SUBST(TMPDIR)
dnl Location of temp file
TMPFILE=no
AC_ARG_WITH(temp-file,AC_HELP_STRING([--with-temp-file=],[sets path to an Icinga exclusive update temp file i.e. /tmp/icinga.tmp]),TMPFILE=$withval,TMPFILE=no)
if test x$TMPFILE = xno; then
TMPFILE="/tmp/icinga.tmp"
fi
AC_SUBST(TMPFILE)
dnl Location of state dir
STATEDIR=no
AC_ARG_WITH(state-dir,AC_HELP_STRING([--with-state-dir=],[sets path to custom localstate dir e.g. /var/spool/icinga]),STATEDIR=$withval,STATEDIR=no)
if test x$STATEDIR = xno; then
STATEDIR="$localstatedir"
fi
AC_SUBST(STATEDIR)
dnl Location of http auth file
HTTPAUTHFILE=no
AC_ARG_WITH(http-auth-file,AC_HELP_STRING([--with-http-auth-file=],[sets path to an Icinga HTTP auth file]),HTTPAUTHFILE=$withval,HTTPAUTHFILE=no)
if test x$HTTPAUTHFILE = xno; then
HTTPAUTHFILE="$sysconfdir/htpasswd.users"
fi
AC_SUBST(HTTPAUTHFILE)
dnl Location of apache conf file
HTTPDCONFFILE=no
AC_ARG_WITH(httpd-conf-file,AC_HELP_STRING([--with-httpd-conf-file=],[sets path to Icinga HTTPD config file]),HTTPDCONFFILE=$withval,HTTPDCONFFILE=no)
if test x$HTTPDCONFFILE = xno; then
HTTPDCONFFILE="$HTTPD_CONF/icinga.conf"
fi
AC_SUBST(HTTPDCONFFILE)
dnl Location of plugin path
PLUGINDIR=no
AC_ARG_WITH(plugin-dir,AC_HELP_STRING([--with-plugin-dir=],[sets path to plugins directory path i.e. $prefix/libexec]),PLUGINDIR=$withval,PLUGINDIR=no)
if test x$PLUGINDIR = xno; then
PLUGINDIR="$libexecdir"
fi
AC_SUBST(PLUGINDIR)
dnl Location of eventhandler path
EVENTHANDLERDIR=no
AC_ARG_WITH(eventhandler-dir,AC_HELP_STRING([--with-eventhandler-dir=],[sets path to eventhandlers directory path i.e. $prefix/libexec/eventhandlers]),EVENTHANDLERDIR=$withval,EVENTHANDLERDIR=no)
if test x$EVENTHANDLERDIR = xno; then
EVENTHANDLERDIR="$libexecdir/eventhandlers"
fi
AC_SUBST(EVENTHANDLERDIR)
dnl enable perfdata
ENABLE_PERFDATA=no
AC_ARG_ENABLE(perfdata,AC_HELP_STRING([--enable-perfdata],[enables perfdata in icinga.cfg]),[
if test x$enableval = xyes; then
ENABLE_PERFDATA=yes
fi
],ENABLE_PERFDATA=no)
if test x$ENABLE_PERFDATA = xyes; then
ENABLEPERFDATA=1
else
ENABLEPERFDATA=0
fi
AC_SUBST(ENABLEPERFDATA)
dnl ################
dnl LOG DIRS
dnl ################
dnl Location of logging path
LOGDIR=no
AC_ARG_WITH(log-dir,AC_HELP_STRING([--with-log-dir=],[sets path to logging directory]),LOGDIR=$withval,LOGDIR=no)
if test x$LOGDIR = xno; then
LOGDIR="$localstatedir"
fi
AC_SUBST(LOGDIR)
dnl Enable cgi logging
ENABLE_CGILOG=no
AC_ARG_ENABLE(cgi-log,AC_HELP_STRING([--enable-cgi-log],[enables cgi logging - experimental!!]),[
if test x$enableval = xyes; then
ENABLE_CGILOG=yes
fi
],ENABLE_CGILOG=no)
if test x$ENABLE_CGILOG = xyes; then
ENABLECGILOG=1
else
ENABLECGILOG=0
fi
AC_SUBST(ENABLECGILOG)
dnl Location of cgi logging path
CGILOGDIR=no
AC_ARG_WITH(cgi-log-dir,AC_HELP_STRING([--with-cgi-log-dir=],[sets path to cgi logging directory]),CGILOGDIR=$withval,CGILOGDIR=no)
if test x$CGILOGDIR = xno; then
CGILOGDIR="$datarootdir/log"
fi
AC_SUBST(CGILOGDIR)
dnl ################
dnl OTHER DIRS
dnl ################
dnl Location of the external command file path
EXTCMDFILEDIR=no
PHPAPIEXTCMDDIR=no
AC_ARG_WITH(ext-cmd-file-dir,AC_HELP_STRING([--with-ext-cmd-file-dir=],[sets path to external command file directory]),EXTCMDFILEDIR=$withval,EXTCMDFILEDIR=no)
if test x$EXTCMDFILEDIR = xno; then
EXTCMDFILEDIR="$localstatedir/rw"
fi
PHPAPIEXTCMDDIR="$EXTCMDFILEDIR"
AC_SUBST(EXTCMDFILEDIR)
AC_SUBST(PHPAPIEXTCMDDIR)
dnl Location of the embedded perl p1.pl
P1FILELOC=no
AC_ARG_WITH(p1-file-dir,AC_HELP_STRING([--with-p1-file-dir=],[sets path to embedded perl p1.pl directory]),P1FILELOC=$withval,P1FILELOC=no)
if test x$P1FILELOC = xno; then
P1FILELOC="$libdir"
fi
AC_SUBST(P1FILELOC)
dnl Check for location of init scripts
init_dir=/etc/rc.d/init.d
if test -d /etc/rc.d/init.d; then
init_dir="/etc/rc.d/init.d"
elif test -d /usr/local/etc/rc.d; then
init_dir="/usr/local/etc/rc.d"
elif test -d /etc/rc.d; then
init_dir="/etc/rc.d"
elif test -d /etc/init.d; then
init_dir="/etc/init.d"
elif test -d /sbin/init.d; then
init_dir="/sbin/init.d"
fi
dnl User can override init script location
AC_ARG_WITH(init_dir,AC_HELP_STRING([--with-init-dir=],[sets directory to place init script into]),init_dir=$withval)
AC_SUBST(init_dir)
dnl Check for location of systemd unit files
systemd_unit_dir=/usr/lib/systemd/system
if test -d /usr/lib/systemd/system; then
systemd_unit_dir=/usr/lib/systemd/system
elif test -d /lib/systemd/system; then
systemd_unit_dir=/lib/systemd/system
fi
systemd_sysconfig_dir=/etc/sysconfig
dnl User can override unit file directory location
AC_ARG_WITH(systemd_unit_dir,AC_HELP_STRING([--with-systemd-unitdir=],[sets directory to place systemd service file into]),systemd_unit_dir=$withval)
AC_SUBST(systemd_unit_dir)
dnl User can override sysconfig file directory location
AC_ARG_WITH(systemd_sysconfig_dir,AC_HELP_STRING([--with-systemd-sysconfigdir=],[sets directory to place systemd service configuration file]),systemd_sysconfig_dir=$withval)
AC_SUBST(systemd_sysconfig_dir)
dnl User can override lock file location
AC_ARG_WITH(lockfile,AC_HELP_STRING([--with-lockfile=],[sets path and file name for lock file]),lockfile=$withval,lockfile=$localstatedir/icinga.lock)
AC_SUBST(lockfile)
dnl Location of icinga.chk (error log on initscript)
ICINGACHKFILE=no
AC_ARG_WITH(icinga-chkfile,AC_HELP_STRING([--with-icinga-chkfile=],[sets path and file name for icinga initscript error file]),ICINGACHKFILE=$withval,ICINGACHKFILE=no)
if test x$ICINGACHKFILE = xno; then
ICINGACHKFILE="$localstatedir/icinga.chk"
fi
AC_SUBST(ICINGACHKFILE)
dnl Location of ido2db.lock
IDO2DBLOCKFILE=no
AC_ARG_WITH(ido2db-lockfile,AC_HELP_STRING([--with-ido2db-lockfile=],[sets path and file name for ido2db lock file]),IDO2DBLOCKFILE=$withval,IDO2DBLOCKFILE=no)
if test x$IDO2DBLOCKFILE = xno; then
IDO2DBLOCKFILE="$localstatedir/ido2db.lock"
fi
AC_SUBST(IDO2DBLOCKFILE)
dnl Location of ido.sock
IDOSOCKFILE=no
AC_ARG_WITH(ido-sockfile,AC_HELP_STRING([--with-ido-sockfile=],[sets path and file name for ido sock file]),IDOSOCKFILE=$withval,IDOSOCKFILE=no)
if test x$IDOSOCKFILE = xno; then
IDOSOCKFILE="$localstatedir/ido.sock"
fi
AC_SUBST(IDOSOCKFILE)
dnl Location of idomod.tmp
IDOMODTMPFILE=no
AC_ARG_WITH(idomod-tmpfile,AC_HELP_STRING([--with-idomod-tmpfile=],[sets path and file name for idomod tmp file]),IDOMODTMPFILE=$withval,IDOMODTMPFILE=no)
if test x$IDOMODTMPFILE = xno; then
IDOMODTMPFILE="$localstatedir/idomod.tmp"
fi
AC_SUBST(IDOMODTMPFILE)
dnl Default xdata routines...
XSDTYPE=default
XCDTYPE=default
XRDTYPE=default
XODTYPE=template
XPDTYPE=default
XDDTYPE=default
XSDCOMMENT=
XCDCOMMENT=
XRDCOMMENT=
XODCOMMENT=
XPDCOMMENT=
XDDCOMMENT=
USE_MYSQL=no
USE_PGSQL=no
dnl Status data
AC_DEFINE_UNQUOTED(USE_XSDDEFAULT,,[use default routines (in xdata/xsddefault.*) for status data I/O...])
XSDC="xsddefault.c"
XSDH="xsddefault.h"
XSDCOMMENT="Default (text file)"
echo "We'll use default routines (in xdata/xsddefault.*) for status data I/O..."
AC_SUBST(XSDC)
AC_SUBST(XSDH)
dnl Comment data
AC_DEFINE_UNQUOTED(USE_XCDDEFAULT,,[use default routines (in xdata/xcddefault.*) for comment data I/O...])
XCDC="xcddefault.c"
XCDH="xcddefault.h"
XCDCOMMENT="Default (text file)"
echo "We'll use default routines (in xdata/xcddefault.*) for comment data I/O..."
AC_SUBST(XCDC)
AC_SUBST(XCDH)
dnl Retention data
AC_DEFINE_UNQUOTED(USE_XRDDEFAULT,,[use default routines (in xdata/xrddefault.*) for retention data I/O...])
XRDC="xrddefault.c"
XRDH="xrddefault.h"
XRDCOMMENT="Default (text file)"
echo "We'll use default routines (in xdata/xrddefault.*) for retention data I/O..."
AC_SUBST(XRDC)
AC_SUBST(XRDH)
dnl Object data
AC_DEFINE_UNQUOTED(USE_XODTEMPLATE,,[use template-based routines (in xdata/xodtemplate.*) for object data I/O...])
XODC="xodtemplate.c"
XODH="xodtemplate.h"
XODCOMMENT="Template-based (text file)"
echo "We'll use template-based routines (in xdata/xodtemplate.*) for object data I/O..."
AC_SUBST(XODC)
AC_SUBST(XODH)
dnl Performance data
AC_DEFINE_UNQUOTED(USE_XPDDEFAULT,,[use default routines (in xdata/xpddefault.*) for performance data I/O...])
XPDC="xpddefault.c"
XPDH="xpddefault.h"
XPDCOMMENT="Default (external commands)"
echo "We'll use default routines (in xdata/xpddefault.*) for performance data I/O..."
AC_SUBST(XPDC)
AC_SUBST(XPDH)
dnl Downtime data
AC_DEFINE_UNQUOTED(USE_XDDDEFAULT,,[use default routines (in xdata/xdddefault.*) for scheduled downtime data I/O...])
XDDC="xdddefault.c"
XDDH="xdddefault.h"
XDDCOMMENT="Default (text file)"
echo "We'll use default routines (in xdata/xdddefault.*) for scheduled downtime data I/O..."
AC_SUBST(XDDC)
AC_SUBST(XDDH)
dnl Optional GD library and include paths
AC_ARG_WITH(gd-lib,AC_HELP_STRING([--with-gd-lib=DIR],[sets location of the gd library]),[
LDFLAGS="${LDFLAGS} -L${withval}"
LD_RUN_PATH="${withval}${LD_RUN_PATH:+:}${LD_RUN_PATH}"
])
AC_ARG_WITH(gd-inc,AC_HELP_STRING([--with-gd-inc=DIR],[sets location of the gd include files]),[
CFLAGS="${CFLAGS} -I${withval}"
])
TRYGD=yep
dnl statusmap CGI enabled by default, unless users chooses not to use it
TRYSTATUSMAP=yep
AC_ARG_ENABLE(statusmap, AC_HELP_STRING([--disable-statusmap], [disables compilation of statusmap CGI]),TRYSTATUSMAP=nope)
dnl JMD_CHECK_LIB_ORDER(LIBRARY, FUNCTION, ORDER [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND
dnl [, OTHER-LIBRARIES]]])
AC_DEFUN([JMD_CHECK_LIB_ORDER],
[AC_MSG_CHECKING([for $2 in -l$1 (order $3)])
dnl Use a cache variable name containing both the library and function name,
dnl because the test really is for library $1 defining function $2, not
dnl just for library $1. Separate tests with the same $1 and different $2s
dnl may have different results.
ac_lib_var=`echo $1['_']$2['_']$3 | sed 'y%./+-%__p_%'`
AC_CACHE_VAL(ac_cv_lib_$ac_lib_var,
[ac_save_LIBS="$LIBS"
LIBS="-l$1 $6 $LIBS"
AC_TRY_LINK(dnl
ifelse([AC_LANG], [FORTRAN77], ,
ifelse([$2], [main], , dnl Avoid conflicting decl of main.
[/* Override any gcc2 internal prototype to avoid an error. */
]ifelse([AC_LANG], CPLUSPLUS, [#ifdef __cplusplus
extern "C"
#endif
])dnl
[/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char $2();
])),
[$2()],
eval "ac_cv_lib_$ac_lib_var=yes",
eval "ac_cv_lib_$ac_lib_var=no")
LIBS="$ac_save_LIBS"
])dnl
if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
AC_MSG_RESULT(yes)
ifelse([$4], ,
[changequote(, )dnl
ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
-e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
changequote([, ])dnl
AC_DEFINE_UNQUOTED($ac_tr_lib)
LIBS="-l$1 $LIBS"
], [$4])
else
AC_MSG_RESULT(no)
ifelse([$5], , , [$5
])dnl
fi
])
dnl Should we try and detect the GD libs?
if test x$TRYGD = xyep; then
dnl libiconv is required on some systems - tack it on if found
AC_CHECK_LIB(iconv,main,ICONV=-liconv,)
dnl See if the GD lib is available and supports PNG images...
dnl GD > 1.8.3 requires the TrueType library to be present as well, so test for that first...
JMD_CHECK_LIB_ORDER(gd,gdImagePng,1,[
GDLIBFOUND=yep
GDLIBS="-lgd -lttf -lpng -ljpeg -lz -lm"
],:,[-lttf -lpng -ljpeg -lz -lm])
dnl GD > 1.8.1 requires the jpeg library to be present as well, so test for that...
if test x$GDLIBFOUND = x; then
JMD_CHECK_LIB_ORDER(gd,gdImagePng,2,[
GDLIBFOUND=yep
GDLIBS="-lgd $ICONV -lpng -ljpeg -lz -lm"
],:,[$ICONV -lpng -ljpeg -lz -lm])
fi
dnl If we failed the first test, try without jpeg library
if test x$GDLIBFOUND = x; then
JMD_CHECK_LIB_ORDER(gd,gdImagePng,3,[
GDLIBFOUND=yep
GDLIBS="-lgd $ICONV -lz -lm -lpng"
],:,[$ICONV -lz -lm -lpng])
fi
dnl We failed again, so try a different library ordering (without jpeg libs)
if test x$GDLIBFOUND = x; then
JMD_CHECK_LIB_ORDER(gd,gdImagePng,4,[
GDLIBFOUND=yep
GDLIBS="-lgd $ICONV -lpng -lz -lm"
],:,[$ICONV -lpng -lz -lm])
fi
dnl Did we find the necessary GD libraries?
if test x$GDLIBFOUND = x; then
echo ""
echo ""
echo "*** GD, PNG, and/or JPEG libraries could not be located... *********"
echo ""
echo "Boutell's GD library is required to compile the statusmap, trends"
echo "and histogram CGIs. Get it from http://www.boutell.com/gd/, compile"
echo "it, and use the --with-gd-lib and --with-gd-inc arguments to specify"
echo "the locations of the GD library and include files."
echo ""
echo "NOTE: In addition to the gd-devel library, you'll also need to make"
echo " sure you have the png-devel and jpeg-devel libraries installed"
echo " on your system."
echo ""
echo "NOTE: After you install the necessary libraries on your system:"
echo " 1. Make sure /etc/ld.so.conf has an entry for the directory in"
echo " which the GD, PNG, and JPEG libraries are installed."
echo " 2. Run 'ldconfig' to update the run-time linker options."
echo " 3. Run 'make clean' in the Icinga distribution to clean out"
echo " any old references to your previous compile."
echo " 4. Rerun the configure script."
echo ""
echo "NOTE: If you can't get the configure script to recognize the GD libs"
echo " on your system, get over it and move on to other things. The"
echo " CGIs that use the GD libs are just a small part of the entire"
echo " Icinga package. Get everything else working first and then"
echo " revisit the problem. Make sure to check the icinga-users"
echo " mailing list archives for possible solutions to GD library"
echo " problems when you resume your troubleshooting."
echo ""
echo "********************************************************************"
echo ""
echo ""
dnl We found the GD lib!
else
echo "GD library was found!"
if test x$TRYSTATUSMAP = xyep; then
AC_DEFINE_UNQUOTED(USE_STATUSMAP,,[defined if the user chose to include status map])
CGIEXTRAS="$CGIEXTRAS statusmap.cgi"
AC_CHECK_LIB(gd,gdImageCreateTrueColor,
AC_DEFINE(HAVE_GDIMAGECREATETRUECOLOR,1,
[Define if your gd library has gdImageCreateTrueColor]))
fi
dnl compile trends CGI
AC_DEFINE_UNQUOTED(USE_TRENDS,,[compile trends CGI])
CGIEXTRAS="$CGIEXTRAS trends.cgi"
dnl compile histogram CGI
AC_DEFINE_UNQUOTED(USE_HISTOGRAM,,[compile histogram CGI])
CGIEXTRAS="$CGIEXTRAS histogram.cgi"
fi
fi
ENABLE_DEBUG=no
AC_ARG_ENABLE(debug,AC_HELP_STRING([--enable-debug],[enables debug mode]),ENABLE_DEBUG=$enableval,ENABLE_DEBUG=no)
if test x$ENABLE_DEBUG = xyes; then
AC_DEFINE_UNQUOTED(ENABLE_DEBUG,,[enables debug mode])
fi
AC_ARG_WITH(cgiurl,AC_HELP_STRING([--with-cgiurl=],[sets URL for cgi programs (do not use a trailing slash)]),cgiurl=$withval,cgiurl=/icinga/cgi-bin)
AC_SUBST(cgiurl)
AC_ARG_WITH(htmurl,AC_HELP_STRING([--with-htmurl=],[sets URL for public html]),htmurl=$withval,htmurl=/icinga)
AC_SUBST(htmurl)
AC_ARG_WITH(mainurl,AC_HELP_STRING([--with-mainurl=],[sets URL for default main frame in index.html (use quotes if special chars like & used)]),mainurl=$withval,mainurl=$cgiurl/tac.cgi)
AC_SUBST(mainurl)
USE_NANOSLEEP=yes
AC_ARG_ENABLE(nanosleep,AC_HELP_STRING([--enable-nanosleep],[enables use of nanosleep (instead sleep) in event timing]),USE_NANOSLEEP=$enableval,USE_NANOSLEEP=yes)
if test x$USE_NANOSLEEP = xyes; then
AC_DEFINE_UNQUOTED(USE_NANOSLEEP,,[enables use of nanosleep (instead of sleep)])
fi
USE_EVENTBROKER=yes
AC_ARG_ENABLE(event-broker,AC_HELP_STRING([--enable-event-broker],[enables integration of event broker routines]),USE_EVENTBROKER=$enableval,USE_EVENTBROKER=yes)
BROKER_LDFLAGS=""
BROKERLIBS="";
some_dl_found="no";
if test x$USE_EVENTBROKER = xyes; then
dnl Which loader library should we use? libtdl or dl?
dnl Hopefully this will be portable and not give us headaches...
AC_CHECK_HEADER(ltdl.h,[
AC_CHECK_LIB(ltdl,lt_dlinit,[
AC_DEFINE(HAVE_LTDL_H,,[Which loader library should we use? libtdl or dl?])
some_dl_found="yes"
BROKERLIBS="$BROKERLIBS -lltdl"
])
])
if test "x$some_dl_found" != xyes; then
AC_CHECK_HEADER(dlfcn.h,[
AC_CHECK_LIB(dl,dlopen,[
AC_DEFINE(HAVE_DLFCN_H,,[Which loader library should we use? libtdl or dl?])
some_dl_found="yes"
BROKERLIBS="$BROKERLIBS -ldl"
])
])
fi
dnl - Modified from www.erlang.org
# Check how to export functions from the broker executable, needed
# when dynamically loaded drivers are loaded (so that they can find
# broker functions).
# OS'es with ELF executables using the GNU linker (Linux and recent *BSD,
# in rare cases Solaris) typically need '-Wl,-export-dynamic' (i.e. pass
# -export-dynamic to the linker - also known as -rdynamic and some other
# variants); some sysVr4 system(s) instead need(s) '-Wl,-Bexport'.
# AIX 4.x (perhaps only for x>=2) wants -Wl,-bexpall,-brtl and doesn't
# reliably return an error for others, thus we separate it out.
# Otherwise we assume that if the linker accepts the flag, it is needed.
AC_MSG_CHECKING(for extra flags needed to export symbols)
case $host_os in
aix4*|aix5*|aix6*|aix7*)
BROKER_LDFLAGS="$BROKER_LDFLAGS -Wl,-bexpall,-brtl"
;;
bsdi*)
BROKER_LDFLAGS="$BROKER_LDFLAGS -rdynamic"
;;
*)
save_ldflags="$LDFLAGS"
LDFLAGS=-Wl,-export-dynamic
AC_TRY_LINK(,,[BROKER_LDFLAGS="$BROKER_LDFLAGS -Wl,-export-dynamic"], [
LDFLAGS=-Wl,-Bexport
AC_TRY_LINK(,,[BROKER_LDFLAGS="$BROKER_LDFLAGS -Wl,-Bexport"],
AC_MSG_RESULT(none))])
LDFLAGS="$save_ldflags"
;;
esac
AC_SUBST(BROKER_LDFLAGS)
AC_SUBST(BROKERLIBS)
test "x$BROKER_LDFLAGS" != x && AC_MSG_RESULT([$BROKER_LDFLAGS])
dnl - Modified version from www.erlang.org
dnl - Some 12/15/05 mods made after reading http://xaxxon.slackworks.com/phuku/dl.html
AC_MSG_CHECKING(for linker flags for loadable modules)
case $host_os in
solaris2*|sysv4*)
MOD_LDFLAGS="-G -fPIC"
MOD_CFLAGS="-fPIC"
INIT_OPTS="-o root -g root"
SNPRINTF_BROKEN="yes"
;;
aix4*|aix5*|aix6*|aix7*)
#MOD_LDFLAGS="-G -bnoentry -bexpall"
MOD_LDFLAGS="-G -bM:SRE -bnoentry -bexpall"
INIT_OPTS="-o root -g root"
;;
freebsd2*)
# Non-ELF GNU linker
MOD_LDFLAGS="-Bshareable"
INIT_OPTS="-o root -g wheel"
;;
darwin*)
# Mach-O linker, a shared lib and a loadable
# object file is not the same thing.
MOD_LDFLAGS="-bundle -flat_namespace -undefined suppress"
MOD_CFLAGS="$MOD_CFLAGS -fno-common"
INIT_OPTS="-o root -g root"
;;
linux* | k*bsd*-gnu*)
# assume GNU linker and ELF
MOD_LDFLAGS="-shared"
MOD_CFLAGS="-fPIC"
INIT_OPTS="-o root -g root"
;;
freebsd*)
MOD_LDFLAGS="-shared"
MOD_CFLAGS="-fPIC"
INIT_OPTS="-o root -g wheel"
;;
*)
# assume GNU linker and ELF
MOD_LDFLAGS="-shared"
INIT_OPTS="-o root -g root"
;;
esac
AC_MSG_RESULT([$MOD_LDFLAGS])
AC_SUBST(MOD_CFLAGS)
AC_SUBST(MOD_LDFLAGS)
AC_DEFINE_UNQUOTED(USE_EVENT_BROKER,,[defined to bring in the event broker objects])
BROKER_O="broker.o nebmods.o"
AC_SUBST(BROKER_O)
BROKER_H="../include/broker.h ../include/nebmods.h ../include/nebmodules.h ../include/nebcallbacks.h ../include/neberrors.h"
AC_SUBST(BROKER_H)
fi
dnl workaround for broken printf implementations (like solaris)
if test x$SNPRINTF_BROKEN = xyes; then
AC_DEFINE(SNPRINTF_BROKEN,"1")
SNPRINTF_O=../common/snprintf.o
SNPRINTF_O_IDO=snprintf.o
AC_SUBST(SNPRINTF_O)
AC_SUBST(SNPRINTF_O_IDO)
fi
dnl Classic UI Standalone
CLASSICUI_STANDALONE=no
AC_ARG_ENABLE(classicui-standalone,AC_HELP_STRING([--enable-classicui-standalone],[enables standalone Classic UI (default: disabled)]),CLASSICUI_STANDALONE=$enableval,CLASSICUI_STANDALONE=no)
if test x$CLASSICUI_STANDALONE = xyes; then
CLASSICUI_STANDALONE_FLAG="1"
fi
if test x$CLASSICUI_STANDALONE = xno; then
CLASSICUI_STANDALONE_FLAG="0"
fi
AC_SUBST(CLASSICUI_STANDALONE_FLAG)
if test x$CLASSICUI_STANDALONE = xno; then
dnl Configure IDOUtils
dnl set dummy for ocilib
OCILIB_LIB=""
USE_IDOUTILS=yes
USE_IDOUTILS_ORACLE=no
AC_ARG_ENABLE(idoutils,AC_HELP_STRING([--enable-idoutils],[enables database connectivity using idoutils (default: enabled)]),USE_IDOUTILS=$enableval,USE_IDOUTILS=yes)
if test x$USE_IDOUTILS = xyes; then
if test x$USE_EVENTBROKER = xno; then
AC_MSG_ERROR([--enable-idoutils needs also --enable-event-broker])
fi
dnl instance name
IDO_INSTANCE_NAME=no
AC_ARG_WITH(ido-instance-name,AC_HELP_STRING([--with-ido-instance-name=],[sets instance_name for IDOUtils in idomod.cfg]),IDO_INSTANCE_NAME=$withval,IDO_INSTANCE_NAME=no)
if test x$IDO_INSTANCE_NAME = xno; then
IDO_INSTANCE_NAME="default"
fi
AC_SUBST(IDO_INSTANCE_NAME)
dnl check if oracle enabled, then require ocilib
dnl check if pgsql enabled, then require libpq
dnl else require libpq
dnl ocilib is to be expected in /usr/local/lib and /usr/local/include
dnl libpq is to be expected in /usr/lib and /usr/include check with $ pg_config --libdir|--includedir
dnl libdbi is to be expected in /usr/lib and /usr/include
dnl Check for optional ocilib
USE_OCILIB=no
USE_LIBPQ=no
AC_ARG_ENABLE(oracle,AC_HELP_STRING([--enable-oracle],[enables idoutils with ocilib and oracle]),USE_OCILIB=$enableval,USE_OCILIB=no)
AC_ARG_ENABLE(pgsql,AC_HELP_STRING([--enable-pgsql],[!use libdbis pgsql support instead, libpq not yet implemented! enables idoutils with libpq and pgsql]),USE_LIBPQ=$enableval,USE_LIBPQ=no)
if test x$USE_OCILIB = xyes; then
dnl set marker for output
USE_IDOUTILS_ORACLE=yes
OCILIB_INC="/usr/local/include"
OCILIB_LIB="/usr/local/lib"
dnl Optional ocilib library and include paths
AC_ARG_WITH(ocilib-lib,AC_HELP_STRING([--with-ocilib-lib=DIR],[sets location of the ocilib library]),[
OCILIB_LIB="${withval}"
])
AC_ARG_WITH(ocilib-inc,AC_HELP_STRING([--with-ocilib-inc=DIR],[sets location of the ocilib include files,]),[
OCILIB_INC="${withval}"
])
ORACLE_LIB=""
AC_ARG_WITH(oracle-lib,AC_HELP_STRING([--with-oracle-lib=DIR],[sets location of the oracle library]),[
ORACLE_LIB="${withval}"
])
if test "$ORACLE_LIB" = ""; then
IDO2DB_RUNTIME="$OCILIB_LIB"
else
IDO2DB_RUNTIME="$OCILIB_LIB:$ORACLE_LIB"
fi
CFLAGS="$CFLAGS -I$OCILIB_INC -DOCI_IMPORT_RUNTIME -DOCI_CHARSET_ANSI"
LDFLAGS="$LDFLAGS -L$OCILIB_LIB"
dnl check and include ocilib.h
AC_CHECK_HEADERS(ocilib.h)
dnl check and include ocilib library, at runtime
AC_DEFINE(HAVE_OCILIB_H,"1")
dnl check libs
AC_MSG_CHECKING(for ocilib)
AC_CHECK_LIB([ocilib], [main],DBLIBS_OCI="${DBCFLAGS} -locilib" , [AC_MSG_ERROR([ERROR - We really need a ocilib to link against])] )
DBLIBS="${DBLIBS} ${DBLIBS_OCI}"
AC_SUBST(DBLIBS)
dnl #define USE_ORACLE
AC_DEFINE_UNQUOTED(USE_ORACLE)
fi
dnl Check for optional libpq
if test x$USE_LIBPQ = xyes; then
LIBPQ_INC=""
LIBPQ_LIB=""
dnl Optional libpq library and include paths
AC_ARG_WITH(pgsql-lib,AC_HELP_STRING([--with-pgsql-lib=DIR],[!use libdbis pgsql support instead, libpq not yet implemented! sets location of the pgsql library]),[
LIBPQ_LIB="-L${withval}"
])
AC_ARG_WITH(psql-inc,AC_HELP_STRING([--with-pgsql-inc=DIR],[!use libdbis pgsql support instead, libpq not yet implemented! sets location of the pgsql include files,]),[
LIBPQ_INC="-I${withval}"
])
CFLAGS="$CFLAGS $LIBPQ_INC"
LDFLAGS="$LDFLAGS $LIBPQ_LIB"
AC_CHECK_HEADERS(libpq-fe.h)
AC_DEFINE(HAVE_LIBPQ_FE_H,"1")
AC_MSG_CHECKING(for lpq)
AC_CHECK_LIB([pq], [main],DBLIBS_PQ="${DBCFLAGS} -lpq" , [AC_MSG_ERROR([ERROR - We really need a libpq to link against])] )
DBLIBS="${DBLIBS} ${DBLIBS_PQ}"
AC_SUBST(DBLIBS)
dnl #define USE_PGSQL
AC_DEFINE_UNQUOTED(USE_PGSQL)
fi
if test x$USE_LIBPQ = xno && test x$USE_OCILIB = xno; then
dnl Checks for libdbi
dnl LIBDBI_INC="-I/usr/include"
LIBDBI_INC=""
dnl LIBDBI_LIB="-L/usr/lib"
LIBDBI_LIB=""
dnl Optional libdbi library and include paths
AC_ARG_WITH(dbi-lib,AC_HELP_STRING([--with-dbi-lib=DIR],[sets location of the libdbi library]),[
LIBDBI_LIB="-L${withval}"
])
AC_ARG_WITH(dbi-inc,AC_HELP_STRING([--with-dbi-inc=DIR],[sets location of the libdbi include files,]),[
LIBDBI_INC="-I${withval}"
])
CFLAGS="$CFLAGS $LIBDBI_INC"
LDFLAGS="$LDFLAGS $LIBDBI_LIB"
AC_CHECK_HEADERS(dbi/dbi.h)
AC_DEFINE(HAVE_DBI_DBI_H,"1")
AC_MSG_CHECKING(for libdbi)
AC_CHECK_LIB([dbi], [main],DBLIBS_DBI="${DBCFLAGS} -ldbi" , [AC_MSG_ERROR([ERROR - We really need a libdbi to link against])] )
DBLIBS="${DBLIBS} ${DBLIBS_DBI}"
AC_SUBST(DBLIBS)
dnl #define USE_LIBDBI
AC_DEFINE_UNQUOTED(USE_LIBDBI)
fi
fi
dnl classic ui standalone
fi
dnl Location of temp path
LIBDBIDRIVERDIR=no
AC_ARG_WITH(libdbi-driver-dir,AC_HELP_STRING([--with-libdbi-driver-dir=],[sets path to libdbi driver directory path (only valid with libdbi, not oracle ocilib)]),LIBDBIDRIVERDIR=$withval,LIBDBIDRIVERDIR=no)
if test x$LIBDBIDRIVERDIR = xno; then
LIBDBIDRIVERDIR="/usr/local/lib/dbd"
fi
AC_SUBST(LIBDBIDRIVERDIR)
USEPERL=no;
INSTALLPERLSTUFF=no;
AC_ARG_ENABLE(embedded-perl,AC_HELP_STRING([--enable-embedded-perl],[will enable embedded Perl interpreter]),[
USEPERL=$enableval
]
,USEPERL=no)
PERLCACHE=yes;
AC_ARG_WITH(perlcache,AC_HELP_STRING([--with-perlcache],[turns on cacheing of internally compiled Perl scripts]),[
PERLCACHE=$withval
]
,[
AC_DEFINE(DO_CLEAN,"1",[whether to clean cached compiled perl])
PERLCACHE=yes;
])
dnl Is embedded Perl being compiled in?
if test x$USEPERL = xyes; then
AC_DEFINE_UNQUOTED(EMBEDDEDPERL,,[Is embedded Perl being compiled in?])
PERLLIBS="`perl -MExtUtils::Embed -e ldopts`"
PERLDIR="`perl -MConfig -e 'print $Config{installsitearch}'`"
CFLAGS="${CFLAGS} `perl -MExtUtils::Embed -e ccopts`"
USEPERL=yes
INSTALLPERLSTUFF=yes;
PERLXSI_O=perlxsi.o
OBJS="${OBJS} ${PERLXSI_O}"
echo "creating base/perlxsi.c"
perl -MExtUtils::Embed -e xsinit -- -o base/perlxsi.c
echo "Embedded Perl interpreter will be compiled in..."
dnl Is caching enabled?
if test x$PERLCACHE = xyes; then
AC_DEFINE(DO_CLEAN,"0",[whether to clean cached compiled perl])
PERLCACHE=yes;
echo "Internally compiled Perl scripts will be cached..."
else
AC_DEFINE(DO_CLEAN,"1",[whether to clean cached compiled perl])
echo "Internally compiled Perl scripts will NOT be cached..."
fi
fi
dnl Test if we're using threaded Perl (patch by Chip Ach)
if test x$USEPERL = xyes; then
if (perl -e 'use Config;exit -1 unless ($Config{'usethreads'});'); then
echo "Using threaded perl"
AC_DEFINE_UNQUOTED(THREADEDPERL,,[defined if we're using threaded Perl])
fi
fi
dnl Option for compiling under CYGWIN
icinga_name=icinga
icingastats_name=icingastats
ido2db_name=ido2db
cygwin=no
AC_ARG_ENABLE(cygwin,AC_HELP_STRING([--enable-cygwin],[enables building under the CYGWIN environment]),[
cygwin=$enableval
])
if test x$cygwin = xyes; then
CFLAGS="${CFLAGS} -DCYGWIN"
icinga_name=icinga.exe;
icingastats_name=icingastats.exe;
fi
AC_SUBST(icinga_name)
AC_SUBST(icingastats_name)
AC_SUBST(ido2db_name)
dnl create ido2db_runtime for rc.ido2db.in
ido2db_runtime="$IDO2DB_RUNTIME"
AC_SUBST(ido2db_runtime)
dnl Should predictive failure routines be compiled in?
dnl AC_ARG_ENABLE(failure-prediction,AC_HELP_STRING([--enable-failure-prediction],[will enable integration with failure prediction module (NOT HERE YET!)]),[
dnl AC_DEFINE_UNQUOTED(PREDICT_FAILURES)
dnl BASEEXTRALIBS="$BASEEXTRALIBS \$(FDATALIBS)"
dnl echo "Failure prediction routines (incomplete!) will be compiled in..."
dnl ])
dnl Package directory for Solaris pkgmk (and other OSs, eventually)
dnl VERSION=`grep 1.0 include/common.h | cut -d ' ' -f 3 | sed 's/"//g'`
VERSION=$PKG_VERSION
PACKDIR=`pwd`/solaris_pkg
SOL_PKG_NAME=Icinga
ARCH=`uname -p`
AC_SUBST(PACKDIR)
AC_SUBST(VERSION)
AC_SUBST(ARCH)
AC_SUBST(SOL_PKG_NAME)
AC_MSG_CHECKING(for type va_list)
AC_TRY_COMPILE([#ifdef __STDC__
#include
#include
#include
#else
#include
#include
#include
#endif],
[va_list args;],
[AC_MSG_RESULT(yes)],
[AC_DEFINE(NEED_VA_LIST,,[defined if va_list fails to compile]) AC_MSG_RESULT(no)])
dnl libtap is now from https://github.com/zorgnax/libtap, no configure needed anymore - FIXME in 1.8
AC_ARG_ENABLE(libtap,
AC_HELP_STRING([--enable-libtap],
[this is deprecated, libtap is built with make test]),
[enable_libtap=$enableval],
[enable_libtap=yes])
dnl Environment Prefix
env_prefix="ICINGA_"
AC_ARG_ENABLE(nagiosenv,
AC_HELP_STRING([--enable-nagiosenv],[expose Icinga Environment variables as NAGIOS_*)]))
AS_IF([ test "x$enable_nagiosenv" = "xyes"],[
env_prefix="NAGIOS_"
AC_DEFINE(USE_NAGIOS_ENV,"1",[use NAGIOS_ as EnvVar Prefix])
])
AC_SUBST(CGIEXTRAS)
AC_SUBST(GDLIBS)
AC_SUBST(PERLLIBS)
AC_SUBST(PERLDIR)
AC_SUBST(PERLXSI_O)
AC_SUBST(BASEEXTRALIBS)
AC_SUBST(INITDIR)
AC_SUBST(INIT_OPTS)
AC_SUBST(INSTALLPERLSTUFF)
AC_SUBST(USE_EVENTBROKER)
AC_SUBST(USE_IDOUTILS)
AC_SUBST(USE_IDOUTILS_ORACLE)
AC_SUBST(ENABLE_DEBUG)
AC_PATH_PROG(PERL,perl)
dnl create perl bin path for idoutils *db scripts
ido2db_perl="$PERL"
AC_SUBST(ido2db_perl)
dnl Does user want to check for SSL?
AC_ARG_ENABLE(ssl,AC_HELP_STRING([--enable-ssl],[enables native SSL support]),[
if test x$enableval = xyes; then
check_for_ssl=yes
else
check_for_ssl=no
fi
],check_for_ssl=no)
dnl Optional SSL library and include paths
ssl_dir=
ssl_inc_dir=
ssl_lib_dir=
AC_ARG_WITH(ssl,AC_HELP_STRING([--with-ssl=DIR],[sets location of the SSL installation]),[
ssl_dir=$withval
])
AC_ARG_WITH(ssl-inc,AC_HELP_STRING([--with-ssl-inc=DIR],[sets location of the SSL include files]),[
ssl_inc_dir=$withval
])
AC_ARG_WITH(ssl-lib,AC_HELP_STRING([--with-ssl-lib=DIR],[sets location of the SSL libraries]),[
ssl_lib_dir=$withval
])
AC_ARG_WITH(kerberos-inc,AC_HELP_STRING([--with-kerberos-inc=DIR],[sets location of the Kerberos include files]),[
kerberos_inc_dir=$withval
])
dnl Check for SSL support
dnl Modified version of Mark Ethan Trostler's macro
if test x$check_for_ssl = xyes; then
AC_MSG_CHECKING(for SSL headers)
found_ssl=no
for dir in $ssl_inc_dir $ssl_dir /usr/local/openssl /usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr /usr/freeware/lib/openssl; do
ssldir="$dir"
if test -f "$dir/include/openssl/ssl.h"; then
found_ssl=yes
CFLAGS="$CFLAGS -I$dir/include/openssl -I$ssldir/include"
sslincdir="$dir/include/openssl"
break
fi
if test -f "$dir/include/ssl.h"; then
found_ssl=yes
CFLAGS="$CFLAGS -I$dir/include"
sslincdir="$dir/include"
break
fi
if test -f "$dir/ssl.h"; then
found_ssl=yes
CFLAGS="$CFLAGS -I$dir"
sslincdir="$dir"
ssldir="$dir/.."
break
fi
if test -f "$dir/openssl/ssl.h"; then
found_ssl=yes
CFLAGS="$CFLAGS -I$dir/openssl"
sslincdir="$dir/openssl"
ssldir="$dir/.."
break
fi
done
if test x_$found_ssl != x_yes; then
AC_MSG_ERROR(Cannot find ssl headers)
else
printf "SSL headers found in $ssldir\n";
dnl Now try and find SSL libraries
AC_MSG_CHECKING(for SSL libraries)
found_ssl=no
for dir in $ssl_lib_dir $ssl_dir /usr/lib/*-linux-gnu /usr/lib64 /usr/lib /usr/local/lib /usr/lib/ssl /usr/ssl/lib /usr/openssl/lib /usr/pkg/lib /usr/freeware/lib/openssl; do
ssllibdir="$dir"
if test -f "$dir/libssl.so"; then
found_ssl=yes
break
fi
if test -f "$dir/lib/libssl.so"; then
found_ssl=yes
ssllibdir="$dir/lib"
break
fi
done
if test x_$found_ssl != x_yes; then
AC_MSG_ERROR(Cannot find ssl libraries)
else
printf "SSL libraries found in $ssllibdir\n";
LDFLAGS="$LDFLAGS -L$ssllibdir";
LIBS="$LIBS -lssl -lcrypto";
AC_DEFINE_UNQUOTED(HAVE_SSL)
AC_SUBST(HAVE_SSL)
dnl if ssl dir provided, thake this instead
if test "ssl_dir" != ""; then
ssldir="$ssl_dir"
fi
dnl Generate DH parameters
echo ""
echo "*** Generating DH Parameters for SSL/TLS ***"
if test -f "$ssldir/sbin/openssl"; then
sslbin=$ssldir/sbin/openssl
else
if test -f "$ssldir/bin/openssl"; then
sslbin=$ssldir/bin/openssl
else
sslbin=openssl
fi
fi
# awk to strip off meta data at bottom of dhparam output
$sslbin dhparam -C 512 | awk '/^-----/ {exit} {print}' > include/dh.h
fi
fi
dnl RedHat 8.0 and 9.0 include openssl compiled with kerberos, so we must include header file
AC_MSG_CHECKING(for Kerberos include files)
found_kerberos=no
for dir in $kerberos_inc_dir /usr/kerberos/include; do
kerbdir="$dir"
if test -f "$dir/krb5.h"; then
found_kerberos=yes
CFLAGS="$CFLAGS -I$kerbdir"
AC_DEFINE_UNQUOTED(HAVE_KRB5_H)
dnl AC_CHECK_HEADERS(krb5.h)
break
fi
done
if test x_$found_kerberos != x_yes; then
printf "could not find include files\n";
else
printf "found Kerberos include files in $kerbdir\n";
fi
fi
TESTS_CFLAGS="$CFLAGS"
AC_SUBST(TESTS_CFLAGS)
dnl set -Wall based on os/compiler
AC_MSG_CHECKING(for -Wall based on os/compiler)
case $host_os in
solaris2*|sysv4*)
;;
aix4*|aix5*|aix6*|aix7*)
CFLAGS="-Wall $CFLAGS"
;;
freebsd2*)
;;
darwin*)
;;
linux* | k*bsd*-gnu*)
CFLAGS="-Wall $CFLAGS"
;;
freebsd*)
CFLAGS="-Wall $CFLAGS"
;;
*)
;;
esac
dnl OUTPUT
AC_OUTPUT(Makefile subst solaris/pkginfo solaris/icinga.xml base/Makefile common/Makefile contrib/Makefile cgi/Makefile html/Makefile module/Makefile module/idoutils/Makefile xdata/Makefile daemon-init rc.ido2db icinga-systemd sysconfig-env ido2db-systemd module/idoutils/src/Makefile t-tap/Makefile t/Makefile module/idoutils/db/scripts/installdb module/idoutils/db/scripts/upgradedb module/idoutils/db/scripts/prepsql p1.pl)
perl subst $srcdir/include/locations.h
perl subst $srcdir/contrib/eventhandlers/submit_check_result
perl subst $srcdir/contrib/eventhandlers/disable_active_service_checks
perl subst $srcdir/contrib/eventhandlers/disable_notifications
perl subst $srcdir/contrib/eventhandlers/enable_active_service_checks
perl subst $srcdir/contrib/eventhandlers/enable_notifications
perl subst $srcdir/html/index.html
perl subst $srcdir/html/menu.html
perl subst $srcdir/html/js/autocomplete.js
echo ""
echo "Creating sample config files in sample-config/ ..."
perl subst $srcdir/sample-config/icinga.cfg
perl subst $srcdir/sample-config/cgi.cfg
perl subst $srcdir/sample-config/cgiauth.cfg
perl subst $srcdir/sample-config/resource.cfg
perl subst $srcdir/sample-config/httpd.conf
perl subst $srcdir/sample-config/mrtg.cfg
perl subst $srcdir/sample-config/template-object/templates.cfg
perl subst $srcdir/sample-config/template-object/commands.cfg
perl subst $srcdir/sample-config/template-object/timeperiods.cfg
perl subst $srcdir/sample-config/template-object/contacts.cfg
perl subst $srcdir/sample-config/template-object/notifications.cfg
perl subst $srcdir/sample-config/template-object/localhost.cfg
perl subst $srcdir/sample-config/template-object/windows.cfg
perl subst $srcdir/sample-config/template-object/printer.cfg
perl subst $srcdir/sample-config/template-object/switch.cfg
echo ""
echo "Creating sample config files in module/idoutils/config/ ..."
perl subst $srcdir/module/idoutils/config/idoutils.cfg-sample
perl subst $srcdir/module/idoutils/config/ido2db.cfg-sample
perl subst $srcdir/module/idoutils/config/idomod.cfg-sample
dnl Create IDOUtils Perl Scripts for DB Handling
dnl perl subst module/idoutils/db/installdb
dnl perl subst module/idoutils/db/prepsql
dnl perl subst module/idoutils/db/upgradedb
dnl Review options
echo ""
echo ""
AC_MSG_RESULT([*** Configuration summary for $PKG_NAME $PKG_VERSION $PKG_REL_DATE ***:])
echo ""
echo " General Options:"
echo " -------------------------"
AC_MSG_RESULT([ Icinga executable: $icinga_name])
AC_MSG_RESULT([ Icinga user/group: $icinga_user,$icinga_grp])
AC_MSG_RESULT([ Command user/group: $command_user,$command_grp])
AC_MSG_RESULT([ Apache user/group: $web_user,$web_group])
if test x$ENABLE_DEBUG = xyes; then
AC_MSG_RESULT([ Debug Mode: yes])
fi
if test x$USEPERL = xyes; then
if test x$PERLCACHE = xyes; then
AC_MSG_RESULT([ Embedded Perl: yes, with caching])
else
AC_MSG_RESULT([ Embedded Perl: yes, without caching])
fi
else
AC_MSG_RESULT([ Embedded Perl: no])
fi
if test x$USE_EVENTBROKER = xyes; then
AC_MSG_RESULT([ Event Broker: yes])
else
AC_MSG_RESULT([ Event Broker: no])
fi
if test x$ENABLE_PERFDATA = xyes; then
AC_MSG_RESULT([ Enable Performance Data: yes])
else
AC_MSG_RESULT([ Enable Performance Data: no])
fi
if test x$USE_IDOUTILS = xyes; then
AC_MSG_RESULT([ ido2db lockfile: $IDO2DBLOCKFILE])
AC_MSG_RESULT([ ido sockfile: $IDOSOCKFILE])
AC_MSG_RESULT([ idomod tempfile: $IDOMODTMPFILE])
if test x$USE_IDOUTILS_ORACLE = xyes; then
AC_MSG_RESULT([ Build IDOUtils: ocilib, instance_name=$IDO_INSTANCE_NAME])
else
AC_MSG_RESULT([ Build IDOUtils: libdbi, instance_name=$IDO_INSTANCE_NAME])
AC_MSG_RESULT([ libdbi driver dir: $LIBDBIDRIVERDIR])
fi
else
AC_MSG_RESULT([ Build IDOUtils: no])
fi
AC_MSG_RESULT([ Install \${prefix}: $prefix])
AC_MSG_RESULT([ Lock file: $lockfile])
AC_MSG_RESULT([ Temp file: $TMPFILE])
AC_MSG_RESULT([ Chk file: $ICINGACHKFILE])
AC_MSG_RESULT([ HTTP auth file: $HTTPAUTHFILE])
AC_MSG_RESULT([ Lib directory: $libdir])
AC_MSG_RESULT([ Bin directory: $bindir])
AC_MSG_RESULT([ Plugin directory: $PLUGINDIR])
AC_MSG_RESULT([ Eventhandler directory: $EVENTHANDLERDIR])
AC_MSG_RESULT([ Log directory: $LOGDIR])
if test x$ENABLE_CGILOG = xyes; then
AC_MSG_RESULT([ cgi log directory: $CGILOGDIR])
fi
AC_MSG_RESULT([ Check result directory: $CHECKRESULTDIR])
AC_MSG_RESULT([ Temp directory: $TMPDIR])
AC_MSG_RESULT([ State directory: $STATEDIR])
AC_MSG_RESULT([ Ext Cmd file directory: $EXTCMDFILEDIR])
AC_MSG_RESULT([ Init directory: $init_dir])
AC_MSG_RESULT([ Apache conf.d directory: $HTTPD_CONF])
AC_MSG_RESULT([ Apache config file: $HTTPDCONFFILE])
AC_MSG_RESULT([ Mail program: $MAIL_PROG])
AC_MSG_RESULT([ Host OS: $host_os])
AC_MSG_RESULT([ Environment Prefix: $env_prefix])
echo ""
echo " Web Interface Options:"
echo " ------------------------"
AC_MSG_RESULT([ HTML URL: http://localhost$htmurl/])
AC_MSG_RESULT([ CGI URL: http://localhost$cgiurl/])
AC_MSG_RESULT([ Main URL: http://localhost$mainurl])
dnl echo ""
dnl echo " External Data Routines:"
dnl echo " ------------------------"
dnl AC_MSG_RESULT([ Status data: $XSDCOMMENT])
dnl AC_MSG_RESULT([ Comment data: $XCDCOMMENT])
dnl AC_MSG_RESULT([ Downtime data: $XDDCOMMENT])
dnl AC_MSG_RESULT([ Peformance data: $XPDCOMMENT])
echo ""
echo ""
echo "Review the options above for accuracy. If they look okay,"
echo "type 'make all' to compile the main program and CGIs."
echo ""
echo ""
echo "!!! Please take care about the upgrade documentation !!!"
echo ""
icinga-1.10.3/contrib/ 0000775 0000000 0000000 00000000000 12276402000 0014457 5 ustar 00root root 0000000 0000000 icinga-1.10.3/contrib/Makefile.in 0000664 0000000 0000000 00000005723 12276402000 0016533 0 ustar 00root root 0000000 0000000 ###############################
# Makefile for contrib software
###############################
CC=@CC@
CFLAGS=@CFLAGS@ @DEFS@
LDFLAGS=@LDFLAGS@ @LIBS@
# Source code directories
SRC_INCLUDE=../include
SRC_COMMON=../common
SRC_CGI=../cgi
# Generated automatically from configure script
SNPRINTF_O=@SNPRINTF_O@
INSTALL=@INSTALL@
INSTALL_OPTS=@INSTALL_OPTS@
prefix=@prefix@
exec_prefix=@exec_prefix@
CGIDIR=@sbindir@
BINDIR=@bindir@
LIBDIR=@libdir@
CGIS=traceroute.cgi daemonchk.cgi
UTILS=mini_epn new_mini_epn convertcfg
ALL=$(CGIS) $(UTILS)
DST=dst
CGI_C=$(SRC_CGI)/getcgi.c
CGI_O=$(SRC_CGI)/getcgi.o $(SNPRINTF_O)
CGI_H=$(SRC_INCLUDE)/getcgi.h
COMMON_H=$(SRC_INCLUDE)/config.h $(SRC_INCLUDE)/common.h $(SRC_INCLUDE)/locations.h
###############################
# Debug
###############################
ENABLE_DEBUG=@ENABLE_DEBUG@
# Compiler flags for use with Valgrind - set when debug is enabled
ifeq ('$(ENABLE_DEBUG)', 'yes')
CFLAGS=-O0 -g
endif
##############################################################################
# standard targets (all, clean, distclean, devclean, install)
all: $(ALL)
clean:
rm -f convertcfg daemonchk.cgi mini_epn new_mini_epn core dst *.o
rm -f */*/*~
rm -f */*~
rm -f *~
distclean: clean
rm -f Makefile
rm -f eventhandlers/disable_active_service_checks eventhandlers/disable_notifications eventhandlers/enable_active_service_checks eventhandlers/enable_notifications eventhandlers/submit_check_result
devclean: distclean
install:
$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(CGIDIR)
$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(BINDIR)
for f in $(CGIS); do $(INSTALL) -m 775 $(INSTALL_OPTS) $$f $(DESTDIR)$(CGIDIR); done
for f in $(UTILS); do $(INSTALL) -m 775 $(INSTALL_OPTS) $$f $(DESTDIR)$(BINDIR); done
##############################################################################
# rules and dependencies for actual target programs
daemonchk.cgi: daemonchk.o $(CGI_O) $(CGI_H) $(COMMON_H)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(CGI_O)
daemonchk.o: daemonchk.c
$(CC) $(CFLAGS) -c -o $@ $< -I$(SRC_INCLUDE)
mini_epn: mini_epn.c
perl -MExtUtils::Embed -e xsinit
$(CC) $(CFLAGS) -c perlxsi.c `perl -MExtUtils::Embed -e ccopts`
$(CC) $(CFLAGS) -c mini_epn.c `perl -MExtUtils::Embed -e ccopts`
$(CC) $(CFLAGS) $(LDFLAGS) perlxsi.o mini_epn.o `perl -MExtUtils::Embed -e ccopts -e ldopts` -o $@
new_mini_epn: new_mini_epn.c
perl -MExtUtils::Embed -e xsinit
$(CC) $(CFLAGS) -c perlxsi.c `perl -MExtUtils::Embed -e ccopts`
$(CC) $(CFLAGS) -c new_mini_epn.c `perl -MExtUtils::Embed -e ccopts`
$(CC) $(CFLAGS) $(LDFLAGS) perlxsi.o new_mini_epn.o `perl -MExtUtils::Embed -e ccopts -e ldopts` -o $@
dst: dst.c
$(CC) $(CFLAGS) -o $@ $<
##############################################################################
# dependencies
$(CGI_O): $(CGI_C)
cd $(SRC_CGI) && make $(CGI_O)
##############################################################################
# implicit rules
%.cgi : %.c
$(CC) $(CFLAGS) $(LDFLAGS) $< $(CGI_O) -o $@
icinga-1.10.3/contrib/README 0000664 0000000 0000000 00000002443 12276402000 0015342 0 ustar 00root root 0000000 0000000 #####################
Nagios Contrib README
#####################
This directory contains various programs, scripts, etc. that
have been contribed by various people. Read the source code
if you want to find who did what.
Here is a description of what you'll find...
Conversion Programs:
--------------------
- convertcfg.c is a program to quickly convert old "host" config
files to the new template-based object config files. It can also
convert extended host information definitions. Type 'make convertcfg'
to compile the utility.
Additional CGIs:
----------------
- traceroute.cgi is (surprise) a CGI that allows you to do a traceroute
to a specific IP address. Simply do a 'chmod +x' to make it executeable
and place it in the CGI directory (i.e. /usr/local/nagios/sbin).
Requires Perl.
- daemonchk.c is a CGI contributed by Karl DeBisschop that can test to
see whether or not the Nagios process is running.
Miscellaneous Goodies:
----------------------
- htaccess.sample is a *sample* .htaccess file that can be used with
Apache to require password authentication for access to the web
interface.
- mini_epn.c is a mini embedded Perl interpreter that can be used to
test the feasibility of running various Perl plugins with the
embedded Perl interpreter compiled in.
icinga-1.10.3/contrib/convertcfg.c 0000664 0000000 0000000 00000055336 12276402000 0016777 0 ustar 00root root 0000000 0000000 /************************************************************************
*
* CONVERTCFG.C - Config File Convertor
*
* Copyright (c) 2001-2005 Ethan Galstad (egalstad@nagios.org)
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
************************************************************************/
#include
#include
#include
char *my_strsep(char **, const char *);
int main(int argc, char **argv) {
FILE *fp;
char *temp_ptr;
char *temp_ptr2;
char input[8096];
int notify_recovery;
int notify_warning;
int notify_critical;
int notify_down;
int notify_unreachable;
int option;
int have_template = 0;
int x = 0, y = 0;
char *host_name;
char *service_description;
char *host_name2;
char *service_description2;
if (argc != 3) {
printf("Nagios Config File Converter\n");
printf("Written by Ethan Galstad (egalstad@nagios.org)\n");
printf("Last Modified: 08-12-2005\n");
printf("\n");
printf("Usage: %s