include/icinga.h

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

Generated on Wed Mar 30 17:22:22 2011 for icinga-core by  doxygen 1.4.7