1 /************************************************************************ 2 * 3 * Nagios Main Header File 4 * Written By: Ethan Galstad (egalstad@nagios.org) 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 2 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 ************************************************************************/ 19 20 #ifndef NAGIOS_NAGIOS_H_INCLUDED 21 #define NAGIOS_NAGIOS_H_INCLUDED 22 23 #ifndef NSCORE 24 # define NSCORE 25 #endif 26 27 #include "defaults.h" 28 #include "common.h" 29 #include "logging.h" 30 #include "locations.h" 31 #include "objects.h" 32 #include "macros.h" 33 34 /* 35 * global variables only used in the core. Reducing this list would be 36 * a Good Thing(tm). 37 */ 38 extern char *nagios_binary_path; 39 extern char *config_file; 40 extern char *command_file; 41 extern char *temp_file; 42 extern char *temp_path; 43 extern char *check_result_path; 44 extern char *lock_file; 45 extern char *object_precache_file; 46 47 extern unsigned int nofile_limit, nproc_limit, max_apps; 48 49 extern int num_check_workers; 50 extern char *qh_socket_path; 51 52 extern char *nagios_user; 53 extern char *nagios_group; 54 55 extern char *macro_user[MAX_USER_MACROS]; 56 57 extern char *ocsp_command; 58 extern char *ochp_command; 59 extern command *ocsp_command_ptr; 60 extern command *ochp_command_ptr; 61 extern int ocsp_timeout; 62 extern int ochp_timeout; 63 64 extern char *global_host_event_handler; 65 extern char *global_service_event_handler; 66 extern command *global_host_event_handler_ptr; 67 extern command *global_service_event_handler_ptr; 68 69 extern char *illegal_object_chars; 70 71 extern int use_regexp_matches; 72 extern int use_true_regexp_matching; 73 74 extern int use_syslog; 75 extern char *log_file; 76 extern char *log_archive_path; 77 extern int log_notifications; 78 extern int log_service_retries; 79 extern int log_host_retries; 80 extern int log_event_handlers; 81 extern int log_external_commands; 82 extern int log_passive_checks; 83 extern unsigned long logging_options; 84 extern unsigned long syslog_options; 85 86 extern int service_check_timeout; 87 extern int service_check_timeout_state; 88 extern int host_check_timeout; 89 extern int event_handler_timeout; 90 extern int notification_timeout; 91 92 extern int log_initial_states; 93 extern int log_current_states; 94 95 extern int daemon_dumps_core; 96 extern int sig_id; 97 extern int caught_signal; 98 99 100 extern int verify_config; 101 extern int test_scheduling; 102 extern int precache_objects; 103 extern int use_precached_objects; 104 105 extern int service_inter_check_delay_method; 106 extern int host_inter_check_delay_method; 107 extern int service_interleave_factor_method; 108 extern int max_host_check_spread; 109 extern int max_service_check_spread; 110 111 extern sched_info scheduling_info; 112 113 extern int max_parallel_service_checks; 114 115 extern int check_reaper_interval; 116 extern int max_check_reaper_time; 117 extern int service_freshness_check_interval; 118 extern int host_freshness_check_interval; 119 extern int auto_rescheduling_interval; 120 extern int auto_rescheduling_window; 121 122 extern int check_orphaned_services; 123 extern int check_orphaned_hosts; 124 extern int check_service_freshness; 125 extern int check_host_freshness; 126 extern int auto_reschedule_checks; 127 128 extern int additional_freshness_latency; 129 130 extern int check_for_updates; 131 extern int bare_update_check; 132 extern time_t last_update_check; 133 extern unsigned long update_uid; 134 extern int update_available; 135 extern char *last_program_version; 136 extern char *new_program_version; 137 138 extern int use_aggressive_host_checking; 139 extern time_t cached_host_check_horizon; 140 extern time_t cached_service_check_horizon; 141 extern int enable_predictive_host_dependency_checks; 142 extern int enable_predictive_service_dependency_checks; 143 144 extern int soft_state_dependencies; 145 146 extern int retain_state_information; 147 extern int retention_update_interval; 148 extern int use_retained_program_state; 149 extern int use_retained_scheduling_info; 150 extern int retention_scheduling_horizon; 151 extern char *retention_file; 152 extern unsigned long retained_host_attribute_mask; 153 extern unsigned long retained_service_attribute_mask; 154 extern unsigned long retained_contact_host_attribute_mask; 155 extern unsigned long retained_contact_service_attribute_mask; 156 extern unsigned long retained_process_host_attribute_mask; 157 extern unsigned long retained_process_service_attribute_mask; 158 159 extern int translate_passive_host_checks; 160 extern int passive_host_checks_are_soft; 161 162 extern int status_update_interval; 163 extern char *retention_file; 164 165 extern int time_change_threshold; 166 167 extern unsigned long event_broker_options; 168 169 extern double low_service_flap_threshold; 170 extern double high_service_flap_threshold; 171 extern double low_host_flap_threshold; 172 extern double high_host_flap_threshold; 173 174 extern int use_large_installation_tweaks; 175 extern int enable_environment_macros; 176 extern int free_child_process_memory; 177 extern int child_processes_fork_twice; 178 179 extern char *use_timezone; 180 181 extern time_t max_check_result_file_age; 182 183 extern char *debug_file; 184 extern int debug_level; 185 extern int debug_verbosity; 186 extern unsigned long max_debug_file_size; 187 188 extern int allow_empty_hostgroup_assignment; 189 190 extern int host_down_disable_service_checks; 191 192 extern time_t last_program_stop; 193 extern time_t event_start; 194 195 extern int sigshutdown, sigrestart; 196 extern int currently_running_service_checks; 197 extern int currently_running_host_checks; 198 199 extern unsigned long next_event_id; 200 extern unsigned long next_problem_id; 201 extern unsigned long next_comment_id; 202 extern unsigned long next_notification_id; 203 204 extern unsigned long modified_process_attributes; 205 extern unsigned long modified_host_process_attributes; 206 extern unsigned long modified_service_process_attributes; 207 208 extern squeue_t *nagios_squeue; 209 extern iobroker_set *nagios_iobs; 210 211 extern struct check_stats check_statistics[MAX_CHECK_STATS_TYPES]; 212 213 /*** perfdata variables ***/ 214 extern int perfdata_timeout; 215 extern char *host_perfdata_command; 216 extern char *service_perfdata_command; 217 extern char *host_perfdata_file_template; 218 extern char *service_perfdata_file_template; 219 extern char *host_perfdata_file; 220 extern char *service_perfdata_file; 221 extern int host_perfdata_file_append; 222 extern int service_perfdata_file_append; 223 extern int host_perfdata_file_pipe; 224 extern int service_perfdata_file_pipe; 225 extern unsigned long host_perfdata_file_processing_interval; 226 extern unsigned long service_perfdata_file_processing_interval; 227 extern char *host_perfdata_file_processing_command; 228 extern char *service_perfdata_file_processing_command; 229 extern int host_perfdata_process_empty_results; 230 extern int service_perfdata_process_empty_results; 231 /*** end perfdata variables */ 232 233 extern struct notify_list *notification_list; 234 235 extern struct check_engine nagios_check_engine; 236 237 /* 238 * Everything we need to keep system load in check. 239 * Don't use this from modules. 240 */ 241 struct load_control { 242 time_t last_check; /* last time we checked the real load */ 243 time_t last_change; /* last time we changed settings */ 244 time_t check_interval; /* seconds between load checks */ 245 double load[3]; /* system load, as reported by getloadavg() */ 246 float backoff_limit; /* limit we must reach before we back off */ 247 float rampup_limit; /* limit we must reach before we ramp back up */ 248 unsigned int backoff_change; /* backoff by this much */ 249 unsigned int rampup_change; /* ramp up by this much */ 250 unsigned int changes; /* number of times we've changed settings */ 251 unsigned int jobs_max; /* upper setting for jobs_limit */ 252 unsigned int jobs_limit; /* current limit */ 253 unsigned int jobs_min; /* lower setting for jobs_limit */ 254 unsigned int jobs_running; /* jobs currently running */ 255 unsigned int nproc_limit; /* rlimit for user processes */ 256 unsigned int nofile_limit; /* rlimit for open files */ 257 unsigned int options; /* various option flags */ 258 }; 259 extern struct load_control loadctl; 260 261 /* options for load control */ 262 #define LOADCTL_ENABLED (1 << 0) 263 264 265 /************* MISC LENGTH/SIZE DEFINITIONS ***********/ 266 267 /* 268 NOTE: Plugin length is artificially capped at 8k to prevent runaway plugins from returning MBs/GBs of data 269 back to Nagios. If you increase the 8k cap by modifying this value, make sure you also increase the value 270 of MAX_EXTERNAL_COMMAND_LENGTH in common.h to allow for passive checks results received through the external 271 command file. EG 10/19/07 272 */ 273 #define MAX_PLUGIN_OUTPUT_LENGTH 8192 /* max length of plugin output (including perf data) */ 274 275 276 /******************* STATE LOGGING TYPES **************/ 277 278 #define INITIAL_STATES 1 279 #define CURRENT_STATES 2 280 281 282 283 /************ SERVICE DEPENDENCY VALUES ***************/ 284 285 #define DEPENDENCIES_OK 0 286 #define DEPENDENCIES_FAILED 1 287 288 289 290 /*********** ROUTE CHECK PROPAGATION TYPES ************/ 291 292 #define PROPAGATE_TO_PARENT_HOSTS 1 293 #define PROPAGATE_TO_CHILD_HOSTS 2 294 295 296 297 /****************** FLAPPING TYPES ********************/ 298 299 #define HOST_FLAPPING 0 300 #define SERVICE_FLAPPING 1 301 302 303 304 /**************** NOTIFICATION TYPES ******************/ 305 306 #define HOST_NOTIFICATION 0 307 #define SERVICE_NOTIFICATION 1 308 309 310 311 /************* NOTIFICATION REASON TYPES ***************/ 312 313 #define NOTIFICATION_NORMAL 0 314 #define NOTIFICATION_ACKNOWLEDGEMENT 1 315 #define NOTIFICATION_FLAPPINGSTART 2 316 #define NOTIFICATION_FLAPPINGSTOP 3 317 #define NOTIFICATION_FLAPPINGDISABLED 4 318 #define NOTIFICATION_DOWNTIMESTART 5 319 #define NOTIFICATION_DOWNTIMEEND 6 320 #define NOTIFICATION_DOWNTIMECANCELLED 7 321 #define NOTIFICATION_CUSTOM 8 322 323 324 325 /**************** EVENT HANDLER TYPES *****************/ 326 327 #define HOST_EVENTHANDLER 0 328 #define SERVICE_EVENTHANDLER 1 329 #define GLOBAL_HOST_EVENTHANDLER 2 330 #define GLOBAL_SERVICE_EVENTHANDLER 3 331 332 333 334 /***************** STATE CHANGE TYPES *****************/ 335 336 #define HOST_STATECHANGE 0 337 #define SERVICE_STATECHANGE 1 338 339 340 341 /***************** OBJECT CHECK TYPES *****************/ 342 #define SERVICE_CHECK 0 343 #define HOST_CHECK 1 344 345 346 347 /******************* EVENT TYPES **********************/ 348 349 #define EVENT_SERVICE_CHECK 0 /* active service check */ 350 #define EVENT_COMMAND_CHECK 1 /* external command check */ 351 #define EVENT_LOG_ROTATION 2 /* log file rotation */ 352 #define EVENT_PROGRAM_SHUTDOWN 3 /* program shutdown */ 353 #define EVENT_PROGRAM_RESTART 4 /* program restart */ 354 #define EVENT_CHECK_REAPER 5 /* reaps results from host and service checks */ 355 #define EVENT_ORPHAN_CHECK 6 /* checks for orphaned hosts and services */ 356 #define EVENT_RETENTION_SAVE 7 /* save (dump) retention data */ 357 #define EVENT_STATUS_SAVE 8 /* save (dump) status data */ 358 #define EVENT_SCHEDULED_DOWNTIME 9 /* scheduled host or service downtime */ 359 #define EVENT_SFRESHNESS_CHECK 10 /* checks service result "freshness" */ 360 #define EVENT_EXPIRE_DOWNTIME 11 /* checks for (and removes) expired scheduled downtime */ 361 #define EVENT_HOST_CHECK 12 /* active host check */ 362 #define EVENT_HFRESHNESS_CHECK 13 /* checks host result "freshness" */ 363 #define EVENT_RESCHEDULE_CHECKS 14 /* adjust scheduling of host and service checks */ 364 #define EVENT_EXPIRE_COMMENT 15 /* removes expired comments */ 365 #define EVENT_CHECK_PROGRAM_UPDATE 16 /* checks for new version of Nagios */ 366 #define EVENT_SLEEP 98 /* asynchronous sleep event that occurs when event queues are empty */ 367 #define EVENT_USER_FUNCTION 99 /* USER-defined function (modules) */ 368 369 /* 370 * VERSIONFIX: Make EVENT_SLEEP and EVENT_USER_FUNCTION appear 371 * linearly in order. 372 */ 373 374 #define EVENT_TYPE_STR(type) ( \ 375 type == EVENT_SERVICE_CHECK ? "SERVICE_CHECK" : \ 376 type == EVENT_COMMAND_CHECK ? "COMMAND_CHECK" : \ 377 type == EVENT_LOG_ROTATION ? "LOG_ROTATION" : \ 378 type == EVENT_PROGRAM_SHUTDOWN ? "PROGRAM_SHUTDOWN" : \ 379 type == EVENT_PROGRAM_RESTART ? "PROGRAM_RESTART" : \ 380 type == EVENT_CHECK_REAPER ? "CHECK_REAPER" : \ 381 type == EVENT_ORPHAN_CHECK ? "ORPHAN_CHECK" : \ 382 type == EVENT_RETENTION_SAVE ? "RETENTION_SAVE" : \ 383 type == EVENT_STATUS_SAVE ? "STATUS_SAVE" : \ 384 type == EVENT_SCHEDULED_DOWNTIME ? "SCHEDULED_DOWNTIME" : \ 385 type == EVENT_SFRESHNESS_CHECK ? "SFRESHNESS_CHECK" : \ 386 type == EVENT_EXPIRE_DOWNTIME ? "EXPIRE_DOWNTIME" : \ 387 type == EVENT_HOST_CHECK ? "HOST_CHECK" : \ 388 type == EVENT_HFRESHNESS_CHECK ? "HFRESHNESS_CHECK" : \ 389 type == EVENT_RESCHEDULE_CHECKS ? "RESCHEDULE_CHECKS" : \ 390 type == EVENT_EXPIRE_COMMENT ? "EXPIRE_COMMENT" : \ 391 type == EVENT_CHECK_PROGRAM_UPDATE ? "CHECK_PROGRAM_UPDATE" : \ 392 type == EVENT_SLEEP ? "SLEEP" : \ 393 type == EVENT_USER_FUNCTION ? "USER_FUNCTION" : \ 394 "UNKNOWN" \ 395 ) 396 397 398 399 /******* INTER-CHECK DELAY CALCULATION TYPES **********/ 400 401 #define ICD_NONE 0 /* no inter-check delay */ 402 #define ICD_DUMB 1 /* dumb delay of 1 second */ 403 #define ICD_SMART 2 /* smart delay */ 404 #define ICD_USER 3 /* user-specified delay */ 405 406 407 408 /******* INTERLEAVE FACTOR CALCULATION TYPES **********/ 409 410 #define ILF_USER 0 /* user-specified interleave factor */ 411 #define ILF_SMART 1 /* smart interleave */ 412 413 414 415 /************ SCHEDULED DOWNTIME TYPES ****************/ 416 417 #define ACTIVE_DOWNTIME 0 /* active downtime - currently in effect */ 418 #define PENDING_DOWNTIME 1 /* pending downtime - scheduled for the future */ 419 420 421 NAGIOS_BEGIN_DECL 422 423 /* useful for hosts and services to determine time 'til next check */ 424 #define normal_check_window(o) ((time_t)(o->check_interval * interval_length)) 425 #define retry_check_window(o) ((time_t)(o->retry_interval * interval_length)) 426 #define check_window(o) \ 427 ((o->current_state && o->state_type == SOFT_STATE) ? \ 428 retry_check_window(o) : \ 429 normal_check_window(o)) 430 431 /** Nerd subscription type */ 432 struct nerd_subscription { 433 int sd; 434 struct nerd_channel *chan; 435 char *format; /* requested format (macro string) for this subscription */ 436 }; 437 438 /******************** FUNCTIONS **********************/ 439 extern int set_loadctl_options(char *opts, unsigned int len); 440 441 /* silly helpers useful pretty much all over the place */ 442 extern const char *service_state_name(int state); 443 extern const char *host_state_name(int state); 444 extern const char *state_type_name(int state_type); 445 extern const char *check_type_name(int check_type); 446 extern const char *check_result_source(check_result *cr); 447 448 /*** Nagios Event Radio Dispatcher functions ***/ 449 extern int nerd_init(void); 450 extern int nerd_mkchan(const char *name, const char *description, int (*handler)(int, void *), unsigned int callbacks); 451 extern int nerd_cancel_subscriber(int sd); 452 extern int nerd_get_channel_id(const char *chan_name); 453 extern objectlist *nerd_get_subscriptions(int chan_id); 454 extern int nerd_broadcast(unsigned int chan_id, void *buf, unsigned int len); 455 456 /*** Query Handler functions, types and macros*/ 457 typedef int (*qh_handler)(int, char *, unsigned int); 458 extern int dump_event_stats(int sd); 459 460 /* return codes for query_handlers() */ 461 #define QH_OK 0 /* keep listening */ 462 #define QH_CLOSE 1 /* we should close the socket */ 463 #define QH_INVALID 2 /* invalid query. Log and close */ 464 #define QH_TAKEOVER 3 /* handler will take full control. de-register but don't close */ 465 extern int qh_init(const char *path); 466 extern void qh_deinit(const char *path); 467 extern int qh_register_handler(const char *name, const char *description, unsigned int options, qh_handler handler); 468 extern const char *qh_strerror(int code); 469 470 /**** Configuration Functions ****/ 471 int read_main_config_file(char *); /* reads the main config file (nagios.cfg) */ 472 int read_resource_file(char *); /* processes macros in resource file */ 473 int read_all_object_data(char *); /* reads all object config data */ 474 475 476 /**** Setup Functions ****/ 477 int pre_flight_check(void); /* try and verify the configuration data */ 478 int pre_flight_object_check(int *, int *); /* verify object relationships and settings */ 479 int pre_flight_circular_check(int *, int *); /* detects circular dependencies and paths */ 480 void init_timing_loop(void); /* setup the initial scheduling queue */ 481 void setup_sighandler(void); /* trap signals */ 482 void reset_sighandler(void); /* reset signals to default action */ 483 extern void handle_sigxfsz(int); /* handle SIGXFSZ */ 484 485 int daemon_init(void); /* switches to daemon mode */ 486 int drop_privileges(char *, char *); /* drops privileges before startup */ 487 void display_scheduling_info(void); /* displays service check scheduling information */ 488 void init_main_cfg_vars(int); /* Initialize the non-shared main configuration variables */ 489 490 491 /**** Event Queue Functions ****/ 492 int init_event_queue(void); /* creates the queue nagios_squeue */ 493 timed_event *schedule_new_event(int, int, time_t, int, unsigned long, void *, int, void *, void *, int); /* schedules a new timed event */ 494 void reschedule_event(squeue_t *sq, timed_event *event); /* reschedules an event */ 495 void add_event(squeue_t *sq, timed_event *event); /* adds an event to the execution queue */ 496 void remove_event(squeue_t *sq, timed_event *event); /* remove an event from the execution queue */ 497 int event_execution_loop(void); /* main monitoring/event handler loop */ 498 int handle_timed_event(timed_event *); /* top level handler for timed events */ 499 void adjust_check_scheduling(void); /* auto-adjusts scheduling of host and service checks */ 500 void compensate_for_system_time_change(unsigned long, unsigned long); /* attempts to compensate for a change in the system time */ 501 void adjust_timestamp_for_time_change(time_t, time_t, unsigned long, time_t *); /* adjusts a timestamp variable for a system time change */ 502 503 504 /**** IPC Functions ****/ 505 int process_check_result_queue(char *); 506 int process_check_result_file(char *); 507 int process_check_result(check_result *); 508 int delete_check_result_file(char *); 509 int init_check_result(check_result *); 510 int free_check_result(check_result *); /* frees memory associated with a host/service check result */ 511 int parse_check_output(char *, char **, char **, char **, int, int); 512 int open_command_file(void); /* creates the external command file as a named pipe (FIFO) and opens it for reading */ 513 int close_command_file(void); /* closes and deletes the external command file (FIFO) */ 514 515 516 /**** Monitoring/Event Handler Functions ****/ 517 int check_service_dependencies(service *, int); /* checks service dependencies */ 518 int check_host_dependencies(host *, int); /* checks host dependencies */ 519 void check_for_orphaned_services(void); /* checks for orphaned services */ 520 void check_for_orphaned_hosts(void); /* checks for orphaned hosts */ 521 void check_service_result_freshness(void); /* checks the "freshness" of service check results */ 522 int is_service_result_fresh(service *, time_t, int); /* determines if a service's check results are fresh */ 523 void check_host_result_freshness(void); /* checks the "freshness" of host check results */ 524 int is_host_result_fresh(host *, time_t, int); /* determines if a host's check results are fresh */ 525 int my_system(char *, int, int *, double *, char **, int); /* executes a command via popen(), but also protects against timeouts */ 526 int my_system_r(nagios_macros *mac, char *, int, int *, double *, char **, int); /* thread-safe version of the above */ 527 528 529 /**** Flap Detection Functions ****/ 530 void check_for_service_flapping(service *, int, int); /* determines whether or not a service is "flapping" between states */ 531 void check_for_host_flapping(host *, int, int, int); /* determines whether or not a host is "flapping" between states */ 532 void set_service_flap(service *, double, double, double, int); /* handles a service that is flapping */ 533 void clear_service_flap(service *, double, double, double, int); /* handles a service that has stopped flapping */ 534 void set_host_flap(host *, double, double, double, int); /* handles a host that is flapping */ 535 void clear_host_flap(host *, double, double, double, int); /* handles a host that has stopped flapping */ 536 void enable_flap_detection_routines(void); /* enables flap detection on a program-wide basis */ 537 void disable_flap_detection_routines(void); /* disables flap detection on a program-wide basis */ 538 void enable_host_flap_detection(host *); /* enables flap detection for a particular host */ 539 void disable_host_flap_detection(host *); /* disables flap detection for a particular host */ 540 void enable_service_flap_detection(service *); /* enables flap detection for a particular service */ 541 void disable_service_flap_detection(service *); /* disables flap detection for a particular service */ 542 void handle_host_flap_detection_disabled(host *); /* handles the details when flap detection is disabled globally or on a per-host basis */ 543 void handle_service_flap_detection_disabled(service *); /* handles the details when flap detection is disabled globally or on a per-service basis */ 544 545 546 /**** Route/Host Check Functions ****/ 547 int check_host_check_viability(host *, int, int *, time_t *); 548 int adjust_host_check_attempt(host *, int); 549 int determine_host_reachability(host *); 550 int process_host_check_result(host *, int, char *, int, int, int, unsigned long); 551 int perform_on_demand_host_check(host *, int *, int, int, unsigned long); 552 int execute_sync_host_check(host *); 553 int run_scheduled_host_check(host *, int, double); 554 int run_async_host_check(host *, int, double, int, int, int *, time_t *); 555 int handle_async_host_check_result(host *, check_result *); 556 557 558 /**** Service Check Functions ****/ 559 int check_service_check_viability(service *, int, int *, time_t *); 560 int run_scheduled_service_check(service *, int, double); 561 int run_async_service_check(service *, int, double, int, int, int *, time_t *); 562 int handle_async_service_check_result(service *, check_result *); 563 564 565 /**** Event Handler Functions ****/ 566 int handle_host_state(host *); /* top level host state handler */ 567 568 569 /**** Common Check Functions *****/ 570 int reap_check_results(void); 571 572 573 /**** Check Statistics Functions ****/ 574 int init_check_stats(void); 575 int update_check_stats(int, time_t); 576 int generate_check_stats(void); 577 578 579 /**** Event Handler Functions ****/ 580 int obsessive_compulsive_service_check_processor(service *); /* distributed monitoring craziness... */ 581 int obsessive_compulsive_host_check_processor(host *); /* distributed monitoring craziness... */ 582 int handle_service_event(service *); /* top level service event logic */ 583 int run_service_event_handler(nagios_macros *mac, service *); /* runs the event handler for a specific service */ 584 int run_global_service_event_handler(nagios_macros *mac, service *); /* runs the global service event handler */ 585 int handle_host_event(host *); /* top level host event logic */ 586 int run_host_event_handler(nagios_macros *mac, host *); /* runs the event handler for a specific host */ 587 int run_global_host_event_handler(nagios_macros *mac, host *); /* runs the global host event handler */ 588 589 590 /**** Notification Functions ****/ 591 const char *notification_reason_name(unsigned int reason_type); 592 int check_service_notification_viability(service *, int, int); /* checks viability of notifying all contacts about a service */ 593 int is_valid_escalation_for_service_notification(service *, serviceescalation *, int); /* checks if an escalation entry is valid for a particular service notification */ 594 int should_service_notification_be_escalated(service *); /* checks if a service notification should be escalated */ 595 int service_notification(service *, int, char *, char *, int); /* notify all contacts about a service (problem or recovery) */ 596 int check_contact_service_notification_viability(contact *, service *, int, int); /* checks viability of notifying a contact about a service */ 597 int notify_contact_of_service(nagios_macros *mac, contact *, service *, int, char *, char *, int, int); /* notify a single contact about a service */ 598 int check_host_notification_viability(host *, int, int); /* checks viability of notifying all contacts about a host */ 599 int is_valid_escalation_for_host_notification(host *, hostescalation *, int); /* checks if an escalation entry is valid for a particular host notification */ 600 int should_host_notification_be_escalated(host *); /* checks if a host notification should be escalated */ 601 int host_notification(host *, int, char *, char *, int); /* notify all contacts about a host (problem or recovery) */ 602 int check_contact_host_notification_viability(contact *, host *, int, int); /* checks viability of notifying a contact about a host */ 603 int notify_contact_of_host(nagios_macros *mac, contact *, host *, int, char *, char *, int, int); /* notify a single contact about a host */ 604 int create_notification_list_from_host(nagios_macros *mac, host *,int,int *,int); /* given a host, create list of contacts to be notified (remove duplicates) */ 605 int create_notification_list_from_service(nagios_macros *mac, service *,int,int *,int); /* given a service, create list of contacts to be notified (remove duplicates) */ 606 int add_notification(nagios_macros *mac, contact *); /* adds a notification instance */ 607 notification *find_notification(contact *); /* finds a notification object */ 608 time_t get_next_host_notification_time(host *, time_t); /* calculates nex acceptable re-notification time for a host */ 609 time_t get_next_service_notification_time(service *, time_t); /* calculates nex acceptable re-notification time for a service */ 610 611 612 /**** Cleanup Functions ****/ 613 void cleanup(void); /* cleanup after ourselves (before quitting or restarting) */ 614 void free_memory(nagios_macros *mac); /* free memory allocated to all linked lists in memory */ 615 int reset_variables(void); /* reset all global variables */ 616 void free_notification_list(void); /* frees all memory allocated to the notification list */ 617 618 619 /**** Miscellaneous Functions ****/ 620 void sighandler(int); /* handles signals */ 621 void my_system_sighandler(int); /* handles timeouts when executing commands via my_system() */ 622 char *get_next_string_from_buf(char *buf, int *start_index, int bufsize); 623 int compare_strings(char *, char *); /* compares two strings for equality */ 624 char *escape_newlines(char *); 625 /** 626 * Unescapes newlines and backslashes in a check result output string read from 627 * a source that uses newlines as a delimiter (e.g., files in the checkresults 628 * spool dir, or the command pipe). 629 * @note: There is an unescape_newlines() in cgi/cgiutils.c that unescapes more 630 * than '\\' and '\n' in place. Since this function is specifically intended 631 * for processing escaped plugin output, we'll use a more specific name to 632 * avoid confusion and conflicts. 633 * @param rawbuf Input string tp unescape. 634 * @return An unescaped copy of rawbuf in a newly allocated string, or NULL if 635 * rawbuf is NULL or no memory could be allocated for the new string. 636 */ 637 char *unescape_check_result_output(const char *rawbuf); 638 639 int contains_illegal_object_chars(char *); /* tests whether or not an object name (host, service, etc.) contains illegal characters */ 640 int my_rename(char *, char *); /* renames a file - works across filesystems */ 641 int my_fcopy(char *, char *); /* copies a file - works across filesystems */ 642 int my_fdcopy(char *, char *, int); /* copies a named source to an already opened destination file */ 643 644 /* thread-safe version of get_raw_command_line_r() */ 645 extern int get_raw_command_line_r(nagios_macros *mac, command *, char *, char **, int); 646 647 /* 648 * given a raw command line, determine the actual command to run 649 * Manipulates global_macros.argv and is thus not threadsafe 650 */ 651 extern int get_raw_command_line(command *, char *, char **, int); 652 653 int check_time_against_period(time_t, timeperiod *); /* check to see if a specific time is covered by a time period */ 654 int is_daterange_single_day(daterange *); 655 time_t calculate_time_from_weekday_of_month(int, int, int, int); /* calculates midnight time of specific (3rd, last, etc.) weekday of a particular month */ 656 time_t calculate_time_from_day_of_month(int, int, int); /* calculates midnight time of specific (1st, last, etc.) day of a particular month */ 657 void get_next_valid_time(time_t, time_t *, timeperiod *); /* get the next valid time in a time period */ 658 time_t get_next_log_rotation_time(void); /* determine the next time to schedule a log rotation */ 659 int dbuf_init(dbuf *, int); 660 int dbuf_free(dbuf *); 661 int dbuf_strcat(dbuf *, const char *); 662 int set_environment_var(char *, char *, int); /* sets/clears and environment variable */ 663 int check_for_nagios_updates(int, int); /* checks to see if new version of Nagios are available */ 664 int query_update_api(void); /* checks to see if new version of Nagios are available */ 665 666 667 /**** External Command Functions ****/ 668 int process_external_command1(char *); /* top-level external command processor */ 669 int process_external_command2(int, time_t, char *); /* process an external command */ 670 int process_external_commands_from_file(char *, int); /* process external commands in a file */ 671 int process_host_command(int, time_t, char *); /* process an external host command */ 672 int process_hostgroup_command(int, time_t, char *); /* process an external hostgroup command */ 673 int process_service_command(int, time_t, char *); /* process an external service command */ 674 int process_servicegroup_command(int, time_t, char *); /* process an external servicegroup command */ 675 int process_contact_command(int, time_t, char *); /* process an external contact command */ 676 int process_contactgroup_command(int, time_t, char *); /* process an external contactgroup command */ 677 678 679 /**** External Command Implementations ****/ 680 int cmd_add_comment(int, time_t, char *); /* add a service or host comment */ 681 int cmd_delete_comment(int, char *); /* delete a service or host comment */ 682 int cmd_delete_all_comments(int, char *); /* delete all comments associated with a host or service */ 683 int cmd_delay_notification(int, char *); /* delay a service or host notification */ 684 int cmd_schedule_check(int, char *); /* schedule an immediate or delayed host check */ 685 int cmd_schedule_host_service_checks(int, char *, int); /* schedule an immediate or delayed checks of all services on a host */ 686 int cmd_signal_process(int, char *); /* schedules a program shutdown or restart */ 687 int cmd_process_service_check_result(int, time_t, char *); /* processes a passive service check */ 688 int cmd_process_host_check_result(int, time_t, char *); /* processes a passive host check */ 689 int cmd_acknowledge_problem(int, char *); /* acknowledges a host or service problem */ 690 int cmd_remove_acknowledgement(int, char *); /* removes a host or service acknowledgement */ 691 int cmd_schedule_downtime(int, time_t, char *); /* schedules host or service downtime */ 692 int cmd_delete_downtime(int, char *); /* cancels active/pending host or service scheduled downtime */ 693 int cmd_change_object_int_var(int, char *); /* changes host/svc (int) variable */ 694 int cmd_change_object_char_var(int, char *); /* changes host/svc (char) variable */ 695 int cmd_change_object_custom_var(int, char *); /* changes host/svc custom variable */ 696 int cmd_process_external_commands_from_file(int, char *); /* process external commands from a file */ 697 int cmd_delete_downtime_by_start_time_comment(int, char *); 698 int cmd_delete_downtime_by_host_name(int, char *); 699 int cmd_delete_downtime_by_hostgroup_name(int, char *); 700 701 int process_passive_service_check(time_t, char *, char *, int, char *); 702 int process_passive_host_check(time_t, char *, int, char *); 703 704 705 /**** Internal Command Implementations ****/ 706 void disable_service_checks(service *); /* disables a service check */ 707 void enable_service_checks(service *); /* enables a service check */ 708 void schedule_service_check(service *, time_t, int); /* schedules an immediate or delayed service check */ 709 void schedule_host_check(host *, time_t, int); /* schedules an immediate or delayed host check */ 710 void enable_all_notifications(void); /* enables notifications on a program-wide basis */ 711 void disable_all_notifications(void); /* disables notifications on a program-wide basis */ 712 void enable_service_notifications(service *); /* enables service notifications */ 713 void disable_service_notifications(service *); /* disables service notifications */ 714 void enable_host_notifications(host *); /* enables host notifications */ 715 void disable_host_notifications(host *); /* disables host notifications */ 716 void enable_and_propagate_notifications(host *, int, int, int, int); /* enables notifications for all hosts and services beyond a given host */ 717 void disable_and_propagate_notifications(host *, int, int, int, int); /* disables notifications for all hosts and services beyond a given host */ 718 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 */ 719 void acknowledge_host_problem(host *, char *, char *, int, int, int); /* acknowledges a host problem */ 720 void acknowledge_service_problem(service *, char *, char *, int, int, int); /* acknowledges a service problem */ 721 void remove_host_acknowledgement(host *); /* removes a host acknowledgement */ 722 void remove_service_acknowledgement(service *); /* removes a service acknowledgement */ 723 void start_executing_service_checks(void); /* starts executing service checks */ 724 void stop_executing_service_checks(void); /* stops executing service checks */ 725 void start_accepting_passive_service_checks(void); /* starts accepting passive service check results */ 726 void stop_accepting_passive_service_checks(void); /* stops accepting passive service check results */ 727 void enable_passive_service_checks(service *); /* enables passive service checks for a particular service */ 728 void disable_passive_service_checks(service *); /* disables passive service checks for a particular service */ 729 void start_using_event_handlers(void); /* enables event handlers on a program-wide basis */ 730 void stop_using_event_handlers(void); /* disables event handlers on a program-wide basis */ 731 void enable_service_event_handler(service *); /* enables the event handler for a particular service */ 732 void disable_service_event_handler(service *); /* disables the event handler for a particular service */ 733 void enable_host_event_handler(host *); /* enables the event handler for a particular host */ 734 void disable_host_event_handler(host *); /* disables the event handler for a particular host */ 735 void enable_host_checks(host *); /* enables checks of a particular host */ 736 void disable_host_checks(host *); /* disables checks of a particular host */ 737 void start_obsessing_over_service_checks(void); /* start obsessing about service check results */ 738 void stop_obsessing_over_service_checks(void); /* stop obsessing about service check results */ 739 void start_obsessing_over_host_checks(void); /* start obsessing about host check results */ 740 void stop_obsessing_over_host_checks(void); /* stop obsessing about host check results */ 741 void enable_service_freshness_checks(void); /* enable service freshness checks */ 742 void disable_service_freshness_checks(void); /* disable service freshness checks */ 743 void enable_host_freshness_checks(void); /* enable host freshness checks */ 744 void disable_host_freshness_checks(void); /* disable host freshness checks */ 745 void enable_performance_data(void); /* enables processing of performance data on a program-wide basis */ 746 void disable_performance_data(void); /* disables processing of performance data on a program-wide basis */ 747 void start_executing_host_checks(void); /* starts executing host checks */ 748 void stop_executing_host_checks(void); /* stops executing host checks */ 749 void start_accepting_passive_host_checks(void); /* starts accepting passive host check results */ 750 void stop_accepting_passive_host_checks(void); /* stops accepting passive host check results */ 751 void enable_passive_host_checks(host *); /* enables passive host checks for a particular host */ 752 void disable_passive_host_checks(host *); /* disables passive host checks for a particular host */ 753 void start_obsessing_over_service(service *); /* start obsessing about specific service check results */ 754 void stop_obsessing_over_service(service *); /* stop obsessing about specific service check results */ 755 void start_obsessing_over_host(host *); /* start obsessing about specific host check results */ 756 void stop_obsessing_over_host(host *); /* stop obsessing about specific host check results */ 757 void set_host_notification_number(host *, int); /* sets current notification number for a specific host */ 758 void set_service_notification_number(service *, int); /* sets current notification number for a specific service */ 759 void enable_contact_host_notifications(contact *); /* enables host notifications for a specific contact */ 760 void disable_contact_host_notifications(contact *); /* disables host notifications for a specific contact */ 761 void enable_contact_service_notifications(contact *); /* enables service notifications for a specific contact */ 762 void disable_contact_service_notifications(contact *); /* disables service notifications for a specific contact */ 763 764 int launch_command_file_worker(void); 765 int shutdown_command_file_worker(void); 766 767 char *get_program_version(void); 768 char *get_program_modification_date(void); 769 770 NAGIOS_END_DECL 771 #endif 772 773