nagios.h

Go to the documentation of this file.
00001 /************************************************************************
00002  *
00003  * Nagios Main Header File
00004  * Written By: Ethan Galstad (nagios@nagios.org)
00005  * Last Modified: 12-12-2007
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License version 2 as
00009  * published by the Free Software Foundation.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  ************************************************************************/
00020 
00021 #ifndef _NAGIOS_H
00022 #define _NAGIOS_H
00023 
00024 #ifndef __GNUC__
00025 # define __attribute__(x) /* nothing */
00026 #endif
00027 
00028 #include "config.h"
00029 #include "common.h"
00030 #include "locations.h"
00031 #include "objects.h"
00032 
00033 #ifdef __cplusplus
00034 extern "C" { 
00035 #endif
00036 
00037 
00038 /************* MISC LENGTH/SIZE DEFINITIONS ***********/
00039 
00040 /* 
00041    NOTE: Plugin length is artificially capped at 8k to prevent runaway plugins from returning MBs/GBs of data
00042    back to Nagios.  If you increase the 8k cap by modifying this value, make sure you also increase the value
00043    of MAX_EXTERNAL_COMMAND_LENGTH in common.h to allow for passive checks results received through the external
00044    command file. EG 10/19/07
00045 */
00046 #define MAX_PLUGIN_OUTPUT_LENGTH                8192    /* max length of plugin output (including perf data) */
00047 
00048 
00049 
00050 /******************* DEFAULT VALUES *******************/
00051 
00052 #define DEFAULT_LOG_LEVEL              1  /* log all events to main log file */
00053 #define DEFAULT_USE_SYSLOG             1  /* log events to syslog? 1=yes, 0=no */
00054 #define DEFAULT_SYSLOG_LEVEL              2  /* log only severe events to syslog */
00055 
00056 #define DEFAULT_NOTIFICATION_LOGGING            1  /* log notification events? 1=yes, 0=no */
00057 
00058 #define DEFAULT_INTER_CHECK_DELAY            5.0   /* seconds between initial service check scheduling */
00059 #define DEFAULT_INTERLEAVE_FACTOR                  1       /* default interleave to use when scheduling checks */
00060 #define DEFAULT_SLEEP_TIME                0.5      /* seconds between event run checks */
00061 #define DEFAULT_INTERVAL_LENGTH           60       /* seconds per interval unit for check scheduling */
00062 #define DEFAULT_RETRY_INTERVAL            30 /* services are retried in 30 seconds if they're not OK */
00063 #define DEFAULT_COMMAND_CHECK_INTERVAL          -1 /* interval to check for external commands (default = as often as possible) */
00064 #define DEFAULT_CHECK_REAPER_INTERVAL           10 /* interval in seconds to reap host and service check results */
00065 #define DEFAULT_MAX_REAPER_TIME                       30      /* maximum number of seconds to spend reaping service checks before we break out for a while */
00066 #define DEFAULT_MAX_CHECK_RESULT_AGE            3600    /* maximum number of seconds that a check result file is considered to be valid */
00067 #define DEFAULT_MAX_PARALLEL_SERVICE_CHECKS        0  /* maximum number of service checks we can have running at any given time (0=unlimited) */
00068 #define DEFAULT_RETENTION_UPDATE_INTERVAL       60 /* minutes between auto-save of retention data */
00069 #define DEFAULT_RETENTION_SCHEDULING_HORIZON          900     /* max seconds between program restarts that we will preserve scheduling information */
00070 #define DEFAULT_STATUS_UPDATE_INTERVAL          60 /* seconds between aggregated status data updates */
00071 #define DEFAULT_FRESHNESS_CHECK_INTERVAL              60      /* seconds between service result freshness checks */
00072 #define DEFAULT_AUTO_RESCHEDULING_INTERVAL            30      /* seconds between host and service check rescheduling events */
00073 #define DEFAULT_AUTO_RESCHEDULING_WINDOW              180     /* window of time (in seconds) for which we should reschedule host and service checks */
00074 #define DEFAULT_ORPHAN_CHECK_INTERVAL                 60      /* seconds between checks for orphaned hosts and services */
00075 
00076 #define DEFAULT_NOTIFICATION_TIMEOUT            30 /* max time in seconds to wait for notification commands to complete */
00077 #define DEFAULT_EVENT_HANDLER_TIMEOUT           30 /* max time in seconds to wait for event handler commands to complete */
00078 #define DEFAULT_HOST_CHECK_TIMEOUT           30 /* max time in seconds to wait for host check commands to complete */
00079 #define DEFAULT_SERVICE_CHECK_TIMEOUT           60 /* max time in seconds to wait for service check commands to complete */
00080 #define DEFAULT_OCSP_TIMEOUT              15 /* max time in seconds to wait for obsessive compulsive processing commands to complete */
00081 #define DEFAULT_OCHP_TIMEOUT              15 /* max time in seconds to wait for obsessive compulsive processing commands to complete */
00082 #define DEFAULT_PERFDATA_TIMEOUT                      5       /* max time in seconds to wait for performance data commands to complete */
00083 #define DEFAULT_TIME_CHANGE_THRESHOLD           900   /* compensate for time changes of more than 15 minutes */
00084 
00085 #define DEFAULT_LOG_HOST_RETRIES          0  /* don't log host retries */
00086 #define DEFAULT_LOG_SERVICE_RETRIES          0  /* don't log service retries */
00087 #define DEFAULT_LOG_EVENT_HANDLERS           1  /* log event handlers */
00088 #define DEFAULT_LOG_INITIAL_STATES           0  /* don't log initial service and host states */
00089 #define DEFAULT_LOG_EXTERNAL_COMMANDS           1  /* log external commands */
00090 #define DEFAULT_LOG_PASSIVE_CHECKS           1  /* log passive service checks */
00091 
00092 #define DEFAULT_DEBUG_LEVEL                                     0       /* don't log any debugging information */
00093 #define DEFAULT_DEBUG_VERBOSITY                                 1
00094 #define DEFAULT_MAX_DEBUG_FILE_SIZE                             1000000 /* max size of debug log */
00095 
00096 #define DEFAULT_AGGRESSIVE_HOST_CHECKING        0  /* don't use "aggressive" host checking */
00097 #define DEFAULT_CHECK_EXTERNAL_COMMANDS            1  /* check for external commands */
00098 #define DEFAULT_CHECK_ORPHANED_SERVICES            1  /* check for orphaned services */
00099 #define DEFAULT_CHECK_ORPHANED_HOSTS                  1       /* check for orphaned hosts */
00100 #define DEFAULT_ENABLE_FLAP_DETECTION                 0       /* don't enable flap detection */
00101 #define DEFAULT_PROCESS_PERFORMANCE_DATA              0       /* don't process performance data */
00102 #define DEFAULT_CHECK_SERVICE_FRESHNESS               1       /* check service result freshness */
00103 #define DEFAULT_CHECK_HOST_FRESHNESS                  0       /* don't check host result freshness */
00104 #define DEFAULT_AUTO_RESCHEDULE_CHECKS                0       /* don't auto-reschedule host and service checks */
00105 #define DEFAULT_TRANSLATE_PASSIVE_HOST_CHECKS                   0       /* should we translate DOWN/UNREACHABLE passive host checks? */
00106 #define DEFAULT_PASSIVE_HOST_CHECKS_SOFT                        0       /* passive host checks are treated as HARD by default */
00107 
00108 #define DEFAULT_LOW_SERVICE_FLAP_THRESHOLD         20.0  /* low threshold for detection of service flapping */
00109 #define DEFAULT_HIGH_SERVICE_FLAP_THRESHOLD        30.0  /* high threshold for detection of service flapping */
00110 #define DEFAULT_LOW_HOST_FLAP_THRESHOLD            20.0  /* low threshold for detection of host flapping */
00111 #define DEFAULT_HIGH_HOST_FLAP_THRESHOLD        30.0  /* high threshold for detection of host flapping */
00112 
00113 #define DEFAULT_HOST_CHECK_SPREAD            30 /* max minutes to schedule all initial host checks */
00114 #define DEFAULT_SERVICE_CHECK_SPREAD            30 /* max minutes to schedule all initial service checks */
00115 
00116 #define DEFAULT_CACHED_HOST_CHECK_HORIZON             15      /* max age in seconds that cached host checks can be used */
00117 #define DEFAULT_CACHED_SERVICE_CHECK_HORIZON          15      /* max age in seconds that cached service checks can be used */
00118 #define DEFAULT_ENABLE_PREDICTIVE_HOST_DEPENDENCY_CHECKS 1  /* should we use predictive host dependency checks? */
00119 #define DEFAULT_ENABLE_PREDICTIVE_SERVICE_DEPENDENCY_CHECKS 1  /* should we use predictive service dependency checks? */
00120 
00121 #define DEFAULT_USE_LARGE_INSTALLATION_TWEAKS                   0       /* don't use tweaks for large Nagios installations */
00122 
00123 #define DEFAULT_ENABLE_EMBEDDED_PERL                            1       /* enable embedded Perl interpreter (if compiled in) */
00124 #define DEFAULT_USE_EMBEDDED_PERL_IMPLICITLY                    1       /* by default, embedded Perl is used for Perl plugins that don't explicitly disable it */
00125 
00126 #define DEFAULT_ADDITIONAL_FRESHNESS_LATENCY       15 /* seconds to be added to freshness thresholds when automatically calculated by Nagios */
00127 
00128 
00129 
00130 /******************* LOGGING TYPES ********************/
00131 
00132 #define NSLOG_RUNTIME_ERROR      1
00133 #define NSLOG_RUNTIME_WARNING    2
00134 
00135 #define NSLOG_VERIFICATION_ERROR 4
00136 #define NSLOG_VERIFICATION_WARNING  8
00137 
00138 #define NSLOG_CONFIG_ERROR    16
00139 #define NSLOG_CONFIG_WARNING     32
00140 
00141 #define NSLOG_PROCESS_INFO    64
00142 #define NSLOG_EVENT_HANDLER      128
00143 /*#define NSLOG_NOTIFICATION     256*/ /* NOT USED ANYMORE - CAN BE REUSED */
00144 #define NSLOG_EXTERNAL_COMMAND      512
00145 
00146 #define NSLOG_HOST_UP            1024
00147 #define NSLOG_HOST_DOWN       2048
00148 #define NSLOG_HOST_UNREACHABLE      4096
00149 
00150 #define NSLOG_SERVICE_OK      8192
00151 #define NSLOG_SERVICE_UNKNOWN    16384
00152 #define NSLOG_SERVICE_WARNING    32768
00153 #define NSLOG_SERVICE_CRITICAL      65536
00154 
00155 #define NSLOG_PASSIVE_CHECK      131072
00156 
00157 #define NSLOG_INFO_MESSAGE    262144
00158 
00159 #define NSLOG_HOST_NOTIFICATION     524288
00160 #define NSLOG_SERVICE_NOTIFICATION  1048576
00161 
00162 
00163 /***************** DEBUGGING LEVELS *******************/
00164 
00165 #define DEBUGL_ALL                      -1
00166 #define DEBUGL_NONE                     0
00167 #define DEBUGL_FUNCTIONS                1
00168 #define DEBUGL_CONFIG         2
00169 #define DEBUGL_PROCESS                  4
00170 #define DEBUGL_STATUSDATA               4
00171 #define DEBUGL_RETENTIONDATA            4
00172 #define DEBUGL_EVENTS                   8
00173 #define DEBUGL_CHECKS                   16
00174 #define DEBUGL_IPC                      16
00175 #define DEBUGL_FLAPPING                 16
00176 #define DEBUGL_EVENTHANDLERS            16
00177 #define DEBUGL_PERFDATA                 16
00178 #define DEBUGL_NOTIFICATIONS            32
00179 #define DEBUGL_EVENTBROKER              64
00180 #define DEBUGL_EXTERNALCOMMANDS         128
00181 #define DEBUGL_COMMANDS                 256
00182 #define DEBUGL_DOWNTIME                 512
00183 #define DEBUGL_COMMENTS                 1024
00184 #define DEBUGL_MACROS                   2048
00185 
00186 #define DEBUGV_BASIC                    0
00187 #define DEBUGV_MORE        1
00188 #define DEBUGV_MOST                     2
00189 
00190 
00191 /******************** HOST STATUS *********************/
00192 
00193 #define HOST_UP            0
00194 #define HOST_DOWN       1
00195 #define HOST_UNREACHABLE      2  
00196 
00197 
00198 
00199 /******************* STATE LOGGING TYPES **************/
00200 
00201 #define INITIAL_STATES                  1
00202 #define CURRENT_STATES                  2
00203 
00204 
00205 
00206 /************ SERVICE DEPENDENCY VALUES ***************/
00207 
00208 #define DEPENDENCIES_OK       0
00209 #define DEPENDENCIES_FAILED      1
00210 
00211 
00212 
00213 /*********** ROUTE CHECK PROPAGATION TYPES ************/
00214 
00215 #define PROPAGATE_TO_PARENT_HOSTS   1
00216 #define PROPAGATE_TO_CHILD_HOSTS 2
00217 
00218 
00219 
00220 /****************** SERVICE STATES ********************/
00221 
00222 #define STATE_OK        0
00223 #define STATE_WARNING         1
00224 #define STATE_CRITICAL        2
00225 #define STATE_UNKNOWN         3       /* changed from -1 on 02/24/2001 */
00226 
00227 
00228 
00229 /****************** FLAPPING TYPES ********************/
00230 
00231 #define HOST_FLAPPING                   0
00232 #define SERVICE_FLAPPING                1
00233 
00234 
00235 
00236 /**************** NOTIFICATION TYPES ******************/
00237 
00238 #define HOST_NOTIFICATION               0
00239 #define SERVICE_NOTIFICATION            1
00240 
00241 
00242 
00243 /************* NOTIFICATION REASON TYPES ***************/
00244 
00245 #define NOTIFICATION_NORMAL             0
00246 #define NOTIFICATION_ACKNOWLEDGEMENT    1
00247 #define NOTIFICATION_FLAPPINGSTART      2
00248 #define NOTIFICATION_FLAPPINGSTOP       3
00249 #define NOTIFICATION_FLAPPINGDISABLED   4
00250 #define NOTIFICATION_DOWNTIMESTART      5
00251 #define NOTIFICATION_DOWNTIMEEND        6
00252 #define NOTIFICATION_DOWNTIMECANCELLED  7
00253 #define NOTIFICATION_CUSTOM             99
00254 
00255 
00256 
00257 /**************** EVENT HANDLER TYPES *****************/
00258 
00259 #define HOST_EVENTHANDLER               0
00260 #define SERVICE_EVENTHANDLER            1
00261 #define GLOBAL_HOST_EVENTHANDLER        2
00262 #define GLOBAL_SERVICE_EVENTHANDLER     3
00263 
00264 
00265 
00266 /***************** STATE CHANGE TYPES *****************/
00267 
00268 #define HOST_STATECHANGE                0
00269 #define SERVICE_STATECHANGE             1
00270 
00271 
00272 
00273 /***************** OBJECT CHECK TYPES *****************/
00274 #define SERVICE_CHECK                   0
00275 #define HOST_CHECK                      1
00276 
00277 
00278 
00279 /******************* EVENT TYPES **********************/
00280 
00281 #define EVENT_SERVICE_CHECK      0  /* active service check */
00282 #define EVENT_COMMAND_CHECK      1  /* external command check */
00283 #define EVENT_LOG_ROTATION    2  /* log file rotation */
00284 #define EVENT_PROGRAM_SHUTDOWN      3  /* program shutdown */
00285 #define EVENT_PROGRAM_RESTART    4  /* program restart */
00286 #define EVENT_CHECK_REAPER              5       /* reaps results from host and service checks */
00287 #define EVENT_ORPHAN_CHECK    6  /* checks for orphaned hosts and services */
00288 #define EVENT_RETENTION_SAVE     7  /* save (dump) retention data */
00289 #define EVENT_STATUS_SAVE     8  /* save (dump) status data */
00290 #define EVENT_SCHEDULED_DOWNTIME 9  /* scheduled host or service downtime */
00291 #define EVENT_SFRESHNESS_CHECK          10      /* checks service result "freshness" */
00292 #define EVENT_EXPIRE_DOWNTIME    11      /* checks for (and removes) expired scheduled downtime */
00293 #define EVENT_HOST_CHECK                12      /* active host check */
00294 #define EVENT_HFRESHNESS_CHECK          13      /* checks host result "freshness" */
00295 #define EVENT_RESCHEDULE_CHECKS     14      /* adjust scheduling of host and service checks */
00296 #define EVENT_EXPIRE_COMMENT            15      /* removes expired comments */
00297 #define EVENT_SLEEP                     98      /* asynchronous sleep event that occurs when event queues are empty */
00298 #define EVENT_USER_FUNCTION             99      /* USER-defined function (modules) */
00299 
00300 
00301 
00302 /******* INTER-CHECK DELAY CALCULATION TYPES **********/
00303 
00304 #define ICD_NONE        0  /* no inter-check delay */
00305 #define ICD_DUMB        1  /* dumb delay of 1 second */
00306 #define ICD_SMART       2  /* smart delay */
00307 #define ICD_USER        3       /* user-specified delay */
00308 
00309 
00310 
00311 /******* INTERLEAVE FACTOR CALCULATION TYPES **********/
00312 
00313 #define ILF_USER        0  /* user-specified interleave factor */
00314 #define ILF_SMART       1  /* smart interleave */
00315 
00316 
00317 
00318 /************ SCHEDULED DOWNTIME TYPES ****************/
00319 
00320 #define ACTIVE_DOWNTIME                 0       /* active downtime - currently in effect */
00321 #define PENDING_DOWNTIME                1       /* pending downtime - scheduled for the future */
00322 
00323 
00324 
00325 /****************** DATA STRUCTURES *******************/
00326 
00327 /* TIMED_EVENT structure */
00328 typedef struct timed_event_struct{
00329    int event_type;
00330    time_t run_time;
00331    int recurring;
00332    unsigned long event_interval;
00333    int compensate_for_time_change;
00334    void *timing_func;
00335    void *event_data;
00336    void *event_args;
00337    int event_options;
00338         struct timed_event_struct *next;
00339         struct timed_event_struct *prev;
00340         }timed_event;
00341 
00342 
00343 /* NOTIFY_LIST structure */
00344 typedef struct notify_list_struct{
00345    contact *contact;
00346    struct notify_list_struct *next;
00347         }notification;
00348 
00349 
00350 /* CHECK_RESULT structure */
00351 typedef struct check_result_struct{
00352    int object_check_type;                          /* is this a service or a host check? */
00353    char *host_name;                                /* host name */
00354    char *service_description;                      /* service description */
00355    int check_type;               /* was this an active or passive service check? */
00356    int check_options;         
00357    int scheduled_check;                            /* was this a scheduled or an on-demand check? */
00358    int reschedule_check;                           /* should we reschedule the next check */
00359    char *output_file;                              /* what file is the output stored in? */
00360    FILE *output_file_fp;
00361    int output_file_fd;
00362    double latency;
00363    struct timeval start_time;       /* time the service check was initiated */
00364    struct timeval finish_time;         /* time the service check was completed */
00365    int early_timeout;                              /* did the service check timeout? */
00366    int exited_ok;             /* did the plugin check return okay? */
00367    int return_code;           /* plugin return code */
00368    char *output;                                  /* plugin output */
00369    struct check_result_struct *next;
00370    }check_result;
00371 
00372 
00373 /* SCHED_INFO structure */
00374 typedef struct sched_info_struct{
00375    int total_services;
00376    int total_scheduled_services;
00377    int total_hosts;
00378    int total_scheduled_hosts;
00379    double average_services_per_host;
00380    double average_scheduled_services_per_host;
00381    unsigned long service_check_interval_total;
00382    unsigned long host_check_interval_total;
00383    double average_service_execution_time;
00384    double average_service_check_interval;
00385    double average_host_check_interval;
00386    double average_service_inter_check_delay;
00387    double average_host_inter_check_delay;
00388    double service_inter_check_delay;
00389    double host_inter_check_delay;
00390    int service_interleave_factor;
00391    int max_service_check_spread;
00392    int max_host_check_spread;
00393    time_t first_service_check;
00394    time_t last_service_check;
00395    time_t first_host_check;
00396    time_t last_host_check;
00397         }sched_info;
00398 
00399 
00400 /* PASSIVE_CHECK_RESULT structure */
00401 typedef struct passive_check_result_struct{
00402    int object_check_type;
00403    char *host_name;
00404    char *service_description;
00405    int return_code;
00406    char *output;
00407    time_t check_time;
00408    double latency;
00409    struct passive_check_result_struct *next;
00410    }passive_check_result;
00411 
00412 
00413 /* CIRCULAR_BUFFER structure - used by worker threads */
00414 typedef struct circular_buffer_struct{
00415    void            **buffer;
00416    int             tail;
00417    int             head;
00418    int             items;
00419    int      high;    /* highest number of items that has ever been stored in buffer */
00420    unsigned long   overflow;
00421    pthread_mutex_t buffer_lock;
00422         }circular_buffer;
00423 
00424 
00425 /* MMAPFILE structure - used for reading files via mmap() */
00426 typedef struct mmapfile_struct{
00427    char *path;
00428    int mode;
00429    int fd;
00430    unsigned long file_size;
00431    unsigned long current_position;
00432    unsigned long current_line;
00433    void *mmap_buf;
00434         }mmapfile;
00435 
00436 
00437 /* DBUF structure - dynamic string storage */
00438 typedef struct dbuf_struct{
00439    char *buf;
00440    unsigned long used_size;
00441    unsigned long allocated_size;
00442    unsigned long chunk_size;
00443         }dbuf;
00444 
00445 
00446 #define CHECK_STATS_BUCKETS                  15
00447 
00448 /* used for tracking host and service check statistics */
00449 typedef struct check_stats_struct{
00450    int current_bucket;
00451    int bucket[CHECK_STATS_BUCKETS];
00452    int overflow_bucket;
00453    int minute_stats[3];
00454    time_t last_update;
00455         }check_stats;
00456 
00457 
00458 /******************* THREAD STUFF ********************/
00459 
00460 /* slots in circular buffers */
00461 #define DEFAULT_EXTERNAL_COMMAND_BUFFER_SLOTS     4096
00462 
00463 /* worker threads */
00464 #define TOTAL_WORKER_THREADS              1
00465 
00466 #define COMMAND_WORKER_THREAD      0
00467 
00468 
00469 
00470 /******************** FUNCTIONS **********************/
00471 
00472 /**** Configuration Functions ****/
00473 int read_main_config_file(char *);                          /* reads the main config file (nagios.cfg) */
00474 int read_resource_file(char *);              /* processes macros in resource file */
00475 int read_all_object_data(char *);            /* reads all object config data */
00476 
00477 
00478 /**** Setup Functions ****/
00479 int pre_flight_check(void);                              /* try and verify the configuration data */
00480 int pre_flight_object_check(int *,int *);                /* verify object relationships and settings */
00481 int pre_flight_circular_check(int *,int *);              /* detects circular dependencies and paths */
00482 void init_timing_loop(void);                             /* setup the initial scheduling queue */
00483 void setup_sighandler(void);                             /* trap signals */
00484 void reset_sighandler(void);                             /* reset signals to default action */
00485 int daemon_init(void);                    /* switches to daemon mode */
00486 int drop_privileges(char *,char *);          /* drops privileges before startup */
00487 void display_scheduling_info(void);          /* displays service check scheduling information */
00488 
00489 
00490 /**** Event Queue Functions ****/
00491 int schedule_new_event(int,int,time_t,int,unsigned long,void *,int,void *,void *,int); /* schedules a new timed event */
00492 void reschedule_event(timed_event *,timed_event **,timed_event **);        /* reschedules an event */
00493 void add_event(timed_event *,timed_event **,timed_event **);         /* adds an event to the execution queue */
00494 void remove_event(timed_event *,timed_event **,timed_event **);         /* remove an event from the execution queue */
00495 int event_execution_loop(void);                          /* main monitoring/event handler loop */
00496 int handle_timed_event(timed_event *);             /* top level handler for timed events */
00497 void adjust_check_scheduling(void);             /* auto-adjusts scheduling of host and service checks */
00498 void compensate_for_system_time_change(unsigned long,unsigned long); /* attempts to compensate for a change in the system time */
00499 void adjust_timestamp_for_time_change(time_t,time_t,unsigned long,time_t *); /* adjusts a timestamp variable for a system time change */
00500 void resort_event_list(timed_event **,timed_event **);                  /* resorts event list by event run time for system time changes */
00501 
00502 
00503 /**** IPC Functions ****/
00504 int move_check_result_to_queue(char *);
00505 int process_check_result_queue(char *);
00506 int process_check_result_file(char *);
00507 int add_check_result_to_list(check_result *);
00508 check_result *read_check_result(void);                   /* reads a host/service check result from the list in memory */
00509 int delete_check_result_file(char *);
00510 int free_check_result_list(void);
00511 int init_check_result(check_result *);
00512 int free_check_result(check_result *);                   /* frees memory associated with a host/service check result */
00513 int parse_check_output(char *,char **,char **,char **,int,int);
00514 int open_command_file(void);              /* creates the external command file as a named pipe (FIFO) and opens it for reading */
00515 int close_command_file(void);             /* closes and deletes the external command file (FIFO) */
00516 
00517 
00518 /**** Monitoring/Event Handler Functions ****/
00519 int check_service_dependencies(service *,int);           /* checks service dependencies */
00520 int check_host_dependencies(host *,int);                 /* checks host dependencies */
00521 void check_for_orphaned_services(void);            /* checks for orphaned services */
00522 void check_for_orphaned_hosts(void);            /* checks for orphaned hosts */
00523 void check_service_result_freshness(void);               /* checks the "freshness" of service check results */
00524 int is_service_result_fresh(service *,time_t,int);              /* determines if a service's check results are fresh */
00525 void check_host_result_freshness(void);                  /* checks the "freshness" of host check results */
00526 int is_host_result_fresh(host *,time_t,int);                    /* determines if a host's check results are fresh */
00527 int my_system(char *,int,int *,double *,char **,int);          /* executes a command via popen(), but also protects against timeouts */
00528 
00529 
00530 /**** Flap Detection Functions ****/
00531 void check_for_service_flapping(service *,int,int);           /* determines whether or not a service is "flapping" between states */
00532 void check_for_host_flapping(host *,int,int,int);     /* determines whether or not a host is "flapping" between states */
00533 void set_service_flap(service *,double,double,double,int);  /* handles a service that is flapping */
00534 void clear_service_flap(service *,double,double,double); /* handles a service that has stopped flapping */
00535 void set_host_flap(host *,double,double,double,int);     /* handles a host that is flapping */
00536 void clear_host_flap(host *,double,double,double);    /* handles a host that has stopped flapping */
00537 void enable_flap_detection_routines(void);         /* enables flap detection on a program-wide basis */
00538 void disable_flap_detection_routines(void);        /* disables flap detection on a program-wide basis */
00539 void enable_host_flap_detection(host *);        /* enables flap detection for a particular host */
00540 void disable_host_flap_detection(host *);       /* disables flap detection for a particular host */
00541 void enable_service_flap_detection(service *);        /* enables flap detection for a particular service */
00542 void disable_service_flap_detection(service *);       /* disables flap detection for a particular service */
00543 void handle_host_flap_detection_disabled(host *);     /* handles the details when flap detection is disabled globally or on a per-host basis */
00544 void handle_service_flap_detection_disabled(service *);     /* handles the details when flap detection is disabled globally or on a per-service basis */
00545 
00546 
00547 /**** Route/Host Check Functions ****/
00548 int perform_on_demand_host_check(host *,int *,int,int,unsigned long);
00549 int perform_scheduled_host_check(host *,int,double);
00550 int check_host_check_viability_3x(host *,int,int *,time_t *);
00551 int adjust_host_check_attempt_3x(host *,int);
00552 int determine_host_reachability(host *);
00553 int process_host_check_result_3x(host *,int,char *,int,int,int,unsigned long);
00554 int perform_on_demand_host_check_3x(host *,int *,int,int,unsigned long);
00555 int run_sync_host_check_3x(host *,int *,int,int,unsigned long);
00556 int execute_sync_host_check_3x(host *);
00557 int run_scheduled_host_check_3x(host *,int,double);
00558 int run_async_host_check_3x(host *,int,double,int,int,int *,time_t *);
00559 int handle_async_host_check_result_3x(host *,check_result *);
00560 
00561 
00562 /**** Service Check Functions ****/
00563 int check_service_check_viability(service *,int,int *,time_t *);
00564 int run_scheduled_service_check(service *,int,double);
00565 int run_async_service_check(service *,int,double,int,int,int *,time_t *);
00566 int handle_async_service_check_result(service *,check_result *);
00567 
00568 
00569 /**** Event Handler Functions ****/
00570 int handle_host_state(host *);                        /* top level host state handler */
00571 
00572 
00573 
00574 /**** Common Check Fucntions *****/
00575 int reap_check_results(void);
00576 
00577 
00578 /**** Check Statistics Functions ****/
00579 int init_check_stats(void);
00580 int update_check_stats(int,time_t);
00581 int generate_check_stats(void);
00582 
00583 
00584 
00585 /**** Event Handler Functions ****/
00586 int obsessive_compulsive_service_check_processor(service *);   /* distributed monitoring craziness... */
00587 int obsessive_compulsive_host_check_processor(host *);      /* distributed monitoring craziness... */
00588 int handle_service_event(service *);            /* top level service event logic */
00589 int run_service_event_handler(service *);       /* runs the event handler for a specific service */
00590 int run_global_service_event_handler(service *);      /* runs the global service event handler */
00591 int handle_host_event(host *);               /* top level host event logic */
00592 int run_host_event_handler(host *);          /* runs the event handler for a specific host */
00593 int run_global_host_event_handler(host *);         /* runs the global host event handler */
00594 
00595 
00596 /**** Notification Functions ****/
00597 int check_service_notification_viability(service *,int,int);         /* checks viability of notifying all contacts about a service */
00598 int is_valid_escalation_for_service_notification(service *,serviceescalation *,int);   /* checks if an escalation entry is valid for a particular service notification */
00599 int should_service_notification_be_escalated(service *);       /* checks if a service notification should be escalated */
00600 int service_notification(service *,int,char *,char *,int);                       /* notify all contacts about a service (problem or recovery) */
00601 int check_contact_service_notification_viability(contact *,service *,int,int);   /* checks viability of notifying a contact about a service */ 
00602 int notify_contact_of_service(contact *,service *,int,char *,char *,int,int);    /* notify a single contact about a service */
00603 int check_host_notification_viability(host *,int,int);            /* checks viability of notifying all contacts about a host */
00604 int is_valid_escalation_for_host_notification(host *,hostescalation *,int);   /* checks if an escalation entry is valid for a particular host notification */
00605 int should_host_notification_be_escalated(host *);          /* checks if a host notification should be escalated */
00606 int host_notification(host *,int,char *,char *,int);                             /* notify all contacts about a host (problem or recovery) */
00607 int check_contact_host_notification_viability(contact *,host *,int,int);   /* checks viability of notifying a contact about a host */ 
00608 int notify_contact_of_host(contact *,host *,int,char *,char *,int,int);          /* notify a single contact about a host */
00609 int create_notification_list_from_host(host *,int,int *);               /* given a host, create list of contacts to be notified (remove duplicates) */
00610 int create_notification_list_from_service(service *,int,int *);         /* given a service, create list of contacts to be notified (remove duplicates) */
00611 int add_notification(contact *);                /* adds a notification instance */
00612 notification *find_notification(contact *);              /* finds a notification object */
00613 time_t get_next_host_notification_time(host *,time_t);            /* calculates nex acceptable re-notification time for a host */
00614 time_t get_next_service_notification_time(service *,time_t);         /* calculates nex acceptable re-notification time for a service */
00615 
00616 
00617 /**** Logging Functions ****/
00618 void logit(int,int,const char *, ...)
00619    __attribute__((__format__(__printf__, 3, 4)));
00620 int write_to_logs_and_console(char *,unsigned long,int); /* writes a string to screen and logs */
00621 int write_to_console(char *);                           /* writes a string to screen */
00622 int write_to_all_logs(char *,unsigned long);            /* writes a string to main log file and syslog facility */
00623 int write_to_all_logs_with_timestamp(char *,unsigned long,time_t *); /* writes a string to main log file and syslog facility */
00624 int write_to_log(char *,unsigned long,time_t *);         /* write a string to the main log file */
00625 int write_to_syslog(char *,unsigned long);               /* write a string to the syslog facility */
00626 int log_service_event(service *);         /* logs a service event */
00627 int log_host_event(host *);            /* logs a host event */
00628 int log_host_states(int,time_t *);                  /* logs initial/current host states */
00629 int log_service_states(int,time_t *);                   /* logs initial/current service states */
00630 int rotate_log_file(time_t);              /* rotates the main log file */
00631 int write_log_file_info(time_t *);        /* records log file/version info */
00632 int open_debug_log(void);
00633 int log_debug_info(int,int,const char *,...)
00634    __attribute__((__format__(__printf__, 3, 4)));
00635 int close_debug_log(void);
00636 
00637 
00638 /**** Cleanup Functions ****/
00639 void cleanup(void);                                   /* cleanup after ourselves (before quitting or restarting) */
00640 void free_memory(void);                               /* free memory allocated to all linked lists in memory */
00641 int reset_variables(void);                            /* reset all global variables */
00642 void free_notification_list(void);           /* frees all memory allocated to the notification list */
00643 
00644 
00645 /**** Hash Functions ****/
00646 int hashfunc(const char *name1, const char *name2, int hashslots);
00647 int compare_hashdata(const char *,const char *,const char *,const char *);
00648 
00649 
00650 /**** Miscellaneous Functions ****/
00651 void sighandler(int);                                 /* handles signals */
00652 void service_check_sighandler(int);                     /* handles timeouts when executing service checks */
00653 void host_check_sighandler(int);                        /* handles timeouts when executing host checks */
00654 void my_system_sighandler(int);           /* handles timeouts when executing commands via my_system() */
00655 void file_lock_sighandler(int);           /* handles timeouts while waiting for file locks */
00656 void strip(char *);                                   /* strips whitespace from string */  
00657 char *my_strtok(char *,char *);                       /* my replacement for strtok() function (doesn't skip consecutive tokens) */
00658 char *my_strsep(char **,const char *);          /* Solaris doesn't have strsep(), so I took this from the glibc source code */
00659 #ifdef REMOVED_10182007
00660 int my_free(void **);                                   /* my wrapper for free() */
00661 #endif
00662 int compare_strings(char *,char *);                     /* compares two strings for equality */
00663 char *escape_newlines(char *);
00664 int contains_illegal_object_chars(char *);      /* tests whether or not an object name (host, service, etc.) contains illegal characters */
00665 int my_rename(char *,char *);                           /* renames a file - works across filesystems */
00666 int get_raw_command_line(command *,char *,char **,int);     /* given a raw command line, determine the actual command to run */
00667 int check_time_against_period(time_t,timeperiod *);   /* check to see if a specific time is covered by a time period */
00668 int is_daterange_single_day(daterange *);
00669 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 */
00670 time_t calculate_time_from_day_of_month(int,int,int); /* calculates midnight time of specific (1st, last, etc.) day of a particular month */
00671 void get_next_valid_time(time_t, time_t *,timeperiod *); /* get the next valid time in a time period */
00672 void get_datetime_string(time_t *,char *,int,int); /* get a date/time string for use in output */
00673 void get_time_breakdown(unsigned long,int *,int *,int *, int *);
00674 time_t get_next_log_rotation_time(void);        /* determine the next time to schedule a log rotation */
00675 int init_embedded_perl(char **);       /* initialized embedded perl interpreter */
00676 int deinit_embedded_perl(void);           /* cleans up embedded perl */
00677 int file_uses_embedded_perl(char *);         /* tests whether or not the embedded perl interpreter should be used on a file */
00678 int dbuf_init(dbuf *,int);
00679 int dbuf_free(dbuf *);
00680 int dbuf_strcat(dbuf *,char *);
00681 int set_environment_var(char *,char *,int);             /* sets/clears and environment variable */
00682 
00683 
00684 /**** External Command Functions ****/
00685 int check_for_external_commands(void);       /* checks for any external commands */
00686 int process_external_command1(char *);                  /* top-level external command processor */
00687 int process_external_command2(int,time_t,char *);  /* process an external command */
00688 int process_external_commands_from_file(char *,int);    /* process external commands in a file */
00689 int process_host_command(int,time_t,char *);            /* process an external host command */
00690 int process_hostgroup_command(int,time_t,char *);       /* process an external hostgroup command */
00691 int process_service_command(int,time_t,char *);         /* process an external service command */
00692 int process_servicegroup_command(int,time_t,char *);    /* process an external servicegroup command */
00693 int process_contact_command(int,time_t,char *);         /* process an external contact command */
00694 int process_contactgroup_command(int,time_t,char *);    /* process an external contactgroup command */
00695 
00696 
00697 /**** External Command Implementations ****/
00698 int cmd_add_comment(int,time_t,char *);            /* add a service or host comment */
00699 int cmd_delete_comment(int,char *);          /* delete a service or host comment */
00700 int cmd_delete_all_comments(int,char *);        /* delete all comments associated with a host or service */
00701 int cmd_delay_notification(int,char *);            /* delay a service or host notification */
00702 int cmd_schedule_service_check(int,char *,int);       /* schedule an immediate or delayed service check */
00703 int cmd_schedule_check(int,char *);          /* schedule an immediate or delayed host check */
00704 int cmd_schedule_host_service_checks(int,char *,int);    /* schedule an immediate or delayed checks of all services on a host */
00705 int cmd_signal_process(int,char *);          /* schedules a program shutdown or restart */
00706 int cmd_process_service_check_result(int,time_t,char *); /* processes a passive service check */
00707 int cmd_process_host_check_result(int,time_t,char *);    /* processes a passive host check */
00708 int cmd_acknowledge_problem(int,char *);        /* acknowledges a host or service problem */
00709 int cmd_remove_acknowledgement(int,char *);        /* removes a host or service acknowledgement */
00710 int cmd_schedule_downtime(int,time_t,char *);                   /* schedules host or service downtime */
00711 int cmd_delete_downtime(int,char *);            /* cancels active/pending host or service scheduled downtime */
00712 int cmd_change_object_int_var(int,char *);                      /* changes host/svc (int) variable */
00713 int cmd_change_object_char_var(int,char *);        /* changes host/svc (char) variable */
00714 int cmd_change_object_custom_var(int,char *);                   /* changes host/svc custom variable */
00715 int cmd_process_external_commands_from_file(int,char *);        /* process external commands from a file */
00716 
00717 int process_passive_service_check(time_t,char *,char *,int,char *);
00718 int process_passive_host_check(time_t,char *,int,char *);
00719 
00720 
00721 /**** Internal Command Implementations ****/
00722 void disable_service_checks(service *);         /* disables a service check */
00723 void enable_service_checks(service *);       /* enables a service check */
00724 void schedule_service_check(service *,time_t,int); /* schedules an immediate or delayed service check */
00725 void schedule_host_check(host *,time_t,int);    /* schedules an immediate or delayed host check */
00726 void enable_all_notifications(void);                    /* enables notifications on a program-wide basis */
00727 void disable_all_notifications(void);                   /* disables notifications on a program-wide basis */
00728 void enable_service_notifications(service *);      /* enables service notifications */
00729 void disable_service_notifications(service *);     /* disables service notifications */
00730 void enable_host_notifications(host *);         /* enables host notifications */
00731 void disable_host_notifications(host *);     /* disables host notifications */
00732 void enable_and_propagate_notifications(host *,int,int,int,int);  /* enables notifications for all hosts and services beyond a given host */
00733 void disable_and_propagate_notifications(host *,int,int,int,int); /* disables notifications for all hosts and services beyond a given host */
00734 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 */
00735 void acknowledge_host_problem(host *,char *,char *,int,int,int);  /* acknowledges a host problem */
00736 void acknowledge_service_problem(service *,char *,char *,int,int,int);  /* acknowledges a service problem */
00737 void remove_host_acknowledgement(host *);    /* removes a host acknowledgement */
00738 void remove_service_acknowledgement(service *);    /* removes a service acknowledgement */
00739 void start_executing_service_checks(void);      /* starts executing service checks */
00740 void stop_executing_service_checks(void);    /* stops executing service checks */
00741 void start_accepting_passive_service_checks(void); /* starts accepting passive service check results */
00742 void stop_accepting_passive_service_checks(void);  /* stops accepting passive service check results */
00743 void enable_passive_service_checks(service *);          /* enables passive service checks for a particular service */
00744 void disable_passive_service_checks(service *);         /* disables passive service checks for a particular service */
00745 void start_using_event_handlers(void);       /* enables event handlers on a program-wide basis */
00746 void stop_using_event_handlers(void);        /* disables event handlers on a program-wide basis */
00747 void enable_service_event_handler(service *);      /* enables the event handler for a particular service */
00748 void disable_service_event_handler(service *);     /* disables the event handler for a particular service */
00749 void enable_host_event_handler(host *);         /* enables the event handler for a particular host */
00750 void disable_host_event_handler(host *);     /* disables the event handler for a particular host */
00751 void enable_host_checks(host *);       /* enables checks of a particular host */
00752 void disable_host_checks(host *);         /* disables checks of a particular host */
00753 void start_obsessing_over_service_checks(void);    /* start obsessing about service check results */
00754 void stop_obsessing_over_service_checks(void);     /* stop obsessing about service check results */
00755 void start_obsessing_over_host_checks(void);    /* start obsessing about host check results */
00756 void stop_obsessing_over_host_checks(void);     /* stop obsessing about host check results */
00757 void enable_service_freshness_checks(void);     /* enable service freshness checks */
00758 void disable_service_freshness_checks(void);    /* disable service freshness checks */
00759 void enable_host_freshness_checks(void);     /* enable host freshness checks */
00760 void disable_host_freshness_checks(void);    /* disable host freshness checks */
00761 void process_passive_checks(void);                      /* processes passive host and service check results */
00762 void enable_all_failure_prediction(void);               /* enables failure prediction on a program-wide basis */
00763 void disable_all_failure_prediction(void);              /* disables failure prediction on a program-wide basis */
00764 void enable_performance_data(void);                     /* enables processing of performance data on a program-wide basis */
00765 void disable_performance_data(void);                    /* disables processing of performance data on a program-wide basis */
00766 void start_executing_host_checks(void);         /* starts executing host checks */
00767 void stop_executing_host_checks(void);       /* stops executing host checks */
00768 void start_accepting_passive_host_checks(void);    /* starts accepting passive host check results */
00769 void stop_accepting_passive_host_checks(void);     /* stops accepting passive host check results */
00770 void enable_passive_host_checks(host *);          /* enables passive host checks for a particular host */
00771 void disable_passive_host_checks(host *);          /* disables passive host checks for a particular host */
00772 void start_obsessing_over_service(service *);      /* start obsessing about specific service check results */
00773 void stop_obsessing_over_service(service *);    /* stop obsessing about specific service check results */
00774 void start_obsessing_over_host(host *);         /* start obsessing about specific host check results */
00775 void stop_obsessing_over_host(host *);       /* stop obsessing about specific host check results */
00776 void set_host_notification_number(host *,int);     /* sets current notification number for a specific host */
00777 void set_service_notification_number(service *,int);  /* sets current notification number for a specific service */
00778 void enable_contact_host_notifications(contact *);      /* enables host notifications for a specific contact */
00779 void disable_contact_host_notifications(contact *);     /* disables host notifications for a specific contact */
00780 void enable_contact_service_notifications(contact *);   /* enables service notifications for a specific contact */
00781 void disable_contact_service_notifications(contact *);  /* disables service notifications for a specific contact */
00782 
00783 int init_check_result_worker_thread(void);
00784 int shutdown_check_result_worker_thread(void);
00785 void * check_result_worker_thread(void *);
00786 void cleanup_check_result_worker_thread(void *);
00787 
00788 int init_command_file_worker_thread(void);
00789 int shutdown_command_file_worker_thread(void);
00790 void * command_file_worker_thread(void *);
00791 void cleanup_command_file_worker_thread(void *);
00792 
00793 int submit_external_command(char *,int *);
00794 int submit_raw_external_command(char *,time_t *,int *);
00795 
00796 char *get_program_version(void);
00797 char *get_program_modification_date(void);
00798 
00799 mmapfile *mmap_fopen(char *);          /* open a file read-only via mmap() */
00800 int mmap_fclose(mmapfile *);
00801 char *mmap_fgets(mmapfile *);
00802 char *mmap_fgets_multiline(mmapfile *);
00803 
00804 
00805 #ifdef __cplusplus
00806 }
00807 #endif
00808 #endif
00809 

Generated on Tue Apr 13 15:15:28 2010 for DNX by  doxygen 1.5.6