import: Fix progress output ETA when skipping files
[nagios-reports-module.git] / nagios / nagios.h
blobe8c51f1e8b675363e1d41a92e470fada98c95f1e
1 /************************************************************************
3 * Nagios Main Header File
4 * Written By: Ethan Galstad (nagios@nagios.org)
5 * Last Modified: 04-13-2008
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.
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.
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 ************************************************************************/
21 #ifndef _NAGIOS_H
22 #define _NAGIOS_H
24 #ifndef __GNUC__
25 # define __attribute__(x) /* nothing */
26 #endif
28 #include "config.h"
29 #include "common.h"
30 #include "locations.h"
31 #include "objects.h"
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
38 /************* MISC LENGTH/SIZE DEFINITIONS ***********/
40 /*
41 NOTE: Plugin length is artificially capped at 8k to prevent runaway plugins from returning MBs/GBs of data
42 back to Nagios. If you increase the 8k cap by modifying this value, make sure you also increase the value
43 of MAX_EXTERNAL_COMMAND_LENGTH in common.h to allow for passive checks results received through the external
44 command file. EG 10/19/07
46 #define MAX_PLUGIN_OUTPUT_LENGTH 8192 /* max length of plugin output (including perf data) */
50 /******************* DEFAULT VALUES *******************/
52 #define DEFAULT_LOG_LEVEL 1 /* log all events to main log file */
53 #define DEFAULT_USE_SYSLOG 1 /* log events to syslog? 1=yes, 0=no */
54 #define DEFAULT_SYSLOG_LEVEL 2 /* log only severe events to syslog */
56 #define DEFAULT_NOTIFICATION_LOGGING 1 /* log notification events? 1=yes, 0=no */
58 #define DEFAULT_INTER_CHECK_DELAY 5.0 /* seconds between initial service check scheduling */
59 #define DEFAULT_INTERLEAVE_FACTOR 1 /* default interleave to use when scheduling checks */
60 #define DEFAULT_SLEEP_TIME 0.5 /* seconds between event run checks */
61 #define DEFAULT_INTERVAL_LENGTH 60 /* seconds per interval unit for check scheduling */
62 #define DEFAULT_RETRY_INTERVAL 30 /* services are retried in 30 seconds if they're not OK */
63 #define DEFAULT_COMMAND_CHECK_INTERVAL -1 /* interval to check for external commands (default = as often as possible) */
64 #define DEFAULT_CHECK_REAPER_INTERVAL 10 /* interval in seconds to reap host and service check results */
65 #define DEFAULT_MAX_REAPER_TIME 30 /* maximum number of seconds to spend reaping service checks before we break out for a while */
66 #define DEFAULT_MAX_CHECK_RESULT_AGE 3600 /* maximum number of seconds that a check result file is considered to be valid */
67 #define DEFAULT_MAX_PARALLEL_SERVICE_CHECKS 0 /* maximum number of service checks we can have running at any given time (0=unlimited) */
68 #define DEFAULT_RETENTION_UPDATE_INTERVAL 60 /* minutes between auto-save of retention data */
69 #define DEFAULT_RETENTION_SCHEDULING_HORIZON 900 /* max seconds between program restarts that we will preserve scheduling information */
70 #define DEFAULT_STATUS_UPDATE_INTERVAL 60 /* seconds between aggregated status data updates */
71 #define DEFAULT_FRESHNESS_CHECK_INTERVAL 60 /* seconds between service result freshness checks */
72 #define DEFAULT_AUTO_RESCHEDULING_INTERVAL 30 /* seconds between host and service check rescheduling events */
73 #define DEFAULT_AUTO_RESCHEDULING_WINDOW 180 /* window of time (in seconds) for which we should reschedule host and service checks */
74 #define DEFAULT_ORPHAN_CHECK_INTERVAL 60 /* seconds between checks for orphaned hosts and services */
76 #define DEFAULT_NOTIFICATION_TIMEOUT 30 /* max time in seconds to wait for notification commands to complete */
77 #define DEFAULT_EVENT_HANDLER_TIMEOUT 30 /* max time in seconds to wait for event handler commands to complete */
78 #define DEFAULT_HOST_CHECK_TIMEOUT 30 /* max time in seconds to wait for host check commands to complete */
79 #define DEFAULT_SERVICE_CHECK_TIMEOUT 60 /* max time in seconds to wait for service check commands to complete */
80 #define DEFAULT_OCSP_TIMEOUT 15 /* max time in seconds to wait for obsessive compulsive processing commands to complete */
81 #define DEFAULT_OCHP_TIMEOUT 15 /* max time in seconds to wait for obsessive compulsive processing commands to complete */
82 #define DEFAULT_PERFDATA_TIMEOUT 5 /* max time in seconds to wait for performance data commands to complete */
83 #define DEFAULT_TIME_CHANGE_THRESHOLD 900 /* compensate for time changes of more than 15 minutes */
85 #define DEFAULT_LOG_HOST_RETRIES 0 /* don't log host retries */
86 #define DEFAULT_LOG_SERVICE_RETRIES 0 /* don't log service retries */
87 #define DEFAULT_LOG_EVENT_HANDLERS 1 /* log event handlers */
88 #define DEFAULT_LOG_INITIAL_STATES 0 /* don't log initial service and host states */
89 #define DEFAULT_LOG_EXTERNAL_COMMANDS 1 /* log external commands */
90 #define DEFAULT_LOG_PASSIVE_CHECKS 1 /* log passive service checks */
92 #define DEFAULT_DEBUG_LEVEL 0 /* don't log any debugging information */
93 #define DEFAULT_DEBUG_VERBOSITY 1
94 #define DEFAULT_MAX_DEBUG_FILE_SIZE 1000000 /* max size of debug log */
96 #define DEFAULT_AGGRESSIVE_HOST_CHECKING 0 /* don't use "aggressive" host checking */
97 #define DEFAULT_CHECK_EXTERNAL_COMMANDS 1 /* check for external commands */
98 #define DEFAULT_CHECK_ORPHANED_SERVICES 1 /* check for orphaned services */
99 #define DEFAULT_CHECK_ORPHANED_HOSTS 1 /* check for orphaned hosts */
100 #define DEFAULT_ENABLE_FLAP_DETECTION 0 /* don't enable flap detection */
101 #define DEFAULT_PROCESS_PERFORMANCE_DATA 0 /* don't process performance data */
102 #define DEFAULT_CHECK_SERVICE_FRESHNESS 1 /* check service result freshness */
103 #define DEFAULT_CHECK_HOST_FRESHNESS 0 /* don't check host result freshness */
104 #define DEFAULT_AUTO_RESCHEDULE_CHECKS 0 /* don't auto-reschedule host and service checks */
105 #define DEFAULT_TRANSLATE_PASSIVE_HOST_CHECKS 0 /* should we translate DOWN/UNREACHABLE passive host checks? */
106 #define DEFAULT_PASSIVE_HOST_CHECKS_SOFT 0 /* passive host checks are treated as HARD by default */
108 #define DEFAULT_LOW_SERVICE_FLAP_THRESHOLD 20.0 /* low threshold for detection of service flapping */
109 #define DEFAULT_HIGH_SERVICE_FLAP_THRESHOLD 30.0 /* high threshold for detection of service flapping */
110 #define DEFAULT_LOW_HOST_FLAP_THRESHOLD 20.0 /* low threshold for detection of host flapping */
111 #define DEFAULT_HIGH_HOST_FLAP_THRESHOLD 30.0 /* high threshold for detection of host flapping */
113 #define DEFAULT_HOST_CHECK_SPREAD 30 /* max minutes to schedule all initial host checks */
114 #define DEFAULT_SERVICE_CHECK_SPREAD 30 /* max minutes to schedule all initial service checks */
116 #define DEFAULT_CACHED_HOST_CHECK_HORIZON 15 /* max age in seconds that cached host checks can be used */
117 #define DEFAULT_CACHED_SERVICE_CHECK_HORIZON 15 /* max age in seconds that cached service checks can be used */
118 #define DEFAULT_ENABLE_PREDICTIVE_HOST_DEPENDENCY_CHECKS 1 /* should we use predictive host dependency checks? */
119 #define DEFAULT_ENABLE_PREDICTIVE_SERVICE_DEPENDENCY_CHECKS 1 /* should we use predictive service dependency checks? */
121 #define DEFAULT_USE_LARGE_INSTALLATION_TWEAKS 0 /* don't use tweaks for large Nagios installations */
123 #define DEFAULT_ENABLE_EMBEDDED_PERL 0 /* enable embedded Perl interpreter (if compiled in) */
124 #define DEFAULT_USE_EMBEDDED_PERL_IMPLICITLY 1 /* by default, embedded Perl is used for Perl plugins that don't explicitly disable it */
126 #define DEFAULT_ADDITIONAL_FRESHNESS_LATENCY 15 /* seconds to be added to freshness thresholds when automatically calculated by Nagios */
130 /******************* LOGGING TYPES ********************/
132 #define NSLOG_RUNTIME_ERROR 1
133 #define NSLOG_RUNTIME_WARNING 2
135 #define NSLOG_VERIFICATION_ERROR 4
136 #define NSLOG_VERIFICATION_WARNING 8
138 #define NSLOG_CONFIG_ERROR 16
139 #define NSLOG_CONFIG_WARNING 32
141 #define NSLOG_PROCESS_INFO 64
142 #define NSLOG_EVENT_HANDLER 128
143 /*#define NSLOG_NOTIFICATION 256*/ /* NOT USED ANYMORE - CAN BE REUSED */
144 #define NSLOG_EXTERNAL_COMMAND 512
146 #define NSLOG_HOST_UP 1024
147 #define NSLOG_HOST_DOWN 2048
148 #define NSLOG_HOST_UNREACHABLE 4096
150 #define NSLOG_SERVICE_OK 8192
151 #define NSLOG_SERVICE_UNKNOWN 16384
152 #define NSLOG_SERVICE_WARNING 32768
153 #define NSLOG_SERVICE_CRITICAL 65536
155 #define NSLOG_PASSIVE_CHECK 131072
157 #define NSLOG_INFO_MESSAGE 262144
159 #define NSLOG_HOST_NOTIFICATION 524288
160 #define NSLOG_SERVICE_NOTIFICATION 1048576
163 /***************** DEBUGGING LEVELS *******************/
165 #define DEBUGL_ALL -1
166 #define DEBUGL_NONE 0
167 #define DEBUGL_FUNCTIONS 1
168 #define DEBUGL_CONFIG 2
169 #define DEBUGL_PROCESS 4
170 #define DEBUGL_STATUSDATA 4
171 #define DEBUGL_RETENTIONDATA 4
172 #define DEBUGL_EVENTS 8
173 #define DEBUGL_CHECKS 16
174 #define DEBUGL_IPC 16
175 #define DEBUGL_FLAPPING 16
176 #define DEBUGL_EVENTHANDLERS 16
177 #define DEBUGL_PERFDATA 16
178 #define DEBUGL_NOTIFICATIONS 32
179 #define DEBUGL_EVENTBROKER 64
180 #define DEBUGL_EXTERNALCOMMANDS 128
181 #define DEBUGL_COMMANDS 256
182 #define DEBUGL_DOWNTIME 512
183 #define DEBUGL_COMMENTS 1024
184 #define DEBUGL_MACROS 2048
186 #define DEBUGV_BASIC 0
187 #define DEBUGV_MORE 1
188 #define DEBUGV_MOST 2
191 /******************** HOST STATUS *********************/
193 #define HOST_UP 0
194 #define HOST_DOWN 1
195 #define HOST_UNREACHABLE 2
199 /******************* STATE LOGGING TYPES **************/
201 #define INITIAL_STATES 1
202 #define CURRENT_STATES 2
206 /************ SERVICE DEPENDENCY VALUES ***************/
208 #define DEPENDENCIES_OK 0
209 #define DEPENDENCIES_FAILED 1
213 /*********** ROUTE CHECK PROPAGATION TYPES ************/
215 #define PROPAGATE_TO_PARENT_HOSTS 1
216 #define PROPAGATE_TO_CHILD_HOSTS 2
220 /****************** SERVICE STATES ********************/
222 #define STATE_OK 0
223 #define STATE_WARNING 1
224 #define STATE_CRITICAL 2
225 #define STATE_UNKNOWN 3 /* changed from -1 on 02/24/2001 */
229 /****************** FLAPPING TYPES ********************/
231 #define HOST_FLAPPING 0
232 #define SERVICE_FLAPPING 1
236 /**************** NOTIFICATION TYPES ******************/
238 #define HOST_NOTIFICATION 0
239 #define SERVICE_NOTIFICATION 1
243 /************* NOTIFICATION REASON TYPES ***************/
245 #define NOTIFICATION_NORMAL 0
246 #define NOTIFICATION_ACKNOWLEDGEMENT 1
247 #define NOTIFICATION_FLAPPINGSTART 2
248 #define NOTIFICATION_FLAPPINGSTOP 3
249 #define NOTIFICATION_FLAPPINGDISABLED 4
250 #define NOTIFICATION_DOWNTIMESTART 5
251 #define NOTIFICATION_DOWNTIMEEND 6
252 #define NOTIFICATION_DOWNTIMECANCELLED 7
253 #define NOTIFICATION_CUSTOM 99
257 /**************** EVENT HANDLER TYPES *****************/
259 #define HOST_EVENTHANDLER 0
260 #define SERVICE_EVENTHANDLER 1
261 #define GLOBAL_HOST_EVENTHANDLER 2
262 #define GLOBAL_SERVICE_EVENTHANDLER 3
266 /***************** STATE CHANGE TYPES *****************/
268 #define HOST_STATECHANGE 0
269 #define SERVICE_STATECHANGE 1
273 /***************** OBJECT CHECK TYPES *****************/
274 #define SERVICE_CHECK 0
275 #define HOST_CHECK 1
279 /******************* EVENT TYPES **********************/
281 #define EVENT_SERVICE_CHECK 0 /* active service check */
282 #define EVENT_COMMAND_CHECK 1 /* external command check */
283 #define EVENT_LOG_ROTATION 2 /* log file rotation */
284 #define EVENT_PROGRAM_SHUTDOWN 3 /* program shutdown */
285 #define EVENT_PROGRAM_RESTART 4 /* program restart */
286 #define EVENT_CHECK_REAPER 5 /* reaps results from host and service checks */
287 #define EVENT_ORPHAN_CHECK 6 /* checks for orphaned hosts and services */
288 #define EVENT_RETENTION_SAVE 7 /* save (dump) retention data */
289 #define EVENT_STATUS_SAVE 8 /* save (dump) status data */
290 #define EVENT_SCHEDULED_DOWNTIME 9 /* scheduled host or service downtime */
291 #define EVENT_SFRESHNESS_CHECK 10 /* checks service result "freshness" */
292 #define EVENT_EXPIRE_DOWNTIME 11 /* checks for (and removes) expired scheduled downtime */
293 #define EVENT_HOST_CHECK 12 /* active host check */
294 #define EVENT_HFRESHNESS_CHECK 13 /* checks host result "freshness" */
295 #define EVENT_RESCHEDULE_CHECKS 14 /* adjust scheduling of host and service checks */
296 #define EVENT_EXPIRE_COMMENT 15 /* removes expired comments */
297 #define EVENT_SLEEP 98 /* asynchronous sleep event that occurs when event queues are empty */
298 #define EVENT_USER_FUNCTION 99 /* USER-defined function (modules) */
302 /******* INTER-CHECK DELAY CALCULATION TYPES **********/
304 #define ICD_NONE 0 /* no inter-check delay */
305 #define ICD_DUMB 1 /* dumb delay of 1 second */
306 #define ICD_SMART 2 /* smart delay */
307 #define ICD_USER 3 /* user-specified delay */
311 /******* INTERLEAVE FACTOR CALCULATION TYPES **********/
313 #define ILF_USER 0 /* user-specified interleave factor */
314 #define ILF_SMART 1 /* smart interleave */
318 /************ SCHEDULED DOWNTIME TYPES ****************/
320 #define ACTIVE_DOWNTIME 0 /* active downtime - currently in effect */
321 #define PENDING_DOWNTIME 1 /* pending downtime - scheduled for the future */
325 /****************** DATA STRUCTURES *******************/
327 /* TIMED_EVENT structure */
328 typedef struct timed_event_struct{
329 int event_type;
330 time_t run_time;
331 int recurring;
332 unsigned long event_interval;
333 int compensate_for_time_change;
334 void *timing_func;
335 void *event_data;
336 void *event_args;
337 int event_options;
338 struct timed_event_struct *next;
339 struct timed_event_struct *prev;
340 }timed_event;
343 /* NOTIFY_LIST structure */
344 typedef struct notify_list_struct{
345 contact *contact;
346 struct notify_list_struct *next;
347 }notification;
350 /* CHECK_RESULT structure */
351 typedef struct check_result_struct{
352 int object_check_type; /* is this a service or a host check? */
353 char *host_name; /* host name */
354 char *service_description; /* service description */
355 int check_type; /* was this an active or passive service check? */
356 int check_options;
357 int scheduled_check; /* was this a scheduled or an on-demand check? */
358 int reschedule_check; /* should we reschedule the next check */
359 char *output_file; /* what file is the output stored in? */
360 FILE *output_file_fp;
361 int output_file_fd;
362 double latency;
363 struct timeval start_time; /* time the service check was initiated */
364 struct timeval finish_time; /* time the service check was completed */
365 int early_timeout; /* did the service check timeout? */
366 int exited_ok; /* did the plugin check return okay? */
367 int return_code; /* plugin return code */
368 char *output; /* plugin output */
369 struct check_result_struct *next;
370 }check_result;
373 /* SCHED_INFO structure */
374 typedef struct sched_info_struct{
375 int total_services;
376 int total_scheduled_services;
377 int total_hosts;
378 int total_scheduled_hosts;
379 double average_services_per_host;
380 double average_scheduled_services_per_host;
381 unsigned long service_check_interval_total;
382 unsigned long host_check_interval_total;
383 double average_service_execution_time;
384 double average_service_check_interval;
385 double average_host_check_interval;
386 double average_service_inter_check_delay;
387 double average_host_inter_check_delay;
388 double service_inter_check_delay;
389 double host_inter_check_delay;
390 int service_interleave_factor;
391 int max_service_check_spread;
392 int max_host_check_spread;
393 time_t first_service_check;
394 time_t last_service_check;
395 time_t first_host_check;
396 time_t last_host_check;
397 }sched_info;
400 /* PASSIVE_CHECK_RESULT structure */
401 typedef struct passive_check_result_struct{
402 int object_check_type;
403 char *host_name;
404 char *service_description;
405 int return_code;
406 char *output;
407 time_t check_time;
408 double latency;
409 struct passive_check_result_struct *next;
410 }passive_check_result;
413 /* CIRCULAR_BUFFER structure - used by worker threads */
414 typedef struct circular_buffer_struct{
415 void **buffer;
416 int tail;
417 int head;
418 int items;
419 int high; /* highest number of items that has ever been stored in buffer */
420 unsigned long overflow;
421 pthread_mutex_t buffer_lock;
422 }circular_buffer;
425 /* MMAPFILE structure - used for reading files via mmap() */
426 typedef struct mmapfile_struct{
427 char *path;
428 int mode;
429 int fd;
430 unsigned long file_size;
431 unsigned long current_position;
432 unsigned long current_line;
433 void *mmap_buf;
434 }mmapfile;
437 /* DBUF structure - dynamic string storage */
438 typedef struct dbuf_struct{
439 char *buf;
440 unsigned long used_size;
441 unsigned long allocated_size;
442 unsigned long chunk_size;
443 }dbuf;
446 #define CHECK_STATS_BUCKETS 15
448 /* used for tracking host and service check statistics */
449 typedef struct check_stats_struct{
450 int current_bucket;
451 int bucket[CHECK_STATS_BUCKETS];
452 int overflow_bucket;
453 int minute_stats[3];
454 time_t last_update;
455 }check_stats;
458 /******************* THREAD STUFF ********************/
460 /* slots in circular buffers */
461 #define DEFAULT_EXTERNAL_COMMAND_BUFFER_SLOTS 4096
463 /* worker threads */
464 #define TOTAL_WORKER_THREADS 1
466 #define COMMAND_WORKER_THREAD 0
470 /******************** FUNCTIONS **********************/
472 /**** Configuration Functions ****/
473 int read_main_config_file(char *); /* reads the main config file (nagios.cfg) */
474 int read_resource_file(char *); /* processes macros in resource file */
475 int read_all_object_data(char *); /* reads all object config data */
478 /**** Setup Functions ****/
479 int pre_flight_check(void); /* try and verify the configuration data */
480 int pre_flight_object_check(int *,int *); /* verify object relationships and settings */
481 int pre_flight_circular_check(int *,int *); /* detects circular dependencies and paths */
482 void init_timing_loop(void); /* setup the initial scheduling queue */
483 void setup_sighandler(void); /* trap signals */
484 void reset_sighandler(void); /* reset signals to default action */
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 */
490 /**** Event Queue Functions ****/
491 int schedule_new_event(int,int,time_t,int,unsigned long,void *,int,void *,void *,int); /* schedules a new timed event */
492 void reschedule_event(timed_event *,timed_event **,timed_event **); /* reschedules an event */
493 void add_event(timed_event *,timed_event **,timed_event **); /* adds an event to the execution queue */
494 void remove_event(timed_event *,timed_event **,timed_event **); /* remove an event from the execution queue */
495 int event_execution_loop(void); /* main monitoring/event handler loop */
496 int handle_timed_event(timed_event *); /* top level handler for timed events */
497 void adjust_check_scheduling(void); /* auto-adjusts scheduling of host and service checks */
498 void compensate_for_system_time_change(unsigned long,unsigned long); /* attempts to compensate for a change in the system time */
499 void adjust_timestamp_for_time_change(time_t,time_t,unsigned long,time_t *); /* adjusts a timestamp variable for a system time change */
500 void resort_event_list(timed_event **,timed_event **); /* resorts event list by event run time for system time changes */
503 /**** IPC Functions ****/
504 int move_check_result_to_queue(char *);
505 int process_check_result_queue(char *);
506 int process_check_result_file(char *);
507 int add_check_result_to_list(check_result *);
508 check_result *read_check_result(void); /* reads a host/service check result from the list in memory */
509 int delete_check_result_file(char *);
510 int free_check_result_list(void);
511 int init_check_result(check_result *);
512 int free_check_result(check_result *); /* frees memory associated with a host/service check result */
513 int parse_check_output(char *,char **,char **,char **,int,int);
514 int open_command_file(void); /* creates the external command file as a named pipe (FIFO) and opens it for reading */
515 int close_command_file(void); /* closes and deletes the external command file (FIFO) */
518 /**** Monitoring/Event Handler Functions ****/
519 int check_service_dependencies(service *,int); /* checks service dependencies */
520 int check_host_dependencies(host *,int); /* checks host dependencies */
521 void check_for_orphaned_services(void); /* checks for orphaned services */
522 void check_for_orphaned_hosts(void); /* checks for orphaned hosts */
523 void check_service_result_freshness(void); /* checks the "freshness" of service check results */
524 int is_service_result_fresh(service *,time_t,int); /* determines if a service's check results are fresh */
525 void check_host_result_freshness(void); /* checks the "freshness" of host check results */
526 int is_host_result_fresh(host *,time_t,int); /* determines if a host's check results are fresh */
527 int my_system(char *,int,int *,double *,char **,int); /* executes a command via popen(), but also protects against timeouts */
530 /**** Flap Detection Functions ****/
531 void check_for_service_flapping(service *,int,int); /* determines whether or not a service is "flapping" between states */
532 void check_for_host_flapping(host *,int,int,int); /* determines whether or not a host is "flapping" between states */
533 void set_service_flap(service *,double,double,double,int); /* handles a service that is flapping */
534 void clear_service_flap(service *,double,double,double); /* handles a service that has stopped flapping */
535 void set_host_flap(host *,double,double,double,int); /* handles a host that is flapping */
536 void clear_host_flap(host *,double,double,double); /* handles a host that has stopped flapping */
537 void enable_flap_detection_routines(void); /* enables flap detection on a program-wide basis */
538 void disable_flap_detection_routines(void); /* disables flap detection on a program-wide basis */
539 void enable_host_flap_detection(host *); /* enables flap detection for a particular host */
540 void disable_host_flap_detection(host *); /* disables flap detection for a particular host */
541 void enable_service_flap_detection(service *); /* enables flap detection for a particular service */
542 void disable_service_flap_detection(service *); /* disables flap detection for a particular service */
543 void handle_host_flap_detection_disabled(host *); /* handles the details when flap detection is disabled globally or on a per-host basis */
544 void handle_service_flap_detection_disabled(service *); /* handles the details when flap detection is disabled globally or on a per-service basis */
547 /**** Route/Host Check Functions ****/
548 int perform_on_demand_host_check(host *,int *,int,int,unsigned long);
549 int perform_scheduled_host_check(host *,int,double);
550 int check_host_check_viability_3x(host *,int,int *,time_t *);
551 int adjust_host_check_attempt_3x(host *,int);
552 int determine_host_reachability(host *);
553 int process_host_check_result_3x(host *,int,char *,int,int,int,unsigned long);
554 int perform_on_demand_host_check_3x(host *,int *,int,int,unsigned long);
555 int run_sync_host_check_3x(host *,int *,int,int,unsigned long);
556 int execute_sync_host_check_3x(host *);
557 int run_scheduled_host_check_3x(host *,int,double);
558 int run_async_host_check_3x(host *,int,double,int,int,int *,time_t *);
559 int handle_async_host_check_result_3x(host *,check_result *);
562 /**** Service Check Functions ****/
563 int check_service_check_viability(service *,int,int *,time_t *);
564 int run_scheduled_service_check(service *,int,double);
565 int run_async_service_check(service *,int,double,int,int,int *,time_t *);
566 int handle_async_service_check_result(service *,check_result *);
569 /**** Event Handler Functions ****/
570 int handle_host_state(host *); /* top level host state handler */
574 /**** Common Check Fucntions *****/
575 int reap_check_results(void);
578 /**** Check Statistics Functions ****/
579 int init_check_stats(void);
580 int update_check_stats(int,time_t);
581 int generate_check_stats(void);
585 /**** Event Handler Functions ****/
586 int obsessive_compulsive_service_check_processor(service *); /* distributed monitoring craziness... */
587 int obsessive_compulsive_host_check_processor(host *); /* distributed monitoring craziness... */
588 int handle_service_event(service *); /* top level service event logic */
589 int run_service_event_handler(service *); /* runs the event handler for a specific service */
590 int run_global_service_event_handler(service *); /* runs the global service event handler */
591 int handle_host_event(host *); /* top level host event logic */
592 int run_host_event_handler(host *); /* runs the event handler for a specific host */
593 int run_global_host_event_handler(host *); /* runs the global host event handler */
596 /**** Notification Functions ****/
597 int check_service_notification_viability(service *,int,int); /* checks viability of notifying all contacts about a service */
598 int is_valid_escalation_for_service_notification(service *,serviceescalation *,int); /* checks if an escalation entry is valid for a particular service notification */
599 int should_service_notification_be_escalated(service *); /* checks if a service notification should be escalated */
600 int service_notification(service *,int,char *,char *,int); /* notify all contacts about a service (problem or recovery) */
601 int check_contact_service_notification_viability(contact *,service *,int,int); /* checks viability of notifying a contact about a service */
602 int notify_contact_of_service(contact *,service *,int,char *,char *,int,int); /* notify a single contact about a service */
603 int check_host_notification_viability(host *,int,int); /* checks viability of notifying all contacts about a host */
604 int is_valid_escalation_for_host_notification(host *,hostescalation *,int); /* checks if an escalation entry is valid for a particular host notification */
605 int should_host_notification_be_escalated(host *); /* checks if a host notification should be escalated */
606 int host_notification(host *,int,char *,char *,int); /* notify all contacts about a host (problem or recovery) */
607 int check_contact_host_notification_viability(contact *,host *,int,int); /* checks viability of notifying a contact about a host */
608 int notify_contact_of_host(contact *,host *,int,char *,char *,int,int); /* notify a single contact about a host */
609 int create_notification_list_from_host(host *,int,int *); /* given a host, create list of contacts to be notified (remove duplicates) */
610 int create_notification_list_from_service(service *,int,int *); /* given a service, create list of contacts to be notified (remove duplicates) */
611 int add_notification(contact *); /* adds a notification instance */
612 notification *find_notification(contact *); /* finds a notification object */
613 time_t get_next_host_notification_time(host *,time_t); /* calculates nex acceptable re-notification time for a host */
614 time_t get_next_service_notification_time(service *,time_t); /* calculates nex acceptable re-notification time for a service */
617 /**** Logging Functions ****/
618 void logit(int,int,const char *, ...)
619 __attribute__((__format__(__printf__, 3, 4)));
620 int write_to_logs_and_console(char *,unsigned long,int); /* writes a string to screen and logs */
621 int write_to_console(char *); /* writes a string to screen */
622 int write_to_all_logs(char *,unsigned long); /* writes a string to main log file and syslog facility */
623 int write_to_all_logs_with_timestamp(char *,unsigned long,time_t *); /* writes a string to main log file and syslog facility */
624 int write_to_log(char *,unsigned long,time_t *); /* write a string to the main log file */
625 int write_to_syslog(char *,unsigned long); /* write a string to the syslog facility */
626 int log_service_event(service *); /* logs a service event */
627 int log_host_event(host *); /* logs a host event */
628 int log_host_states(int,time_t *); /* logs initial/current host states */
629 int log_service_states(int,time_t *); /* logs initial/current service states */
630 int rotate_log_file(time_t); /* rotates the main log file */
631 int write_log_file_info(time_t *); /* records log file/version info */
632 int open_debug_log(void);
633 int log_debug_info(int,int,const char *,...)
634 __attribute__((__format__(__printf__, 3, 4)));
635 int close_debug_log(void);
638 /**** Cleanup Functions ****/
639 void cleanup(void); /* cleanup after ourselves (before quitting or restarting) */
640 void free_memory(void); /* free memory allocated to all linked lists in memory */
641 int reset_variables(void); /* reset all global variables */
642 void free_notification_list(void); /* frees all memory allocated to the notification list */
645 /**** Hash Functions ****/
646 int hashfunc(const char *name1, const char *name2, int hashslots);
647 int compare_hashdata(const char *,const char *,const char *,const char *);
650 /**** Miscellaneous Functions ****/
651 void sighandler(int); /* handles signals */
652 void service_check_sighandler(int); /* handles timeouts when executing service checks */
653 void host_check_sighandler(int); /* handles timeouts when executing host checks */
654 void my_system_sighandler(int); /* handles timeouts when executing commands via my_system() */
655 void file_lock_sighandler(int); /* handles timeouts while waiting for file locks */
656 void strip(char *); /* strips whitespace from string */
657 char *my_strtok(char *,char *); /* my replacement for strtok() function (doesn't skip consecutive tokens) */
658 char *my_strsep(char **,const char *); /* Solaris doesn't have strsep(), so I took this from the glibc source code */
659 #ifdef REMOVED_10182007
660 int my_free(void **); /* my wrapper for free() */
661 #endif
662 int compare_strings(char *,char *); /* compares two strings for equality */
663 char *escape_newlines(char *);
664 int contains_illegal_object_chars(char *); /* tests whether or not an object name (host, service, etc.) contains illegal characters */
665 int my_rename(char *,char *); /* renames a file - works across filesystems */
666 int my_fcopy(char *,char *); /* copies a file - works across filesystems */
667 int get_raw_command_line(command *,char *,char **,int); /* given a raw command line, determine the actual command to run */
668 int check_time_against_period(time_t,timeperiod *); /* check to see if a specific time is covered by a time period */
669 int is_daterange_single_day(daterange *);
670 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 */
671 time_t calculate_time_from_day_of_month(int,int,int); /* calculates midnight time of specific (1st, last, etc.) day of a particular month */
672 void get_next_valid_time(time_t, time_t *,timeperiod *); /* get the next valid time in a time period */
673 void get_datetime_string(time_t *,char *,int,int); /* get a date/time string for use in output */
674 void get_time_breakdown(unsigned long,int *,int *,int *, int *);
675 time_t get_next_log_rotation_time(void); /* determine the next time to schedule a log rotation */
676 int init_embedded_perl(char **); /* initialized embedded perl interpreter */
677 int deinit_embedded_perl(void); /* cleans up embedded perl */
678 int file_uses_embedded_perl(char *); /* tests whether or not the embedded perl interpreter should be used on a file */
679 int dbuf_init(dbuf *,int);
680 int dbuf_free(dbuf *);
681 int dbuf_strcat(dbuf *,char *);
682 int set_environment_var(char *,char *,int); /* sets/clears and environment variable */
685 /**** External Command Functions ****/
686 int check_for_external_commands(void); /* checks for any external commands */
687 int process_external_command1(char *); /* top-level external command processor */
688 int process_external_command2(int,time_t,char *); /* process an external command */
689 int process_external_commands_from_file(char *,int); /* process external commands in a file */
690 int process_host_command(int,time_t,char *); /* process an external host command */
691 int process_hostgroup_command(int,time_t,char *); /* process an external hostgroup command */
692 int process_service_command(int,time_t,char *); /* process an external service command */
693 int process_servicegroup_command(int,time_t,char *); /* process an external servicegroup command */
694 int process_contact_command(int,time_t,char *); /* process an external contact command */
695 int process_contactgroup_command(int,time_t,char *); /* process an external contactgroup command */
698 /**** External Command Implementations ****/
699 int cmd_add_comment(int,time_t,char *); /* add a service or host comment */
700 int cmd_delete_comment(int,char *); /* delete a service or host comment */
701 int cmd_delete_all_comments(int,char *); /* delete all comments associated with a host or service */
702 int cmd_delay_notification(int,char *); /* delay a service or host notification */
703 int cmd_schedule_service_check(int,char *,int); /* schedule an immediate or delayed service check */
704 int cmd_schedule_check(int,char *); /* schedule an immediate or delayed host check */
705 int cmd_schedule_host_service_checks(int,char *,int); /* schedule an immediate or delayed checks of all services on a host */
706 int cmd_signal_process(int,char *); /* schedules a program shutdown or restart */
707 int cmd_process_service_check_result(int,time_t,char *); /* processes a passive service check */
708 int cmd_process_host_check_result(int,time_t,char *); /* processes a passive host check */
709 int cmd_acknowledge_problem(int,char *); /* acknowledges a host or service problem */
710 int cmd_remove_acknowledgement(int,char *); /* removes a host or service acknowledgement */
711 int cmd_schedule_downtime(int,time_t,char *); /* schedules host or service downtime */
712 int cmd_delete_downtime(int,char *); /* cancels active/pending host or service scheduled downtime */
713 int cmd_change_object_int_var(int,char *); /* changes host/svc (int) variable */
714 int cmd_change_object_char_var(int,char *); /* changes host/svc (char) variable */
715 int cmd_change_object_custom_var(int,char *); /* changes host/svc custom variable */
716 int cmd_process_external_commands_from_file(int,char *); /* process external commands from a file */
718 int process_passive_service_check(time_t,char *,char *,int,char *);
719 int process_passive_host_check(time_t,char *,int,char *);
722 /**** Internal Command Implementations ****/
723 void disable_service_checks(service *); /* disables a service check */
724 void enable_service_checks(service *); /* enables a service check */
725 void schedule_service_check(service *,time_t,int); /* schedules an immediate or delayed service check */
726 void schedule_host_check(host *,time_t,int); /* schedules an immediate or delayed host check */
727 void enable_all_notifications(void); /* enables notifications on a program-wide basis */
728 void disable_all_notifications(void); /* disables notifications on a program-wide basis */
729 void enable_service_notifications(service *); /* enables service notifications */
730 void disable_service_notifications(service *); /* disables service notifications */
731 void enable_host_notifications(host *); /* enables host notifications */
732 void disable_host_notifications(host *); /* disables host notifications */
733 void enable_and_propagate_notifications(host *,int,int,int,int); /* enables notifications for all hosts and services beyond a given host */
734 void disable_and_propagate_notifications(host *,int,int,int,int); /* disables notifications for all hosts and services beyond a given host */
735 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 */
736 void acknowledge_host_problem(host *,char *,char *,int,int,int); /* acknowledges a host problem */
737 void acknowledge_service_problem(service *,char *,char *,int,int,int); /* acknowledges a service problem */
738 void remove_host_acknowledgement(host *); /* removes a host acknowledgement */
739 void remove_service_acknowledgement(service *); /* removes a service acknowledgement */
740 void start_executing_service_checks(void); /* starts executing service checks */
741 void stop_executing_service_checks(void); /* stops executing service checks */
742 void start_accepting_passive_service_checks(void); /* starts accepting passive service check results */
743 void stop_accepting_passive_service_checks(void); /* stops accepting passive service check results */
744 void enable_passive_service_checks(service *); /* enables passive service checks for a particular service */
745 void disable_passive_service_checks(service *); /* disables passive service checks for a particular service */
746 void start_using_event_handlers(void); /* enables event handlers on a program-wide basis */
747 void stop_using_event_handlers(void); /* disables event handlers on a program-wide basis */
748 void enable_service_event_handler(service *); /* enables the event handler for a particular service */
749 void disable_service_event_handler(service *); /* disables the event handler for a particular service */
750 void enable_host_event_handler(host *); /* enables the event handler for a particular host */
751 void disable_host_event_handler(host *); /* disables the event handler for a particular host */
752 void enable_host_checks(host *); /* enables checks of a particular host */
753 void disable_host_checks(host *); /* disables checks of a particular host */
754 void start_obsessing_over_service_checks(void); /* start obsessing about service check results */
755 void stop_obsessing_over_service_checks(void); /* stop obsessing about service check results */
756 void start_obsessing_over_host_checks(void); /* start obsessing about host check results */
757 void stop_obsessing_over_host_checks(void); /* stop obsessing about host check results */
758 void enable_service_freshness_checks(void); /* enable service freshness checks */
759 void disable_service_freshness_checks(void); /* disable service freshness checks */
760 void enable_host_freshness_checks(void); /* enable host freshness checks */
761 void disable_host_freshness_checks(void); /* disable host freshness checks */
762 void process_passive_checks(void); /* processes passive host and service check results */
763 void enable_all_failure_prediction(void); /* enables failure prediction on a program-wide basis */
764 void disable_all_failure_prediction(void); /* disables failure prediction on a program-wide basis */
765 void enable_performance_data(void); /* enables processing of performance data on a program-wide basis */
766 void disable_performance_data(void); /* disables processing of performance data on a program-wide basis */
767 void start_executing_host_checks(void); /* starts executing host checks */
768 void stop_executing_host_checks(void); /* stops executing host checks */
769 void start_accepting_passive_host_checks(void); /* starts accepting passive host check results */
770 void stop_accepting_passive_host_checks(void); /* stops accepting passive host check results */
771 void enable_passive_host_checks(host *); /* enables passive host checks for a particular host */
772 void disable_passive_host_checks(host *); /* disables passive host checks for a particular host */
773 void start_obsessing_over_service(service *); /* start obsessing about specific service check results */
774 void stop_obsessing_over_service(service *); /* stop obsessing about specific service check results */
775 void start_obsessing_over_host(host *); /* start obsessing about specific host check results */
776 void stop_obsessing_over_host(host *); /* stop obsessing about specific host check results */
777 void set_host_notification_number(host *,int); /* sets current notification number for a specific host */
778 void set_service_notification_number(service *,int); /* sets current notification number for a specific service */
779 void enable_contact_host_notifications(contact *); /* enables host notifications for a specific contact */
780 void disable_contact_host_notifications(contact *); /* disables host notifications for a specific contact */
781 void enable_contact_service_notifications(contact *); /* enables service notifications for a specific contact */
782 void disable_contact_service_notifications(contact *); /* disables service notifications for a specific contact */
784 int init_check_result_worker_thread(void);
785 int shutdown_check_result_worker_thread(void);
786 void * check_result_worker_thread(void *);
787 void cleanup_check_result_worker_thread(void *);
789 int init_command_file_worker_thread(void);
790 int shutdown_command_file_worker_thread(void);
791 void * command_file_worker_thread(void *);
792 void cleanup_command_file_worker_thread(void *);
794 int submit_external_command(char *,int *);
795 int submit_raw_external_command(char *,time_t *,int *);
797 char *get_program_version(void);
798 char *get_program_modification_date(void);
800 mmapfile *mmap_fopen(char *); /* open a file read-only via mmap() */
801 int mmap_fclose(mmapfile *);
802 char *mmap_fgets(mmapfile *);
803 char *mmap_fgets_multiline(mmapfile *);
806 #ifdef __cplusplus
808 #endif
809 #endif