[d97e03]: cgi / notifications.c  Maximize  Restore  History

Download this file

746 lines (611 with data), 25.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
/************************************************************************
*
* NOTIFICATIONS.C - Nagios Notifications CGI
*
*
* This CGI program will display the notification events for
* a given host or contact or for all contacts/hosts.
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
***********************************************************************/
#include "../include/config.h"
#include "../include/common.h"
#include "../include/getcgi.h"
#include "../include/cgiutils.h"
#include "../include/cgiauth.h"
extern char main_config_file[MAX_FILENAME_LENGTH];
extern char url_html_path[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH];
extern char url_docs_path[MAX_FILENAME_LENGTH];
extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
#define FIND_HOST 1
#define FIND_CONTACT 2
#define FIND_SERVICE 3
#define MAX_QUERYNAME_LENGTH 256
#define SERVICE_NOTIFICATION 0
#define HOST_NOTIFICATION 1
#define SERVICE_NOTIFICATION_STRING "] SERVICE NOTIFICATION:"
#define HOST_NOTIFICATION_STRING "] HOST NOTIFICATION:"
void display_notifications(void);
void document_header(int);
void document_footer(void);
int process_cgivars(void);
authdata current_authdata;
char log_file_to_use[MAX_FILENAME_LENGTH];
int log_archive = 0;
int query_type = FIND_HOST;
int find_all = TRUE;
char *query_contact_name = "";
char *query_host_name = "";
char *query_svc_description = "";
int notification_options = NOTIFICATION_ALL;
int use_lifo = TRUE;
int embedded = FALSE;
int display_header = TRUE;
int main(void) {
char temp_buffer[MAX_INPUT_BUFFER];
char temp_buffer2[MAX_INPUT_BUFFER];
/* get the arguments passed in the URL */
process_cgivars();
/* reset internal variables */
reset_cgi_vars();
cgi_init(document_header, document_footer, READ_ALL_OBJECT_DATA, 0);
document_header(TRUE);
/* get authentication information */
get_authentication_information(&current_authdata);
/* determine what log file we should use */
get_log_archive_to_use(log_archive, log_file_to_use, (int)sizeof(log_file_to_use));
if(display_header == TRUE) {
/* begin top table */
printf("<table border=0 width=100%%>\n");
printf("<tr>\n");
/* left column of top row */
printf("<td align=left valign=top width=33%%>\n");
if(query_type == FIND_SERVICE)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Service Notifications");
else if(query_type == FIND_HOST) {
if(find_all == TRUE)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Notifications");
else
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Host Notifications");
}
else
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Contact Notifications");
display_info_table(temp_buffer, FALSE, &current_authdata);
if(query_type == FIND_HOST || query_type == FIND_SERVICE) {
printf("<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 CLASS='linkBox'>\n");
printf("<TR><TD CLASS='linkBox'>\n");
if(query_type == FIND_HOST) {
printf("<A HREF='%s?host=%s'>View Status Detail For %s</A><BR>\n", STATUS_CGI, (find_all == TRUE) ? "all" : url_encode(query_host_name), (find_all == TRUE) ? "All Hosts" : "This Host");
printf("<A HREF='%s?host=%s'>View History For %s</A><BR>\n", HISTORY_CGI, (find_all == TRUE) ? "all" : url_encode(query_host_name), (find_all == TRUE) ? "All Hosts" : "This Host");
#ifdef USE_TRENDS
if(find_all == FALSE)
printf("<A HREF='%s?host=%s'>View Trends For This Host</A><BR>\n", TRENDS_CGI, url_encode(query_host_name));
#endif
}
else if(query_type == FIND_SERVICE) {
printf("<A HREF='%s?host=%s&", HISTORY_CGI, (find_all == TRUE) ? "all" : url_encode(query_host_name));
printf("service=%s'>View History For This Service</A><BR>\n", url_encode(query_svc_description));
#ifdef USE_TRENDS
printf("<A HREF='%s?host=%s&", TRENDS_CGI, (find_all == TRUE) ? "all" : url_encode(query_host_name));
printf("service=%s'>View Trends For This Service</A><BR>\n", url_encode(query_svc_description));
#endif
}
printf("</TD></TR>\n");
printf("</TABLE>\n");
}
printf("</td>\n");
/* middle column of top row */
printf("<td align=center valign=top width=33%%>\n");
printf("<DIV ALIGN=CENTER CLASS='dataTitle'>\n");
if(query_type == FIND_SERVICE)
printf("Service '%s' On Host '%s'", query_svc_description, query_host_name);
else if(query_type == FIND_HOST) {
if(find_all == TRUE)
printf("All Hosts and Services");
else
printf("Host '%s'", query_host_name);
}
else {
if(find_all == TRUE)
printf("All Contacts");
else
printf("Contact '%s'", query_contact_name);
}
printf("</DIV>\n");
printf("<BR>\n");
if(query_type == FIND_SERVICE) {
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%s?%shost=%s&", NOTIFICATIONS_CGI, (use_lifo == FALSE) ? "oldestfirst&" : "", url_encode(query_host_name));
snprintf(temp_buffer2, sizeof(temp_buffer2) - 1, "service=%s&type=%d&", url_encode(query_svc_description), notification_options);
strncat(temp_buffer, temp_buffer2, sizeof(temp_buffer) - strlen(temp_buffer) - 1);
}
else
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%s?%s%s=%s&type=%d&", NOTIFICATIONS_CGI, (use_lifo == FALSE) ? "oldestfirst&" : "", (query_type == FIND_HOST) ? "host" : "contact", (query_type == FIND_HOST) ? url_encode(query_host_name) : url_encode(query_contact_name), notification_options);
temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
display_nav_table(temp_buffer, log_archive);
printf("</td>\n");
/* right hand column of top row */
printf("<td align=right valign=top width=33%%>\n");
printf("<form method='GET' action='%s'>\n", NOTIFICATIONS_CGI);
if(query_type == FIND_SERVICE) {
printf("<input type='hidden' name='host' value='%s'>\n", escape_string(query_host_name));
printf("<input type='hidden' name='service' value='%s'>\n", escape_string(query_svc_description));
}
else
printf("<input type='hidden' name='%s' value='%s'>\n", (query_type == FIND_HOST) ? "host" : "contact", (query_type == FIND_HOST) ? escape_string(query_host_name) : escape_string(query_contact_name));
printf("<input type='hidden' name='archive' value='%d'>\n", log_archive);
printf("<table border=0 CLASS='optBox'>\n");
printf("<tr>\n");
if(query_type == FIND_SERVICE)
printf("<td align=left colspan=2 CLASS='optBoxItem'>Notification detail level for this service:</td>");
else
printf("<td align=left colspan=2 CLASS='optBoxItem'>Notification detail level for %s %s%s:</td>", (find_all == TRUE) ? "all" : "this", (query_type == FIND_HOST) ? "host" : "contact", (find_all == TRUE) ? "s" : "");
printf("</tr>\n");
printf("<tr>\n");
printf("<td align=left colspan=2 CLASS='optBoxItem'><select name='type'>\n");
printf("<option value=%d %s>All notifications\n", NOTIFICATION_ALL, (notification_options == NOTIFICATION_ALL) ? "selected" : "");
if(query_type != FIND_SERVICE) {
printf("<option value=%d %s>All service notifications\n", NOTIFICATION_SERVICE_ALL, (notification_options == NOTIFICATION_SERVICE_ALL) ? "selected" : "");
printf("<option value=%d %s>All host notifications\n", NOTIFICATION_HOST_ALL, (notification_options == NOTIFICATION_HOST_ALL) ? "selected" : "");
}
printf("<option value=%d %s>Service custom\n", NOTIFICATION_SERVICE_CUSTOM, (notification_options == NOTIFICATION_SERVICE_CUSTOM) ? "selected" : "");
printf("<option value=%d %s>Service acknowledgements\n", NOTIFICATION_SERVICE_ACK, (notification_options == NOTIFICATION_SERVICE_ACK) ? "selected" : "");
printf("<option value=%d %s>Service warning\n", NOTIFICATION_SERVICE_WARNING, (notification_options == NOTIFICATION_SERVICE_WARNING) ? "selected" : "");
printf("<option value=%d %s>Service unknown\n", NOTIFICATION_SERVICE_UNKNOWN, (notification_options == NOTIFICATION_SERVICE_UNKNOWN) ? "selected" : "");
printf("<option value=%d %s>Service critical\n", NOTIFICATION_SERVICE_CRITICAL, (notification_options == NOTIFICATION_SERVICE_CRITICAL) ? "selected" : "");
printf("<option value=%d %s>Service recovery\n", NOTIFICATION_SERVICE_RECOVERY, (notification_options == NOTIFICATION_SERVICE_RECOVERY) ? "selected" : "");
printf("<option value=%d %s>Service flapping\n", NOTIFICATION_SERVICE_FLAP, (notification_options == NOTIFICATION_SERVICE_FLAP) ? "selected" : "");
if(query_type != FIND_SERVICE) {
printf("<option value=%d %s>Host custom\n", NOTIFICATION_HOST_CUSTOM, (notification_options == NOTIFICATION_HOST_CUSTOM) ? "selected" : "");
printf("<option value=%d %s>Host acknowledgements\n", NOTIFICATION_HOST_ACK, (notification_options == NOTIFICATION_HOST_ACK) ? "selected" : "");
printf("<option value=%d %s>Host down\n", NOTIFICATION_HOST_DOWN, (notification_options == NOTIFICATION_HOST_DOWN) ? "selected" : "");
printf("<option value=%d %s>Host unreachable\n", NOTIFICATION_HOST_UNREACHABLE, (notification_options == NOTIFICATION_HOST_UNREACHABLE) ? "selected" : "");
printf("<option value=%d %s>Host recovery\n", NOTIFICATION_HOST_RECOVERY, (notification_options == NOTIFICATION_HOST_RECOVERY) ? "selected" : "");
printf("<option value=%d %s>Host flapping\n", NOTIFICATION_HOST_FLAP, (notification_options == NOTIFICATION_HOST_FLAP) ? "selected" : "");
}
printf("</select></td>\n");
printf("</tr>\n");
printf("<tr>\n");
printf("<td align=left CLASS='optBoxItem'>Older Entries First:</td>\n");
printf("<td></td>\n");
printf("</tr>\n");
printf("<tr>\n");
printf("<td align=left valign=bottom CLASS='optBoxItem'><input type='checkbox' name='oldestfirst' %s></td>", (use_lifo == FALSE) ? "checked" : "");
printf("<td align=right CLASS='optBoxItem'><input type='submit' value='Update'></td>\n");
printf("</tr>\n");
/* display context-sensitive help */
printf("<tr><td></td><td align=right valign=bottom>\n");
display_context_help(CONTEXTHELP_NOTIFICATIONS);
printf("</td></tr>\n");
printf("</table>\n");
printf("</form>\n");
printf("</td>\n");
/* end of top table */
printf("</tr>\n");
printf("</table>\n");
}
/* display notifications */
display_notifications();
document_footer();
/* free allocated memory */
free_memory();
return OK;
}
void document_header(int use_stylesheet) {
char date_time[MAX_DATETIME_LENGTH];
time_t current_time;
time_t expire_time;
printf("Cache-Control: no-store\r\n");
printf("Pragma: no-cache\r\n");
time(&current_time);
get_time_string(&current_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME);
printf("Last-Modified: %s\r\n", date_time);
expire_time = (time_t)0L;
get_time_string(&expire_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME);
printf("Expires: %s\r\n", date_time);
printf("Content-type: text/html\r\n\r\n");
if(embedded == TRUE)
return;
printf("<html>\n");
printf("<head>\n");
printf("<link rel=\"shortcut icon\" href=\"%sfavicon.ico\" type=\"image/ico\">\n", url_images_path);
printf("<title>\n");
printf("Alert Notifications\n");
printf("</title>\n");
if(use_stylesheet == TRUE) {
printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>\n", url_stylesheets_path, COMMON_CSS);
printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>\n", url_stylesheets_path, NOTIFICATIONS_CSS);
}
printf("</head>\n");
printf("<body CLASS='notifications'>\n");
/* include user SSI header */
include_ssi_files(NOTIFICATIONS_CGI, SSI_HEADER);
return;
}
void document_footer(void) {
if(embedded == TRUE)
return;
/* include user SSI footer */
include_ssi_files(NOTIFICATIONS_CGI, SSI_FOOTER);
printf("</body>\n");
printf("</html>\n");
return;
}
int process_cgivars(void) {
char **variables;
int error = FALSE;
int x;
variables = getcgivars();
for(x = 0; variables[x] != NULL; x++) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */
if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
continue;
}
/* we found the host argument */
else if(!strcmp(variables[x], "host")) {
query_type = FIND_HOST;
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
if((query_host_name = strdup(variables[x])) == NULL)
query_host_name = "";
strip_html_brackets(query_host_name);
if(!strcmp(query_host_name, "all"))
find_all = TRUE;
else
find_all = FALSE;
}
/* we found the contact argument */
else if(!strcmp(variables[x], "contact")) {
query_type = FIND_CONTACT;
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
if((query_contact_name = strdup(variables[x])) == NULL)
query_contact_name = "";
strip_html_brackets(query_contact_name);
if(!strcmp(query_contact_name, "all"))
find_all = TRUE;
else
find_all = FALSE;
}
/* we found the service argument */
else if(!strcmp(variables[x], "service")) {
query_type = FIND_SERVICE;
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
if((query_svc_description = strdup(variables[x])) == NULL)
query_svc_description = "";
strip_html_brackets(query_svc_description);
}
/* we found the notification type argument */
else if(!strcmp(variables[x], "type")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
notification_options = atoi(variables[x]);
}
/* we found the log archive argument */
else if(!strcmp(variables[x], "archive")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
log_archive = atoi(variables[x]);
if(log_archive < 0)
log_archive = 0;
}
/* we found the order argument */
else if(!strcmp(variables[x], "oldestfirst")) {
use_lifo = FALSE;
}
/* we found the embed option */
else if(!strcmp(variables[x], "embedded"))
embedded = TRUE;
/* we found the noheader option */
else if(!strcmp(variables[x], "noheader"))
display_header = FALSE;
}
/*
* Set some default values if not already set.
* Done here as they won't be set if variable
* not provided via cgi parameters
* Only required for hosts & contacts, not services
* as there is no service_name=all option
*/
if(query_type == FIND_HOST && strlen(query_host_name) == 0) {
query_host_name = "all";
find_all = TRUE;
}
if(query_type == FIND_CONTACT && strlen(query_contact_name) == 0) {
query_contact_name = "all";
find_all = TRUE;
}
/* free memory allocated to the CGI variables */
free_cgivars(variables);
return error;
}
void display_notifications(void) {
mmapfile *thefile = NULL;
char *input = NULL;
char *temp_buffer;
char date_time[MAX_DATETIME_LENGTH];
char alert_level[MAX_INPUT_BUFFER];
char alert_level_class[MAX_INPUT_BUFFER];
char contact_name[MAX_INPUT_BUFFER];
char service_name[MAX_INPUT_BUFFER];
char host_name[MAX_INPUT_BUFFER];
char method_name[MAX_INPUT_BUFFER];
int show_entry;
int total_notifications;
int notification_type = SERVICE_NOTIFICATION;
int notification_detail_type = NOTIFICATION_SERVICE_CRITICAL;
int odd = 0;
time_t t;
host *temp_host;
service *temp_service;
int result;
if(use_lifo == TRUE) {
result = read_file_into_lifo(log_file_to_use);
if(result != LIFO_OK) {
if(result == LIFO_ERROR_MEMORY) {
printf("<P><DIV CLASS='warningMessage'>Not enough memory to reverse log file - displaying notifications in natural order...</DIV></P>");
}
else if(result == LIFO_ERROR_FILE) {
printf("<P><DIV CLASS='errorMessage'>Error: Cannot open log file '%s' for reading!</DIV></P>", log_file_to_use);
return;
}
use_lifo = FALSE;
}
}
if(use_lifo == FALSE) {
if((thefile = mmap_fopen(log_file_to_use)) == NULL) {
printf("<P><DIV CLASS='errorMessage'>Error: Cannot open log file '%s' for reading!</DIV></P>", log_file_to_use);
return;
}
}
printf("<p>\n");
printf("<div align='center'>\n");
printf("<table border=0 CLASS='notifications'>\n");
printf("<tr>\n");
printf("<th CLASS='notifications'>Host</th>\n");
printf("<th CLASS='notifications'>Service</th>\n");
printf("<th CLASS='notifications'>Type</th>\n");
printf("<th CLASS='notifications'>Time</th>\n");
printf("<th CLASS='notifications'>Contact</th>\n");
printf("<th CLASS='notifications'>Notification Command</th>\n");
printf("<th CLASS='notifications'>Information</th>\n");
printf("</tr>\n");
total_notifications = 0;
while(1) {
free(input);
if(use_lifo == TRUE) {
if((input = pop_lifo()) == NULL)
break;
}
else {
if((input = mmap_fgets(thefile)) == NULL)
break;
}
strip(input);
/* see if this line contains the notification event string */
if(strstr(input, HOST_NOTIFICATION_STRING) || strstr(input, SERVICE_NOTIFICATION_STRING)) {
if(strstr(input, HOST_NOTIFICATION_STRING))
notification_type = HOST_NOTIFICATION;
else
notification_type = SERVICE_NOTIFICATION;
/* get the date/time */
temp_buffer = (char *)strtok(input, "]");
t = (time_t)(temp_buffer == NULL) ? 0L : strtoul(temp_buffer + 1, NULL, 10);
get_time_string(&t, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
strip(date_time);
/* get the contact name */
temp_buffer = (char *)strtok(NULL, ":");
temp_buffer = (char *)strtok(NULL, ";");
snprintf(contact_name, sizeof(contact_name), "%s", (temp_buffer == NULL) ? "" : temp_buffer + 1);
contact_name[sizeof(contact_name) - 1] = '\x0';
/* get the host name */
temp_buffer = (char *)strtok(NULL, ";");
snprintf(host_name, sizeof(host_name), "%s", (temp_buffer == NULL) ? "" : temp_buffer);
host_name[sizeof(host_name) - 1] = '\x0';
/* get the service name */
if(notification_type == SERVICE_NOTIFICATION) {
temp_buffer = (char *)strtok(NULL, ";");
snprintf(service_name, sizeof(service_name), "%s", (temp_buffer == NULL) ? "" : temp_buffer);
service_name[sizeof(service_name) - 1] = '\x0';
}
/* get the alert level */
temp_buffer = (char *)strtok(NULL, ";");
snprintf(alert_level, sizeof(alert_level), "%s", (temp_buffer == NULL) ? "" : temp_buffer);
alert_level[sizeof(alert_level) - 1] = '\x0';
if(notification_type == SERVICE_NOTIFICATION) {
if(!strcmp(alert_level, "CRITICAL")) {
notification_detail_type = NOTIFICATION_SERVICE_CRITICAL;
strcpy(alert_level_class, "CRITICAL");
}
else if(!strcmp(alert_level, "WARNING")) {
notification_detail_type = NOTIFICATION_SERVICE_WARNING;
strcpy(alert_level_class, "WARNING");
}
else if(!strcmp(alert_level, "RECOVERY") || !strcmp(alert_level, "OK")) {
strcpy(alert_level, "OK");
notification_detail_type = NOTIFICATION_SERVICE_RECOVERY;
strcpy(alert_level_class, "OK");
}
else if(strstr(alert_level, "CUSTOM (")) {
notification_detail_type = NOTIFICATION_SERVICE_CUSTOM;
strcpy(alert_level_class, "CUSTOM");
}
else if(strstr(alert_level, "ACKNOWLEDGEMENT (")) {
notification_detail_type = NOTIFICATION_SERVICE_ACK;
strcpy(alert_level_class, "ACKNOWLEDGEMENT");
}
else if(strstr(alert_level, "FLAPPINGSTART (")) {
strcpy(alert_level, "FLAPPING START");
notification_detail_type = NOTIFICATION_SERVICE_FLAP;
strcpy(alert_level_class, "UNKNOWN");
}
else if(strstr(alert_level, "FLAPPINGSTOP (")) {
strcpy(alert_level, "FLAPPING STOP");
notification_detail_type = NOTIFICATION_SERVICE_FLAP;
strcpy(alert_level_class, "UNKNOWN");
}
else {
strcpy(alert_level, "UNKNOWN");
notification_detail_type = NOTIFICATION_SERVICE_UNKNOWN;
strcpy(alert_level_class, "UNKNOWN");
}
}
else {
if(!strcmp(alert_level, "DOWN")) {
strncpy(alert_level, "HOST DOWN", sizeof(alert_level));
strcpy(alert_level_class, "HOSTDOWN");
notification_detail_type = NOTIFICATION_HOST_DOWN;
}
else if(!strcmp(alert_level, "UNREACHABLE")) {
strncpy(alert_level, "HOST UNREACHABLE", sizeof(alert_level));
strcpy(alert_level_class, "HOSTUNREACHABLE");
notification_detail_type = NOTIFICATION_HOST_UNREACHABLE;
}
else if(!strcmp(alert_level, "RECOVERY") || !strcmp(alert_level, "UP")) {
strncpy(alert_level, "HOST UP", sizeof(alert_level));
strcpy(alert_level_class, "HOSTUP");
notification_detail_type = NOTIFICATION_HOST_RECOVERY;
}
else if(strstr(alert_level, "CUSTOM (")) {
strcpy(alert_level_class, "HOSTCUSTOM");
notification_detail_type = NOTIFICATION_HOST_CUSTOM;
}
else if(strstr(alert_level, "ACKNOWLEDGEMENT (")) {
strcpy(alert_level_class, "HOSTACKNOWLEDGEMENT");
notification_detail_type = NOTIFICATION_HOST_ACK;
}
else if(strstr(alert_level, "FLAPPINGSTART (")) {
strcpy(alert_level, "FLAPPING START");
strcpy(alert_level_class, "UNKNOWN");
notification_detail_type = NOTIFICATION_HOST_FLAP;
}
else if(strstr(alert_level, "FLAPPINGSTOP (")) {
strcpy(alert_level, "FLAPPING STOP");
strcpy(alert_level_class, "UNKNOWN");
notification_detail_type = NOTIFICATION_HOST_FLAP;
}
}
/* get the method name */
temp_buffer = (char *)strtok(NULL, ";");
snprintf(method_name, sizeof(method_name), "%s", (temp_buffer == NULL) ? "" : temp_buffer);
method_name[sizeof(method_name) - 1] = '\x0';
/* move to the informational message */
temp_buffer = strtok(NULL, ";");
show_entry = FALSE;
/* if we're searching by contact, filter out unwanted contact */
if(query_type == FIND_CONTACT) {
if(find_all == TRUE)
show_entry = TRUE;
else if(!strcmp(query_contact_name, contact_name))
show_entry = TRUE;
}
else if(query_type == FIND_HOST) {
if(find_all == TRUE)
show_entry = TRUE;
else if(!strcmp(query_host_name, host_name))
show_entry = TRUE;
}
else if(query_type == FIND_SERVICE) {
if(!strcmp(query_host_name, host_name) && !strcmp(query_svc_description, service_name))
show_entry = TRUE;
}
if(show_entry == TRUE) {
if(notification_options == NOTIFICATION_ALL)
show_entry = TRUE;
else if(notification_options == NOTIFICATION_HOST_ALL && notification_type == HOST_NOTIFICATION)
show_entry = TRUE;
else if(notification_options == NOTIFICATION_SERVICE_ALL && notification_type == SERVICE_NOTIFICATION)
show_entry = TRUE;
else if(notification_detail_type & notification_options)
show_entry = TRUE;
else
show_entry = FALSE;
}
/* make sure user has authorization to view this notification */
if(notification_type == HOST_NOTIFICATION) {
temp_host = find_host(host_name);
if(is_authorized_for_host(temp_host, &current_authdata) == FALSE)
show_entry = FALSE;
}
else {
temp_service = find_service(host_name, service_name);
if(is_authorized_for_service(temp_service, &current_authdata) == FALSE)
show_entry = FALSE;
}
if(show_entry == TRUE) {
total_notifications++;
if(odd) {
odd = 0;
printf("<tr CLASS='notificationsOdd'>\n");
}
else {
odd = 1;
printf("<tr CLASS='notificationsEven'>\n");
}
printf("<td CLASS='notifications%s'><a href='%s?type=%d&host=%s'>%s</a></td>\n", (odd) ? "Even" : "Odd", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(host_name), host_name);
if(notification_type == SERVICE_NOTIFICATION) {
printf("<td CLASS='notifications%s'><a href='%s?type=%d&host=%s", (odd) ? "Even" : "Odd", EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(host_name));
printf("&service=%s'>%s</a></td>\n", url_encode(service_name), service_name);
}
else
printf("<td CLASS='notifications%s'>N/A</td>\n", (odd) ? "Even" : "Odd");
printf("<td CLASS='notifications%s'>%s</td>\n", alert_level_class, alert_level);
printf("<td CLASS='notifications%s'>%s</td>\n", (odd) ? "Even" : "Odd", date_time);
printf("<td CLASS='notifications%s'><a href='%s?type=contacts#%s'>%s</a></td>\n", (odd) ? "Even" : "Odd", CONFIG_CGI, url_encode(contact_name), contact_name);
printf("<td CLASS='notifications%s'><a href='%s?type=commands#%s'>%s</a></td>\n", (odd) ? "Even" : "Odd", CONFIG_CGI, url_encode(method_name), method_name);
printf("<td CLASS='notifications%s'>%s</td>\n", (odd) ? "Even" : "Odd", html_encode(temp_buffer, FALSE));
printf("</tr>\n");
}
}
}
printf("</table>\n");
printf("</div>\n");
printf("</p>\n");
if(total_notifications == 0) {
printf("<P><DIV CLASS='errorMessage'>No notifications have been recorded");
if(find_all == FALSE) {
if(query_type == FIND_SERVICE)
printf(" for this service");
else if(query_type == FIND_CONTACT)
printf(" for this contact");
else
printf(" for this host");
}
printf(" in %s log file</DIV></P>", (log_archive == 0) ? "the current" : "this archived");
}
free(input);
if(use_lifo == TRUE)
free_lifo_memory();
else
mmap_fclose(thefile);
return;
}