1 /*****************************************************************************
2  *
3  * STATUSDATA.H - Header for external status data routines
4  *
5  * Copyright (c) 2000-2007 Ethan Galstad (egalstad@nagios.org)
6  * Last Modified:   10-19-2007
7  *
8  * License:
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  *****************************************************************************/
24 
25 #ifndef _STATUSDATA_H
26 #define _STATUSDATA_H
27 
28 #include "compat.h"
29 
30 #ifdef NSCORE
31 #include "objects.h"
32 #endif
33 
34 #ifdef NSCGI
35 
36 #define READ_PROGRAM_STATUS	1
37 #define READ_HOST_STATUS	2
38 #define READ_SERVICE_STATUS	4
39 #define READ_CONTACT_STATUS     8
40 
41 #define READ_ALL_STATUS_DATA    READ_PROGRAM_STATUS | READ_HOST_STATUS | READ_SERVICE_STATUS | READ_CONTACT_STATUS
42 
43 
44 
45 	/*************************** CHAINED HASH LIMITS ***************************/
46 
47 #define SERVICESTATUS_HASHSLOTS      1024
48 #define HOSTSTATUS_HASHSLOTS         1024
49 
50 
51 	/**************************** DATA STRUCTURES ******************************/
52 
53 NAGIOS_BEGIN_DECL
54 
55 /* HOST STATUS structure */
56 typedef struct hoststatus_struct {
57 	char    *host_name;
58 	char    *plugin_output;
59 	char    *long_plugin_output;
60 	char    *perf_data;
61 	int     status;
62 	time_t  last_update;
63 	int     has_been_checked;
64 	int     should_be_scheduled;
65 	int     current_attempt;
66 	int     max_attempts;
67 	time_t  last_check;
68 	time_t  next_check;
69 	int     check_options;
70 	int     check_type;
71 	time_t	last_state_change;
72 	time_t	last_hard_state_change;
73 	int     last_hard_state;
74 	time_t  last_time_up;
75 	time_t  last_time_down;
76 	time_t  last_time_unreachable;
77 	int     state_type;
78 	time_t  last_notification;
79 	time_t  next_notification;
80 	int     no_more_notifications;
81 	int     notifications_enabled;
82 	int     problem_has_been_acknowledged;
83 	int     acknowledgement_type;
84 	int     current_notification_number;
85 	int     accept_passive_host_checks;
86 	int     event_handler_enabled;
87 	int     checks_enabled;
88 	int     flap_detection_enabled;
89 	int     is_flapping;
90 	double  percent_state_change;
91 	double  latency;
92 	double  execution_time;
93 	int     scheduled_downtime_depth;
94 	int     failure_prediction_enabled;
95 	int     process_performance_data;
96 	int     obsess_over_host;
97 	struct  hoststatus_struct *next;
98 	struct  hoststatus_struct *nexthash;
99 	} hoststatus;
100 
101 
102 /* SERVICE STATUS structure */
103 typedef struct servicestatus_struct {
104 	char    *host_name;
105 	char    *description;
106 	char    *plugin_output;
107 	char    *long_plugin_output;
108 	char    *perf_data;
109 	int     max_attempts;
110 	int     current_attempt;
111 	int     status;
112 	time_t  last_update;
113 	int     has_been_checked;
114 	int     should_be_scheduled;
115 	time_t  last_check;
116 	time_t  next_check;
117 	int     check_options;
118 	int     check_type;
119 	int	checks_enabled;
120 	time_t	last_state_change;
121 	time_t	last_hard_state_change;
122 	int	last_hard_state;
123 	time_t  last_time_ok;
124 	time_t  last_time_warning;
125 	time_t  last_time_unknown;
126 	time_t  last_time_critical;
127 	int     state_type;
128 	time_t  last_notification;
129 	time_t  next_notification;
130 	int     no_more_notifications;
131 	int     notifications_enabled;
132 	int     problem_has_been_acknowledged;
133 	int     acknowledgement_type;
134 	int     current_notification_number;
135 	int     accept_passive_service_checks;
136 	int     event_handler_enabled;
137 	int     flap_detection_enabled;
138 	int     is_flapping;
139 	double  percent_state_change;
140 	double  latency;
141 	double  execution_time;
142 	int     scheduled_downtime_depth;
143 	int     failure_prediction_enabled;
144 	int     process_performance_data;
145 	int     obsess_over_service;
146 	struct  servicestatus_struct *next;
147 	struct  servicestatus_struct *nexthash;
148 	} servicestatus;
149 
150 
151 /*************************** SERVICE STATES ***************************/
152 
153 #define SERVICE_PENDING			1
154 #define SERVICE_OK			2
155 #define SERVICE_WARNING			4
156 #define SERVICE_UNKNOWN			8
157 #define SERVICE_CRITICAL		16
158 
159 
160 
161 /**************************** HOST STATES ****************************/
162 
163 #define HOST_PENDING			1
164 #define HOST_UP				2
165 #define HOST_DOWN			4
166 #define HOST_UNREACHABLE		8
167 
168 /* Convert the (historically ordered) host states into a notion of "urgency".
169 	  This is defined as, in ascending order:
170 		HOST_UP			(business as usual)
171 		HOST_PENDING		(waiting for - supposedly first - check result)
172 		HOST_UNREACHABLE	(a problem, but likely not its cause)
173 		HOST_DOWN		(look here!!)
174 	  The exact values are irrelevant, so I try to make the conversion as
175 	  CPU-efficient as possible: */
176 #define HOST_URGENCY(hs)		((hs)|(((hs)&0x5)<<1))
177 
178 
179 
180 /**************************** FUNCTIONS ******************************/
181 
182 int read_status_data(char *, int);                      /* reads all status data */
183 int add_host_status(hoststatus *);                      /* adds a host status entry to the list in memory */
184 int add_service_status(servicestatus *);                /* adds a service status entry to the list in memory */
185 
186 int add_hoststatus_to_hashlist(hoststatus *);
187 int add_servicestatus_to_hashlist(servicestatus *);
188 
189 servicestatus *find_servicestatus(char *, char *);      /* finds status information for a specific service */
190 hoststatus *find_hoststatus(char *);                    /* finds status information for a specific host */
191 int get_servicestatus_count(char *, int);		/* gets total number of services of a certain type for a specific host */
192 
193 void free_status_data(void);                            /* free all memory allocated to status data */
194 #endif
195 
196 #ifdef NSCORE
197 int initialize_status_data(char *);                     /* initializes status data at program start */
198 int update_all_status_data(void);                       /* updates all status data */
199 int cleanup_status_data(char *, int);                   /* cleans up status data at program termination */
200 int update_program_status(int);                         /* updates program status data */
201 int update_host_status(host *, int);                    /* updates host status data */
202 int update_service_status(service *, int);              /* updates service status data */
203 int update_contact_status(contact *, int);              /* updates contact status data */
204 #endif
205 
206 NAGIOS_END_DECL
207 #endif
208