1 /*****************************************************************************
2  *
3  * OBJECTS.H - Header file for object addition/search functions
4  *
5  *
6  * License:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  *****************************************************************************/
22 
23 
24 #ifndef NAGIOS_OBJECTS_H_INCLUDED
25 #define NAGIOS_OBJECTS_H_INCLUDED
26 
27 #include "common.h"
28 
29 NAGIOS_BEGIN_DECL
30 
31 
32 /*************** CURRENT OBJECT REVISION **************/
33 
34 #define CURRENT_OBJECT_STRUCTURE_VERSION        403     /* increment when changes are made to data structures... */
35 /* Nagios 3 starts at 300, Nagios 4 at 400, etc. */
36 
37 
38 
39 /***************** OBJECT SIZE LIMITS *****************/
40 
41 #define MAX_STATE_HISTORY_ENTRIES		21	/* max number of old states to keep track of for flap detection */
42 #define MAX_CONTACT_ADDRESSES                   6       /* max number of custom addresses a contact can have */
43 
44 
45 
46 /***************** SKIP LISTS ****************/
47 
48 #define NUM_OBJECT_SKIPLISTS                   12
49 #define NUM_HASHED_OBJECT_TYPES                8
50 
51 #define HOST_SKIPLIST                          0
52 #define SERVICE_SKIPLIST                       1
53 #define COMMAND_SKIPLIST                       2
54 #define TIMEPERIOD_SKIPLIST                    3
55 #define CONTACT_SKIPLIST                       4
56 #define CONTACTGROUP_SKIPLIST                  5
57 #define HOSTGROUP_SKIPLIST                     6
58 #define SERVICEGROUP_SKIPLIST                  7
59 #define HOSTDEPENDENCY_SKIPLIST                8
60 #define SERVICEDEPENDENCY_SKIPLIST             9
61 #define HOSTESCALATION_SKIPLIST                10
62 #define SERVICEESCALATION_SKIPLIST             11
63 
64 
65 /***************** DATE RANGE TYPES *******************/
66 
67 #define DATERANGE_CALENDAR_DATE  0  /* 2008-12-25 */
68 #define DATERANGE_MONTH_DATE     1  /* july 4 (specific month) */
69 #define DATERANGE_MONTH_DAY      2  /* day 21 (generic month) */
70 #define DATERANGE_MONTH_WEEK_DAY 3  /* 3rd thursday (specific month) */
71 #define DATERANGE_WEEK_DAY       4  /* 3rd thursday (generic month) */
72 #define DATERANGE_TYPES          5
73 
74 
75 /*
76  * flags for notification_options, flapping_options and other similar
77  * flags. They overlap (hosts and services), so we can't use enum's.
78  */
79 #define OPT_NOTHING       0 /* no options selected */
80 #define OPT_ALL           (~0) /* everything selected, so all bits set */
81 #define OPT_DOWN          (1 << HOST_DOWN)
82 #define OPT_UP            (1 << HOST_UP)
83 #define OPT_UNREACHABLE   (1 << HOST_UNREACHABLE)
84 #define OPT_OK            (1 << STATE_OK)
85 #define OPT_WARNING       (1 << STATE_WARNING)
86 #define OPT_CRITICAL      (1 << STATE_CRITICAL)
87 #define OPT_UNKNOWN       (1 << STATE_UNKNOWN)
88 #define OPT_RECOVERY      OPT_OK
89 /* and now the "unreal" states... */
90 #define OPT_NOTIFICATIONS (1 << 9)
91 #define OPT_PENDING       (1 << 10)
92 #define OPT_FLAPPING      (1 << 11)
93 #define OPT_DOWNTIME      (1 << 12)
94 #define OPT_DISABLED      (1 << 15) /* will denote disabled checks some day */
95 
96 /* macros useful with both hosts and services */
97 #define flag_set(c, flag)    ((c) |= (flag))
98 #define flag_get(c, flag)    (unsigned int)((c) & (flag))
99 #define flag_isset(c, flag)  (flag_get((c), (flag)) == (unsigned int)(flag))
100 #define flag_unset(c, flag)  (c &= ~(flag))
101 #define should_stalk(o) flag_isset(o->stalking_options, 1 << o->current_state)
102 #define should_stalk_notifications(o) flag_isset(o->stalking_options, OPT_NOTIFICATIONS)
103 #define should_flap_detect(o) flag_isset(o->flap_detection_options, 1 << o->current_state)
104 #define should_notify(o) flag_isset(o->notification_options, 1 << o->current_state)
105 #define add_notified_on(o, f) (o->notified_on |= (1 << f))
106 
107 
108 /* Event-related macros */
109 #define NUDGE_MIN	5
110 #define NUDGE_MAX	17
111 
112 /****************** DATA STRUCTURES *******************/
113 
114 /* @todo Remove typedef's of non-opaque types in Nagios 5 */
115 typedef struct host host;
116 typedef struct service service;
117 typedef struct contact contact;
118 
119 /* TIMED_EVENT structure */
120 typedef struct timed_event {
121 	int event_type;
122 	time_t run_time;
123 	int recurring;
124 	unsigned long event_interval;
125 	int compensate_for_time_change;
126 	void *timing_func;
127 	void *event_data;
128 	void *event_args;
129 	int event_options;
130 	unsigned int priority; /* 0 is auto, 1 is highest. n+1 < n */
131 	struct squeue_event *sq_event;
132 	} timed_event;
133 
134 
135 /* NOTIFY_LIST structure */
136 typedef struct notify_list {
137 	struct contact *contact;
138 	struct notify_list *next;
139 	} notification;
140 
141 
142 /*
143  * *name can be "Nagios Core", "Merlin", "mod_gearman" or "DNX", fe.
144  * source_name gets passed the 'source' pointer from check_result
145  * and must return a non-free()'able string useful for printing what
146  * we need to determine exactly where the check was received from,
147  * such as "mod_gearman worker@10.11.12.13", or "Nagios Core command
148  * file worker" (for passive checks submitted locally), which will be
149  * stashed with hosts and services and used as the "CHECKSOURCE" macro.
150  */
151 struct check_engine {
152 	char *name;         /* "Nagios Core", "Merlin", "Mod Gearman" fe */
153 	const char *(*source_name)( const void *);
154 	void (*clean_result)(void *);
155 };
156 
157 /* CHECK_RESULT structure */
158 typedef struct check_result {
159 	int object_check_type;                          /* is this a service or a host check? */
160 	char *host_name;                                /* host name */
161 	char *service_description;                      /* service description */
162 	int check_type;					/* was this an active or passive service check? */
163 	int check_options;
164 	int scheduled_check;                            /* was this a scheduled or an on-demand check? */
165 	int reschedule_check;                           /* should we reschedule the next check */
166 	char *output_file;                              /* what file is the output stored in? */
167 	FILE *output_file_fp;
168 	double latency;
169 	struct timeval start_time;			/* time the service check was initiated */
170 	struct timeval finish_time;			/* time the service check was completed */
171 	int early_timeout;                              /* did the service check timeout? */
172 	int exited_ok;					/* did the plugin check return okay? */
173 	int return_code;				/* plugin return code */
174 	char *output;	                                /* plugin output */
175 	/* 5DEPR: rusage is deprecated in Nagios, will be removed in 5.0.0 */
176 	struct rusage rusage;   			/* resource usage by this check */
177 	struct check_engine *engine;                    /* where did we get this check from? */
178 	const void *source;				/* engine handles this */
179 	} check_result;
180 
181 
182 /* SCHED_INFO structure */
183 typedef struct sched_info {
184 	int total_services;
185 	int total_scheduled_services;
186 	int total_hosts;
187 	int total_scheduled_hosts;
188 	double average_services_per_host;
189 	double average_scheduled_services_per_host;
190 	unsigned long service_check_interval_total;
191 	unsigned long host_check_interval_total;
192 	double average_service_execution_time;
193 	double average_service_check_interval;
194 	double average_host_check_interval;
195 	double average_service_inter_check_delay;
196 	double average_host_inter_check_delay;
197 	double service_inter_check_delay;
198 	double host_inter_check_delay;
199 	int service_interleave_factor;
200 	int max_service_check_spread;
201 	int max_host_check_spread;
202 	time_t first_service_check;
203 	time_t last_service_check;
204 	time_t first_host_check;
205 	time_t last_host_check;
206 	} sched_info;
207 
208 
209 /* DBUF structure - dynamic string storage */
210 typedef struct dbuf {
211 	char *buf;
212 	unsigned long used_size;
213 	unsigned long allocated_size;
214 	unsigned long chunk_size;
215 	} dbuf;
216 
217 
218 #define CHECK_STATS_BUCKETS                  15
219 
220 /* used for tracking host and service check statistics */
221 typedef struct check_stats {
222 	int current_bucket;
223 	int bucket[CHECK_STATS_BUCKETS];
224 	int overflow_bucket;
225 	int minute_stats[3];
226 	time_t last_update;
227 	} check_stats;
228 
229 
230 
231 /* OBJECT LIST STRUCTURE */
232 typedef struct objectlist {
233 	void      *object_ptr;
234 	struct objectlist *next;
235 	} objectlist;
236 
237 
238 /* TIMERANGE structure */
239 typedef struct timerange {
240 	unsigned long range_start;
241 	unsigned long range_end;
242 	struct timerange *next;
243 	} timerange;
244 
245 
246 /* DATERANGE structure */
247 typedef struct daterange {
248 	int type;
249 	int syear;          /* start year */
250 	int smon;           /* start month */
251 	int smday;          /* start day of month (may 3rd, last day in feb) */
252 	int swday;          /* start day of week (thursday) */
253 	int swday_offset;   /* start weekday offset (3rd thursday, last monday in jan) */
254 	int eyear;
255 	int emon;
256 	int emday;
257 	int ewday;
258 	int ewday_offset;
259 	int skip_interval;
260 	struct timerange *times;
261 	struct daterange *next;
262 	} daterange;
263 
264 
265 /* TIMEPERIODEXCLUSION structure */
266 typedef struct timeperiodexclusion {
267 	char  *timeperiod_name;
268 	struct timeperiod *timeperiod_ptr;
269 	struct timeperiodexclusion *next;
270 	} timeperiodexclusion;
271 
272 
273 /* TIMEPERIOD structure */
274 typedef struct timeperiod {
275 	unsigned int id;
276 	char    *name;
277 	char    *alias;
278 	struct timerange *days[7];
279 	struct daterange *exceptions[DATERANGE_TYPES];
280 	struct timeperiodexclusion *exclusions;
281 	struct timeperiod *next;
282 	} timeperiod;
283 
284 
285 /* CONTACTSMEMBER structure */
286 typedef struct contactsmember {
287 	char    *contact_name;
288 	struct contact *contact_ptr;
289 	struct contactsmember *next;
290 	} contactsmember;
291 
292 
293 /* CONTACTGROUP structure */
294 typedef struct contactgroup {
295 	unsigned int id;
296 	char	*group_name;
297 	char    *alias;
298 	struct contactsmember *members;
299 	struct contactgroup *next;
300 	} contactgroup;
301 
302 
303 /* CONTACTGROUPSMEMBER structure */
304 typedef struct contactgroupsmember {
305 	char    *group_name;
306 	struct contactgroup *group_ptr;
307 	struct contactgroupsmember *next;
308 	} contactgroupsmember;
309 
310 
311 /* CUSTOMVARIABLESMEMBER structure */
312 typedef struct customvariablesmember {
313 	char    *variable_name;
314 	char    *variable_value;
315 	int     has_been_modified;
316 	struct customvariablesmember *next;
317 	} customvariablesmember;
318 
319 
320 /* COMMAND structure */
321 typedef struct command {
322 	unsigned int id;
323 	char    *name;
324 	char    *command_line;
325 	struct command *next;
326 	} command;
327 
328 
329 /* COMMANDSMEMBER structure */
330 typedef struct commandsmember {
331 	char	*command;
332 	struct command *command_ptr;
333 	struct	commandsmember *next;
334 	} commandsmember;
335 
336 
337 /* CONTACT structure */
338 struct contact {
339 	unsigned int id;
340 	char	*name;
341 	char	*alias;
342 	char	*email;
343 	char	*pager;
344 	char    *address[MAX_CONTACT_ADDRESSES];
345 	struct commandsmember *host_notification_commands;
346 	struct commandsmember *service_notification_commands;
347 	unsigned int host_notification_options;
348 	unsigned int service_notification_options;
349 	unsigned int minimum_value;
350 	char	*host_notification_period;
351 	char	*service_notification_period;
352 	int     host_notifications_enabled;
353 	int     service_notifications_enabled;
354 	int     can_submit_commands;
355 	int     retain_status_information;
356 	int     retain_nonstatus_information;
357 	struct customvariablesmember *custom_variables;
358 #ifndef NSCGI
359 	time_t  last_host_notification;
360 	time_t  last_service_notification;
361 	unsigned long modified_attributes;
362 	unsigned long modified_host_attributes;
363 	unsigned long modified_service_attributes;
364 #endif
365 
366 	struct timeperiod *host_notification_period_ptr;
367 	struct timeperiod *service_notification_period_ptr;
368 	struct objectlist *contactgroups_ptr;
369 	struct	contact *next;
370 	};
371 
372 
373 /* SERVICESMEMBER structure */
374 typedef struct servicesmember {
375 	char    *host_name;
376 	char    *service_description;
377 	struct service *service_ptr;
378 	struct servicesmember *next;
379 	} servicesmember;
380 
381 
382 /* HOSTSMEMBER structure */
383 typedef struct hostsmember {
384 	char    *host_name;
385 	struct host    *host_ptr;
386 	struct hostsmember *next;
387 	} hostsmember;
388 
389 
390 /* HOSTGROUP structure */
391 typedef struct hostgroup {
392 	unsigned int id;
393 	char 	*group_name;
394 	char    *alias;
395 	struct hostsmember *members;
396 	char    *notes;
397 	char    *notes_url;
398 	char    *action_url;
399 	struct	hostgroup *next;
400 	} hostgroup;
401 
402 
403 /* HOST structure */
404 struct host {
405 	unsigned int id;
406 	char    *name;
407 	char    *display_name;
408 	char	*alias;
409 	char    *address;
410 	struct hostsmember *parent_hosts;
411 	struct hostsmember *child_hosts;
412 	struct servicesmember *services;
413 	char    *check_command;
414 	int     initial_state;
415 	double  check_interval;
416 	double  retry_interval;
417 	int     max_attempts;
418 	char    *event_handler;
419 	struct contactgroupsmember *contact_groups;
420 	struct contactsmember *contacts;
421 	double  notification_interval;
422 	double  first_notification_delay;
423 	unsigned int notification_options;
424 	unsigned int hourly_value;
425 	char	*notification_period;
426 	char    *check_period;
427 	int     flap_detection_enabled;
428 	double  low_flap_threshold;
429 	double  high_flap_threshold;
430 	int     flap_detection_options;
431 	unsigned int stalking_options;
432 	int     check_freshness;
433 	int     freshness_threshold;
434 	int     process_performance_data;
435 	int     checks_enabled;
436 	const char *check_source;
437 	int     accept_passive_checks;
438 	int     event_handler_enabled;
439 	int     retain_status_information;
440 	int     retain_nonstatus_information;
441 	int     obsess;
442 	char    *notes;
443 	char    *notes_url;
444 	char    *action_url;
445 	char    *icon_image;
446 	char    *icon_image_alt;
447 	char    *statusmap_image; /* used by lots of graphing tools */
448 /* #ifdef NSCGI */
449 	/*
450 	 * these are kept in ancillary storage for the daemon and
451 	 * thrown out as soon as we've created the object cache.
452 	 * The CGI's still attach them though, since they are the
453 	 * only users of this utter crap.
454 	 */
455 	char    *vrml_image;
456 	int     have_2d_coords;
457 	int     x_2d;
458 	int     y_2d;
459 	int     have_3d_coords;
460 	double  x_3d;
461 	double  y_3d;
462 	double  z_3d;
463 	int     should_be_drawn;
464 /* #endif */
465 	customvariablesmember *custom_variables;
466 #ifndef NSCGI
467 	int     problem_has_been_acknowledged;
468 	int     acknowledgement_type;
469 	int     check_type;
470 	int     current_state;
471 	int     last_state;
472 	int     last_hard_state;
473 	char	*plugin_output;
474 	char    *long_plugin_output;
475 	char    *perf_data;
476 	int     state_type;
477 	int     current_attempt;
478 	unsigned long current_event_id;
479 	unsigned long last_event_id;
480 	unsigned long current_problem_id;
481 	unsigned long last_problem_id;
482 	double  latency;
483 	double  execution_time;
484 	int     is_executing;
485 	int     check_options;
486 	int     notifications_enabled;
487 	time_t  last_notification;
488 	time_t  next_notification;
489 	time_t  next_check;
490 	int     should_be_scheduled;
491 	time_t  last_check;
492 	time_t	last_state_change;
493 	time_t	last_hard_state_change;
494 	time_t  last_time_up;
495 	time_t  last_time_down;
496 	time_t  last_time_unreachable;
497 	int     has_been_checked;
498 	int     is_being_freshened;
499 	int     notified_on;
500 	int     current_notification_number;
501 	int     no_more_notifications;
502 	unsigned long current_notification_id;
503 	int     check_flapping_recovery_notification;
504 	int     scheduled_downtime_depth;
505 	int     pending_flex_downtime;
506 	int     state_history[MAX_STATE_HISTORY_ENTRIES];    /* flap detection */
507 	int     state_history_index;
508 	time_t  last_state_history_update;
509 	int     is_flapping;
510 	unsigned long flapping_comment_id;
511 	double  percent_state_change;
512 	int     total_services;
513 	unsigned long total_service_check_interval;
514 	unsigned long modified_attributes;
515 #endif
516 
517 	struct command *event_handler_ptr;
518 	struct command *check_command_ptr;
519 	struct timeperiod *check_period_ptr;
520 	struct timeperiod *notification_period_ptr;
521 	struct objectlist *hostgroups_ptr;
522 	/* objects we depend upon */
523 	struct objectlist *exec_deps, *notify_deps;
524 	struct objectlist *escalation_list;
525 	struct  host *next;
526 	struct timed_event *next_check_event;
527 	};
528 
529 
530 /* SERVICEGROUP structure */
531 typedef struct servicegroup {
532 	unsigned int id;
533 	char 	*group_name;
534 	char    *alias;
535 	struct servicesmember *members;
536 	char    *notes;
537 	char    *notes_url;
538 	char    *action_url;
539 	struct	servicegroup *next;
540 	} servicegroup;
541 
542 
543 /* SERVICE structure */
544 struct service {
545 	unsigned int id;
546 	char	*host_name;
547 	char	*description;
548 	char    *display_name;
549 	struct servicesmember *parents;
550 	struct servicesmember *children;
551 	char    *check_command;
552 	char    *event_handler;
553 	int     initial_state;
554 	double	check_interval;
555 	double  retry_interval;
556 	int	max_attempts;
557 	int     parallelize;
558 	struct contactgroupsmember *contact_groups;
559 	struct contactsmember *contacts;
560 	double	notification_interval;
561 	double  first_notification_delay;
562 	unsigned int notification_options;
563 	unsigned int stalking_options;
564 	unsigned int hourly_value;
565 	int     is_volatile;
566 	char	*notification_period;
567 	char	*check_period;
568 	int     flap_detection_enabled;
569 	double  low_flap_threshold;
570 	double  high_flap_threshold;
571 	unsigned int flap_detection_options;
572 	int     process_performance_data;
573 	int     check_freshness;
574 	int     freshness_threshold;
575 	int     accept_passive_checks;
576 	int     event_handler_enabled;
577 	int	checks_enabled;
578 	const char *check_source;
579 	int     retain_status_information;
580 	int     retain_nonstatus_information;
581 	int     notifications_enabled;
582 	int     obsess;
583 	char    *notes;
584 	char    *notes_url;
585 	char    *action_url;
586 	char    *icon_image;
587 	char    *icon_image_alt;
588 	struct customvariablesmember *custom_variables;
589 #ifndef NSCGI
590 	int     problem_has_been_acknowledged;
591 	int     acknowledgement_type;
592 	int     host_problem_at_last_check;
593 	int     check_type;
594 	int	current_state;
595 	int	last_state;
596 	int	last_hard_state;
597 	char	*plugin_output;
598 	char    *long_plugin_output;
599 	char    *perf_data;
600 	int     state_type;
601 	time_t	next_check;
602 	int     should_be_scheduled;
603 	time_t	last_check;
604 	int	current_attempt;
605 	unsigned long current_event_id;
606 	unsigned long last_event_id;
607 	unsigned long current_problem_id;
608 	unsigned long last_problem_id;
609 	time_t	last_notification;
610 	time_t  next_notification;
611 	int     no_more_notifications;
612 	int     check_flapping_recovery_notification;
613 	time_t	last_state_change;
614 	time_t	last_hard_state_change;
615 	time_t  last_time_ok;
616 	time_t  last_time_warning;
617 	time_t  last_time_unknown;
618 	time_t  last_time_critical;
619 	int     has_been_checked;
620 	int     is_being_freshened;
621 	unsigned int notified_on;
622 	int     current_notification_number;
623 	unsigned long current_notification_id;
624 	double  latency;
625 	double  execution_time;
626 	int     is_executing;
627 	int     check_options;
628 	int     scheduled_downtime_depth;
629 	int     pending_flex_downtime;
630 	int     state_history[MAX_STATE_HISTORY_ENTRIES];    /* flap detection */
631 	int     state_history_index;
632 	int     is_flapping;
633 	unsigned long flapping_comment_id;
634 	double  percent_state_change;
635 	unsigned long modified_attributes;
636 #endif
637 
638 	struct host *host_ptr;
639 	struct command *event_handler_ptr;
640 	char *event_handler_args;
641 	struct command *check_command_ptr;
642 	char *check_command_args;
643 	struct timeperiod *check_period_ptr;
644 	struct timeperiod *notification_period_ptr;
645 	struct objectlist *servicegroups_ptr;
646 	struct objectlist *exec_deps, *notify_deps;
647 	struct objectlist *escalation_list;
648 	struct service *next;
649 	struct timed_event *next_check_event;
650 	};
651 
652 
653 /* SERVICE ESCALATION structure */
654 typedef struct serviceescalation {
655 	unsigned int id;
656 	char    *host_name;
657 	char    *description;
658 	int     first_notification;
659 	int     last_notification;
660 	double  notification_interval;
661 	char    *escalation_period;
662 	int     escalation_options;
663 	struct contactgroupsmember *contact_groups;
664 	struct contactsmember *contacts;
665 	struct service *service_ptr;
666 	struct timeperiod *escalation_period_ptr;
667 	} serviceescalation;
668 
669 
670 /* SERVICE DEPENDENCY structure */
671 typedef struct servicedependency {
672 	unsigned int id;
673 	int     dependency_type;
674 	char    *dependent_host_name;
675 	char    *dependent_service_description;
676 	char    *host_name;
677 	char    *service_description;
678 	char    *dependency_period;
679 	int     inherits_parent;
680 	int     failure_options;
681 	struct service *master_service_ptr;
682 	struct service *dependent_service_ptr;
683 	struct timeperiod *dependency_period_ptr;
684 	} servicedependency;
685 
686 
687 /* HOST ESCALATION structure */
688 typedef struct hostescalation {
689 	unsigned int id;
690 	char    *host_name;
691 	int     first_notification;
692 	int     last_notification;
693 	double  notification_interval;
694 	char    *escalation_period;
695 	int     escalation_options;
696 	struct contactgroupsmember *contact_groups;
697 	struct contactsmember *contacts;
698 	struct host    *host_ptr;
699 	struct timeperiod *escalation_period_ptr;
700 	} hostescalation;
701 
702 
703 /* HOST DEPENDENCY structure */
704 typedef struct hostdependency {
705 	unsigned int id;
706 	int     dependency_type;
707 	char    *dependent_host_name;
708 	char    *host_name;
709 	char    *dependency_period;
710 	int     inherits_parent;
711 	int     failure_options;
712 	struct host    *master_host_ptr;
713 	struct host    *dependent_host_ptr;
714 	struct timeperiod *dependency_period_ptr;
715 	} hostdependency;
716 
717 extern struct command *command_list;
718 extern struct timeperiod *timeperiod_list;
719 extern struct host *host_list;
720 extern struct service *service_list;
721 extern struct contact *contact_list;
722 extern struct hostgroup *hostgroup_list;
723 extern struct servicegroup *servicegroup_list;
724 extern struct contactgroup *contactgroup_list;
725 extern struct hostescalation *hostescalation_list;
726 extern struct serviceescalation *serviceescalation_list;
727 extern struct command **command_ary;
728 extern struct timeperiod **timeperiod_ary;
729 extern struct host **host_ary;
730 extern struct service **service_ary;
731 extern struct contact **contact_ary;
732 extern struct hostgroup **hostgroup_ary;
733 extern struct servicegroup **servicegroup_ary;
734 extern struct contactgroup **contactgroup_ary;
735 extern struct hostescalation **hostescalation_ary;
736 extern struct hostdependency **hostdependency_ary;
737 extern struct serviceescalation **serviceescalation_ary;
738 extern struct servicedependency **servicedependency_ary;
739 
740 
741 /********************* FUNCTIONS **********************/
742 
743 /**** Top-level input functions ****/
744 int read_object_config_data(const char *, int);     /* reads all external configuration data of specific types */
745 
746 
747 /**** Object Creation Functions ****/
748 struct contact *add_contact(char *name, char *alias, char *email, char *pager, char **addresses, char *svc_notification_period, char *host_notification_period, int service_notification_options, int host_notification_options, int service_notifications_enabled, int host_notifications_enabled, int can_submit_commands, int retain_status_information, int retain_nonstatus_information, unsigned int minimum_value);
749 struct commandsmember *add_service_notification_command_to_contact(contact *, char *);				/* adds a service notification command to a contact definition */
750 struct commandsmember *add_host_notification_command_to_contact(contact *, char *);				/* adds a host notification command to a contact definition */
751 struct customvariablesmember *add_custom_variable_to_contact(contact *, char *, char *);                       /* adds a custom variable to a service definition */
752 struct host *add_host(char *name, char *display_name, char *alias, char *address, char *check_period, int initial_state, double check_interval, double retry_interval, int max_attempts, int notification_options, double notification_interval, double first_notification_delay, char *notification_period, int notifications_enabled, char *check_command, int checks_enabled, int accept_passive_checks, char *event_handler, int event_handler_enabled, int flap_detection_enabled, double low_flap_threshold, double high_flap_threshold, int flap_detection_options, int stalking_options, int process_perfdata, int check_freshness, int freshness_threshold, char *notes, char *notes_url, char *action_url, char *icon_image, char *icon_image_alt, char *vrml_image, char *statusmap_image, int x_2d, int y_2d, int have_2d_coords, double x_3d, double y_3d, double z_3d, int have_3d_coords, int should_be_drawn, int retain_status_information, int retain_nonstatus_information, int obsess_over_host, unsigned int hourly_value);
753 struct hostsmember *add_parent_host_to_host(host *, char *);							/* adds a parent host to a host definition */
754 struct servicesmember *add_parent_service_to_service(service *, char *host_name, char *description);
755 struct hostsmember *add_child_link_to_host(host *, host *);						       /* adds a child host to a host definition */
756 struct servicesmember *add_child_link_to_service(service *, service *);						       /* adds a child host to a host definition */
757 struct contactgroupsmember *add_contactgroup_to_host(host *, char *);					       /* adds a contactgroup to a host definition */
758 struct contactsmember *add_contact_to_host(host *, char *);                                                    /* adds a contact to a host definition */
759 struct customvariablesmember *add_custom_variable_to_host(host *, char *, char *);                             /* adds a custom variable to a host definition */
760 struct timeperiod *add_timeperiod(char *, char *);								/* adds a timeperiod definition */
761 struct timeperiodexclusion *add_exclusion_to_timeperiod(timeperiod *, char *);                                 /* adds an exclusion to a timeperiod */
762 struct timerange *add_timerange_to_timeperiod(timeperiod *, int, unsigned long, unsigned long);			/* adds a timerange to a timeperiod definition */
763 struct daterange *add_exception_to_timeperiod(timeperiod *, int, int, int, int, int, int, int, int, int, int, int, int);
764 struct timerange *add_timerange_to_daterange(daterange *, unsigned long, unsigned long);
765 struct hostgroup *add_hostgroup(char *, char *, char *, char *, char *);						/* adds a hostgroup definition */
766 struct hostsmember *add_host_to_hostgroup(hostgroup *, char *);						/* adds a host to a hostgroup definition */
767 struct servicegroup *add_servicegroup(char *, char *, char *, char *, char *);                                 /* adds a servicegroup definition */
768 struct servicesmember *add_service_to_servicegroup(servicegroup *, char *, char *);                            /* adds a service to a servicegroup definition */
769 struct contactgroup *add_contactgroup(char *, char *);								/* adds a contactgroup definition */
770 struct contactsmember *add_contact_to_contactgroup(contactgroup *, char *);					/* adds a contact to a contact group definition */
771 struct command *add_command(char *, char *);									/* adds a command definition */
772 struct service *add_service(char *host_name, char *description, char *display_name, char *check_period, int initial_state, int max_attempts, int parallelize, int accept_passive_checks, double check_interval, double retry_interval, double notification_interval, double first_notification_delay, char *notification_period, int notification_options, int notifications_enabled, int is_volatile, char *event_handler, int event_handler_enabled, char *check_command, int checks_enabled, int flap_detection_enabled, double low_flap_threshold, double high_flap_threshold, int flap_detection_options, int stalking_options, int process_perfdata, int check_freshness, int freshness_threshold, char *notes, char *notes_url, char *action_url, char *icon_image, char *icon_image_alt, int retain_status_information, int retain_nonstatus_information, int obsess_over_service, unsigned int hourly_value);
773 struct contactgroupsmember *add_contactgroup_to_service(service *, char *);					/* adds a contact group to a service definition */
774 struct contactsmember *add_contact_to_service(service *, char *);                                              /* adds a contact to a host definition */
775 struct serviceescalation *add_serviceescalation(char *host_name, char *description, int first_notification, int last_notification, double notification_interval, char *escalation_period, int escalation_options);
776 struct contactgroupsmember *add_contactgroup_to_serviceescalation(serviceescalation *, char *);                /* adds a contact group to a service escalation definition */
777 struct contactsmember *add_contact_to_serviceescalation(serviceescalation *, char *);                          /* adds a contact to a service escalation definition */
778 struct customvariablesmember *add_custom_variable_to_service(service *, char *, char *);                       /* adds a custom variable to a service definition */
779 struct servicedependency *add_service_dependency(char *dependent_host_name, char *dependent_service_description, char *host_name, char *service_description, int dependency_type, int inherits_parent, int failure_options, char *dependency_period);
780 struct hostdependency *add_host_dependency(char *dependent_host_name, char *host_name, int dependency_type, int inherits_parent, int failure_options, char *dependency_period);
781 struct hostescalation *add_hostescalation(char *host_name, int first_notification, int last_notification, double notification_interval, char *escalation_period, int escalation_options);
782 struct contactsmember *add_contact_to_hostescalation(hostescalation *, char *);                                /* adds a contact to a host escalation definition */
783 struct contactgroupsmember *add_contactgroup_to_hostescalation(hostescalation *, char *);                      /* adds a contact group to a host escalation definition */
784 
785 struct contactsmember *add_contact_to_object(contactsmember **, char *);                                       /* adds a contact to an object */
786 struct customvariablesmember *add_custom_variable_to_object(customvariablesmember **, char *, char *);         /* adds a custom variable to an object */
787 
788 
789 struct servicesmember *add_service_link_to_host(host *, service *);
790 
791 
792 int skiplist_compare_text(const char *val1a, const char *val1b, const char *val2a, const char *val2b);
793 int get_host_count(void);
794 int get_service_count(void);
795 
796 
797 int create_object_tables(unsigned int *);
798 
799 /**** Object Search Functions ****/
800 struct timeperiod *find_timeperiod(const char *);
801 struct host *find_host(const char *);
802 struct hostgroup *find_hostgroup(const char *);
803 struct servicegroup *find_servicegroup(const char *);
804 struct contact *find_contact(const char *);
805 struct contactgroup *find_contactgroup(const char *);
806 struct command *find_command(const char *);
807 struct service *find_service(const char *, const char *);
808 
809 
810 #define OBJECTLIST_DUPE 1
811 int add_object_to_objectlist(struct objectlist **, void *);
812 int prepend_object_to_objectlist(struct objectlist **, void *);
813 int prepend_unique_object_to_objectlist(struct objectlist **, void *, size_t size);
814 int free_objectlist(objectlist **);
815 
816 
817 /**** Object Query Functions ****/
818 unsigned int host_services_value(struct host *h);
819 int is_host_immediate_child_of_host(struct host *, struct host *);	               /* checks if a host is an immediate child of another host */
820 int is_host_primary_immediate_child_of_host(struct host *, struct host *);            /* checks if a host is an immediate child (and primary child) of another host */
821 int is_host_immediate_parent_of_host(struct host *, struct host *);	               /* checks if a host is an immediate child of another host */
822 int is_host_member_of_hostgroup(struct hostgroup *, struct host *);		       /* tests whether or not a host is a member of a specific hostgroup */
823 int is_host_member_of_servicegroup(struct servicegroup *, struct host *);	       /* tests whether or not a service is a member of a specific servicegroup */
824 int is_service_member_of_servicegroup(struct servicegroup *, struct service *);	/* tests whether or not a service is a member of a specific servicegroup */
825 int is_contact_member_of_contactgroup(struct contactgroup *, struct contact *);	/* tests whether or not a contact is a member of a specific contact group */
826 int is_contact_for_host(struct host *, struct contact *);			       /* tests whether or not a contact is a contact member for a specific host */
827 int is_contactgroup_for_host(struct host *, struct contactgroup *);
828 	/* tests whether a contact group is a contract group for a specific host */
829 int is_escalated_contact_for_host(struct host *, struct contact *);                   /* checks whether or not a contact is an escalated contact for a specific host */
830 int is_contact_for_host_escalation(hostescalation *, contact *);
831 	/* tests whether a contact is an contact for a particular host escalation */
832 int is_contactgroup_for_host_escalation(hostescalation *, contactgroup *);
833 	/*  tests whether a contactgroup is a contactgroup for a particular
834 	host escalation */
835 int is_contact_for_service(struct service *, struct contact *);		       /* tests whether or not a contact is a contact member for a specific service */
836 int is_contactgroup_for_service(struct service *, struct contactgroup *);
837 	/* tests whether a contact group is a contract group for a specific service */
838 int is_escalated_contact_for_host(struct host *, struct contact *);                   /* checks whether or not a contact is an escalated contact for a specific host */
839 int is_escalated_contact_for_service(struct service *, struct contact *);             /* checks whether or not a contact is an escalated contact for a specific service */
840 int is_contact_for_service_escalation(serviceescalation *, contact *);
841 	/* tests whether a contact is an contact for a particular service
842 		escalation */
843 int is_contactgroup_for_service_escalation(serviceescalation *, contactgroup *);
844 /*  tests whether a contactgroup is a contactgroup for a particular
845 	service escalation */
846 
847 int number_of_immediate_child_hosts(struct host *);		                /* counts the number of immediate child hosts for a particular host */
848 int number_of_total_child_hosts(struct host *);				/* counts the number of total child hosts for a particular host */
849 int number_of_immediate_parent_hosts(struct host *);				/* counts the number of immediate parents hosts for a particular host */
850 
851 #ifndef NSCGI
852 void fcache_contactlist(FILE *fp, const char *prefix, struct contactsmember *list);
853 void fcache_contactgrouplist(FILE *fp, const char *prefix, struct contactgroupsmember *list);
854 void fcache_hostlist(FILE *fp, const char *prefix, struct hostsmember *list);
855 void fcache_customvars(FILE *fp, struct customvariablesmember *cvlist);
856 void fcache_timeperiod(FILE *fp, struct timeperiod *temp_timeperiod);
857 void fcache_command(FILE *fp, struct command *temp_command);
858 void fcache_contactgroup(FILE *fp, struct contactgroup *temp_contactgroup);
859 void fcache_hostgroup(FILE *fp, struct hostgroup *temp_hostgroup);
860 void fcache_servicegroup(FILE *fp, struct servicegroup *temp_servicegroup);
861 void fcache_contact(FILE *fp, struct contact *temp_contact);
862 void fcache_host(FILE *fp, struct host *temp_host);
863 void fcache_service(FILE *fp, struct service *temp_service);
864 void fcache_servicedependency(FILE *fp, struct servicedependency *temp_servicedependency);
865 void fcache_serviceescalation(FILE *fp, struct serviceescalation *temp_serviceescalation);
866 void fcache_hostdependency(FILE *fp, struct hostdependency *temp_hostdependency);
867 void fcache_hostescalation(FILE *fp, struct hostescalation *temp_hostescalation);
868 int fcache_objects(char *cache_file);
869 #endif
870 
871 
872 /**** Object Cleanup Functions ****/
873 int free_object_data(void);                             /* frees all allocated memory for the object definitions */
874 
875 
876 NAGIOS_END_DECL
877 #endif
878