1 /**************************************************************************
2 *
3 * EXTINFO.C - Nagios Extended Information CGI
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 #include "../include/config.h"
23 #include "../include/common.h"
24 #include "../include/objects.h"
25 #include "../include/macros.h"
26 #include "../include/comments.h"
27 #include "../include/downtime.h"
28 #include "../include/statusdata.h"
29
30 #include "../include/cgiutils.h"
31 #include "../include/getcgi.h"
32 #include "../include/cgiauth.h"
33
34 static nagios_macros *mac;
35
36 extern char nagios_process_info[MAX_INPUT_BUFFER];
37 extern int nagios_process_state;
38 extern int refresh_rate;
39 extern int enable_page_tour;
40
41 extern int buffer_stats[1][3];
42 extern int program_stats[MAX_CHECK_STATS_TYPES][3];
43
44 extern char main_config_file[MAX_FILENAME_LENGTH];
45 extern char url_html_path[MAX_FILENAME_LENGTH];
46 extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
47 extern char url_docs_path[MAX_FILENAME_LENGTH];
48 extern char url_images_path[MAX_FILENAME_LENGTH];
49 extern char url_logo_images_path[MAX_FILENAME_LENGTH];
50 extern char url_js_path[MAX_FILENAME_LENGTH];
51
52 extern int enable_splunk_integration;
53
54 extern char *notes_url_target;
55 extern char *action_url_target;
56
57 extern hoststatus *hoststatus_list;
58 extern servicestatus *servicestatus_list;
59
60
61 #define MAX_MESSAGE_BUFFER 4096
62
63 #define HEALTH_WARNING_PERCENTAGE 85
64 #define HEALTH_CRITICAL_PERCENTAGE 75
65
66 /* SORTDATA structure */
67 typedef struct sortdata_struct {
68 int is_service;
69 servicestatus *svcstatus;
70 hoststatus *hststatus;
71 struct sortdata_struct *next;
72 } sortdata;
73
74 void document_header(int);
75 void document_footer(void);
76 int process_cgivars(void);
77
78 void show_process_info(void);
79 void show_host_info(void);
80 void show_service_info(void);
81 void show_all_comments(void);
82 void show_performance_data(void);
83 void show_hostgroup_info(void);
84 void show_servicegroup_info(void);
85 void show_all_downtime(void);
86 void show_scheduling_queue(void);
87 void display_comments(int);
88
89 int sort_data(int, int);
90 int compare_sortdata_entries(int, int, sortdata *, sortdata *);
91 void free_sortdata_list(void);
92
93 authdata current_authdata;
94
95 sortdata *sortdata_list = NULL;
96
97 char *host_name = "";
98 char *hostgroup_name = "";
99 char *servicegroup_name = "";
100 char *service_desc = "";
101
102 int display_type = DISPLAY_PROCESS_INFO;
103
104 int sort_type = SORT_ASCENDING;
105 int sort_option = SORT_NEXTCHECKTIME;
106
107 int embedded = FALSE;
108 int display_header = TRUE;
109
110
111
main(void)112 int main(void) {
113 int found = FALSE;
114 char temp_buffer[MAX_INPUT_BUFFER] = "";
115 char *processed_string = NULL;
116 host *temp_host = NULL;
117 hostsmember *temp_parenthost = NULL;
118 hostgroup *temp_hostgroup = NULL;
119 service *temp_service = NULL;
120 servicegroup *temp_servicegroup = NULL;
121
122 mac = get_global_macros();
123
124 /* get the arguments passed in the URL */
125 process_cgivars();
126
127 /* reset internal variables */
128 reset_cgi_vars();
129
130 cgi_init(document_header, document_footer, READ_ALL_OBJECT_DATA, READ_ALL_STATUS_DATA);
131
132 /* initialize macros */
133 init_macros();
134
135 /* get authentication information */
136 get_authentication_information(¤t_authdata);
137
138 document_header(TRUE);
139
140
141 if(display_header == TRUE) {
142
143 /* begin top table */
144 printf("<table border=0 width=100%%>\n");
145 printf("<tr>\n");
146
147 /* left column of the first row */
148 printf("<td align=left valign=top width=33%%>\n");
149
150 if(display_type == DISPLAY_HOST_INFO)
151 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Host Information");
152 else if(display_type == DISPLAY_SERVICE_INFO)
153 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Service Information");
154 else if(display_type == DISPLAY_COMMENTS)
155 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "All Host and Service Comments");
156 else if(display_type == DISPLAY_PERFORMANCE)
157 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Performance Information");
158 else if(display_type == DISPLAY_HOSTGROUP_INFO)
159 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Hostgroup Information");
160 else if(display_type == DISPLAY_SERVICEGROUP_INFO)
161 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Servicegroup Information");
162 else if(display_type == DISPLAY_DOWNTIME)
163 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "All Host and Service Scheduled Downtime");
164 else if(display_type == DISPLAY_SCHEDULING_QUEUE)
165 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Check Scheduling Queue");
166 else
167 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Nagios Process Information");
168 temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
169 display_info_table(temp_buffer, TRUE, ¤t_authdata);
170
171 /* find the host */
172 if(display_type == DISPLAY_HOST_INFO || display_type == DISPLAY_SERVICE_INFO) {
173
174 temp_host = find_host(host_name);
175 grab_host_macros_r(mac, temp_host);
176
177 if(display_type == DISPLAY_SERVICE_INFO) {
178 temp_service = find_service(host_name, service_desc);
179 grab_service_macros_r(mac, temp_service);
180 }
181
182 /* write some Javascript helper functions */
183 if(temp_host != NULL) {
184 printf("<SCRIPT LANGUAGE=\"JavaScript\">\n<!--\n");
185 printf("function nagios_get_host_name()\n{\n");
186 printf("return \"%s\";\n", temp_host->name);
187 printf("}\n");
188 printf("function nagios_get_host_address()\n{\n");
189 printf("return \"%s\";\n", temp_host->address);
190 printf("}\n");
191 if(temp_service != NULL) {
192 printf("function nagios_get_service_description()\n{\n");
193 printf("return \"%s\";\n", temp_service->description);
194 printf("}\n");
195 }
196 printf("//-->\n</SCRIPT>\n");
197 }
198 }
199
200 /* find the hostgroup */
201 else if(display_type == DISPLAY_HOSTGROUP_INFO) {
202 temp_hostgroup = find_hostgroup(hostgroup_name);
203 grab_hostgroup_macros_r(mac, temp_hostgroup);
204 }
205
206 /* find the servicegroup */
207 else if(display_type == DISPLAY_SERVICEGROUP_INFO) {
208 temp_servicegroup = find_servicegroup(servicegroup_name);
209 grab_servicegroup_macros_r(mac, temp_servicegroup);
210 }
211
212 if((display_type == DISPLAY_HOST_INFO && temp_host != NULL) || (display_type == DISPLAY_SERVICE_INFO && temp_host != NULL && temp_service != NULL) || (display_type == DISPLAY_HOSTGROUP_INFO && temp_hostgroup != NULL) || (display_type == DISPLAY_SERVICEGROUP_INFO && temp_servicegroup != NULL)) {
213 printf("<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 CLASS='linkBox'>\n");
214 printf("<TR><TD CLASS='linkBox'>\n");
215 if(display_type == DISPLAY_SERVICE_INFO)
216 printf("<A HREF='%s?type=%d&host=%s'>View Information For This Host</A><br>\n", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(host_name));
217 if(display_type == DISPLAY_SERVICE_INFO || display_type == DISPLAY_HOST_INFO)
218 printf("<A HREF='%s?host=%s'>View Status Detail For This Host</A><BR>\n", STATUS_CGI, url_encode(host_name));
219 if(display_type == DISPLAY_HOST_INFO) {
220 printf("<A HREF='%s?host=%s'>View Alert History For This Host</A><BR>\n", HISTORY_CGI, url_encode(host_name));
221 #ifdef USE_TRENDS
222 printf("<A HREF='%s?host=%s'>View Trends For This Host</A><BR>\n", TRENDS_CGI, url_encode(host_name));
223 #endif
224 #ifdef USE_HISTOGRAM
225 printf("<A HREF='%s?host=%s'>View Alert Histogram For This Host</A><BR>\n", HISTOGRAM_CGI, url_encode(host_name));
226 #endif
227 printf("<A HREF='%s?host=%s&show_log_entries'>View Availability Report For This Host</A><BR>\n", AVAIL_CGI, url_encode(host_name));
228 printf("<A HREF='%s?host=%s'>View Notifications For This Host</A>\n", NOTIFICATIONS_CGI, url_encode(host_name));
229 }
230 else if(display_type == DISPLAY_SERVICE_INFO) {
231 printf("<A HREF='%s?host=%s&", HISTORY_CGI, url_encode(host_name));
232 printf("service=%s'>View Alert History For This Service</A><BR>\n", url_encode(service_desc));
233 #ifdef USE_TRENDS
234 printf("<A HREF='%s?host=%s&", TRENDS_CGI, url_encode(host_name));
235 printf("service=%s'>View Trends For This Service</A><BR>\n", url_encode(service_desc));
236 #endif
237 #ifdef USE_HISTOGRAM
238 printf("<A HREF='%s?host=%s&", HISTOGRAM_CGI, url_encode(host_name));
239 printf("service=%s'>View Alert Histogram For This Service</A><BR>\n", url_encode(service_desc));
240 #endif
241 printf("<A HREF='%s?host=%s&", AVAIL_CGI, url_encode(host_name));
242 printf("service=%s&show_log_entries'>View Availability Report For This Service</A><BR>\n", url_encode(service_desc));
243 printf("<A HREF='%s?host=%s&", NOTIFICATIONS_CGI, url_encode(host_name));
244 printf("service=%s'>View Notifications For This Service</A>\n", url_encode(service_desc));
245 }
246 else if(display_type == DISPLAY_HOSTGROUP_INFO) {
247 printf("<A HREF='%s?hostgroup=%s&style=detail'>View Status Detail For This Hostgroup</A><BR>\n", STATUS_CGI, url_encode(hostgroup_name));
248 printf("<A HREF='%s?hostgroup=%s&style=overview'>View Status Overview For This Hostgroup</A><BR>\n", STATUS_CGI, url_encode(hostgroup_name));
249 printf("<A HREF='%s?hostgroup=%s&style=grid'>View Status Grid For This Hostgroup</A><BR>\n", STATUS_CGI, url_encode(hostgroup_name));
250 printf("<A HREF='%s?hostgroup=%s'>View Availability For This Hostgroup</A><BR>\n", AVAIL_CGI, url_encode(hostgroup_name));
251 }
252 else if(display_type == DISPLAY_SERVICEGROUP_INFO) {
253 printf("<A HREF='%s?servicegroup=%s&style=detail'>View Status Detail For This Servicegroup</A><BR>\n", STATUS_CGI, url_encode(servicegroup_name));
254 printf("<A HREF='%s?servicegroup=%s&style=overview'>View Status Overview For This Servicegroup</A><BR>\n", STATUS_CGI, url_encode(servicegroup_name));
255 printf("<A HREF='%s?servicegroup=%s&style=grid'>View Status Grid For This Servicegroup</A><BR>\n", STATUS_CGI, url_encode(servicegroup_name));
256 printf("<A HREF='%s?servicegroup=%s'>View Availability For This Servicegroup</A><BR>\n", AVAIL_CGI, url_encode(servicegroup_name));
257 }
258 printf("</TD></TR>\n");
259 printf("</TABLE>\n");
260 }
261
262 printf("</td>\n");
263
264 /* middle column of top row */
265 printf("<td align=center valign=middle width=33%%>\n");
266
267 if((display_type == DISPLAY_HOST_INFO && temp_host != NULL) || (display_type == DISPLAY_SERVICE_INFO && temp_host != NULL && temp_service != NULL) || (display_type == DISPLAY_HOSTGROUP_INFO && temp_hostgroup != NULL) || (display_type == DISPLAY_SERVICEGROUP_INFO && temp_servicegroup != NULL)) {
268
269 if(display_type == DISPLAY_HOST_INFO) {
270 printf("<DIV CLASS='data'>Host</DIV>\n");
271 printf("<DIV CLASS='dataTitle'>%s</DIV>\n", temp_host->alias);
272 printf("<DIV CLASS='dataTitle'>(%s)</DIV><BR>\n", temp_host->name);
273
274 if(temp_host->parent_hosts != NULL) {
275 /* print all parent hosts */
276 printf("<DIV CLASS='data'>Parents:</DIV>\n");
277 for(temp_parenthost = temp_host->parent_hosts; temp_parenthost != NULL; temp_parenthost = temp_parenthost->next)
278 printf("<DIV CLASS='dataTitle'><A HREF='%s?host=%s'>%s</A></DIV>\n", STATUS_CGI, url_encode(temp_parenthost->host_name), temp_parenthost->host_name);
279 printf("<BR>");
280 }
281
282 printf("<DIV CLASS='data'>Member of</DIV><DIV CLASS='dataTitle'>");
283 for(temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {
284 if(is_host_member_of_hostgroup(temp_hostgroup, temp_host) == TRUE) {
285 if(found == TRUE)
286 printf(", ");
287 printf("<A HREF='%s?hostgroup=%s&style=overview'>%s</A>", STATUS_CGI, url_encode(temp_hostgroup->group_name), temp_hostgroup->group_name);
288 found = TRUE;
289 }
290 }
291
292 if(found == FALSE)
293 printf("No hostgroups");
294 printf("</DIV><BR>\n");
295 printf("<DIV CLASS='data'>%s</DIV>\n", temp_host->address);
296 }
297 if(display_type == DISPLAY_SERVICE_INFO) {
298 printf("<DIV CLASS='data'>Service</DIV><DIV CLASS='dataTitle'>%s</DIV><DIV CLASS='data'>On Host</DIV>\n", service_desc);
299 printf("<DIV CLASS='dataTitle'>%s</DIV>\n", temp_host->alias);
300 printf("<DIV CLASS='dataTitle'>(<A HREF='%s?type=%d&host=%s'>%s</a>)</DIV><BR>\n", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_host->name), temp_host->name);
301 printf("<DIV CLASS='data'>Member of</DIV><DIV CLASS='dataTitle'>");
302 for(temp_servicegroup = servicegroup_list; temp_servicegroup != NULL; temp_servicegroup = temp_servicegroup->next) {
303 if(is_service_member_of_servicegroup(temp_servicegroup, temp_service) == TRUE) {
304 if(found == TRUE)
305 printf(", ");
306 printf("<A HREF='%s?servicegroup=%s&style=overview'>%s</A>", STATUS_CGI, url_encode(temp_servicegroup->group_name), temp_servicegroup->group_name);
307 found = TRUE;
308 }
309 }
310
311 if(found == FALSE)
312 printf("No servicegroups.");
313 printf("</DIV><BR>\n");
314
315 printf("<DIV CLASS='data'>%s</DIV>\n", temp_host->address);
316 }
317 if(display_type == DISPLAY_HOSTGROUP_INFO) {
318 printf("<DIV CLASS='data'>Hostgroup</DIV>\n");
319 printf("<DIV CLASS='dataTitle'>%s</DIV>\n", temp_hostgroup->alias);
320 printf("<DIV CLASS='dataTitle'>(%s)</DIV>\n", temp_hostgroup->group_name);
321 if(temp_hostgroup->notes != NULL) {
322 process_macros_r(mac, temp_hostgroup->notes, &processed_string, 0);
323 printf("<p>%s</p>", processed_string);
324 free(processed_string);
325 }
326 }
327 if(display_type == DISPLAY_SERVICEGROUP_INFO) {
328 printf("<DIV CLASS='data'>Servicegroup</DIV>\n");
329 printf("<DIV CLASS='dataTitle'>%s</DIV>\n", temp_servicegroup->alias);
330 printf("<DIV CLASS='dataTitle'>(%s)</DIV>\n", temp_servicegroup->group_name);
331 if(temp_servicegroup->notes != NULL) {
332 process_macros_r(mac, temp_servicegroup->notes, &processed_string, 0);
333 printf("<p>%s</p>", processed_string);
334 free(processed_string);
335 }
336 }
337
338 if(display_type == DISPLAY_SERVICE_INFO) {
339 if(temp_service->icon_image != NULL) {
340 printf("<img src='%s", url_logo_images_path);
341 process_macros_r(mac, temp_service->icon_image, &processed_string, 0);
342 printf("%s", processed_string);
343 free(processed_string);
344 printf("' border=0 alt='%s' title='%s'><BR CLEAR=ALL>", (temp_service->icon_image_alt == NULL) ? "" : temp_service->icon_image_alt, (temp_service->icon_image_alt == NULL) ? "" : temp_service->icon_image_alt);
345 }
346 if(temp_service->icon_image_alt != NULL)
347 printf("<font size=-1><i>( %s )</i></font>\n", temp_service->icon_image_alt);
348 if(temp_service->notes != NULL) {
349 process_macros_r(mac, temp_service->notes, &processed_string, 0);
350 printf("<p>%s</p>\n", processed_string);
351 free(processed_string);
352 }
353 }
354
355 if(display_type == DISPLAY_HOST_INFO) {
356 if(temp_host->icon_image != NULL) {
357 printf("<img src='%s", url_logo_images_path);
358 process_macros_r(mac, temp_host->icon_image, &processed_string, 0);
359 printf("%s", processed_string);
360 free(processed_string);
361 printf("' border=0 alt='%s' title='%s'><BR CLEAR=ALL>", (temp_host->icon_image_alt == NULL) ? "" : temp_host->icon_image_alt, (temp_host->icon_image_alt == NULL) ? "" : temp_host->icon_image_alt);
362 }
363 if(temp_host->icon_image_alt != NULL)
364 printf("<font size=-1><i>( %s )</i><font>\n", temp_host->icon_image_alt);
365 if(temp_host->notes != NULL) {
366 process_macros_r(mac, temp_host->notes, &processed_string, 0);
367 printf("<p>%s</p>\n", processed_string);
368 free(processed_string);
369 }
370 }
371 }
372
373 printf("</td>\n");
374
375 /* right column of top row */
376 printf("<td align=right valign=bottom width=33%%>\n");
377
378 if(display_type == DISPLAY_HOST_INFO && temp_host != NULL) {
379 printf("<TABLE BORDER='0'>\n");
380 if(temp_host->action_url != NULL && strcmp(temp_host->action_url, "")) {
381 printf("<TR><TD ALIGN='right'>\n");
382 printf("<A HREF='");
383 process_macros_r(mac, temp_host->action_url, &processed_string, 0);
384 printf("%s", processed_string);
385 free(processed_string);
386 printf("' TARGET='%s'><img src='%s%s' border=0 alt='Perform Additional Actions On This Host' title='Perform Additional Actions On This Host'></A>\n", (action_url_target == NULL) ? "_blank" : action_url_target, url_images_path, ACTION_ICON);
387 printf("<BR CLEAR=ALL><FONT SIZE=-1><I>Extra Actions</I></FONT><BR CLEAR=ALL><BR CLEAR=ALL>\n");
388 printf("</TD></TR>\n");
389 }
390 if(temp_host->notes_url != NULL && strcmp(temp_host->notes_url, "")) {
391 printf("<TR><TD ALIGN='right'>\n");
392 printf("<A HREF='");
393 process_macros_r(mac, temp_host->notes_url, &processed_string, 0);
394 printf("%s", processed_string);
395 free(processed_string);
396 /*print_extra_host_url(temp_host->name,temp_host->notes_url);*/
397 printf("' TARGET='%s'><img src='%s%s' border=0 alt='View Additional Notes For This Host' title='View Additional Notes For This Host'></A>\n", (notes_url_target == NULL) ? "_blank" : notes_url_target, url_images_path, NOTES_ICON);
398 printf("<BR CLEAR=ALL><FONT SIZE=-1><I>Extra Notes</I></FONT><BR CLEAR=ALL><BR CLEAR=ALL>\n");
399 printf("</TD></TR>\n");
400 }
401 printf("</TABLE>\n");
402 }
403
404 else if(display_type == DISPLAY_SERVICE_INFO && temp_service != NULL) {
405 printf("<TABLE BORDER='0'><TR><TD ALIGN='right'>\n");
406 if(temp_service->action_url != NULL && strcmp(temp_service->action_url, "")) {
407 printf("<A HREF='");
408 process_macros_r(mac, temp_service->action_url, &processed_string, 0);
409 printf("%s", processed_string);
410 free(processed_string);
411 printf("' TARGET='%s'><img src='%s%s' border=0 alt='Perform Additional Actions On This Service' title='Perform Additional Actions On This Service'></A>\n", (action_url_target == NULL) ? "_blank" : action_url_target, url_images_path, ACTION_ICON);
412 printf("<BR CLEAR=ALL><FONT SIZE=-1><I>Extra Actions</I></FONT><BR CLEAR=ALL><BR CLEAR=ALL>\n");
413 }
414 if(temp_service->notes_url != NULL && strcmp(temp_service->notes_url, "")) {
415 printf("<A HREF='");
416 process_macros_r(mac, temp_service->notes_url, &processed_string, 0);
417 printf("%s", processed_string);
418 free(processed_string);
419 printf("' TARGET='%s'><img src='%s%s' border=0 alt='View Additional Notes For This Service' title='View Additional Notes For This Service'></A>\n", (notes_url_target == NULL) ? "_blank" : notes_url_target, url_images_path, NOTES_ICON);
420 printf("<BR CLEAR=ALL><FONT SIZE=-1><I>Extra Notes</I></FONT><BR CLEAR=ALL><BR CLEAR=ALL>\n");
421 }
422 printf("</TD></TR></TABLE>\n");
423 }
424
425 if(display_type == DISPLAY_HOSTGROUP_INFO && temp_hostgroup != NULL) {
426 printf("<TABLE BORDER='0'>\n");
427 if(temp_hostgroup->action_url != NULL && strcmp(temp_hostgroup->action_url, "")) {
428 printf("<TR><TD ALIGN='right'>\n");
429 printf("<A HREF='");
430 print_extra_hostgroup_url(temp_hostgroup->group_name, temp_hostgroup->action_url);
431 printf("' TARGET='%s'><img src='%s%s' border=0 alt='Perform Additional Actions On This Hostgroup' title='Perform Additional Actions On This Hostgroup'></A>\n", (action_url_target == NULL) ? "_blank" : action_url_target, url_images_path, ACTION_ICON);
432 printf("<BR CLEAR=ALL><FONT SIZE=-1><I>Extra Actions</I></FONT><BR CLEAR=ALL><BR CLEAR=ALL>\n");
433 printf("</TD></TR>\n");
434 }
435 if(temp_hostgroup->notes_url != NULL && strcmp(temp_hostgroup->notes_url, "")) {
436 printf("<TR><TD ALIGN='right'>\n");
437 printf("<A HREF='");
438 print_extra_hostgroup_url(temp_hostgroup->group_name, temp_hostgroup->notes_url);
439 printf("' TARGET='%s'><img src='%s%s' border=0 alt='View Additional Notes For This Hostgroup' title='View Additional Notes For This Hostgroup'></A>\n", (notes_url_target == NULL) ? "_blank" : notes_url_target, url_images_path, NOTES_ICON);
440 printf("<BR CLEAR=ALL><FONT SIZE=-1><I>Extra Notes</I></FONT><BR CLEAR=ALL><BR CLEAR=ALL>\n");
441 printf("</TD></TR>\n");
442 }
443 printf("</TABLE>\n");
444 }
445
446 else if(display_type == DISPLAY_SERVICEGROUP_INFO && temp_servicegroup != NULL) {
447 printf("<TABLE BORDER='0'>\n");
448 if(temp_servicegroup->action_url != NULL && strcmp(temp_servicegroup->action_url, "")) {
449 printf("<A HREF='");
450 print_extra_servicegroup_url(temp_servicegroup->group_name, temp_servicegroup->action_url);
451 printf("' TARGET='%s'><img src='%s%s' border=0 alt='Perform Additional Actions On This Servicegroup' title='Perform Additional Actions On This Servicegroup'></A>\n", (action_url_target == NULL) ? "_blank" : action_url_target, url_images_path, ACTION_ICON);
452 printf("<BR CLEAR=ALL><FONT SIZE=-1><I>Extra Actions</I></FONT><BR CLEAR=ALL><BR CLEAR=ALL>\n");
453 }
454 if(temp_servicegroup->notes_url != NULL && strcmp(temp_servicegroup->notes_url, "")) {
455 printf("<A HREF='");
456 print_extra_servicegroup_url(temp_servicegroup->group_name, temp_servicegroup->notes_url);
457 printf("' TARGET='%s'><img src='%s%s' border=0 alt='View Additional Notes For This Servicegroup' title='View Additional Notes For This Servicegroup'></A>\n", (notes_url_target == NULL) ? "_blank" : notes_url_target, url_images_path, NOTES_ICON);
458 printf("<BR CLEAR=ALL><FONT SIZE=-1><I>Extra Notes</I></FONT><BR CLEAR=ALL><BR CLEAR=ALL>\n");
459 }
460 printf("</TABLE>\n");
461 }
462
463 /* display context-sensitive help */
464 if(display_type == DISPLAY_HOST_INFO)
465 display_context_help(CONTEXTHELP_EXT_HOST);
466 else if(display_type == DISPLAY_SERVICE_INFO)
467 display_context_help(CONTEXTHELP_EXT_SERVICE);
468 else if(display_type == DISPLAY_HOSTGROUP_INFO)
469 display_context_help(CONTEXTHELP_EXT_HOSTGROUP);
470 else if(display_type == DISPLAY_SERVICEGROUP_INFO)
471 display_context_help(CONTEXTHELP_EXT_SERVICEGROUP);
472 else if(display_type == DISPLAY_PROCESS_INFO)
473 display_context_help(CONTEXTHELP_EXT_PROCESS);
474 else if(display_type == DISPLAY_PERFORMANCE)
475 display_context_help(CONTEXTHELP_EXT_PERFORMANCE);
476 else if(display_type == DISPLAY_COMMENTS)
477 display_context_help(CONTEXTHELP_EXT_COMMENTS);
478 else if(display_type == DISPLAY_DOWNTIME)
479 display_context_help(CONTEXTHELP_EXT_DOWNTIME);
480 else if(display_type == DISPLAY_SCHEDULING_QUEUE)
481 display_context_help(CONTEXTHELP_EXT_QUEUE);
482
483 printf("</td>\n");
484
485 /* end of top table */
486 printf("</tr>\n");
487 printf("</table>\n");
488
489 }
490
491 printf("<BR>\n");
492
493 if(display_type == DISPLAY_HOST_INFO)
494 show_host_info();
495 else if(display_type == DISPLAY_SERVICE_INFO)
496 show_service_info();
497 else if(display_type == DISPLAY_COMMENTS)
498 show_all_comments();
499 else if(display_type == DISPLAY_PERFORMANCE)
500 show_performance_data();
501 else if(display_type == DISPLAY_HOSTGROUP_INFO)
502 show_hostgroup_info();
503 else if(display_type == DISPLAY_SERVICEGROUP_INFO)
504 show_servicegroup_info();
505 else if(display_type == DISPLAY_DOWNTIME)
506 show_all_downtime();
507 else if(display_type == DISPLAY_SCHEDULING_QUEUE)
508 show_scheduling_queue();
509 else
510 show_process_info();
511
512 document_footer();
513
514 /* free all allocated memory */
515 free_memory();
516 free_comment_data();
517 free_downtime_data();
518
519 return OK;
520 }
521
522
523
document_header(int use_stylesheet)524 void document_header(int use_stylesheet) {
525 char date_time[MAX_DATETIME_LENGTH];
526 char *vidurl = NULL;
527 time_t current_time;
528 time_t expire_time;
529
530 printf("Cache-Control: no-store\r\n");
531 printf("Pragma: no-cache\r\n");
532 printf("Refresh: %d\r\n", refresh_rate);
533
534 time(¤t_time);
535 get_time_string(¤t_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME);
536 printf("Last-Modified: %s\r\n", date_time);
537
538 expire_time = (time_t)0L;
539 get_time_string(&expire_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME);
540 printf("Expires: %s\r\n", date_time);
541
542 printf("Content-type: text/html; charset=utf-8\r\n\r\n");
543
544 if(embedded == TRUE)
545 return;
546
547 printf("<html>\n");
548 printf("<head>\n");
549 printf("<link rel=\"shortcut icon\" href=\"%sfavicon.ico\" type=\"image/ico\">\n", url_images_path);
550 printf("<title>\n");
551 printf("Extended Information\n");
552 printf("</title>\n");
553
554 if(use_stylesheet == TRUE) {
555 printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>", url_stylesheets_path, COMMON_CSS);
556 printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>", url_stylesheets_path, EXTINFO_CSS);
557 printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>\n", url_stylesheets_path, NAGFUNCS_CSS);
558 }
559
560 if (display_type == DISPLAY_HOST_INFO)
561 vidurl = "https://www.youtube.com/embed/n3QEAf-MxY4";
562 else if(display_type == DISPLAY_SERVICE_INFO)
563 vidurl = "https://www.youtube.com/embed/f_knwQOS6FI";
564
565 if (enable_page_tour == TRUE && vidurl) {
566 printf("<script type='text/javascript' src='%s%s'></script>\n", url_js_path, JQUERY_JS);
567 printf("<script type='text/javascript' src='%s%s'></script>\n", url_js_path, NAGFUNCS_JS);
568 printf("<script type='text/javascript'>\n");
569 printf("var vbox, vBoxId='extinfo%d', vboxText = "
570 "'<a href=https://www.nagios.com/tours target=_blank>"
571 "Click here to watch the entire Nagios Core 4 Tour!</a>';\n",
572 display_type);
573 printf("$(document).ready(function() {\n"
574 "var user = '%s';\nvBoxId += ';' + user;\n",
575 current_authdata.username);
576 printf("vbox = new vidbox({pos:'lr',vidurl:'%s',text:vboxText,"
577 "vidid:vBoxId});\n", vidurl);
578 printf("});\n</script>\n");
579 }
580
581 printf("</head>\n");
582
583 printf("<body CLASS='extinfo'>\n");
584
585 /* include user SSI header */
586 include_ssi_files(EXTINFO_CGI, SSI_HEADER);
587
588 return;
589 }
590
591
document_footer(void)592 void document_footer(void) {
593
594 if(embedded == TRUE)
595 return;
596
597 /* include user SSI footer */
598 include_ssi_files(EXTINFO_CGI, SSI_FOOTER);
599
600 printf("</body>\n");
601 printf("</html>\n");
602
603 return;
604 }
605
606
process_cgivars(void)607 int process_cgivars(void) {
608 char **variables;
609 int error = FALSE;
610 int temp_type;
611 int x;
612
613 variables = getcgivars();
614
615 for(x = 0; variables[x]; x++) {
616
617 /* do some basic length checking on the variable identifier to prevent buffer overflows */
618 if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
619 continue;
620 }
621
622 /* we found the display type */
623 else if(!strcmp(variables[x], "type")) {
624 x++;
625 if(variables[x] == NULL) {
626 error = TRUE;
627 break;
628 }
629 temp_type = atoi(variables[x]);
630 if(temp_type == DISPLAY_HOST_INFO)
631 display_type = DISPLAY_HOST_INFO;
632 else if(temp_type == DISPLAY_SERVICE_INFO)
633 display_type = DISPLAY_SERVICE_INFO;
634 else if(temp_type == DISPLAY_COMMENTS)
635 display_type = DISPLAY_COMMENTS;
636 else if(temp_type == DISPLAY_PERFORMANCE)
637 display_type = DISPLAY_PERFORMANCE;
638 else if(temp_type == DISPLAY_HOSTGROUP_INFO)
639 display_type = DISPLAY_HOSTGROUP_INFO;
640 else if(temp_type == DISPLAY_SERVICEGROUP_INFO)
641 display_type = DISPLAY_SERVICEGROUP_INFO;
642 else if(temp_type == DISPLAY_DOWNTIME)
643 display_type = DISPLAY_DOWNTIME;
644 else if(temp_type == DISPLAY_SCHEDULING_QUEUE)
645 display_type = DISPLAY_SCHEDULING_QUEUE;
646 else
647 display_type = DISPLAY_PROCESS_INFO;
648 }
649
650 /* we found the host name */
651 else if(!strcmp(variables[x], "host")) {
652 x++;
653 if(variables[x] == NULL) {
654 error = TRUE;
655 break;
656 }
657
658 host_name = strdup(variables[x]);
659 if(host_name == NULL)
660 host_name = "";
661 strip_html_brackets(host_name);
662 }
663
664 /* we found the hostgroup name */
665 else if(!strcmp(variables[x], "hostgroup")) {
666 x++;
667 if(variables[x] == NULL) {
668 error = TRUE;
669 break;
670 }
671
672 hostgroup_name = strdup(variables[x]);
673 if(hostgroup_name == NULL)
674 hostgroup_name = "";
675 strip_html_brackets(hostgroup_name);
676 }
677
678 /* we found the service name */
679 else if(!strcmp(variables[x], "service")) {
680 x++;
681 if(variables[x] == NULL) {
682 error = TRUE;
683 break;
684 }
685
686 service_desc = strdup(variables[x]);
687 if(service_desc == NULL)
688 service_desc = "";
689 strip_html_brackets(service_desc);
690 }
691
692 /* we found the servicegroup name */
693 else if(!strcmp(variables[x], "servicegroup")) {
694 x++;
695 if(variables[x] == NULL) {
696 error = TRUE;
697 break;
698 }
699
700 servicegroup_name = strdup(variables[x]);
701 if(servicegroup_name == NULL)
702 servicegroup_name = "";
703 strip_html_brackets(servicegroup_name);
704 }
705
706 /* we found the sort type argument */
707 else if(!strcmp(variables[x], "sorttype")) {
708 x++;
709 if(variables[x] == NULL) {
710 error = TRUE;
711 break;
712 }
713
714 sort_type = atoi(variables[x]);
715 }
716
717 /* we found the sort option argument */
718 else if(!strcmp(variables[x], "sortoption")) {
719 x++;
720 if(variables[x] == NULL) {
721 error = TRUE;
722 break;
723 }
724
725 sort_option = atoi(variables[x]);
726 }
727
728 /* we found the embed option */
729 else if(!strcmp(variables[x], "embedded"))
730 embedded = TRUE;
731
732 /* we found the noheader option */
733 else if(!strcmp(variables[x], "noheader"))
734 display_header = FALSE;
735 }
736
737 /* free memory allocated to the CGI variables */
738 free_cgivars(variables);
739
740 return error;
741 }
742
743
744
show_process_info(void)745 void show_process_info(void) {
746 char date_time[MAX_DATETIME_LENGTH];
747 time_t current_time;
748 unsigned long run_time;
749 char run_time_string[24];
750 int days = 0;
751 int hours = 0;
752 int minutes = 0;
753 int seconds = 0;
754
755 /* make sure the user has rights to view system information */
756 if(is_authorized_for_system_information(¤t_authdata) == FALSE) {
757
758 printf("<P><DIV CLASS='errorMessage'>It appears as though you do not have permission to view process information...</DIV></P>\n");
759 printf("<P><DIV CLASS='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
760 printf("and check the authorization options in your CGI configuration file.</DIV></P>\n");
761
762 return;
763 }
764
765 printf("<BR />\n");
766 printf("<DIV ALIGN=CENTER>\n");
767
768 printf("<TABLE BORDER=0 CELLPADDING=20>\n");
769 printf("<TR><TD VALIGN=TOP>\n");
770
771 printf("<DIV CLASS='dataTitle'>Process Information</DIV>\n");
772
773 printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 CLASS='data'>\n");
774 printf("<TR><TD class='stateInfoTable1'>\n");
775 printf("<TABLE BORDER=0>\n");
776
777 /* program version */
778 printf("<TR><TD CLASS='dataVar'>Program Version:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", PROGRAM_VERSION);
779
780 /* program start time */
781 get_time_string(&program_start, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
782 printf("<TR><TD CLASS='dataVar'>Program Start Time:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", date_time);
783
784 /* total running time */
785 time(¤t_time);
786 run_time = (unsigned long)(current_time - program_start);
787 get_time_breakdown(run_time, &days, &hours, &minutes, &seconds);
788 sprintf(run_time_string, "%dd %dh %dm %ds", days, hours, minutes, seconds);
789 printf("<TR><TD CLASS='dataVar'>Total Running Time:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", run_time_string);
790
791 /* last log file rotation */
792 get_time_string(&last_log_rotation, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
793 printf("<TR><TD CLASS='dataVar'>Last Log File Rotation:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (last_log_rotation == (time_t)0) ? "N/A" : date_time);
794
795 /* PID */
796 printf("<TR><TD CLASS='dataVar'>Nagios PID</TD><TD CLASS='dataVal'>%d</TD></TR>\n", nagios_pid);
797
798 /* notifications enabled */
799 printf("<TR><TD CLASS='dataVar'>Notifications Enabled?</TD><TD CLASS='dataVal'><DIV CLASS='notifications%s'> %s </DIV></TD></TR>\n", (enable_notifications == TRUE) ? "ENABLED" : "DISABLED", (enable_notifications == TRUE) ? "YES" : "NO");
800
801 /* service check execution enabled */
802 printf("<TR><TD CLASS='dataVar'>Service Checks Being Executed?</TD><TD CLASS='dataVal'><DIV CLASS='checks%s'> %s </DIV></TD></TR>\n", (execute_service_checks == TRUE) ? "ENABLED" : "DISABLED", (execute_service_checks == TRUE) ? "YES" : "NO");
803
804 /* passive service check acceptance */
805 printf("<TR><TD CLASS='dataVar'>Passive Service Checks Being Accepted?</TD><TD CLASS='dataVal'><DIV CLASS='checks%s'> %s </DIV></TD></TR>\n", (accept_passive_service_checks == TRUE) ? "ENABLED" : "DISABLED", (accept_passive_service_checks == TRUE) ? "YES" : "NO");
806
807 /* host check execution enabled */
808 printf("<TR><TD CLASS='dataVar'>Host Checks Being Executed?</TD><TD CLASS='dataVal'><DIV CLASS='checks%s'> %s </DIV></TD></TR>\n", (execute_host_checks == TRUE) ? "ENABLED" : "DISABLED", (execute_host_checks == TRUE) ? "YES" : "NO");
809
810 /* passive host check acceptance */
811 printf("<TR><TD CLASS='dataVar'>Passive Host Checks Being Accepted?</TD><TD CLASS='dataVal'><DIV CLASS='checks%s'> %s </DIV></TD></TR>\n", (accept_passive_host_checks == TRUE) ? "ENABLED" : "DISABLED", (accept_passive_host_checks == TRUE) ? "YES" : "NO");
812
813 /* event handlers enabled */
814 printf("<TR><TD CLASS='dataVar'>Event Handlers Enabled?</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (enable_event_handlers == TRUE) ? "Yes" : "No");
815
816 /* obsessing over services */
817 printf("<TR><TD CLASS='dataVar'>Obsessing Over Services?</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (obsess_over_services == TRUE) ? "Yes" : "No");
818
819 /* obsessing over hosts */
820 printf("<TR><TD CLASS='dataVar'>Obsessing Over Hosts?</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (obsess_over_hosts == TRUE) ? "Yes" : "No");
821
822 /* flap detection enabled */
823 printf("<TR><TD CLASS='dataVar'>Flap Detection Enabled?</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (enable_flap_detection == TRUE) ? "Yes" : "No");
824
825 /* process performance data */
826 printf("<TR><TD CLASS='dataVar'>Performance Data Being Processed?</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (process_performance_data == TRUE) ? "Yes" : "No");
827
828 printf("</TABLE>\n");
829 printf("</TD></TR>\n");
830 printf("</TABLE>\n");
831
832
833 printf("</TD><TD VALIGN=TOP>\n");
834
835 printf("<DIV CLASS='commandTitle'>Process Commands</DIV>\n");
836
837 printf("<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 CLASS='command'>\n");
838 printf("<TR><TD>\n");
839
840 if(nagios_process_state == STATE_OK) {
841 printf("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 CLASS='command'>\n");
842
843 #ifndef DUMMY_INSTALL
844 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Shutdown the Nagios Process' TITLE='Shutdown the Nagios Process'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Shutdown the Nagios process</a></td></tr>\n", url_images_path, STOP_ICON, COMMAND_CGI, CMD_SHUTDOWN_PROCESS);
845 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Restart the Nagios Process' TITLE='Restart the Nagios Process'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Restart the Nagios process</a></td></tr>\n", url_images_path, RESTART_ICON, COMMAND_CGI, CMD_RESTART_PROCESS);
846 #endif
847
848 if(enable_notifications == TRUE)
849 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Disable Notifications' TITLE='Disable Notifications'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Disable notifications</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_NOTIFICATIONS);
850 else
851 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Enable Notifications' TITLE='Enable Notifications'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Enable notifications</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_NOTIFICATIONS);
852
853 if(execute_service_checks == TRUE)
854 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Stop Executing Service Checks' TITLE='Stop Executing Service Checks'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Stop executing service checks</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_EXECUTING_SVC_CHECKS);
855 else
856 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Start Executing Service Checks' TITLE='Start Executing Service Checks'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Start executing service checks</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_EXECUTING_SVC_CHECKS);
857
858 if(accept_passive_service_checks == TRUE)
859 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Stop Accepting Passive Service Checks' TITLE='Stop Accepting Passive Service Checks'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Stop accepting passive service checks</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS);
860 else
861 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Start Accepting Passive Service Checks' TITLE='Start Accepting Passive Service Checks'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Start accepting passive service checks</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS);
862
863 if(execute_host_checks == TRUE)
864 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Stop Executing Host Checks' TITLE='Stop Executing Host Checks'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Stop executing host checks</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_EXECUTING_HOST_CHECKS);
865 else
866 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Start Executing Host Checks' TITLE='Start Executing Host Checks'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Start executing host checks</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_EXECUTING_HOST_CHECKS);
867
868 if(accept_passive_host_checks == TRUE)
869 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Stop Accepting Passive Host Checks' TITLE='Stop Accepting Passive Host Checks'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Stop accepting passive host checks</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS);
870 else
871 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Start Accepting Passive Host Checks' TITLE='Start Accepting Passive Host Checks'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Start accepting passive host checks</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS);
872
873 if(enable_event_handlers == TRUE)
874 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Disable Event Handlers' TITLE='Disable Event Handlers'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Disable event handlers</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_EVENT_HANDLERS);
875 else
876 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Enable Event Handlers' TITLE='Enable Event Handlers'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Enable event handlers</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_EVENT_HANDLERS);
877
878 if(obsess_over_services == TRUE)
879 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Stop Obsessing Over Services' TITLE='Stop Obsessing Over Services'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Stop obsessing over services</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_OBSESSING_OVER_SVC_CHECKS);
880 else
881 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Start Obsessing Over Services' TITLE='Start Obsessing Over Services'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Start obsessing over services</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_OBSESSING_OVER_SVC_CHECKS);
882
883 if(obsess_over_hosts == TRUE)
884 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Stop Obsessing Over Hosts' TITLE='Stop Obsessing Over Hosts'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Stop obsessing over hosts</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_OBSESSING_OVER_HOST_CHECKS);
885 else
886 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Start Obsessing Over Hosts' TITLE='Start Obsessing Over Hosts'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Start obsessing over hosts</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_OBSESSING_OVER_HOST_CHECKS);
887
888 if(enable_flap_detection == TRUE)
889 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Disable Flap Detection' TITLE='Disable Flap Detection'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Disable flap detection</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_FLAP_DETECTION);
890 else
891 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Enable Flap Detection' TITLE='Enable Flap Detection'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Enable flap detection</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_FLAP_DETECTION);
892
893 if(process_performance_data == TRUE)
894 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Disable Performance Data' TITLE='Disable Performance Data'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Disable performance data</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_PERFORMANCE_DATA);
895 else
896 printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Enable Performance Data' TITLE='Enable Performance Data'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Enable performance data</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_PERFORMANCE_DATA);
897
898 printf("</TABLE>\n");
899 }
900 else {
901 printf("<DIV ALIGN=CENTER CLASS='infoMessage'>It appears as though Nagios is not running, so commands are temporarily unavailable...\n");
902 printf("</DIV>\n");
903 }
904
905 printf("</TD></TR>\n");
906 printf("</TABLE>\n");
907
908 printf("</TD></TR></TABLE>\n");
909 printf("</DIV>\n");
910 }
911
912
show_host_info(void)913 void show_host_info(void) {
914 hoststatus *temp_hoststatus;
915 host *temp_host;
916 char date_time[MAX_DATETIME_LENGTH];
917 char state_duration[48];
918 char status_age[48];
919 char state_string[MAX_INPUT_BUFFER];
920 const char *bg_class = "";
921 char *buf = NULL;
922 int days;
923 int hours;
924 int minutes;
925 int seconds;
926 time_t current_time;
927 time_t t;
928 int duration_error = FALSE;
929
930
931 /* get host info */
932 temp_host = find_host(host_name);
933
934 /* make sure the user has rights to view host information */
935 if(is_authorized_for_host(temp_host, ¤t_authdata) == FALSE) {
936
937 printf("<P><DIV CLASS='errorMessage'>It appears as though you do not have permission to view information for this host...</DIV></P>\n");
938 printf("<P><DIV CLASS='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
939 printf("and check the authorization options in your CGI configuration file.</DIV></P>\n");
940
941 return;
942 }
943
944 /* get host status info */
945 temp_hoststatus = find_hoststatus(host_name);
946
947 /* make sure host information exists */
948 if(temp_host == NULL) {
949 printf("<P><DIV CLASS='errorMessage'>Error: Host Not Found!</DIV></P>>");
950 return;
951 }
952 if(temp_hoststatus == NULL) {
953 printf("<P><DIV CLASS='errorMessage'>Error: Host Status Information Not Found!</DIV></P");
954 return;
955 }
956
957
958 printf("<DIV ALIGN=CENTER>\n");
959 printf("<TABLE BORDER=0 CELLPADDING=0 WIDTH=100%%>\n");
960 printf("<TR>\n");
961
962 printf("<TD ALIGN=CENTER VALIGN=TOP CLASS='stateInfoPanel'>\n");
963
964 printf("<DIV CLASS='dataTitle'>Host State Information</DIV>\n");
965
966 if(temp_hoststatus->has_been_checked == FALSE)
967 printf("<P><DIV ALIGN=CENTER>This host has not yet been checked, so status information is not available.</DIV></P>\n");
968
969 else {
970
971 printf("<TABLE BORDER=0>\n");
972 printf("<TR><TD>\n");
973
974 printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
975 printf("<TR><TD class='stateInfoTable1'>\n");
976 printf("<TABLE BORDER=0>\n");
977
978 current_time = time(NULL);
979 t = 0;
980 duration_error = FALSE;
981 if(temp_hoststatus->last_state_change == (time_t)0) {
982 if(program_start > current_time)
983 duration_error = TRUE;
984 else
985 t = current_time - program_start;
986 }
987 else {
988 if(temp_hoststatus->last_state_change > current_time)
989 duration_error = TRUE;
990 else
991 t = current_time - temp_hoststatus->last_state_change;
992 }
993 get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds);
994 if(duration_error == TRUE)
995 snprintf(state_duration, sizeof(state_duration) - 1, "???");
996 else
997 snprintf(state_duration, sizeof(state_duration) - 1, "%2dd %2dh %2dm %2ds%s", days, hours, minutes, seconds, (temp_hoststatus->last_state_change == (time_t)0) ? "+" : "");
998 state_duration[sizeof(state_duration) - 1] = '\x0';
999
1000 if(temp_hoststatus->status == SD_HOST_UP) {
1001 strcpy(state_string, "UP");
1002 bg_class = "hostUP";
1003 }
1004 else if(temp_hoststatus->status == SD_HOST_DOWN) {
1005 strcpy(state_string, "DOWN");
1006 bg_class = "hostDOWN";
1007 }
1008 else if(temp_hoststatus->status == SD_HOST_UNREACHABLE) {
1009 strcpy(state_string, "UNREACHABLE");
1010 bg_class = "hostUNREACHABLE";
1011 }
1012
1013 printf("<TR><TD CLASS='dataVar'>Host Status:</td><td CLASS='dataVal'><DIV CLASS='%s'> %s </DIV> (for %s)%s</td></tr>\n", bg_class, state_string, state_duration, (temp_hoststatus->problem_has_been_acknowledged == TRUE) ? " (Has been acknowledged)" : "");
1014
1015 printf("<TR><TD CLASS='dataVar' VALIGN='top'>Status Information:</td><td CLASS='dataVal'>%s", (temp_hoststatus->plugin_output == NULL) ? "" : html_encode(temp_hoststatus->plugin_output, TRUE));
1016 if(enable_splunk_integration == TRUE) {
1017 printf(" ");
1018 asprintf(&buf, "%s %s", temp_host->name, temp_hoststatus->plugin_output);
1019 display_splunk_generic_url(buf, 1);
1020 free(buf);
1021 }
1022 if(temp_hoststatus->long_plugin_output != NULL)
1023 printf("<BR>%s", html_encode(temp_hoststatus->long_plugin_output, TRUE));
1024 printf("</TD></TR>\n");
1025
1026 printf("<TR><TD CLASS='dataVar' VALIGN='top'>Performance Data:</td><td CLASS='dataVal'>%s</td></tr>\n", (temp_hoststatus->perf_data == NULL) ? "" : html_encode(temp_hoststatus->perf_data, TRUE));
1027
1028 printf("<TR><TD CLASS='dataVar'>Current Attempt:</TD><TD CLASS='dataVal'>%d/%d", temp_hoststatus->current_attempt, temp_hoststatus->max_attempts);
1029 printf(" (%s state)</TD></TR>\n", (temp_hoststatus->state_type == HARD_STATE) ? "HARD" : "SOFT");
1030
1031 get_time_string(&temp_hoststatus->last_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1032 printf("<TR><TD CLASS='dataVar'>Last Check Time:</td><td CLASS='dataVal'>%s</td></tr>\n", date_time);
1033
1034 printf("<TR><TD CLASS='dataVar'>Check Type:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (temp_hoststatus->check_type == CHECK_TYPE_ACTIVE) ? "ACTIVE" : "PASSIVE");
1035
1036 printf("<TR><TD CLASS='dataVar' NOWRAP>Check Latency / Duration:</TD><TD CLASS='dataVal'>");
1037 if(temp_hoststatus->check_type == CHECK_TYPE_ACTIVE)
1038 printf("%.3f", temp_hoststatus->latency);
1039 else
1040 printf("N/A");
1041 printf(" / %.3f seconds", temp_hoststatus->execution_time);
1042 printf("</TD></TR>\n");
1043
1044 get_time_string(&temp_hoststatus->next_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1045 printf("<TR><TD CLASS='dataVar'>Next Scheduled Active Check: </TD><TD CLASS='dataVal'>%s</TD></TR>\n", (temp_hoststatus->checks_enabled && temp_hoststatus->next_check != (time_t)0 && temp_hoststatus->should_be_scheduled == TRUE) ? date_time : "N/A");
1046
1047 get_time_string(&temp_hoststatus->last_state_change, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1048 printf("<TR><TD CLASS='dataVar'>Last State Change:</td><td CLASS='dataVal'>%s</td></tr>\n", (temp_hoststatus->last_state_change == (time_t)0) ? "N/A" : date_time);
1049
1050 get_time_string(&temp_hoststatus->last_notification, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1051 printf("<TR><TD CLASS='dataVar'>Last Notification:</td><td CLASS='dataVal'>%s (notification %d)</td></tr>\n", (temp_hoststatus->last_notification == (time_t)0) ? "N/A" : date_time, temp_hoststatus->current_notification_number);
1052
1053 printf("<TR><TD CLASS='dataVar'>Is This Host Flapping?</td><td CLASS='dataVal'>");
1054 if(temp_hoststatus->flap_detection_enabled == FALSE || enable_flap_detection == FALSE)
1055 printf("N/A");
1056 else
1057 printf("<DIV CLASS='%sflapping'> %s </DIV> (%3.2f%% state change)", (temp_hoststatus->is_flapping == TRUE) ? "" : "not", (temp_hoststatus->is_flapping == TRUE) ? "YES" : "NO", temp_hoststatus->percent_state_change);
1058 printf("</td></tr>\n");
1059
1060 printf("<TR><TD CLASS='dataVar'>In Scheduled Downtime?</td><td CLASS='dataVal'><DIV CLASS='downtime%s'> %s </DIV></td></tr>\n", (temp_hoststatus->scheduled_downtime_depth > 0) ? "ACTIVE" : "INACTIVE", (temp_hoststatus->scheduled_downtime_depth > 0) ? "YES" : "NO");
1061
1062 t = 0;
1063 duration_error = FALSE;
1064 if(temp_hoststatus->last_check > current_time)
1065 duration_error = TRUE;
1066 else
1067 /*t=current_time-temp_hoststatus->last_check;*/
1068 t = current_time - temp_hoststatus->last_update;
1069 get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds);
1070 if(duration_error == TRUE)
1071 snprintf(status_age, sizeof(status_age) - 1, "???");
1072 else if(temp_hoststatus->last_check == (time_t)0)
1073 snprintf(status_age, sizeof(status_age) - 1, "N/A");
1074 else
1075 snprintf(status_age, sizeof(status_age) - 1, "%2dd %2dh %2dm %2ds", days, hours, minutes, seconds);
1076 status_age[sizeof(status_age) - 1] = '\x0';
1077
1078 get_time_string(&temp_hoststatus->last_update, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1079 printf("<TR><TD CLASS='dataVar'>Last Update:</td><td CLASS='dataVal'>%s (%s ago)</td></tr>\n", (temp_hoststatus->last_update == (time_t)0) ? "N/A" : date_time, status_age);
1080
1081 printf("</TABLE>\n");
1082 printf("</TD></TR>\n");
1083 printf("</TABLE>\n");
1084
1085 printf("</TD></TR>\n");
1086 printf("<TR><TD>\n");
1087
1088 printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
1089 printf("<TR><TD class='stateInfoTable2'>\n");
1090 printf("<TABLE BORDER=0>\n");
1091
1092 printf("<TR><TD CLASS='dataVar'>Active Checks:</TD><TD CLASS='dataVal'><DIV CLASS='checks%s'> %s </DIV></TD></TR>\n", (temp_hoststatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED", (temp_hoststatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED");
1093
1094 printf("<TR><TD CLASS='dataVar'>Passive Checks:</TD><td CLASS='dataVal'><DIV CLASS='checks%s'> %s </DIV></TD></TR>\n", (temp_hoststatus->accept_passive_checks == TRUE) ? "ENABLED" : "DISABLED", (temp_hoststatus->accept_passive_checks) ? "ENABLED" : "DISABLED");
1095
1096 printf("<TR><TD CLASS='dataVar'>Obsessing:</TD><td CLASS='dataVal'><DIV CLASS='checks%s'> %s </DIV></TD></TR>\n", (temp_hoststatus->obsess == TRUE) ? "ENABLED" : "DISABLED", (temp_hoststatus->obsess) ? "ENABLED" : "DISABLED");
1097
1098 printf("<TR><TD CLASS='dataVar'>Notifications:</td><td CLASS='dataVal'><DIV CLASS='notifications%s'> %s </DIV></td></tr>\n", (temp_hoststatus->notifications_enabled) ? "ENABLED" : "DISABLED", (temp_hoststatus->notifications_enabled) ? "ENABLED" : "DISABLED");
1099
1100 printf("<TR><TD CLASS='dataVar'>Event Handler:</td><td CLASS='dataVal'><DIV CLASS='eventhandlers%s'> %s </DIV></td></tr>\n", (temp_hoststatus->event_handler_enabled) ? "ENABLED" : "DISABLED", (temp_hoststatus->event_handler_enabled) ? "ENABLED" : "DISABLED");
1101
1102 printf("<TR><TD CLASS='dataVar'>Flap Detection:</td><td CLASS='dataVal'><DIV CLASS='flapdetection%s'> %s </DIV></td></tr>\n", (temp_hoststatus->flap_detection_enabled == TRUE) ? "ENABLED" : "DISABLED", (temp_hoststatus->flap_detection_enabled == TRUE) ? "ENABLED" : "DISABLED");
1103
1104 printf("</TABLE>\n");
1105 printf("</TD></TR>\n");
1106 printf("</TABLE>\n");
1107
1108 printf("</TD></TR>\n");
1109 printf("</TABLE>\n");
1110 }
1111
1112 printf("</TD>\n");
1113
1114 printf("<TD ALIGN=CENTER VALIGN=TOP>\n");
1115 printf("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0><TR>\n");
1116
1117 printf("<TD ALIGN=CENTER VALIGN=TOP CLASS='commandPanel'>\n");
1118
1119 printf("<DIV CLASS='commandTitle'>Host Commands</DIV>\n");
1120
1121 printf("<TABLE BORDER='1' CELLPADDING=0 CELLSPACING=0><TR><TD>\n");
1122
1123 if(nagios_process_state == STATE_OK && is_authorized_for_read_only(¤t_authdata) == FALSE) {
1124
1125 printf("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 CLASS='command'>\n");
1126 #ifdef USE_STATUSMAP
1127 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Locate Host On Map' TITLE='Locate Host On Map'></td><td CLASS='command'><a href='%s?host=%s&root=%s'>Locate host on map</a></td></tr>\n", url_images_path, STATUSMAP_ICON, STATUSMAP_CGI, url_encode(host_name), url_encode(host_name));
1128 #endif
1129 if(temp_hoststatus->checks_enabled == TRUE) {
1130 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Active Checks Of This Host' TITLE='Disable Active Checks Of This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Disable active checks of this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_CHECK, url_encode(host_name));
1131 }
1132 else
1133 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Active Checks Of This Host' TITLE='Enable Active Checks Of This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Enable active checks of this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_CHECK, url_encode(host_name));
1134 printf("<tr CLASS='data'><td><img src='%s%s' border=0 ALT='Re-schedule Next Host Check' TITLE='Re-schedule Next Host Check'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s%s'>Re-schedule the next check of this host</a></td></tr>\n", url_images_path, DELAY_ICON, COMMAND_CGI, CMD_SCHEDULE_HOST_CHECK, url_encode(host_name), (temp_hoststatus->checks_enabled == TRUE) ? "&force_check" : "");
1135
1136 if(temp_hoststatus->accept_passive_checks == TRUE) {
1137 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Submit Passive Check Result For This Host' TITLE='Submit Passive Check Result For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Submit passive check result for this host</a></td></tr>\n", url_images_path, PASSIVE_ICON, COMMAND_CGI, CMD_PROCESS_HOST_CHECK_RESULT, url_encode(host_name));
1138 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Stop Accepting Passive Checks For This Host' TITLE='Stop Accepting Passive Checks For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Stop accepting passive checks for this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_PASSIVE_HOST_CHECKS, url_encode(host_name));
1139 }
1140 else
1141 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Start Accepting Passive Checks For This Host' TITLE='Start Accepting Passive Checks For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Start accepting passive checks for this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_PASSIVE_HOST_CHECKS, url_encode(host_name));
1142
1143 if(temp_hoststatus->obsess == TRUE)
1144 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Stop Obsessing Over This Host' TITLE='Stop Obsessing Over This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Stop obsessing over this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_OBSESSING_OVER_HOST, url_encode(host_name));
1145 else
1146 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Start Obsessing Over This Host' TITLE='Start Obsessing Over This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Start obsessing over this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_OBSESSING_OVER_HOST, url_encode(host_name));
1147
1148 if(temp_hoststatus->status == SD_HOST_DOWN || temp_hoststatus->status == SD_HOST_UNREACHABLE) {
1149 if(temp_hoststatus->problem_has_been_acknowledged == FALSE)
1150 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Acknowledge This Host Problem' TITLE='Acknowledge This Host Problem'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Acknowledge this host problem</a></td></tr>\n", url_images_path, ACKNOWLEDGEMENT_ICON, COMMAND_CGI, CMD_ACKNOWLEDGE_HOST_PROBLEM, url_encode(host_name));
1151 else
1152 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Remove Problem Acknowledgement' TITLE='Remove Problem Acknowledgement'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Remove problem acknowledgement</a></td></tr>\n", url_images_path, REMOVE_ACKNOWLEDGEMENT_ICON, COMMAND_CGI, CMD_REMOVE_HOST_ACKNOWLEDGEMENT, url_encode(host_name));
1153 }
1154
1155 if(temp_hoststatus->notifications_enabled == TRUE)
1156 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Notifications For This Host' TITLE='Disable Notifications For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Disable notifications for this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_NOTIFICATIONS, url_encode(host_name));
1157 else
1158 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Notifications For This Host' TITLE='Enable Notifications For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Enable notifications for this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_NOTIFICATIONS, url_encode(host_name));
1159
1160 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Send Custom Notification' TITLE='Send Custom Notification'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Send custom host notification</a></td></tr>\n", url_images_path, NOTIFICATION_ICON, COMMAND_CGI, CMD_SEND_CUSTOM_HOST_NOTIFICATION, url_encode(host_name));
1161
1162 if(temp_hoststatus->status != SD_HOST_UP)
1163 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Delay Next Host Notification' TITLE='Delay Next Host Notification'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Delay next host notification</a></td></tr>\n", url_images_path, DELAY_ICON, COMMAND_CGI, CMD_DELAY_HOST_NOTIFICATION, url_encode(host_name));
1164
1165 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Schedule Downtime For This Host' TITLE='Schedule Downtime For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Schedule downtime for this host</a></td></tr>\n", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_HOST_DOWNTIME, url_encode(host_name));
1166
1167 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Schedule Downtime For All Services On This Host' TITLE='Schedule Downtime For All Services On This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Schedule downtime for all services on this host</a></td></tr>\n", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_HOST_SVC_DOWNTIME, url_encode(host_name));
1168
1169 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Notifications For All Services On This Host' TITLE='Disable Notifications For All Services On This Host'></td><td CLASS='command' NOWRAP><a href='%s?cmd_typ=%d&host=%s'>Disable notifications for all services on this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_SVC_NOTIFICATIONS, url_encode(host_name));
1170
1171 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Notifications For All Services On This Host' TITLE='Enable Notifications For All Services On This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Enable notifications for all services on this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_SVC_NOTIFICATIONS, url_encode(host_name));
1172
1173 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Schedule A Check Of All Services On This Host' TITLE='Schedule A Check Of All Services On This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Schedule a check of all services on this host</a></td></tr>\n", url_images_path, DELAY_ICON, COMMAND_CGI, CMD_SCHEDULE_HOST_SVC_CHECKS, url_encode(host_name));
1174
1175 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Checks Of All Services On This Host' TITLE='Disable Checks Of All Services On This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Disable checks of all services on this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_SVC_CHECKS, url_encode(host_name));
1176
1177 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Checks Of All Services On This Host' TITLE='Enable Checks Of All Services On This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Enable checks of all services on this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_SVC_CHECKS, url_encode(host_name));
1178
1179 if(temp_hoststatus->event_handler_enabled == TRUE)
1180 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Event Handler For This Host' TITLE='Disable Event Handler For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Disable event handler for this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_EVENT_HANDLER, url_encode(host_name));
1181 else
1182 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Event Handler For This Host' TITLE='Enable Event Handler For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Enable event handler for this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_EVENT_HANDLER, url_encode(host_name));
1183 if(temp_hoststatus->flap_detection_enabled == TRUE) {
1184 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Flap Detection For This Host' TITLE='Disable Flap Detection For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Disable flap detection for this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_FLAP_DETECTION, url_encode(host_name));
1185 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Clear Flapping State For This Host' TITLE='Clear Flapping State For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Clear flapping state for this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_CLEAR_HOST_FLAPPING_STATE, url_encode(host_name));
1186 } else
1187 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Flap Detection For This Host' TITLE='Enable Flap Detection For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Enable flap detection for this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_FLAP_DETECTION, url_encode(host_name));
1188
1189 printf("</TABLE>\n");
1190 }
1191 else if(is_authorized_for_read_only(¤t_authdata) == TRUE) {
1192 printf("<DIV ALIGN=CENTER CLASS='infoMessage'>Your account does not have permissions to execute commands.<br>\n");
1193 }
1194 else {
1195 printf("<DIV ALIGN=CENTER CLASS='infoMessage'>It appears as though Nagios is not running, so commands are temporarily unavailable...<br>\n");
1196 printf("Click <a href='%s?type=%d'>here</a> to view Nagios process information</DIV>\n", EXTINFO_CGI, DISPLAY_PROCESS_INFO);
1197 }
1198 printf("</TD></TR></TABLE>\n");
1199
1200 printf("</TD>\n");
1201
1202 printf("</TR>\n");
1203 printf("</TABLE></TR>\n");
1204
1205 printf("<TR>\n");
1206
1207 printf("<TD COLSPAN=2 ALIGN=CENTER VALIGN=TOP CLASS='commentPanel'>\n");
1208
1209 /* display comments */
1210 display_comments(HOST_COMMENT);
1211
1212 printf("</TD>\n");
1213
1214 printf("</TR>\n");
1215 printf("</TABLE>\n");
1216 printf("</DIV>\n");
1217
1218 return;
1219 }
1220
1221
show_service_info(void)1222 void show_service_info(void) {
1223 service *temp_service;
1224 char date_time[MAX_DATETIME_LENGTH];
1225 char status_age[48];
1226 char state_duration[48];
1227 servicestatus *temp_svcstatus;
1228 char state_string[MAX_INPUT_BUFFER];
1229 const char *bg_class = "";
1230 char *buf = NULL;
1231 int days;
1232 int hours;
1233 int minutes;
1234 int seconds;
1235 time_t t;
1236 time_t current_time;
1237 int duration_error = FALSE;
1238
1239 /* find the service */
1240 temp_service = find_service(host_name, service_desc);
1241
1242 /* make sure the user has rights to view service information */
1243 if(is_authorized_for_service(temp_service, ¤t_authdata) == FALSE) {
1244
1245 printf("<P><DIV CLASS='errorMessage'>It appears as though you do not have permission to view information for this service...</DIV></P>\n");
1246 printf("<P><DIV CLASS='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
1247 printf("and check the authorization options in your CGI configuration file.</DIV></P>\n");
1248
1249 return;
1250 }
1251
1252 /* get service status info */
1253 temp_svcstatus = find_servicestatus(host_name, service_desc);
1254
1255 /* make sure service information exists */
1256 if(temp_service == NULL) {
1257 printf("<P><DIV CLASS='errorMessage'>Error: Service Not Found!</DIV></P>");
1258 return;
1259 }
1260 if(temp_svcstatus == NULL) {
1261 printf("<P><DIV CLASS='errorMessage'>Error: Service Status Not Found!</DIV></P>");
1262 return;
1263 }
1264
1265
1266 printf("<DIV ALIGN=CENTER>\n");
1267 printf("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%%>\n");
1268 printf("<TR>\n");
1269
1270 printf("<TD ALIGN=CENTER VALIGN=TOP CLASS='stateInfoPanel'>\n");
1271
1272 printf("<DIV CLASS='dataTitle'>Service State Information</DIV>\n");
1273
1274 if(temp_svcstatus->has_been_checked == FALSE)
1275 printf("<P><DIV ALIGN=CENTER>This service has not yet been checked, so status information is not available.</DIV></P>\n");
1276
1277 else {
1278
1279 printf("<TABLE BORDER=0>\n");
1280
1281 printf("<TR><TD>\n");
1282
1283 printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
1284 printf("<TR><TD class='stateInfoTable1'>\n");
1285 printf("<TABLE BORDER=0>\n");
1286
1287
1288 current_time = time(NULL);
1289 t = 0;
1290 duration_error = FALSE;
1291 if(temp_svcstatus->last_state_change == (time_t)0) {
1292 if(program_start > current_time)
1293 duration_error = TRUE;
1294 else
1295 t = current_time - program_start;
1296 }
1297 else {
1298 if(temp_svcstatus->last_state_change > current_time)
1299 duration_error = TRUE;
1300 else
1301 t = current_time - temp_svcstatus->last_state_change;
1302 }
1303 get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds);
1304 if(duration_error == TRUE)
1305 snprintf(state_duration, sizeof(state_duration) - 1, "???");
1306 else
1307 snprintf(state_duration, sizeof(state_duration) - 1, "%2dd %2dh %2dm %2ds%s", days, hours, minutes, seconds, (temp_svcstatus->last_state_change == (time_t)0) ? "+" : "");
1308 state_duration[sizeof(state_duration) - 1] = '\x0';
1309
1310 if(temp_svcstatus->status == SERVICE_OK) {
1311 strcpy(state_string, "OK");
1312 bg_class = "serviceOK";
1313 }
1314 else if(temp_svcstatus->status == SERVICE_WARNING) {
1315 strcpy(state_string, "WARNING");
1316 bg_class = "serviceWARNING";
1317 }
1318 else if(temp_svcstatus->status == SERVICE_CRITICAL) {
1319 strcpy(state_string, "CRITICAL");
1320 bg_class = "serviceCRITICAL";
1321 }
1322 else {
1323 strcpy(state_string, "UNKNOWN");
1324 bg_class = "serviceUNKNOWN";
1325 }
1326 printf("<TR><TD CLASS='dataVar'>Current Status:</TD><TD CLASS='dataVal'><DIV CLASS='%s'> %s </DIV> (for %s)%s</TD></TR>\n", bg_class, state_string, state_duration, (temp_svcstatus->problem_has_been_acknowledged == TRUE) ? " (Has been acknowledged)" : "");
1327
1328 printf("<TR><TD CLASS='dataVar' VALIGN='top'>Status Information:</TD><TD CLASS='dataVal'>%s", (temp_svcstatus->plugin_output == NULL) ? "" : html_encode(temp_svcstatus->plugin_output, TRUE));
1329 if(enable_splunk_integration == TRUE) {
1330 printf(" ");
1331 asprintf(&buf, "%s %s %s", temp_service->host_name, temp_service->description, temp_svcstatus->plugin_output);
1332 display_splunk_generic_url(buf, 1);
1333 free(buf);
1334 }
1335 if(temp_svcstatus->long_plugin_output != NULL)
1336 printf("<BR>%s", html_encode(temp_svcstatus->long_plugin_output, TRUE));
1337 printf("</TD></TR>\n");
1338
1339 printf("<TR><TD CLASS='dataVar' VALIGN='top'>Performance Data:</td><td CLASS='dataVal'>%s</td></tr>\n", (temp_svcstatus->perf_data == NULL) ? "" : html_encode(temp_svcstatus->perf_data, TRUE));
1340
1341 printf("<TR><TD CLASS='dataVar'>Current Attempt:</TD><TD CLASS='dataVal'>%d/%d", temp_svcstatus->current_attempt, temp_svcstatus->max_attempts);
1342 printf(" (%s state)</TD></TR>\n", (temp_svcstatus->state_type == HARD_STATE) ? "HARD" : "SOFT");
1343
1344 get_time_string(&temp_svcstatus->last_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1345 printf("<TR><TD CLASS='dataVar'>Last Check Time:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", date_time);
1346
1347 printf("<TR><TD CLASS='dataVar'>Check Type:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (temp_svcstatus->check_type == CHECK_TYPE_ACTIVE) ? "ACTIVE" : "PASSIVE");
1348
1349 printf("<TR><TD CLASS='dataVar' NOWRAP>Check Latency / Duration:</TD><TD CLASS='dataVal'>");
1350 if(temp_svcstatus->check_type == CHECK_TYPE_ACTIVE)
1351 printf("%.3f", temp_svcstatus->latency);
1352 else
1353 printf("N/A");
1354 printf(" / %.3f seconds", temp_svcstatus->execution_time);
1355 printf("</TD></TR>\n");
1356
1357 get_time_string(&temp_svcstatus->next_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1358 printf("<TR><TD CLASS='dataVar'>Next Scheduled Check: </TD><TD CLASS='dataVal'>%s</TD></TR>\n", (temp_svcstatus->checks_enabled && temp_svcstatus->next_check != (time_t)0 && temp_svcstatus->should_be_scheduled == TRUE) ? date_time : "N/A");
1359
1360 get_time_string(&temp_svcstatus->last_state_change, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1361 printf("<TR><TD CLASS='dataVar'>Last State Change:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (temp_svcstatus->last_state_change == (time_t)0) ? "N/A" : date_time);
1362
1363 get_time_string(&temp_svcstatus->last_notification, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1364 printf("<TR><TD CLASS='dataVar'>Last Notification:</TD><TD CLASS='dataVal'>%s (notification %d)</TD></TR>\n", (temp_svcstatus->last_notification == (time_t)0) ? "N/A" : date_time, temp_svcstatus->current_notification_number);
1365
1366 printf("<TR><TD CLASS='dataVar'>Is This Service Flapping?</TD><TD CLASS='dataVal'>");
1367 if(temp_svcstatus->flap_detection_enabled == FALSE || enable_flap_detection == FALSE)
1368 printf("N/A");
1369 else
1370 printf("<DIV CLASS='%sflapping'> %s </DIV> (%3.2f%% state change)", (temp_svcstatus->is_flapping == TRUE) ? "" : "not", (temp_svcstatus->is_flapping == TRUE) ? "YES" : "NO", temp_svcstatus->percent_state_change);
1371 printf("</TD></TR>\n");
1372
1373 printf("<TR><TD CLASS='dataVar'>In Scheduled Downtime?</TD><TD CLASS='dataVal'><DIV CLASS='downtime%s'> %s </DIV></TD></TR>\n", (temp_svcstatus->scheduled_downtime_depth > 0) ? "ACTIVE" : "INACTIVE", (temp_svcstatus->scheduled_downtime_depth > 0) ? "YES" : "NO");
1374
1375 t = 0;
1376 duration_error = FALSE;
1377 if(temp_svcstatus->last_check > current_time)
1378 duration_error = TRUE;
1379 else
1380 /*t=current_time-temp_svcstatus->last_check;*/
1381 t = current_time - temp_svcstatus->last_update;
1382 get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds);
1383 if(duration_error == TRUE)
1384 snprintf(status_age, sizeof(status_age) - 1, "???");
1385 else if(temp_svcstatus->last_check == (time_t)0)
1386 snprintf(status_age, sizeof(status_age) - 1, "N/A");
1387 else
1388 snprintf(status_age, sizeof(status_age) - 1, "%2dd %2dh %2dm %2ds", days, hours, minutes, seconds);
1389 status_age[sizeof(status_age) - 1] = '\x0';
1390
1391 get_time_string(&temp_svcstatus->last_update, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1392 printf("<TR><TD CLASS='dataVar'>Last Update:</TD><TD CLASS='dataVal'>%s (%s ago)</TD></TR>\n", (temp_svcstatus->last_update == (time_t)0) ? "N/A" : date_time, status_age);
1393
1394
1395 printf("</TABLE>\n");
1396 printf("</TD></TR>\n");
1397 printf("</TABLE>\n");
1398
1399 printf("</TD></TR>\n");
1400
1401 printf("<TR><TD>\n");
1402
1403 printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
1404 printf("<TR><TD class='stateInfoTable2'>\n");
1405 printf("<TABLE BORDER=0>\n");
1406
1407 printf("<TR><TD CLASS='dataVar'>Active Checks:</TD><td CLASS='dataVal'><DIV CLASS='checks%s'> %s </DIV></TD></TR>\n", (temp_svcstatus->checks_enabled) ? "ENABLED" : "DISABLED", (temp_svcstatus->checks_enabled) ? "ENABLED" : "DISABLED");
1408
1409 printf("<TR><TD CLASS='dataVar'>Passive Checks:</TD><td CLASS='dataVal'><DIV CLASS='checks%s'> %s </DIV></TD></TR>\n", (temp_svcstatus->accept_passive_checks == TRUE) ? "ENABLED" : "DISABLED", (temp_svcstatus->accept_passive_checks) ? "ENABLED" : "DISABLED");
1410
1411 printf("<TR><TD CLASS='dataVar'>Obsessing:</TD><td CLASS='dataVal'><DIV CLASS='checks%s'> %s </DIV></TD></TR>\n", (temp_svcstatus->obsess == TRUE) ? "ENABLED" : "DISABLED", (temp_svcstatus->obsess) ? "ENABLED" : "DISABLED");
1412
1413 printf("<TR><td CLASS='dataVar'>Notifications:</TD><td CLASS='dataVal'><DIV CLASS='notifications%s'> %s </DIV></TD></TR>\n", (temp_svcstatus->notifications_enabled) ? "ENABLED" : "DISABLED", (temp_svcstatus->notifications_enabled) ? "ENABLED" : "DISABLED");
1414
1415 printf("<TR><TD CLASS='dataVar'>Event Handler:</TD><td CLASS='dataVal'><DIV CLASS='eventhandlers%s'> %s </DIV></TD></TR>\n", (temp_svcstatus->event_handler_enabled) ? "ENABLED" : "DISABLED", (temp_svcstatus->event_handler_enabled) ? "ENABLED" : "DISABLED");
1416
1417 printf("<TR><TD CLASS='dataVar'>Flap Detection:</TD><td CLASS='dataVal'><DIV CLASS='flapdetection%s'> %s </DIV></TD></TR>\n", (temp_svcstatus->flap_detection_enabled == TRUE) ? "ENABLED" : "DISABLED", (temp_svcstatus->flap_detection_enabled == TRUE) ? "ENABLED" : "DISABLED");
1418
1419
1420 printf("</TABLE>\n");
1421 printf("</TD></TR>\n");
1422 printf("</TABLE>\n");
1423
1424 printf("</TD></TR>\n");
1425
1426 printf("</TABLE>\n");
1427 }
1428
1429
1430 printf("</TD>\n");
1431
1432 printf("<TD ALIGN=CENTER VALIGN=TOP>\n");
1433 printf("<TABLE BORDER='0' CELLPADDING=0 CELLSPACING=0><TR>\n");
1434
1435 printf("<TD ALIGN=CENTER VALIGN=TOP CLASS='commandPanel'>\n");
1436
1437 printf("<DIV CLASS='dataTitle'>Service Commands</DIV>\n");
1438
1439 printf("<TABLE BORDER='1' CELLSPACING=0 CELLPADDING=0>\n");
1440 printf("<TR><TD>\n");
1441
1442 if(nagios_process_state == STATE_OK && is_authorized_for_read_only(¤t_authdata) == FALSE) {
1443 printf("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 CLASS='command'>\n");
1444
1445 if(temp_svcstatus->checks_enabled) {
1446
1447 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Active Checks Of This Service' TITLE='Disable Active Checks Of This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_SVC_CHECK, url_encode(host_name));
1448 printf("&service=%s'>Disable active checks of this service</a></td></tr>\n", url_encode(service_desc));
1449 }
1450 else {
1451 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Active Checks Of This Service' TITLE='Enable Active Checks Of This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_SVC_CHECK, url_encode(host_name));
1452 printf("&service=%s'>Enable active checks of this service</a></td></tr>\n", url_encode(service_desc));
1453 }
1454 printf("<tr CLASS='data'><td><img src='%s%s' border=0 ALT='Re-schedule Next Service Check' TITLE='Re-schedule Next Service Check'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DELAY_ICON, COMMAND_CGI, CMD_SCHEDULE_SVC_CHECK, url_encode(host_name));
1455 printf("&service=%s%s'>Re-schedule the next check of this service</a></td></tr>\n", url_encode(service_desc), (temp_svcstatus->checks_enabled == TRUE) ? "&force_check" : "");
1456
1457 if(temp_svcstatus->accept_passive_checks == TRUE) {
1458 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Submit Passive Check Result For This Service' TITLE='Submit Passive Check Result For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, PASSIVE_ICON, COMMAND_CGI, CMD_PROCESS_SERVICE_CHECK_RESULT, url_encode(host_name));
1459 printf("&service=%s'>Submit passive check result for this service</a></td></tr>\n", url_encode(service_desc));
1460
1461 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Stop Accepting Passive Checks For This Service' TITLE='Stop Accepting Passive Checks For This Service'></td><td CLASS='command' NOWRAP><a href='%s?cmd_typ=%d&host=%s", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_PASSIVE_SVC_CHECKS, url_encode(host_name));
1462 printf("&service=%s'>Stop accepting passive checks for this service</a></td></tr>\n", url_encode(service_desc));
1463 }
1464 else {
1465 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Start Accepting Passive Checks For This Service' TITLE='Start Accepting Passive Checks For This Service'></td><td CLASS='command' NOWRAP><a href='%s?cmd_typ=%d&host=%s", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_PASSIVE_SVC_CHECKS, url_encode(host_name));
1466 printf("&service=%s'>Start accepting passive checks for this service</a></td></tr>\n", url_encode(service_desc));
1467 }
1468
1469 if(temp_svcstatus->obsess == TRUE) {
1470 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Stop Obsessing Over This Service' TITLE='Stop Obsessing Over This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_OBSESSING_OVER_SVC, url_encode(host_name));
1471 printf("&service=%s'>Stop obsessing over this service</a></td></tr>\n", url_encode(service_desc));
1472 }
1473 else {
1474 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Start Obsessing Over This Service' TITLE='Start Obsessing Over This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_OBSESSING_OVER_SVC, url_encode(host_name));
1475 printf("&service=%s'>Start obsessing over this service</a></td></tr>\n", url_encode(service_desc));
1476 }
1477
1478 if((temp_svcstatus->status == SERVICE_WARNING || temp_svcstatus->status == SERVICE_UNKNOWN || temp_svcstatus->status == SERVICE_CRITICAL) && temp_svcstatus->state_type == HARD_STATE) {
1479 if(temp_svcstatus->problem_has_been_acknowledged == FALSE) {
1480 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Acknowledge This Service Problem' TITLE='Acknowledge This Service Problem'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, ACKNOWLEDGEMENT_ICON, COMMAND_CGI, CMD_ACKNOWLEDGE_SVC_PROBLEM, url_encode(host_name));
1481 printf("&service=%s'>Acknowledge this service problem</a></td></tr>\n", url_encode(service_desc));
1482 }
1483 else {
1484 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Remove Problem Acknowledgement' TITLE='Remove Problem Acknowledgement'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, REMOVE_ACKNOWLEDGEMENT_ICON, COMMAND_CGI, CMD_REMOVE_SVC_ACKNOWLEDGEMENT, url_encode(host_name));
1485 printf("&service=%s'>Remove problem acknowledgement</a></td></tr>\n", url_encode(service_desc));
1486 }
1487 }
1488 if(temp_svcstatus->notifications_enabled == TRUE) {
1489 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Notifications For This Service' TITLE='Disable Notifications For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_SVC_NOTIFICATIONS, url_encode(host_name));
1490 printf("&service=%s'>Disable notifications for this service</a></td></tr>\n", url_encode(service_desc));
1491 if(temp_svcstatus->status != SERVICE_OK) {
1492 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Delay Next Service Notification' TITLE='Delay Next Service Notification'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DELAY_ICON, COMMAND_CGI, CMD_DELAY_SVC_NOTIFICATION, url_encode(host_name));
1493 printf("&service=%s'>Delay next service notification</a></td></tr>\n", url_encode(service_desc));
1494 }
1495 }
1496 else {
1497 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Notifications For This Service' TITLE='Enable Notifications For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_SVC_NOTIFICATIONS, url_encode(host_name));
1498 printf("&service=%s'>Enable notifications for this service</a></td></tr>\n", url_encode(service_desc));
1499 }
1500
1501 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Send Custom Notification' TITLE='Send Custom Notification'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, NOTIFICATION_ICON, COMMAND_CGI, CMD_SEND_CUSTOM_SVC_NOTIFICATION, url_encode(host_name));
1502 printf("&service=%s'>Send custom service notification</a></td></tr>\n", url_encode(service_desc));
1503
1504 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Schedule Downtime For This Service' TITLE='Schedule Downtime For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_SVC_DOWNTIME, url_encode(host_name));
1505 printf("&service=%s'>Schedule downtime for this service</a></td></tr>\n", url_encode(service_desc));
1506
1507 /*
1508 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Cancel Scheduled Downtime For This Service' TITLE='Cancel Scheduled Downtime For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s",url_images_path,SCHEDULED_DOWNTIME_ICON,COMMAND_CGI,CMD_CANCEL_SVC_DOWNTIME,url_encode(host_name));
1509 printf("&service=%s'>Cancel scheduled downtime for this service</a></td></tr>\n",url_encode(service_desc));
1510 */
1511
1512 if(temp_svcstatus->event_handler_enabled == TRUE) {
1513 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Event Handler For This Service' TITLE='Disable Event Handler For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_SVC_EVENT_HANDLER, url_encode(host_name));
1514 printf("&service=%s'>Disable event handler for this service</a></td></tr>\n", url_encode(service_desc));
1515 }
1516 else {
1517 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Event Handler For This Service' TITLE='Enable Event Handler For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_SVC_EVENT_HANDLER, url_encode(host_name));
1518 printf("&service=%s'>Enable event handler for this service</a></td></tr>\n", url_encode(service_desc));
1519 }
1520
1521 if(temp_svcstatus->flap_detection_enabled == TRUE) {
1522 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Flap Detection For This Service' TITLE='Disable Flap Detection For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_SVC_FLAP_DETECTION, url_encode(host_name));
1523 printf("&service=%s'>Disable flap detection for this service</a></td></tr>\n", url_encode(service_desc));
1524 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Clear Flapping State For This Service' TITLE='Clear Flapping State For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_CLEAR_SVC_FLAPPING_STATE, url_encode(host_name));
1525 printf("&service=%s'>Clear flapping state for this service</a></td></tr>\n", url_encode(service_desc));
1526 }
1527 else {
1528 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Flap Detection For This Service' TITLE='Enable Flap Detection For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_SVC_FLAP_DETECTION, url_encode(host_name));
1529 printf("&service=%s'>Enable flap detection for this service</a></td></tr>\n", url_encode(service_desc));
1530 }
1531
1532 printf("</table>\n");
1533 }
1534 else if(is_authorized_for_read_only(¤t_authdata) == TRUE) {
1535 printf("<DIV ALIGN=CENTER CLASS='infoMessage'>Your account does not have permissions to execute commands.<br>\n");
1536 }
1537 else {
1538 printf("<DIV CLASS='infoMessage'>It appears as though Nagios is not running, so commands are temporarily unavailable...<br>\n");
1539 printf("Click <a href='%s?type=%d'>here</a> to view Nagios process information</DIV>\n", EXTINFO_CGI, DISPLAY_PROCESS_INFO);
1540 }
1541
1542 printf("</td></tr>\n");
1543 printf("</table>\n");
1544
1545 printf("</TD>\n");
1546
1547 printf("</TR></TABLE></TD>\n");
1548 printf("</TR>\n");
1549
1550 printf("<TR><TD COLSPAN=2><BR></TD></TR>\n");
1551
1552 printf("<TR>\n");
1553 printf("<TD COLSPAN=2 ALIGN=CENTER VALIGN=TOP CLASS='commentPanel'>\n");
1554
1555 /* display comments */
1556 display_comments(SERVICE_COMMENT);
1557
1558 printf("</TD>\n");
1559 printf("</TR>\n");
1560
1561 printf("</TABLE>\n");
1562 printf("</DIV>\n");
1563
1564 return;
1565 }
1566
1567
1568
1569
show_hostgroup_info(void)1570 void show_hostgroup_info(void) {
1571 hostgroup *temp_hostgroup;
1572
1573
1574 /* get hostgroup info */
1575 temp_hostgroup = find_hostgroup(hostgroup_name);
1576
1577 /* make sure the user has rights to view hostgroup information */
1578 if(is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == FALSE) {
1579
1580 printf("<P><DIV CLASS='errorMessage'>It appears as though you do not have permission to view information for this hostgroup...</DIV></P>\n");
1581 printf("<P><DIV CLASS='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
1582 printf("and check the authorization options in your CGI configuration file.</DIV></P>\n");
1583
1584 return;
1585 }
1586
1587 /* make sure hostgroup information exists */
1588 if(temp_hostgroup == NULL) {
1589 printf("<P><DIV CLASS='errorMessage'>Error: Hostgroup Not Found!</DIV></P>");
1590 return;
1591 }
1592
1593
1594 printf("<DIV ALIGN=CENTER>\n");
1595 printf("<TABLE BORDER=0 WIDTH=100%%>\n");
1596 printf("<TR>\n");
1597
1598
1599 /* top left panel */
1600 printf("<TD ALIGN=CENTER VALIGN=TOP CLASS='stateInfoPanel'>\n");
1601
1602 /* right top panel */
1603 printf("</TD><TD ALIGN=CENTER VALIGN=TOP CLASS='stateInfoPanel' ROWSPAN=2>\n");
1604
1605 printf("<DIV CLASS='dataTitle'>Hostgroup Commands</DIV>\n");
1606
1607 if(nagios_process_state == STATE_OK && is_authorized_for_read_only(¤t_authdata) == FALSE) {
1608
1609 printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 CLASS='command'>\n");
1610 printf("<TR><TD>\n");
1611
1612 printf("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 CLASS='command'>\n");
1613
1614 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Schedule Downtime For All Hosts In This Hostgroup' TITLE='Schedule Downtime For All Hosts In This Hostgroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&hostgroup=%s'>Schedule downtime for all hosts in this hostgroup</a></td></tr>\n", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME, url_encode(hostgroup_name));
1615
1616 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Schedule Downtime For All Services In This Hostgroup' TITLE='Schedule Downtime For All Services In This Hostgroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&hostgroup=%s'>Schedule downtime for all services in this hostgroup</a></td></tr>\n", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME, url_encode(hostgroup_name));
1617
1618 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Notifications For All Hosts In This Hostgroup' TITLE='Enable Notifications For All Hosts In This Hostgroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&hostgroup=%s'>Enable notifications for all hosts in this hostgroup</a></td></tr>\n", url_images_path, NOTIFICATION_ICON, COMMAND_CGI, CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS, url_encode(hostgroup_name));
1619
1620 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Notifications For All Hosts In This Hostgroup' TITLE='Disable Notifications For All Hosts In This Hostgroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&hostgroup=%s'>Disable notifications for all hosts in this hostgroup</a></td></tr>\n", url_images_path, NOTIFICATIONS_DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS, url_encode(hostgroup_name));
1621
1622 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Notifications For All Services In This Hostgroup' TITLE='Enable Notifications For All Services In This Hostgroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&hostgroup=%s'>Enable notifications for all services in this hostgroup</a></td></tr>\n", url_images_path, NOTIFICATION_ICON, COMMAND_CGI, CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS, url_encode(hostgroup_name));
1623
1624 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Notifications For All Services In This Hostgroup' TITLE='Disable Notifications For All Services In This Hostgroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&hostgroup=%s'>Disable notifications for all services in this hostgroup</a></td></tr>\n", url_images_path, NOTIFICATIONS_DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS, url_encode(hostgroup_name));
1625
1626 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Active Checks Of All Services In This Hostgroup' TITLE='Enable Active Checks Of All Services In This Hostgroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&hostgroup=%s'>Enable active checks of all services in this hostgroup</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOSTGROUP_SVC_CHECKS, url_encode(hostgroup_name));
1627
1628 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Active Checks Of All Services In This Hostgroup' TITLE='Disable Active Checks Of All Services In This Hostgroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&hostgroup=%s'>Disable active checks of all services in this hostgroup</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOSTGROUP_SVC_CHECKS, url_encode(hostgroup_name));
1629
1630 printf("</table>\n");
1631
1632 printf("</TD></TR>\n");
1633 printf("</TABLE>\n");
1634 }
1635 else if(is_authorized_for_read_only(¤t_authdata) == TRUE) {
1636 printf("<DIV ALIGN=CENTER CLASS='infoMessage'>Your account does not have permissions to execute commands.<br>\n");
1637 }
1638 else {
1639 printf("<DIV CLASS='infoMessage'>It appears as though Nagios is not running, so commands are temporarily unavailable...<br>\n");
1640 printf("Click <a href='%s?type=%d'>here</a> to view Nagios process information</DIV>\n", EXTINFO_CGI, DISPLAY_PROCESS_INFO);
1641 }
1642
1643 printf("</TD></TR>\n");
1644 printf("<TR>\n");
1645
1646 /* left bottom panel */
1647 printf("<TD ALIGN=CENTER VALIGN=TOP CLASS='stateInfoPanel'>\n");
1648
1649 printf("</TD></TR>\n");
1650 printf("</TABLE>\n");
1651 printf("</DIV>\n");
1652
1653
1654 printf("</div>\n");
1655
1656 printf("</TD>\n");
1657
1658
1659
1660 return;
1661 }
1662
1663
1664
1665
show_servicegroup_info()1666 void show_servicegroup_info() {
1667 servicegroup *temp_servicegroup;
1668
1669
1670 /* get servicegroup info */
1671 temp_servicegroup = find_servicegroup(servicegroup_name);
1672
1673 /* make sure the user has rights to view servicegroup information */
1674 if(is_authorized_for_servicegroup(temp_servicegroup, ¤t_authdata) == FALSE) {
1675
1676 printf("<P><DIV CLASS='errorMessage'>It appears as though you do not have permission to view information for this servicegroup...</DIV></P>\n");
1677 printf("<P><DIV CLASS='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
1678 printf("and check the authorization options in your CGI configuration file.</DIV></P>\n");
1679
1680 return;
1681 }
1682
1683 /* make sure servicegroup information exists */
1684 if(temp_servicegroup == NULL) {
1685 printf("<P><DIV CLASS='errorMessage'>Error: Servicegroup Not Found!</DIV></P>");
1686 return;
1687 }
1688
1689
1690 printf("<DIV ALIGN=CENTER>\n");
1691 printf("<TABLE BORDER=0 WIDTH=100%%>\n");
1692 printf("<TR>\n");
1693
1694
1695 /* top left panel */
1696 printf("<TD ALIGN=CENTER VALIGN=TOP CLASS='stateInfoPanel'>\n");
1697
1698 /* right top panel */
1699 printf("</TD><TD ALIGN=CENTER VALIGN=TOP CLASS='stateInfoPanel' ROWSPAN=2>\n");
1700
1701 printf("<DIV CLASS='dataTitle'>Servicegroup Commands</DIV>\n");
1702
1703 if(nagios_process_state == STATE_OK) {
1704
1705 printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 CLASS='command'>\n");
1706 printf("<TR><TD>\n");
1707
1708 printf("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 CLASS='command'>\n");
1709
1710 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Schedule Downtime For All Hosts In This Servicegroup' TITLE='Schedule Downtime For All Hosts In This Servicegroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&servicegroup=%s'>Schedule downtime for all hosts in this servicegroup</a></td></tr>\n", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME, url_encode(servicegroup_name));
1711
1712 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Schedule Downtime For All Services In This Servicegroup' TITLE='Schedule Downtime For All Services In This Servicegroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&servicegroup=%s'>Schedule downtime for all services in this servicegroup</a></td></tr>\n", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME, url_encode(servicegroup_name));
1713
1714 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Notifications For All Hosts In This Servicegroup' TITLE='Enable Notifications For All Hosts In This Servicegroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&servicegroup=%s'>Enable notifications for all hosts in this servicegroup</a></td></tr>\n", url_images_path, NOTIFICATION_ICON, COMMAND_CGI, CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS, url_encode(servicegroup_name));
1715
1716 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Notifications For All Hosts In This Servicegroup' TITLE='Disable Notifications For All Hosts In This Servicegroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&servicegroup=%s'>Disable notifications for all hosts in this servicegroup</a></td></tr>\n", url_images_path, NOTIFICATIONS_DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS, url_encode(servicegroup_name));
1717
1718 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Notifications For All Services In This Servicegroup' TITLE='Enable Notifications For All Services In This Servicegroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&servicegroup=%s'>Enable notifications for all services in this servicegroup</a></td></tr>\n", url_images_path, NOTIFICATION_ICON, COMMAND_CGI, CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS, url_encode(servicegroup_name));
1719
1720 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Notifications For All Services In This Servicegroup' TITLE='Disable Notifications For All Services In This Servicegroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&servicegroup=%s'>Disable notifications for all services in this servicegroup</a></td></tr>\n", url_images_path, NOTIFICATIONS_DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS, url_encode(servicegroup_name));
1721
1722 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Active Checks Of All Services In This Servicegroup' TITLE='Enable Active Checks Of All Services In This Servicegroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&servicegroup=%s'>Enable active checks of all services in this servicegroup</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_SERVICEGROUP_SVC_CHECKS, url_encode(servicegroup_name));
1723
1724 printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Active Checks Of All Services In This Servicegroup' TITLE='Disable Active Checks Of All Services In This Servicegroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&servicegroup=%s'>Disable active checks of all services in this servicegroup</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_SERVICEGROUP_SVC_CHECKS, url_encode(servicegroup_name));
1725
1726 printf("</table>\n");
1727
1728 printf("</TD></TR>\n");
1729 printf("</TABLE>\n");
1730 }
1731 else {
1732 printf("<DIV CLASS='infoMessage'>It appears as though Nagios is not running, so commands are temporarily unavailable...<br>\n");
1733 printf("Click <a href='%s?type=%d'>here</a> to view Nagios process information</DIV>\n", EXTINFO_CGI, DISPLAY_PROCESS_INFO);
1734 }
1735
1736 printf("</TD></TR>\n");
1737 printf("<TR>\n");
1738
1739 /* left bottom panel */
1740 printf("<TD ALIGN=CENTER VALIGN=TOP CLASS='stateInfoPanel'>\n");
1741
1742 printf("</TD></TR>\n");
1743 printf("</TABLE>\n");
1744 printf("</DIV>\n");
1745
1746
1747 printf("</div>\n");
1748
1749 printf("</TD>\n");
1750
1751
1752 return;
1753 }
1754
1755
1756
1757 /* shows all service and host comments */
show_all_comments(void)1758 void show_all_comments(void) {
1759 int total_comments = 0;
1760 const char *bg_class = "";
1761 int odd = 0;
1762 char date_time[MAX_DATETIME_LENGTH];
1763 nagios_comment *temp_comment;
1764 host *temp_host;
1765 service *temp_service;
1766 char *comment_type;
1767 char expire_time[MAX_DATETIME_LENGTH];
1768
1769 printf("<BR />\n");
1770 printf("<DIV CLASS='commentNav'>[ <A HREF='#HOSTCOMMENTS' CLASS='commentNav'>Host Comments</A> | <A HREF='#SERVICECOMMENTS' CLASS='commentNav'>Service Comments</A> ]</DIV>\n");
1771 printf("<BR />\n");
1772
1773 printf("<A NAME=HOSTCOMMENTS></A>\n");
1774 printf("<DIV CLASS='commentTitle'>Host Comments</DIV>\n");
1775
1776 if(is_authorized_for_read_only(¤t_authdata)==FALSE) {
1777 printf("<div CLASS='comment'><img src='%s%s' border=0> ", url_images_path, COMMENT_ICON);
1778 printf("<a href='%s?cmd_typ=%d'>", COMMAND_CGI, CMD_ADD_HOST_COMMENT);
1779 printf("Add a new host comment</a></div>\n");
1780 }
1781
1782 printf("<BR />\n");
1783 printf("<DIV ALIGN=CENTER>\n");
1784 printf("<TABLE BORDER=0 CLASS='comment'>\n");
1785 if(is_authorized_for_read_only(¤t_authdata)==FALSE)
1786 printf("<TR CLASS='comment'><TH CLASS='comment'>Host Name</TH><TH CLASS='comment'>Entry Time</TH><TH CLASS='comment'>Author</TH><TH CLASS='comment'>Comment</TH><TH CLASS='comment'>Comment ID</TH><TH CLASS='comment'>Persistent</TH><TH CLASS='comment'>Type</TH><TH CLASS='comment'>Expires</TH><TH CLASS='comment'>Actions</TH></TR>\n");
1787 else
1788 printf("<TR CLASS='comment'><TH CLASS='comment'>Host Name</TH><TH CLASS='comment'>Entry Time</TH><TH CLASS='comment'>Author</TH><TH CLASS='comment'>Comment</TH><TH CLASS='comment'>Comment ID</TH><TH CLASS='comment'>Persistent</TH><TH CLASS='comment'>Type</TH><TH CLASS='comment'>Expires</TH></TR>\n");
1789
1790 /* display all the host comments */
1791 for(temp_comment = comment_list, total_comments = 0; temp_comment != NULL; temp_comment = temp_comment->next) {
1792
1793 if(temp_comment->comment_type != HOST_COMMENT)
1794 continue;
1795
1796 temp_host = find_host(temp_comment->host_name);
1797
1798 /* make sure the user has rights to view host information */
1799 if(is_authorized_for_host(temp_host, ¤t_authdata) == FALSE)
1800 continue;
1801
1802 total_comments++;
1803
1804 if(odd) {
1805 odd = 0;
1806 bg_class = "commentOdd";
1807 }
1808 else {
1809 odd = 1;
1810 bg_class = "commentEven";
1811 }
1812
1813 switch(temp_comment->entry_type) {
1814 case USER_COMMENT:
1815 comment_type = "User";
1816 break;
1817 case DOWNTIME_COMMENT:
1818 comment_type = "Scheduled Downtime";
1819 break;
1820 case FLAPPING_COMMENT:
1821 comment_type = "Flap Detection";
1822 break;
1823 case ACKNOWLEDGEMENT_COMMENT:
1824 comment_type = "Acknowledgement";
1825 break;
1826 default:
1827 comment_type = "?";
1828 }
1829
1830 get_time_string(&temp_comment->entry_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1831 get_time_string(&temp_comment->expire_time, expire_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1832 printf("<tr CLASS='%s'>", bg_class);
1833 printf("<td CLASS='%s'><A HREF='%s?type=%d&host=%s'>%s</A></td>", bg_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_comment->host_name), temp_comment->host_name);
1834 printf("<td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%ld</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td>", bg_class, date_time, bg_class, temp_comment->author, bg_class, temp_comment->comment_data, bg_class, temp_comment->comment_id, bg_class, (temp_comment->persistent) ? "Yes" : "No", bg_class, comment_type, bg_class, (temp_comment->expires == TRUE) ? expire_time : "N/A");
1835 if(is_authorized_for_read_only(¤t_authdata)==FALSE)
1836 printf("<td><a href='%s?cmd_typ=%d&com_id=%lu'><img src='%s%s' border=0 ALT='Delete This Comment' TITLE='Delete This Comment'></td>", COMMAND_CGI, CMD_DEL_HOST_COMMENT, temp_comment->comment_id, url_images_path, DELETE_ICON);
1837 printf("</tr>\n");
1838 }
1839
1840 if(total_comments == 0)
1841 printf("<TR CLASS='commentOdd'><TD CLASS='commentOdd' COLSPAN=9>There are no host comments</TD></TR>");
1842
1843 printf("</TABLE>\n");
1844 printf("</DIV>\n");
1845
1846 printf("<BR /><BR /><BR />\n");
1847
1848
1849 printf("<A NAME=SERVICECOMMENTS></A>\n");
1850 printf("<DIV CLASS='commentTitle'>Service Comments</DIV>\n");
1851
1852 if(is_authorized_for_read_only(¤t_authdata)==FALSE){
1853 printf("<div CLASS='comment'><img src='%s%s' border=0> ", url_images_path, COMMENT_ICON);
1854 printf("<a href='%s?cmd_typ=%d'>", COMMAND_CGI, CMD_ADD_SVC_COMMENT);
1855 printf("Add a new service comment</a></div>\n");
1856 }
1857
1858 printf("<BR />\n");
1859 printf("<DIV ALIGN=CENTER>\n");
1860 printf("<TABLE BORDER=0 CLASS='comment'>\n");
1861 if(is_authorized_for_read_only(¤t_authdata)==FALSE)
1862 printf("<TR CLASS='comment'><TH CLASS='comment'>Host Name</TH><TH CLASS='comment'>Service</TH><TH CLASS='comment'>Entry Time</TH><TH CLASS='comment'>Author</TH><TH CLASS='comment'>Comment</TH><TH CLASS='comment'>Comment ID</TH><TH CLASS='comment'>Persistent</TH><TH CLASS='comment'>Type</TH><TH CLASS='comment'>Expires</TH><TH CLASS='comment'>Actions</TH></TR>\n");
1863 else
1864 printf("<TR CLASS='comment'><TH CLASS='comment'>Host Name</TH><TH CLASS='comment'>Service</TH><TH CLASS='comment'>Entry Time</TH><TH CLASS='comment'>Author</TH><TH CLASS='comment'>Comment</TH><TH CLASS='comment'>Comment ID</TH><TH CLASS='comment'>Persistent</TH><TH CLASS='comment'>Type</TH><TH CLASS='comment'>Expires</TH></TR>\n");
1865
1866 /* display all the service comments */
1867 for(temp_comment = comment_list, total_comments = 0; temp_comment != NULL; temp_comment = temp_comment->next) {
1868
1869 if(temp_comment->comment_type != SERVICE_COMMENT)
1870 continue;
1871
1872 temp_service = find_service(temp_comment->host_name, temp_comment->service_description);
1873
1874 /* make sure the user has rights to view service information */
1875 if(is_authorized_for_service(temp_service, ¤t_authdata) == FALSE)
1876 continue;
1877
1878 total_comments++;
1879
1880 if(odd) {
1881 odd = 0;
1882 bg_class = "commentOdd";
1883 }
1884 else {
1885 odd = 1;
1886 bg_class = "commentEven";
1887 }
1888
1889 switch(temp_comment->entry_type) {
1890 case USER_COMMENT:
1891 comment_type = "User";
1892 break;
1893 case DOWNTIME_COMMENT:
1894 comment_type = "Scheduled Downtime";
1895 break;
1896 case FLAPPING_COMMENT:
1897 comment_type = "Flap Detection";
1898 break;
1899 case ACKNOWLEDGEMENT_COMMENT:
1900 comment_type = "Acknowledgement";
1901 break;
1902 default:
1903 comment_type = "?";
1904 }
1905
1906 get_time_string(&temp_comment->entry_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1907 get_time_string(&temp_comment->expire_time, expire_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1908 printf("<tr CLASS='%s'>", bg_class);
1909 printf("<td CLASS='%s'><A HREF='%s?type=%d&host=%s'>%s</A></td>", bg_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_comment->host_name), temp_comment->host_name);
1910 printf("<td CLASS='%s'><A HREF='%s?type=%d&host=%s", bg_class, EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(temp_comment->host_name));
1911 printf("&service=%s'>%s</A></td>", url_encode(temp_comment->service_description), temp_comment->service_description);
1912 printf("<td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%ld</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td>", bg_class, date_time, bg_class, temp_comment->author, bg_class, temp_comment->comment_data, bg_class, temp_comment->comment_id, bg_class, (temp_comment->persistent) ? "Yes" : "No", bg_class, comment_type, bg_class, (temp_comment->expires == TRUE) ? expire_time : "N/A");
1913 if(is_authorized_for_read_only(¤t_authdata)==FALSE)
1914 printf("<td><a href='%s?cmd_typ=%d&com_id=%ld'><img src='%s%s' border=0 ALT='Delete This Comment' TITLE='Delete This Comment'></td>", COMMAND_CGI, CMD_DEL_SVC_COMMENT, temp_comment->comment_id, url_images_path, DELETE_ICON);
1915 printf("</tr>\n");
1916 }
1917
1918 if(total_comments == 0)
1919 printf("<TR CLASS='commentOdd'><TD CLASS='commentOdd' COLSPAN=10>There are no service comments</TD></TR>");
1920
1921 printf("</TABLE>\n");
1922 printf("</DIV>\n");
1923
1924 return;
1925 }
1926
1927
1928
show_performance_data(void)1929 void show_performance_data(void) {
1930 service *temp_service = NULL;
1931 servicestatus *temp_servicestatus = NULL;
1932 host *temp_host = NULL;
1933 hoststatus *temp_hoststatus = NULL;
1934 int total_active_service_checks = 0;
1935 int total_passive_service_checks = 0;
1936 double min_service_execution_time = 0.0;
1937 double max_service_execution_time = 0.0;
1938 double total_service_execution_time = 0.0;
1939 int have_min_service_execution_time = FALSE;
1940 int have_max_service_execution_time = FALSE;
1941 double min_service_latency = 0.0;
1942 double max_service_latency = 0.0;
1943 double long total_service_latency = 0.0;
1944 int have_min_service_latency = FALSE;
1945 int have_max_service_latency = FALSE;
1946 double min_host_latency = 0.0;
1947 double max_host_latency = 0.0;
1948 double total_host_latency = 0.0;
1949 int have_min_host_latency = FALSE;
1950 int have_max_host_latency = FALSE;
1951 double min_service_percent_change_a = 0.0;
1952 double max_service_percent_change_a = 0.0;
1953 double total_service_percent_change_a = 0.0;
1954 int have_min_service_percent_change_a = FALSE;
1955 int have_max_service_percent_change_a = FALSE;
1956 double min_service_percent_change_b = 0.0;
1957 double max_service_percent_change_b = 0.0;
1958 double total_service_percent_change_b = 0.0;
1959 int have_min_service_percent_change_b = FALSE;
1960 int have_max_service_percent_change_b = FALSE;
1961 int active_service_checks_1min = 0;
1962 int active_service_checks_5min = 0;
1963 int active_service_checks_15min = 0;
1964 int active_service_checks_1hour = 0;
1965 int active_service_checks_start = 0;
1966 int active_service_checks_ever = 0;
1967 int passive_service_checks_1min = 0;
1968 int passive_service_checks_5min = 0;
1969 int passive_service_checks_15min = 0;
1970 int passive_service_checks_1hour = 0;
1971 int passive_service_checks_start = 0;
1972 int passive_service_checks_ever = 0;
1973 int total_active_host_checks = 0;
1974 int total_passive_host_checks = 0;
1975 double min_host_execution_time = 0.0;
1976 double max_host_execution_time = 0.0;
1977 double total_host_execution_time = 0.0;
1978 int have_min_host_execution_time = FALSE;
1979 int have_max_host_execution_time = FALSE;
1980 double min_host_percent_change_a = 0.0;
1981 double max_host_percent_change_a = 0.0;
1982 double total_host_percent_change_a = 0.0;
1983 int have_min_host_percent_change_a = FALSE;
1984 int have_max_host_percent_change_a = FALSE;
1985 double min_host_percent_change_b = 0.0;
1986 double max_host_percent_change_b = 0.0;
1987 double total_host_percent_change_b = 0.0;
1988 int have_min_host_percent_change_b = FALSE;
1989 int have_max_host_percent_change_b = FALSE;
1990 int active_host_checks_1min = 0;
1991 int active_host_checks_5min = 0;
1992 int active_host_checks_15min = 0;
1993 int active_host_checks_1hour = 0;
1994 int active_host_checks_start = 0;
1995 int active_host_checks_ever = 0;
1996 int passive_host_checks_1min = 0;
1997 int passive_host_checks_5min = 0;
1998 int passive_host_checks_15min = 0;
1999 int passive_host_checks_1hour = 0;
2000 int passive_host_checks_start = 0;
2001 int passive_host_checks_ever = 0;
2002 time_t current_time;
2003
2004
2005 time(¤t_time);
2006
2007 /* check all services */
2008 for(temp_servicestatus = servicestatus_list; temp_servicestatus != NULL; temp_servicestatus = temp_servicestatus->next) {
2009
2010 /* find the service */
2011 temp_service = find_service(temp_servicestatus->host_name, temp_servicestatus->description);
2012
2013 /* make sure the user has rights to view service information */
2014 if(is_authorized_for_service(temp_service, ¤t_authdata) == FALSE)
2015 continue;
2016
2017 /* is this an active or passive check? */
2018 if(temp_servicestatus->check_type == CHECK_TYPE_ACTIVE) {
2019
2020 total_active_service_checks++;
2021
2022 total_service_execution_time += temp_servicestatus->execution_time;
2023 if(have_min_service_execution_time == FALSE || temp_servicestatus->execution_time < min_service_execution_time) {
2024 have_min_service_execution_time = TRUE;
2025 min_service_execution_time = temp_servicestatus->execution_time;
2026 }
2027 if(have_max_service_execution_time == FALSE || temp_servicestatus->execution_time > max_service_execution_time) {
2028 have_max_service_execution_time = TRUE;
2029 max_service_execution_time = temp_servicestatus->execution_time;
2030 }
2031
2032 total_service_percent_change_a += temp_servicestatus->percent_state_change;
2033 if(have_min_service_percent_change_a == FALSE || temp_servicestatus->percent_state_change < min_service_percent_change_a) {
2034 have_min_service_percent_change_a = TRUE;
2035 min_service_percent_change_a = temp_servicestatus->percent_state_change;
2036 }
2037 if(have_max_service_percent_change_a == FALSE || temp_servicestatus->percent_state_change > max_service_percent_change_a) {
2038 have_max_service_percent_change_a = TRUE;
2039 max_service_percent_change_a = temp_servicestatus->percent_state_change;
2040 }
2041
2042 total_service_latency += temp_servicestatus->latency;
2043 if(have_min_service_latency == FALSE || temp_servicestatus->latency < min_service_latency) {
2044 have_min_service_latency = TRUE;
2045 min_service_latency = temp_servicestatus->latency;
2046 }
2047 if(have_max_service_latency == FALSE || temp_servicestatus->latency > max_service_latency) {
2048 have_max_service_latency = TRUE;
2049 max_service_latency = temp_servicestatus->latency;
2050 }
2051
2052 if(temp_servicestatus->last_check >= (current_time - 60))
2053 active_service_checks_1min++;
2054 if(temp_servicestatus->last_check >= (current_time - 300))
2055 active_service_checks_5min++;
2056 if(temp_servicestatus->last_check >= (current_time - 900))
2057 active_service_checks_15min++;
2058 if(temp_servicestatus->last_check >= (current_time - 3600))
2059 active_service_checks_1hour++;
2060 if(temp_servicestatus->last_check >= program_start)
2061 active_service_checks_start++;
2062 if(temp_servicestatus->last_check != (time_t)0)
2063 active_service_checks_ever++;
2064 }
2065
2066 else {
2067 total_passive_service_checks++;
2068
2069 total_service_percent_change_b += temp_servicestatus->percent_state_change;
2070 if(have_min_service_percent_change_b == FALSE || temp_servicestatus->percent_state_change < min_service_percent_change_b) {
2071 have_min_service_percent_change_b = TRUE;
2072 min_service_percent_change_b = temp_servicestatus->percent_state_change;
2073 }
2074 if(have_max_service_percent_change_b == FALSE || temp_servicestatus->percent_state_change > max_service_percent_change_b) {
2075 have_max_service_percent_change_b = TRUE;
2076 max_service_percent_change_b = temp_servicestatus->percent_state_change;
2077 }
2078
2079 if(temp_servicestatus->last_check >= (current_time - 60))
2080 passive_service_checks_1min++;
2081 if(temp_servicestatus->last_check >= (current_time - 300))
2082 passive_service_checks_5min++;
2083 if(temp_servicestatus->last_check >= (current_time - 900))
2084 passive_service_checks_15min++;
2085 if(temp_servicestatus->last_check >= (current_time - 3600))
2086 passive_service_checks_1hour++;
2087 if(temp_servicestatus->last_check >= program_start)
2088 passive_service_checks_start++;
2089 if(temp_servicestatus->last_check != (time_t)0)
2090 passive_service_checks_ever++;
2091 }
2092 }
2093
2094 /* check all hosts */
2095 for(temp_hoststatus = hoststatus_list; temp_hoststatus != NULL; temp_hoststatus = temp_hoststatus->next) {
2096
2097 /* find the host */
2098 temp_host = find_host(temp_hoststatus->host_name);
2099
2100 /* make sure the user has rights to view host information */
2101 if(is_authorized_for_host(temp_host, ¤t_authdata) == FALSE)
2102 continue;
2103
2104 /* is this an active or passive check? */
2105 if(temp_hoststatus->check_type == CHECK_TYPE_ACTIVE) {
2106
2107 total_active_host_checks++;
2108
2109 total_host_execution_time += temp_hoststatus->execution_time;
2110 if(have_min_host_execution_time == FALSE || temp_hoststatus->execution_time < min_host_execution_time) {
2111 have_min_host_execution_time = TRUE;
2112 min_host_execution_time = temp_hoststatus->execution_time;
2113 }
2114 if(have_max_host_execution_time == FALSE || temp_hoststatus->execution_time > max_host_execution_time) {
2115 have_max_host_execution_time = TRUE;
2116 max_host_execution_time = temp_hoststatus->execution_time;
2117 }
2118
2119 total_host_percent_change_a += temp_hoststatus->percent_state_change;
2120 if(have_min_host_percent_change_a == FALSE || temp_hoststatus->percent_state_change < min_host_percent_change_a) {
2121 have_min_host_percent_change_a = TRUE;
2122 min_host_percent_change_a = temp_hoststatus->percent_state_change;
2123 }
2124 if(have_max_host_percent_change_a == FALSE || temp_hoststatus->percent_state_change > max_host_percent_change_a) {
2125 have_max_host_percent_change_a = TRUE;
2126 max_host_percent_change_a = temp_hoststatus->percent_state_change;
2127 }
2128
2129 total_host_latency += temp_hoststatus->latency;
2130 if(have_min_host_latency == FALSE || temp_hoststatus->latency < min_host_latency) {
2131 have_min_host_latency = TRUE;
2132 min_host_latency = temp_hoststatus->latency;
2133 }
2134 if(have_max_host_latency == FALSE || temp_hoststatus->latency > max_host_latency) {
2135 have_max_host_latency = TRUE;
2136 max_host_latency = temp_hoststatus->latency;
2137 }
2138
2139 if(temp_hoststatus->last_check >= (current_time - 60))
2140 active_host_checks_1min++;
2141 if(temp_hoststatus->last_check >= (current_time - 300))
2142 active_host_checks_5min++;
2143 if(temp_hoststatus->last_check >= (current_time - 900))
2144 active_host_checks_15min++;
2145 if(temp_hoststatus->last_check >= (current_time - 3600))
2146 active_host_checks_1hour++;
2147 if(temp_hoststatus->last_check >= program_start)
2148 active_host_checks_start++;
2149 if(temp_hoststatus->last_check != (time_t)0)
2150 active_host_checks_ever++;
2151 }
2152
2153 else {
2154 total_passive_host_checks++;
2155
2156 total_host_percent_change_b += temp_hoststatus->percent_state_change;
2157 if(have_min_host_percent_change_b == FALSE || temp_hoststatus->percent_state_change < min_host_percent_change_b) {
2158 have_min_host_percent_change_b = TRUE;
2159 min_host_percent_change_b = temp_hoststatus->percent_state_change;
2160 }
2161 if(have_max_host_percent_change_b == FALSE || temp_hoststatus->percent_state_change > max_host_percent_change_b) {
2162 have_max_host_percent_change_b = TRUE;
2163 max_host_percent_change_b = temp_hoststatus->percent_state_change;
2164 }
2165
2166 if(temp_hoststatus->last_check >= (current_time - 60))
2167 passive_host_checks_1min++;
2168 if(temp_hoststatus->last_check >= (current_time - 300))
2169 passive_host_checks_5min++;
2170 if(temp_hoststatus->last_check >= (current_time - 900))
2171 passive_host_checks_15min++;
2172 if(temp_hoststatus->last_check >= (current_time - 3600))
2173 passive_host_checks_1hour++;
2174 if(temp_hoststatus->last_check >= program_start)
2175 passive_host_checks_start++;
2176 if(temp_hoststatus->last_check != (time_t)0)
2177 passive_host_checks_ever++;
2178 }
2179 }
2180
2181
2182 printf("<div align=center>\n");
2183
2184
2185 printf("<DIV CLASS='dataTitle'>Program-Wide Performance Information</DIV>\n");
2186
2187 printf("<table border='0' cellpadding='10'>\n");
2188
2189
2190 /***** ACTIVE SERVICE CHECKS *****/
2191
2192 printf("<tr>\n");
2193 printf("<td valign=middle><div class='perfTypeTitle'>Services Actively Checked:</div></td>\n");
2194 printf("<td valign=top>\n");
2195
2196 /* fake this so we don't divide by zero for just showing the table */
2197 if(total_active_service_checks == 0)
2198 total_active_service_checks = 1;
2199
2200 printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
2201 printf("<TR><TD class='stateInfoTable1'>\n");
2202 printf("<TABLE BORDER=0>\n");
2203
2204 printf("<tr class='data'><th class='data'>Time Frame</th><th class='data'>Services Checked</th></tr>\n");
2205 printf("<tr><td class='dataVar'><= 1 minute:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", active_service_checks_1min, (double)(((double)active_service_checks_1min * 100.0) / (double)total_active_service_checks));
2206 printf("<tr><td class='dataVar'><= 5 minutes:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", active_service_checks_5min, (double)(((double)active_service_checks_5min * 100.0) / (double)total_active_service_checks));
2207 printf("<tr><td class='dataVar'><= 15 minutes:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", active_service_checks_15min, (double)(((double)active_service_checks_15min * 100.0) / (double)total_active_service_checks));
2208 printf("<tr><td class='dataVar'><= 1 hour:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", active_service_checks_1hour, (double)(((double)active_service_checks_1hour * 100.0) / (double)total_active_service_checks));
2209 printf("<tr><td class='dataVar'>Since program start: </td><td class='dataVal'>%d (%.1f%%)</td>", active_service_checks_start, (double)(((double)active_service_checks_start * 100.0) / (double)total_active_service_checks));
2210
2211 printf("</TABLE>\n");
2212 printf("</TD></TR>\n");
2213 printf("</TABLE>\n");
2214
2215 printf("</td><td valign=top>\n");
2216
2217 printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
2218 printf("<TR><TD class='stateInfoTable2'>\n");
2219 printf("<TABLE BORDER=0>\n");
2220
2221 printf("<tr class='data'><th class='data'>Metric</th><th class='data'>Min.</th><th class='data'>Max.</th><th class='data'>Average</th></tr>\n");
2222
2223 printf("<tr><td class='dataVar'>Check Execution Time: </td><td class='dataVal'>%.2f sec</td><td class='dataVal'>%.2f sec</td><td class='dataVal'>%.3f sec</td></tr>\n", min_service_execution_time, max_service_execution_time, (double)((double)total_service_execution_time / (double)total_active_service_checks));
2224
2225 printf("<tr><td class='dataVar'>Check Latency:</td><td class='dataVal'>%.2f sec</td><td class='dataVal'>%.2f sec</td><td class='dataVal'>%.3f sec</td></tr>\n", min_service_latency, max_service_latency, (double)((double)total_service_latency / (double)total_active_service_checks));
2226
2227 printf("<tr><td class='dataVar'>Percent State Change:</td><td class='dataVal'>%.2f%%</td><td class='dataVal'>%.2f%%</td><td class='dataVal'>%.2f%%</td></tr>\n", min_service_percent_change_a, max_service_percent_change_a, (double)((double)total_service_percent_change_a / (double)total_active_service_checks));
2228
2229 printf("</TABLE>\n");
2230 printf("</TD></TR>\n");
2231 printf("</TABLE>\n");
2232
2233
2234 printf("</td>\n");
2235 printf("</tr>\n");
2236
2237
2238 /***** PASSIVE SERVICE CHECKS *****/
2239
2240 printf("<tr>\n");
2241 printf("<td valign=middle><div class='perfTypeTitle'>Services Passively Checked:</div></td>\n");
2242 printf("<td valign=top>\n");
2243
2244
2245 /* fake this so we don't divide by zero for just showing the table */
2246 if(total_passive_service_checks == 0)
2247 total_passive_service_checks = 1;
2248
2249 printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
2250 printf("<TR><TD class='stateInfoTable1'>\n");
2251 printf("<TABLE BORDER=0>\n");
2252
2253 printf("<tr class='data'><th class='data'>Time Frame</th><th class='data'>Services Checked</th></tr>\n");
2254 printf("<tr><td class='dataVar'><= 1 minute:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", passive_service_checks_1min, (double)(((double)passive_service_checks_1min * 100.0) / (double)total_passive_service_checks));
2255 printf("<tr><td class='dataVar'><= 5 minutes:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", passive_service_checks_5min, (double)(((double)passive_service_checks_5min * 100.0) / (double)total_passive_service_checks));
2256 printf("<tr><td class='dataVar'><= 15 minutes:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", passive_service_checks_15min, (double)(((double)passive_service_checks_15min * 100.0) / (double)total_passive_service_checks));
2257 printf("<tr><td class='dataVar'><= 1 hour:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", passive_service_checks_1hour, (double)(((double)passive_service_checks_1hour * 100.0) / (double)total_passive_service_checks));
2258 printf("<tr><td class='dataVar'>Since program start: </td><td class='dataVal'>%d (%.1f%%)</td></tr>", passive_service_checks_start, (double)(((double)passive_service_checks_start * 100.0) / (double)total_passive_service_checks));
2259
2260 printf("</TABLE>\n");
2261 printf("</TD></TR>\n");
2262 printf("</TABLE>\n");
2263
2264 printf("</td><td valign=top>\n");
2265
2266 printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
2267 printf("<TR><TD class='stateInfoTable2'>\n");
2268 printf("<TABLE BORDER=0>\n");
2269
2270 printf("<tr class='data'><th class='data'>Metric</th><th class='data'>Min.</th><th class='data'>Max.</th><th class='data'>Average</th></tr>\n");
2271 printf("<tr><td class='dataVar'>Percent State Change: </td><td class='dataVal'>%.2f%%</td><td class='dataVal'>%.2f%%</td><td class='dataVal'>%.2f%%</td></tr>\n", min_service_percent_change_b, max_service_percent_change_b, (double)((double)total_service_percent_change_b / (double)total_passive_service_checks));
2272
2273 printf("</TABLE>\n");
2274 printf("</TD></TR>\n");
2275 printf("</TABLE>\n");
2276
2277 printf("</td>\n");
2278 printf("</tr>\n");
2279
2280
2281 /***** ACTIVE HOST CHECKS *****/
2282
2283 printf("<tr>\n");
2284 printf("<td valign=middle><div class='perfTypeTitle'>Hosts Actively Checked:</div></td>\n");
2285 printf("<td valign=top>\n");
2286
2287 /* fake this so we don't divide by zero for just showing the table */
2288 if(total_active_host_checks == 0)
2289 total_active_host_checks = 1;
2290
2291 printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
2292 printf("<TR><TD class='stateInfoTable1'>\n");
2293 printf("<TABLE BORDER=0>\n");
2294
2295 printf("<tr class='data'><th class='data'>Time Frame</th><th class='data'>Hosts Checked</th></tr>\n");
2296 printf("<tr><td class='dataVar'><= 1 minute:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", active_host_checks_1min, (double)(((double)active_host_checks_1min * 100.0) / (double)total_active_host_checks));
2297 printf("<tr><td class='dataVar'><= 5 minutes:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", active_host_checks_5min, (double)(((double)active_host_checks_5min * 100.0) / (double)total_active_host_checks));
2298 printf("<tr><td class='dataVar'><= 15 minutes:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", active_host_checks_15min, (double)(((double)active_host_checks_15min * 100.0) / (double)total_active_host_checks));
2299 printf("<tr><td class='dataVar'><= 1 hour:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", active_host_checks_1hour, (double)(((double)active_host_checks_1hour * 100.0) / (double)total_active_host_checks));
2300 printf("<tr><td class='dataVar'>Since program start: </td><td class='dataVal'>%d (%.1f%%)</td>", active_host_checks_start, (double)(((double)active_host_checks_start * 100.0) / (double)total_active_host_checks));
2301
2302 printf("</TABLE>\n");
2303 printf("</TD></TR>\n");
2304 printf("</TABLE>\n");
2305
2306 printf("</td><td valign=top>\n");
2307
2308 printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
2309 printf("<TR><TD class='stateInfoTable2'>\n");
2310 printf("<TABLE BORDER=0>\n");
2311
2312 printf("<tr class='data'><th class='data'>Metric</th><th class='data'>Min.</th><th class='data'>Max.</th><th class='data'>Average</th></tr>\n");
2313
2314 printf("<tr><td class='dataVar'>Check Execution Time: </td><td class='dataVal'>%.2f sec</td><td class='dataVal'>%.2f sec</td><td class='dataVal'>%.3f sec</td></tr>\n", min_host_execution_time, max_host_execution_time, (double)((double)total_host_execution_time / (double)total_active_host_checks));
2315
2316 printf("<tr><td class='dataVar'>Check Latency:</td><td class='dataVal'>%.2f sec</td><td class='dataVal'>%.2f sec</td><td class='dataVal'>%.3f sec</td></tr>\n", min_host_latency, max_host_latency, (double)((double)total_host_latency / (double)total_active_host_checks));
2317
2318 printf("<tr><td class='dataVar'>Percent State Change:</td><td class='dataVal'>%.2f%%</td><td class='dataVal'>%.2f%%</td><td class='dataVal'>%.2f%%</td></tr>\n", min_host_percent_change_a, max_host_percent_change_a, (double)((double)total_host_percent_change_a / (double)total_active_host_checks));
2319
2320 printf("</TABLE>\n");
2321 printf("</TD></TR>\n");
2322 printf("</TABLE>\n");
2323
2324
2325 printf("</td>\n");
2326 printf("</tr>\n");
2327
2328
2329 /***** PASSIVE HOST CHECKS *****/
2330
2331 printf("<tr>\n");
2332 printf("<td valign=middle><div class='perfTypeTitle'>Hosts Passively Checked:</div></td>\n");
2333 printf("<td valign=top>\n");
2334
2335
2336 /* fake this so we don't divide by zero for just showing the table */
2337 if(total_passive_host_checks == 0)
2338 total_passive_host_checks = 1;
2339
2340 printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
2341 printf("<TR><TD class='stateInfoTable1'>\n");
2342 printf("<TABLE BORDER=0>\n");
2343
2344 printf("<tr class='data'><th class='data'>Time Frame</th><th class='data'>Hosts Checked</th></tr>\n");
2345 printf("<tr><td class='dataVar'><= 1 minute:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", passive_host_checks_1min, (double)(((double)passive_host_checks_1min * 100.0) / (double)total_passive_host_checks));
2346 printf("<tr><td class='dataVar'><= 5 minutes:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", passive_host_checks_5min, (double)(((double)passive_host_checks_5min * 100.0) / (double)total_passive_host_checks));
2347 printf("<tr><td class='dataVar'><= 15 minutes:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", passive_host_checks_15min, (double)(((double)passive_host_checks_15min * 100.0) / (double)total_passive_host_checks));
2348 printf("<tr><td class='dataVar'><= 1 hour:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", passive_host_checks_1hour, (double)(((double)passive_host_checks_1hour * 100.0) / (double)total_passive_host_checks));
2349 printf("<tr><td class='dataVar'>Since program start: </td><td class='dataVal'>%d (%.1f%%)</td></tr>", passive_host_checks_start, (double)(((double)passive_host_checks_start * 100.0) / (double)total_passive_host_checks));
2350
2351 printf("</TABLE>\n");
2352 printf("</TD></TR>\n");
2353 printf("</TABLE>\n");
2354
2355 printf("</td><td valign=top>\n");
2356
2357 printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
2358 printf("<TR><TD class='stateInfoTable2'>\n");
2359 printf("<TABLE BORDER=0>\n");
2360
2361 printf("<tr class='data'><th class='data'>Metric</th><th class='data'>Min.</th><th class='data'>Max.</th><th class='data'>Average</th></tr>\n");
2362 printf("<tr><td class='dataVar'>Percent State Change: </td><td class='dataVal'>%.2f%%</td><td class='dataVal'>%.2f%%</td><td class='dataVal'>%.2f%%</td></tr>\n", min_host_percent_change_b, max_host_percent_change_b, (double)((double)total_host_percent_change_b / (double)total_passive_host_checks));
2363
2364 printf("</TABLE>\n");
2365 printf("</TD></TR>\n");
2366 printf("</TABLE>\n");
2367
2368 printf("</td>\n");
2369 printf("</tr>\n");
2370
2371
2372
2373 /***** CHECK STATS *****/
2374
2375 printf("<tr>\n");
2376 printf("<td valign=center><div class='perfTypeTitle'>Check Statistics:</div></td>\n");
2377 printf("<td valign=top colspan='2'>\n");
2378
2379
2380 printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
2381 printf("<TR><TD class='stateInfoTable1'>\n");
2382 printf("<TABLE BORDER=0>\n");
2383
2384 printf("<tr class='data'><th class='data'>Type</th><th class='data'>Last 1 Min</th><th class='data'>Last 5 Min</th><th class='data'>Last 15 Min</th></tr>\n");
2385 printf("<tr><td class='dataVar'>Active Scheduled Host Checks</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[ACTIVE_SCHEDULED_HOST_CHECK_STATS][0], program_stats[ACTIVE_SCHEDULED_HOST_CHECK_STATS][1], program_stats[ACTIVE_SCHEDULED_HOST_CHECK_STATS][2]);
2386 printf("<tr><td class='dataVar'>Active On-Demand Host Checks</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[ACTIVE_ONDEMAND_HOST_CHECK_STATS][0], program_stats[ACTIVE_ONDEMAND_HOST_CHECK_STATS][1], program_stats[ACTIVE_ONDEMAND_HOST_CHECK_STATS][2]);
2387 printf("<tr><td class='dataVar'>Parallel Host Checks</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[PARALLEL_HOST_CHECK_STATS][0], program_stats[PARALLEL_HOST_CHECK_STATS][1], program_stats[PARALLEL_HOST_CHECK_STATS][2]);
2388 printf("<tr><td class='dataVar'>Serial Host Checks</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[SERIAL_HOST_CHECK_STATS][0], program_stats[SERIAL_HOST_CHECK_STATS][1], program_stats[SERIAL_HOST_CHECK_STATS][2]);
2389 printf("<tr><td class='dataVar'>Cached Host Checks</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[ACTIVE_CACHED_HOST_CHECK_STATS][0], program_stats[ACTIVE_CACHED_HOST_CHECK_STATS][1], program_stats[ACTIVE_CACHED_HOST_CHECK_STATS][2]);
2390 printf("<tr><td class='dataVar'>Passive Host Checks</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[PASSIVE_HOST_CHECK_STATS][0], program_stats[PASSIVE_HOST_CHECK_STATS][1], program_stats[PASSIVE_HOST_CHECK_STATS][2]);
2391
2392 printf("<tr><td class='dataVar'>Active Scheduled Service Checks</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS][0], program_stats[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS][1], program_stats[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS][2]);
2393 printf("<tr><td class='dataVar'>Active On-Demand Service Checks</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS][0], program_stats[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS][1], program_stats[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS][2]);
2394 printf("<tr><td class='dataVar'>Cached Service Checks</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[ACTIVE_CACHED_SERVICE_CHECK_STATS][0], program_stats[ACTIVE_CACHED_SERVICE_CHECK_STATS][1], program_stats[ACTIVE_CACHED_SERVICE_CHECK_STATS][2]);
2395 printf("<tr><td class='dataVar'>Passive Service Checks</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[PASSIVE_SERVICE_CHECK_STATS][0], program_stats[PASSIVE_SERVICE_CHECK_STATS][1], program_stats[PASSIVE_SERVICE_CHECK_STATS][2]);
2396
2397 printf("<tr><td class='dataVar'>External Commands</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[EXTERNAL_COMMAND_STATS][0], program_stats[EXTERNAL_COMMAND_STATS][1], program_stats[EXTERNAL_COMMAND_STATS][2]);
2398
2399 printf("</TABLE>\n");
2400 printf("</TD></TR>\n");
2401 printf("</TABLE>\n");
2402
2403 printf("</td>\n");
2404 printf("</tr>\n");
2405
2406
2407
2408 /***** BUFFER STATS *****/
2409
2410 printf("<tr>\n");
2411 printf("<td valign=center><div class='perfTypeTitle'>Buffer Usage:</div></td>\n");
2412 printf("<td valign=top colspan='2'>\n");
2413
2414
2415 printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
2416 printf("<TR><TD class='stateInfoTable1'>\n");
2417 printf("<TABLE BORDER=0>\n");
2418
2419 printf("<tr class='data'><th class='data'>Type</th><th class='data'>In Use</th><th class='data'>Max Used</th><th class='data'>Total Available</th></tr>\n");
2420 printf("<tr><td class='dataVar'>External Commands </td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", buffer_stats[0][1], buffer_stats[0][2], buffer_stats[0][0]);
2421
2422 printf("</TABLE>\n");
2423 printf("</TD></TR>\n");
2424 printf("</TABLE>\n");
2425
2426 printf("</td>\n");
2427 printf("</tr>\n");
2428
2429
2430
2431 printf("</table>\n");
2432
2433
2434 printf("</div>\n");
2435
2436 return;
2437 }
2438
2439
2440
display_comments(int type)2441 void display_comments(int type) {
2442 host *temp_host = NULL;
2443 service *temp_service = NULL;
2444 int total_comments = 0;
2445 int display_comment = FALSE;
2446 const char *bg_class = "";
2447 int odd = 1;
2448 char date_time[MAX_DATETIME_LENGTH];
2449 nagios_comment *temp_comment;
2450 scheduled_downtime *temp_downtime;
2451 char *comment_type;
2452 char expire_time[MAX_DATETIME_LENGTH];
2453
2454
2455 /* find the host or service */
2456 if(type == HOST_COMMENT) {
2457 temp_host = find_host(host_name);
2458 if(temp_host == NULL)
2459 return;
2460 }
2461 else {
2462 temp_service = find_service(host_name, service_desc);
2463 if(temp_service == NULL)
2464 return;
2465 }
2466
2467
2468 printf("<A NAME=comments></A>\n");
2469 printf("<DIV CLASS='commentTitle'>%s Comments</DIV>\n", (type == HOST_COMMENT) ? "Host" : "Service");
2470
2471 if(is_authorized_for_read_only(¤t_authdata)==FALSE){
2472 printf("<TABLE BORDER=0>\n");
2473
2474 printf("<tr>\n");
2475 printf("<td valign=middle><img src='%s%s' border=0 align=center></td><td CLASS='comment'>", url_images_path, COMMENT_ICON);
2476 if(type == HOST_COMMENT)
2477 printf("<a href='%s?cmd_typ=%d&host=%s' CLASS='comment'>", COMMAND_CGI, CMD_ADD_HOST_COMMENT, url_encode(host_name));
2478 else {
2479 printf("<a href='%s?cmd_typ=%d&host=%s&", COMMAND_CGI, CMD_ADD_SVC_COMMENT, url_encode(host_name));
2480 printf("service=%s' CLASS='comment'>", url_encode(service_desc));
2481 }
2482 printf("Add a new comment</a></td>\n");
2483
2484 printf("<td valign=middle><img src='%s%s' border=0 align=center></td><td CLASS='comment'>", url_images_path, DELETE_ICON);
2485 if(type == HOST_COMMENT)
2486 printf("<a href='%s?cmd_typ=%d&host=%s' CLASS='comment'>", COMMAND_CGI, CMD_DEL_ALL_HOST_COMMENTS, url_encode(host_name));
2487 else {
2488 printf("<a href='%s?cmd_typ=%d&host=%s&", COMMAND_CGI, CMD_DEL_ALL_SVC_COMMENTS, url_encode(host_name));
2489 printf("service=%s' CLASS='comment'>", url_encode(service_desc));
2490 }
2491 printf("Delete all comments</a></td>\n");
2492 printf("</tr>\n");
2493
2494 printf("</TABLE>\n");
2495 }
2496
2497
2498 printf("<DIV ALIGN=CENTER>\n");
2499 printf("<TABLE BORDER=0 CLASS='comment'>\n");
2500 if(is_authorized_for_read_only(¤t_authdata)==FALSE)
2501 printf("<TR CLASS='comment'><TH CLASS='comment'>Entry Time</TH><TH CLASS='comment'>Author</TH><TH CLASS='comment'>Comment</TH><TH CLASS='comment'>Comment ID</TH><TH CLASS='comment'>Persistent</TH><TH CLASS='comment'>Type</TH><TH CLASS='comment'>Expires</TH><TH CLASS='comment'>Actions</TH></TR>\n");
2502 else
2503 printf("<TR CLASS='comment'><TH CLASS='comment'>Entry Time</TH><TH CLASS='comment'>Author</TH><TH CLASS='comment'>Comment</TH><TH CLASS='comment'>Comment ID</TH><TH CLASS='comment'>Persistent</TH><TH CLASS='comment'>Type</TH><TH CLASS='comment'>Expires</TH></TR>\n");
2504
2505 /* check all the comments to see if they apply to this host or service */
2506 /* Comments are displayed in the order they are read from the status.dat file */
2507 for(temp_comment = get_first_comment_by_host(host_name); temp_comment != NULL; temp_comment = get_next_comment_by_host(host_name, temp_comment)) {
2508
2509 display_comment = FALSE;
2510
2511 if(type == HOST_COMMENT && temp_comment->comment_type == HOST_COMMENT)
2512 display_comment = TRUE;
2513
2514 else if(type == SERVICE_COMMENT && temp_comment->comment_type == SERVICE_COMMENT && !strcmp(temp_comment->service_description, service_desc))
2515 display_comment = TRUE;
2516
2517 if(display_comment == TRUE) {
2518
2519 if(odd) {
2520 odd = 0;
2521 bg_class = "commentOdd";
2522 }
2523 else {
2524 odd = 1;
2525 bg_class = "commentEven";
2526 }
2527
2528 switch(temp_comment->entry_type) {
2529 case USER_COMMENT:
2530 comment_type = "User";
2531 break;
2532 case DOWNTIME_COMMENT:
2533 comment_type = "Scheduled Downtime";
2534 break;
2535 case FLAPPING_COMMENT:
2536 comment_type = "Flap Detection";
2537 break;
2538 case ACKNOWLEDGEMENT_COMMENT:
2539 comment_type = "Acknowledgement";
2540 break;
2541 default:
2542 comment_type = "?";
2543 }
2544
2545 if (temp_comment->entry_type == DOWNTIME_COMMENT) {
2546 for(temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
2547 if (temp_downtime->comment_id == temp_comment->comment_id)
2548 break;
2549 }
2550 }
2551 else
2552 temp_downtime = NULL;
2553
2554 get_time_string(&temp_comment->entry_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2555 get_time_string(&temp_comment->expire_time, expire_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2556 printf("<tr CLASS='%s'>", bg_class);
2557 printf("<td CLASS='%s'>%s</td><td CLASS='%s'>%s</td>", bg_class, date_time, bg_class, temp_comment->author);
2558 printf("<td CLASS='%s'>%s", bg_class, temp_comment->comment_data);
2559 if (temp_downtime)
2560 printf("<hr>%s", temp_downtime->comment);
2561 printf("</td><td CLASS='%s'>%lu</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td>",
2562 bg_class, temp_comment->comment_id, bg_class, (temp_comment->persistent) ? "Yes" : "No",
2563 bg_class, comment_type, bg_class, (temp_comment->expires == TRUE) ? expire_time : "N/A");
2564 if(is_authorized_for_read_only(¤t_authdata)==FALSE)
2565 printf("<td><a href='%s?cmd_typ=%d&com_id=%lu'><img src='%s%s' border=0 ALT='Delete This Comment' TITLE='Delete This Comment'></td>", COMMAND_CGI, (type == HOST_COMMENT) ? CMD_DEL_HOST_COMMENT : CMD_DEL_SVC_COMMENT, temp_comment->comment_id, url_images_path, DELETE_ICON);
2566 printf("</tr>\n");
2567
2568 total_comments++;
2569
2570 }
2571 }
2572
2573 /* see if this host or service has any comments associated with it */
2574 if(total_comments == 0)
2575 printf("<TR CLASS='commentOdd'><TD CLASS='commentOdd' COLSPAN='%d'>This %s has no comments associated with it</TD></TR>", (type == HOST_COMMENT) ? 9 : 10, (type == HOST_COMMENT) ? "host" : "service");
2576
2577 printf("</TABLE></DIV>\n");
2578
2579 return;
2580 }
2581
2582
2583
2584
2585 /* shows all service and host scheduled downtime */
show_all_downtime(void)2586 void show_all_downtime(void) {
2587 int total_downtime = 0;
2588 const char *bg_class = "";
2589 int odd = 0;
2590 char date_time[MAX_DATETIME_LENGTH];
2591 scheduled_downtime *temp_downtime;
2592 host *temp_host;
2593 service *temp_service;
2594 int days;
2595 int hours;
2596 int minutes;
2597 int seconds;
2598
2599
2600 printf("<BR />\n");
2601 printf("<DIV CLASS='downtimeNav'>[ <A HREF='#HOSTDOWNTIME' CLASS='downtimeNav'>Host Downtime</A> | <A HREF='#SERVICEDOWNTIME' CLASS='downtimeNav'>Service Downtime</A> ]</DIV>\n");
2602 printf("<BR />\n");
2603
2604 printf("<A NAME=HOSTDOWNTIME></A>\n");
2605 printf("<DIV CLASS='downtimeTitle'>Scheduled Host Downtime</DIV>\n");
2606
2607 printf("<div CLASS='comment'><img src='%s%s' border=0> ", url_images_path, DOWNTIME_ICON);
2608 printf("<a href='%s?cmd_typ=%d'>", COMMAND_CGI, CMD_SCHEDULE_HOST_DOWNTIME);
2609 printf("Schedule host downtime</a></div>\n");
2610
2611 printf("<BR />\n");
2612 printf("<DIV ALIGN=CENTER>\n");
2613 printf("<TABLE BORDER=0 CLASS='downtime'>\n");
2614 printf("<TR CLASS='downtime'><TH CLASS='downtime'>Host Name</TH><TH CLASS='downtime'>Entry Time</TH><TH CLASS='downtime'>Author</TH><TH CLASS='downtime'>Comment</TH><TH CLASS='downtime'>Start Time</TH><TH CLASS='downtime'>End Time</TH><TH CLASS='downtime'>Type</TH><TH CLASS='downtime'>Duration</TH><TH CLASS='downtime'>Downtime ID</TH><TH CLASS='downtime'>Trigger ID</TH><TH CLASS='downtime'>Actions</TH></TR>\n");
2615
2616 /* display all the host downtime */
2617 for(temp_downtime = scheduled_downtime_list, total_downtime = 0; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
2618
2619 if(temp_downtime->type != HOST_DOWNTIME)
2620 continue;
2621
2622 temp_host = find_host(temp_downtime->host_name);
2623
2624 /* make sure the user has rights to view host information */
2625 if(is_authorized_for_host(temp_host, ¤t_authdata) == FALSE)
2626 continue;
2627
2628 total_downtime++;
2629
2630 if(odd) {
2631 odd = 0;
2632 bg_class = "downtimeOdd";
2633 }
2634 else {
2635 odd = 1;
2636 bg_class = "downtimeEven";
2637 }
2638
2639 printf("<tr CLASS='%s'>", bg_class);
2640 printf("<td CLASS='%s'><A HREF='%s?type=%d&host=%s'>%s</A></td>", bg_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_downtime->host_name), temp_downtime->host_name);
2641 get_time_string(&temp_downtime->entry_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2642 printf("<td CLASS='%s'>%s</td>", bg_class, date_time);
2643 printf("<td CLASS='%s'>%s</td>", bg_class, (temp_downtime->author == NULL) ? "N/A" : temp_downtime->author);
2644 printf("<td CLASS='%s'>%s</td>", bg_class, (temp_downtime->comment == NULL) ? "N/A" : temp_downtime->comment);
2645 get_time_string(&temp_downtime->start_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2646 printf("<td CLASS='%s'>%s</td>", bg_class, date_time);
2647 get_time_string(&temp_downtime->end_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2648 printf("<td CLASS='%s'>%s</td>", bg_class, date_time);
2649 printf("<td CLASS='%s'>%s</td>", bg_class, (temp_downtime->fixed == TRUE) ? "Fixed" : "Flexible");
2650 get_time_breakdown(temp_downtime->duration, &days, &hours, &minutes, &seconds);
2651 printf("<td CLASS='%s'>%dd %dh %dm %ds</td>", bg_class, days, hours, minutes, seconds);
2652 printf("<td CLASS='%s'>%lu</td>", bg_class, temp_downtime->downtime_id);
2653 printf("<td CLASS='%s'>", bg_class);
2654 if(temp_downtime->triggered_by == 0)
2655 printf("N/A");
2656 else
2657 printf("%lu", temp_downtime->triggered_by);
2658 printf("</td>\n");
2659 printf("<td><a href='%s?cmd_typ=%d&down_id=%lu'><img src='%s%s' border=0 ALT='Delete/Cancel This Scheduled Downtime Entry' TITLE='Delete/Cancel This Scheduled Downtime Entry'></td>", COMMAND_CGI, CMD_DEL_HOST_DOWNTIME, temp_downtime->downtime_id, url_images_path, DELETE_ICON);
2660 printf("</tr>\n");
2661 }
2662
2663 if(total_downtime == 0)
2664 printf("<TR CLASS='downtimeOdd'><TD CLASS='downtimeOdd' COLSPAN=11>There are no hosts with scheduled downtime</TD></TR>");
2665
2666 printf("</TABLE>\n");
2667 printf("</DIV>\n");
2668
2669 printf("<BR /><BR /><BR />\n");
2670
2671
2672 printf("<A NAME=SERVICEDOWNTIME></A>\n");
2673 printf("<DIV CLASS='downtimeTitle'>Scheduled Service Downtime</DIV>\n");
2674
2675 printf("<div CLASS='comment'><img src='%s%s' border=0> ", url_images_path, DOWNTIME_ICON);
2676 printf("<a href='%s?cmd_typ=%d'>", COMMAND_CGI, CMD_SCHEDULE_SVC_DOWNTIME);
2677 printf("Schedule service downtime</a></div>\n");
2678
2679 printf("<BR />\n");
2680 printf("<DIV ALIGN=CENTER>\n");
2681 printf("<TABLE BORDER=0 CLASS='downtime'>\n");
2682 printf("<TR CLASS='downtime'><TH CLASS='downtime'>Host Name</TH><TH CLASS='downtime'>Service</TH><TH CLASS='downtime'>Entry Time</TH><TH CLASS='downtime'>Author</TH><TH CLASS='downtime'>Comment</TH><TH CLASS='downtime'>Start Time</TH><TH CLASS='downtime'>End Time</TH><TH CLASS='downtime'>Type</TH><TH CLASS='downtime'>Duration</TH><TH CLASS='downtime'>Downtime ID</TH><TH CLASS='downtime'>Trigger ID</TH><TH CLASS='downtime'>Actions</TH></TR>\n");
2683
2684 /* display all the service downtime */
2685 for(temp_downtime = scheduled_downtime_list, total_downtime = 0; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
2686
2687 if(temp_downtime->type != SERVICE_DOWNTIME)
2688 continue;
2689
2690 temp_service = find_service(temp_downtime->host_name, temp_downtime->service_description);
2691
2692 /* make sure the user has rights to view service information */
2693 if(is_authorized_for_service(temp_service, ¤t_authdata) == FALSE)
2694 continue;
2695
2696 total_downtime++;
2697
2698 if(odd) {
2699 odd = 0;
2700 bg_class = "downtimeOdd";
2701 }
2702 else {
2703 odd = 1;
2704 bg_class = "downtimeEven";
2705 }
2706
2707 printf("<tr CLASS='%s'>", bg_class);
2708 printf("<td CLASS='%s'><A HREF='%s?type=%d&host=%s'>%s</A></td>", bg_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_downtime->host_name), temp_downtime->host_name);
2709 printf("<td CLASS='%s'><A HREF='%s?type=%d&host=%s", bg_class, EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(temp_downtime->host_name));
2710 printf("&service=%s'>%s</A></td>", url_encode(temp_downtime->service_description), temp_downtime->service_description);
2711 get_time_string(&temp_downtime->entry_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2712 printf("<td CLASS='%s'>%s</td>", bg_class, date_time);
2713 printf("<td CLASS='%s'>%s</td>", bg_class, (temp_downtime->author == NULL) ? "N/A" : temp_downtime->author);
2714 printf("<td CLASS='%s'>%s</td>", bg_class, (temp_downtime->comment == NULL) ? "N/A" : temp_downtime->comment);
2715 get_time_string(&temp_downtime->start_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2716 printf("<td CLASS='%s'>%s</td>", bg_class, date_time);
2717 get_time_string(&temp_downtime->end_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2718 printf("<td CLASS='%s'>%s</td>", bg_class, date_time);
2719 printf("<td CLASS='%s'>%s</td>", bg_class, (temp_downtime->fixed == TRUE) ? "Fixed" : "Flexible");
2720 get_time_breakdown(temp_downtime->duration, &days, &hours, &minutes, &seconds);
2721 printf("<td CLASS='%s'>%dd %dh %dm %ds</td>", bg_class, days, hours, minutes, seconds);
2722 printf("<td CLASS='%s'>%lu</td>", bg_class, temp_downtime->downtime_id);
2723 printf("<td CLASS='%s'>", bg_class);
2724 if(temp_downtime->triggered_by == 0)
2725 printf("N/A");
2726 else
2727 printf("%lu", temp_downtime->triggered_by);
2728 printf("</td>\n");
2729 printf("<td><a href='%s?cmd_typ=%d&down_id=%lu'><img src='%s%s' border=0 ALT='Delete/Cancel This Scheduled Downtime Entry' TITLE='Delete/Cancel This Scheduled Downtime Entry'></td>", COMMAND_CGI, CMD_DEL_SVC_DOWNTIME, temp_downtime->downtime_id, url_images_path, DELETE_ICON);
2730 printf("</tr>\n");
2731 }
2732
2733 if(total_downtime == 0)
2734 printf("<TR CLASS='downtimeOdd'><TD CLASS='downtimeOdd' COLSPAN=12>There are no services with scheduled downtime</TD></TR>");
2735
2736 printf("</TABLE>\n");
2737 printf("</DIV>\n");
2738
2739 return;
2740 }
2741
2742
2743
2744 /* shows check scheduling queue */
show_scheduling_queue(void)2745 void show_scheduling_queue(void) {
2746 sortdata *temp_sortdata;
2747 servicestatus *temp_svcstatus = NULL;
2748 hoststatus *temp_hststatus = NULL;
2749 char date_time[MAX_DATETIME_LENGTH];
2750 char temp_url[MAX_INPUT_BUFFER];
2751 int odd = 0;
2752 const char *bgclass = "";
2753
2754
2755 /* make sure the user has rights to view system information */
2756 if(is_authorized_for_system_information(¤t_authdata) == FALSE) {
2757
2758 printf("<P><DIV CLASS='errorMessage'>It appears as though you do not have permission to view process information...</DIV></P>\n");
2759 printf("<P><DIV CLASS='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
2760 printf("and check the authorization options in your CGI configuration file.</DIV></P>\n");
2761
2762 return;
2763 }
2764
2765 /* sort hosts and services */
2766 sort_data(sort_type, sort_option);
2767
2768 printf("<DIV ALIGN=CENTER CLASS='statusSort'>Entries sorted by <b>");
2769 if(sort_option == SORT_HOSTNAME)
2770 printf("host name");
2771 else if(sort_option == SORT_SERVICENAME)
2772 printf("service name");
2773 else if(sort_option == SORT_SERVICESTATUS)
2774 printf("service status");
2775 else if(sort_option == SORT_LASTCHECKTIME)
2776 printf("last check time");
2777 else if(sort_option == SORT_NEXTCHECKTIME)
2778 printf("next check time");
2779 printf("</b> (%s)\n", (sort_type == SORT_ASCENDING) ? "ascending" : "descending");
2780 printf("</DIV>\n");
2781
2782 printf("<P>\n");
2783 printf("<DIV ALIGN=CENTER>\n");
2784 printf("<TABLE BORDER=0 CLASS='queue'>\n");
2785 printf("<TR CLASS='queue'>");
2786
2787 snprintf(temp_url, sizeof(temp_url) - 1, "%s?type=%d", EXTINFO_CGI, DISPLAY_SCHEDULING_QUEUE);
2788 temp_url[sizeof(temp_url) - 1] = '\x0';
2789
2790 printf("<TH CLASS='queue'>Host <A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by host name (ascending)' TITLE='Sort by host name (ascending)'></A><A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by host name (descending)' TITLE='Sort by host name (descending)'></A></TH>", temp_url, SORT_ASCENDING, SORT_HOSTNAME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_HOSTNAME, url_images_path, DOWN_ARROW_ICON);
2791
2792 printf("<TH CLASS='queue'>Service <A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by service name (ascending)' TITLE='Sort by service name (ascending)'></A><A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by service name (descending)' TITLE='Sort by service name (descending)'></A></TH>", temp_url, SORT_ASCENDING, SORT_SERVICENAME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_SERVICENAME, url_images_path, DOWN_ARROW_ICON);
2793
2794 printf("<TH CLASS='queue'>Last Check <A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by last check time (ascending)' TITLE='Sort by last check time (ascending)'></A><A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by last check time (descending)' TITLE='Sort by last check time (descending)'></A></TH>", temp_url, SORT_ASCENDING, SORT_LASTCHECKTIME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_LASTCHECKTIME, url_images_path, DOWN_ARROW_ICON);
2795
2796 printf("<TH CLASS='queue'>Next Check <A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by next check time (ascending)' TITLE='Sort by next check time (ascending)'></A><A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by next check time (descending)' TITLE='Sort by next check time (descending)'></A></TH>", temp_url, SORT_ASCENDING, SORT_NEXTCHECKTIME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_NEXTCHECKTIME, url_images_path, DOWN_ARROW_ICON);
2797
2798
2799 printf("<TH CLASS='queue'>Type</TH><TH CLASS='queue'>Active Checks</TH><TH CLASS='queue'>Actions</TH></TR>\n");
2800
2801
2802 /* display all services and hosts */
2803 for(temp_sortdata = sortdata_list; temp_sortdata != NULL; temp_sortdata = temp_sortdata->next) {
2804
2805 /* skip hosts and services that shouldn't be scheduled */
2806 if(temp_sortdata->is_service == TRUE) {
2807 temp_svcstatus = temp_sortdata->svcstatus;
2808 if(temp_svcstatus->should_be_scheduled == FALSE) {
2809 /* passive-only checks should appear if they're being forced */
2810 if(!(temp_svcstatus->checks_enabled == FALSE && temp_svcstatus->next_check != (time_t)0L && (temp_svcstatus->check_options & CHECK_OPTION_FORCE_EXECUTION)))
2811 continue;
2812 }
2813 }
2814 else {
2815 temp_hststatus = temp_sortdata->hststatus;
2816 if(temp_hststatus->should_be_scheduled == FALSE) {
2817 /* passive-only checks should appear if they're being forced */
2818 if(!(temp_hststatus->checks_enabled == FALSE && temp_hststatus->next_check != (time_t)0L && (temp_hststatus->check_options & CHECK_OPTION_FORCE_EXECUTION)))
2819 continue;
2820 }
2821 }
2822
2823 if(odd) {
2824 odd = 0;
2825 bgclass = "Even";
2826 }
2827 else {
2828 odd = 1;
2829 bgclass = "Odd";
2830 }
2831
2832 printf("<TR CLASS='queue%s'>", bgclass);
2833
2834 /* get the service status */
2835 if(temp_sortdata->is_service == TRUE) {
2836
2837 printf("<TD CLASS='queue%s'><A HREF='%s?type=%d&host=%s'>%s</A></TD>", bgclass, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_svcstatus->host_name), temp_svcstatus->host_name);
2838
2839 printf("<TD CLASS='queue%s'><A HREF='%s?type=%d&host=%s", bgclass, EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(temp_svcstatus->host_name));
2840 printf("&service=%s'>%s</A></TD>", url_encode(temp_svcstatus->description), temp_svcstatus->description);
2841
2842 get_time_string(&temp_svcstatus->last_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2843 printf("<TD CLASS='queue%s'>%s</TD>", bgclass, (temp_svcstatus->last_check == (time_t)0) ? "N/A" : date_time);
2844
2845 get_time_string(&temp_svcstatus->next_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2846 printf("<TD CLASS='queue%s'>%s</TD>", bgclass, (temp_svcstatus->next_check == (time_t)0) ? "N/A" : date_time);
2847
2848 printf("<TD CLASS='queue%s'>", bgclass);
2849 if(temp_svcstatus->check_options == CHECK_OPTION_NONE)
2850 printf("Normal ");
2851 else {
2852 if(temp_svcstatus->check_options & CHECK_OPTION_FORCE_EXECUTION)
2853 printf("Forced ");
2854 if(temp_svcstatus->check_options & CHECK_OPTION_FRESHNESS_CHECK)
2855 printf("Freshness ");
2856 if(temp_svcstatus->check_options & CHECK_OPTION_ORPHAN_CHECK)
2857 printf("Orphan ");
2858 }
2859 printf("</TD>");
2860
2861 printf("<TD CLASS='queue%s'>%s</TD>", (temp_svcstatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED", (temp_svcstatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED");
2862
2863 printf("<TD CLASS='queue%s'>", bgclass);
2864 if(temp_svcstatus->checks_enabled == TRUE) {
2865 printf("<a href='%s?cmd_typ=%d&host=%s", COMMAND_CGI, CMD_DISABLE_SVC_CHECK, url_encode(temp_svcstatus->host_name));
2866 printf("&service=%s'><img src='%s%s' border=0 ALT='Disable Active Checks Of This Service' TITLE='Disable Active Checks Of This Service'></a>\n", url_encode(temp_svcstatus->description), url_images_path, DISABLED_ICON);
2867 }
2868 else {
2869 printf("<a href='%s?cmd_typ=%d&host=%s", COMMAND_CGI, CMD_ENABLE_SVC_CHECK, url_encode(temp_svcstatus->host_name));
2870 printf("&service=%s'><img src='%s%s' border=0 ALT='Enable Active Checks Of This Service' TITLE='Enable Active Checks Of This Service'></a>\n", url_encode(temp_svcstatus->description), url_images_path, ENABLED_ICON);
2871 }
2872 printf("<a href='%s?cmd_typ=%d&host=%s", COMMAND_CGI, CMD_SCHEDULE_SVC_CHECK, url_encode(temp_svcstatus->host_name));
2873 printf("&service=%s%s'><img src='%s%s' border=0 ALT='Re-schedule This Service Check' TITLE='Re-schedule This Service Check'></a>\n", url_encode(temp_svcstatus->description), (temp_svcstatus->checks_enabled == TRUE) ? "&force_check" : "", url_images_path, DELAY_ICON);
2874 printf("</TD>\n");
2875 }
2876
2877 /* get the host status */
2878 else {
2879
2880 printf("<TD CLASS='queue%s'><A HREF='%s?type=%d&host=%s'>%s</A></TD>", bgclass, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_hststatus->host_name), temp_hststatus->host_name);
2881
2882 printf("<TD CLASS='queue%s'> </TD>", bgclass);
2883
2884 get_time_string(&temp_hststatus->last_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2885 printf("<TD CLASS='queue%s'>%s</TD>", bgclass, (temp_hststatus->last_check == (time_t)0) ? "N/A" : date_time);
2886
2887 get_time_string(&temp_hststatus->next_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2888 printf("<TD CLASS='queue%s'>%s</TD>", bgclass, (temp_hststatus->next_check == (time_t)0) ? "N/A" : date_time);
2889
2890 printf("<TD CLASS='queue%s'>", bgclass);
2891 if(temp_hststatus->check_options == CHECK_OPTION_NONE)
2892 printf("Normal ");
2893 else {
2894 if(temp_hststatus->check_options & CHECK_OPTION_FORCE_EXECUTION)
2895 printf("Forced ");
2896 if(temp_hststatus->check_options & CHECK_OPTION_FRESHNESS_CHECK)
2897 printf("Freshness ");
2898 if(temp_hststatus->check_options & CHECK_OPTION_ORPHAN_CHECK)
2899 printf("Orphan ");
2900 }
2901 printf("</TD>");
2902
2903 printf("<TD CLASS='queue%s'>%s</TD>", (temp_hststatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED", (temp_hststatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED");
2904
2905 printf("<TD CLASS='queue%s'>", bgclass);
2906 if(temp_hststatus->checks_enabled == TRUE) {
2907 printf("<a href='%s?cmd_typ=%d&host=%s", COMMAND_CGI, CMD_DISABLE_HOST_CHECK, url_encode(temp_hststatus->host_name));
2908 printf("'><img src='%s%s' border=0 ALT='Disable Active Checks Of This Host' TITLE='Disable Active Checks Of This Host'></a>\n", url_images_path, DISABLED_ICON);
2909 }
2910 else {
2911 printf("<a href='%s?cmd_typ=%d&host=%s", COMMAND_CGI, CMD_ENABLE_HOST_CHECK, url_encode(temp_hststatus->host_name));
2912 printf("'><img src='%s%s' border=0 ALT='Enable Active Checks Of This Host' TITLE='Enable Active Checks Of This Host'></a>\n", url_images_path, ENABLED_ICON);
2913 }
2914 printf("<a href='%s?cmd_typ=%d&host=%s%s", COMMAND_CGI, CMD_SCHEDULE_HOST_CHECK, url_encode(temp_hststatus->host_name), (temp_hststatus->checks_enabled == TRUE) ? "&force_check" : "");
2915 printf("'><img src='%s%s' border=0 ALT='Re-schedule This Host Check' TITLE='Re-schedule This Host Check'></a>\n", url_images_path, DELAY_ICON);
2916 printf("</TD>\n");
2917 }
2918
2919 printf("</TR>\n");
2920
2921 }
2922
2923 printf("</TABLE>\n");
2924 printf("</DIV>\n");
2925 printf("</P>\n");
2926
2927
2928 /* free memory allocated to sorted data list */
2929 free_sortdata_list();
2930
2931 return;
2932 }
2933
2934
2935
2936 /* sorts host and service data */
sort_data(int s_type,int s_option)2937 int sort_data(int s_type, int s_option) {
2938 sortdata *new_sortdata;
2939 sortdata *last_sortdata;
2940 sortdata *temp_sortdata;
2941 servicestatus *temp_svcstatus;
2942 hoststatus *temp_hststatus;
2943
2944 if(s_type == SORT_NONE)
2945 return ERROR;
2946
2947 /* sort all service status entries */
2948 for(temp_svcstatus = servicestatus_list; temp_svcstatus != NULL; temp_svcstatus = temp_svcstatus->next) {
2949
2950 /* allocate memory for a new sort structure */
2951 new_sortdata = (sortdata *)malloc(sizeof(sortdata));
2952 if(new_sortdata == NULL)
2953 return ERROR;
2954
2955 new_sortdata->is_service = TRUE;
2956 new_sortdata->svcstatus = temp_svcstatus;
2957 new_sortdata->hststatus = NULL;
2958
2959 last_sortdata = sortdata_list;
2960 for(temp_sortdata = sortdata_list; temp_sortdata != NULL; temp_sortdata = temp_sortdata->next) {
2961
2962 if(compare_sortdata_entries(s_type, s_option, new_sortdata, temp_sortdata) == TRUE) {
2963 new_sortdata->next = temp_sortdata;
2964 if(temp_sortdata == sortdata_list)
2965 sortdata_list = new_sortdata;
2966 else
2967 last_sortdata->next = new_sortdata;
2968 break;
2969 }
2970 else
2971 last_sortdata = temp_sortdata;
2972 }
2973
2974 if(sortdata_list == NULL) {
2975 new_sortdata->next = NULL;
2976 sortdata_list = new_sortdata;
2977 }
2978 else if(temp_sortdata == NULL) {
2979 new_sortdata->next = NULL;
2980 last_sortdata->next = new_sortdata;
2981 }
2982 }
2983
2984 /* sort all host status entries */
2985 for(temp_hststatus = hoststatus_list; temp_hststatus != NULL; temp_hststatus = temp_hststatus->next) {
2986
2987 /* allocate memory for a new sort structure */
2988 new_sortdata = (sortdata *)malloc(sizeof(sortdata));
2989 if(new_sortdata == NULL)
2990 return ERROR;
2991
2992 new_sortdata->is_service = FALSE;
2993 new_sortdata->svcstatus = NULL;
2994 new_sortdata->hststatus = temp_hststatus;
2995
2996 last_sortdata = sortdata_list;
2997 for(temp_sortdata = sortdata_list; temp_sortdata != NULL; temp_sortdata = temp_sortdata->next) {
2998
2999 if(compare_sortdata_entries(s_type, s_option, new_sortdata, temp_sortdata) == TRUE) {
3000 new_sortdata->next = temp_sortdata;
3001 if(temp_sortdata == sortdata_list)
3002 sortdata_list = new_sortdata;
3003 else
3004 last_sortdata->next = new_sortdata;
3005 break;
3006 }
3007 else
3008 last_sortdata = temp_sortdata;
3009 }
3010
3011 if(sortdata_list == NULL) {
3012 new_sortdata->next = NULL;
3013 sortdata_list = new_sortdata;
3014 }
3015 else if(temp_sortdata == NULL) {
3016 new_sortdata->next = NULL;
3017 last_sortdata->next = new_sortdata;
3018 }
3019 }
3020
3021 return OK;
3022 }
3023
3024
compare_sortdata_entries(int s_type,int s_option,sortdata * new_sortdata,sortdata * temp_sortdata)3025 int compare_sortdata_entries(int s_type, int s_option, sortdata *new_sortdata, sortdata *temp_sortdata) {
3026 hoststatus *temp_hststatus = NULL;
3027 servicestatus *temp_svcstatus = NULL;
3028 time_t last_check[2];
3029 time_t next_check[2];
3030 int current_attempt[2];
3031 int status[2];
3032 char *hname[2];
3033 char *service_description[2];
3034
3035 if(new_sortdata->is_service == TRUE) {
3036 temp_svcstatus = new_sortdata->svcstatus;
3037 last_check[0] = temp_svcstatus->last_check;
3038 next_check[0] = temp_svcstatus->next_check;
3039 status[0] = temp_svcstatus->status;
3040 hname[0] = temp_svcstatus->host_name;
3041 service_description[0] = temp_svcstatus->description;
3042 current_attempt[0] = temp_svcstatus->current_attempt;
3043 }
3044 else {
3045 temp_hststatus = new_sortdata->hststatus;
3046 last_check[0] = temp_hststatus->last_check;
3047 next_check[0] = temp_hststatus->next_check;
3048 status[0] = temp_hststatus->status;
3049 hname[0] = temp_hststatus->host_name;
3050 service_description[0] = "";
3051 current_attempt[0] = temp_hststatus->current_attempt;
3052 }
3053 if(temp_sortdata->is_service == TRUE) {
3054 temp_svcstatus = temp_sortdata->svcstatus;
3055 last_check[1] = temp_svcstatus->last_check;
3056 next_check[1] = temp_svcstatus->next_check;
3057 status[1] = temp_svcstatus->status;
3058 hname[1] = temp_svcstatus->host_name;
3059 service_description[1] = temp_svcstatus->description;
3060 current_attempt[1] = temp_svcstatus->current_attempt;
3061 }
3062 else {
3063 temp_hststatus = temp_sortdata->hststatus;
3064 last_check[1] = temp_hststatus->last_check;
3065 next_check[1] = temp_hststatus->next_check;
3066 status[1] = temp_hststatus->status;
3067 hname[1] = temp_hststatus->host_name;
3068 service_description[1] = "";
3069 current_attempt[1] = temp_hststatus->current_attempt;
3070 }
3071
3072 if(s_type == SORT_ASCENDING) {
3073
3074 if(s_option == SORT_LASTCHECKTIME) {
3075 if(last_check[0] <= last_check[1])
3076 return TRUE;
3077 else
3078 return FALSE;
3079 }
3080 if(s_option == SORT_NEXTCHECKTIME) {
3081 if(next_check[0] <= next_check[1])
3082 return TRUE;
3083 else
3084 return FALSE;
3085 }
3086 else if(s_option == SORT_CURRENTATTEMPT) {
3087 if(current_attempt[0] <= current_attempt[1])
3088 return TRUE;
3089 else
3090 return FALSE;
3091 }
3092 else if(s_option == SORT_SERVICESTATUS) {
3093 if(status[0] <= status[1])
3094 return TRUE;
3095 else
3096 return FALSE;
3097 }
3098 else if(s_option == SORT_HOSTNAME) {
3099 if(strcasecmp(hname[0], hname[1]) < 0)
3100 return TRUE;
3101 else
3102 return FALSE;
3103 }
3104 else if(s_option == SORT_SERVICENAME) {
3105 if(strcasecmp(service_description[0], service_description[1]) < 0)
3106 return TRUE;
3107 else
3108 return FALSE;
3109 }
3110 }
3111 else {
3112 if(s_option == SORT_LASTCHECKTIME) {
3113 if(last_check[0] > last_check[1])
3114 return TRUE;
3115 else
3116 return FALSE;
3117 }
3118 if(s_option == SORT_NEXTCHECKTIME) {
3119 if(next_check[0] > next_check[1])
3120 return TRUE;
3121 else
3122 return FALSE;
3123 }
3124 else if(s_option == SORT_CURRENTATTEMPT) {
3125 if(current_attempt[0] > current_attempt[1])
3126 return TRUE;
3127 else
3128 return FALSE;
3129 }
3130 else if(s_option == SORT_SERVICESTATUS) {
3131 if(status[0] > status[1])
3132 return TRUE;
3133 else
3134 return FALSE;
3135 }
3136 else if(s_option == SORT_HOSTNAME) {
3137 if(strcasecmp(hname[0], hname[1]) > 0)
3138 return TRUE;
3139 else
3140 return FALSE;
3141 }
3142 else if(s_option == SORT_SERVICENAME) {
3143 if(strcasecmp(service_description[0], service_description[1]) > 0)
3144 return TRUE;
3145 else
3146 return FALSE;
3147 }
3148 }
3149
3150 return TRUE;
3151 }
3152
3153
3154
3155 /* free all memory allocated to the sortdata structures */
free_sortdata_list(void)3156 void free_sortdata_list(void) {
3157 sortdata *this_sortdata;
3158 sortdata *next_sortdata;
3159
3160 /* free memory for the sortdata list */
3161 for(this_sortdata = sortdata_list; this_sortdata != NULL; this_sortdata = next_sortdata) {
3162 next_sortdata = this_sortdata->next;
3163 free(this_sortdata);
3164 }
3165
3166 return;
3167 }
3168