1 /**************************************************************************
2 *
3 * STATUS.C - Nagios Status CGI
4 *
5 * Copyright (c) 1999-2010 Ethan Galstad (egalstad@nagios.org)
6 * Last Modified: 08-05-2020
7 *
8 * License:
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Tthis program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *************************************************************************/
23
24 #include "../include/config.h"
25 #include "../include/common.h"
26 #include "../include/objects.h"
27 #include "../include/comments.h"
28 #include "../include/macros.h"
29 #include "../include/statusdata.h"
30
31 #include "../include/cgiutils.h"
32 #include "../include/getcgi.h"
33 #include "../include/cgiauth.h"
34
35 extern int refresh_rate;
36 extern int result_limit;
37 extern time_t program_start;
38
39 extern char main_config_file[MAX_FILENAME_LENGTH];
40 extern char url_html_path[MAX_FILENAME_LENGTH];
41 extern char url_docs_path[MAX_FILENAME_LENGTH];
42 extern char url_images_path[MAX_FILENAME_LENGTH];
43 extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
44 extern char url_logo_images_path[MAX_FILENAME_LENGTH];
45 extern char url_media_path[MAX_FILENAME_LENGTH];
46 extern char url_js_path[MAX_FILENAME_LENGTH];
47 extern char log_file[MAX_FILENAME_LENGTH];
48
49 extern char *service_critical_sound;
50 extern char *service_warning_sound;
51 extern char *service_unknown_sound;
52 extern char *host_down_sound;
53 extern char *host_unreachable_sound;
54 extern char *normal_sound;
55
56 extern char *notes_url_target;
57 extern char *action_url_target;
58
59 extern int suppress_alert_window;
60
61 extern int enable_splunk_integration;
62
63 extern host *host_list;
64 extern service *service_list;
65 extern hostgroup *hostgroup_list;
66 extern servicegroup *servicegroup_list;
67 extern hoststatus *hoststatus_list;
68 extern servicestatus *servicestatus_list;
69
70 static nagios_macros *mac;
71
72 #define MAX_MESSAGE_BUFFER 4096
73
74 #define DISPLAY_HOSTS 0
75 #define DISPLAY_HOSTGROUPS 1
76 #define DISPLAY_SERVICEGROUPS 2
77
78 #define STYLE_OVERVIEW 0
79 #define STYLE_DETAIL 1
80 #define STYLE_SUMMARY 2
81 #define STYLE_GRID 3
82 #define STYLE_HOST_DETAIL 4
83
84
85 /* HOSTSORT structure */
86 typedef struct hostsort_struct {
87 hoststatus *hststatus;
88 struct hostsort_struct *next;
89 } hostsort;
90
91 /* SERVICESORT structure */
92 typedef struct servicesort_struct {
93 servicestatus *svcstatus;
94 struct servicesort_struct *next;
95 } servicesort;
96
97 hostsort *hostsort_list = NULL;
98 servicesort *servicesort_list = NULL;
99
100 int sort_services(int, int); /* sorts services */
101 int sort_hosts(int, int); /* sorts hosts */
102 int compare_servicesort_entries(int, int, servicesort *, servicesort *); /* compares service sort entries */
103 int compare_hostsort_entries(int, int, hostsort *, hostsort *); /* compares host sort entries */
104 void free_servicesort_list(void);
105 void free_hostsort_list(void);
106
107 void show_host_status_totals(void);
108 void show_service_status_totals(void);
109 void show_service_detail(void);
110 void show_host_detail(void);
111 void show_servicegroup_overviews(void);
112 void show_servicegroup_overview(servicegroup *);
113 void show_servicegroup_summaries(void);
114 void show_servicegroup_summary(servicegroup *, int);
115 void show_servicegroup_host_totals_summary(servicegroup *);
116 void show_servicegroup_service_totals_summary(servicegroup *);
117 void show_servicegroup_grids(void);
118 void show_servicegroup_grid(servicegroup *);
119 void show_hostgroup_overviews(void);
120 void show_hostgroup_overview(hostgroup *);
121 void show_servicegroup_hostgroup_member_overview(hoststatus *, int, void *);
122 void show_servicegroup_hostgroup_member_service_status_totals(char *, void *);
123 void show_hostgroup_summaries(void);
124 void show_hostgroup_summary(hostgroup *, int);
125 void show_hostgroup_host_totals_summary(hostgroup *);
126 void show_hostgroup_service_totals_summary(hostgroup *);
127 void show_hostgroup_grids(void);
128 void show_hostgroup_grid(hostgroup *);
129
130 void show_filters(void);
131 void create_pagenumbers(int total_entries, int visible_entries, char *temp_url, int type_service);
132 void create_page_limiter(int result_limit, char *temp_url);
133
134 int passes_host_properties_filter(hoststatus *);
135 int passes_service_properties_filter(servicestatus *);
136
137 void document_header(int);
138 void document_footer(void);
139 int process_cgivars(void);
140
141
142 authdata current_authdata;
143 time_t current_time;
144
145 char alert_message[MAX_MESSAGE_BUFFER];
146 char *host_name = NULL;
147 char *host_filter = NULL;
148 char *hostgroup_name = NULL;
149 char *servicegroup_name = NULL;
150 char *service_filter = NULL;
151 int host_alert = FALSE;
152 int show_all_hosts = TRUE;
153 int show_all_hostgroups = TRUE;
154 int show_all_servicegroups = TRUE;
155 int display_type = DISPLAY_HOSTS;
156 int overview_columns = 3;
157 int max_grid_width = 8;
158 int group_style_type = STYLE_OVERVIEW;
159 int navbar_search = FALSE;
160
161 /* experimental paging feature */
162 int temp_result_limit;
163 int page_start;
164 int limit_results = TRUE;
165
166
167 int service_status_types = SERVICE_PENDING | SERVICE_OK | SERVICE_UNKNOWN | SERVICE_WARNING | SERVICE_CRITICAL;
168 int all_service_status_types = SERVICE_PENDING | SERVICE_OK | SERVICE_UNKNOWN | SERVICE_WARNING | SERVICE_CRITICAL;
169
170 int host_status_types = HOST_PENDING | HOST_UP | HOST_DOWN | HOST_UNREACHABLE;
171 int all_host_status_types = HOST_PENDING | HOST_UP | HOST_DOWN | HOST_UNREACHABLE;
172
173 int all_service_problems = SERVICE_UNKNOWN | SERVICE_WARNING | SERVICE_CRITICAL;
174 int all_host_problems = HOST_DOWN | HOST_UNREACHABLE;
175
176 unsigned long host_properties = 0L;
177 unsigned long service_properties = 0L;
178
179
180
181
182 int sort_type = SORT_NONE;
183 int sort_option = SORT_HOSTNAME;
184
185 int problem_hosts_down = 0;
186 int problem_hosts_unreachable = 0;
187 int problem_services_critical = 0;
188 int problem_services_warning = 0;
189 int problem_services_unknown = 0;
190
191 int embedded = FALSE;
192 int display_header = TRUE;
193
194
195
main(void)196 int main(void) {
197 int result = OK;
198 char *sound = NULL;
199 host *temp_host = NULL;
200 hostgroup *temp_hostgroup = NULL;
201 servicegroup *temp_servicegroup = NULL;
202 int regex_i = 1, i = 0;
203 int len;
204
205 mac = get_global_macros();
206
207 time(¤t_time);
208
209 /* get the arguments passed in the URL */
210 process_cgivars();
211
212 /* reset internal variables */
213 reset_cgi_vars();
214
215 /* read the CGI configuration file */
216 result = read_cgi_config_file(get_cgi_config_location());
217 if(result == ERROR) {
218 document_header(FALSE);
219 cgi_config_file_error(get_cgi_config_location());
220 document_footer();
221 return ERROR;
222 }
223
224 /* read the main configuration file */
225 result = read_main_config_file(main_config_file);
226 if(result == ERROR) {
227 document_header(FALSE);
228 main_config_file_error(main_config_file);
229 document_footer();
230 return ERROR;
231 }
232
233 /* read all object configuration data */
234 result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
235 if(result == ERROR) {
236 document_header(FALSE);
237 object_data_error();
238 document_footer();
239 return ERROR;
240 }
241
242 /* read all status data */
243 result = read_all_status_data(get_cgi_config_location(), READ_ALL_STATUS_DATA);
244 if(result == ERROR) {
245 document_header(FALSE);
246 status_data_error();
247 document_footer();
248 free_memory();
249 return ERROR;
250 }
251
252 /* initialize macros */
253 init_macros();
254
255 document_header(TRUE);
256
257 /* get authentication information */
258 get_authentication_information(¤t_authdata);
259
260 /* if a navbar search was performed, find the host by name, address or partial name */
261 if(navbar_search == TRUE) {
262 if(host_name != NULL && NULL != strstr(host_name, "*")) {
263 /* allocate for 3 extra chars, ^, $ and \0 */
264 host_filter = malloc(sizeof(char) * (strlen(host_name) * 2 + 3));
265 len = strlen(host_name);
266 for(i = 0; i < len; i++, regex_i++) {
267 if(host_name[i] == '*') {
268 host_filter[regex_i++] = '.';
269 host_filter[regex_i] = '*';
270 }
271 else
272 host_filter[regex_i] = host_name[i];
273 }
274 host_filter[0] = '^';
275 host_filter[regex_i++] = '$';
276 host_filter[regex_i] = '\0';
277 }
278 else {
279 if((temp_host = find_host(host_name)) == NULL) {
280 for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
281 if(is_authorized_for_host(temp_host, ¤t_authdata) == FALSE)
282 continue;
283 if(!strcmp(host_name, temp_host->address)) {
284 free(host_name);
285 host_name = strdup(temp_host->name);
286 break;
287 }
288 }
289 if(temp_host == NULL) {
290 for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
291 if(is_authorized_for_host(temp_host, ¤t_authdata) == FALSE)
292 continue;
293 if((strstr(temp_host->name, host_name) == temp_host->name) || !strncasecmp(temp_host->name, host_name, strlen(host_name))) {
294 free(host_name);
295 host_name = strdup(temp_host->name);
296 break;
297 }
298 }
299 }
300 }
301 /* last effort, search hostgroups then servicegroups */
302 if(temp_host == NULL) {
303 if((temp_hostgroup = find_hostgroup(host_name)) != NULL) {
304 display_type = DISPLAY_HOSTGROUPS;
305 show_all_hostgroups = FALSE;
306 free(host_name);
307 hostgroup_name = strdup(temp_hostgroup->group_name);
308 }
309 else if((temp_servicegroup = find_servicegroup(host_name)) != NULL) {
310 display_type = DISPLAY_SERVICEGROUPS;
311 show_all_servicegroups = FALSE;
312 free(host_name);
313 servicegroup_name = strdup(temp_servicegroup->group_name);
314 }
315 }
316 }
317 }
318
319 if(display_header == TRUE) {
320
321 /* begin top table */
322 printf("<table class='headertable'>\n");
323 printf("<tr>\n");
324
325 /* left column of the first row */
326 printf("<td align=left valign=top width=33%%>\n");
327
328 /* info table */
329 display_info_table("Current Network Status", TRUE, ¤t_authdata);
330
331 printf("<table class='linkBox'>\n");
332 printf("<tr><td class='linkBox'>\n");
333
334 if(display_type == DISPLAY_HOSTS) {
335 printf("<a href='%s?host=%s'>View History For %s</a><br>\n", HISTORY_CGI, (show_all_hosts == TRUE) ? "all" : url_encode(host_name), (show_all_hosts == TRUE) ? "all hosts" : "This Host");
336 printf("<a href='%s?host=%s'>View Notifications For %s</a>\n", NOTIFICATIONS_CGI, (show_all_hosts == TRUE) ? "all" : url_encode(host_name), (show_all_hosts == TRUE) ? "All Hosts" : "This Host");
337 if(show_all_hosts == FALSE)
338 printf("<br /><a href='%s?host=all'>View Service Status Detail For All Hosts</a>\n", STATUS_CGI);
339 else
340 printf("<br /><a href='%s?hostgroup=all&style=hostdetail'>View Host Status Detail For All Hosts</a>\n", STATUS_CGI);
341 }
342 else if(display_type == DISPLAY_SERVICEGROUPS) {
343 if(show_all_servicegroups == FALSE) {
344
345 if(group_style_type == STYLE_OVERVIEW || group_style_type == STYLE_GRID || group_style_type == STYLE_SUMMARY)
346 printf("<a href='%s?servicegroup=%s&style=detail'>View Service Status Detail For This Service Group</a><br>\n", STATUS_CGI, url_encode(servicegroup_name));
347 if(group_style_type == STYLE_DETAIL || group_style_type == STYLE_GRID || group_style_type == STYLE_SUMMARY)
348 printf("<a href='%s?servicegroup=%s&style=overview'>View Status Overview For This Service Group</a><br>\n", STATUS_CGI, url_encode(servicegroup_name));
349 if(group_style_type == STYLE_DETAIL || group_style_type == STYLE_OVERVIEW || group_style_type == STYLE_GRID)
350 printf("<a href='%s?servicegroup=%s&style=summary'>View Status Summary For This Service Group</a><br>\n", STATUS_CGI, url_encode(servicegroup_name));
351 if(group_style_type == STYLE_DETAIL || group_style_type == STYLE_OVERVIEW || group_style_type == STYLE_SUMMARY)
352 printf("<a href='%s?servicegroup=%s&style=grid'>View Service Status Grid For This Service Group</a><br>\n", STATUS_CGI, url_encode(servicegroup_name));
353
354 if(group_style_type == STYLE_DETAIL)
355 printf("<a href='%s?servicegroup=all&style=detail'>View Service Status Detail For All Service Groups</a><br>\n", STATUS_CGI);
356 if(group_style_type == STYLE_OVERVIEW)
357 printf("<a href='%s?servicegroup=all&style=overview'>View Status Overview For All Service Groups</a><br>\n", STATUS_CGI);
358 if(group_style_type == STYLE_SUMMARY)
359 printf("<a href='%s?servicegroup=all&style=summary'>View Status Summary For All Service Groups</a><br>\n", STATUS_CGI);
360 if(group_style_type == STYLE_GRID)
361 printf("<a href='%s?servicegroup=all&style=grid'>View Service Status Grid For All Service Groups</a><br>\n", STATUS_CGI);
362
363 }
364 else {
365 if(group_style_type == STYLE_OVERVIEW || group_style_type == STYLE_GRID || group_style_type == STYLE_SUMMARY)
366 printf("<a href='%s?servicegroup=all&style=detail'>View Service Status Detail For All Service Groups</a><br>\n", STATUS_CGI);
367 if(group_style_type == STYLE_DETAIL || group_style_type == STYLE_GRID || group_style_type == STYLE_SUMMARY)
368 printf("<a href='%s?servicegroup=all&style=overview'>View Status Overview For All Service Groups</a><br>\n", STATUS_CGI);
369 if(group_style_type == STYLE_DETAIL || group_style_type == STYLE_OVERVIEW || group_style_type == STYLE_GRID)
370 printf("<a href='%s?servicegroup=all&style=summary'>View Status Summary For All Service Groups</a><br>\n", STATUS_CGI);
371 if(group_style_type == STYLE_DETAIL || group_style_type == STYLE_OVERVIEW || group_style_type == STYLE_SUMMARY)
372 printf("<a href='%s?servicegroup=all&style=grid'>View Service Status Grid For All Service Groups</a><br>\n", STATUS_CGI);
373 }
374
375 }
376 else {
377 if(show_all_hostgroups == FALSE) {
378
379 if(group_style_type == STYLE_DETAIL)
380 printf("<a href='%s?hostgroup=all&style=detail'>View Service Status Detail For All Host Groups</a><br>\n", STATUS_CGI);
381 if(group_style_type == STYLE_HOST_DETAIL)
382 printf("<a href='%s?hostgroup=all&style=hostdetail'>View Host Status Detail For All Host Groups</a><br>\n", STATUS_CGI);
383 if(group_style_type == STYLE_OVERVIEW)
384 printf("<a href='%s?hostgroup=all&style=overview'>View Status Overview For All Host Groups</a><br>\n", STATUS_CGI);
385 if(group_style_type == STYLE_SUMMARY)
386 printf("<a href='%s?hostgroup=all&style=summary'>View Status Summary For All Host Groups</a><br>\n", STATUS_CGI);
387 if(group_style_type == STYLE_GRID)
388 printf("<a href='%s?hostgroup=all&style=grid'>View Status Grid For All Host Groups</a><br>\n", STATUS_CGI);
389
390 if(group_style_type == STYLE_OVERVIEW || group_style_type == STYLE_SUMMARY || group_style_type == STYLE_GRID || group_style_type == STYLE_HOST_DETAIL)
391 printf("<a href='%s?hostgroup=%s&style=detail'>View Service Status Detail For This Host Group</a><br>\n", STATUS_CGI, url_encode(hostgroup_name));
392 if(group_style_type == STYLE_OVERVIEW || group_style_type == STYLE_DETAIL || group_style_type == STYLE_SUMMARY || group_style_type == STYLE_GRID)
393 printf("<a href='%s?hostgroup=%s&style=hostdetail'>View Host Status Detail For This Host Group</a><br>\n", STATUS_CGI, url_encode(hostgroup_name));
394 if(group_style_type == STYLE_DETAIL || group_style_type == STYLE_SUMMARY || group_style_type == STYLE_GRID || group_style_type == STYLE_HOST_DETAIL)
395 printf("<a href='%s?hostgroup=%s&style=overview'>View Status Overview For This Host Group</a><br>\n", STATUS_CGI, url_encode(hostgroup_name));
396 if(group_style_type == STYLE_OVERVIEW || group_style_type == STYLE_DETAIL || group_style_type == STYLE_GRID || group_style_type == STYLE_HOST_DETAIL)
397 printf("<a href='%s?hostgroup=%s&style=summary'>View Status Summary For This Host Group</a><br>\n", STATUS_CGI, url_encode(hostgroup_name));
398 if(group_style_type == STYLE_OVERVIEW || group_style_type == STYLE_DETAIL || group_style_type == STYLE_SUMMARY || group_style_type == STYLE_HOST_DETAIL)
399 printf("<a href='%s?hostgroup=%s&style=grid'>View Status Grid For This Host Group</a><br>\n", STATUS_CGI, url_encode(hostgroup_name));
400 }
401 else {
402 if(group_style_type == STYLE_OVERVIEW || group_style_type == STYLE_SUMMARY || group_style_type == STYLE_GRID || group_style_type == STYLE_HOST_DETAIL)
403 printf("<a href='%s?hostgroup=all&style=detail'>View Service Status Detail For All Host Groups</a><br>\n", STATUS_CGI);
404 if(group_style_type == STYLE_OVERVIEW || group_style_type == STYLE_DETAIL || group_style_type == STYLE_SUMMARY || group_style_type == STYLE_GRID)
405 printf("<a href='%s?hostgroup=all&style=hostdetail'>View Host Status Detail For All Host Groups</a><br>\n", STATUS_CGI);
406 if(group_style_type == STYLE_DETAIL || group_style_type == STYLE_SUMMARY || group_style_type == STYLE_GRID || group_style_type == STYLE_HOST_DETAIL)
407 printf("<a href='%s?hostgroup=all&style=overview'>View Status Overview For All Host Groups</a><br>\n", STATUS_CGI);
408 if(group_style_type == STYLE_OVERVIEW || group_style_type == STYLE_DETAIL || group_style_type == STYLE_GRID || group_style_type == STYLE_HOST_DETAIL)
409 printf("<a href='%s?hostgroup=all&style=summary'>View Status Summary For All Host Groups</a><br>\n", STATUS_CGI);
410 if(group_style_type == STYLE_OVERVIEW || group_style_type == STYLE_DETAIL || group_style_type == STYLE_SUMMARY || group_style_type == STYLE_HOST_DETAIL)
411 printf("<a href='%s?hostgroup=all&style=grid'>View Status Grid For All Host Groups</a><br>\n", STATUS_CGI);
412 }
413 }
414
415 printf("</td></tr>\n");
416 printf("</table>\n");
417
418 printf("</td>\n");
419
420 /* middle column of top row */
421 printf("<td align=center valign=top width=33%%>\n");
422 show_host_status_totals();
423 printf("</td>\n");
424
425 /* right hand column of top row */
426 printf("<td align=center valign=top width=33%%>\n");
427 show_service_status_totals();
428 printf("</td>\n");
429
430 /* display context-sensitive help */
431 printf("<td align=right valign=bottom>\n");
432 if(display_type == DISPLAY_HOSTS)
433 display_context_help(CONTEXTHELP_STATUS_DETAIL);
434 else if(display_type == DISPLAY_SERVICEGROUPS) {
435 if(group_style_type == STYLE_HOST_DETAIL)
436 display_context_help(CONTEXTHELP_STATUS_DETAIL);
437 else if(group_style_type == STYLE_OVERVIEW)
438 display_context_help(CONTEXTHELP_STATUS_SGOVERVIEW);
439 else if(group_style_type == STYLE_SUMMARY)
440 display_context_help(CONTEXTHELP_STATUS_SGSUMMARY);
441 else if(group_style_type == STYLE_GRID)
442 display_context_help(CONTEXTHELP_STATUS_SGGRID);
443 }
444 else {
445 if(group_style_type == STYLE_HOST_DETAIL)
446 display_context_help(CONTEXTHELP_STATUS_HOST_DETAIL);
447 else if(group_style_type == STYLE_OVERVIEW)
448 display_context_help(CONTEXTHELP_STATUS_HGOVERVIEW);
449 else if(group_style_type == STYLE_SUMMARY)
450 display_context_help(CONTEXTHELP_STATUS_HGSUMMARY);
451 else if(group_style_type == STYLE_GRID)
452 display_context_help(CONTEXTHELP_STATUS_HGGRID);
453 }
454 printf("</td>\n");
455
456 /* end of top table */
457 printf("</tr>\n");
458 printf("</table>\n");
459 }
460
461
462 /* embed sound tag if necessary... */
463 if(problem_hosts_unreachable > 0 && host_unreachable_sound != NULL)
464 sound = host_unreachable_sound;
465 else if(problem_hosts_down > 0 && host_down_sound != NULL)
466 sound = host_down_sound;
467 else if(problem_services_critical > 0 && service_critical_sound != NULL)
468 sound = service_critical_sound;
469 else if(problem_services_warning > 0 && service_warning_sound != NULL)
470 sound = service_warning_sound;
471 else if(problem_services_unknown > 0 && service_unknown_sound != NULL)
472 sound = service_unknown_sound;
473 else if(problem_services_unknown == 0 && problem_services_warning == 0 && problem_services_critical == 0 && problem_hosts_down == 0 && problem_hosts_unreachable == 0 && normal_sound != NULL)
474 sound = normal_sound;
475 if(sound != NULL) {
476 printf("<object type=\"audio/x-wav\" data=\"%s%s\" height=\"0\" width=\"0\">", url_media_path, sound);
477 printf("<param name=\"filename\" value=\"%s%s\">", url_media_path, sound);
478 printf("<param name=\"autostart\" value=\"true\">");
479 printf("<param name=\"playcount\" value=\"1\">");
480 printf("</object>");
481 }
482
483
484 /* bottom portion of screen - service or hostgroup detail */
485 if(display_type == DISPLAY_HOSTS)
486 show_service_detail();
487 else if(display_type == DISPLAY_SERVICEGROUPS) {
488 if(group_style_type == STYLE_OVERVIEW)
489 show_servicegroup_overviews();
490 else if(group_style_type == STYLE_SUMMARY)
491 show_servicegroup_summaries();
492 else if(group_style_type == STYLE_GRID)
493 show_servicegroup_grids();
494 else if(group_style_type == STYLE_HOST_DETAIL)
495 show_host_detail();
496 else
497 show_service_detail();
498 }
499 else {
500 if(group_style_type == STYLE_OVERVIEW)
501 show_hostgroup_overviews();
502 else if(group_style_type == STYLE_SUMMARY)
503 show_hostgroup_summaries();
504 else if(group_style_type == STYLE_GRID)
505 show_hostgroup_grids();
506 else if(group_style_type == STYLE_HOST_DETAIL)
507 show_host_detail();
508 else
509 show_service_detail();
510 }
511
512 document_footer();
513
514 /* free all allocated memory */
515 free_memory();
516 free_comment_data();
517
518 /* free memory allocated to the sort lists */
519 free_servicesort_list();
520 free_hostsort_list();
521
522 return OK;
523 }
524
525
document_header(int use_stylesheet)526 void document_header(int use_stylesheet) {
527 char date_time[MAX_DATETIME_LENGTH];
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 get_time_string(¤t_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME);
535 printf("Last-Modified: %s\r\n", date_time);
536
537 expire_time = (time_t)0L;
538 get_time_string(&expire_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME);
539 printf("Expires: %s\r\n", date_time);
540
541 printf("Content-type: text/html\r\n\r\n");
542
543 if(embedded == TRUE)
544 return;
545
546 printf("<html>\n");
547 printf("<head>\n");
548 printf("<link rel=\"shortcut icon\" href=\"%sfavicon.ico\" type=\"image/ico\">\n", url_images_path);
549 printf("<title>\n");
550 printf("Current Network Status\n");
551 printf("</title>\n");
552
553 if(use_stylesheet == TRUE) {
554 printf("<link rel='stylesheet' type='text/css' href='%s%s' />\n", url_stylesheets_path, COMMON_CSS);
555 printf("<link rel='stylesheet' type='text/css' href='%s%s' />\n", url_stylesheets_path, STATUS_CSS);
556 }
557
558 /* added jquery library 1/31/2012 */
559 printf("<script type='text/javascript' src='%s%s'></script>\n", url_js_path, JQUERY_JS);
560 /* JS function to append content to elements on page */
561 printf("<script type='text/javascript'>\n");
562 printf("$(document).ready(function() { $('#top_page_numbers').append($('#bottom_page_numbers').html() ); });");
563 printf("function set_limit(url) { \nthis.location = url+'&limit='+$('#limit').val();\n }");
564 printf("</script>\n");
565
566 printf("</head>\n");
567
568 printf("<body class='status'>\n");
569
570 /* include user SSI header */
571 include_ssi_files(STATUS_CGI, SSI_HEADER);
572
573 return;
574 }
575
576
document_footer(void)577 void document_footer(void) {
578
579 if(embedded == TRUE)
580 return;
581
582 /* include user SSI footer */
583 include_ssi_files(STATUS_CGI, SSI_FOOTER);
584
585 printf("</body>\n");
586 printf("</html>\n");
587
588 return;
589 }
590
591
process_cgivars(void)592 int process_cgivars(void) {
593 char **variables;
594 int error = FALSE;
595 int x;
596
597 variables = getcgivars();
598
599 for(x = 0; variables[x] != NULL; x++) {
600
601 /* do some basic length checking on the variable identifier to prevent buffer overflows */
602 if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
603 continue;
604 }
605
606 /* we found the navbar search argument */
607 else if(!strcmp(variables[x], "navbarsearch")) {
608 x++;
609 if(variables[x] == NULL) {
610 error = TRUE;
611 break;
612 }
613 navbar_search = TRUE;
614 }
615
616 /* we found the hostgroup argument */
617 else if(!strcmp(variables[x], "hostgroup")) {
618 display_type = DISPLAY_HOSTGROUPS;
619 x++;
620 if(variables[x] == NULL) {
621 error = TRUE;
622 break;
623 }
624
625 hostgroup_name = (char *)strdup(variables[x]);
626 strip_html_brackets(hostgroup_name);
627
628 if(hostgroup_name != NULL && !strcmp(hostgroup_name, "all"))
629 show_all_hostgroups = TRUE;
630 else
631 show_all_hostgroups = FALSE;
632 }
633
634 /* we found the servicegroup argument */
635 else if(!strcmp(variables[x], "servicegroup")) {
636 display_type = DISPLAY_SERVICEGROUPS;
637 x++;
638 if(variables[x] == NULL) {
639 error = TRUE;
640 break;
641 }
642
643 servicegroup_name = strdup(variables[x]);
644 strip_html_brackets(servicegroup_name);
645
646 if(servicegroup_name != NULL && !strcmp(servicegroup_name, "all"))
647 show_all_servicegroups = TRUE;
648 else
649 show_all_servicegroups = FALSE;
650 }
651
652 /* we found the host argument */
653 else if(!strcmp(variables[x], "host")) {
654 display_type = DISPLAY_HOSTS;
655 x++;
656 if(variables[x] == NULL) {
657 error = TRUE;
658 break;
659 }
660
661 host_name = strdup(variables[x]);
662 strip_html_brackets(host_name);
663
664 if(host_name != NULL && !strcmp(host_name, "all"))
665 show_all_hosts = TRUE;
666 else
667 show_all_hosts = FALSE;
668 }
669
670 /* we found the columns argument */
671 else if(!strcmp(variables[x], "columns")) {
672 x++;
673 if(variables[x] == NULL) {
674 error = TRUE;
675 break;
676 }
677
678 overview_columns = atoi(variables[x]);
679 if(overview_columns <= 0)
680 overview_columns = 1;
681 }
682
683 /* we found the service status type argument */
684 else if(!strcmp(variables[x], "servicestatustypes")) {
685 x++;
686 if(variables[x] == NULL) {
687 error = TRUE;
688 break;
689 }
690
691 service_status_types = atoi(variables[x]);
692 }
693
694 /* we found the host status type argument */
695 else if(!strcmp(variables[x], "hoststatustypes")) {
696 x++;
697 if(variables[x] == NULL) {
698 error = TRUE;
699 break;
700 }
701
702 host_status_types = atoi(variables[x]);
703 }
704
705 /* we found the service properties argument */
706 else if(!strcmp(variables[x], "serviceprops")) {
707 x++;
708 if(variables[x] == NULL) {
709 error = TRUE;
710 break;
711 }
712
713 service_properties = strtoul(variables[x], NULL, 10);
714 }
715
716 /* we found the host properties argument */
717 else if(!strcmp(variables[x], "hostprops")) {
718 x++;
719 if(variables[x] == NULL) {
720 error = TRUE;
721 break;
722 }
723
724 host_properties = strtoul(variables[x], NULL, 10);
725 }
726
727 /* we found the host or service group style argument */
728 else if(!strcmp(variables[x], "style")) {
729 x++;
730 if(variables[x] == NULL) {
731 error = TRUE;
732 break;
733 }
734
735 if(!strcmp(variables[x], "overview"))
736 group_style_type = STYLE_OVERVIEW;
737 else if(!strcmp(variables[x], "detail"))
738 group_style_type = STYLE_DETAIL;
739 else if(!strcmp(variables[x], "summary"))
740 group_style_type = STYLE_SUMMARY;
741 else if(!strcmp(variables[x], "grid"))
742 group_style_type = STYLE_GRID;
743 else if(!strcmp(variables[x], "hostdetail"))
744 group_style_type = STYLE_HOST_DETAIL;
745 else
746 group_style_type = STYLE_DETAIL;
747 }
748
749 /* we found the sort type argument */
750 else if(!strcmp(variables[x], "sorttype")) {
751 x++;
752 if(variables[x] == NULL) {
753 error = TRUE;
754 break;
755 }
756
757 sort_type = atoi(variables[x]);
758 }
759
760 /* we found the sort option argument */
761 else if(!strcmp(variables[x], "sortoption")) {
762 x++;
763 if(variables[x] == NULL) {
764 error = TRUE;
765 break;
766 }
767
768 sort_option = atoi(variables[x]);
769 }
770
771 /* we found the embed option */
772 else if(!strcmp(variables[x], "embedded"))
773 embedded = TRUE;
774
775 /* we found the noheader option */
776 else if(!strcmp(variables[x], "noheader"))
777 display_header = FALSE;
778
779 /* servicefilter cgi var */
780 else if(!strcmp(variables[x], "servicefilter")) {
781 x++;
782 if(variables[x] == NULL) {
783 error = TRUE;
784 break;
785 }
786 service_filter = strdup(variables[x]);
787 strip_html_brackets(service_filter);
788 }
789
790 /* experimental page limit feature */
791 else if(!strcmp(variables[x], "start")) {
792 x++;
793 if(variables[x] == NULL) {
794 error = TRUE;
795 break;
796 }
797 page_start = atoi(variables[x]);
798 }
799 else if(!strcmp(variables[x], "limit")) {
800 x++;
801 if(variables[x] == NULL) {
802 error = TRUE;
803 break;
804 }
805 temp_result_limit = atoi(variables[x]);
806 if(temp_result_limit == 0)
807 limit_results = FALSE;
808 else
809 limit_results = TRUE;
810 }
811
812 }
813
814
815 /* free memory allocated to the CGI variables */
816 free_cgivars(variables);
817
818 return error;
819 }
820
821
822
823 /* display table with service status totals... */
show_service_status_totals(void)824 void show_service_status_totals(void) {
825 int total_ok = 0;
826 int total_warning = 0;
827 int total_unknown = 0;
828 int total_critical = 0;
829 int total_pending = 0;
830 int total_services = 0;
831 int total_problems = 0;
832 servicestatus *temp_servicestatus;
833 service *temp_service;
834 host *temp_host;
835 int count_service;
836
837
838 /* check the status of all services... */
839 for(temp_servicestatus = servicestatus_list; temp_servicestatus != NULL; temp_servicestatus = temp_servicestatus->next) {
840
841 /* find the host and service... */
842 temp_host = find_host(temp_servicestatus->host_name);
843 temp_service = find_service(temp_servicestatus->host_name, temp_servicestatus->description);
844
845 /* make sure user has rights to see this service... */
846 if(is_authorized_for_service(temp_service, ¤t_authdata) == FALSE)
847 continue;
848
849 count_service = 0;
850
851 if(display_type == DISPLAY_HOSTS && (show_all_hosts == TRUE || !strcmp(host_name, temp_servicestatus->host_name)))
852 count_service = 1;
853 else if(display_type == DISPLAY_SERVICEGROUPS && (show_all_servicegroups == TRUE || (is_service_member_of_servicegroup(find_servicegroup(servicegroup_name), temp_service) == TRUE)))
854 count_service = 1;
855 else if(display_type == DISPLAY_HOSTGROUPS && (show_all_hostgroups == TRUE || (is_host_member_of_hostgroup(find_hostgroup(hostgroup_name), temp_host) == TRUE)))
856 count_service = 1;
857
858 if(count_service) {
859
860 if(temp_servicestatus->status == SERVICE_CRITICAL) {
861 total_critical++;
862 if(temp_servicestatus->problem_has_been_acknowledged == FALSE && (temp_servicestatus->checks_enabled == TRUE || temp_servicestatus->accept_passive_service_checks == TRUE) && temp_servicestatus->notifications_enabled == TRUE && temp_servicestatus->scheduled_downtime_depth == 0)
863 problem_services_critical++;
864 }
865 else if(temp_servicestatus->status == SERVICE_WARNING) {
866 total_warning++;
867 if(temp_servicestatus->problem_has_been_acknowledged == FALSE && (temp_servicestatus->checks_enabled == TRUE || temp_servicestatus->accept_passive_service_checks == TRUE) && temp_servicestatus->notifications_enabled == TRUE && temp_servicestatus->scheduled_downtime_depth == 0)
868 problem_services_warning++;
869 }
870 else if(temp_servicestatus->status == SERVICE_UNKNOWN) {
871 total_unknown++;
872 if(temp_servicestatus->problem_has_been_acknowledged == FALSE && (temp_servicestatus->checks_enabled == TRUE || temp_servicestatus->accept_passive_service_checks == TRUE) && temp_servicestatus->notifications_enabled == TRUE && temp_servicestatus->scheduled_downtime_depth == 0)
873 problem_services_unknown++;
874 }
875 else if(temp_servicestatus->status == SERVICE_OK)
876 total_ok++;
877 else if(temp_servicestatus->status == SERVICE_PENDING)
878 total_pending++;
879 else
880 total_ok++;
881 }
882 }
883
884 total_services = total_ok + total_unknown + total_warning + total_critical + total_pending;
885 total_problems = total_unknown + total_warning + total_critical;
886
887
888 printf("<div class='serviceTotals'>Service Status Totals</div>\n");
889
890 printf("<table border='0' cellspacing='0' cellpadding='0'>\n");
891 printf("<tr><td>\n");
892
893 printf("<table class='serviceTotals'>\n");
894 printf("<tr>\n");
895
896 printf("<th class='serviceTotals'>");
897 printf("<a class='serviceTotals' href='%s?", STATUS_CGI);
898 /* paging */
899 if(temp_result_limit)
900 printf("limit=%i&", temp_result_limit);
901 if(display_type == DISPLAY_HOSTS)
902 printf("host=%s", (host_name == NULL) ? "all" : url_encode(host_name));
903 else if(display_type == DISPLAY_SERVICEGROUPS)
904 printf("servicegroup=%s&style=detail", url_encode(servicegroup_name));
905 else
906 printf("hostgroup=%s&style=detail", url_encode(hostgroup_name));
907 printf("&servicestatustypes=%d", SERVICE_OK);
908 printf("&hoststatustypes=%d'>", host_status_types);
909 printf("Ok</a></th>\n");
910
911 printf("<th class='serviceTotals'>");
912 printf("<a class='serviceTotals' href='%s?", STATUS_CGI);
913 /* paging */
914 if(temp_result_limit)
915 printf("limit=%i&", temp_result_limit);
916 if(display_type == DISPLAY_HOSTS)
917 printf("host=%s", (host_name == NULL) ? "all" : url_encode(host_name));
918 else if(display_type == DISPLAY_SERVICEGROUPS)
919 printf("servicegroup=%s&style=detail", url_encode(servicegroup_name));
920 else
921 printf("hostgroup=%s&style=detail", url_encode(hostgroup_name));
922 printf("&servicestatustypes=%d", SERVICE_WARNING);
923 printf("&hoststatustypes=%d'>", host_status_types);
924 printf("Warning</a></th>\n");
925
926 printf("<th class='serviceTotals'>");
927 printf("<a class='serviceTotals' href='%s?", STATUS_CGI);
928 /* paging */
929 if(temp_result_limit)
930 printf("limit=%i&", temp_result_limit);
931 if(display_type == DISPLAY_HOSTS)
932 printf("host=%s", (host_name == NULL) ? "all" : url_encode(host_name));
933 else if(display_type == DISPLAY_SERVICEGROUPS)
934 printf("servicegroup=%s&style=detail", url_encode(servicegroup_name));
935 else
936 printf("hostgroup=%s&style=detail", url_encode(hostgroup_name));
937 printf("&servicestatustypes=%d", SERVICE_UNKNOWN);
938 printf("&hoststatustypes=%d'>", host_status_types);
939 printf("Unknown</a></th>\n");
940
941 printf("<th class='serviceTotals'>");
942 printf("<a class='serviceTotals' href='%s?", STATUS_CGI);
943 /* paging */
944 if(temp_result_limit)
945 printf("limit=%i&", temp_result_limit);
946 if(display_type == DISPLAY_HOSTS)
947 printf("host=%s", (host_name == NULL) ? "all" : url_encode(host_name));
948 else if(display_type == DISPLAY_SERVICEGROUPS)
949 printf("servicegroup=%s&style=detail", url_encode(servicegroup_name));
950 else
951 printf("hostgroup=%s&style=detail", url_encode(hostgroup_name));
952 printf("&servicestatustypes=%d", SERVICE_CRITICAL);
953 printf("&hoststatustypes=%d'>", host_status_types);
954 printf("Critical</a></th>\n");
955
956 printf("<th class='serviceTotals'>");
957 printf("<a class='serviceTotals' href='%s?", STATUS_CGI);
958 /* paging */
959 if(temp_result_limit)
960 printf("limit=%i&", temp_result_limit);
961 if(display_type == DISPLAY_HOSTS)
962 printf("host=%s", (host_name == NULL) ? "all" : url_encode(host_name));
963 else if(display_type == DISPLAY_SERVICEGROUPS)
964 printf("servicegroup=%s&style=detail", url_encode(servicegroup_name));
965 else
966 printf("hostgroup=%s&style=detail", url_encode(hostgroup_name));
967 printf("&servicestatustypes=%d", SERVICE_PENDING);
968 printf("&hoststatustypes=%d'>", host_status_types);
969 printf("Pending</a></th>\n");
970
971 printf("</tr>\n");
972
973 printf("<tr>\n");
974
975
976 /* total services ok */
977 printf("<td class='serviceTotals%s'>%d</td>\n", (total_ok > 0) ? "OK" : "", total_ok);
978
979 /* total services in warning state */
980 printf("<td class='serviceTotals%s'>%d</td>\n", (total_warning > 0) ? "WARNING" : "", total_warning);
981
982 /* total services in unknown state */
983 printf("<td class='serviceTotals%s'>%d</td>\n", (total_unknown > 0) ? "UNKNOWN" : "", total_unknown);
984
985 /* total services in critical state */
986 printf("<td class='serviceTotals%s'>%d</td>\n", (total_critical > 0) ? "CRITICAL" : "", total_critical);
987
988 /* total services in pending state */
989 printf("<td class='serviceTotals%s'>%d</td>\n", (total_pending > 0) ? "PENDING" : "", total_pending);
990
991
992 printf("</tr>\n");
993 printf("</table>\n");
994
995 printf("</td></tr><tr><td align='center'>\n");
996
997 printf("<table class='serviceTotals'>\n");
998 printf("<tr>\n");
999
1000 printf("<th class='serviceTotals'>");
1001 printf("<a class='serviceTotals' href='%s?", STATUS_CGI);
1002 /* paging */
1003 if(temp_result_limit)
1004 printf("limit=%i&", temp_result_limit);
1005 if(display_type == DISPLAY_HOSTS)
1006 printf("host=%s", (host_name == NULL) ? "all" : url_encode(host_name));
1007 else if(display_type == DISPLAY_SERVICEGROUPS)
1008 printf("servicegroup=%s&style=detail", url_encode(servicegroup_name));
1009 else
1010 printf("hostgroup=%s&style=detail", url_encode(hostgroup_name));
1011 printf("&servicestatustypes=%d", SERVICE_UNKNOWN | SERVICE_WARNING | SERVICE_CRITICAL);
1012 printf("&hoststatustypes=%d'>", host_status_types);
1013 printf("<em>All Problems</em></a></th>\n");
1014
1015 printf("<th class='serviceTotals'>");
1016 printf("<a class='serviceTotals' href='%s?", STATUS_CGI);
1017 /* paging */
1018 if(temp_result_limit)
1019 printf("limit=%i&", temp_result_limit);
1020 if(display_type == DISPLAY_HOSTS)
1021 printf("host=%s", (host_name == NULL) ? "all" : url_encode(host_name));
1022 else if(display_type == DISPLAY_SERVICEGROUPS)
1023 printf("servicegroup=%s&style=detail", url_encode(servicegroup_name));
1024 else
1025 printf("hostgroup=%s&style=detail", url_encode(hostgroup_name));
1026 printf("&hoststatustypes=%d'>", host_status_types);
1027 printf("<em>All Types</em></a></th>\n");
1028
1029
1030 printf("</tr><tr>\n");
1031
1032 /* total service problems */
1033 printf("<td class='serviceTotals%s'>%d</td>\n", (total_problems > 0) ? "PROBLEMS" : "", total_problems);
1034
1035 /* total services */
1036 printf("<td class='serviceTotals'>%d</td>\n", total_services);
1037
1038 printf("</tr>\n");
1039 printf("</table>\n");
1040
1041 printf("</td></tr>\n");
1042 printf("</table>\n");
1043
1044 printf("</div>\n");
1045
1046 return;
1047 }
1048
1049
1050 /* display a table with host status totals... */
show_host_status_totals(void)1051 void show_host_status_totals(void) {
1052 int total_up = 0;
1053 int total_down = 0;
1054 int total_unreachable = 0;
1055 int total_pending = 0;
1056 int total_hosts = 0;
1057 int total_problems = 0;
1058 hoststatus *temp_hoststatus;
1059 host *temp_host;
1060 int count_host;
1061
1062
1063 /* check the status of all hosts... */
1064 for(temp_hoststatus = hoststatus_list; temp_hoststatus != NULL; temp_hoststatus = temp_hoststatus->next) {
1065
1066 /* find the host... */
1067 temp_host = find_host(temp_hoststatus->host_name);
1068
1069 /* make sure user has rights to view this host */
1070 if(is_authorized_for_host(temp_host, ¤t_authdata) == FALSE)
1071 continue;
1072
1073 count_host = 0;
1074
1075 if(display_type == DISPLAY_HOSTS && (show_all_hosts == TRUE || !strcmp(host_name, temp_hoststatus->host_name)))
1076 count_host = 1;
1077 else if(display_type == DISPLAY_SERVICEGROUPS) {
1078 if(show_all_servicegroups == TRUE) {
1079 count_host = 1;
1080 }
1081 else if(is_host_member_of_servicegroup(find_servicegroup(servicegroup_name), temp_host) == TRUE) {
1082 count_host = 1;
1083 }
1084 }
1085 else if(display_type == DISPLAY_HOSTGROUPS && (show_all_hostgroups == TRUE || (is_host_member_of_hostgroup(find_hostgroup(hostgroup_name), temp_host) == TRUE)))
1086 count_host = 1;
1087
1088 if(count_host) {
1089
1090 if(temp_hoststatus->status == HOST_UP)
1091 total_up++;
1092 else if(temp_hoststatus->status == HOST_DOWN) {
1093 total_down++;
1094 if(temp_hoststatus->problem_has_been_acknowledged == FALSE && temp_hoststatus->notifications_enabled == TRUE && temp_hoststatus->checks_enabled == TRUE && temp_hoststatus->scheduled_downtime_depth == 0)
1095 problem_hosts_down++;
1096 }
1097 else if(temp_hoststatus->status == HOST_UNREACHABLE) {
1098 total_unreachable++;
1099 if(temp_hoststatus->problem_has_been_acknowledged == FALSE && temp_hoststatus->notifications_enabled == TRUE && temp_hoststatus->checks_enabled == TRUE && temp_hoststatus->scheduled_downtime_depth == 0)
1100 problem_hosts_unreachable++;
1101 }
1102
1103 else if(temp_hoststatus->status == HOST_PENDING)
1104 total_pending++;
1105 else
1106 total_up++;
1107 }
1108 }
1109
1110 total_hosts = total_up + total_down + total_unreachable + total_pending;
1111 total_problems = total_down + total_unreachable;
1112
1113 printf("<div class='hostTotals'>Host Status Totals</div>\n");
1114
1115 printf("<table border=0 cellspacing=0 cellpadding=0>\n");
1116 printf("<tr><td>\n");
1117
1118
1119 printf("<table class='hostTotals'>\n");
1120 printf("<tr>\n");
1121
1122 printf("<th class='hostTotals'>");
1123 printf("<a class='hostTotals' href='%s?", STATUS_CGI);
1124 /* paging */
1125 if(temp_result_limit)
1126 printf("limit=%i&", temp_result_limit);
1127 if(display_type == DISPLAY_HOSTS)
1128 printf("host=%s", (host_name == NULL) ? "all" : url_encode(host_name));
1129 else if(display_type == DISPLAY_SERVICEGROUPS)
1130 printf("servicegroup=%s", url_encode(servicegroup_name));
1131 else {
1132 printf("hostgroup=%s", url_encode(hostgroup_name));
1133 if((service_status_types != all_service_status_types) || group_style_type == STYLE_DETAIL)
1134 printf("&style=detail");
1135 else if(group_style_type == STYLE_HOST_DETAIL)
1136 printf("&style=hostdetail");
1137 }
1138 if(service_status_types != all_service_status_types)
1139 printf("&servicestatustypes=%d", service_status_types);
1140 printf("&hoststatustypes=%d'>", HOST_UP);
1141 printf("Up</a></th>\n");
1142
1143 printf("<th class='hostTotals'>");
1144 printf("<a class='hostTotals' href='%s?", STATUS_CGI);
1145 /* paging */
1146 if(temp_result_limit)
1147 printf("limit=%i&", temp_result_limit);
1148 if(display_type == DISPLAY_HOSTS)
1149 printf("host=%s", (host_name == NULL) ? "all" : url_encode(host_name));
1150 else if(display_type == DISPLAY_SERVICEGROUPS)
1151 printf("servicegroup=%s", url_encode(servicegroup_name));
1152 else {
1153 printf("hostgroup=%s", url_encode(hostgroup_name));
1154 if((service_status_types != all_service_status_types) || group_style_type == STYLE_DETAIL)
1155 printf("&style=detail");
1156 else if(group_style_type == STYLE_HOST_DETAIL)
1157 printf("&style=hostdetail");
1158 }
1159 if(service_status_types != all_service_status_types)
1160 printf("&servicestatustypes=%d", service_status_types);
1161 printf("&hoststatustypes=%d'>", HOST_DOWN);
1162 printf("Down</a></th>\n");
1163
1164 printf("<th class='hostTotals'>");
1165 printf("<a class='hostTotals' href='%s?", STATUS_CGI);
1166 /* paging */
1167 if(temp_result_limit)
1168 printf("limit=%i&", temp_result_limit);
1169 if(display_type == DISPLAY_HOSTS)
1170 printf("host=%s", (host_name == NULL) ? "all" : url_encode(host_name));
1171 else if(display_type == DISPLAY_SERVICEGROUPS)
1172 printf("servicegroup=%s", url_encode(servicegroup_name));
1173 else {
1174 printf("hostgroup=%s", url_encode(hostgroup_name));
1175 if((service_status_types != all_service_status_types) || group_style_type == STYLE_DETAIL)
1176 printf("&style=detail");
1177 else if(group_style_type == STYLE_HOST_DETAIL)
1178 printf("&style=hostdetail");
1179 }
1180 if(service_status_types != all_service_status_types)
1181 printf("&servicestatustypes=%d", service_status_types);
1182 printf("&hoststatustypes=%d'>", HOST_UNREACHABLE);
1183 printf("Unreachable</a></th>\n");
1184
1185 printf("<th class='hostTotals'>");
1186 printf("<a class='hostTotals' href='%s?", STATUS_CGI);
1187 /* paging */
1188 if(temp_result_limit)
1189 printf("limit=%i&", temp_result_limit);
1190 if(display_type == DISPLAY_HOSTS)
1191 printf("host=%s", (host_name == NULL) ? "all" : url_encode(host_name));
1192 else if(display_type == DISPLAY_SERVICEGROUPS)
1193 printf("servicegroup=%s", url_encode(servicegroup_name));
1194 else {
1195 printf("hostgroup=%s", url_encode(hostgroup_name));
1196 if((service_status_types != all_service_status_types) || group_style_type == STYLE_DETAIL)
1197 printf("&style=detail");
1198 else if(group_style_type == STYLE_HOST_DETAIL)
1199 printf("&style=hostdetail");
1200 }
1201 if(service_status_types != all_service_status_types)
1202 printf("&servicestatustypes=%d", service_status_types);
1203 printf("&hoststatustypes=%d'>", HOST_PENDING);
1204 printf("Pending</a></th>\n");
1205
1206 printf("</tr>\n");
1207
1208
1209 printf("<tr>\n");
1210
1211 /* total hosts up */
1212 printf("<td class='hostTotals%s'>%d</td>\n", (total_up > 0) ? "UP" : "", total_up);
1213
1214 /* total hosts down */
1215 printf("<td class='hostTotals%s'>%d</td>\n", (total_down > 0) ? "DOWN" : "", total_down);
1216
1217 /* total hosts unreachable */
1218 printf("<td class='hostTotals%s'>%d</td>\n", (total_unreachable > 0) ? "UNREACHABLE" : "", total_unreachable);
1219
1220 /* total hosts pending */
1221 printf("<td class='hostTotals%s'>%d</td>\n", (total_pending > 0) ? "PENDING" : "", total_pending);
1222
1223 printf("</tr>\n");
1224 printf("</table>\n");
1225
1226 printf("</td></tr><tr><td align='center'>\n");
1227
1228 printf("<table class='hostTotals'>\n");
1229 printf("<tr>\n");
1230
1231 printf("<th class='hostTotals'>");
1232 printf("<a class='hostTotals' href='%s?", STATUS_CGI);
1233 /* paging */
1234 if(temp_result_limit)
1235 printf("limit=%i&", temp_result_limit);
1236 if(display_type == DISPLAY_HOSTS)
1237 printf("host=%s", (host_name == NULL) ? "all" : url_encode(host_name));
1238 else if(display_type == DISPLAY_SERVICEGROUPS)
1239 printf("servicegroup=%s", url_encode(servicegroup_name));
1240 else {
1241 printf("hostgroup=%s", url_encode(hostgroup_name));
1242 if((service_status_types != all_service_status_types) || group_style_type == STYLE_DETAIL)
1243 printf("&style=detail");
1244 else if(group_style_type == STYLE_HOST_DETAIL)
1245 printf("&style=hostdetail");
1246 }
1247 if(service_status_types != all_service_status_types)
1248 printf("&servicestatustypes=%d", service_status_types);
1249 printf("&hoststatustypes=%d'>", HOST_DOWN | HOST_UNREACHABLE);
1250 printf("<em>All Problems</em></a></th>\n");
1251
1252 printf("<th class='hostTotals'>");
1253 printf("<a class='hostTotals' href='%s?", STATUS_CGI);
1254 /* paging */
1255 if(temp_result_limit)
1256 printf("limit=%i&", temp_result_limit);
1257 if(display_type == DISPLAY_HOSTS)
1258 printf("host=%s", (host_name == NULL) ? "all" : url_encode(host_name));
1259 else if(display_type == DISPLAY_SERVICEGROUPS)
1260 printf("servicegroup=%s", url_encode(servicegroup_name));
1261 else {
1262 printf("hostgroup=%s", url_encode(hostgroup_name));
1263 if((service_status_types != all_service_status_types) || group_style_type == STYLE_DETAIL)
1264 printf("&style=detail");
1265 else if(group_style_type == STYLE_HOST_DETAIL)
1266 printf("&style=hostdetail");
1267 }
1268 if(service_status_types != all_service_status_types)
1269 printf("&servicestatustypes=%d", service_status_types);
1270 printf("'>");
1271 printf("<em>All Types</em></a></th>\n");
1272
1273 printf("</tr><tr>\n");
1274
1275 /* total hosts with problems */
1276 printf("<td class='hostTotals%s'>%d</td>\n", (total_problems > 0) ? "PROBLEMS" : "", total_problems);
1277
1278 /* total hosts */
1279 printf("<td class='hostTotals'>%d</td>\n", total_hosts);
1280
1281 printf("</tr>\n");
1282 printf("</table>\n");
1283
1284 printf("</td></tr>\n");
1285 printf("</table>\n");
1286
1287 printf("</div>\n");
1288
1289 return;
1290 }
1291
1292
1293
1294 /* display a detailed listing of the status of all services... */
show_service_detail(void)1295 void show_service_detail(void) {
1296 regex_t preg, preg_hostname;
1297 time_t t;
1298 char date_time[MAX_DATETIME_LENGTH];
1299 char state_duration[48];
1300 char status[MAX_INPUT_BUFFER];
1301 char temp_buffer[MAX_INPUT_BUFFER];
1302 char temp_url[MAX_INPUT_BUFFER];
1303 char *processed_string = NULL;
1304 char *status_class = "";
1305 char *status_bg_class = "";
1306 char *host_status_bg_class = "";
1307 char *last_host = "";
1308 int new_host = FALSE;
1309 servicestatus *temp_status = NULL;
1310 hostgroup *temp_hostgroup = NULL;
1311 servicegroup *temp_servicegroup = NULL;
1312 hoststatus *temp_hoststatus = NULL;
1313 host *temp_host = NULL;
1314 service *temp_service = NULL;
1315 int odd = 0;
1316 int total_comments = 0;
1317 int user_has_seen_something = FALSE;
1318 servicesort *temp_servicesort = NULL;
1319 int use_sort = FALSE;
1320 int result = OK;
1321 int first_entry = TRUE;
1322 int days;
1323 int hours;
1324 int minutes;
1325 int seconds;
1326 int duration_error = FALSE;
1327 int total_entries = 0;
1328 int show_service = FALSE;
1329 int visible_entries = 0;
1330
1331
1332 /* sort the service list if necessary */
1333 if(sort_type != SORT_NONE) {
1334 result = sort_services(sort_type, sort_option);
1335 if(result == ERROR)
1336 use_sort = FALSE;
1337 else
1338 use_sort = TRUE;
1339 }
1340 else
1341 use_sort = FALSE;
1342
1343
1344 printf("<table class='pageTitle' border='0' width='100%%'>\n");
1345 printf("<tr>\n");
1346
1347 printf("<td valign=top align=left width=33%%>\n");
1348
1349 if(display_header == TRUE)
1350 show_filters();
1351
1352 printf("</td>");
1353
1354 printf("<td valign=top align=center width=33%%>\n");
1355
1356 printf("<div align='center' class='statusTitle'>Service Status Details For ");
1357 if(display_type == DISPLAY_HOSTS) {
1358 if(show_all_hosts == TRUE)
1359 printf("All Hosts");
1360 else
1361 printf("Host '%s'", host_name);
1362 }
1363 else if(display_type == DISPLAY_SERVICEGROUPS) {
1364 if(show_all_servicegroups == TRUE)
1365 printf("All Service Groups");
1366 else
1367 printf("Service Group '%s'", url_encode(servicegroup_name));
1368 }
1369 else {
1370 if(show_all_hostgroups == TRUE)
1371 printf("All Host Groups");
1372 else
1373 printf("Host Group '%s'", hostgroup_name);
1374 }
1375 printf("</div>\n");
1376
1377 if(use_sort == TRUE) {
1378 printf("<div align='center' class='statusSort'>Entries sorted by <b>");
1379 if(sort_option == SORT_HOSTNAME)
1380 printf("host name");
1381 else if(sort_option == SORT_SERVICENAME)
1382 printf("service name");
1383 else if(sort_option == SORT_SERVICESTATUS)
1384 printf("service status");
1385 else if(sort_option == SORT_LASTCHECKTIME)
1386 printf("last check time");
1387 else if(sort_option == SORT_CURRENTATTEMPT)
1388 printf("attempt number");
1389 else if(sort_option == SORT_STATEDURATION)
1390 printf("state duration");
1391 printf("</b> (%s)\n", (sort_type == SORT_ASCENDING) ? "ascending" : "descending");
1392 printf("</div>\n");
1393 }
1394
1395 if(service_filter != NULL)
1396 printf("<div align='center' class='statusSort'>Filtered By Services Matching \'%s\'</div>", service_filter);
1397
1398 printf("<br>");
1399
1400 printf("</td>\n");
1401
1402 printf("<td valign=top align=right width=33%%></td>\n");
1403
1404 printf("</tr>\n");
1405 printf("</table>\n");
1406
1407
1408
1409
1410 /* handle navigation GET variables */
1411 snprintf(temp_url, sizeof(temp_url) - 1, "%s?", STATUS_CGI);
1412 temp_url[sizeof(temp_url) - 1] = '\x0';
1413 if(display_type == DISPLAY_HOSTS)
1414 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%shost=%s", (navbar_search == TRUE) ? "&navbarsearch=1&" : "", (host_name == NULL) ? "all" : url_encode(host_name));
1415 else if(display_type == DISPLAY_SERVICEGROUPS)
1416 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "servicegroup=%s&style=detail", url_encode(servicegroup_name));
1417 else
1418 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "hostgroup=%s&style=detail", url_encode(hostgroup_name));
1419 temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
1420 strncat(temp_url, temp_buffer, sizeof(temp_url) - strlen(temp_url) - 1);
1421 temp_url[sizeof(temp_url) - 1] = '\x0';
1422 if(service_status_types != all_service_status_types) {
1423 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "&servicestatustypes=%d", service_status_types);
1424 temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
1425 strncat(temp_url, temp_buffer, sizeof(temp_url) - strlen(temp_url) - 1);
1426 temp_url[sizeof(temp_url) - 1] = '\x0';
1427 }
1428 if(host_status_types != all_host_status_types) {
1429 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "&hoststatustypes=%d", host_status_types);
1430 temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
1431 strncat(temp_url, temp_buffer, sizeof(temp_url) - strlen(temp_url) - 1);
1432 temp_url[sizeof(temp_url) - 1] = '\x0';
1433 }
1434 if(service_properties != 0) {
1435 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "&serviceprops=%lu", service_properties);
1436 temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
1437 strncat(temp_url, temp_buffer, sizeof(temp_url) - strlen(temp_url) - 1);
1438 temp_url[sizeof(temp_url) - 1] = '\x0';
1439 }
1440 if(host_properties != 0) {
1441 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "&hostprops=%lu", host_properties);
1442 temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
1443 strncat(temp_url, temp_buffer, sizeof(temp_url) - strlen(temp_url) - 1);
1444 temp_url[sizeof(temp_url) - 1] = '\x0';
1445 }
1446 /*
1447 if(temp_result_limit) {
1448 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "&limit=%i", temp_result_limit);
1449 temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
1450 strncat(temp_url, temp_buffer, sizeof(temp_url) - strlen(temp_url) - 1);
1451 temp_url[sizeof(temp_url) - 1] = '\x0';
1452 }
1453 */
1454
1455 if(sort_type != SORT_NONE) {
1456 snprintf(temp_buffer, sizeof(temp_buffer), "&sorttype=%i&sortoption=%i", sort_type, sort_option);
1457 temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
1458 strncat(temp_url, temp_buffer, sizeof(temp_url) - strlen(temp_url) - 1);
1459 temp_url[sizeof(temp_url) - 1] = '\x0';
1460 }
1461
1462 /* GET input can override cgi.cfg */
1463 if(limit_results == TRUE)
1464 result_limit = temp_result_limit ? temp_result_limit : result_limit;
1465 else
1466 result_limit = 0;
1467 /* select box to set result limit */
1468 if(result_limit) {
1469 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "&limit=%i", temp_result_limit);
1470 temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
1471 strncat(temp_url, temp_buffer, sizeof(temp_url) - strlen(temp_url) - 1);
1472 temp_url[sizeof(temp_url) - 1] = '\x0';
1473 }
1474 create_page_limiter(result_limit, temp_url);
1475
1476 /* the main list of services */
1477 printf("<table border=0 width=100%% class='status'>\n");
1478 printf("<tr>\n");
1479
1480 printf("<th class='status'>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);
1481
1482 printf("<th class='status'>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);
1483
1484 printf("<th class='status'>Status <a href='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' border=0 ALT='Sort by service status (ascending)' TITLE='Sort by service status (ascending)'></a><a href='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' border=0 ALT='Sort by service status (descending)' TITLE='Sort by service status (descending)'></a></th>", temp_url, SORT_ASCENDING, SORT_SERVICESTATUS, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_SERVICESTATUS, url_images_path, DOWN_ARROW_ICON);
1485
1486 printf("<th class='status'>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);
1487
1488 printf("<th class='status'>Duration <a href='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' border=0 ALT='Sort by state duration (ascending)' TITLE='Sort by state duration (ascending)'></a><a href='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' border=0 ALT='Sort by state duration time (descending)' TITLE='Sort by state duration time (descending)'></a></th>", temp_url, SORT_ASCENDING, SORT_STATEDURATION, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_STATEDURATION, url_images_path, DOWN_ARROW_ICON);
1489
1490 printf("<th class='status'>Attempt <a href='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' border=0 ALT='Sort by current attempt (ascending)' TITLE='Sort by current attempt (ascending)'></a><a href='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' border=0 ALT='Sort by current attempt (descending)' TITLE='Sort by current attempt (descending)'></a></th>", temp_url, SORT_ASCENDING, SORT_CURRENTATTEMPT, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_CURRENTATTEMPT, url_images_path, DOWN_ARROW_ICON);
1491
1492 printf("<th class='status'>Status Information</th>\n");
1493 printf("</tr>\n");
1494
1495
1496 if(service_filter != NULL)
1497 regcomp(&preg, service_filter, 0);
1498 if(host_filter != NULL)
1499 regcomp(&preg_hostname, host_filter, REG_ICASE);
1500
1501 temp_hostgroup = find_hostgroup(hostgroup_name);
1502 temp_servicegroup = find_servicegroup(servicegroup_name);
1503
1504 /* check all services... */
1505 while(1) {
1506
1507 /* get the next service to display */
1508 if(use_sort == TRUE) {
1509 if(first_entry == TRUE)
1510 temp_servicesort = servicesort_list;
1511 else
1512 temp_servicesort = temp_servicesort->next;
1513 if(temp_servicesort == NULL)
1514 break;
1515 temp_status = temp_servicesort->svcstatus;
1516 }
1517 else {
1518 if(first_entry == TRUE)
1519 temp_status = servicestatus_list;
1520 else
1521 temp_status = temp_status->next;
1522 }
1523
1524 if(temp_status == NULL)
1525 break;
1526
1527 first_entry = FALSE;
1528
1529 /* find the service */
1530 temp_service = find_service(temp_status->host_name, temp_status->description);
1531
1532 /* if we couldn't find the service, go to the next service */
1533 if(temp_service == NULL)
1534 continue;
1535
1536 /* find the host */
1537 temp_host = find_host(temp_service->host_name);
1538
1539 /* make sure user has rights to see this... */
1540 if(is_authorized_for_service(temp_service, ¤t_authdata) == FALSE)
1541 continue;
1542
1543 user_has_seen_something = TRUE;
1544
1545 /* get the host status information */
1546 temp_hoststatus = find_hoststatus(temp_service->host_name);
1547
1548 /* see if we should display services for hosts with tis type of status */
1549 if(!(host_status_types & temp_hoststatus->status))
1550 continue;
1551
1552 /* see if we should display this type of service status */
1553 if(!(service_status_types & temp_status->status))
1554 continue;
1555
1556 /* check host properties filter */
1557 if(passes_host_properties_filter(temp_hoststatus) == FALSE)
1558 continue;
1559
1560 /* check service properties filter */
1561 if(passes_service_properties_filter(temp_status) == FALSE)
1562 continue;
1563
1564 /* servicefilter cgi var */
1565 if(service_filter != NULL)
1566 if(regexec(&preg, temp_status->description, 0, NULL, 0))
1567 continue;
1568
1569 show_service = FALSE;
1570
1571 if(display_type == DISPLAY_HOSTS) {
1572 if(show_all_hosts == TRUE)
1573 show_service = TRUE;
1574 else if(host_filter != NULL && 0 == regexec(&preg_hostname, temp_status->host_name, 0, NULL, 0))
1575 show_service = TRUE;
1576 else if(!strcmp(host_name, temp_status->host_name))
1577 show_service = TRUE;
1578 }
1579
1580 else if(display_type == DISPLAY_HOSTGROUPS) {
1581 if(show_all_hostgroups == TRUE)
1582 show_service = TRUE;
1583 else if(is_host_member_of_hostgroup(temp_hostgroup, temp_host) == TRUE)
1584 show_service = TRUE;
1585 }
1586
1587 else if(display_type == DISPLAY_SERVICEGROUPS) {
1588 if(show_all_servicegroups == TRUE)
1589 show_service = TRUE;
1590 else if(is_service_member_of_servicegroup(temp_servicegroup, temp_service) == TRUE)
1591 show_service = TRUE;
1592 }
1593
1594 /* final checks for display visibility, add to total results. Used for page numbers */
1595 if(result_limit == 0)
1596 limit_results = FALSE;
1597
1598 if((limit_results == TRUE && show_service == TRUE) && ((total_entries < page_start) || (total_entries >= (page_start + result_limit)))) {
1599 total_entries++;
1600 show_service = FALSE;
1601 }
1602
1603 /* a visible entry */
1604 if(show_service == TRUE) {
1605 if(strcmp(last_host, temp_status->host_name) || visible_entries == 0)
1606 new_host = TRUE;
1607 else
1608 new_host = FALSE;
1609
1610 if(new_host == TRUE) {
1611 if(strcmp(last_host, "")) {
1612 printf("<tr><td colspan='6'></td></tr>\n");
1613 printf("<tr><td colspan='6'></td></tr>\n");
1614 }
1615 }
1616
1617 if(odd)
1618 odd = 0;
1619 else
1620 odd = 1;
1621
1622 /* keep track of total number of services we're displaying */
1623 visible_entries++;
1624 total_entries++;
1625
1626 /* get the last service check time */
1627 t = temp_status->last_check;
1628 get_time_string(&t, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1629 if((unsigned long)temp_status->last_check == 0L)
1630 strcpy(date_time, "N/A");
1631
1632 if(temp_status->status == SERVICE_PENDING) {
1633 strncpy(status, "PENDING", sizeof(status));
1634 status_class = "PENDING";
1635 status_bg_class = (odd) ? "Even" : "Odd";
1636 }
1637 else if(temp_status->status == SERVICE_OK) {
1638 strncpy(status, "OK", sizeof(status));
1639 status_class = "OK";
1640 status_bg_class = (odd) ? "Even" : "Odd";
1641 }
1642 else if(temp_status->status == SERVICE_WARNING) {
1643 strncpy(status, "WARNING", sizeof(status));
1644 status_class = "WARNING";
1645 if(temp_status->problem_has_been_acknowledged == TRUE)
1646 status_bg_class = "BGWARNINGACK";
1647 else if(temp_status->scheduled_downtime_depth > 0)
1648 status_bg_class = "BGWARNINGSCHED";
1649 else
1650 status_bg_class = "BGWARNING";
1651 }
1652 else if(temp_status->status == SERVICE_UNKNOWN) {
1653 strncpy(status, "UNKNOWN", sizeof(status));
1654 status_class = "UNKNOWN";
1655 if(temp_status->problem_has_been_acknowledged == TRUE)
1656 status_bg_class = "BGUNKNOWNACK";
1657 else if(temp_status->scheduled_downtime_depth > 0)
1658 status_bg_class = "BGUNKNOWNSCHED";
1659 else
1660 status_bg_class = "BGUNKNOWN";
1661 }
1662 else if(temp_status->status == SERVICE_CRITICAL) {
1663 strncpy(status, "CRITICAL", sizeof(status));
1664 status_class = "CRITICAL";
1665 if(temp_status->problem_has_been_acknowledged == TRUE)
1666 status_bg_class = "BGCRITICALACK";
1667 else if(temp_status->scheduled_downtime_depth > 0)
1668 status_bg_class = "BGCRITICALSCHED";
1669 else
1670 status_bg_class = "BGCRITICAL";
1671 }
1672 status[sizeof(status) - 1] = '\x0';
1673
1674
1675 printf("<tr>\n");
1676
1677 /* host name column */
1678 if(new_host == TRUE) {
1679
1680 /* grab macros */
1681 grab_host_macros_r(mac, temp_host);
1682
1683 if(temp_hoststatus->status == HOST_DOWN) {
1684 if(temp_hoststatus->problem_has_been_acknowledged == TRUE)
1685 host_status_bg_class = "HOSTDOWNACK";
1686 else if(temp_hoststatus->scheduled_downtime_depth > 0)
1687 host_status_bg_class = "HOSTDOWNSCHED";
1688 else
1689 host_status_bg_class = "HOSTDOWN";
1690 }
1691 else if(temp_hoststatus->status == HOST_UNREACHABLE) {
1692 if(temp_hoststatus->problem_has_been_acknowledged == TRUE)
1693 host_status_bg_class = "HOSTUNREACHABLEACK";
1694 else if(temp_hoststatus->scheduled_downtime_depth > 0)
1695 host_status_bg_class = "HOSTUNREACHABLESCHED";
1696 else
1697 host_status_bg_class = "HOSTUNREACHABLE";
1698 }
1699 else
1700 host_status_bg_class = (odd) ? "Even" : "Odd";
1701
1702 printf("<td class='status%s'>", host_status_bg_class);
1703
1704 printf("<table border=0 width='100%%' cellpadding=0 cellspacing=0>\n");
1705 printf("<tr>\n");
1706 printf("<td align='left'>\n");
1707 printf("<table border=0 cellpadding=0 cellspacing=0>\n");
1708 printf("<tr>\n");
1709 printf("<td align=left valign=center class='status%s'><a href='%s?type=%d&host=%s' title='%s'>%s</a></td>\n", host_status_bg_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_status->host_name), temp_host->address, temp_status->host_name);
1710 printf("</tr>\n");
1711 printf("</table>\n");
1712 printf("</td>\n");
1713 printf("<td align=right valign=center>\n");
1714 printf("<table border=0 cellpadding=0 cellspacing=0>\n");
1715 printf("<tr>\n");
1716 total_comments = number_of_host_comments(temp_host->name);
1717 if(temp_hoststatus->problem_has_been_acknowledged == TRUE) {
1718 printf("<td ALIGN=center valign=center><a href='%s?type=%d&host=%s#comments'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='This host problem has been acknowledged' TITLE='This host problem has been acknowledged'></a></td>", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_status->host_name), url_images_path, ACKNOWLEDGEMENT_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT);
1719 }
1720 /* only show comments if this is a non-read-only user */
1721 if(is_authorized_for_read_only(¤t_authdata) == FALSE) {
1722 if(total_comments > 0)
1723 printf("<td ALIGN=center valign=center><a href='%s?type=%d&host=%s#comments'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='This host has %d comment%s associated with it' TITLE='This host has %d comment%s associated with it'></a></td>", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_status->host_name), url_images_path, COMMENT_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, total_comments, (total_comments == 1) ? "" : "s", total_comments, (total_comments == 1) ? "" : "s");
1724 }
1725 if(temp_hoststatus->notifications_enabled == FALSE) {
1726 printf("<td ALIGN=center valign=center><a href='%s?type=%d&host=%s'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='Notifications for this host have been disabled' TITLE='Notifications for this host have been disabled'></a></td>", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_status->host_name), url_images_path, NOTIFICATIONS_DISABLED_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT);
1727 }
1728 if(temp_hoststatus->checks_enabled == FALSE) {
1729 printf("<td ALIGN=center valign=center><a href='%s?type=%d&host=%s'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='Checks of this host have been disabled'd TITLE='Checks of this host have been disabled'></a></td>", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_status->host_name), url_images_path, DISABLED_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT);
1730 }
1731 if(temp_hoststatus->is_flapping == TRUE) {
1732 printf("<td ALIGN=center valign=center><a href='%s?type=%d&host=%s'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='This host is flapping between states' TITLE='This host is flapping between states'></a></td>", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_status->host_name), url_images_path, FLAPPING_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT);
1733 }
1734 if(temp_hoststatus->scheduled_downtime_depth > 0) {
1735 printf("<td ALIGN=center valign=center><a href='%s?type=%d&host=%s'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='This host is currently in a period of scheduled downtime' TITLE='This host is currently in a period of scheduled downtime'></a></td>", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_status->host_name), url_images_path, SCHEDULED_DOWNTIME_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT);
1736 }
1737 if(temp_host->notes_url != NULL) {
1738 printf("<td align=center valign=center>");
1739 printf("<a href='");
1740 process_macros_r(mac, temp_host->notes_url, &processed_string, 0);
1741 printf("%s", processed_string);
1742 free(processed_string);
1743 printf("' TARGET='%s'>", (notes_url_target == NULL) ? "_blank" : notes_url_target);
1744 printf("<IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>", url_images_path, NOTES_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, "View Extra Host Notes", "View Extra Host Notes");
1745 printf("</a>");
1746 printf("</td>\n");
1747 }
1748 if(temp_host->action_url != NULL) {
1749 printf("<td align=center valign=center>");
1750 printf("<a href='");
1751 process_macros_r(mac, temp_host->action_url, &processed_string, 0);
1752 printf("%s", processed_string);
1753 free(processed_string);
1754 printf("' TARGET='%s'>", (action_url_target == NULL) ? "_blank" : action_url_target);
1755 printf("<IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>", url_images_path, ACTION_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, "Perform Extra Host Actions", "Perform Extra Host Actions");
1756 printf("</a>");
1757 printf("</td>\n");
1758 }
1759 if(temp_host->icon_image != NULL) {
1760 printf("<td align=center valign=center>");
1761 printf("<a href='%s?type=%d&host=%s'>", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_status->host_name));
1762 printf("<IMG SRC='%s", url_logo_images_path);
1763 process_macros_r(mac, temp_host->icon_image, &processed_string, 0);
1764 printf("%s", processed_string);
1765 free(processed_string);
1766 printf("' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>", STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, (temp_host->icon_image_alt == NULL) ? "" : temp_host->icon_image_alt, (temp_host->icon_image_alt == NULL) ? "" : temp_host->icon_image_alt);
1767 printf("</a>");
1768 printf("</td>\n");
1769 }
1770 printf("</tr>\n");
1771 printf("</table>\n");
1772 printf("</td>\n");
1773 printf("</tr>\n");
1774 printf("</table>\n");
1775 }
1776 else
1777 printf("<td>");
1778 printf("</td>\n");
1779
1780 /* grab macros */
1781 grab_service_macros_r(mac, temp_service);
1782
1783 /* service name column */
1784 printf("<td class='status%s'>", status_bg_class);
1785 printf("<table border=0 WIDTH='100%%' cellspacing=0 cellpadding=0>");
1786 printf("<tr>");
1787 printf("<td align='left'>");
1788 printf("<table border=0 cellspacing=0 cellpadding=0>\n");
1789 printf("<tr>\n");
1790 printf("<td align='left' valign=center class='status%s'><a href='%s?type=%d&host=%s", status_bg_class, EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(temp_status->host_name));
1791 printf("&service=%s'>", url_encode(temp_status->description));
1792 printf("%s</a></td>", temp_status->description);
1793 printf("</tr>\n");
1794 printf("</table>\n");
1795 printf("</td>\n");
1796 printf("<td ALIGN=RIGHT class='status%s'>\n", status_bg_class);
1797 printf("<table border=0 cellspacing=0 cellpadding=0>\n");
1798 printf("<tr>\n");
1799 total_comments = number_of_service_comments(temp_service->host_name, temp_service->description);
1800 /* only show comments if this is a non-read-only user */
1801 if(is_authorized_for_read_only(¤t_authdata) == FALSE) {
1802 if(total_comments > 0) {
1803 printf("<td ALIGN=center valign=center><a href='%s?type=%d&host=%s", EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(temp_status->host_name));
1804 printf("&service=%s#comments'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='This service has %d comment%s associated with it' TITLE='This service has %d comment%s associated with it'></a></td>", url_encode(temp_status->description), url_images_path, COMMENT_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, total_comments, (total_comments == 1) ? "" : "s", total_comments, (total_comments == 1) ? "" : "s");
1805 }
1806 }
1807 if(temp_status->problem_has_been_acknowledged == TRUE) {
1808 printf("<td ALIGN=center valign=center><a href='%s?type=%d&host=%s", EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(temp_status->host_name));
1809 printf("&service=%s#comments'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='This service problem has been acknowledged' TITLE='This service problem has been acknowledged'></a></td>", url_encode(temp_status->description), url_images_path, ACKNOWLEDGEMENT_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT);
1810 }
1811 if(temp_status->checks_enabled == FALSE && temp_status->accept_passive_service_checks == FALSE) {
1812 printf("<td ALIGN=center valign=center><a href='%s?type=%d&host=%s", EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(temp_status->host_name));
1813 printf("&service=%s'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='Active and passive checks have been disabled for this service' TITLE='Active and passive checks have been disabled for this service'></a></td>", url_encode(temp_status->description), url_images_path, DISABLED_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT);
1814 }
1815 else if(temp_status->checks_enabled == FALSE) {
1816 printf("<td ALIGN=center valign=center><a href='%s?type=%d&host=%s", EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(temp_status->host_name));
1817 printf("&service=%s'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='Active checks of the service have been disabled - only passive checks are being accepted' TITLE='Active checks of the service have been disabled - only passive checks are being accepted'></a></td>", url_encode(temp_status->description), url_images_path, PASSIVE_ONLY_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT);
1818 }
1819 if(temp_status->notifications_enabled == FALSE) {
1820 printf("<td ALIGN=center valign=center><a href='%s?type=%d&host=%s", EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(temp_status->host_name));
1821 printf("&service=%s'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='Notifications for this service have been disabled' TITLE='Notifications for this service have been disabled'></a></td>", url_encode(temp_status->description), url_images_path, NOTIFICATIONS_DISABLED_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT);
1822 }
1823 if(temp_status->is_flapping == TRUE) {
1824 printf("<td ALIGN=center valign=center><a href='%s?type=%d&host=%s", EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(temp_status->host_name));
1825 printf("&service=%s'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='This service is flapping between states' TITLE='This service is flapping between states'></a></td>", url_encode(temp_status->description), url_images_path, FLAPPING_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT);
1826 }
1827 if(temp_status->scheduled_downtime_depth > 0) {
1828 printf("<td ALIGN=center valign=center><a href='%s?type=%d&host=%s", EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(temp_status->host_name));
1829 printf("&service=%s'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='This service is currently in a period of scheduled downtime' TITLE='This service is currently in a period of scheduled downtime'></a></td>", url_encode(temp_status->description), url_images_path, SCHEDULED_DOWNTIME_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT);
1830 }
1831 if(temp_service->notes_url != NULL) {
1832 printf("<td align=center valign=center>");
1833 printf("<a href='");
1834 process_macros_r(mac, temp_service->notes_url, &processed_string, 0);
1835 printf("%s", processed_string);
1836 free(processed_string);
1837 printf("' TARGET='%s'>", (notes_url_target == NULL) ? "_blank" : notes_url_target);
1838 printf("<IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>", url_images_path, NOTES_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, "View Extra Service Notes", "View Extra Service Notes");
1839 printf("</a>");
1840 printf("</td>\n");
1841 }
1842 if(temp_service->action_url != NULL) {
1843 printf("<td align=center valign=center>");
1844 printf("<a href='");
1845 process_macros_r(mac, temp_service->action_url, &processed_string, 0);
1846 printf("%s", processed_string);
1847 free(processed_string);
1848 printf("' TARGET='%s'>", (action_url_target == NULL) ? "_blank" : action_url_target);
1849 printf("<IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>", url_images_path, ACTION_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, "Perform Extra Service Actions", "Perform Extra Service Actions");
1850 printf("</a>");
1851 printf("</td>\n");
1852 }
1853 if(temp_service->icon_image != NULL) {
1854 printf("<td ALIGN=center valign=center>");
1855 printf("<a href='%s?type=%d&host=%s", EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(temp_service->host_name));
1856 printf("&service=%s'>", url_encode(temp_service->description));
1857 printf("<IMG SRC='%s", url_logo_images_path);
1858 process_macros_r(mac, temp_service->icon_image, &processed_string, 0);
1859 printf("%s", processed_string);
1860 free(processed_string);
1861 printf("' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>", STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, (temp_service->icon_image_alt == NULL) ? "" : temp_service->icon_image_alt, (temp_service->icon_image_alt == NULL) ? "" : temp_service->icon_image_alt);
1862 printf("</a>");
1863 printf("</td>\n");
1864 }
1865 if(enable_splunk_integration == TRUE) {
1866 printf("<td ALIGN=center valign=center>");
1867 display_splunk_service_url(temp_service);
1868 printf("</td>\n");
1869 }
1870 printf("</tr>\n");
1871 printf("</table>\n");
1872 printf("</td>\n");
1873 printf("</tr>");
1874 printf("</table>");
1875 printf("</td>\n");
1876
1877 /* state duration calculation... */
1878 t = 0;
1879 duration_error = FALSE;
1880 if(temp_status->last_state_change == (time_t)0) {
1881 if(program_start > current_time)
1882 duration_error = TRUE;
1883 else
1884 t = current_time - program_start;
1885 }
1886 else {
1887 if(temp_status->last_state_change > current_time)
1888 duration_error = TRUE;
1889 else
1890 t = current_time - temp_status->last_state_change;
1891 }
1892 get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds);
1893 if(duration_error == TRUE)
1894 snprintf(state_duration, sizeof(state_duration) - 1, "???");
1895 else
1896 snprintf(state_duration, sizeof(state_duration) - 1, "%2dd %2dh %2dm %2ds%s", days, hours, minutes, seconds, (temp_status->last_state_change == (time_t)0) ? "+" : "");
1897 state_duration[sizeof(state_duration) - 1] = '\x0';
1898
1899 /* the rest of the columns... */
1900 printf("<td class='status%s'>%s</td>\n", status_class, status);
1901 printf("<td class='status%s' nowrap>%s</td>\n", status_bg_class, date_time);
1902 printf("<td class='status%s' nowrap>%s</td>\n", status_bg_class, state_duration);
1903 printf("<td class='status%s'>%d/%d</td>\n", status_bg_class, temp_status->current_attempt, temp_status->max_attempts);
1904 printf("<td class='status%s' valign='center'>", status_bg_class);
1905 printf("%s ", (temp_status->plugin_output == NULL) ? "" : html_encode(temp_status->plugin_output, TRUE));
1906 /*
1907 if(enable_splunk_integration==TRUE)
1908 display_splunk_service_url(temp_service);
1909 */
1910 printf("</td>\n");
1911
1912 printf("</tr>\n");
1913
1914 /* mod to account for paging */
1915 if(visible_entries != 0)
1916 last_host = temp_status->host_name;
1917 }
1918
1919 }
1920
1921 printf("</table>\n");
1922
1923 /* if user couldn't see anything, print out some helpful info... */
1924 if(user_has_seen_something == FALSE) {
1925
1926 if(servicestatus_list != NULL) {
1927 printf("<P><div class='errorMessage'>It appears as though you do not have permission to view information for any of the services you requested...</div></P>\n");
1928 printf("<P><div class='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
1929 printf("and check the authorization options in your CGI configuration file.</div></P>\n");
1930 }
1931 else {
1932 printf("<p><div class='infoMessage'>There doesn't appear to be any service status information in the status log...<br><br>\n");
1933 printf("Make sure that Nagios is running and that you have specified the location of you status log correctly in the configuration files.</div></p>\n");
1934 }
1935 }
1936 else {
1937 /* do page numbers if applicable */
1938 create_pagenumbers(total_entries, visible_entries, temp_url, TRUE);
1939 }
1940
1941 return;
1942 }
1943
1944
1945
1946
1947 /* display a detailed listing of the status of all hosts... */
show_host_detail(void)1948 void show_host_detail(void) {
1949 time_t t;
1950 char date_time[MAX_DATETIME_LENGTH];
1951 char state_duration[48];
1952 char status[MAX_INPUT_BUFFER];
1953 char temp_buffer[MAX_INPUT_BUFFER];
1954 char temp_url[MAX_INPUT_BUFFER];
1955 char *processed_string = NULL;
1956 char *status_class = "";
1957 char *status_bg_class = "";
1958 hoststatus *temp_status = NULL;
1959 hostgroup *temp_hostgroup = NULL;
1960 host *temp_host = NULL;
1961 hostsort *temp_hostsort = NULL;
1962 int odd = 0;
1963 int total_comments = 0;
1964 int user_has_seen_something = FALSE;
1965 int use_sort = FALSE;
1966 int result = OK;
1967 int first_entry = TRUE;
1968 int days;
1969 int hours;
1970 int minutes;
1971 int seconds;
1972 int duration_error = FALSE;
1973 int total_entries = 0;
1974 int visible_entries = 0;
1975 // int show_host = FALSE;
1976
1977
1978 /* sort the host list if necessary */
1979 if(sort_type != SORT_NONE) {
1980 result = sort_hosts(sort_type, sort_option);
1981 if(result == ERROR)
1982 use_sort = FALSE;
1983 else
1984 use_sort = TRUE;
1985 }
1986 else
1987 use_sort = FALSE;
1988
1989
1990 // printf("<P>\n");
1991
1992
1993 printf("<table class='pageTitle' border='0' width='100%%'>\n");
1994 printf("<tr>\n");
1995
1996 printf("<td valign=top align=left width=33%%>\n");
1997
1998 if(display_header == TRUE)
1999 show_filters();
2000
2001 printf("</td>");
2002
2003 printf("<td valign=top align=center width=33%%>\n");
2004
2005 printf("<div align='center' class='statusTitle'>Host Status Details For ");
2006 if(show_all_hostgroups == TRUE)
2007 printf("All Host Groups");
2008 else
2009 printf("Host Group '%s'", hostgroup_name);
2010 printf("</div>\n");
2011
2012 if(use_sort == TRUE) {
2013 printf("<div align='center' class='statusSort'>Entries sorted by <b>");
2014 if(sort_option == SORT_HOSTNAME)
2015 printf("host name");
2016 else if(sort_option == SORT_HOSTSTATUS)
2017 printf("host status");
2018 else if(sort_option == SORT_HOSTURGENCY)
2019 printf("host urgency");
2020 else if(sort_option == SORT_LASTCHECKTIME)
2021 printf("last check time");
2022 else if(sort_option == SORT_CURRENTATTEMPT)
2023 printf("attempt number");
2024 else if(sort_option == SORT_STATEDURATION)
2025 printf("state duration");
2026 printf("</b> (%s)\n", (sort_type == SORT_ASCENDING) ? "ascending" : "descending");
2027 printf("</div>\n");
2028 }
2029
2030 printf("<br>");
2031
2032 printf("</td>\n");
2033
2034 printf("<td valign=top align=right width=33%%></td>\n");
2035
2036 printf("</tr>\n");
2037 printf("</table>\n");
2038
2039
2040
2041
2042
2043 snprintf(temp_url, sizeof(temp_url) - 1, "%s?", STATUS_CGI);
2044 temp_url[sizeof(temp_url) - 1] = '\x0';
2045 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "hostgroup=%s&style=hostdetail", url_encode(hostgroup_name));
2046 temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
2047 strncat(temp_url, temp_buffer, sizeof(temp_url) - strlen(temp_url) - 1);
2048 temp_url[sizeof(temp_url) - 1] = '\x0';
2049 if(service_status_types != all_service_status_types) {
2050 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "&servicestatustypes=%d", service_status_types);
2051 temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
2052 strncat(temp_url, temp_buffer, sizeof(temp_url) - strlen(temp_url) - 1);
2053 temp_url[sizeof(temp_url) - 1] = '\x0';
2054 }
2055 if(host_status_types != all_host_status_types) {
2056 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "&hoststatustypes=%d", host_status_types);
2057 temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
2058 strncat(temp_url, temp_buffer, sizeof(temp_url) - strlen(temp_url) - 1);
2059 temp_url[sizeof(temp_url) - 1] = '\x0';
2060 }
2061 if(service_properties != 0) {
2062 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "&serviceprops=%lu", service_properties);
2063 temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
2064 strncat(temp_url, temp_buffer, sizeof(temp_url) - strlen(temp_url) - 1);
2065 temp_url[sizeof(temp_url) - 1] = '\x0';
2066 }
2067 if(host_properties != 0) {
2068 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "&hostprops=%lu", host_properties);
2069 temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
2070 strncat(temp_url, temp_buffer, sizeof(temp_url) - strlen(temp_url) - 1);
2071 temp_url[sizeof(temp_url) - 1] = '\x0';
2072 }
2073 /*
2074 if(temp_result_limit) {
2075 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "&limit=%i", temp_result_limit);
2076 temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
2077 strncat(temp_url, temp_buffer, sizeof(temp_url) - strlen(temp_url) - 1);
2078 temp_url[sizeof(temp_url) - 1] = '\x0';
2079 }
2080 */
2081
2082 /* GET input can override cgi.cfg */
2083 if(limit_results == TRUE)
2084 result_limit = temp_result_limit ? temp_result_limit : result_limit;
2085 else
2086 result_limit = 0;
2087 /* select box to set result limit */
2088 create_page_limiter(result_limit, temp_url);
2089
2090
2091 /* the main list of hosts */
2092 printf("<div align='center'>\n");
2093 printf("<table border=0 class='status' width='100%%'>\n");
2094 printf("<tr>\n");
2095
2096 printf("<th class='status'>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);
2097
2098 printf("<th class='status'>Status <a href='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' border=0 ALT='Sort by host status (ascending)' TITLE='Sort by host status (ascending)'></a><a href='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' border=0 ALT='Sort by host status (descending)' TITLE='Sort by host status (descending)'></a></th>", temp_url, SORT_ASCENDING, SORT_HOSTSTATUS, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_HOSTSTATUS, url_images_path, DOWN_ARROW_ICON);
2099
2100 printf("<th class='status'>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);
2101
2102 printf("<th class='status'>Duration <a href='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' border=0 ALT='Sort by state duration (ascending)' TITLE='Sort by state duration (ascending)'></a><a href='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' border=0 ALT='Sort by state duration time (descending)' TITLE='Sort by state duration time (descending)'></a></th>", temp_url, SORT_ASCENDING, SORT_STATEDURATION, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_STATEDURATION, url_images_path, DOWN_ARROW_ICON);
2103
2104 printf("<th class='status'>Status Information</th>\n");
2105 printf("</tr>\n");
2106
2107
2108 /* check all hosts... */
2109 while(1) {
2110
2111 /* get the next service to display */
2112 if(use_sort == TRUE) {
2113 if(first_entry == TRUE)
2114 temp_hostsort = hostsort_list;
2115 else
2116 temp_hostsort = temp_hostsort->next;
2117 if(temp_hostsort == NULL)
2118 break;
2119 temp_status = temp_hostsort->hststatus;
2120 }
2121 else {
2122 if(first_entry == TRUE)
2123 temp_status = hoststatus_list;
2124 else
2125 temp_status = temp_status->next;
2126 }
2127
2128 if(temp_status == NULL)
2129 break;
2130
2131 first_entry = FALSE;
2132
2133 /* find the host */
2134 temp_host = find_host(temp_status->host_name);
2135
2136 /* if we couldn't find the host, go to the next status entry */
2137 if(temp_host == NULL)
2138 continue;
2139
2140 /* make sure user has rights to see this... */
2141 if(is_authorized_for_host(temp_host, ¤t_authdata) == FALSE)
2142 continue;
2143
2144 user_has_seen_something = TRUE;
2145
2146 /* see if we should display services for hosts with this type of status */
2147 if(!(host_status_types & temp_status->status))
2148 continue;
2149
2150 /* check host properties filter */
2151 if(passes_host_properties_filter(temp_status) == FALSE)
2152 continue;
2153
2154
2155 /* see if this host is a member of the hostgroup */
2156 if(show_all_hostgroups == FALSE) {
2157 temp_hostgroup = find_hostgroup(hostgroup_name);
2158 if(temp_hostgroup == NULL)
2159 continue;
2160 if(is_host_member_of_hostgroup(temp_hostgroup, temp_host) == FALSE)
2161 continue;
2162 }
2163
2164
2165
2166 total_entries++;
2167
2168 /* final checks for display visibility, add to total results. Used for page numbers */
2169 if(result_limit == 0)
2170 limit_results = FALSE;
2171
2172 if((limit_results == TRUE) && ((total_entries < page_start) || (total_entries >= (page_start + result_limit)))) {
2173 continue;
2174 }
2175
2176 visible_entries++;
2177
2178
2179 /* grab macros */
2180 grab_host_macros_r(mac, temp_host);
2181
2182
2183 if(display_type == DISPLAY_HOSTGROUPS) {
2184
2185 if(odd)
2186 odd = 0;
2187 else
2188 odd = 1;
2189
2190
2191 /* get the last host check time */
2192 t = temp_status->last_check;
2193 get_time_string(&t, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2194 if((unsigned long)temp_status->last_check == 0L)
2195 strcpy(date_time, "N/A");
2196
2197 if(temp_status->status == HOST_PENDING) {
2198 strncpy(status, "PENDING", sizeof(status));
2199 status_class = "PENDING";
2200 status_bg_class = (odd) ? "Even" : "Odd";
2201 }
2202 else if(temp_status->status == HOST_UP) {
2203 strncpy(status, "UP", sizeof(status));
2204 status_class = "HOSTUP";
2205 status_bg_class = (odd) ? "Even" : "Odd";
2206 }
2207 else if(temp_status->status == HOST_DOWN) {
2208 strncpy(status, "DOWN", sizeof(status));
2209 status_class = "HOSTDOWN";
2210 if(temp_status->problem_has_been_acknowledged == TRUE)
2211 status_bg_class = "BGDOWNACK";
2212 else if(temp_status->scheduled_downtime_depth > 0)
2213 status_bg_class = "BGDOWNSCHED";
2214 else
2215 status_bg_class = "BGDOWN";
2216 }
2217 else if(temp_status->status == HOST_UNREACHABLE) {
2218 strncpy(status, "UNREACHABLE", sizeof(status));
2219 status_class = "HOSTUNREACHABLE";
2220 if(temp_status->problem_has_been_acknowledged == TRUE)
2221 status_bg_class = "BGUNREACHABLEACK";
2222 else if(temp_status->scheduled_downtime_depth > 0)
2223 status_bg_class = "BGUNREACHABLESCHED";
2224 else
2225 status_bg_class = "BGUNREACHABLE";
2226 }
2227 status[sizeof(status) - 1] = '\x0';
2228
2229
2230 printf("<tr>\n");
2231
2232
2233 /**** host name column ****/
2234
2235 printf("<td class='status%s'>", status_class);
2236
2237 printf("<table border=0 WIDTH='100%%' cellpadding=0 cellspacing=0>\n");
2238 printf("<tr>\n");
2239 printf("<td align='left'>\n");
2240 printf("<table border=0 cellpadding=0 cellspacing=0>\n");
2241 printf("<tr>\n");
2242 printf("<td align=left valign=center class='status%s'><a href='%s?type=%d&host=%s' title='%s'>%s</a> </td>\n", status_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_status->host_name), temp_host->address, temp_status->host_name);
2243 printf("</tr>\n");
2244 printf("</table>\n");
2245 printf("</td>\n");
2246 printf("<td align=right valign=center>\n");
2247 printf("<table border=0 cellpadding=0 cellspacing=0>\n");
2248 printf("<tr>\n");
2249 total_comments = number_of_host_comments(temp_host->name);
2250 if(temp_status->problem_has_been_acknowledged == TRUE) {
2251 printf("<td ALIGN=center valign=center><a href='%s?type=%d&host=%s#comments'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='This host problem has been acknowledged' TITLE='This host problem has been acknowledged'></a></td>", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_status->host_name), url_images_path, ACKNOWLEDGEMENT_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT);
2252 }
2253 if(total_comments > 0)
2254 printf("<td ALIGN=center valign=center><a href='%s?type=%d&host=%s#comments'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='This host has %d comment%s associated with it' TITLE='This host has %d comment%s associated with it'></a></td>", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_status->host_name), url_images_path, COMMENT_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, total_comments, (total_comments == 1) ? "" : "s", total_comments, (total_comments == 1) ? "" : "s");
2255 if(temp_status->notifications_enabled == FALSE) {
2256 printf("<td ALIGN=center valign=center><a href='%s?type=%d&host=%s'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='Notifications for this host have been disabled' TITLE='Notifications for this host have been disabled'></a></td>", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_status->host_name), url_images_path, NOTIFICATIONS_DISABLED_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT);
2257 }
2258 if(temp_status->checks_enabled == FALSE) {
2259 printf("<td ALIGN=center valign=center><a href='%s?type=%d&host=%s'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='Checks of this host have been disabled' TITLE='Checks of this host have been disabled'></a></td>", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_status->host_name), url_images_path, DISABLED_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT);
2260 }
2261 if(temp_status->is_flapping == TRUE) {
2262 printf("<td ALIGN=center valign=center><a href='%s?type=%d&host=%s'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='This host is flapping between states' TITLE='This host is flapping between states'></a></td>", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_status->host_name), url_images_path, FLAPPING_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT);
2263 }
2264 if(temp_status->scheduled_downtime_depth > 0) {
2265 printf("<td ALIGN=center valign=center><a href='%s?type=%d&host=%s'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='This host is currently in a period of scheduled downtime' TITLE='This host is currently in a period of scheduled downtime'></a></td>", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_status->host_name), url_images_path, SCHEDULED_DOWNTIME_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT);
2266 }
2267 if(temp_host->notes_url != NULL) {
2268 printf("<td align=center valign=center>");
2269 printf("<a href='");
2270 process_macros_r(mac, temp_host->notes_url, &processed_string, 0);
2271 printf("%s", processed_string);
2272 free(processed_string);
2273 printf("' TARGET='%s'>", (notes_url_target == NULL) ? "_blank" : notes_url_target);
2274 printf("<IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>", url_images_path, NOTES_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, "View Extra Host Notes", "View Extra Host Notes");
2275 printf("</a>");
2276 printf("</td>\n");
2277 }
2278 if(temp_host->action_url != NULL) {
2279 printf("<td align=center valign=center>");
2280 printf("<a href='");
2281 process_macros_r(mac, temp_host->action_url, &processed_string, 0);
2282 printf("%s", processed_string);
2283 free(processed_string);
2284 printf("' TARGET='%s'>", (action_url_target == NULL) ? "_blank" : action_url_target);
2285 printf("<IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>", url_images_path, ACTION_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, "Perform Extra Host Actions", "Perform Extra Host Actions");
2286 printf("</a>");
2287 printf("</td>\n");
2288 }
2289 if(temp_host->icon_image != NULL) {
2290 printf("<td align=center valign=center>");
2291 printf("<a href='%s?type=%d&host=%s'>", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_status->host_name));
2292 printf("<IMG SRC='%s", url_logo_images_path);
2293 process_macros_r(mac, temp_host->icon_image, &processed_string, 0);
2294 printf("%s", processed_string);
2295 free(processed_string);
2296 printf("' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>", STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, (temp_host->icon_image_alt == NULL) ? "" : temp_host->icon_image_alt, (temp_host->icon_image_alt == NULL) ? "" : temp_host->icon_image_alt);
2297 printf("</a>");
2298 printf("</td>\n");
2299 }
2300 if(enable_splunk_integration == TRUE) {
2301 printf("<td ALIGN=center valign=center>");
2302 display_splunk_host_url(temp_host);
2303 printf("</td>\n");
2304 }
2305 printf("<td>");
2306 printf("<a href='%s?host=%s'><img src='%s%s' border=0 alt='View Service Details For This Host' title='View Service Details For This Host'></a>", STATUS_CGI, url_encode(temp_status->host_name), url_images_path, STATUS_DETAIL_ICON);
2307 printf("</td>\n");
2308 printf("</tr>\n");
2309 printf("</table>\n");
2310 printf("</td>\n");
2311 printf("</tr>\n");
2312 printf("</table>\n");
2313
2314 printf("</td>\n");
2315
2316
2317 /* state duration calculation... */
2318 t = 0;
2319 duration_error = FALSE;
2320 if(temp_status->last_state_change == (time_t)0) {
2321 if(program_start > current_time)
2322 duration_error = TRUE;
2323 else
2324 t = current_time - program_start;
2325 }
2326 else {
2327 if(temp_status->last_state_change > current_time)
2328 duration_error = TRUE;
2329 else
2330 t = current_time - temp_status->last_state_change;
2331 }
2332 get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds);
2333 if(duration_error == TRUE)
2334 snprintf(state_duration, sizeof(state_duration) - 1, "???");
2335 else
2336 snprintf(state_duration, sizeof(state_duration) - 1, "%2dd %2dh %2dm %2ds%s", days, hours, minutes, seconds, (temp_status->last_state_change == (time_t)0) ? "+" : "");
2337 state_duration[sizeof(state_duration) - 1] = '\x0';
2338
2339 /* the rest of the columns... */
2340 printf("<td class='status%s'>%s</td>\n", status_class, status);
2341 printf("<td class='status%s' nowrap>%s</td>\n", status_bg_class, date_time);
2342 printf("<td class='status%s' nowrap>%s</td>\n", status_bg_class, state_duration);
2343 printf("<td class='status%s' valign='center'>", status_bg_class);
2344 printf("%s ", (temp_status->plugin_output == NULL) ? "" : html_encode(temp_status->plugin_output, TRUE));
2345 /*
2346 if(enable_splunk_integration==TRUE)
2347 display_splunk_host_url(temp_host);
2348 */
2349 printf("</td>\n");
2350
2351 printf("</tr>\n");
2352 }
2353
2354 }
2355
2356 printf("</table>\n");
2357 printf("</div>\n");
2358
2359 /* if user couldn't see anything, print out some helpful info... */
2360 if(user_has_seen_something == FALSE) {
2361
2362 if(hoststatus_list != NULL) {
2363 printf("<P><div class='errorMessage'>It appears as though you do not have permission to view information for any of the hosts you requested...</div></P>\n");
2364 printf("<P><div class='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
2365 printf("and check the authorization options in your CGI configuration file.</div></P>\n");
2366 }
2367 else {
2368 printf("<P><div class='infoMessage'>There doesn't appear to be any host status information in the status log...<br><br>\n");
2369 printf("Make sure that Nagios is running and that you have specified the location of you status log correctly in the configuration files.</div></P>\n");
2370 }
2371 }
2372
2373 else {
2374 /* do page numbers if applicable */
2375 create_pagenumbers(total_entries, visible_entries, temp_url, FALSE);
2376 }
2377 return;
2378 }
2379
2380
2381
2382
2383 /* show an overview of servicegroup(s)... */
show_servicegroup_overviews(void)2384 void show_servicegroup_overviews(void) {
2385 servicegroup *temp_servicegroup = NULL;
2386 int current_column;
2387 int user_has_seen_something = FALSE;
2388 int servicegroup_error = FALSE;
2389
2390
2391 //printf("<P>\n");
2392
2393 printf("<table border=0 width=100%%>\n");
2394 printf("<tr>\n");
2395
2396 printf("<td valign=top align=left width=33%%>\n");
2397
2398 show_filters();
2399
2400 printf("</td>");
2401
2402 printf("<td valign=top align=center width=33%%>\n");
2403
2404 printf("<div align='center' class='statusTitle'>Service Overview For ");
2405 if(show_all_servicegroups == TRUE)
2406 printf("All Service Groups");
2407 else
2408 printf("Service Group '%s'", servicegroup_name);
2409 printf("</div>\n");
2410
2411 printf("<br>");
2412
2413 printf("</td>\n");
2414
2415 printf("<td valign=top align=right width=33%%></td>\n");
2416
2417 printf("</tr>\n");
2418 printf("</table>\n");
2419
2420 //printf("</P>\n");
2421
2422
2423 /* display status overviews for all servicegroups */
2424 if(show_all_servicegroups == TRUE) {
2425
2426
2427 printf("<div ALIGN=center>\n");
2428 printf("<table border=0 cellpadding=10>\n");
2429
2430 current_column = 1;
2431
2432 /* loop through all servicegroups... */
2433 for(temp_servicegroup = servicegroup_list; temp_servicegroup != NULL; temp_servicegroup = temp_servicegroup->next) {
2434
2435 /* make sure the user is authorized to view at least one host in this servicegroup */
2436 if(is_authorized_for_servicegroup(temp_servicegroup, ¤t_authdata) == FALSE)
2437 continue;
2438
2439 if(current_column == 1)
2440 printf("<tr>\n");
2441 printf("<td VALIGN=top ALIGN=center>\n");
2442
2443 show_servicegroup_overview(temp_servicegroup);
2444
2445 user_has_seen_something = TRUE;
2446
2447 printf("</td>\n");
2448 if(current_column == overview_columns)
2449 printf("</tr>\n");
2450
2451 if(current_column < overview_columns)
2452 current_column++;
2453 else
2454 current_column = 1;
2455 }
2456
2457 if(current_column != 1) {
2458
2459 for(; current_column <= overview_columns; current_column++)
2460 printf("<td></td>\n");
2461 printf("</tr>\n");
2462 }
2463
2464 printf("</table>\n");
2465 printf("</div>\n");
2466 }
2467
2468 /* else display overview for just a specific servicegroup */
2469 else {
2470
2471 temp_servicegroup = find_servicegroup(servicegroup_name);
2472 if(temp_servicegroup != NULL) {
2473
2474 //printf("<P>\n");
2475 printf("<div align='center'>\n");
2476 printf("<table border=0 cellpadding=0 cellspacing=0><tr><td align='center'>\n");
2477
2478 if(is_authorized_for_servicegroup(temp_servicegroup, ¤t_authdata) == TRUE) {
2479
2480 show_servicegroup_overview(temp_servicegroup);
2481
2482 user_has_seen_something = TRUE;
2483 }
2484
2485 printf("</td></tr></table>\n");
2486 printf("</div>\n");
2487 //printf("</P>\n");
2488 }
2489 else {
2490 printf("<div class='errorMessage'>Sorry, but service group '%s' doesn't seem to exist...</div>", servicegroup_name);
2491 servicegroup_error = TRUE;
2492 }
2493 }
2494
2495 /* if user couldn't see anything, print out some helpful info... */
2496 if(user_has_seen_something == FALSE && servicegroup_error == FALSE) {
2497
2498 //printf("<p>\n");
2499 printf("<div align='center'>\n");
2500
2501 if(servicegroup_list != NULL) {
2502 printf("<div class='errorMessage'>It appears as though you do not have permission to view information for any of the hosts you requested...</div>\n");
2503 printf("<div class='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
2504 printf("and check the authorization options in your CGI configuration file.</div>\n");
2505 }
2506 else {
2507 printf("<div class='errorMessage'>There are no service groups defined.</div>\n");
2508 }
2509
2510 printf("</div>\n");
2511 //printf("</p>\n");
2512 }
2513
2514 return;
2515 }
2516
2517
2518
2519 /* shows an overview of a specific servicegroup... */
show_servicegroup_overview(servicegroup * temp_servicegroup)2520 void show_servicegroup_overview(servicegroup *temp_servicegroup) {
2521 servicesmember *temp_member;
2522 host *temp_host;
2523 host *last_host;
2524 hoststatus *temp_hoststatus = NULL;
2525 int odd = 0;
2526
2527
2528 printf("<div class='status'>\n");
2529 printf("<a href='%s?servicegroup=%s&style=detail'>%s</a>", STATUS_CGI, url_encode(temp_servicegroup->group_name), temp_servicegroup->alias);
2530 printf(" (<a href='%s?type=%d&servicegroup=%s'>%s</a>)", EXTINFO_CGI, DISPLAY_SERVICEGROUP_INFO, url_encode(temp_servicegroup->group_name), temp_servicegroup->group_name);
2531 printf("</div>\n");
2532
2533 printf("<div class='status'>\n");
2534 printf("<table class='status'>\n");
2535
2536 printf("<tr>\n");
2537 printf("<th class='status'>Host</th><th class='status'>Status</th><th class='status'>Services</th><th class='status'>Actions</th>\n");
2538 printf("</tr>\n");
2539
2540 /* find all hosts that have services that are members of the servicegroup */
2541 last_host = NULL;
2542 for(temp_member = temp_servicegroup->members; temp_member != NULL; temp_member = temp_member->next) {
2543
2544 /* find the host */
2545 temp_host = find_host(temp_member->host_name);
2546 if(temp_host == NULL)
2547 continue;
2548
2549 /* skip this if it isn't a new host... */
2550 if(temp_host == last_host)
2551 continue;
2552
2553 /* find the host status */
2554 temp_hoststatus = find_hoststatus(temp_host->name);
2555 if(temp_hoststatus == NULL)
2556 continue;
2557
2558 /* make sure we only display hosts of the specified status levels */
2559 if(!(host_status_types & temp_hoststatus->status))
2560 continue;
2561
2562 /* make sure we only display hosts that have the desired properties */
2563 if(passes_host_properties_filter(temp_hoststatus) == FALSE)
2564 continue;
2565
2566 if(odd)
2567 odd = 0;
2568 else
2569 odd = 1;
2570
2571 show_servicegroup_hostgroup_member_overview(temp_hoststatus, odd, temp_servicegroup);
2572
2573 last_host = temp_host;
2574 }
2575
2576 printf("</table>\n");
2577 printf("</div>\n");
2578
2579 return;
2580 }
2581
2582
2583
2584 /* show a summary of servicegroup(s)... */
show_servicegroup_summaries(void)2585 void show_servicegroup_summaries(void) {
2586 servicegroup *temp_servicegroup = NULL;
2587 int user_has_seen_something = FALSE;
2588 int servicegroup_error = FALSE;
2589 int odd = 0;
2590
2591
2592 printf("<P>\n");
2593
2594 printf("<table border=0 width=100%%>\n");
2595 printf("<tr>\n");
2596
2597 printf("<td valign=top align=left width=33%%>\n");
2598
2599 show_filters();
2600
2601 printf("</td>");
2602
2603 printf("<td valign=top align=center width=33%%>\n");
2604
2605 printf("<div align='center' class='statusTitle'>Status Summary For ");
2606 if(show_all_servicegroups == TRUE)
2607 printf("All Service Groups");
2608 else
2609 printf("Service Group '%s'", servicegroup_name);
2610 printf("</div>\n");
2611
2612 printf("<br>");
2613
2614 printf("</td>\n");
2615
2616 printf("<td valign=top align=right width=33%%></td>\n");
2617
2618 printf("</tr>\n");
2619 printf("</table>\n");
2620
2621 printf("</P>\n");
2622
2623
2624 printf("<div ALIGN=center>\n");
2625 printf("<table class='status'>\n");
2626
2627 printf("<tr>\n");
2628 printf("<th class='status'>Service Group</th><th class='status'>Host Status Summary</th><th class='status'>Service Status Summary</th>\n");
2629 printf("</tr>\n");
2630
2631 /* display status summary for all servicegroups */
2632 if(show_all_servicegroups == TRUE) {
2633
2634 /* loop through all servicegroups... */
2635 for(temp_servicegroup = servicegroup_list; temp_servicegroup != NULL; temp_servicegroup = temp_servicegroup->next) {
2636
2637 /* make sure the user is authorized to view at least one host in this servicegroup */
2638 if(is_authorized_for_servicegroup(temp_servicegroup, ¤t_authdata) == FALSE)
2639 continue;
2640
2641 if(odd == 0)
2642 odd = 1;
2643 else
2644 odd = 0;
2645
2646 /* show summary for this servicegroup */
2647 show_servicegroup_summary(temp_servicegroup, odd);
2648
2649 user_has_seen_something = TRUE;
2650 }
2651
2652 }
2653
2654 /* else just show summary for a specific servicegroup */
2655 else {
2656 temp_servicegroup = find_servicegroup(servicegroup_name);
2657 if(temp_servicegroup == NULL)
2658 servicegroup_error = TRUE;
2659 else {
2660 show_servicegroup_summary(temp_servicegroup, 1);
2661 user_has_seen_something = TRUE;
2662 }
2663 }
2664
2665 printf("</table>\n");
2666 printf("</div>\n");
2667
2668 /* if user couldn't see anything, print out some helpful info... */
2669 if(user_has_seen_something == FALSE && servicegroup_error == FALSE) {
2670
2671 printf("<P><div align='center'>\n");
2672
2673 if(servicegroup_list != NULL) {
2674 printf("<div class='errorMessage'>It appears as though you do not have permission to view information for any of the hosts you requested...</div>\n");
2675 printf("<div class='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
2676 printf("and check the authorization options in your CGI configuration file.</div>\n");
2677 }
2678 else {
2679 printf("<div class='errorMessage'>There are no service groups defined.</div>\n");
2680 }
2681
2682 printf("</div></P>\n");
2683 }
2684
2685 /* we couldn't find the servicegroup */
2686 else if(servicegroup_error == TRUE) {
2687 printf("<P><div align='center'>\n");
2688 printf("<div class='errorMessage'>Sorry, but servicegroup '%s' doesn't seem to exist...</div>\n", servicegroup_name);
2689 printf("</div></P>\n");
2690 }
2691
2692 return;
2693 }
2694
2695
2696
2697 /* displays status summary information for a specific servicegroup */
show_servicegroup_summary(servicegroup * temp_servicegroup,int odd)2698 void show_servicegroup_summary(servicegroup *temp_servicegroup, int odd) {
2699 char *status_bg_class = "";
2700
2701 if(odd == 1)
2702 status_bg_class = "Even";
2703 else
2704 status_bg_class = "Odd";
2705
2706 printf("<tr class='status%s'><td class='status%s'>\n", status_bg_class, status_bg_class);
2707 printf("<a href='%s?servicegroup=%s&style=overview'>%s</a> ", STATUS_CGI, url_encode(temp_servicegroup->group_name), temp_servicegroup->alias);
2708 printf("(<a href='%s?type=%d&servicegroup=%s'>%s</a>)", EXTINFO_CGI, DISPLAY_SERVICEGROUP_INFO, url_encode(temp_servicegroup->group_name), temp_servicegroup->group_name);
2709 printf("</td>");
2710
2711 printf("<td class='status%s' align='center' Valign='center'>", status_bg_class);
2712 show_servicegroup_host_totals_summary(temp_servicegroup);
2713 printf("</td>");
2714
2715 printf("<td class='status%s' align='center' Valign='center'>", status_bg_class);
2716 show_servicegroup_service_totals_summary(temp_servicegroup);
2717 printf("</td>");
2718
2719 printf("</tr>\n");
2720
2721 return;
2722 }
2723
2724
2725
2726 /* shows host total summary information for a specific servicegroup */
show_servicegroup_host_totals_summary(servicegroup * temp_servicegroup)2727 void show_servicegroup_host_totals_summary(servicegroup *temp_servicegroup) {
2728 servicesmember *temp_member;
2729 int hosts_up = 0;
2730 int hosts_down = 0;
2731 int hosts_unreachable = 0;
2732 int hosts_pending = 0;
2733 int hosts_down_scheduled = 0;
2734 int hosts_down_acknowledged = 0;
2735 int hosts_down_disabled = 0;
2736 int hosts_down_unacknowledged = 0;
2737 int hosts_unreachable_scheduled = 0;
2738 int hosts_unreachable_acknowledged = 0;
2739 int hosts_unreachable_disabled = 0;
2740 int hosts_unreachable_unacknowledged = 0;
2741 hoststatus *temp_hoststatus = NULL;
2742 host *temp_host = NULL;
2743 host *last_host = NULL;
2744 int problem = FALSE;
2745
2746 /* find all the hosts that belong to the servicegroup */
2747 for(temp_member = temp_servicegroup->members; temp_member != NULL; temp_member = temp_member->next) {
2748
2749 /* find the host... */
2750 temp_host = find_host(temp_member->host_name);
2751 if(temp_host == NULL)
2752 continue;
2753
2754 /* skip this if it isn't a new host... */
2755 if(temp_host == last_host)
2756 continue;
2757
2758 /* find the host status */
2759 temp_hoststatus = find_hoststatus(temp_host->name);
2760 if(temp_hoststatus == NULL)
2761 continue;
2762
2763 /* make sure we only display hosts of the specified status levels */
2764 if(!(host_status_types & temp_hoststatus->status))
2765 continue;
2766
2767 /* make sure we only display hosts that have the desired properties */
2768 if(passes_host_properties_filter(temp_hoststatus) == FALSE)
2769 continue;
2770
2771 problem = TRUE;
2772
2773 if(temp_hoststatus->status == HOST_UP)
2774 hosts_up++;
2775
2776 else if(temp_hoststatus->status == HOST_DOWN) {
2777 if(temp_hoststatus->scheduled_downtime_depth > 0) {
2778 hosts_down_scheduled++;
2779 problem = FALSE;
2780 }
2781 if(temp_hoststatus->problem_has_been_acknowledged == TRUE) {
2782 hosts_down_acknowledged++;
2783 problem = FALSE;
2784 }
2785 if(temp_hoststatus->checks_enabled == FALSE) {
2786 hosts_down_disabled++;
2787 problem = FALSE;
2788 }
2789 if(problem == TRUE)
2790 hosts_down_unacknowledged++;
2791 hosts_down++;
2792 }
2793
2794 else if(temp_hoststatus->status == HOST_UNREACHABLE) {
2795 if(temp_hoststatus->scheduled_downtime_depth > 0) {
2796 hosts_unreachable_scheduled++;
2797 problem = FALSE;
2798 }
2799 if(temp_hoststatus->problem_has_been_acknowledged == TRUE) {
2800 hosts_unreachable_acknowledged++;
2801 problem = FALSE;
2802 }
2803 if(temp_hoststatus->checks_enabled == FALSE) {
2804 hosts_unreachable_disabled++;
2805 problem = FALSE;
2806 }
2807 if(problem == TRUE)
2808 hosts_unreachable_unacknowledged++;
2809 hosts_unreachable++;
2810 }
2811
2812 else
2813 hosts_pending++;
2814
2815 last_host = temp_host;
2816 }
2817
2818 printf("<table border='0'>\n");
2819
2820 if(hosts_up > 0) {
2821 printf("<tr>");
2822 printf("<td class='miniStatusUP'><a href='%s?servicegroup=%s&style=detail&&hoststatustypes=%d&hostprops=%lu'>%d UP</a></td>", STATUS_CGI, url_encode(temp_servicegroup->group_name), HOST_UP, host_properties, hosts_up);
2823 printf("</tr>\n");
2824 }
2825
2826 if(hosts_down > 0) {
2827 printf("<tr>\n");
2828 printf("<td class='miniStatusDOWN'><table border='0'>\n");
2829 printf("<tr>\n");
2830
2831 printf("<td class='miniStatusDOWN'><a href='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%lu'>%d DOWN</a> :</td>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), HOST_DOWN, host_properties, hosts_down);
2832
2833 printf("<td><table border='0'>\n");
2834
2835 if(hosts_down_unacknowledged > 0)
2836 printf("<tr><td width=100%% class='hostImportantProblem'><a href='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%d'>%d Unhandled</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), HOST_DOWN, HOST_NO_SCHEDULED_DOWNTIME | HOST_STATE_UNACKNOWLEDGED | HOST_CHECKS_ENABLED, hosts_down_unacknowledged);
2837
2838 if(hosts_down_scheduled > 0)
2839 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%d'>%d Scheduled</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), HOST_DOWN, HOST_SCHEDULED_DOWNTIME, hosts_down_scheduled);
2840
2841 if(hosts_down_acknowledged > 0)
2842 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%d'>%d Acknowledged</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), HOST_DOWN, HOST_STATE_ACKNOWLEDGED, hosts_down_acknowledged);
2843
2844 if(hosts_down_disabled > 0)
2845 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%d'>%d Disabled</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), HOST_DOWN, HOST_CHECKS_DISABLED, hosts_down_disabled);
2846
2847 printf("</table></td>\n");
2848
2849 printf("</tr>\n");
2850 printf("</table></td>\n");
2851 printf("</tr>\n");
2852 }
2853
2854 if(hosts_unreachable > 0) {
2855 printf("<tr>\n");
2856 printf("<td class='miniStatusUNREACHABLE'><table border='0'>\n");
2857 printf("<tr>\n");
2858
2859 printf("<td class='miniStatusUNREACHABLE'><a href='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%lu'>%d UNREACHABLE</a> :</td>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), HOST_UNREACHABLE, host_properties, hosts_unreachable);
2860
2861 printf("<td><table border='0'>\n");
2862
2863 if(hosts_unreachable_unacknowledged > 0)
2864 printf("<tr><td width=100%% class='hostImportantProblem'><a href='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%d'>%d Unhandled</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), HOST_UNREACHABLE, HOST_NO_SCHEDULED_DOWNTIME | HOST_STATE_UNACKNOWLEDGED | HOST_CHECKS_ENABLED, hosts_unreachable_unacknowledged);
2865
2866 if(hosts_unreachable_scheduled > 0)
2867 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%d'>%d Scheduled</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), HOST_UNREACHABLE, HOST_SCHEDULED_DOWNTIME, hosts_unreachable_scheduled);
2868
2869 if(hosts_unreachable_acknowledged > 0)
2870 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%d'>%d Acknowledged</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), HOST_UNREACHABLE, HOST_STATE_ACKNOWLEDGED, hosts_unreachable_acknowledged);
2871
2872 if(hosts_unreachable_disabled > 0)
2873 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%d'>%d Disabled</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), HOST_UNREACHABLE, HOST_CHECKS_DISABLED, hosts_unreachable_disabled);
2874
2875 printf("</table></td>\n");
2876
2877 printf("</tr>\n");
2878 printf("</table></td>\n");
2879 printf("</tr>\n");
2880 }
2881
2882 if(hosts_pending > 0)
2883 printf("<tr><td class='miniStatusPENDING'><a href='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%lu'>%d PENDING</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), HOST_PENDING, host_properties, hosts_pending);
2884
2885 printf("</table>\n");
2886
2887 if((hosts_up + hosts_down + hosts_unreachable + hosts_pending) == 0)
2888 printf("No matching hosts");
2889
2890 return;
2891 return;
2892 }
2893
2894
2895
2896 /* shows service total summary information for a specific servicegroup */
show_servicegroup_service_totals_summary(servicegroup * temp_servicegroup)2897 void show_servicegroup_service_totals_summary(servicegroup *temp_servicegroup) {
2898 int services_ok = 0;
2899 int services_warning = 0;
2900 int services_unknown = 0;
2901 int services_critical = 0;
2902 int services_pending = 0;
2903 int services_warning_host_problem = 0;
2904 int services_warning_scheduled = 0;
2905 int services_warning_acknowledged = 0;
2906 int services_warning_disabled = 0;
2907 int services_warning_unacknowledged = 0;
2908 int services_unknown_host_problem = 0;
2909 int services_unknown_scheduled = 0;
2910 int services_unknown_acknowledged = 0;
2911 int services_unknown_disabled = 0;
2912 int services_unknown_unacknowledged = 0;
2913 int services_critical_host_problem = 0;
2914 int services_critical_scheduled = 0;
2915 int services_critical_acknowledged = 0;
2916 int services_critical_disabled = 0;
2917 int services_critical_unacknowledged = 0;
2918 servicesmember *temp_member = NULL;
2919 servicestatus *temp_servicestatus = NULL;
2920 hoststatus *temp_hoststatus = NULL;
2921 service *temp_service = NULL;
2922 service *last_service = NULL;
2923 int problem = FALSE;
2924
2925
2926 /* find all the services that belong to the servicegroup */
2927 for(temp_member = temp_servicegroup->members; temp_member != NULL; temp_member = temp_member->next) {
2928
2929 /* find the service */
2930 temp_service = find_service(temp_member->host_name, temp_member->service_description);
2931 if(temp_service == NULL)
2932 continue;
2933
2934 /* skip this if it isn't a new service... */
2935 if(temp_service == last_service)
2936 continue;
2937
2938 /* find the service status */
2939 temp_servicestatus = find_servicestatus(temp_service->host_name, temp_service->description);
2940 if(temp_servicestatus == NULL)
2941 continue;
2942
2943 /* find the status of the associated host */
2944 temp_hoststatus = find_hoststatus(temp_servicestatus->host_name);
2945 if(temp_hoststatus == NULL)
2946 continue;
2947
2948 /* make sure we only display hosts of the specified status levels */
2949 if(!(host_status_types & temp_hoststatus->status))
2950 continue;
2951
2952 /* make sure we only display hosts that have the desired properties */
2953 if(passes_host_properties_filter(temp_hoststatus) == FALSE)
2954 continue;
2955
2956 /* make sure we only display services of the specified status levels */
2957 if(!(service_status_types & temp_servicestatus->status))
2958 continue;
2959
2960 /* make sure we only display services that have the desired properties */
2961 if(passes_service_properties_filter(temp_servicestatus) == FALSE)
2962 continue;
2963
2964 problem = TRUE;
2965
2966 if(temp_servicestatus->status == SERVICE_OK)
2967 services_ok++;
2968
2969 else if(temp_servicestatus->status == SERVICE_WARNING) {
2970 temp_hoststatus = find_hoststatus(temp_servicestatus->host_name);
2971 if(temp_hoststatus != NULL && (temp_hoststatus->status == HOST_DOWN || temp_hoststatus->status == HOST_UNREACHABLE)) {
2972 services_warning_host_problem++;
2973 problem = FALSE;
2974 }
2975 if(temp_servicestatus->scheduled_downtime_depth > 0) {
2976 services_warning_scheduled++;
2977 problem = FALSE;
2978 }
2979 if(temp_servicestatus->problem_has_been_acknowledged == TRUE) {
2980 services_warning_acknowledged++;
2981 problem = FALSE;
2982 }
2983 if(temp_servicestatus->checks_enabled == FALSE) {
2984 services_warning_disabled++;
2985 problem = FALSE;
2986 }
2987 if(problem == TRUE)
2988 services_warning_unacknowledged++;
2989 services_warning++;
2990 }
2991
2992 else if(temp_servicestatus->status == SERVICE_UNKNOWN) {
2993 temp_hoststatus = find_hoststatus(temp_servicestatus->host_name);
2994 if(temp_hoststatus != NULL && (temp_hoststatus->status == HOST_DOWN || temp_hoststatus->status == HOST_UNREACHABLE)) {
2995 services_unknown_host_problem++;
2996 problem = FALSE;
2997 }
2998 if(temp_servicestatus->scheduled_downtime_depth > 0) {
2999 services_unknown_scheduled++;
3000 problem = FALSE;
3001 }
3002 if(temp_servicestatus->problem_has_been_acknowledged == TRUE) {
3003 services_unknown_acknowledged++;
3004 problem = FALSE;
3005 }
3006 if(temp_servicestatus->checks_enabled == FALSE) {
3007 services_unknown_disabled++;
3008 problem = FALSE;
3009 }
3010 if(problem == TRUE)
3011 services_unknown_unacknowledged++;
3012 services_unknown++;
3013 }
3014
3015 else if(temp_servicestatus->status == SERVICE_CRITICAL) {
3016 temp_hoststatus = find_hoststatus(temp_servicestatus->host_name);
3017 if(temp_hoststatus != NULL && (temp_hoststatus->status == HOST_DOWN || temp_hoststatus->status == HOST_UNREACHABLE)) {
3018 services_critical_host_problem++;
3019 problem = FALSE;
3020 }
3021 if(temp_servicestatus->scheduled_downtime_depth > 0) {
3022 services_critical_scheduled++;
3023 problem = FALSE;
3024 }
3025 if(temp_servicestatus->problem_has_been_acknowledged == TRUE) {
3026 services_critical_acknowledged++;
3027 problem = FALSE;
3028 }
3029 if(temp_servicestatus->checks_enabled == FALSE) {
3030 services_critical_disabled++;
3031 problem = FALSE;
3032 }
3033 if(problem == TRUE)
3034 services_critical_unacknowledged++;
3035 services_critical++;
3036 }
3037
3038 else if(temp_servicestatus->status == SERVICE_PENDING)
3039 services_pending++;
3040
3041 last_service = temp_service;
3042 }
3043
3044
3045 printf("<table border=0>\n");
3046
3047 if(services_ok > 0)
3048 printf("<tr><td class='miniStatusOK'><a href='%s?servicegroup=%s&style=detail&&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d OK</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), SERVICE_OK, host_status_types, service_properties, host_properties, services_ok);
3049
3050 if(services_warning > 0) {
3051 printf("<tr>\n");
3052 printf("<td class='miniStatusWARNING'><table border='0'>\n");
3053 printf("<tr>\n");
3054
3055 printf("<td class='miniStatusWARNING'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d WARNING</a> :</td>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), SERVICE_WARNING, host_status_types, service_properties, host_properties, services_warning);
3056
3057 printf("<td><table border='0'>\n");
3058
3059 if(services_warning_unacknowledged > 0)
3060 printf("<tr><td width=100%% class='serviceImportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%d'>%d Unhandled</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), SERVICE_WARNING, HOST_UP | HOST_PENDING, SERVICE_NO_SCHEDULED_DOWNTIME | SERVICE_STATE_UNACKNOWLEDGED | SERVICE_CHECKS_ENABLED, services_warning_unacknowledged);
3061
3062 if(services_warning_host_problem > 0)
3063 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d'>%d on Problem Hosts</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), SERVICE_WARNING, HOST_DOWN | HOST_UNREACHABLE, services_warning_host_problem);
3064
3065 if(services_warning_scheduled > 0)
3066 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Scheduled</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), SERVICE_WARNING, SERVICE_SCHEDULED_DOWNTIME, services_warning_scheduled);
3067
3068 if(services_warning_acknowledged > 0)
3069 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Acknowledged</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), SERVICE_WARNING, SERVICE_STATE_ACKNOWLEDGED, services_warning_acknowledged);
3070
3071 if(services_warning_disabled > 0)
3072 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Disabled</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), SERVICE_WARNING, SERVICE_CHECKS_DISABLED, services_warning_disabled);
3073
3074 printf("</table></td>\n");
3075
3076 printf("</tr>\n");
3077 printf("</table></td>\n");
3078 printf("</tr>\n");
3079 }
3080
3081 if(services_unknown > 0) {
3082 printf("<tr>\n");
3083 printf("<td class='miniStatusUNKNOWN'><table border='0'>\n");
3084 printf("<tr>\n");
3085
3086 printf("<td class='miniStatusUNKNOWN'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d UNKNOWN</a> :</td>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), SERVICE_UNKNOWN, host_status_types, service_properties, host_properties, services_unknown);
3087
3088 printf("<td><table border='0'>\n");
3089
3090 if(services_unknown_unacknowledged > 0)
3091 printf("<tr><td width=100%% class='serviceImportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%d'>%d Unhandled</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), SERVICE_UNKNOWN, HOST_UP | HOST_PENDING, SERVICE_NO_SCHEDULED_DOWNTIME | SERVICE_STATE_UNACKNOWLEDGED | SERVICE_CHECKS_ENABLED, services_unknown_unacknowledged);
3092
3093 if(services_unknown_host_problem > 0)
3094 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d'>%d on Problem Hosts</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), SERVICE_UNKNOWN, HOST_DOWN | HOST_UNREACHABLE, services_unknown_host_problem);
3095
3096 if(services_unknown_scheduled > 0)
3097 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Scheduled</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), SERVICE_UNKNOWN, SERVICE_SCHEDULED_DOWNTIME, services_unknown_scheduled);
3098
3099 if(services_unknown_acknowledged > 0)
3100 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Acknowledged</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), SERVICE_UNKNOWN, SERVICE_STATE_ACKNOWLEDGED, services_unknown_acknowledged);
3101
3102 if(services_unknown_disabled > 0)
3103 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Disabled</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), SERVICE_UNKNOWN, SERVICE_CHECKS_DISABLED, services_unknown_disabled);
3104
3105 printf("</table></td>\n");
3106
3107 printf("</tr>\n");
3108 printf("</table></td>\n");
3109 printf("</tr>\n");
3110 }
3111
3112 if(services_critical > 0) {
3113 printf("<tr>\n");
3114 printf("<td class='miniStatusCRITICAL'><table border='0'>\n");
3115 printf("<tr>\n");
3116
3117 printf("<td class='miniStatusCRITICAL'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d CRITICAL</a> :</td>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), SERVICE_CRITICAL, host_status_types, service_properties, host_properties, services_critical);
3118
3119 printf("<td><table border='0'>\n");
3120
3121 if(services_critical_unacknowledged > 0)
3122 printf("<tr><td width=100%% class='serviceImportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%d'>%d Unhandled</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), SERVICE_CRITICAL, HOST_UP | HOST_PENDING, SERVICE_NO_SCHEDULED_DOWNTIME | SERVICE_STATE_UNACKNOWLEDGED | SERVICE_CHECKS_ENABLED, services_critical_unacknowledged);
3123
3124 if(services_critical_host_problem > 0)
3125 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d'>%d on Problem Hosts</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), SERVICE_CRITICAL, HOST_DOWN | HOST_UNREACHABLE, services_critical_host_problem);
3126
3127 if(services_critical_scheduled > 0)
3128 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Scheduled</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), SERVICE_CRITICAL, SERVICE_SCHEDULED_DOWNTIME, services_critical_scheduled);
3129
3130 if(services_critical_acknowledged > 0)
3131 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Acknowledged</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), SERVICE_CRITICAL, SERVICE_STATE_ACKNOWLEDGED, services_critical_acknowledged);
3132
3133 if(services_critical_disabled > 0)
3134 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Disabled</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), SERVICE_CRITICAL, SERVICE_CHECKS_DISABLED, services_critical_disabled);
3135
3136 printf("</table></td>\n");
3137
3138 printf("</tr>\n");
3139 printf("</table></td>\n");
3140 printf("</tr>\n");
3141 }
3142
3143 if(services_pending > 0)
3144 printf("<tr><td class='miniStatusPENDING'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d PENDING</a></td></tr>\n", STATUS_CGI, url_encode(temp_servicegroup->group_name), SERVICE_PENDING, host_status_types, service_properties, host_properties, services_pending);
3145
3146 printf("</table>\n");
3147
3148 if((services_ok + services_warning + services_unknown + services_critical + services_pending) == 0)
3149 printf("No matching services");
3150
3151 return;
3152 }
3153
3154
3155
3156 /* show a grid layout of servicegroup(s)... */
show_servicegroup_grids(void)3157 void show_servicegroup_grids(void) {
3158 servicegroup *temp_servicegroup = NULL;
3159 int user_has_seen_something = FALSE;
3160 int servicegroup_error = FALSE;
3161 int odd = 0;
3162
3163
3164 printf("<P>\n");
3165
3166 printf("<table border=0 width=100%%>\n");
3167 printf("<tr>\n");
3168
3169 printf("<td valign=top align=left width=33%%>\n");
3170
3171 show_filters();
3172
3173 printf("</td>");
3174
3175 printf("<td valign=top align=center width=33%%>\n");
3176
3177 printf("<div align='center' class='statusTitle'>Status Grid For ");
3178 if(show_all_servicegroups == TRUE)
3179 printf("All Service Groups");
3180 else
3181 printf("Service Group '%s'", servicegroup_name);
3182 printf("</div>\n");
3183
3184 printf("<br>");
3185
3186 printf("</td>\n");
3187
3188 printf("<td valign=top align=right width=33%%></td>\n");
3189
3190 printf("</tr>\n");
3191 printf("</table>\n");
3192
3193 printf("</P>\n");
3194
3195
3196 /* display status grids for all servicegroups */
3197 if(show_all_servicegroups == TRUE) {
3198
3199 /* loop through all servicegroups... */
3200 for(temp_servicegroup = servicegroup_list; temp_servicegroup != NULL; temp_servicegroup = temp_servicegroup->next) {
3201
3202 /* make sure the user is authorized to view at least one host in this servicegroup */
3203 if(is_authorized_for_servicegroup(temp_servicegroup, ¤t_authdata) == FALSE)
3204 continue;
3205
3206 if(odd == 0)
3207 odd = 1;
3208 else
3209 odd = 0;
3210
3211 /* show grid for this servicegroup */
3212 show_servicegroup_grid(temp_servicegroup);
3213
3214 user_has_seen_something = TRUE;
3215 }
3216
3217 }
3218
3219 /* else just show grid for a specific servicegroup */
3220 else {
3221 temp_servicegroup = find_servicegroup(servicegroup_name);
3222 if(temp_servicegroup == NULL)
3223 servicegroup_error = TRUE;
3224 else {
3225 show_servicegroup_grid(temp_servicegroup);
3226 user_has_seen_something = TRUE;
3227 }
3228 }
3229
3230 /* if user couldn't see anything, print out some helpful info... */
3231 if(user_has_seen_something == FALSE && servicegroup_error == FALSE) {
3232
3233 printf("<P><div align='center'>\n");
3234
3235 if(servicegroup_list != NULL) {
3236 printf("<div class='errorMessage'>It appears as though you do not have permission to view information for any of the hosts you requested...</div>\n");
3237 printf("<div class='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
3238 printf("and check the authorization options in your CGI configuration file.</div>\n");
3239 }
3240 else {
3241 printf("<div class='errorMessage'>There are no service groups defined.</div>\n");
3242 }
3243
3244 printf("</div></P>\n");
3245 }
3246
3247 /* we couldn't find the servicegroup */
3248 else if(servicegroup_error == TRUE) {
3249 printf("<P><div align='center'>\n");
3250 printf("<div class='errorMessage'>Sorry, but servicegroup '%s' doesn't seem to exist...</div>\n", servicegroup_name);
3251 printf("</div></P>\n");
3252 }
3253
3254 return;
3255 }
3256
3257
3258 /* displays status grid for a specific servicegroup */
show_servicegroup_grid(servicegroup * temp_servicegroup)3259 void show_servicegroup_grid(servicegroup *temp_servicegroup) {
3260 char *status_bg_class = "";
3261 char *host_status_class = "";
3262 char *service_status_class = "";
3263 char *processed_string = NULL;
3264 servicesmember *temp_member;
3265 servicesmember *temp_member2;
3266 host *temp_host;
3267 host *last_host;
3268 hoststatus *temp_hoststatus;
3269 servicestatus *temp_servicestatus;
3270 int odd = 0;
3271 int current_item;
3272
3273
3274 printf("<P>\n");
3275 printf("<div align='center'>\n");
3276
3277 printf("<div class='status'><a href='%s?servicegroup=%s&style=detail'>%s</a>", STATUS_CGI, url_encode(temp_servicegroup->group_name), temp_servicegroup->alias);
3278 printf(" (<a href='%s?type=%d&servicegroup=%s'>%s</a>)</div>", EXTINFO_CGI, DISPLAY_SERVICEGROUP_INFO, url_encode(temp_servicegroup->group_name), temp_servicegroup->group_name);
3279
3280 printf("<table class='status' align='center'>\n");
3281 printf("<tr><th class='status'>Host</th><th class='status'>Services</a></th><th class='status'>Actions</th></tr>\n");
3282
3283 /* find all hosts that have services that are members of the servicegroup */
3284 last_host = NULL;
3285 for(temp_member = temp_servicegroup->members; temp_member != NULL; temp_member = temp_member->next) {
3286
3287 /* find the host */
3288 temp_host = find_host(temp_member->host_name);
3289 if(temp_host == NULL)
3290 continue;
3291
3292 /* get the status of the host */
3293 temp_hoststatus = find_hoststatus(temp_host->name);
3294 if(temp_hoststatus == NULL)
3295 continue;
3296
3297 /* skip this if it isn't a new host... */
3298 if(temp_host == last_host)
3299 continue;
3300
3301 if(odd == 1) {
3302 status_bg_class = "Even";
3303 odd = 0;
3304 }
3305 else {
3306 status_bg_class = "Odd";
3307 odd = 1;
3308 }
3309
3310 printf("<tr class='status%s'>\n", status_bg_class);
3311
3312 if(temp_hoststatus->status == HOST_DOWN)
3313 host_status_class = "HOStdOWN";
3314 else if(temp_hoststatus->status == HOST_UNREACHABLE)
3315 host_status_class = "HOSTUNREACHABLE";
3316 else
3317 host_status_class = status_bg_class;
3318
3319 printf("<td class='status%s'>", host_status_class);
3320
3321 printf("<table border=0 WIDTH='100%%' cellpadding=0 cellspacing=0>\n");
3322 printf("<tr>\n");
3323 printf("<td align='left'>\n");
3324 printf("<table border=0 cellpadding=0 cellspacing=0>\n");
3325 printf("<tr>\n");
3326 printf("<td align=left valign=center class='status%s'>", host_status_class);
3327 printf("<a href='%s?type=%d&host=%s'>%s</a>\n", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_host->name), temp_host->name);
3328 printf("</td>\n");
3329 printf("</tr>\n");
3330 printf("</table>\n");
3331 printf("</td>\n");
3332 printf("<td align=right valign=center nowrap>\n");
3333 printf("<table border=0 cellpadding=0 cellspacing=0>\n");
3334 printf("<tr>\n");
3335
3336 if(temp_host->icon_image != NULL) {
3337 printf("<td align=center valign=center>");
3338 printf("<a href='%s?type=%d&host=%s'>\n", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_host->name));
3339 printf("<IMG SRC='%s", url_logo_images_path);
3340 process_macros_r(mac, temp_host->icon_image, &processed_string, 0);
3341 printf("%s", processed_string);
3342 free(processed_string);
3343 printf("' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>", STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, (temp_host->icon_image_alt == NULL) ? "" : temp_host->icon_image_alt, (temp_host->icon_image_alt == NULL) ? "" : temp_host->icon_image_alt);
3344 printf("</a>");
3345 printf("<td>\n");
3346 }
3347
3348 printf("</tr>\n");
3349 printf("</table>\n");
3350 printf("</td>\n");
3351 printf("</tr>\n");
3352 printf("</table>\n");
3353
3354 printf("</td>\n");
3355
3356 printf("<td class='status%s'>", host_status_class);
3357
3358 /* display all services on the host that are part of the hostgroup */
3359 current_item = 1;
3360 for(temp_member2 = temp_member; temp_member2 != NULL; temp_member2 = temp_member2->next) {
3361
3362 /* bail out if we've reached the end of the services that are associated with this servicegroup */
3363 if(strcmp(temp_member2->host_name, temp_host->name))
3364 break;
3365
3366 if(current_item > max_grid_width && max_grid_width > 0) {
3367 printf("<BR>\n");
3368 current_item = 1;
3369 }
3370
3371 /* get the status of the service */
3372 temp_servicestatus = find_servicestatus(temp_member2->host_name, temp_member2->service_description);
3373 if(temp_servicestatus == NULL)
3374 service_status_class = "NULL";
3375 else if(temp_servicestatus->status == SERVICE_OK)
3376 service_status_class = "OK";
3377 else if(temp_servicestatus->status == SERVICE_WARNING)
3378 service_status_class = "WARNING";
3379 else if(temp_servicestatus->status == SERVICE_UNKNOWN)
3380 service_status_class = "UNKNOWN";
3381 else if(temp_servicestatus->status == SERVICE_CRITICAL)
3382 service_status_class = "CRITICAL";
3383 else
3384 service_status_class = "PENDING";
3385
3386 printf("<a href='%s?type=%d&host=%s", EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(temp_servicestatus->host_name));
3387 printf("&service=%s' class='status%s'>%s</a> ", url_encode(temp_servicestatus->description), service_status_class, temp_servicestatus->description);
3388
3389 current_item++;
3390 }
3391
3392 /* actions */
3393 printf("<td class='status%s'>", host_status_class);
3394
3395 /* grab macros */
3396 grab_host_macros_r(mac, temp_host);
3397
3398 printf("<a href='%s?type=%d&host=%s'>\n", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_host->name));
3399 printf("<IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>", url_images_path, DETAIL_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, "View Extended Information For This Host", "View Extended Information For This Host");
3400 printf("</a>");
3401
3402 if(temp_host->notes_url != NULL) {
3403 printf("<a href='");
3404 process_macros_r(mac, temp_host->notes_url, &processed_string, 0);
3405 printf("%s", processed_string);
3406 free(processed_string);
3407 printf("' TARGET='%s'>", (notes_url_target == NULL) ? "_blank" : notes_url_target);
3408 printf("<IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>", url_images_path, NOTES_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, "View Extra Host Notes", "View Extra Host Notes");
3409 printf("</a>");
3410 }
3411 if(temp_host->action_url != NULL) {
3412 printf("<a href='");
3413 process_macros_r(mac, temp_host->action_url, &processed_string, 0);
3414 printf("%s", processed_string);
3415 free(processed_string);
3416 printf("' TARGET='%s'>", (action_url_target == NULL) ? "blank" : action_url_target);
3417 printf("<IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>", url_images_path, ACTION_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, "Perform Extra Host Actions", "Perform Extra Host Actions");
3418 printf("</a>");
3419 }
3420
3421 printf("<a href='%s?host=%s'><img src='%s%s' border=0 alt='View Service Details For This Host' title='View Service Details For This Host'></a>\n", STATUS_CGI, url_encode(temp_host->name), url_images_path, STATUS_DETAIL_ICON);
3422
3423 #ifdef USE_STATUSMAP
3424 printf("<a href='%s?host=%s'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'></a>", STATUSMAP_CGI, url_encode(temp_host->name), url_images_path, STATUSMAP_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, "Locate Host On Map", "Locate Host On Map");
3425 #endif
3426 printf("</td>\n");
3427 printf("</tr>\n");
3428
3429 last_host = temp_host;
3430 }
3431
3432 printf("</table>\n");
3433 printf("</div>\n");
3434 printf("</P>\n");
3435
3436 return;
3437 }
3438
3439
3440
3441 /* show an overview of hostgroup(s)... */
show_hostgroup_overviews(void)3442 void show_hostgroup_overviews(void) {
3443 hostgroup *temp_hostgroup = NULL;
3444 int current_column;
3445 int user_has_seen_something = FALSE;
3446 int hostgroup_error = FALSE;
3447
3448
3449 printf("<P>\n");
3450
3451 printf("<table border=0 width=100%%>\n");
3452 printf("<tr>\n");
3453
3454 printf("<td valign=top align=left width=33%%>\n");
3455
3456 show_filters();
3457
3458 printf("</td>");
3459
3460 printf("<td valign=top align=center width=33%%>\n");
3461
3462 printf("<div align='center' class='statusTitle'>Service Overview For ");
3463 if(show_all_hostgroups == TRUE)
3464 printf("All Host Groups");
3465 else
3466 printf("Host Group '%s'", hostgroup_name);
3467 printf("</div>\n");
3468
3469 printf("<br>");
3470
3471 printf("</td>\n");
3472
3473 printf("<td valign=top align=right width=33%%></td>\n");
3474
3475 printf("</tr>\n");
3476 printf("</table>\n");
3477
3478 printf("</P>\n");
3479
3480
3481 /* display status overviews for all hostgroups */
3482 if(show_all_hostgroups == TRUE) {
3483
3484
3485 printf("<div ALIGN=center>\n");
3486 printf("<table border=0 cellpadding=10>\n");
3487
3488 current_column = 1;
3489
3490 /* loop through all hostgroups... */
3491 for(temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {
3492
3493 /* make sure the user is authorized to view this hostgroup */
3494 if(is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == FALSE)
3495 continue;
3496
3497 if(current_column == 1)
3498 printf("<tr>\n");
3499 printf("<td VALIGN=top ALIGN=center>\n");
3500
3501 show_hostgroup_overview(temp_hostgroup);
3502
3503 user_has_seen_something = TRUE;
3504
3505 printf("</td>\n");
3506 if(current_column == overview_columns)
3507 printf("</tr>\n");
3508
3509 if(current_column < overview_columns)
3510 current_column++;
3511 else
3512 current_column = 1;
3513 }
3514
3515 if(current_column != 1) {
3516
3517 for(; current_column <= overview_columns; current_column++)
3518 printf("<td></td>\n");
3519 printf("</tr>\n");
3520 }
3521
3522 printf("</table>\n");
3523 printf("</div>\n");
3524 }
3525
3526 /* else display overview for just a specific hostgroup */
3527 else {
3528
3529 temp_hostgroup = find_hostgroup(hostgroup_name);
3530 if(temp_hostgroup != NULL) {
3531
3532 printf("<P>\n");
3533 printf("<div align='center'>\n");
3534 printf("<table border=0 cellpadding=0 cellspacing=0><tr><td align='center'>\n");
3535
3536 if(is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == TRUE) {
3537
3538 show_hostgroup_overview(temp_hostgroup);
3539
3540 user_has_seen_something = TRUE;
3541 }
3542
3543 printf("</td></tr></table>\n");
3544 printf("</div>\n");
3545 printf("</P>\n");
3546 }
3547 else {
3548 printf("<div class='errorMessage'>Sorry, but host group '%s' doesn't seem to exist...</div>", hostgroup_name);
3549 hostgroup_error = TRUE;
3550 }
3551 }
3552
3553 /* if user couldn't see anything, print out some helpful info... */
3554 if(user_has_seen_something == FALSE && hostgroup_error == FALSE) {
3555
3556 printf("<p>\n");
3557 printf("<div align='center'>\n");
3558
3559 if(hoststatus_list != NULL) {
3560 printf("<div class='errorMessage'>It appears as though you do not have permission to view information for any of the hosts you requested...</div>\n");
3561 printf("<div class='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
3562 printf("and check the authorization options in your CGI configuration file.</div>\n");
3563 }
3564 else {
3565 printf("<div class='infoMessage'>There doesn't appear to be any host status information in the status log...<br><br>\n");
3566 printf("Make sure that Nagios is running and that you have specified the location of you status log correctly in the configuration files.</div>\n");
3567 }
3568
3569 printf("</div>\n");
3570 printf("</p>\n");
3571 }
3572
3573 return;
3574 }
3575
3576
3577
3578 /* shows an overview of a specific hostgroup... */
show_hostgroup_overview(hostgroup * hstgrp)3579 void show_hostgroup_overview(hostgroup *hstgrp) {
3580 hostsmember *temp_member = NULL;
3581 host *temp_host = NULL;
3582 hoststatus *temp_hoststatus = NULL;
3583 int odd = 0;
3584
3585 /* make sure the user is authorized to view this hostgroup */
3586 if(is_authorized_for_hostgroup(hstgrp, ¤t_authdata) == FALSE)
3587 return;
3588
3589 printf("<div class='status'>\n");
3590 printf("<a href='%s?hostgroup=%s&style=detail'>%s</a>", STATUS_CGI, url_encode(hstgrp->group_name), hstgrp->alias);
3591 printf(" (<a href='%s?type=%d&hostgroup=%s'>%s</a>)", EXTINFO_CGI, DISPLAY_HOSTGROUP_INFO, url_encode(hstgrp->group_name), hstgrp->group_name);
3592 printf("</div>\n");
3593
3594 printf("<div class='status'>\n");
3595 printf("<table class='status'>\n");
3596
3597 printf("<tr>\n");
3598 printf("<th class='status'>Host</th><th class='status'>Status</th><th class='status'>Services</th><th class='status'>Actions</th>\n");
3599 printf("</tr>\n");
3600
3601 /* find all the hosts that belong to the hostgroup */
3602 for(temp_member = hstgrp->members; temp_member != NULL; temp_member = temp_member->next) {
3603
3604 /* find the host... */
3605 temp_host = find_host(temp_member->host_name);
3606 if(temp_host == NULL)
3607 continue;
3608
3609 /* find the host status */
3610 temp_hoststatus = find_hoststatus(temp_host->name);
3611 if(temp_hoststatus == NULL)
3612 continue;
3613
3614 /* make sure we only display hosts of the specified status levels */
3615 if(!(host_status_types & temp_hoststatus->status))
3616 continue;
3617
3618 /* make sure we only display hosts that have the desired properties */
3619 if(passes_host_properties_filter(temp_hoststatus) == FALSE)
3620 continue;
3621
3622 if(odd)
3623 odd = 0;
3624 else
3625 odd = 1;
3626
3627 show_servicegroup_hostgroup_member_overview(temp_hoststatus, odd, NULL);
3628 }
3629
3630 printf("</table>\n");
3631 printf("</div>\n");
3632
3633 return;
3634 }
3635
3636
3637
3638 /* shows a host status overview... */
show_servicegroup_hostgroup_member_overview(hoststatus * hststatus,int odd,void * data)3639 void show_servicegroup_hostgroup_member_overview(hoststatus *hststatus, int odd, void *data) {
3640 char status[MAX_INPUT_BUFFER];
3641 char *status_bg_class = "";
3642 char *status_class = "";
3643 host *temp_host = NULL;
3644 char *processed_string = NULL;
3645
3646 temp_host = find_host(hststatus->host_name);
3647
3648 /* grab macros */
3649 grab_host_macros_r(mac, temp_host);
3650
3651 if(hststatus->status == HOST_PENDING) {
3652 strncpy(status, "PENDING", sizeof(status));
3653 status_class = "HOSTPENDING";
3654 status_bg_class = (odd) ? "Even" : "Odd";
3655 }
3656 else if(hststatus->status == HOST_UP) {
3657 strncpy(status, "UP", sizeof(status));
3658 status_class = "HOSTUP";
3659 status_bg_class = (odd) ? "Even" : "Odd";
3660 }
3661 else if(hststatus->status == HOST_DOWN) {
3662 strncpy(status, "DOWN", sizeof(status));
3663 status_class = "HOStdOWN";
3664 status_bg_class = "HOStdOWN";
3665 }
3666 else if(hststatus->status == HOST_UNREACHABLE) {
3667 strncpy(status, "UNREACHABLE", sizeof(status));
3668 status_class = "HOSTUNREACHABLE";
3669 status_bg_class = "HOSTUNREACHABLE";
3670 }
3671
3672 status[sizeof(status) - 1] = '\x0';
3673
3674 printf("<tr class='status%s'>\n", status_bg_class);
3675
3676 printf("<td class='status%s'>\n", status_bg_class);
3677
3678 printf("<table border=0 WIDTH=100%% cellpadding=0 cellspacing=0>\n");
3679 printf("<tr class='status%s'>\n", status_bg_class);
3680 printf("<td class='status%s'><a href='%s?host=%s&style=detail' title='%s'>%s</a></td>\n", status_bg_class, STATUS_CGI, url_encode(hststatus->host_name), temp_host->address, hststatus->host_name);
3681
3682 if(temp_host->icon_image != NULL) {
3683 printf("<td class='status%s' WIDTH=5></td>\n", status_bg_class);
3684 printf("<td class='status%s' ALIGN=right>", status_bg_class);
3685 printf("<a href='%s?type=%d&host=%s'>", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(hststatus->host_name));
3686 printf("<IMG SRC='%s", url_logo_images_path);
3687 process_macros_r(mac, temp_host->icon_image, &processed_string, 0);
3688 printf("%s", processed_string);
3689 free(processed_string);
3690 printf("' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>", STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, (temp_host->icon_image_alt == NULL) ? "" : temp_host->icon_image_alt, (temp_host->icon_image_alt == NULL) ? "" : temp_host->icon_image_alt);
3691 printf("</a>");
3692 printf("</td>\n");
3693 }
3694 printf("</tr>\n");
3695 printf("</table>\n");
3696 printf("</td>\n");
3697
3698 printf("<td class='status%s'>%s</td>\n", status_class, status);
3699
3700 printf("<td class='status%s'>\n", status_bg_class);
3701 show_servicegroup_hostgroup_member_service_status_totals(hststatus->host_name, data);
3702 printf("</td>\n");
3703
3704 printf("<td valign=center class='status%s'>", status_bg_class);
3705 printf("<a href='%s?type=%d&host=%s'><img src='%s%s' border=0 alt='View Extended Information For This Host' title='View Extended Information For This Host'></a>\n", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(hststatus->host_name), url_images_path, DETAIL_ICON);
3706 if(temp_host->notes_url != NULL) {
3707 printf("<a href='");
3708 process_macros_r(mac, temp_host->notes_url, &processed_string, 0);
3709 printf("%s", processed_string);
3710 free(processed_string);
3711 printf("' TARGET='%s'>", (notes_url_target == NULL) ? "_blank" : notes_url_target);
3712 printf("<IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>", url_images_path, NOTES_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, "View Extra Host Notes", "View Extra Host Notes");
3713 printf("</a>");
3714 }
3715 if(temp_host->action_url != NULL) {
3716 printf("<a href='");
3717 process_macros_r(mac, temp_host->action_url, &processed_string, 0);
3718 printf("%s", processed_string);
3719 free(processed_string);
3720 printf("' TARGET='%s'>", (action_url_target == NULL) ? "_blank" : action_url_target);
3721 printf("<IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>", url_images_path, ACTION_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, "Perform Extra Host Actions", "Perform Extra Host Actions");
3722 printf("</a>");
3723 }
3724 printf("<a href='%s?host=%s'><img src='%s%s' border=0 alt='View Service Details For This Host' title='View Service Details For This Host'></a>\n", STATUS_CGI, url_encode(hststatus->host_name), url_images_path, STATUS_DETAIL_ICON);
3725 #ifdef USE_STATUSMAP
3726 printf("<a href='%s?host=%s'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'></a>", STATUSMAP_CGI, url_encode(hststatus->host_name), url_images_path, STATUSMAP_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, "Locate Host On Map", "Locate Host On Map");
3727 #endif
3728 printf("</td>");
3729
3730 printf("</tr>\n");
3731
3732 return;
3733 }
3734
3735
3736
show_servicegroup_hostgroup_member_service_status_totals(char * host_name,void * data)3737 void show_servicegroup_hostgroup_member_service_status_totals(char *host_name, void *data) {
3738 int total_ok = 0;
3739 int total_warning = 0;
3740 int total_unknown = 0;
3741 int total_critical = 0;
3742 int total_pending = 0;
3743 servicestatus *temp_servicestatus;
3744 service *temp_service;
3745 servicegroup *temp_servicegroup = NULL;
3746 char temp_buffer[MAX_INPUT_BUFFER];
3747
3748
3749 if(display_type == DISPLAY_SERVICEGROUPS)
3750 temp_servicegroup = (servicegroup *)data;
3751
3752 /* check all services... */
3753 for(temp_servicestatus = servicestatus_list; temp_servicestatus != NULL; temp_servicestatus = temp_servicestatus->next) {
3754
3755 if(!strcmp(host_name, temp_servicestatus->host_name)) {
3756
3757 /* make sure the user is authorized to see this service... */
3758 temp_service = find_service(temp_servicestatus->host_name, temp_servicestatus->description);
3759 if(is_authorized_for_service(temp_service, ¤t_authdata) == FALSE)
3760 continue;
3761
3762 if(display_type == DISPLAY_SERVICEGROUPS) {
3763
3764 /* is this service a member of the servicegroup? */
3765 if(is_service_member_of_servicegroup(temp_servicegroup, temp_service) == FALSE)
3766 continue;
3767 }
3768
3769 /* make sure we only display services of the specified status levels */
3770 if(!(service_status_types & temp_servicestatus->status))
3771 continue;
3772
3773 /* make sure we only display services that have the desired properties */
3774 if(passes_service_properties_filter(temp_servicestatus) == FALSE)
3775 continue;
3776
3777 if(temp_servicestatus->status == SERVICE_CRITICAL)
3778 total_critical++;
3779 else if(temp_servicestatus->status == SERVICE_WARNING)
3780 total_warning++;
3781 else if(temp_servicestatus->status == SERVICE_UNKNOWN)
3782 total_unknown++;
3783 else if(temp_servicestatus->status == SERVICE_OK)
3784 total_ok++;
3785 else if(temp_servicestatus->status == SERVICE_PENDING)
3786 total_pending++;
3787 else
3788 total_ok++;
3789 }
3790 }
3791
3792
3793 printf("<table border=0 WIDTH=100%%>\n");
3794
3795 if(display_type == DISPLAY_SERVICEGROUPS)
3796 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "servicegroup=%s&style=detail", url_encode(temp_servicegroup->group_name));
3797 else
3798 snprintf(temp_buffer, sizeof(temp_buffer) - 1, "host=%s", url_encode(host_name));
3799 temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
3800
3801 if(total_ok > 0)
3802 printf("<tr><td class='miniStatusOK'><a href='%s?%s&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d OK</a></td></tr>\n", STATUS_CGI, temp_buffer, SERVICE_OK, host_status_types, service_properties, host_properties, total_ok);
3803 if(total_warning > 0)
3804 printf("<tr><td class='miniStatusWARNING'><a href='%s?%s&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d WARNING</a></td></tr>\n", STATUS_CGI, temp_buffer, SERVICE_WARNING, host_status_types, service_properties, host_properties, total_warning);
3805 if(total_unknown > 0)
3806 printf("<tr><td class='miniStatusUNKNOWN'><a href='%s?%s&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d UNKNOWN</a></td></tr>\n", STATUS_CGI, temp_buffer, SERVICE_UNKNOWN, host_status_types, service_properties, host_properties, total_unknown);
3807 if(total_critical > 0)
3808 printf("<tr><td class='miniStatusCRITICAL'><a href='%s?%s&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d CRITICAL</a></td></tr>\n", STATUS_CGI, temp_buffer, SERVICE_CRITICAL, host_status_types, service_properties, host_properties, total_critical);
3809 if(total_pending > 0)
3810 printf("<tr><td class='miniStatusPENDING'><a href='%s?%s&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d PENDING</a></td></tr>\n", STATUS_CGI, temp_buffer, SERVICE_PENDING, host_status_types, service_properties, host_properties, total_pending);
3811
3812 printf("</table>\n");
3813
3814 if((total_ok + total_warning + total_unknown + total_critical + total_pending) == 0)
3815 printf("No matching services");
3816
3817 return;
3818 }
3819
3820
3821
3822 /* show a summary of hostgroup(s)... */
show_hostgroup_summaries(void)3823 void show_hostgroup_summaries(void) {
3824 hostgroup *temp_hostgroup = NULL;
3825 int user_has_seen_something = FALSE;
3826 int hostgroup_error = FALSE;
3827 int odd = 0;
3828
3829
3830 printf("<P>\n");
3831
3832 printf("<table border=0 width=100%%>\n");
3833 printf("<tr>\n");
3834
3835 printf("<td valign=top align=left width=33%%>\n");
3836
3837 show_filters();
3838
3839 printf("</td>");
3840
3841 printf("<td valign=top align=center width=33%%>\n");
3842
3843 printf("<div align='center' class='statusTitle'>Status Summary For ");
3844 if(show_all_hostgroups == TRUE)
3845 printf("All Host Groups");
3846 else
3847 printf("Host Group '%s'", hostgroup_name);
3848 printf("</div>\n");
3849
3850 printf("<br>");
3851
3852 printf("</td>\n");
3853
3854 printf("<td valign=top align=right width=33%%></td>\n");
3855
3856 printf("</tr>\n");
3857 printf("</table>\n");
3858
3859 printf("</P>\n");
3860
3861
3862 printf("<div ALIGN=center>\n");
3863 printf("<table class='status'>\n");
3864
3865 printf("<tr>\n");
3866 printf("<th class='status'>Host Group</th><th class='status'>Host Status Summary</th><th class='status'>Service Status Summary</th>\n");
3867 printf("</tr>\n");
3868
3869 /* display status summary for all hostgroups */
3870 if(show_all_hostgroups == TRUE) {
3871
3872 /* loop through all hostgroups... */
3873 for(temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {
3874
3875 /* make sure the user is authorized to view this hostgroup */
3876 if(is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == FALSE)
3877 continue;
3878
3879 if(odd == 0)
3880 odd = 1;
3881 else
3882 odd = 0;
3883
3884 /* show summary for this hostgroup */
3885 show_hostgroup_summary(temp_hostgroup, odd);
3886
3887 user_has_seen_something = TRUE;
3888 }
3889
3890 }
3891
3892 /* else just show summary for a specific hostgroup */
3893 else {
3894 temp_hostgroup = find_hostgroup(hostgroup_name);
3895 if(temp_hostgroup == NULL)
3896 hostgroup_error = TRUE;
3897 else {
3898 show_hostgroup_summary(temp_hostgroup, 1);
3899 user_has_seen_something = TRUE;
3900 }
3901 }
3902
3903 printf("</table>\n");
3904 printf("</div>\n");
3905
3906 /* if user couldn't see anything, print out some helpful info... */
3907 if(user_has_seen_something == FALSE && hostgroup_error == FALSE) {
3908
3909 printf("<P><div align='center'>\n");
3910
3911 if(hoststatus_list != NULL) {
3912 printf("<div class='errorMessage'>It appears as though you do not have permission to view information for any of the hosts you requested...</div>\n");
3913 printf("<div class='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
3914 printf("and check the authorization options in your CGI configuration file.</div>\n");
3915 }
3916 else {
3917 printf("<div class='infoMessage'>There doesn't appear to be any host status information in the status log...<br><br>\n");
3918 printf("Make sure that Nagios is running and that you have specified the location of you status log correctly in the configuration files.</div>\n");
3919 }
3920
3921 printf("</div></P>\n");
3922 }
3923
3924 /* we couldn't find the hostgroup */
3925 else if(hostgroup_error == TRUE) {
3926 printf("<P><div align='center'>\n");
3927 printf("<div class='errorMessage'>Sorry, but hostgroup '%s' doesn't seem to exist...</div>\n", hostgroup_name);
3928 printf("</div></P>\n");
3929 }
3930
3931 return;
3932 }
3933
3934
3935
3936 /* displays status summary information for a specific hostgroup */
show_hostgroup_summary(hostgroup * temp_hostgroup,int odd)3937 void show_hostgroup_summary(hostgroup *temp_hostgroup, int odd) {
3938 char *status_bg_class = "";
3939
3940 if(odd == 1)
3941 status_bg_class = "Even";
3942 else
3943 status_bg_class = "Odd";
3944
3945 printf("<tr class='status%s'><td class='status%s'>\n", status_bg_class, status_bg_class);
3946 printf("<a href='%s?hostgroup=%s&style=overview'>%s</a> ", STATUS_CGI, url_encode(temp_hostgroup->group_name), temp_hostgroup->alias);
3947 printf("(<a href='%s?type=%d&hostgroup=%s'>%s</a>)", EXTINFO_CGI, DISPLAY_HOSTGROUP_INFO, url_encode(temp_hostgroup->group_name), temp_hostgroup->group_name);
3948 printf("</td>");
3949
3950 printf("<td class='status%s' align='center' Valign='center'>", status_bg_class);
3951 show_hostgroup_host_totals_summary(temp_hostgroup);
3952 printf("</td>");
3953
3954 printf("<td class='status%s' align='center' Valign='center'>", status_bg_class);
3955 show_hostgroup_service_totals_summary(temp_hostgroup);
3956 printf("</td>");
3957
3958 printf("</tr>\n");
3959
3960 return;
3961 }
3962
3963
3964
3965 /* shows host total summary information for a specific hostgroup */
show_hostgroup_host_totals_summary(hostgroup * temp_hostgroup)3966 void show_hostgroup_host_totals_summary(hostgroup *temp_hostgroup) {
3967 hostsmember *temp_member;
3968 int hosts_up = 0;
3969 int hosts_down = 0;
3970 int hosts_unreachable = 0;
3971 int hosts_pending = 0;
3972 int hosts_down_scheduled = 0;
3973 int hosts_down_acknowledged = 0;
3974 int hosts_down_disabled = 0;
3975 int hosts_down_unacknowledged = 0;
3976 int hosts_unreachable_scheduled = 0;
3977 int hosts_unreachable_acknowledged = 0;
3978 int hosts_unreachable_disabled = 0;
3979 int hosts_unreachable_unacknowledged = 0;
3980 hoststatus *temp_hoststatus;
3981 host *temp_host;
3982 int problem = FALSE;
3983
3984 /* find all the hosts that belong to the hostgroup */
3985 for(temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
3986
3987 /* find the host... */
3988 temp_host = find_host(temp_member->host_name);
3989 if(temp_host == NULL)
3990 continue;
3991
3992 /* find the host status */
3993 temp_hoststatus = find_hoststatus(temp_host->name);
3994 if(temp_hoststatus == NULL)
3995 continue;
3996
3997 /* make sure we only display hosts of the specified status levels */
3998 if(!(host_status_types & temp_hoststatus->status))
3999 continue;
4000
4001 /* make sure we only display hosts that have the desired properties */
4002 if(passes_host_properties_filter(temp_hoststatus) == FALSE)
4003 continue;
4004
4005 problem = TRUE;
4006
4007 if(temp_hoststatus->status == HOST_UP)
4008 hosts_up++;
4009
4010 else if(temp_hoststatus->status == HOST_DOWN) {
4011 if(temp_hoststatus->scheduled_downtime_depth > 0) {
4012 hosts_down_scheduled++;
4013 problem = FALSE;
4014 }
4015 if(temp_hoststatus->problem_has_been_acknowledged == TRUE) {
4016 hosts_down_acknowledged++;
4017 problem = FALSE;
4018 }
4019 if(temp_hoststatus->checks_enabled == FALSE) {
4020 hosts_down_disabled++;
4021 problem = FALSE;
4022 }
4023 if(problem == TRUE)
4024 hosts_down_unacknowledged++;
4025 hosts_down++;
4026 }
4027
4028 else if(temp_hoststatus->status == HOST_UNREACHABLE) {
4029 if(temp_hoststatus->scheduled_downtime_depth > 0) {
4030 hosts_unreachable_scheduled++;
4031 problem = FALSE;
4032 }
4033 if(temp_hoststatus->problem_has_been_acknowledged == TRUE) {
4034 hosts_unreachable_acknowledged++;
4035 problem = FALSE;
4036 }
4037 if(temp_hoststatus->checks_enabled == FALSE) {
4038 hosts_unreachable_disabled++;
4039 problem = FALSE;
4040 }
4041 if(problem == TRUE)
4042 hosts_unreachable_unacknowledged++;
4043 hosts_unreachable++;
4044 }
4045
4046 else
4047 hosts_pending++;
4048 }
4049
4050 printf("<table border='0'>\n");
4051
4052 if(hosts_up > 0) {
4053 printf("<tr>");
4054 printf("<td class='miniStatusUP'><a href='%s?hostgroup=%s&style=hostdetail&&hoststatustypes=%d&hostprops=%lu'>%d UP</a></td>", STATUS_CGI, url_encode(temp_hostgroup->group_name), HOST_UP, host_properties, hosts_up);
4055 printf("</tr>\n");
4056 }
4057
4058 if(hosts_down > 0) {
4059 printf("<tr>\n");
4060 printf("<td class='miniStatusDOWN'><table border='0'>\n");
4061 printf("<tr>\n");
4062
4063 printf("<td class='miniStatusDOWN'><a href='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%lu'>%d DOWN</a> :</td>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), HOST_DOWN, host_properties, hosts_down);
4064
4065 printf("<td><table border='0'>\n");
4066
4067 if(hosts_down_unacknowledged > 0)
4068 printf("<tr><td width=100%% class='hostImportantProblem'><a href='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Unhandled</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), HOST_DOWN, HOST_NO_SCHEDULED_DOWNTIME | HOST_STATE_UNACKNOWLEDGED | HOST_CHECKS_ENABLED, hosts_down_unacknowledged);
4069
4070 if(hosts_down_scheduled > 0)
4071 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Scheduled</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), HOST_DOWN, HOST_SCHEDULED_DOWNTIME, hosts_down_scheduled);
4072
4073 if(hosts_down_acknowledged > 0)
4074 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Acknowledged</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), HOST_DOWN, HOST_STATE_ACKNOWLEDGED, hosts_down_acknowledged);
4075
4076 if(hosts_down_disabled > 0)
4077 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Disabled</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), HOST_DOWN, HOST_CHECKS_DISABLED, hosts_down_disabled);
4078
4079 printf("</table></td>\n");
4080
4081 printf("</tr>\n");
4082 printf("</table></td>\n");
4083 printf("</tr>\n");
4084 }
4085
4086 if(hosts_unreachable > 0) {
4087 printf("<tr>\n");
4088 printf("<td class='miniStatusUNREACHABLE'><table border='0'>\n");
4089 printf("<tr>\n");
4090
4091 printf("<td class='miniStatusUNREACHABLE'><a href='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%lu'>%d UNREACHABLE</a> :</td>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), HOST_UNREACHABLE, host_properties, hosts_unreachable);
4092
4093 printf("<td><table border='0'>\n");
4094
4095 if(hosts_unreachable_unacknowledged > 0)
4096 printf("<tr><td width=100%% class='hostImportantProblem'><a href='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Unhandled</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), HOST_UNREACHABLE, HOST_NO_SCHEDULED_DOWNTIME | HOST_STATE_UNACKNOWLEDGED | HOST_CHECKS_ENABLED, hosts_unreachable_unacknowledged);
4097
4098 if(hosts_unreachable_scheduled > 0)
4099 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Scheduled</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), HOST_UNREACHABLE, HOST_SCHEDULED_DOWNTIME, hosts_unreachable_scheduled);
4100
4101 if(hosts_unreachable_acknowledged > 0)
4102 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Acknowledged</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), HOST_UNREACHABLE, HOST_STATE_ACKNOWLEDGED, hosts_unreachable_acknowledged);
4103
4104 if(hosts_unreachable_disabled > 0)
4105 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Disabled</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), HOST_UNREACHABLE, HOST_CHECKS_DISABLED, hosts_unreachable_disabled);
4106
4107 printf("</table></td>\n");
4108
4109 printf("</tr>\n");
4110 printf("</table></td>\n");
4111 printf("</tr>\n");
4112 }
4113
4114 if(hosts_pending > 0)
4115 printf("<tr><td class='miniStatusPENDING'><a href='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%lu'>%d PENDING</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), HOST_PENDING, host_properties, hosts_pending);
4116
4117 printf("</table>\n");
4118
4119 if((hosts_up + hosts_down + hosts_unreachable + hosts_pending) == 0)
4120 printf("No matching hosts");
4121
4122 return;
4123 }
4124
4125
4126
4127 /* shows service total summary information for a specific hostgroup */
show_hostgroup_service_totals_summary(hostgroup * temp_hostgroup)4128 void show_hostgroup_service_totals_summary(hostgroup *temp_hostgroup) {
4129 int services_ok = 0;
4130 int services_warning = 0;
4131 int services_unknown = 0;
4132 int services_critical = 0;
4133 int services_pending = 0;
4134 int services_warning_host_problem = 0;
4135 int services_warning_scheduled = 0;
4136 int services_warning_acknowledged = 0;
4137 int services_warning_disabled = 0;
4138 int services_warning_unacknowledged = 0;
4139 int services_unknown_host_problem = 0;
4140 int services_unknown_scheduled = 0;
4141 int services_unknown_acknowledged = 0;
4142 int services_unknown_disabled = 0;
4143 int services_unknown_unacknowledged = 0;
4144 int services_critical_host_problem = 0;
4145 int services_critical_scheduled = 0;
4146 int services_critical_acknowledged = 0;
4147 int services_critical_disabled = 0;
4148 int services_critical_unacknowledged = 0;
4149 servicestatus *temp_servicestatus = NULL;
4150 hoststatus *temp_hoststatus = NULL;
4151 host *temp_host = NULL;
4152 int problem = FALSE;
4153
4154
4155 /* check all services... */
4156 for(temp_servicestatus = servicestatus_list; temp_servicestatus != NULL; temp_servicestatus = temp_servicestatus->next) {
4157
4158 /* find the host this service is associated with */
4159 temp_host = find_host(temp_servicestatus->host_name);
4160 if(temp_host == NULL)
4161 continue;
4162
4163 /* see if this service is associated with a host in the specified hostgroup */
4164 if(is_host_member_of_hostgroup(temp_hostgroup, temp_host) == FALSE)
4165 continue;
4166
4167 /* find the status of the associated host */
4168 temp_hoststatus = find_hoststatus(temp_servicestatus->host_name);
4169 if(temp_hoststatus == NULL)
4170 continue;
4171
4172 /* find the status of the associated host */
4173 temp_hoststatus = find_hoststatus(temp_servicestatus->host_name);
4174 if(temp_hoststatus == NULL)
4175 continue;
4176
4177 /* make sure we only display hosts of the specified status levels */
4178 if(!(host_status_types & temp_hoststatus->status))
4179 continue;
4180
4181 /* make sure we only display hosts that have the desired properties */
4182 if(passes_host_properties_filter(temp_hoststatus) == FALSE)
4183 continue;
4184
4185 /* make sure we only display services of the specified status levels */
4186 if(!(service_status_types & temp_servicestatus->status))
4187 continue;
4188
4189 /* make sure we only display services that have the desired properties */
4190 if(passes_service_properties_filter(temp_servicestatus) == FALSE)
4191 continue;
4192
4193 problem = TRUE;
4194
4195 if(temp_servicestatus->status == SERVICE_OK)
4196 services_ok++;
4197
4198 else if(temp_servicestatus->status == SERVICE_WARNING) {
4199 temp_hoststatus = find_hoststatus(temp_servicestatus->host_name);
4200 if(temp_hoststatus != NULL && (temp_hoststatus->status == HOST_DOWN || temp_hoststatus->status == HOST_UNREACHABLE)) {
4201 services_warning_host_problem++;
4202 problem = FALSE;
4203 }
4204 if(temp_servicestatus->scheduled_downtime_depth > 0) {
4205 services_warning_scheduled++;
4206 problem = FALSE;
4207 }
4208 if(temp_servicestatus->problem_has_been_acknowledged == TRUE) {
4209 services_warning_acknowledged++;
4210 problem = FALSE;
4211 }
4212 if(temp_servicestatus->checks_enabled == FALSE) {
4213 services_warning_disabled++;
4214 problem = FALSE;
4215 }
4216 if(problem == TRUE)
4217 services_warning_unacknowledged++;
4218 services_warning++;
4219 }
4220
4221 else if(temp_servicestatus->status == SERVICE_UNKNOWN) {
4222 temp_hoststatus = find_hoststatus(temp_servicestatus->host_name);
4223 if(temp_hoststatus != NULL && (temp_hoststatus->status == HOST_DOWN || temp_hoststatus->status == HOST_UNREACHABLE)) {
4224 services_unknown_host_problem++;
4225 problem = FALSE;
4226 }
4227 if(temp_servicestatus->scheduled_downtime_depth > 0) {
4228 services_unknown_scheduled++;
4229 problem = FALSE;
4230 }
4231 if(temp_servicestatus->problem_has_been_acknowledged == TRUE) {
4232 services_unknown_acknowledged++;
4233 problem = FALSE;
4234 }
4235 if(temp_servicestatus->checks_enabled == FALSE) {
4236 services_unknown_disabled++;
4237 problem = FALSE;
4238 }
4239 if(problem == TRUE)
4240 services_unknown_unacknowledged++;
4241 services_unknown++;
4242 }
4243
4244 else if(temp_servicestatus->status == SERVICE_CRITICAL) {
4245 temp_hoststatus = find_hoststatus(temp_servicestatus->host_name);
4246 if(temp_hoststatus != NULL && (temp_hoststatus->status == HOST_DOWN || temp_hoststatus->status == HOST_UNREACHABLE)) {
4247 services_critical_host_problem++;
4248 problem = FALSE;
4249 }
4250 if(temp_servicestatus->scheduled_downtime_depth > 0) {
4251 services_critical_scheduled++;
4252 problem = FALSE;
4253 }
4254 if(temp_servicestatus->problem_has_been_acknowledged == TRUE) {
4255 services_critical_acknowledged++;
4256 problem = FALSE;
4257 }
4258 if(temp_servicestatus->checks_enabled == FALSE) {
4259 services_critical_disabled++;
4260 problem = FALSE;
4261 }
4262 if(problem == TRUE)
4263 services_critical_unacknowledged++;
4264 services_critical++;
4265 }
4266
4267 else if(temp_servicestatus->status == SERVICE_PENDING)
4268 services_pending++;
4269 }
4270
4271
4272 printf("<table border=0>\n");
4273
4274 if(services_ok > 0)
4275 printf("<tr><td class='miniStatusOK'><a href='%s?hostgroup=%s&style=detail&&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d OK</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), SERVICE_OK, host_status_types, service_properties, host_properties, services_ok);
4276
4277 if(services_warning > 0) {
4278 printf("<tr>\n");
4279 printf("<td class='miniStatusWARNING'><table border='0'>\n");
4280 printf("<tr>\n");
4281
4282 printf("<td class='miniStatusWARNING'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d WARNING</a> :</td>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), SERVICE_WARNING, host_status_types, service_properties, host_properties, services_warning);
4283
4284 printf("<td><table border='0'>\n");
4285
4286 if(services_warning_unacknowledged > 0)
4287 printf("<tr><td width=100%% class='serviceImportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%d'>%d Unhandled</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), SERVICE_WARNING, HOST_UP | HOST_PENDING, SERVICE_NO_SCHEDULED_DOWNTIME | SERVICE_STATE_UNACKNOWLEDGED | SERVICE_CHECKS_ENABLED, services_warning_unacknowledged);
4288
4289 if(services_warning_host_problem > 0)
4290 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d'>%d on Problem Hosts</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), SERVICE_WARNING, HOST_DOWN | HOST_UNREACHABLE, services_warning_host_problem);
4291
4292 if(services_warning_scheduled > 0)
4293 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Scheduled</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), SERVICE_WARNING, SERVICE_SCHEDULED_DOWNTIME, services_warning_scheduled);
4294
4295 if(services_warning_acknowledged > 0)
4296 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Acknowledged</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), SERVICE_WARNING, SERVICE_STATE_ACKNOWLEDGED, services_warning_acknowledged);
4297
4298 if(services_warning_disabled > 0)
4299 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Disabled</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), SERVICE_WARNING, SERVICE_CHECKS_DISABLED, services_warning_disabled);
4300
4301 printf("</table></td>\n");
4302
4303 printf("</tr>\n");
4304 printf("</table></td>\n");
4305 printf("</tr>\n");
4306 }
4307
4308 if(services_unknown > 0) {
4309 printf("<tr>\n");
4310 printf("<td class='miniStatusUNKNOWN'><table border='0'>\n");
4311 printf("<tr>\n");
4312
4313 printf("<td class='miniStatusUNKNOWN'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d UNKNOWN</a> :</td>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), SERVICE_UNKNOWN, host_status_types, service_properties, host_properties, services_unknown);
4314
4315 printf("<td><table border='0'>\n");
4316
4317 if(services_unknown_unacknowledged > 0)
4318 printf("<tr><td width=100%% class='serviceImportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%d'>%d Unhandled</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), SERVICE_UNKNOWN, HOST_UP | HOST_PENDING, SERVICE_NO_SCHEDULED_DOWNTIME | SERVICE_STATE_UNACKNOWLEDGED | SERVICE_CHECKS_ENABLED, services_unknown_unacknowledged);
4319
4320 if(services_unknown_host_problem > 0)
4321 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d'>%d on Problem Hosts</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), SERVICE_UNKNOWN, HOST_DOWN | HOST_UNREACHABLE, services_unknown_host_problem);
4322
4323 if(services_unknown_scheduled > 0)
4324 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Scheduled</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), SERVICE_UNKNOWN, SERVICE_SCHEDULED_DOWNTIME, services_unknown_scheduled);
4325
4326 if(services_unknown_acknowledged > 0)
4327 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Acknowledged</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), SERVICE_UNKNOWN, SERVICE_STATE_ACKNOWLEDGED, services_unknown_acknowledged);
4328
4329 if(services_unknown_disabled > 0)
4330 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Disabled</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), SERVICE_UNKNOWN, SERVICE_CHECKS_DISABLED, services_unknown_disabled);
4331
4332 printf("</table></td>\n");
4333
4334 printf("</tr>\n");
4335 printf("</table></td>\n");
4336 printf("</tr>\n");
4337 }
4338
4339 if(services_critical > 0) {
4340 printf("<tr>\n");
4341 printf("<td class='miniStatusCRITICAL'><table border='0'>\n");
4342 printf("<tr>\n");
4343
4344 printf("<td class='miniStatusCRITICAL'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d CRITICAL</a> :</td>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), SERVICE_CRITICAL, host_status_types, service_properties, host_properties, services_critical);
4345
4346 printf("<td><table border='0'>\n");
4347
4348 if(services_critical_unacknowledged > 0)
4349 printf("<tr><td width=100%% class='serviceImportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%d'>%d Unhandled</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), SERVICE_CRITICAL, HOST_UP | HOST_PENDING, SERVICE_NO_SCHEDULED_DOWNTIME | SERVICE_STATE_UNACKNOWLEDGED | SERVICE_CHECKS_ENABLED, services_critical_unacknowledged);
4350
4351 if(services_critical_host_problem > 0)
4352 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d'>%d on Problem Hosts</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), SERVICE_CRITICAL, HOST_DOWN | HOST_UNREACHABLE, services_critical_host_problem);
4353
4354 if(services_critical_scheduled > 0)
4355 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Scheduled</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), SERVICE_CRITICAL, SERVICE_SCHEDULED_DOWNTIME, services_critical_scheduled);
4356
4357 if(services_critical_acknowledged > 0)
4358 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Acknowledged</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), SERVICE_CRITICAL, SERVICE_STATE_ACKNOWLEDGED, services_critical_acknowledged);
4359
4360 if(services_critical_disabled > 0)
4361 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Disabled</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), SERVICE_CRITICAL, SERVICE_CHECKS_DISABLED, services_critical_disabled);
4362
4363 printf("</table></td>\n");
4364
4365 printf("</tr>\n");
4366 printf("</table></td>\n");
4367 printf("</tr>\n");
4368 }
4369
4370 if(services_pending > 0)
4371 printf("<tr><td class='miniStatusPENDING'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d PENDING</a></td></tr>\n", STATUS_CGI, url_encode(temp_hostgroup->group_name), SERVICE_PENDING, host_status_types, service_properties, host_properties, services_pending);
4372
4373 printf("</table>\n");
4374
4375 if((services_ok + services_warning + services_unknown + services_critical + services_pending) == 0)
4376 printf("No matching services");
4377
4378 return;
4379 }
4380
4381
4382
4383 /* show a grid layout of hostgroup(s)... */
show_hostgroup_grids(void)4384 void show_hostgroup_grids(void) {
4385 hostgroup *temp_hostgroup = NULL;
4386 int user_has_seen_something = FALSE;
4387 int hostgroup_error = FALSE;
4388 int odd = 0;
4389
4390
4391 printf("<P>\n");
4392
4393 printf("<table border=0 width=100%%>\n");
4394 printf("<tr>\n");
4395
4396 printf("<td valign=top align=left width=33%%>\n");
4397
4398 show_filters();
4399
4400 printf("</td>");
4401
4402 printf("<td valign=top align=center width=33%%>\n");
4403
4404 printf("<div align='center' class='statusTitle'>Status Grid For ");
4405 if(show_all_hostgroups == TRUE)
4406 printf("All Host Groups");
4407 else
4408 printf("Host Group '%s'", hostgroup_name);
4409 printf("</div>\n");
4410
4411 printf("<br>");
4412
4413 printf("</td>\n");
4414
4415 printf("<td valign=top align=right width=33%%></td>\n");
4416
4417 printf("</tr>\n");
4418 printf("</table>\n");
4419
4420 printf("</P>\n");
4421
4422
4423 /* display status grids for all hostgroups */
4424 if(show_all_hostgroups == TRUE) {
4425
4426 /* loop through all hostgroups... */
4427 for(temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {
4428
4429 /* make sure the user is authorized to view this hostgroup */
4430 if(is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == FALSE)
4431 continue;
4432
4433 if(odd == 0)
4434 odd = 1;
4435 else
4436 odd = 0;
4437
4438 /* show grid for this hostgroup */
4439 show_hostgroup_grid(temp_hostgroup);
4440
4441 user_has_seen_something = TRUE;
4442 }
4443
4444 }
4445
4446 /* else just show grid for a specific hostgroup */
4447 else {
4448 temp_hostgroup = find_hostgroup(hostgroup_name);
4449 if(temp_hostgroup == NULL)
4450 hostgroup_error = TRUE;
4451 else {
4452 show_hostgroup_grid(temp_hostgroup);
4453 user_has_seen_something = TRUE;
4454 }
4455 }
4456
4457 /* if user couldn't see anything, print out some helpful info... */
4458 if(user_has_seen_something == FALSE && hostgroup_error == FALSE) {
4459
4460 printf("<P><div align='center'>\n");
4461
4462 if(hoststatus_list != NULL) {
4463 printf("<div class='errorMessage'>It appears as though you do not have permission to view information for any of the hosts you requested...</div>\n");
4464 printf("<div class='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
4465 printf("and check the authorization options in your CGI configuration file.</div>\n");
4466 }
4467 else {
4468 printf("<div class='infoMessage'>There doesn't appear to be any host status information in the status log...<br><br>\n");
4469 printf("Make sure that Nagios is running and that you have specified the location of you status log correctly in the configuration files.</div>\n");
4470 }
4471
4472 printf("</div></P>\n");
4473 }
4474
4475 /* we couldn't find the hostgroup */
4476 else if(hostgroup_error == TRUE) {
4477 printf("<P><div align='center'>\n");
4478 printf("<div class='errorMessage'>Sorry, but hostgroup '%s' doesn't seem to exist...</div>\n", hostgroup_name);
4479 printf("</div></P>\n");
4480 }
4481
4482 return;
4483 }
4484
4485
4486 /* displays status grid for a specific hostgroup */
show_hostgroup_grid(hostgroup * temp_hostgroup)4487 void show_hostgroup_grid(hostgroup *temp_hostgroup) {
4488 hostsmember *temp_member;
4489 char *status_bg_class = "";
4490 char *host_status_class = "";
4491 char *service_status_class = "";
4492 host *temp_host;
4493 service *temp_service;
4494 hoststatus *temp_hoststatus;
4495 servicestatus *temp_servicestatus;
4496 char *processed_string = NULL;
4497 int odd = 0;
4498 int current_item;
4499
4500
4501 printf("<P>\n");
4502 printf("<div align='center'>\n");
4503
4504 printf("<div class='status'><a href='%s?hostgroup=%s&style=detail'>%s</a>", STATUS_CGI, url_encode(temp_hostgroup->group_name), temp_hostgroup->alias);
4505 printf(" (<a href='%s?type=%d&hostgroup=%s'>%s</a>)</div>", EXTINFO_CGI, DISPLAY_HOSTGROUP_INFO, url_encode(temp_hostgroup->group_name), temp_hostgroup->group_name);
4506
4507 printf("<table class='status' align='center'>\n");
4508 printf("<tr><th class='status'>Host</th><th class='status'>Services</a></th><th class='status'>Actions</th></tr>\n");
4509
4510 /* find all the hosts that belong to the hostgroup */
4511 for(temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
4512
4513 /* find the host... */
4514 temp_host = find_host(temp_member->host_name);
4515 if(temp_host == NULL)
4516 continue;
4517
4518 /* grab macros */
4519 grab_host_macros_r(mac, temp_host);
4520
4521 /* find the host status */
4522 temp_hoststatus = find_hoststatus(temp_host->name);
4523 if(temp_hoststatus == NULL)
4524 continue;
4525
4526 if(odd == 1) {
4527 status_bg_class = "Even";
4528 odd = 0;
4529 }
4530 else {
4531 status_bg_class = "Odd";
4532 odd = 1;
4533 }
4534
4535 printf("<tr class='status%s'>\n", status_bg_class);
4536
4537 /* get the status of the host */
4538 if(temp_hoststatus->status == HOST_DOWN)
4539 host_status_class = "HOStdOWN";
4540 else if(temp_hoststatus->status == HOST_UNREACHABLE)
4541 host_status_class = "HOSTUNREACHABLE";
4542 else
4543 host_status_class = status_bg_class;
4544
4545 printf("<td class='status%s'>", host_status_class);
4546
4547 printf("<table border=0 WIDTH='100%%' cellpadding=0 cellspacing=0>\n");
4548 printf("<tr>\n");
4549 printf("<td align='left'>\n");
4550 printf("<table border=0 cellpadding=0 cellspacing=0>\n");
4551 printf("<tr>\n");
4552 printf("<td align=left valign=center class='status%s'>", host_status_class);
4553 printf("<a href='%s?type=%d&host=%s'>%s</a>\n", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_host->name), temp_host->name);
4554 printf("</td>\n");
4555 printf("</tr>\n");
4556 printf("</table>\n");
4557 printf("</td>\n");
4558 printf("<td align=right valign=center nowrap>\n");
4559 printf("<table border=0 cellpadding=0 cellspacing=0>\n");
4560 printf("<tr>\n");
4561
4562 if(temp_host->icon_image != NULL) {
4563 printf("<td align=center valign=center>");
4564 printf("<a href='%s?type=%d&host=%s'>\n", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_host->name));
4565 printf("<IMG SRC='%s", url_logo_images_path);
4566 process_macros_r(mac, temp_host->icon_image, &processed_string, 0);
4567 printf("%s", processed_string);
4568 free(processed_string);
4569 printf("' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>", STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, (temp_host->icon_image_alt == NULL) ? "" : temp_host->icon_image_alt, (temp_host->icon_image_alt == NULL) ? "" : temp_host->icon_image_alt);
4570 printf("</a>");
4571 printf("<td>\n");
4572 }
4573 printf("<td>\n");
4574
4575 printf("</tr>\n");
4576 printf("</table>\n");
4577 printf("</td>\n");
4578 printf("</tr>\n");
4579 printf("</table>\n");
4580
4581 printf("</td>\n");
4582
4583 printf("<td class='status%s'>", host_status_class);
4584
4585 /* display all services on the host */
4586 current_item = 1;
4587 for(temp_service = service_list; temp_service; temp_service = temp_service->next) {
4588
4589 /* skip this service if it's not associate with the host */
4590 if(strcmp(temp_service->host_name, temp_host->name))
4591 continue;
4592
4593 if(current_item > max_grid_width && max_grid_width > 0) {
4594 printf("<BR>\n");
4595 current_item = 1;
4596 }
4597
4598 /* grab macros */
4599 grab_service_macros_r(mac, temp_service);
4600
4601 /* get the status of the service */
4602 temp_servicestatus = find_servicestatus(temp_service->host_name, temp_service->description);
4603 if(temp_servicestatus == NULL)
4604 service_status_class = "NULL";
4605 else if(temp_servicestatus->status == SERVICE_OK)
4606 service_status_class = "OK";
4607 else if(temp_servicestatus->status == SERVICE_WARNING)
4608 service_status_class = "WARNING";
4609 else if(temp_servicestatus->status == SERVICE_UNKNOWN)
4610 service_status_class = "UNKNOWN";
4611 else if(temp_servicestatus->status == SERVICE_CRITICAL)
4612 service_status_class = "CRITICAL";
4613 else
4614 service_status_class = "PENDING";
4615
4616 printf("<a href='%s?type=%d&host=%s", EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(temp_servicestatus->host_name));
4617 printf("&service=%s' class='status%s'>%s</a> ", url_encode(temp_servicestatus->description), service_status_class, temp_servicestatus->description);
4618
4619 current_item++;
4620 }
4621
4622 printf("</td>\n");
4623
4624 /* actions */
4625 printf("<td class='status%s'>", host_status_class);
4626
4627 printf("<a href='%s?type=%d&host=%s'>\n", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_host->name));
4628 printf("<IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>", url_images_path, DETAIL_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, "View Extended Information For This Host", "View Extended Information For This Host");
4629 printf("</a>");
4630
4631 if(temp_host->notes_url != NULL) {
4632 printf("<a href='");
4633 process_macros_r(mac, temp_host->notes_url, &processed_string, 0);
4634 printf("%s", processed_string);
4635 free(processed_string);
4636 printf("' TARGET='%s'>", (notes_url_target == NULL) ? "_blank" : notes_url_target);
4637 printf("<IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>", url_images_path, NOTES_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, "View Extra Host Notes", "View Extra Host Notes");
4638 printf("</a>");
4639 }
4640 if(temp_host->action_url != NULL) {
4641 printf("<a href='");
4642 process_macros_r(mac, temp_host->action_url, &processed_string, 0);
4643 printf("%s", processed_string);
4644 free(processed_string);
4645 printf("' TARGET='%s'>", (action_url_target == NULL) ? "_blank" : action_url_target);
4646 printf("<IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>", url_images_path, ACTION_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, "Perform Extra Host Actions", "Perform Extra Host Actions");
4647 printf("</a>");
4648 }
4649
4650 printf("<a href='%s?host=%s'><img src='%s%s' border=0 alt='View Service Details For This Host' title='View Service Details For This Host'></a>\n", STATUS_CGI, url_encode(temp_host->name), url_images_path, STATUS_DETAIL_ICON);
4651 #ifdef USE_STATUSMAP
4652 printf("<a href='%s?host=%s'><IMG SRC='%s%s' border=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'></a>", STATUSMAP_CGI, url_encode(temp_host->name), url_images_path, STATUSMAP_ICON, STATUS_ICON_WIDTH, STATUS_ICON_HEIGHT, "Locate Host On Map", "Locate Host On Map");
4653 #endif
4654 printf("</td>\n");
4655
4656 printf("</tr>\n");
4657 }
4658
4659 printf("</table>\n");
4660 printf("</div>\n");
4661 printf("</P>\n");
4662
4663 return;
4664 }
4665
4666
4667
4668
4669 /******************************************************************/
4670 /********** SERVICE SORTING & FILTERING FUNCTIONS ***************/
4671 /******************************************************************/
4672
4673
4674 /* sorts the service list */
sort_services(int s_type,int s_option)4675 int sort_services(int s_type, int s_option) {
4676 servicesort *new_servicesort;
4677 servicesort *last_servicesort;
4678 servicesort *temp_servicesort;
4679 servicestatus *temp_svcstatus;
4680
4681 if(s_type == SORT_NONE)
4682 return ERROR;
4683
4684 if(servicestatus_list == NULL)
4685 return ERROR;
4686
4687 /* sort all services status entries */
4688 for(temp_svcstatus = servicestatus_list; temp_svcstatus != NULL; temp_svcstatus = temp_svcstatus->next) {
4689
4690 /* allocate memory for a new sort structure */
4691 new_servicesort = (servicesort *)malloc(sizeof(servicesort));
4692 if(new_servicesort == NULL)
4693 return ERROR;
4694
4695 new_servicesort->svcstatus = temp_svcstatus;
4696
4697 last_servicesort = servicesort_list;
4698 for(temp_servicesort = servicesort_list; temp_servicesort != NULL; temp_servicesort = temp_servicesort->next) {
4699
4700 if(compare_servicesort_entries(s_type, s_option, new_servicesort, temp_servicesort) == TRUE) {
4701 new_servicesort->next = temp_servicesort;
4702 if(temp_servicesort == servicesort_list)
4703 servicesort_list = new_servicesort;
4704 else
4705 last_servicesort->next = new_servicesort;
4706 break;
4707 }
4708 else
4709 last_servicesort = temp_servicesort;
4710 }
4711
4712 if(servicesort_list == NULL) {
4713 new_servicesort->next = NULL;
4714 servicesort_list = new_servicesort;
4715 }
4716 else if(temp_servicesort == NULL) {
4717 new_servicesort->next = NULL;
4718 last_servicesort->next = new_servicesort;
4719 }
4720 }
4721
4722 return OK;
4723 }
4724
4725
compare_servicesort_entries(int s_type,int s_option,servicesort * new_servicesort,servicesort * temp_servicesort)4726 int compare_servicesort_entries(int s_type, int s_option, servicesort *new_servicesort, servicesort *temp_servicesort) {
4727 servicestatus *new_svcstatus;
4728 servicestatus *temp_svcstatus;
4729 time_t nt;
4730 time_t tt;
4731
4732 new_svcstatus = new_servicesort->svcstatus;
4733 temp_svcstatus = temp_servicesort->svcstatus;
4734
4735 if(s_type == SORT_ASCENDING) {
4736
4737 if(s_option == SORT_LASTCHECKTIME) {
4738 if(new_svcstatus->last_check < temp_svcstatus->last_check)
4739 return TRUE;
4740 else
4741 return FALSE;
4742 }
4743 else if(s_option == SORT_CURRENTATTEMPT) {
4744 if(new_svcstatus->current_attempt < temp_svcstatus->current_attempt)
4745 return TRUE;
4746 else
4747 return FALSE;
4748 }
4749 else if(s_option == SORT_SERVICESTATUS) {
4750 if(new_svcstatus->status <= temp_svcstatus->status)
4751 return TRUE;
4752 else
4753 return FALSE;
4754 }
4755 else if(s_option == SORT_HOSTNAME) {
4756 if(strcasecmp(new_svcstatus->host_name, temp_svcstatus->host_name) < 0)
4757 return TRUE;
4758 else
4759 return FALSE;
4760 }
4761 else if(s_option == SORT_SERVICENAME) {
4762 if(strcasecmp(new_svcstatus->description, temp_svcstatus->description) < 0)
4763 return TRUE;
4764 else
4765 return FALSE;
4766 }
4767 else if(s_option == SORT_STATEDURATION) {
4768 if(new_svcstatus->last_state_change == (time_t)0)
4769 nt = (program_start > current_time) ? 0 : (current_time - program_start);
4770 else
4771 nt = (new_svcstatus->last_state_change > current_time) ? 0 : (current_time - new_svcstatus->last_state_change);
4772 if(temp_svcstatus->last_state_change == (time_t)0)
4773 tt = (program_start > current_time) ? 0 : (current_time - program_start);
4774 else
4775 tt = (temp_svcstatus->last_state_change > current_time) ? 0 : (current_time - temp_svcstatus->last_state_change);
4776 if(nt < tt)
4777 return TRUE;
4778 else
4779 return FALSE;
4780 }
4781 }
4782 else {
4783 if(s_option == SORT_LASTCHECKTIME) {
4784 if(new_svcstatus->last_check > temp_svcstatus->last_check)
4785 return TRUE;
4786 else
4787 return FALSE;
4788 }
4789 else if(s_option == SORT_CURRENTATTEMPT) {
4790 if(new_svcstatus->current_attempt > temp_svcstatus->current_attempt)
4791 return TRUE;
4792 else
4793 return FALSE;
4794 }
4795 else if(s_option == SORT_SERVICESTATUS) {
4796 if(new_svcstatus->status > temp_svcstatus->status)
4797 return TRUE;
4798 else
4799 return FALSE;
4800 }
4801 else if(s_option == SORT_HOSTNAME) {
4802 if(strcasecmp(new_svcstatus->host_name, temp_svcstatus->host_name) > 0)
4803 return TRUE;
4804 else
4805 return FALSE;
4806 }
4807 else if(s_option == SORT_SERVICENAME) {
4808 if(strcasecmp(new_svcstatus->description, temp_svcstatus->description) > 0)
4809 return TRUE;
4810 else
4811 return FALSE;
4812 }
4813 else if(s_option == SORT_STATEDURATION) {
4814 if(new_svcstatus->last_state_change == (time_t)0)
4815 nt = (program_start > current_time) ? 0 : (current_time - program_start);
4816 else
4817 nt = (new_svcstatus->last_state_change > current_time) ? 0 : (current_time - new_svcstatus->last_state_change);
4818 if(temp_svcstatus->last_state_change == (time_t)0)
4819 tt = (program_start > current_time) ? 0 : (current_time - program_start);
4820 else
4821 tt = (temp_svcstatus->last_state_change > current_time) ? 0 : (current_time - temp_svcstatus->last_state_change);
4822 if(nt > tt)
4823 return TRUE;
4824 else
4825 return FALSE;
4826 }
4827 }
4828
4829 return TRUE;
4830 }
4831
4832
4833
4834 /* sorts the host list */
sort_hosts(int s_type,int s_option)4835 int sort_hosts(int s_type, int s_option) {
4836 hostsort *new_hostsort;
4837 hostsort *last_hostsort;
4838 hostsort *temp_hostsort;
4839 hoststatus *temp_hststatus;
4840
4841 if(s_type == SORT_NONE)
4842 return ERROR;
4843
4844 if(hoststatus_list == NULL)
4845 return ERROR;
4846
4847 /* sort all hosts status entries */
4848 for(temp_hststatus = hoststatus_list; temp_hststatus != NULL; temp_hststatus = temp_hststatus->next) {
4849
4850 /* allocate memory for a new sort structure */
4851 new_hostsort = (hostsort *)malloc(sizeof(hostsort));
4852 if(new_hostsort == NULL)
4853 return ERROR;
4854
4855 new_hostsort->hststatus = temp_hststatus;
4856
4857 last_hostsort = hostsort_list;
4858 for(temp_hostsort = hostsort_list; temp_hostsort != NULL; temp_hostsort = temp_hostsort->next) {
4859
4860 if(compare_hostsort_entries(s_type, s_option, new_hostsort, temp_hostsort) == TRUE) {
4861 new_hostsort->next = temp_hostsort;
4862 if(temp_hostsort == hostsort_list)
4863 hostsort_list = new_hostsort;
4864 else
4865 last_hostsort->next = new_hostsort;
4866 break;
4867 }
4868 else
4869 last_hostsort = temp_hostsort;
4870 }
4871
4872 if(hostsort_list == NULL) {
4873 new_hostsort->next = NULL;
4874 hostsort_list = new_hostsort;
4875 }
4876 else if(temp_hostsort == NULL) {
4877 new_hostsort->next = NULL;
4878 last_hostsort->next = new_hostsort;
4879 }
4880 }
4881
4882 return OK;
4883 }
4884
4885
compare_hostsort_entries(int s_type,int s_option,hostsort * new_hostsort,hostsort * temp_hostsort)4886 int compare_hostsort_entries(int s_type, int s_option, hostsort *new_hostsort, hostsort *temp_hostsort) {
4887 hoststatus *new_hststatus;
4888 hoststatus *temp_hststatus;
4889 time_t nt;
4890 time_t tt;
4891
4892 new_hststatus = new_hostsort->hststatus;
4893 temp_hststatus = temp_hostsort->hststatus;
4894
4895 if(s_type == SORT_ASCENDING) {
4896
4897 if(s_option == SORT_LASTCHECKTIME) {
4898 if(new_hststatus->last_check < temp_hststatus->last_check)
4899 return TRUE;
4900 else
4901 return FALSE;
4902 }
4903 else if(s_option == SORT_HOSTSTATUS) {
4904 if(new_hststatus->status <= temp_hststatus->status)
4905 return TRUE;
4906 else
4907 return FALSE;
4908 }
4909 else if(s_option == SORT_HOSTURGENCY) {
4910 if(HOST_URGENCY(new_hststatus->status) <= HOST_URGENCY(temp_hststatus->status))
4911 return TRUE;
4912 else
4913 return FALSE;
4914 }
4915 else if(s_option == SORT_HOSTNAME) {
4916 if(strcasecmp(new_hststatus->host_name, temp_hststatus->host_name) < 0)
4917 return TRUE;
4918 else
4919 return FALSE;
4920 }
4921 else if(s_option == SORT_STATEDURATION) {
4922 if(new_hststatus->last_state_change == (time_t)0)
4923 nt = (program_start > current_time) ? 0 : (current_time - program_start);
4924 else
4925 nt = (new_hststatus->last_state_change > current_time) ? 0 : (current_time - new_hststatus->last_state_change);
4926 if(temp_hststatus->last_state_change == (time_t)0)
4927 tt = (program_start > current_time) ? 0 : (current_time - program_start);
4928 else
4929 tt = (temp_hststatus->last_state_change > current_time) ? 0 : (current_time - temp_hststatus->last_state_change);
4930 if(nt < tt)
4931 return TRUE;
4932 else
4933 return FALSE;
4934 }
4935 }
4936 else {
4937 if(s_option == SORT_LASTCHECKTIME) {
4938 if(new_hststatus->last_check > temp_hststatus->last_check)
4939 return TRUE;
4940 else
4941 return FALSE;
4942 }
4943 else if(s_option == SORT_HOSTSTATUS) {
4944 if(new_hststatus->status > temp_hststatus->status)
4945 return TRUE;
4946 else
4947 return FALSE;
4948 }
4949 else if(s_option == SORT_HOSTURGENCY) {
4950 if(HOST_URGENCY(new_hststatus->status) > HOST_URGENCY(temp_hststatus->status))
4951 return TRUE;
4952 else
4953 return FALSE;
4954 }
4955 else if(s_option == SORT_HOSTNAME) {
4956 if(strcasecmp(new_hststatus->host_name, temp_hststatus->host_name) > 0)
4957 return TRUE;
4958 else
4959 return FALSE;
4960 }
4961 else if(s_option == SORT_STATEDURATION) {
4962 if(new_hststatus->last_state_change == (time_t)0)
4963 nt = (program_start > current_time) ? 0 : (current_time - program_start);
4964 else
4965 nt = (new_hststatus->last_state_change > current_time) ? 0 : (current_time - new_hststatus->last_state_change);
4966 if(temp_hststatus->last_state_change == (time_t)0)
4967 tt = (program_start > current_time) ? 0 : (current_time - program_start);
4968 else
4969 tt = (temp_hststatus->last_state_change > current_time) ? 0 : (current_time - temp_hststatus->last_state_change);
4970 if(nt > tt)
4971 return TRUE;
4972 else
4973 return FALSE;
4974 }
4975 }
4976
4977 return TRUE;
4978 }
4979
4980
4981
4982 /* free all memory allocated to the servicesort structures */
free_servicesort_list(void)4983 void free_servicesort_list(void) {
4984 servicesort *this_servicesort;
4985 servicesort *next_servicesort;
4986
4987 /* free memory for the servicesort list */
4988 for(this_servicesort = servicesort_list; this_servicesort != NULL; this_servicesort = next_servicesort) {
4989 next_servicesort = this_servicesort->next;
4990 free(this_servicesort);
4991 }
4992
4993 return;
4994 }
4995
4996
4997 /* free all memory allocated to the hostsort structures */
free_hostsort_list(void)4998 void free_hostsort_list(void) {
4999 hostsort *this_hostsort;
5000 hostsort *next_hostsort;
5001
5002 /* free memory for the hostsort list */
5003 for(this_hostsort = hostsort_list; this_hostsort != NULL; this_hostsort = next_hostsort) {
5004 next_hostsort = this_hostsort->next;
5005 free(this_hostsort);
5006 }
5007
5008 return;
5009 }
5010
5011
5012
5013 /* check host properties filter */
passes_host_properties_filter(hoststatus * temp_hoststatus)5014 int passes_host_properties_filter(hoststatus *temp_hoststatus) {
5015
5016 if((host_properties & HOST_SCHEDULED_DOWNTIME) && temp_hoststatus->scheduled_downtime_depth <= 0)
5017 return FALSE;
5018
5019 if((host_properties & HOST_NO_SCHEDULED_DOWNTIME) && temp_hoststatus->scheduled_downtime_depth > 0)
5020 return FALSE;
5021
5022 if((host_properties & HOST_STATE_ACKNOWLEDGED) && temp_hoststatus->problem_has_been_acknowledged == FALSE)
5023 return FALSE;
5024
5025 if((host_properties & HOST_STATE_UNACKNOWLEDGED) && temp_hoststatus->problem_has_been_acknowledged == TRUE)
5026 return FALSE;
5027
5028 if((host_properties & HOST_CHECKS_DISABLED) && temp_hoststatus->checks_enabled == TRUE)
5029 return FALSE;
5030
5031 if((host_properties & HOST_CHECKS_ENABLED) && temp_hoststatus->checks_enabled == FALSE)
5032 return FALSE;
5033
5034 if((host_properties & HOST_EVENT_HANDLER_DISABLED) && temp_hoststatus->event_handler_enabled == TRUE)
5035 return FALSE;
5036
5037 if((host_properties & HOST_EVENT_HANDLER_ENABLED) && temp_hoststatus->event_handler_enabled == FALSE)
5038 return FALSE;
5039
5040 if((host_properties & HOST_FLAP_DETECTION_DISABLED) && temp_hoststatus->flap_detection_enabled == TRUE)
5041 return FALSE;
5042
5043 if((host_properties & HOST_FLAP_DETECTION_ENABLED) && temp_hoststatus->flap_detection_enabled == FALSE)
5044 return FALSE;
5045
5046 if((host_properties & HOST_IS_FLAPPING) && temp_hoststatus->is_flapping == FALSE)
5047 return FALSE;
5048
5049 if((host_properties & HOST_IS_NOT_FLAPPING) && temp_hoststatus->is_flapping == TRUE)
5050 return FALSE;
5051
5052 if((host_properties & HOST_NOTIFICATIONS_DISABLED) && temp_hoststatus->notifications_enabled == TRUE)
5053 return FALSE;
5054
5055 if((host_properties & HOST_NOTIFICATIONS_ENABLED) && temp_hoststatus->notifications_enabled == FALSE)
5056 return FALSE;
5057
5058 if((host_properties & HOST_PASSIVE_CHECKS_DISABLED) && temp_hoststatus->accept_passive_host_checks == TRUE)
5059 return FALSE;
5060
5061 if((host_properties & HOST_PASSIVE_CHECKS_ENABLED) && temp_hoststatus->accept_passive_host_checks == FALSE)
5062 return FALSE;
5063
5064 if((host_properties & HOST_PASSIVE_CHECK) && temp_hoststatus->check_type == HOST_CHECK_ACTIVE)
5065 return FALSE;
5066
5067 if((host_properties & HOST_ACTIVE_CHECK) && temp_hoststatus->check_type == HOST_CHECK_PASSIVE)
5068 return FALSE;
5069
5070 if((host_properties & HOST_HARD_STATE) && temp_hoststatus->state_type == SOFT_STATE)
5071 return FALSE;
5072
5073 if((host_properties & HOST_SOFT_STATE) && temp_hoststatus->state_type == HARD_STATE)
5074 return FALSE;
5075
5076 return TRUE;
5077 }
5078
5079
5080
5081 /* check service properties filter */
passes_service_properties_filter(servicestatus * temp_servicestatus)5082 int passes_service_properties_filter(servicestatus *temp_servicestatus) {
5083
5084 if((service_properties & SERVICE_SCHEDULED_DOWNTIME) && temp_servicestatus->scheduled_downtime_depth <= 0)
5085 return FALSE;
5086
5087 if((service_properties & SERVICE_NO_SCHEDULED_DOWNTIME) && temp_servicestatus->scheduled_downtime_depth > 0)
5088 return FALSE;
5089
5090 if((service_properties & SERVICE_STATE_ACKNOWLEDGED) && temp_servicestatus->problem_has_been_acknowledged == FALSE)
5091 return FALSE;
5092
5093 if((service_properties & SERVICE_STATE_UNACKNOWLEDGED) && temp_servicestatus->problem_has_been_acknowledged == TRUE)
5094 return FALSE;
5095
5096 if((service_properties & SERVICE_CHECKS_DISABLED) && temp_servicestatus->checks_enabled == TRUE)
5097 return FALSE;
5098
5099 if((service_properties & SERVICE_CHECKS_ENABLED) && temp_servicestatus->checks_enabled == FALSE)
5100 return FALSE;
5101
5102 if((service_properties & SERVICE_EVENT_HANDLER_DISABLED) && temp_servicestatus->event_handler_enabled == TRUE)
5103 return FALSE;
5104
5105 if((service_properties & SERVICE_EVENT_HANDLER_ENABLED) && temp_servicestatus->event_handler_enabled == FALSE)
5106 return FALSE;
5107
5108 if((service_properties & SERVICE_FLAP_DETECTION_DISABLED) && temp_servicestatus->flap_detection_enabled == TRUE)
5109 return FALSE;
5110
5111 if((service_properties & SERVICE_FLAP_DETECTION_ENABLED) && temp_servicestatus->flap_detection_enabled == FALSE)
5112 return FALSE;
5113
5114 if((service_properties & SERVICE_IS_FLAPPING) && temp_servicestatus->is_flapping == FALSE)
5115 return FALSE;
5116
5117 if((service_properties & SERVICE_IS_NOT_FLAPPING) && temp_servicestatus->is_flapping == TRUE)
5118 return FALSE;
5119
5120 if((service_properties & SERVICE_NOTIFICATIONS_DISABLED) && temp_servicestatus->notifications_enabled == TRUE)
5121 return FALSE;
5122
5123 if((service_properties & SERVICE_NOTIFICATIONS_ENABLED) && temp_servicestatus->notifications_enabled == FALSE)
5124 return FALSE;
5125
5126 if((service_properties & SERVICE_PASSIVE_CHECKS_DISABLED) && temp_servicestatus->accept_passive_service_checks == TRUE)
5127 return FALSE;
5128
5129 if((service_properties & SERVICE_PASSIVE_CHECKS_ENABLED) && temp_servicestatus->accept_passive_service_checks == FALSE)
5130 return FALSE;
5131
5132 if((service_properties & SERVICE_PASSIVE_CHECK) && temp_servicestatus->check_type == SERVICE_CHECK_ACTIVE)
5133 return FALSE;
5134
5135 if((service_properties & SERVICE_ACTIVE_CHECK) && temp_servicestatus->check_type == SERVICE_CHECK_PASSIVE)
5136 return FALSE;
5137
5138 if((service_properties & SERVICE_HARD_STATE) && temp_servicestatus->state_type == SOFT_STATE)
5139 return FALSE;
5140
5141 if((service_properties & SERVICE_SOFT_STATE) && temp_servicestatus->state_type == HARD_STATE)
5142 return FALSE;
5143
5144 return TRUE;
5145 }
5146
5147
5148
5149 /* shows service and host filters in use */
show_filters(void)5150 void show_filters(void) {
5151 int found = 0;
5152
5153 /* show filters box if necessary */
5154 if(host_properties != 0L || service_properties != 0L || host_status_types != all_host_status_types || service_status_types != all_service_status_types) {
5155
5156 printf("<table class='filter'>\n");
5157 printf("<tr><td class='filter'>\n");
5158 printf("<table border=0 cellspacing=2 cellpadding=0>\n");
5159 printf("<tr><td colspan=2 valign=top align=left class='filterTitle'>Display Filters:</td></tr>");
5160 printf("<tr><td valign=top align=left class='filterName'>Host Status Types:</td>");
5161 printf("<td valign=top align=left class='filterValue'>");
5162 if(host_status_types == all_host_status_types)
5163 printf("All");
5164 else if(host_status_types == all_host_problems)
5165 printf("All problems");
5166 else {
5167 found = 0;
5168 if(host_status_types & HOST_PENDING) {
5169 printf(" Pending");
5170 found = 1;
5171 }
5172 if(host_status_types & HOST_UP) {
5173 printf("%s Up", (found == 1) ? " |" : "");
5174 found = 1;
5175 }
5176 if(host_status_types & HOST_DOWN) {
5177 printf("%s Down", (found == 1) ? " |" : "");
5178 found = 1;
5179 }
5180 if(host_status_types & HOST_UNREACHABLE)
5181 printf("%s Unreachable", (found == 1) ? " |" : "");
5182 }
5183 printf("</td></tr>");
5184 printf("<tr><td valign=top align=left class='filterName'>Host Properties:</td>");
5185 printf("<td valign=top align=left class='filterValue'>");
5186 if(host_properties == 0)
5187 printf("Any");
5188 else {
5189 found = 0;
5190 if(host_properties & HOST_SCHEDULED_DOWNTIME) {
5191 printf(" In Scheduled Downtime");
5192 found = 1;
5193 }
5194 if(host_properties & HOST_NO_SCHEDULED_DOWNTIME) {
5195 printf("%s Not In Scheduled Downtime", (found == 1) ? " &" : "");
5196 found = 1;
5197 }
5198 if(host_properties & HOST_STATE_ACKNOWLEDGED) {
5199 printf("%s Has Been Acknowledged", (found == 1) ? " &" : "");
5200 found = 1;
5201 }
5202 if(host_properties & HOST_STATE_UNACKNOWLEDGED) {
5203 printf("%s Has Not Been Acknowledged", (found == 1) ? " &" : "");
5204 found = 1;
5205 }
5206 if(host_properties & HOST_CHECKS_DISABLED) {
5207 printf("%s Checks Disabled", (found == 1) ? " &" : "");
5208 found = 1;
5209 }
5210 if(host_properties & HOST_CHECKS_ENABLED) {
5211 printf("%s Checks Enabled", (found == 1) ? " &" : "");
5212 found = 1;
5213 }
5214 if(host_properties & HOST_EVENT_HANDLER_DISABLED) {
5215 printf("%s Event Handler Disabled", (found == 1) ? " &" : "");
5216 found = 1;
5217 }
5218 if(host_properties & HOST_EVENT_HANDLER_ENABLED) {
5219 printf("%s Event Handler Enabled", (found == 1) ? " &" : "");
5220 found = 1;
5221 }
5222 if(host_properties & HOST_FLAP_DETECTION_DISABLED) {
5223 printf("%s Flap Detection Disabled", (found == 1) ? " &" : "");
5224 found = 1;
5225 }
5226 if(host_properties & HOST_FLAP_DETECTION_ENABLED) {
5227 printf("%s Flap Detection Enabled", (found == 1) ? " &" : "");
5228 found = 1;
5229 }
5230 if(host_properties & HOST_IS_FLAPPING) {
5231 printf("%s Is Flapping", (found == 1) ? " &" : "");
5232 found = 1;
5233 }
5234 if(host_properties & HOST_IS_NOT_FLAPPING) {
5235 printf("%s Is Not Flapping", (found == 1) ? " &" : "");
5236 found = 1;
5237 }
5238 if(host_properties & HOST_NOTIFICATIONS_DISABLED) {
5239 printf("%s Notifications Disabled", (found == 1) ? " &" : "");
5240 found = 1;
5241 }
5242 if(host_properties & HOST_NOTIFICATIONS_ENABLED) {
5243 printf("%s Notifications Enabled", (found == 1) ? " &" : "");
5244 found = 1;
5245 }
5246 if(host_properties & HOST_PASSIVE_CHECKS_DISABLED) {
5247 printf("%s Passive Checks Disabled", (found == 1) ? " &" : "");
5248 found = 1;
5249 }
5250 if(host_properties & HOST_PASSIVE_CHECKS_ENABLED) {
5251 printf("%s Passive Checks Enabled", (found == 1) ? " &" : "");
5252 found = 1;
5253 }
5254 if(host_properties & HOST_PASSIVE_CHECK) {
5255 printf("%s Passive Checks", (found == 1) ? " &" : "");
5256 found = 1;
5257 }
5258 if(host_properties & HOST_ACTIVE_CHECK) {
5259 printf("%s Active Checks", (found == 1) ? " &" : "");
5260 found = 1;
5261 }
5262 if(host_properties & HOST_HARD_STATE) {
5263 printf("%s In Hard State", (found == 1) ? " &" : "");
5264 found = 1;
5265 }
5266 if(host_properties & HOST_SOFT_STATE) {
5267 printf("%s In Soft State", (found == 1) ? " &" : "");
5268 found = 1;
5269 }
5270 }
5271 printf("</td>");
5272 printf("</tr>\n");
5273
5274
5275 printf("<tr><td valign=top align=left class='filterName'>Service Status Types:</td>");
5276 printf("<td valign=top align=left class='filterValue'>");
5277 if(service_status_types == all_service_status_types)
5278 printf("All");
5279 else if(service_status_types == all_service_problems)
5280 printf("All Problems");
5281 else {
5282 found = 0;
5283 if(service_status_types & SERVICE_PENDING) {
5284 printf(" Pending");
5285 found = 1;
5286 }
5287 if(service_status_types & SERVICE_OK) {
5288 printf("%s Ok", (found == 1) ? " |" : "");
5289 found = 1;
5290 }
5291 if(service_status_types & SERVICE_UNKNOWN) {
5292 printf("%s Unknown", (found == 1) ? " |" : "");
5293 found = 1;
5294 }
5295 if(service_status_types & SERVICE_WARNING) {
5296 printf("%s Warning", (found == 1) ? " |" : "");
5297 found = 1;
5298 }
5299 if(service_status_types & SERVICE_CRITICAL) {
5300 printf("%s Critical", (found == 1) ? " |" : "");
5301 found = 1;
5302 }
5303 }
5304 printf("</td></tr>");
5305 printf("<tr><td valign=top align=left class='filterName'>Service Properties:</td>");
5306 printf("<td valign=top align=left class='filterValue'>");
5307 if(service_properties == 0)
5308 printf("Any");
5309 else {
5310 found = 0;
5311 if(service_properties & SERVICE_SCHEDULED_DOWNTIME) {
5312 printf(" In Scheduled Downtime");
5313 found = 1;
5314 }
5315 if(service_properties & SERVICE_NO_SCHEDULED_DOWNTIME) {
5316 printf("%s Not In Scheduled Downtime", (found == 1) ? " &" : "");
5317 found = 1;
5318 }
5319 if(service_properties & SERVICE_STATE_ACKNOWLEDGED) {
5320 printf("%s Has Been Acknowledged", (found == 1) ? " &" : "");
5321 found = 1;
5322 }
5323 if(service_properties & SERVICE_STATE_UNACKNOWLEDGED) {
5324 printf("%s Has Not Been Acknowledged", (found == 1) ? " &" : "");
5325 found = 1;
5326 }
5327 if(service_properties & SERVICE_CHECKS_DISABLED) {
5328 printf("%s Active Checks Disabled", (found == 1) ? " &" : "");
5329 found = 1;
5330 }
5331 if(service_properties & SERVICE_CHECKS_ENABLED) {
5332 printf("%s Active Checks Enabled", (found == 1) ? " &" : "");
5333 found = 1;
5334 }
5335 if(service_properties & SERVICE_EVENT_HANDLER_DISABLED) {
5336 printf("%s Event Handler Disabled", (found == 1) ? " &" : "");
5337 found = 1;
5338 }
5339 if(service_properties & SERVICE_EVENT_HANDLER_ENABLED) {
5340 printf("%s Event Handler Enabled", (found == 1) ? " &" : "");
5341 found = 1;
5342 }
5343 if(service_properties & SERVICE_FLAP_DETECTION_DISABLED) {
5344 printf("%s Flap Detection Disabled", (found == 1) ? " &" : "");
5345 found = 1;
5346 }
5347 if(service_properties & SERVICE_FLAP_DETECTION_ENABLED) {
5348 printf("%s Flap Detection Enabled", (found == 1) ? " &" : "");
5349 found = 1;
5350 }
5351 if(service_properties & SERVICE_IS_FLAPPING) {
5352 printf("%s Is Flapping", (found == 1) ? " &" : "");
5353 found = 1;
5354 }
5355 if(service_properties & SERVICE_IS_NOT_FLAPPING) {
5356 printf("%s Is Not Flapping", (found == 1) ? " &" : "");
5357 found = 1;
5358 }
5359 if(service_properties & SERVICE_NOTIFICATIONS_DISABLED) {
5360 printf("%s Notifications Disabled", (found == 1) ? " &" : "");
5361 found = 1;
5362 }
5363 if(service_properties & SERVICE_NOTIFICATIONS_ENABLED) {
5364 printf("%s Notifications Enabled", (found == 1) ? " &" : "");
5365 found = 1;
5366 }
5367 if(service_properties & SERVICE_PASSIVE_CHECKS_DISABLED) {
5368 printf("%s Passive Checks Disabled", (found == 1) ? " &" : "");
5369 found = 1;
5370 }
5371 if(service_properties & SERVICE_PASSIVE_CHECKS_ENABLED) {
5372 printf("%s Passive Checks Enabled", (found == 1) ? " &" : "");
5373 found = 1;
5374 }
5375 if(service_properties & SERVICE_PASSIVE_CHECK) {
5376 printf("%s Passive Checks", (found == 1) ? " &" : "");
5377 found = 1;
5378 }
5379 if(service_properties & SERVICE_ACTIVE_CHECK) {
5380 printf("%s Active Checks", (found == 1) ? " &" : "");
5381 found = 1;
5382 }
5383 if(service_properties & SERVICE_HARD_STATE) {
5384 printf("%s In Hard State", (found == 1) ? " &" : "");
5385 found = 1;
5386 }
5387 if(service_properties & SERVICE_SOFT_STATE) {
5388 printf("%s In Soft State", (found == 1) ? " &" : "");
5389 found = 1;
5390 }
5391 }
5392 printf("</td></tr>");
5393 printf("</table>\n");
5394
5395 printf("</td></tr>");
5396 printf("</table>\n");
5397 }
5398
5399 return;
5400 }
5401
create_pagenumbers(int total_entries,int visible_entries,char * temp_url,int type_service)5402 void create_pagenumbers(int total_entries, int visible_entries, char *temp_url, int type_service) {
5403
5404 int pages = 1;
5405 int leftovers = 0;
5406 int tmp_start;
5407 int i;
5408 int next_page;
5409 int previous_page;
5410
5411 /* do page numbers if applicable */
5412 if(result_limit > 0 && total_entries > result_limit) {
5413 pages = (total_entries / result_limit);
5414 leftovers = (total_entries % result_limit);
5415 previous_page = (page_start - result_limit) > 0 ? (page_start - result_limit) : 0;
5416 next_page = (page_start + result_limit) > total_entries ? page_start : (page_start + result_limit);
5417 printf("<div id='bottom_page_numbers'>\n");
5418 printf("<div class='inner_numbers'>\n");
5419 printf("<a href='%s&start=0&limit=%i' class='pagenumber' title='First Page'><img src='%s%s' height='15' width='15' alt='<<' /></a>\n", temp_url, result_limit, url_images_path, FIRST_PAGE_ICON);
5420 printf("<a href='%s&start=%i&limit=%i' class='pagenumber' title='Previous Page'><img src='%s%s' height='15' width='10' alt='<' /></a>\n", temp_url, previous_page, result_limit, url_images_path, PREVIOUS_PAGE_ICON);
5421
5422 for(i = 0; i < (pages + 1); i++) {
5423 tmp_start = (i * result_limit);
5424 if(tmp_start == page_start)
5425 printf("<div class='pagenumber current_page'> %i </div>\n", (i + 1));
5426 else
5427 printf("<a class='pagenumber' href='%s&start=%i&limit=%i' title='Page %i'> %i </a>\n", temp_url, tmp_start, result_limit, (i + 1), (i + 1));
5428 }
5429
5430 printf("<a href='%s&start=%i&limit=%i' class='pagenumber' title='Next Page'><img src='%s%s' height='15' width='10' alt='>' /></a>\n", temp_url, (page_start + result_limit), result_limit, url_images_path, NEXT_PAGE_ICON);
5431 printf("<a href='%s&start=%i&limit=%i' class='pagenumber' title='Last Page'><img src='%s%s' height='15' width='15' alt='>>' /></a>\n", temp_url, ((pages)*result_limit), result_limit, url_images_path, LAST_PAGE_ICON);
5432 printf("</div> <!-- end inner_page_numbers div -->\n");
5433 if(type_service == TRUE)
5434 printf("<br /><div class='itemTotalsTitle'>Results %i - %i of %d Matching Services</div>\n</div>\n", page_start, ((page_start + result_limit) > total_entries ? total_entries : (page_start + result_limit)), total_entries);
5435 else
5436 printf("<br /><div class='itemTotalsTitle'>Results %i - %i of %d Matching Hosts</div>\n\n", page_start, ((page_start + result_limit) > total_entries ? total_entries : (page_start + result_limit)), total_entries);
5437
5438 printf("</div> <!-- end bottom_page_numbers div -->\n\n");
5439 }
5440 else {
5441 if(type_service == TRUE)
5442 printf("<br /><div class='itemTotalsTitle'>Results %i - %i of %d Matching Services</div>\n</div>\n", 1, total_entries, total_entries);
5443 else
5444 printf("<br /><div class='itemTotalsTitle'>Results %i - %i of %d Matching Hosts</div>\n\n", 1, total_entries, total_entries);
5445
5446 }
5447
5448 /* show total results displayed */
5449 //printf("<br /><div class='itemTotalsTitle'>Results %i - %i of %d Matching Services</div>\n</div>\n",page_start,((page_start+result_limit) > total_entries ? total_entries :(page_start+result_limit) ),total_entries );
5450
5451 }
5452
create_page_limiter(int result_limit,char * temp_url)5453 void create_page_limiter(int result_limit, char *temp_url) {
5454
5455 /* Result Limit Select Box */
5456 printf("<div id='pagelimit'>\n<div id='result_limit'>\n");
5457 printf("<label for='limit'>Limit Results: </label>\n");
5458 printf("<select onchange='set_limit(\"%s\")' name='limit' id='limit'>\n", temp_url);
5459 printf("<option %s value='50'>50</option>\n", ((result_limit == 50) ? "selected='selected'" : ""));
5460 printf("<option %s value='100'>100</option>\n", ((result_limit == 100) ? "selected='selected'" : ""));
5461 printf("<option %s value='250'>250</option>\n", ((result_limit == 250) ? "selected='selected'" : ""));
5462 printf("<option %s value='1000'>1000</option>\n", ((result_limit == 1000) ? "selected='selected'" : ""));
5463 printf("<option %s value='0'>All</option>\n", (result_limit == 0) ? "selected='selected'" : "");
5464 printf("</select></div>\n");
5465 printf("<div id='top_page_numbers'></div>\n</div>\n");
5466 //page numbers
5467
5468 }
5469