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: 01-08-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 #include "config.h"
00025 #include "common.h"
00026 #include "locations.h"
00027 #include "objects.h"
00028 
00029 #ifdef __cplusplus
00030 extern "C" { 
00031 #endif
00032 
00033 #define MAX_COMMAND_ARGUMENTS       32 /* maximum number of $ARGx$ macros */
00034 #define MAX_USER_MACROS          256   /* maximum number of $USERx$ macros */
00035 
00036 #define MAX_STATE_LENGTH         32 /* length definitions used in macros */
00037 #define MAX_STATETYPE_LENGTH        24
00038 #define MAX_CHECKTYPE_LENGTH              8
00039 #define MAX_NOTIFICATIONTYPE_LENGTH    32
00040 #define MAX_NOTIFICATIONNUMBER_LENGTH     8
00041 #define MAX_ATTEMPT_LENGTH       8
00042 #define MAX_TOTALS_LENGTH        8
00043 #define MAX_EXECUTIONTIME_LENGTH    10
00044 #define MAX_LATENCY_LENGTH       10
00045 #define MAX_DURATION_LENGTH         17
00046 #define MAX_DOWNTIME_LENGTH         3
00047 #define MAX_STATEID_LENGTH       2
00048 #define MAX_PERCENTCHANGE_LENGTH             8
00049 
00050 #define MACRO_ENV_VAR_PREFIX        "NAGIOS_"
00051 
00052 #define MACRO_X_COUNT            99 /* size of macro_x[] array */
00053 
00054 #define MACRO_HOSTNAME           0
00055 #define MACRO_HOSTALIAS          1
00056 #define MACRO_HOSTADDRESS        2
00057 #define MACRO_SERVICEDESC        3
00058 #define MACRO_SERVICESTATE       4
00059 #define MACRO_SERVICESTATEID                    5
00060 #define MACRO_SERVICEATTEMPT        6
00061 #define MACRO_LONGDATETIME       7
00062 #define MACRO_SHORTDATETIME         8
00063 #define MACRO_DATE            9
00064 #define MACRO_TIME            10
00065 #define MACRO_TIMET           11
00066 #define MACRO_LASTHOSTCHECK         12
00067 #define MACRO_LASTSERVICECHECK         13
00068 #define MACRO_LASTHOSTSTATECHANGE      14
00069 #define MACRO_LASTSERVICESTATECHANGE      15
00070 #define MACRO_HOSTOUTPUT         16
00071 #define MACRO_SERVICEOUTPUT         17
00072 #define MACRO_HOSTPERFDATA       18
00073 #define MACRO_SERVICEPERFDATA       19
00074 #define MACRO_CONTACTNAME        20
00075 #define MACRO_CONTACTALIAS       21
00076 #define MACRO_CONTACTEMAIL       22
00077 #define MACRO_CONTACTPAGER       23
00078 #define MACRO_ADMINEMAIL         24
00079 #define MACRO_ADMINPAGER         25
00080 #define MACRO_HOSTSTATE          26
00081 #define MACRO_HOSTSTATEID                       27
00082 #define MACRO_HOSTATTEMPT        28
00083 #define MACRO_NOTIFICATIONTYPE         29
00084 #define MACRO_NOTIFICATIONNUMBER    30
00085 #define MACRO_HOSTEXECUTIONTIME        31
00086 #define MACRO_SERVICEEXECUTIONTIME     32
00087 #define MACRO_HOSTLATENCY                       33
00088 #define MACRO_SERVICELATENCY        34
00089 #define MACRO_HOSTDURATION       35
00090 #define MACRO_SERVICEDURATION       36
00091 #define MACRO_HOSTDURATIONSEC       37
00092 #define MACRO_SERVICEDURATIONSEC    38
00093 #define MACRO_HOSTDOWNTIME       39
00094 #define MACRO_SERVICEDOWNTIME       40
00095 #define MACRO_HOSTSTATETYPE         41
00096 #define MACRO_SERVICESTATETYPE         42
00097 #define MACRO_HOSTPERCENTCHANGE        43
00098 #define MACRO_SERVICEPERCENTCHANGE     44
00099 #define MACRO_HOSTGROUPNAME         45
00100 #define MACRO_HOSTGROUPALIAS        46
00101 #define MACRO_SERVICEGROUPNAME         47
00102 #define MACRO_SERVICEGROUPALIAS        48
00103 #define MACRO_HOSTACKAUTHOR                     49
00104 #define MACRO_HOSTACKCOMMENT                    50
00105 #define MACRO_SERVICEACKAUTHOR                  51
00106 #define MACRO_SERVICEACKCOMMENT                 52
00107 #define MACRO_LASTSERVICEOK                     53
00108 #define MACRO_LASTSERVICEWARNING                54
00109 #define MACRO_LASTSERVICEUNKNOWN                55
00110 #define MACRO_LASTSERVICECRITICAL               56
00111 #define MACRO_LASTHOSTUP                        57
00112 #define MACRO_LASTHOSTDOWN                      58
00113 #define MACRO_LASTHOSTUNREACHABLE               59
00114 #define MACRO_SERVICECHECKCOMMAND      60
00115 #define MACRO_HOSTCHECKCOMMAND         61
00116 #define MACRO_MAINCONFIGFILE        62
00117 #define MACRO_STATUSDATAFILE        63
00118 #define MACRO_COMMENTDATAFILE       64
00119 #define MACRO_DOWNTIMEDATAFILE         65
00120 #define MACRO_RETENTIONDATAFILE        66
00121 #define MACRO_OBJECTCACHEFILE       67
00122 #define MACRO_TEMPFILE           68
00123 #define MACRO_LOGFILE            69
00124 #define MACRO_RESOURCEFILE       70
00125 #define MACRO_COMMANDFILE        71
00126 #define MACRO_HOSTPERFDATAFILE         72
00127 #define MACRO_SERVICEPERFDATAFILE      73
00128 #define MACRO_HOSTACTIONURL         74
00129 #define MACRO_HOSTNOTESURL       75
00130 #define MACRO_HOSTNOTES          76
00131 #define MACRO_SERVICEACTIONURL         77
00132 #define MACRO_SERVICENOTESURL       78
00133 #define MACRO_SERVICENOTES       79
00134 #define MACRO_TOTALHOSTSUP       80
00135 #define MACRO_TOTALHOSTSDOWN        81
00136 #define MACRO_TOTALHOSTSUNREACHABLE    82
00137 #define MACRO_TOTALHOSTSDOWNUNHANDLED     83
00138 #define MACRO_TOTALHOSTSUNREACHABLEUNHANDLED 84
00139 #define MACRO_TOTALHOSTPROBLEMS        85
00140 #define MACRO_TOTALHOSTPROBLEMSUNHANDLED  86
00141 #define MACRO_TOTALSERVICESOK       87
00142 #define MACRO_TOTALSERVICESWARNING     88
00143 #define MACRO_TOTALSERVICESCRITICAL    89
00144 #define MACRO_TOTALSERVICESUNKNOWN     90
00145 #define MACRO_TOTALSERVICESWARNINGUNHANDLED  91
00146 #define MACRO_TOTALSERVICESCRITICALUNHANDLED 92
00147 #define MACRO_TOTALSERVICESUNKNOWNUNHANDLED  93
00148 #define MACRO_TOTALSERVICEPROBLEMS     94
00149 #define MACRO_TOTALSERVICEPROBLEMSUNHANDLED  95
00150 #define MACRO_PROCESSSTARTTIME         96
00151 #define MACRO_HOSTCHECKTYPE         97
00152 #define MACRO_SERVICECHECKTYPE         98
00153 
00154 
00155 
00156 #define DEFAULT_LOG_LEVEL        1  /* log all events to main log file */
00157 #define DEFAULT_USE_SYSLOG       1  /* log events to syslog? 1=yes, 0=no */
00158 #define DEFAULT_SYSLOG_LEVEL        2  /* log only severe events to syslog */
00159 
00160 #define DEFAULT_NOTIFICATION_LOGGING      1  /* log notification events? 1=yes, 0=no */
00161 
00162 #define DEFAULT_INTER_CHECK_DELAY      5.0   /* seconds between initial service check scheduling */
00163 #define DEFAULT_INTERLEAVE_FACTOR            1       /* default interleave to use when scheduling checks */
00164 #define DEFAULT_SLEEP_TIME          0.5      /* seconds between event run checks */
00165 #define DEFAULT_INTERVAL_LENGTH     60       /* seconds per interval unit for check scheduling */
00166 #define DEFAULT_RETRY_INTERVAL      30 /* services are retried in 30 seconds if they're not OK */
00167 #define DEFAULT_COMMAND_CHECK_INTERVAL    -1 /* interval to check for external commands (default = as often as possible) */
00168 #define DEFAULT_SERVICE_REAPER_INTERVAL      10 /* interval in seconds to reap service check results */
00169 #define DEFAULT_MAX_REAPER_TIME                 30      /* maximum number of seconds to spend reaping service checks before we break out for a while */
00170 #define DEFAULT_MAX_PARALLEL_SERVICE_CHECKS  0  /* maximum number of service checks we can have running at any given time (0=unlimited) */
00171 #define DEFAULT_RETENTION_UPDATE_INTERVAL 60 /* minutes between auto-save of retention data */
00172 #define DEFAULT_RETENTION_SCHEDULING_HORIZON    900     /* max seconds between program restarts that we will preserve scheduling information */
00173 #define DEFAULT_STATUS_UPDATE_INTERVAL    60 /* seconds between aggregated status data updates */
00174 #define DEFAULT_FRESHNESS_CHECK_INTERVAL        60      /* seconds between service result freshness checks */
00175 #define DEFAULT_AUTO_RESCHEDULING_INTERVAL      30      /* seconds between host and service check rescheduling events */
00176 #define DEFAULT_AUTO_RESCHEDULING_WINDOW        180     /* window of time (in seconds) for which we should reschedule host and service checks */
00177 
00178 #define DEFAULT_NOTIFICATION_TIMEOUT      30 /* max time in seconds to wait for notification commands to complete */
00179 #define DEFAULT_EVENT_HANDLER_TIMEOUT     30 /* max time in seconds to wait for event handler commands to complete */
00180 #define DEFAULT_HOST_CHECK_TIMEOUT     30 /* max time in seconds to wait for host check commands to complete */
00181 #define DEFAULT_SERVICE_CHECK_TIMEOUT     60 /* max time in seconds to wait for service check commands to complete */
00182 #define DEFAULT_OCSP_TIMEOUT        15 /* max time in seconds to wait for obsessive compulsive processing commands to complete */
00183 #define DEFAULT_OCHP_TIMEOUT        15 /* max time in seconds to wait for obsessive compulsive processing commands to complete */
00184 #define DEFAULT_PERFDATA_TIMEOUT                5       /* max time in seconds to wait for performance data commands to complete */
00185 #define DEFAULT_TIME_CHANGE_THRESHOLD     900   /* compensate for time changes of more than 15 minutes */
00186 
00187 #define DEFAULT_LOG_HOST_RETRIES    0  /* don't log host retries */
00188 #define DEFAULT_LOG_SERVICE_RETRIES    0  /* don't log service retries */
00189 #define DEFAULT_LOG_EVENT_HANDLERS     1  /* log event handlers */
00190 #define DEFAULT_LOG_INITIAL_STATES     0  /* don't log initial service and host states */
00191 #define DEFAULT_LOG_EXTERNAL_COMMANDS     1  /* log external commands */
00192 #define DEFAULT_LOG_PASSIVE_CHECKS     1  /* log passive service checks */
00193 
00194 #define DEFAULT_AGGRESSIVE_HOST_CHECKING  0  /* don't use "aggressive" host checking */
00195 #define DEFAULT_CHECK_EXTERNAL_COMMANDS      0  /* don't check for external commands */
00196 #define DEFAULT_CHECK_ORPHANED_SERVICES      1  /* don't check for orphaned services */
00197 #define DEFAULT_ENABLE_FLAP_DETECTION           0       /* don't enable flap detection */
00198 #define DEFAULT_PROCESS_PERFORMANCE_DATA        0       /* don't process performance data */
00199 #define DEFAULT_CHECK_SERVICE_FRESHNESS         1       /* check service result freshness */
00200 #define DEFAULT_CHECK_HOST_FRESHNESS            0       /* don't check host result freshness */
00201 #define DEFAULT_AUTO_RESCHEDULE_CHECKS          0       /* don't auto-reschedule host and service checks */
00202 
00203 #define DEFAULT_LOW_SERVICE_FLAP_THRESHOLD   20.0  /* low threshold for detection of service flapping */
00204 #define DEFAULT_HIGH_SERVICE_FLAP_THRESHOLD  30.0  /* high threshold for detection of service flapping */
00205 #define DEFAULT_LOW_HOST_FLAP_THRESHOLD      20.0  /* low threshold for detection of host flapping */
00206 #define DEFAULT_HIGH_HOST_FLAP_THRESHOLD  30.0  /* high threshold for detection of host flapping */
00207 
00208 #define DEFAULT_HOST_CHECK_SPREAD      30 /* max minutes to schedule all initial host checks */
00209 #define DEFAULT_SERVICE_CHECK_SPREAD      30 /* max minutes to schedule all initial service checks */
00210 
00211 
00212 
00213 /******************* LOGGING TYPES ********************/
00214 
00215 #define NSLOG_RUNTIME_ERROR      1
00216 #define NSLOG_RUNTIME_WARNING    2
00217 
00218 #define NSLOG_VERIFICATION_ERROR 4
00219 #define NSLOG_VERIFICATION_WARNING  8
00220 
00221 #define NSLOG_CONFIG_ERROR    16
00222 #define NSLOG_CONFIG_WARNING     32
00223 
00224 #define NSLOG_PROCESS_INFO    64
00225 #define NSLOG_EVENT_HANDLER      128
00226 /*#define NSLOG_NOTIFICATION     256*/ /* NOT USED ANYMORE - CAN BE REUSED */
00227 #define NSLOG_EXTERNAL_COMMAND      512
00228 
00229 #define NSLOG_HOST_UP            1024
00230 #define NSLOG_HOST_DOWN       2048
00231 #define NSLOG_HOST_UNREACHABLE      4096
00232 
00233 #define NSLOG_SERVICE_OK      8192
00234 #define NSLOG_SERVICE_UNKNOWN    16384
00235 #define NSLOG_SERVICE_WARNING    32768
00236 #define NSLOG_SERVICE_CRITICAL      65536
00237 
00238 #define NSLOG_PASSIVE_CHECK      131072
00239 
00240 #define NSLOG_INFO_MESSAGE    262144
00241 
00242 #define NSLOG_HOST_NOTIFICATION     524288
00243 #define NSLOG_SERVICE_NOTIFICATION  1048576
00244 
00245 
00246 /******************** HOST STATUS *********************/
00247 
00248 #define HOST_UP            0
00249 #define HOST_DOWN       1
00250 #define HOST_UNREACHABLE      2  
00251 
00252 
00253 /******************* STATE LOGGING TYPES **************/
00254 
00255 #define INITIAL_STATES                  1
00256 #define CURRENT_STATES                  2
00257 
00258 
00259 /************ SERVICE DEPENDENCY VALUES ***************/
00260 
00261 #define DEPENDENCIES_OK       0
00262 #define DEPENDENCIES_FAILED      1
00263 
00264 
00265 /*********** ROUTE CHECK PROPAGATION TYPES ************/
00266 
00267 #define PROPAGATE_TO_PARENT_HOSTS   1
00268 #define PROPAGATE_TO_CHILD_HOSTS 2
00269 
00270 
00271 /****************** SERVICE STATES ********************/
00272 
00273 #define STATE_OK        0
00274 #define STATE_WARNING         1
00275 #define STATE_CRITICAL        2
00276 #define STATE_UNKNOWN         3       /* changed from -1 on 02/24/2001 */
00277 
00278 
00279 /****************** FLAPPING TYPES ********************/
00280 
00281 #define HOST_FLAPPING                   0
00282 #define SERVICE_FLAPPING                1
00283 
00284 
00285 /**************** NOTIFICATION TYPES ******************/
00286 
00287 #define HOST_NOTIFICATION               0
00288 #define SERVICE_NOTIFICATION            1
00289 
00290 
00291 /************* NOTIFICATION REASON TYPES ***************/
00292 
00293 #define NOTIFICATION_NORMAL             0
00294 #define NOTIFICATION_ACKNOWLEDGEMENT    1
00295 #define NOTIFICATION_FLAPPINGSTART      2
00296 #define NOTIFICATION_FLAPPINGSTOP       3
00297 
00298 
00299 /**************** EVENT HANDLER TYPES *****************/
00300 
00301 #define HOST_EVENTHANDLER               0
00302 #define SERVICE_EVENTHANDLER            1
00303 #define GLOBAL_HOST_EVENTHANDLER        2
00304 #define GLOBAL_SERVICE_EVENTHANDLER     3
00305 
00306 
00307 /***************** STATE CHANGE TYPES *****************/
00308 
00309 #define HOST_STATECHANGE                0
00310 #define SERVICE_STATECHANGE             1
00311 
00312 
00313 /******************* EVENT TYPES **********************/
00314 
00315 #define EVENT_SERVICE_CHECK      0  /* active service check */
00316 #define EVENT_COMMAND_CHECK      1  /* external command check */
00317 #define EVENT_LOG_ROTATION    2  /* log file rotation */
00318 #define EVENT_PROGRAM_SHUTDOWN      3  /* program shutdown */
00319 #define EVENT_PROGRAM_RESTART    4  /* program restart */
00320 #define EVENT_SERVICE_REAPER     5  /* reaps results from service checks */
00321 #define EVENT_ORPHAN_CHECK    6  /* checks for orphaned service checks */
00322 #define EVENT_RETENTION_SAVE     7  /* save (dump) retention data */
00323 #define EVENT_STATUS_SAVE     8  /* save (dump) status data */
00324 #define EVENT_SCHEDULED_DOWNTIME 9  /* scheduled host or service downtime */
00325 #define EVENT_SFRESHNESS_CHECK          10      /* checks service result "freshness" */
00326 #define EVENT_EXPIRE_DOWNTIME    11      /* checks for (and removes) expired scheduled downtime */
00327 #define EVENT_HOST_CHECK                12      /* active host check */
00328 #define EVENT_HFRESHNESS_CHECK          13      /* checks host result "freshness" */
00329 #define EVENT_RESCHEDULE_CHECKS     14      /* adjust scheduling of host and service checks */
00330 #define EVENT_EXPIRE_COMMENT            15      /* removes expired comments */
00331 #define EVENT_SLEEP                     98      /* asynchronous sleep event that occurs when event queues are empty */
00332 #define EVENT_USER_FUNCTION             99      /* USER-defined function (modules) */
00333 
00334 
00335 /******* INTER-CHECK DELAY CALCULATION TYPES **********/
00336 
00337 #define ICD_NONE        0  /* no inter-check delay */
00338 #define ICD_DUMB        1  /* dumb delay of 1 second */
00339 #define ICD_SMART       2  /* smart delay */
00340 #define ICD_USER        3       /* user-specified delay */
00341 
00342 
00343 /******* INTERLEAVE FACTOR CALCULATION TYPES **********/
00344 
00345 #define ILF_USER        0  /* user-specified interleave factor */
00346 #define ILF_SMART       1  /* smart interleave */
00347 
00348 
00349 /************** SERVICE CHECK OPTIONS *****************/
00350 
00351 #define CHECK_OPTION_NONE     0  /* no check options */
00352 #define CHECK_OPTION_FORCE_EXECUTION   1  /* force execution of a service check (ignores disabled services, invalid timeperiods) */
00353 
00354 
00355 /************ SCHEDULED DOWNTIME TYPES ****************/
00356 
00357 #define ACTIVE_DOWNTIME                 0       /* active downtime - currently in effect */
00358 #define PENDING_DOWNTIME                1       /* pending downtime - scheduled for the future */
00359 
00360 
00361 /************* MACRO CLEANING OPTIONS *****************/
00362 
00363 #define STRIP_ILLEGAL_MACRO_CHARS       1
00364 #define ESCAPE_MACRO_CHARS              2
00365 #define URL_ENCODE_MACRO_CHARS      4
00366 
00367 
00368 
00369 /****************** DATA STRUCTURES *******************/
00370 
00371 /* TIMED_EVENT structure */
00372 typedef struct timed_event_struct{
00373    int event_type;
00374    time_t run_time;
00375    int recurring;
00376    unsigned long event_interval;
00377    int compensate_for_time_change;
00378    void *timing_func;
00379    void *event_data;
00380    void *event_args;
00381         struct timed_event_struct *next;
00382         }timed_event;
00383 
00384 
00385 /* NOTIFY_LIST structure */
00386 typedef struct notify_list_struct{
00387    contact *contact;
00388    struct notify_list_struct *next;
00389         }notification;
00390 
00391 
00392 /* SERVICE_MESSAGE structure */
00393 typedef struct service_message_struct{
00394    char host_name[MAX_HOSTNAME_LENGTH];      /* host name */
00395    char description[MAX_SERVICEDESC_LENGTH]; /* service description */
00396    int return_code;           /* plugin return code */
00397    int exited_ok;             /* did the plugin check return okay? */
00398    int check_type;               /* was this an active or passive service check? */
00399    int parallelized;                               /* was this check run in parallel? */
00400    struct timeval start_time;       /* time the service check was initiated */
00401    struct timeval finish_time;         /* time the service check was completed */
00402    int early_timeout;                              /* did the service check timeout? */
00403    char output[MAX_PLUGINOUTPUT_LENGTH];     /* plugin output */
00404    }service_message;
00405 
00406 
00407 /* SCHED_INFO structure */
00408 typedef struct sched_info_struct{
00409    int total_services;
00410    int total_scheduled_services;
00411    int total_hosts;
00412    int total_scheduled_hosts;
00413    double average_services_per_host;
00414    double average_scheduled_services_per_host;
00415    unsigned long service_check_interval_total;
00416    unsigned long host_check_interval_total;
00417    double average_service_check_interval;
00418    double average_host_check_interval;
00419    double average_service_inter_check_delay;
00420    double average_host_inter_check_delay;
00421    double service_inter_check_delay;
00422    double host_inter_check_delay;
00423    int service_interleave_factor;
00424    int max_service_check_spread;
00425    int max_host_check_spread;
00426    time_t first_service_check;
00427    time_t last_service_check;
00428    time_t first_host_check;
00429    time_t last_host_check;
00430         }sched_info;
00431 
00432 
00433 /* PASSIVE_CHECK_RESULT structure */
00434 typedef struct passive_check_result_struct{
00435    char *host_name;
00436    char *svc_description;
00437    int return_code;
00438    char *output;
00439    time_t check_time;
00440    struct passive_check_result_struct *next;
00441    }passive_check_result;
00442 
00443 
00444 /* CIRCULAR_BUFFER structure - used by worker threads */
00445 typedef struct circular_buffer_struct{
00446    void            **buffer;
00447    int             tail;
00448    int             head;
00449    int             items;
00450    int      high;    /* highest number of items that has ever been stored in buffer */
00451    unsigned long   overflow;
00452    pthread_mutex_t buffer_lock;
00453         }circular_buffer;
00454 
00455 
00456 /* MMAPFILE structure - used for reading files via mmap() */
00457 typedef struct mmapfile_struct{
00458    char *path;
00459    int mode;
00460    int fd;
00461    unsigned long file_size;
00462    unsigned long current_position;
00463    unsigned long current_line;
00464    void *mmap_buf;
00465         }mmapfile;
00466 
00467 
00468 
00469 /* slots in circular buffers */
00470 #define DEFAULT_EXTERNAL_COMMAND_BUFFER_SLOTS   4096
00471 #define DEFAULT_CHECK_RESULT_BUFFER_SLOTS 4096
00472 
00473 /* worker threads */
00474 #define TOTAL_WORKER_THREADS              2
00475 
00476 #define COMMAND_WORKER_THREAD      0
00477 #define SERVICE_WORKER_THREAD         1
00478 
00479 
00480 /******************** FUNCTIONS **********************/
00481 
00482 /**** Configuration Functions ****/
00483 int read_main_config_file(char *);                       /* reads the main config file (nagios.cfg) */
00484 int read_resource_file(char *);           /* processes macros in resource file */
00485 int read_all_object_data(char *);         /* reads all object config data */
00486 
00487 
00488 /**** Setup Functions ****/
00489 int pre_flight_check(void);                           /* try and verify the configuration data */
00490 void init_timing_loop(void);                          /* setup the initial scheduling queue */
00491 void setup_sighandler(void);                          /* trap signals */
00492 void reset_sighandler(void);                          /* reset signals to default action */
00493 int daemon_init(void);                 /* switches to daemon mode */
00494 int drop_privileges(char *,char *);       /* drops privileges before startup */
00495 void display_scheduling_info(void);       /* displays service check scheduling information */
00496 
00497 
00498 /**** IPC Functions ****/
00499 int read_svc_message(service_message *);     /* reads a service check message from the message pipe */
00500 int write_svc_message(service_message *);    /* writes a service check message to the message pipe */
00501 int open_command_file(void);           /* creates the external command file as a named pipe (FIFO) and opens it for reading */
00502 int close_command_file(void);          /* closes and deletes the external command file (FIFO) */
00503 
00504 
00505 /**** Monitoring/Event Handler Functions ****/
00506 int schedule_new_event(int,int,time_t,int,unsigned long,void *,int,void *,void *); /* schedules a new timed event */
00507 void reschedule_event(timed_event *,timed_event **);     /* reschedules an event */
00508 int deschedule_event(int,int,void *,void *);            /* removes an event from the schedule */
00509 void add_event(timed_event *,timed_event **);      /* adds an event to the execution queue */
00510 void remove_event(timed_event *,timed_event **);      /* remove an event from the execution queue */
00511 int event_execution_loop(void);                       /* main monitoring/event handler loop */
00512 int handle_timed_event(timed_event *);          /* top level handler for timed events */
00513 void run_service_check(service *);        /* parallelized service check routine */
00514 void reap_service_checks(void);           /* handles results from service checks */
00515 int check_service_dependencies(service *,int);          /* checks service dependencies */
00516 int check_host_dependencies(host *,int);                /* checks host dependencies */
00517 void check_for_orphaned_services(void);         /* checks for orphaned services */
00518 void check_service_result_freshness(void);              /* checks the "freshness" of service check results */
00519 void check_host_result_freshness(void);                 /* checks the "freshness" of host check results */
00520 void adjust_check_scheduling(void);            /* auto-adjusts scheduling of host and service checks */
00521 int my_system(char *,int,int *,double *,char *,int);              /* executes a command via popen(), but also protects against timeouts */
00522 void compensate_for_system_time_change(unsigned long,unsigned long); /* attempts to compensate for a change in the system time */
00523 void adjust_timestamp_for_time_change(time_t,time_t,unsigned long,time_t *); /* adjusts a timestamp variable for a system time change */
00524 void resort_event_list(timed_event **);                 /* resorts event list by event run time for system time changes */
00525 
00526 
00527 /**** Flap Detection Functions ****/
00528 void check_for_service_flapping(service *,int);    /* determines whether or not a service is "flapping" between states */
00529 void check_for_host_flapping(host *,int);       /* determines whether or not a host is "flapping" between states */
00530 void set_service_flap(service *,double,double,double);      /* handles a service that is flapping */
00531 void clear_service_flap(service *,double,double,double); /* handles a service that has stopped flapping */
00532 void set_host_flap(host *,double,double,double);      /* handles a host that is flapping */
00533 void clear_host_flap(host *,double,double,double);    /* handles a host that has stopped flapping */
00534 void enable_flap_detection_routines(void);      /* enables flap detection on a program-wide basis */
00535 void disable_flap_detection_routines(void);     /* disables flap detection on a program-wide basis */
00536 void enable_host_flap_detection(host *);     /* enables flap detection for a particular host */
00537 void disable_host_flap_detection(host *);    /* disables flap detection for a particular host */
00538 void enable_service_flap_detection(service *);     /* enables flap detection for a particular service */
00539 void disable_service_flap_detection(service *);    /* disables flap detection for a particular service */
00540 
00541 
00542 /**** Route/Host Check Functions ****/
00543 int verify_route_to_host(host *,int);                   /* on-demand check of whether a host is up, down, or unreachable */
00544 int run_scheduled_host_check(host *);        /* runs a scheduled host check */
00545 int check_host(host *,int,int);                         /* checks if a host is up or down */
00546 int run_host_check(host *,int);                    /* runs a host check */
00547 int handle_host_state(host *);                     /* top level host state handler */
00548 
00549 
00550 /**** Event Handler Functions ****/
00551 int obsessive_compulsive_service_check_processor(service *);   /* distributed monitoring craziness... */
00552 int obsessive_compulsive_host_check_processor(host *);      /* distributed monitoring craziness... */
00553 int handle_service_event(service *);            /* top level service event logic */
00554 int run_service_event_handler(service *);       /* runs the event handler for a specific service */
00555 int run_global_service_event_handler(service *);      /* runs the global service event handler */
00556 int handle_host_event(host *);               /* top level host event logic */
00557 int run_host_event_handler(host *);          /* runs the event handler for a specific host */
00558 int run_global_host_event_handler(host *);         /* runs the global host event handler */
00559 
00560 
00561 /**** Notification Functions ****/
00562 int check_service_notification_viability(service *,int);    /* checks viability of notifying all contacts about a service */
00563 int is_valid_escalation_for_service_notification(service *,serviceescalation *); /* checks if an escalation entry is valid for a particular service notification */
00564 int should_service_notification_be_escalated(service *);    /* checks if a service notification should be escalated */
00565 int service_notification(service *,int,char *,char *);                           /* notify all contacts about a service (problem or recovery) */
00566 int check_contact_service_notification_viability(contact *,service *,int); /* checks viability of notifying a contact about a service */ 
00567 int notify_contact_of_service(contact *,service *,int,char *,char *,int);        /* notify a single contact about a service */
00568 int check_host_notification_viability(host *,int);       /* checks viability of notifying all contacts about a host */
00569 int is_valid_host_escalation_for_host_notification(host *,hostescalation *);  /* checks if an escalation entry is valid for a particular host notification */
00570 int should_host_notification_be_escalated(host *);       /* checks if a host notification should be escalated */
00571 int host_notification(host *,int,char *,char *);                              /* notify all contacts about a host (problem or recovery) */
00572 int check_contact_host_notification_viability(contact *,host *,int); /* checks viability of notifying a contact about a host */ 
00573 int notify_contact_of_host(contact *,host *,int,char *,char *,int);              /* notify a single contact about a host */
00574 int create_notification_list_from_host(host *,int *);          /* given a host, create list of contacts to be notified (remove duplicates) */
00575 int create_notification_list_from_service(service *,int *);       /* given a service, create list of contacts to be notified (remove duplicates) */
00576 int add_notification(contact *);          /* adds a notification instance */
00577 notification * find_notification(char *);       /* finds a notification object */
00578 time_t get_next_host_notification_time(host *,time_t);      /* calculates nex acceptable re-notification time for a host */
00579 time_t get_next_service_notification_time(service *,time_t);   /* calculates nex acceptable re-notification time for a service */
00580 
00581 
00582 /**** Logging Functions ****/
00583 int write_to_logs_and_console(char *,unsigned long,int); /* writes a string to screen and logs */
00584 int write_to_console(char *);                           /* writes a string to screen */
00585 int write_to_all_logs(char *,unsigned long);            /* writes a string to main log file and syslog facility */
00586 int write_to_all_logs_with_timestamp(char *,unsigned long,time_t *);   /* writes a string to main log file and syslog facility */
00587 int write_to_log(char *,unsigned long,time_t *);         /* write a string to the main log file */
00588 int write_to_syslog(char *,unsigned long);               /* write a string to the syslog facility */
00589 int log_service_event(service *);         /* logs a service event */
00590 int log_host_event(host *);            /* logs a host event */
00591 int log_host_states(int,time_t *);                  /* logs initial/current host states */
00592 int log_service_states(int,time_t *);                   /* logs initial/current service states */
00593 int rotate_log_file(time_t);              /* rotates the main log file */
00594 int write_log_file_info(time_t *);        /* records log file/version info */
00595 
00596 
00597 /**** Cleanup Functions ****/
00598 void cleanup(void);                                   /* cleanup after ourselves (before quitting or restarting) */
00599 void free_memory(void);                               /* free memory allocated to all linked lists in memory */
00600 int reset_variables(void);                            /* reset all global variables */
00601 void free_notification_list(void);           /* frees all memory allocated to the notification list */
00602 
00603 
00604 /**** Hash Functions ****/
00605 int hashfunc1(const char *name1, int hashslots);
00606 int hashfunc2(const char *name1, const char *name2, int hashslots);
00607 int compare_hashdata1(const char *,const char *);
00608 int compare_hashdata2(const char *,const char *,const char *,const char *);
00609 
00610 
00611 /**** Miscellaneous Functions ****/
00612 void sighandler(int);                                 /* handles signals */
00613 void service_check_sighandler(int);                     /* handles timeouts when executing service checks */
00614 void my_system_sighandler(int);           /* handles timeouts when executing commands via my_system() */
00615 void file_lock_sighandler(int);           /* handles timeouts while waiting for file locks */
00616 void strip(char *);                                   /* strips whitespace from string */  
00617 char *my_strtok(char *,char *);                       /* my replacement for strtok() function (doesn't skip consecutive tokens) */
00618 char *my_strsep(char **,const char *);          /* Solaris doesn't have strsep(), so I took this from the glibc source code */
00619 char *get_url_encoded_string(char *);        /* URL encode a string */
00620 int contains_illegal_object_chars(char *);      /* tests whether or not an object name (host, service, etc.) contains illegal characters */
00621 int my_rename(char *,char *);                           /* renames a file - works across filesystems */
00622 void get_raw_command_line(char *,char *,int,int);        /* given a raw command line, determine the actual command to run */
00623 int check_time_against_period(time_t,char *);      /* check to see if a specific time is covered by a time period */
00624 void get_next_valid_time(time_t, time_t *,char *); /* get the next valid time in a time period */
00625 void get_datetime_string(time_t *,char *,int,int); /* get a date/time string for use in output */
00626 time_t get_next_log_rotation_time(void);        /* determine the next time to schedule a log rotation */
00627 int init_embedded_perl(char **);       /* initialized embedded perl interpreter */
00628 int deinit_embedded_perl(void);           /* cleans up embedded perl */
00629 
00630 
00631 /**** Macro Functions ****/
00632 int process_macros(char *,char *,int,int);               /* replace macros with their actual values */
00633 char *clean_macro_chars(char *,int);                    /* cleans macros characters before insertion into output string */
00634 int grab_service_macros(service *);                   /* updates the service macro data */
00635 int grab_host_macros(host *);                         /* updates the host macro data */
00636 int grab_contact_macros(contact *);                   /* updates the contact macro data */
00637 int grab_datetime_macros(void);           /* updates date/time macros */
00638 int grab_summary_macros(contact *);       /* updates summary macros */
00639 int grab_on_demand_macro(char *);                       /* fetches an on-demand macro */
00640 int grab_on_demand_host_macro(host *,char *);      /* fetches an on-demand host macro */
00641 int grab_on_demand_service_macro(service *,char *);     /* fetches an on-demand service macro */
00642 int clear_argv_macros(void);                            /* clear all argv macros used in commands */
00643 int clear_volatile_macros(void);                      /* clear all "volatile" macros that change between service/host checks */
00644 int clear_nonvolatile_macros(void);                   /* clear all "nonvolatile" macros which remain relatively constant */
00645 
00646 
00647 /**** External Command Functions ****/
00648 void check_for_external_commands(void);         /* checks for any external commands */
00649 void process_external_command(int,time_t,char *);  /* process an external command */
00650 int process_host_command(int,time_t,char *);            /* process an external host command */
00651 int process_hostgroup_command(int,time_t,char *);       /* process an external hostgroup command */
00652 int process_service_command(int,time_t,char *);         /* process an external service command */
00653 int process_servicegroup_command(int,time_t,char *);    /* process an external servicegroup command */
00654 
00655 
00656 /**** External Command Implementations ****/
00657 int cmd_add_comment(int,time_t,char *);         /* add a service or host comment */
00658 int cmd_delete_comment(int,char *);       /* delete a service or host comment */
00659 int cmd_delete_all_comments(int,char *);     /* delete all comments associated with a host or service */
00660 int cmd_delay_notification(int,char *);         /* delay a service or host notification */
00661 int cmd_schedule_service_check(int,char *,int);    /* schedule an immediate or delayed service check */
00662 int cmd_schedule_check(int,char *);       /* schedule an immediate or delayed host check */
00663 int cmd_schedule_host_service_checks(int,char *,int); /* schedule an immediate or delayed checks of all services on a host */
00664 int cmd_signal_process(int,char *);          /* schedules a program shutdown or restart */
00665 int cmd_process_service_check_result(int,time_t,char *); /* processes a passive service check */
00666 int cmd_process_host_check_result(int,time_t,char *);    /* processes a passive host check */
00667 int cmd_acknowledge_problem(int,char *);        /* acknowledges a host or service problem */
00668 int cmd_remove_acknowledgement(int,char *);        /* removes a host or service acknowledgement */
00669 int cmd_schedule_downtime(int,time_t,char *);                   /* schedules host or service downtime */
00670 int cmd_delete_downtime(int,char *);            /* cancels active/pending host or service scheduled downtime */
00671 int cmd_change_command(int,char *);          /* changes host/svc command */
00672 int cmd_change_check_interval(int,char *);         /* changes host/svc check interval */
00673 int cmd_change_max_attempts(int,char *);        /* changes host/svc max attempts */
00674 
00675 int process_passive_service_check(time_t,char *,char *,int,char *);
00676 int process_passive_host_check(time_t,char *,int,char *);
00677 
00678 
00679 /**** Internal Command Implementations ****/
00680 void disable_service_checks(service *);         /* disables a service check */
00681 void enable_service_checks(service *);       /* enables a service check */
00682 void schedule_service_check(service *,time_t,int); /* schedules an immediate or delayed service check */
00683 void schedule_host_check(host *,time_t,int);    /* schedules an immediate or delayed host check */
00684 void enable_all_notifications(void);                    /* enables notifications on a program-wide basis */
00685 void disable_all_notifications(void);                   /* disables notifications on a program-wide basis */
00686 void enable_service_notifications(service *);      /* enables service notifications */
00687 void disable_service_notifications(service *);     /* disables service notifications */
00688 void enable_host_notifications(host *);         /* enables host notifications */
00689 void disable_host_notifications(host *);     /* disables host notifications */
00690 void enable_and_propagate_notifications(host *,int,int,int,int);  /* enables notifications for all hosts and services beyond a given host */
00691 void disable_and_propagate_notifications(host *,int,int,int,int); /* disables notifications for all hosts and services beyond a given host */
00692 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 */
00693 void acknowledge_host_problem(host *,char *,char *,int,int,int);  /* acknowledges a host problem */
00694 void acknowledge_service_problem(service *,char *,char *,int,int,int);  /* acknowledges a service problem */
00695 void remove_host_acknowledgement(host *);    /* removes a host acknowledgement */
00696 void remove_service_acknowledgement(service *);    /* removes a service acknowledgement */
00697 void start_executing_service_checks(void);      /* starts executing service checks */
00698 void stop_executing_service_checks(void);    /* stops executing service checks */
00699 void start_accepting_passive_service_checks(void); /* starts accepting passive service check results */
00700 void stop_accepting_passive_service_checks(void);  /* stops accepting passive service check results */
00701 void enable_passive_service_checks(service *);          /* enables passive service checks for a particular service */
00702 void disable_passive_service_checks(service *);         /* disables passive service checks for a particular service */
00703 void start_using_event_handlers(void);       /* enables event handlers on a program-wide basis */
00704 void stop_using_event_handlers(void);        /* disables event handlers on a program-wide basis */
00705 void enable_service_event_handler(service *);      /* enables the event handler for a particular service */
00706 void disable_service_event_handler(service *);     /* disables the event handler for a particular service */
00707 void enable_host_event_handler(host *);         /* enables the event handler for a particular host */
00708 void disable_host_event_handler(host *);     /* disables the event handler for a particular host */
00709 void enable_host_checks(host *);       /* enables checks of a particular host */
00710 void disable_host_checks(host *);         /* disables checks of a particular host */
00711 void start_obsessing_over_service_checks(void);    /* start obsessing about service check results */
00712 void stop_obsessing_over_service_checks(void);     /* stop obsessing about service check results */
00713 void start_obsessing_over_host_checks(void);    /* start obsessing about host check results */
00714 void stop_obsessing_over_host_checks(void);     /* stop obsessing about host check results */
00715 void enable_service_freshness_checks(void);     /* enable service freshness checks */
00716 void disable_service_freshness_checks(void);    /* disable service freshness checks */
00717 void enable_host_freshness_checks(void);     /* enable host freshness checks */
00718 void disable_host_freshness_checks(void);    /* disable host freshness checks */
00719 void process_passive_service_checks(void);              /* processes passive service check results */
00720 void enable_all_failure_prediction(void);               /* enables failure prediction on a program-wide basis */
00721 void disable_all_failure_prediction(void);              /* disables failure prediction on a program-wide basis */
00722 void enable_performance_data(void);                     /* enables processing of performance data on a program-wide basis */
00723 void disable_performance_data(void);                    /* disables processing of performance data on a program-wide basis */
00724 void start_executing_host_checks(void);         /* starts executing host checks */
00725 void stop_executing_host_checks(void);       /* stops executing host checks */
00726 void start_accepting_passive_host_checks(void);    /* starts accepting passive host check results */
00727 void stop_accepting_passive_host_checks(void);     /* stops accepting passive host check results */
00728 void enable_passive_host_checks(host *);          /* enables passive host checks for a particular host */
00729 void disable_passive_host_checks(host *);          /* disables passive host checks for a particular host */
00730 void start_obsessing_over_service(service *);      /* start obsessing about specific service check results */
00731 void stop_obsessing_over_service(service *);    /* stop obsessing about specific service check results */
00732 void start_obsessing_over_host(host *);         /* start obsessing about specific host check results */
00733 void stop_obsessing_over_host(host *);       /* stop obsessing about specific host check results */
00734 void set_host_notification_number(host *,int);     /* sets current notification number for a specific host */
00735 void set_service_notification_number(service *,int);  /* sets current notification number for a specific service */
00736 
00737 int init_service_result_worker_thread(void);
00738 int shutdown_service_result_worker_thread(void);
00739 void * service_result_worker_thread(void *);
00740 void cleanup_service_result_worker_thread(void *);
00741 
00742 int init_command_file_worker_thread(void);
00743 int shutdown_command_file_worker_thread(void);
00744 void * command_file_worker_thread(void *);
00745 void cleanup_command_file_worker_thread(void *);
00746 
00747 int submit_external_command(char *,int *);
00748 int submit_raw_external_command(char *,time_t *,int *);
00749 
00750 char *get_program_version(void);
00751 char *get_program_modification_date(void);
00752 
00753 mmapfile *mmap_fopen(char *);          /* open a file read-only via mmap() */
00754 int mmap_fclose(mmapfile *);
00755 char *mmap_fgets(mmapfile *);
00756 char *mmap_fgets_multiline(mmapfile *);
00757 
00758 
00759 int init_macrox_names(void);
00760 int add_macrox_name(int,char *);
00761 int free_macrox_names(void);
00762 int set_all_macro_environment_vars(int);
00763 int set_macrox_environment_vars(int);
00764 int set_argv_macro_environment_vars(int);
00765 int set_macro_environment_var(char *,char *,int);
00766 
00767 #ifdef __cplusplus
00768 }
00769 #endif
00770 #endif
00771 

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