1 /************************************************************************ 2 * 3 * Nagios Main Header File 4 * Written By: Ethan Galstad (nagios@nagios.org) 5 * Last Modified: 01-08-2007 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 ************************************************************************/ 20 21 #ifndef _NAGIOS_H 22 #define _NAGIOS_H 23 24 #include "config.h" 25 #include "common.h" 26 #include "locations.h" 27 #include "objects.h" 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 #define MAX_COMMAND_ARGUMENTS 32 /* maximum number of $ARGx$ macros */ 34 #define MAX_USER_MACROS 256 /* maximum number of $USERx$ macros */ 35 36 #define MAX_STATE_LENGTH 32 /* length definitions used in macros */ 37 #define MAX_STATETYPE_LENGTH 24 38 #define MAX_CHECKTYPE_LENGTH 8 39 #define MAX_NOTIFICATIONTYPE_LENGTH 32 40 #define MAX_NOTIFICATIONNUMBER_LENGTH 8 41 #define MAX_ATTEMPT_LENGTH 8 42 #define MAX_TOTALS_LENGTH 8 43 #define MAX_EXECUTIONTIME_LENGTH 10 44 #define MAX_LATENCY_LENGTH 10 45 #define MAX_DURATION_LENGTH 17 46 #define MAX_DOWNTIME_LENGTH 3 47 #define MAX_STATEID_LENGTH 2 48 #define MAX_PERCENTCHANGE_LENGTH 8 49 50 #define MACRO_ENV_VAR_PREFIX "NAGIOS_" 51 52 #define MACRO_X_COUNT 99 /* size of macro_x[] array */ 53 54 #define MACRO_HOSTNAME 0 55 #define MACRO_HOSTALIAS 1 56 #define MACRO_HOSTADDRESS 2 57 #define MACRO_SERVICEDESC 3 58 #define MACRO_SERVICESTATE 4 59 #define MACRO_SERVICESTATEID 5 60 #define MACRO_SERVICEATTEMPT 6 61 #define MACRO_LONGDATETIME 7 62 #define MACRO_SHORTDATETIME 8 63 #define MACRO_DATE 9 64 #define MACRO_TIME 10 65 #define MACRO_TIMET 11 66 #define MACRO_LASTHOSTCHECK 12 67 #define MACRO_LASTSERVICECHECK 13 68 #define MACRO_LASTHOSTSTATECHANGE 14 69 #define MACRO_LASTSERVICESTATECHANGE 15 70 #define MACRO_HOSTOUTPUT 16 71 #define MACRO_SERVICEOUTPUT 17 72 #define MACRO_HOSTPERFDATA 18 73 #define MACRO_SERVICEPERFDATA 19 74 #define MACRO_CONTACTNAME 20 75 #define MACRO_CONTACTALIAS 21 76 #define MACRO_CONTACTEMAIL 22 77 #define MACRO_CONTACTPAGER 23 78 #define MACRO_ADMINEMAIL 24 79 #define MACRO_ADMINPAGER 25 80 #define MACRO_HOSTSTATE 26 81 #define MACRO_HOSTSTATEID 27 82 #define MACRO_HOSTATTEMPT 28 83 #define MACRO_NOTIFICATIONTYPE 29 84 #define MACRO_NOTIFICATIONNUMBER 30 85 #define MACRO_HOSTEXECUTIONTIME 31 86 #define MACRO_SERVICEEXECUTIONTIME 32 87 #define MACRO_HOSTLATENCY 33 88 #define MACRO_SERVICELATENCY 34 89 #define MACRO_HOSTDURATION 35 90 #define MACRO_SERVICEDURATION 36 91 #define MACRO_HOSTDURATIONSEC 37 92 #define MACRO_SERVICEDURATIONSEC 38 93 #define MACRO_HOSTDOWNTIME 39 94 #define MACRO_SERVICEDOWNTIME 40 95 #define MACRO_HOSTSTATETYPE 41 96 #define MACRO_SERVICESTATETYPE 42 97 #define MACRO_HOSTPERCENTCHANGE 43 98 #define MACRO_SERVICEPERCENTCHANGE 44 99 #define MACRO_HOSTGROUPNAME 45 100 #define MACRO_HOSTGROUPALIAS 46 101 #define MACRO_SERVICEGROUPNAME 47 102 #define MACRO_SERVICEGROUPALIAS 48 103 #define MACRO_HOSTACKAUTHOR 49 104 #define MACRO_HOSTACKCOMMENT 50 105 #define MACRO_SERVICEACKAUTHOR 51 106 #define MACRO_SERVICEACKCOMMENT 52 107 #define MACRO_LASTSERVICEOK 53 108 #define MACRO_LASTSERVICEWARNING 54 109 #define MACRO_LASTSERVICEUNKNOWN 55 110 #define MACRO_LASTSERVICECRITICAL 56 111 #define MACRO_LASTHOSTUP 57 112 #define MACRO_LASTHOSTDOWN 58 113 #define MACRO_LASTHOSTUNREACHABLE 59 114 #define MACRO_SERVICECHECKCOMMAND 60 115 #define MACRO_HOSTCHECKCOMMAND 61 116 #define MACRO_MAINCONFIGFILE 62 117 #define MACRO_STATUSDATAFILE 63 118 #define MACRO_COMMENTDATAFILE 64 119 #define MACRO_DOWNTIMEDATAFILE 65 120 #define MACRO_RETENTIONDATAFILE 66 121 #define MACRO_OBJECTCACHEFILE 67 122 #define MACRO_TEMPFILE 68 123 #define MACRO_LOGFILE 69 124 #define MACRO_RESOURCEFILE 70 125 #define MACRO_COMMANDFILE 71 126 #define MACRO_HOSTPERFDATAFILE 72 127 #define MACRO_SERVICEPERFDATAFILE 73 128 #define MACRO_HOSTACTIONURL 74 129 #define MACRO_HOSTNOTESURL 75 130 #define MACRO_HOSTNOTES 76 131 #define MACRO_SERVICEACTIONURL 77 132 #define MACRO_SERVICENOTESURL 78 133 #define MACRO_SERVICENOTES 79 134 #define MACRO_TOTALHOSTSUP 80 135 #define MACRO_TOTALHOSTSDOWN 81 136 #define MACRO_TOTALHOSTSUNREACHABLE 82 137 #define MACRO_TOTALHOSTSDOWNUNHANDLED 83 138 #define MACRO_TOTALHOSTSUNREACHABLEUNHANDLED 84 139 #define MACRO_TOTALHOSTPROBLEMS 85 140 #define MACRO_TOTALHOSTPROBLEMSUNHANDLED 86 141 #define MACRO_TOTALSERVICESOK 87 142 #define MACRO_TOTALSERVICESWARNING 88 143 #define MACRO_TOTALSERVICESCRITICAL 89 144 #define MACRO_TOTALSERVICESUNKNOWN 90 145 #define MACRO_TOTALSERVICESWARNINGUNHANDLED 91 146 #define MACRO_TOTALSERVICESCRITICALUNHANDLED 92 147 #define MACRO_TOTALSERVICESUNKNOWNUNHANDLED 93 148 #define MACRO_TOTALSERVICEPROBLEMS 94 149 #define MACRO_TOTALSERVICEPROBLEMSUNHANDLED 95 150 #define MACRO_PROCESSSTARTTIME 96 151 #define MACRO_HOSTCHECKTYPE 97 152 #define MACRO_SERVICECHECKTYPE 98 153 154 155 156 #define DEFAULT_LOG_LEVEL 1 /* log all events to main log file */ 157 #define DEFAULT_USE_SYSLOG 1 /* log events to syslog? 1=yes, 0=no */ 158 #define DEFAULT_SYSLOG_LEVEL 2 /* log only severe events to syslog */ 159 160 #define DEFAULT_NOTIFICATION_LOGGING 1 /* log notification events? 1=yes, 0=no */ 161 162 #define DEFAULT_INTER_CHECK_DELAY 5.0 /* seconds between initial service check scheduling */ 163 #define DEFAULT_INTERLEAVE_FACTOR 1 /* default interleave to use when scheduling checks */ 164 #define DEFAULT_SLEEP_TIME 0.5 /* seconds between event run checks */ 165 #define DEFAULT_INTERVAL_LENGTH 60 /* seconds per interval unit for check scheduling */ 166 #define DEFAULT_RETRY_INTERVAL 30 /* services are retried in 30 seconds if they're not OK */ 167 #define DEFAULT_COMMAND_CHECK_INTERVAL -1 /* interval to check for external commands (default = as often as possible) */ 168 #define DEFAULT_SERVICE_REAPER_INTERVAL 10 /* interval in seconds to reap service check results */ 169 #define DEFAULT_MAX_REAPER_TIME 30 /* maximum number of seconds to spend reaping service checks before we break out for a while */ 170 #define DEFAULT_MAX_PARALLEL_SERVICE_CHECKS 0 /* maximum number of service checks we can have running at any given time (0=unlimited) */ 171 #define DEFAULT_RETENTION_UPDATE_INTERVAL 60 /* minutes between auto-save of retention data */ 172 #define DEFAULT_RETENTION_SCHEDULING_HORIZON 900 /* max seconds between program restarts that we will preserve scheduling information */ 173 #define DEFAULT_STATUS_UPDATE_INTERVAL 60 /* seconds between aggregated status data updates */ 174 #define DEFAULT_FRESHNESS_CHECK_INTERVAL 60 /* seconds between service result freshness checks */ 175 #define DEFAULT_AUTO_RESCHEDULING_INTERVAL 30 /* seconds between host and service check rescheduling events */ 176 #define DEFAULT_AUTO_RESCHEDULING_WINDOW 180 /* window of time (in seconds) for which we should reschedule host and service checks */ 177 178 #define DEFAULT_NOTIFICATION_TIMEOUT 30 /* max time in seconds to wait for notification commands to complete */ 179 #define DEFAULT_EVENT_HANDLER_TIMEOUT 30 /* max time in seconds to wait for event handler commands to complete */ 180 #define DEFAULT_HOST_CHECK_TIMEOUT 30 /* max time in seconds to wait for host check commands to complete */ 181 #define DEFAULT_SERVICE_CHECK_TIMEOUT 60 /* max time in seconds to wait for service check commands to complete */ 182 #define DEFAULT_OCSP_TIMEOUT 15 /* max time in seconds to wait for obsessive compulsive processing commands to complete */ 183 #define DEFAULT_OCHP_TIMEOUT 15 /* max time in seconds to wait for obsessive compulsive processing commands to complete */ 184 #define DEFAULT_PERFDATA_TIMEOUT 5 /* max time in seconds to wait for performance data commands to complete */ 185 #define DEFAULT_TIME_CHANGE_THRESHOLD 900 /* compensate for time changes of more than 15 minutes */ 186 187 #define DEFAULT_LOG_HOST_RETRIES 0 /* don't log host retries */ 188 #define DEFAULT_LOG_SERVICE_RETRIES 0 /* don't log service retries */ 189 #define DEFAULT_LOG_EVENT_HANDLERS 1 /* log event handlers */ 190 #define DEFAULT_LOG_INITIAL_STATES 0 /* don't log initial service and host states */ 191 #define DEFAULT_LOG_EXTERNAL_COMMANDS 1 /* log external commands */ 192 #define DEFAULT_LOG_PASSIVE_CHECKS 1 /* log passive service checks */ 193 194 #define DEFAULT_AGGRESSIVE_HOST_CHECKING 0 /* don't use "aggressive" host checking */ 195 #define DEFAULT_CHECK_EXTERNAL_COMMANDS 0 /* don't check for external commands */ 196 #define DEFAULT_CHECK_ORPHANED_SERVICES 1 /* don't check for orphaned services */ 197 #define DEFAULT_ENABLE_FLAP_DETECTION 0 /* don't enable flap detection */ 198 #define DEFAULT_PROCESS_PERFORMANCE_DATA 0 /* don't process performance data */ 199 #define DEFAULT_CHECK_SERVICE_FRESHNESS 1 /* check service result freshness */ 200 #define DEFAULT_CHECK_HOST_FRESHNESS 0 /* don't check host result freshness */ 201 #define DEFAULT_AUTO_RESCHEDULE_CHECKS 0 /* don't auto-reschedule host and service checks */ 202 203 #define DEFAULT_LOW_SERVICE_FLAP_THRESHOLD 20.0 /* low threshold for detection of service flapping */ 204 #define DEFAULT_HIGH_SERVICE_FLAP_THRESHOLD 30.0 /* high threshold for detection of service flapping */ 205 #define DEFAULT_LOW_HOST_FLAP_THRESHOLD 20.0 /* low threshold for detection of host flapping */ 206 #define DEFAULT_HIGH_HOST_FLAP_THRESHOLD 30.0 /* high threshold for detection of host flapping */ 207 208 #define DEFAULT_HOST_CHECK_SPREAD 30 /* max minutes to schedule all initial host checks */ 209 #define DEFAULT_SERVICE_CHECK_SPREAD 30 /* max minutes to schedule all initial service checks */ 210 211 212 213 /******************* LOGGING TYPES ********************/ 214 215 #define NSLOG_RUNTIME_ERROR 1 216 #define NSLOG_RUNTIME_WARNING 2 217 218 #define NSLOG_VERIFICATION_ERROR 4 219 #define NSLOG_VERIFICATION_WARNING 8 220 221 #define NSLOG_CONFIG_ERROR 16 222 #define NSLOG_CONFIG_WARNING 32 223 224 #define NSLOG_PROCESS_INFO 64 225 #define NSLOG_EVENT_HANDLER 128 226 /*#define NSLOG_NOTIFICATION 256*/ /* NOT USED ANYMORE - CAN BE REUSED */ 227 #define NSLOG_EXTERNAL_COMMAND 512 228 229 #define NSLOG_HOST_UP 1024 230 #define NSLOG_HOST_DOWN 2048 231 #define NSLOG_HOST_UNREACHABLE 4096 232 233 #define NSLOG_SERVICE_OK 8192 234 #define NSLOG_SERVICE_UNKNOWN 16384 235 #define NSLOG_SERVICE_WARNING 32768 236 #define NSLOG_SERVICE_CRITICAL 65536 237 238 #define NSLOG_PASSIVE_CHECK 131072 239 240 #define NSLOG_INFO_MESSAGE 262144 241 242 #define NSLOG_HOST_NOTIFICATION 524288 243 #define NSLOG_SERVICE_NOTIFICATION 1048576 244 245 246 /******************** HOST STATUS *********************/ 247 248 #define HOST_UP 0 249 #define HOST_DOWN 1 250 #define HOST_UNREACHABLE 2 251 252 253 /******************* STATE LOGGING TYPES **************/ 254 255 #define INITIAL_STATES 1 256 #define CURRENT_STATES 2 257 258 259 /************ SERVICE DEPENDENCY VALUES ***************/ 260 261 #define DEPENDENCIES_OK 0 262 #define DEPENDENCIES_FAILED 1 263 264 265 /*********** ROUTE CHECK PROPAGATION TYPES ************/ 266 267 #define PROPAGATE_TO_PARENT_HOSTS 1 268 #define PROPAGATE_TO_CHILD_HOSTS 2 269 270 271 /****************** SERVICE STATES ********************/ 272 273 #define STATE_OK 0 274 #define STATE_WARNING 1 275 #define STATE_CRITICAL 2 276 #define STATE_UNKNOWN 3 /* changed from -1 on 02/24/2001 */ 277 278 279 /****************** FLAPPING TYPES ********************/ 280 281 #define HOST_FLAPPING 0 282 #define SERVICE_FLAPPING 1 283 284 285 /**************** NOTIFICATION TYPES ******************/ 286 287 #define HOST_NOTIFICATION 0 288 #define SERVICE_NOTIFICATION 1 289 290 291 /************* NOTIFICATION REASON TYPES ***************/ 292 293 #define NOTIFICATION_NORMAL 0 294 #define NOTIFICATION_ACKNOWLEDGEMENT 1 295 #define NOTIFICATION_FLAPPINGSTART 2 296 #define NOTIFICATION_FLAPPINGSTOP 3 297 298 299 /**************** EVENT HANDLER TYPES *****************/ 300 301 #define HOST_EVENTHANDLER 0 302 #define SERVICE_EVENTHANDLER 1 303 #define GLOBAL_HOST_EVENTHANDLER 2 304 #define GLOBAL_SERVICE_EVENTHANDLER 3 305 306 307 /***************** STATE CHANGE TYPES *****************/ 308 309 #define HOST_STATECHANGE 0 310 #define SERVICE_STATECHANGE 1 311 312 313 /******************* EVENT TYPES **********************/ 314 315 #define EVENT_SERVICE_CHECK 0 /* active service check */ 316 #define EVENT_COMMAND_CHECK 1 /* external command check */ 317 #define EVENT_LOG_ROTATION 2 /* log file rotation */ 318 #define EVENT_PROGRAM_SHUTDOWN 3 /* program shutdown */ 319 #define EVENT_PROGRAM_RESTART 4 /* program restart */ 320 #define EVENT_SERVICE_REAPER 5 /* reaps results from service checks */ 321 #define EVENT_ORPHAN_CHECK 6 /* checks for orphaned service checks */ 322 #define EVENT_RETENTION_SAVE 7 /* save (dump) retention data */ 323 #define EVENT_STATUS_SAVE 8 /* save (dump) status data */ 324 #define EVENT_SCHEDULED_DOWNTIME 9 /* scheduled host or service downtime */ 325 #define EVENT_SFRESHNESS_CHECK 10 /* checks service result "freshness" */ 326 #define EVENT_EXPIRE_DOWNTIME 11 /* checks for (and removes) expired scheduled downtime */ 327 #define EVENT_HOST_CHECK 12 /* active host check */ 328 #define EVENT_HFRESHNESS_CHECK 13 /* checks host result "freshness" */ 329 #define EVENT_RESCHEDULE_CHECKS 14 /* adjust scheduling of host and service checks */ 330 #define EVENT_EXPIRE_COMMENT 15 /* removes expired comments */ 331 #define EVENT_SLEEP 98 /* asynchronous sleep event that occurs when event queues are empty */ 332 #define EVENT_USER_FUNCTION 99 /* USER-defined function (modules) */ 333 334 335 /******* INTER-CHECK DELAY CALCULATION TYPES **********/ 336 337 #define ICD_NONE 0 /* no inter-check delay */ 338 #define ICD_DUMB 1 /* dumb delay of 1 second */ 339 #define ICD_SMART 2 /* smart delay */ 340 #define ICD_USER 3 /* user-specified delay */ 341 342 343 /******* INTERLEAVE FACTOR CALCULATION TYPES **********/ 344 345 #define ILF_USER 0 /* user-specified interleave factor */ 346 #define ILF_SMART 1 /* smart interleave */ 347 348 349 /************** SERVICE CHECK OPTIONS *****************/ 350 351 #define CHECK_OPTION_NONE 0 /* no check options */ 352 #define CHECK_OPTION_FORCE_EXECUTION 1 /* force execution of a service check (ignores disabled services, invalid timeperiods) */ 353 354 355 /************ SCHEDULED DOWNTIME TYPES ****************/ 356 357 #define ACTIVE_DOWNTIME 0 /* active downtime - currently in effect */ 358 #define PENDING_DOWNTIME 1 /* pending downtime - scheduled for the future */ 359 360 361 /************* MACRO CLEANING OPTIONS *****************/ 362 363 #define STRIP_ILLEGAL_MACRO_CHARS 1 364 #define ESCAPE_MACRO_CHARS 2 365 #define URL_ENCODE_MACRO_CHARS 4 366 367 368 369 /****************** DATA STRUCTURES *******************/ 370 371 /* TIMED_EVENT structure */ 372 typedef struct timed_event_struct{ 373 int event_type; 374 time_t run_time; 375 int recurring; 376 unsigned long event_interval; 377 int compensate_for_time_change; 378 void *timing_func; 379 void *event_data; 380 void *event_args; 381 struct timed_event_struct *next; 382 }timed_event; 383 384 385 /* NOTIFY_LIST structure */ 386 typedef struct notify_list_struct{ 387 contact *contact; 388 struct notify_list_struct *next; 389 }notification; 390 391 392 /* SERVICE_MESSAGE structure */ 393 typedef struct service_message_struct{ 394 char host_name[MAX_HOSTNAME_LENGTH]; /* host name */ 395 char description[MAX_SERVICEDESC_LENGTH]; /* service description */ 396 int return_code; /* plugin return code */ 397 int exited_ok; /* did the plugin check return okay? */ 398 int check_type; /* was this an active or passive service check? */ 399 int parallelized; /* was this check run in parallel? */ 400 struct timeval start_time; /* time the service check was initiated */ 401 struct timeval finish_time; /* time the service check was completed */ 402 int early_timeout; /* did the service check timeout? */ 403 char output[MAX_PLUGINOUTPUT_LENGTH]; /* plugin output */ 404 }service_message; 405 406 407 /* SCHED_INFO structure */ 408 typedef struct sched_info_struct{ 409 int total_services; 410 int total_scheduled_services; 411 int total_hosts; 412 int total_scheduled_hosts; 413 double average_services_per_host; 414 double average_scheduled_services_per_host; 415 unsigned long service_check_interval_total; 416 unsigned long host_check_interval_total; 417 double average_service_check_interval; 418 double average_host_check_interval; 419 double average_service_inter_check_delay; 420 double average_host_inter_check_delay; 421 double service_inter_check_delay; 422 double host_inter_check_delay; 423 int service_interleave_factor; 424 int max_service_check_spread; 425 int max_host_check_spread; 426 time_t first_service_check; 427 time_t last_service_check; 428 time_t first_host_check; 429 time_t last_host_check; 430 }sched_info; 431 432 433 /* PASSIVE_CHECK_RESULT structure */ 434 typedef struct passive_check_result_struct{ 435 char *host_name; 436 char *svc_description; 437 int return_code; 438 char *output; 439 time_t check_time; 440 struct passive_check_result_struct *next; 441 }passive_check_result; 442 443 444 /* CIRCULAR_BUFFER structure - used by worker threads */ 445 typedef struct circular_buffer_struct{ 446 void **buffer; 447 int tail; 448 int head; 449 int items; 450 int high; /* highest number of items that has ever been stored in buffer */ 451 unsigned long overflow; 452 pthread_mutex_t buffer_lock; 453 }circular_buffer; 454 455 456 /* MMAPFILE structure - used for reading files via mmap() */ 457 typedef struct mmapfile_struct{ 458 char *path; 459 int mode; 460 int fd; 461 unsigned long file_size; 462 unsigned long current_position; 463 unsigned long current_line; 464 void *mmap_buf; 465 }mmapfile; 466 467 468 469 /* slots in circular buffers */ 470 #define DEFAULT_EXTERNAL_COMMAND_BUFFER_SLOTS 4096 471 #define DEFAULT_CHECK_RESULT_BUFFER_SLOTS 4096 472 473 /* worker threads */ 474 #define TOTAL_WORKER_THREADS 2 475 476 #define COMMAND_WORKER_THREAD 0 477 #define SERVICE_WORKER_THREAD 1 478 479 480 /******************** FUNCTIONS **********************/ 481 482 /**** Configuration Functions ****/ 483 int read_main_config_file(char *); /* reads the main config file (nagios.cfg) */ 484 int read_resource_file(char *); /* processes macros in resource file */ 485 int read_all_object_data(char *); /* reads all object config data */ 486 487 488 /**** Setup Functions ****/ 489 int pre_flight_check(void); /* try and verify the configuration data */ 490 void init_timing_loop(void); /* setup the initial scheduling queue */ 491 void setup_sighandler(void); /* trap signals */ 492 void reset_sighandler(void); /* reset signals to default action */ 493 int daemon_init(void); /* switches to daemon mode */ 494 int drop_privileges(char *,char *); /* drops privileges before startup */ 495 void display_scheduling_info(void); /* displays service check scheduling information */ 496 497 498 /**** IPC Functions ****/ 499 int read_svc_message(service_message *); /* reads a service check message from the message pipe */ 500 int write_svc_message(service_message *); /* writes a service check message to the message pipe */ 501 int open_command_file(void); /* creates the external command file as a named pipe (FIFO) and opens it for reading */ 502 int close_command_file(void); /* closes and deletes the external command file (FIFO) */ 503 504 505 /**** Monitoring/Event Handler Functions ****/ 506 int schedule_new_event(int,int,time_t,int,unsigned long,void *,int,void *,void *); /* schedules a new timed event */ 507 void reschedule_event(timed_event *,timed_event **); /* reschedules an event */ 508 int deschedule_event(int,int,void *,void *); /* removes an event from the schedule */ 509 void add_event(timed_event *,timed_event **); /* adds an event to the execution queue */ 510 void remove_event(timed_event *,timed_event **); /* remove an event from the execution queue */ 511 int event_execution_loop(void); /* main monitoring/event handler loop */ 512 int handle_timed_event(timed_event *); /* top level handler for timed events */ 513 void run_service_check(service *); /* parallelized service check routine */ 514 void reap_service_checks(void); /* handles results from service checks */ 515 int check_service_dependencies(service *,int); /* checks service dependencies */ 516 int check_host_dependencies(host *,int); /* checks host dependencies */ 517 void check_for_orphaned_services(void); /* checks for orphaned services */ 518 void check_service_result_freshness(void); /* checks the "freshness" of service check results */ 519 void check_host_result_freshness(void); /* checks the "freshness" of host check results */ 520 void adjust_check_scheduling(void); /* auto-adjusts scheduling of host and service checks */ 521 int my_system(char *,int,int *,double *,char *,int); /* executes a command via popen(), but also protects against timeouts */ 522 void compensate_for_system_time_change(unsigned long,unsigned long); /* attempts to compensate for a change in the system time */ 523 void adjust_timestamp_for_time_change(time_t,time_t,unsigned long,time_t *); /* adjusts a timestamp variable for a system time change */ 524 void resort_event_list(timed_event **); /* resorts event list by event run time for system time changes */ 525 526 527 /**** Flap Detection Functions ****/ 528 void check_for_service_flapping(service *,int); /* determines whether or not a service is "flapping" between states */ 529 void check_for_host_flapping(host *,int); /* determines whether or not a host is "flapping" between states */ 530 void set_service_flap(service *,double,double,double); /* handles a service that is flapping */ 531 void clear_service_flap(service *,double,double,double); /* handles a service that has stopped flapping */ 532 void set_host_flap(host *,double,double,double); /* handles a host that is flapping */ 533 void clear_host_flap(host *,double,double,double); /* handles a host that has stopped flapping */ 534 void enable_flap_detection_routines(void); /* enables flap detection on a program-wide basis */ 535 void disable_flap_detection_routines(void); /* disables flap detection on a program-wide basis */ 536 void enable_host_flap_detection(host *); /* enables flap detection for a particular host */ 537 void disable_host_flap_detection(host *); /* disables flap detection for a particular host */ 538 void enable_service_flap_detection(service *); /* enables flap detection for a particular service */ 539 void disable_service_flap_detection(service *); /* disables flap detection for a particular service */ 540 541 542 /**** Route/Host Check Functions ****/ 543 int verify_route_to_host(host *,int); /* on-demand check of whether a host is up, down, or unreachable */ 544 int run_scheduled_host_check(host *); /* runs a scheduled host check */ 545 int check_host(host *,int,int); /* checks if a host is up or down */ 546 int run_host_check(host *,int); /* runs a host check */ 547 int handle_host_state(host *); /* top level host state handler */ 548 549 550 /**** Event Handler Functions ****/ 551 int obsessive_compulsive_service_check_processor(service *); /* distributed monitoring craziness... */ 552 int obsessive_compulsive_host_check_processor(host *); /* distributed monitoring craziness... */ 553 int handle_service_event(service *); /* top level service event logic */ 554 int run_service_event_handler(service *); /* runs the event handler for a specific service */ 555 int run_global_service_event_handler(service *); /* runs the global service event handler */ 556 int handle_host_event(host *); /* top level host event logic */ 557 int run_host_event_handler(host *); /* runs the event handler for a specific host */ 558 int run_global_host_event_handler(host *); /* runs the global host event handler */ 559 560 561 /**** Notification Functions ****/ 562 int check_service_notification_viability(service *,int); /* checks viability of notifying all contacts about a service */ 563 int is_valid_escalation_for_service_notification(service *,serviceescalation *); /* checks if an escalation entry is valid for a particular service notification */ 564 int should_service_notification_be_escalated(service *); /* checks if a service notification should be escalated */ 565 int service_notification(service *,int,char *,char *); /* notify all contacts about a service (problem or recovery) */ 566 int check_contact_service_notification_viability(contact *,service *,int); /* checks viability of notifying a contact about a service */ 567 int notify_contact_of_service(contact *,service *,int,char *,char *,int); /* notify a single contact about a service */ 568 int check_host_notification_viability(host *,int); /* checks viability of notifying all contacts about a host */ 569 int is_valid_host_escalation_for_host_notification(host *,hostescalation *); /* checks if an escalation entry is valid for a particular host notification */ 570 int should_host_notification_be_escalated(host *); /* checks if a host notification should be escalated */ 571 int host_notification(host *,int,char *,char *); /* notify all contacts about a host (problem or recovery) */ 572 int check_contact_host_notification_viability(contact *,host *,int); /* checks viability of notifying a contact about a host */ 573 int notify_contact_of_host(contact *,host *,int,char *,char *,int); /* notify a single contact about a host */ 574 int create_notification_list_from_host(host *,int *); /* given a host, create list of contacts to be notified (remove duplicates) */ 575 int create_notification_list_from_service(service *,int *); /* given a service, create list of contacts to be notified (remove duplicates) */ 576 int add_notification(contact *); /* adds a notification instance */ 577 notification * find_notification(char *); /* finds a notification object */ 578 time_t get_next_host_notification_time(host *,time_t); /* calculates nex acceptable re-notification time for a host */ 579 time_t get_next_service_notification_time(service *,time_t); /* calculates nex acceptable re-notification time for a service */ 580 581 582 /**** Logging Functions ****/ 583 int write_to_logs_and_console(char *,unsigned long,int); /* writes a string to screen and logs */ 584 int write_to_console(char *); /* writes a string to screen */ 585 int write_to_all_logs(char *,unsigned long); /* writes a string to main log file and syslog facility */ 586 int write_to_all_logs_with_timestamp(char *,unsigned long,time_t *); /* writes a string to main log file and syslog facility */ 587 int write_to_log(char *,unsigned long,time_t *); /* write a string to the main log file */ 588 int write_to_syslog(char *,unsigned long); /* write a string to the syslog facility */ 589 int log_service_event(service *); /* logs a service event */ 590 int log_host_event(host *); /* logs a host event */ 591 int log_host_states(int,time_t *); /* logs initial/current host states */ 592 int log_service_states(int,time_t *); /* logs initial/current service states */ 593 int rotate_log_file(time_t); /* rotates the main log file */ 594 int write_log_file_info(time_t *); /* records log file/version info */ 595 596 597 /**** Cleanup Functions ****/ 598 void cleanup(void); /* cleanup after ourselves (before quitting or restarting) */ 599 void free_memory(void); /* free memory allocated to all linked lists in memory */ 600 int reset_variables(void); /* reset all global variables */ 601 void free_notification_list(void); /* frees all memory allocated to the notification list */ 602 603 604 /**** Hash Functions ****/ 605 int hashfunc1(const char *name1, int hashslots); 606 int hashfunc2(const char *name1, const char *name2, int hashslots); 607 int compare_hashdata1(const char *,const char *); 608 int compare_hashdata2(const char *,const char *,const char *,const char *); 609 610 611 /**** Miscellaneous Functions ****/ 612 void sighandler(int); /* handles signals */ 613 void service_check_sighandler(int); /* handles timeouts when executing service checks */ 614 void my_system_sighandler(int); /* handles timeouts when executing commands via my_system() */ 615 void file_lock_sighandler(int); /* handles timeouts while waiting for file locks */ 616 void strip(char *); /* strips whitespace from string */ 617 char *my_strtok(char *,char *); /* my replacement for strtok() function (doesn't skip consecutive tokens) */ 618 char *my_strsep(char **,const char *); /* Solaris doesn't have strsep(), so I took this from the glibc source code */ 619 char *get_url_encoded_string(char *); /* URL encode a string */ 620 int contains_illegal_object_chars(char *); /* tests whether or not an object name (host, service, etc.) contains illegal characters */ 621 int my_rename(char *,char *); /* renames a file - works across filesystems */ 622 void get_raw_command_line(char *,char *,int,int); /* given a raw command line, determine the actual command to run */ 623 int check_time_against_period(time_t,char *); /* check to see if a specific time is covered by a time period */ 624 void get_next_valid_time(time_t, time_t *,char *); /* get the next valid time in a time period */ 625 void get_datetime_string(time_t *,char *,int,int); /* get a date/time string for use in output */ 626 time_t get_next_log_rotation_time(void); /* determine the next time to schedule a log rotation */ 627 int init_embedded_perl(char **); /* initialized embedded perl interpreter */ 628 int deinit_embedded_perl(void); /* cleans up embedded perl */ 629 630 631 /**** Macro Functions ****/ 632 int process_macros(char *,char *,int,int); /* replace macros with their actual values */ 633 char *clean_macro_chars(char *,int); /* cleans macros characters before insertion into output string */ 634 int grab_service_macros(service *); /* updates the service macro data */ 635 int grab_host_macros(host *); /* updates the host macro data */ 636 int grab_contact_macros(contact *); /* updates the contact macro data */ 637 int grab_datetime_macros(void); /* updates date/time macros */ 638 int grab_summary_macros(contact *); /* updates summary macros */ 639 int grab_on_demand_macro(char *); /* fetches an on-demand macro */ 640 int grab_on_demand_host_macro(host *,char *); /* fetches an on-demand host macro */ 641 int grab_on_demand_service_macro(service *,char *); /* fetches an on-demand service macro */ 642 int clear_argv_macros(void); /* clear all argv macros used in commands */ 643 int clear_volatile_macros(void); /* clear all "volatile" macros that change between service/host checks */ 644 int clear_nonvolatile_macros(void); /* clear all "nonvolatile" macros which remain relatively constant */ 645 646 647 /**** External Command Functions ****/ 648 void check_for_external_commands(void); /* checks for any external commands */ 649 void process_external_command(int,time_t,char *); /* process an external command */ 650 int process_host_command(int,time_t,char *); /* process an external host command */ 651 int process_hostgroup_command(int,time_t,char *); /* process an external hostgroup command */ 652 int process_service_command(int,time_t,char *); /* process an external service command */ 653 int process_servicegroup_command(int,time_t,char *); /* process an external servicegroup command */ 654 655 656 /**** External Command Implementations ****/ 657 int cmd_add_comment(int,time_t,char *); /* add a service or host comment */ 658 int cmd_delete_comment(int,char *); /* delete a service or host comment */ 659 int cmd_delete_all_comments(int,char *); /* delete all comments associated with a host or service */ 660 int cmd_delay_notification(int,char *); /* delay a service or host notification */ 661 int cmd_schedule_service_check(int,char *,int); /* schedule an immediate or delayed service check */ 662 int cmd_schedule_check(int,char *); /* schedule an immediate or delayed host check */ 663 int cmd_schedule_host_service_checks(int,char *,int); /* schedule an immediate or delayed checks of all services on a host */ 664 int cmd_signal_process(int,char *); /* schedules a program shutdown or restart */ 665 int cmd_process_service_check_result(int,time_t,char *); /* processes a passive service check */ 666 int cmd_process_host_check_result(int,time_t,char *); /* processes a passive host check */ 667 int cmd_acknowledge_problem(int,char *); /* acknowledges a host or service problem */ 668 int cmd_remove_acknowledgement(int,char *); /* removes a host or service acknowledgement */ 669 int cmd_schedule_downtime(int,time_t,char *); /* schedules host or service downtime */ 670 int cmd_delete_downtime(int,char *); /* cancels active/pending host or service scheduled downtime */ 671 int cmd_change_command(int,char *); /* changes host/svc command */ 672 int cmd_change_check_interval(int,char *); /* changes host/svc check interval */ 673 int cmd_change_max_attempts(int,char *); /* changes host/svc max attempts */ 674 675 int process_passive_service_check(time_t,char *,char *,int,char *); 676 int process_passive_host_check(time_t,char *,int,char *); 677 678 679 /**** Internal Command Implementations ****/ 680 void disable_service_checks(service *); /* disables a service check */ 681 void enable_service_checks(service *); /* enables a service check */ 682 void schedule_service_check(service *,time_t,int); /* schedules an immediate or delayed service check */ 683 void schedule_host_check(host *,time_t,int); /* schedules an immediate or delayed host check */ 684 void enable_all_notifications(void); /* enables notifications on a program-wide basis */ 685 void disable_all_notifications(void); /* disables notifications on a program-wide basis */ 686 void enable_service_notifications(service *); /* enables service notifications */ 687 void disable_service_notifications(service *); /* disables service notifications */ 688 void enable_host_notifications(host *); /* enables host notifications */ 689 void disable_host_notifications(host *); /* disables host notifications */ 690 void enable_and_propagate_notifications(host *,int,int,int,int); /* enables notifications for all hosts and services beyond a given host */ 691 void disable_and_propagate_notifications(host *,int,int,int,int); /* disables notifications for all hosts and services beyond a given host */ 692 void schedule_and_propagate_downtime(host *,time_t,char *,char *,time_t,time_t,int,unsigned long,unsigned long); /* schedules downtime for all hosts beyond a given host */ 693 void acknowledge_host_problem(host *,char *,char *,int,int,int); /* acknowledges a host problem */ 694 void acknowledge_service_problem(service *,char *,char *,int,int,int); /* acknowledges a service problem */ 695 void remove_host_acknowledgement(host *); /* removes a host acknowledgement */ 696 void remove_service_acknowledgement(service *); /* removes a service acknowledgement */ 697 void start_executing_service_checks(void); /* starts executing service checks */ 698 void stop_executing_service_checks(void); /* stops executing service checks */ 699 void start_accepting_passive_service_checks(void); /* starts accepting passive service check results */ 700 void stop_accepting_passive_service_checks(void); /* stops accepting passive service check results */ 701 void enable_passive_service_checks(service *); /* enables passive service checks for a particular service */ 702 void disable_passive_service_checks(service *); /* disables passive service checks for a particular service */ 703 void start_using_event_handlers(void); /* enables event handlers on a program-wide basis */ 704 void stop_using_event_handlers(void); /* disables event handlers on a program-wide basis */ 705 void enable_service_event_handler(service *); /* enables the event handler for a particular service */ 706 void disable_service_event_handler(service *); /* disables the event handler for a particular service */ 707 void enable_host_event_handler(host *); /* enables the event handler for a particular host */ 708 void disable_host_event_handler(host *); /* disables the event handler for a particular host */ 709 void enable_host_checks(host *); /* enables checks of a particular host */ 710 void disable_host_checks(host *); /* disables checks of a particular host */ 711 void start_obsessing_over_service_checks(void); /* start obsessing about service check results */ 712 void stop_obsessing_over_service_checks(void); /* stop obsessing about service check results */ 713 void start_obsessing_over_host_checks(void); /* start obsessing about host check results */ 714 void stop_obsessing_over_host_checks(void); /* stop obsessing about host check results */ 715 void enable_service_freshness_checks(void); /* enable service freshness checks */ 716 void disable_service_freshness_checks(void); /* disable service freshness checks */ 717 void enable_host_freshness_checks(void); /* enable host freshness checks */ 718 void disable_host_freshness_checks(void); /* disable host freshness checks */ 719 void process_passive_service_checks(void); /* processes passive service check results */ 720 void enable_all_failure_prediction(void); /* enables failure prediction on a program-wide basis */ 721 void disable_all_failure_prediction(void); /* disables failure prediction on a program-wide basis */ 722 void enable_performance_data(void); /* enables processing of performance data on a program-wide basis */ 723 void disable_performance_data(void); /* disables processing of performance data on a program-wide basis */ 724 void start_executing_host_checks(void); /* starts executing host checks */ 725 void stop_executing_host_checks(void); /* stops executing host checks */ 726 void start_accepting_passive_host_checks(void); /* starts accepting passive host check results */ 727 void stop_accepting_passive_host_checks(void); /* stops accepting passive host check results */ 728 void enable_passive_host_checks(host *); /* enables passive host checks for a particular host */ 729 void disable_passive_host_checks(host *); /* disables passive host checks for a particular host */ 730 void start_obsessing_over_service(service *); /* start obsessing about specific service check results */ 731 void stop_obsessing_over_service(service *); /* stop obsessing about specific service check results */ 732 void start_obsessing_over_host(host *); /* start obsessing about specific host check results */ 733 void stop_obsessing_over_host(host *); /* stop obsessing about specific host check results */ 734 void set_host_notification_number(host *,int); /* sets current notification number for a specific host */ 735 void set_service_notification_number(service *,int); /* sets current notification number for a specific service */ 736 737 int init_service_result_worker_thread(void); 738 int shutdown_service_result_worker_thread(void); 739 void * service_result_worker_thread(void *); 740 void cleanup_service_result_worker_thread(void *); 741 742 int init_command_file_worker_thread(void); 743 int shutdown_command_file_worker_thread(void); 744 void * command_file_worker_thread(void *); 745 void cleanup_command_file_worker_thread(void *); 746 747 int submit_external_command(char *,int *); 748 int submit_raw_external_command(char *,time_t *,int *); 749 750 char *get_program_version(void); 751 char *get_program_modification_date(void); 752 753 mmapfile *mmap_fopen(char *); /* open a file read-only via mmap() */ 754 int mmap_fclose(mmapfile *); 755 char *mmap_fgets(mmapfile *); 756 char *mmap_fgets_multiline(mmapfile *); 757 758 759 int init_macrox_names(void); 760 int add_macrox_name(int,char *); 761 int free_macrox_names(void); 762 int set_all_macro_environment_vars(int); 763 int set_macrox_environment_vars(int); 764 int set_argv_macro_environment_vars(int); 765 int set_macro_environment_var(char *,char *,int); 766 767 #ifdef __cplusplus 768 } 769 #endif 770 #endif 771 772