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 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
|
/*****************************************************************************
*
* NOTIFICATIONS.C - Icinga Notifications CGI
*
* Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org)
* Copyright (c) 2009-2015 Icinga Development Team (http://www.icinga.org)
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*****************************************************************************/
/** @file notifications.c
* @brief cgi to browse through Icinga notification history
**/
#include "../include/config.h"
#include "../include/common.h"
#include "../include/getcgi.h"
#include "../include/cgiutils.h"
#include "../include/cgiauth.h"
#include "../include/readlogs.h"
/** @name External vars
@{ **/
extern char *csv_delimiter;
extern char *csv_data_enclosure;
extern char main_config_file[MAX_FILENAME_LENGTH];
extern int embedded;
extern int display_header;
extern int daemon_check;
extern int content_type;
extern int result_limit;
extern int show_partial_hostgroups;
extern int show_partial_servicegroups;
/** @} */
/** @name Internal vars
@{ **/
int query_type = DISPLAY_HOSTS; /**< holds requested notifications type */
int find_all = TRUE; /**< display all or just one requested host / contact */
int notification_options = NOTIFICATION_ALL; /**< determine type of notifications */
int reverse = FALSE; /**< determine if log should be viewed in reverse order */
int timeperiod_type = TIMEPERIOD_SINGLE_DAY; /**< determines the time period to view see cgiutils.h */
int result_start = 1; /**< keep track from where we have to start displaying results */
int get_result_limit = -1; /**< needed to overwrite config value with result_limit we get vie GET */
char *query_contact_name = ""; /**< the requested contact */
char *query_host_name = ""; /**< the requested host name */
char *query_svc_description = ""; /**< the requested service */
char *query_hostgroup_name = ""; /**< the requested host group */
char *query_servicegroup_name = ""; /**< the requested service group */
char *start_time_string = ""; /**< the requested start time */
char *end_time_string = ""; /**< the requested end time */
time_t ts_start = 0L; /**< start time as unix timestamp */
time_t ts_end = 0L; /**< end time as unix timestamp */
authdata current_authdata; /**< struct to hold current authentication data */
html_request *html_request_list = NULL; /**< contains html requested data */
int CGI_ID = NOTIFICATIONS_CGI_ID; /**< ID to identify the cgi for functions in cgiutils.c */
/** @} */
/** @brief displays the requested notification entries
*
* Applies the requested filters, reads in all necessary log files
* and afterwards showing each matching notification log entry.
**/
void display_notifications(void);
/** @brief Parses the requested GET/POST variables
*
* @n This function parses the request and set's the necessary variables
**/
void process_cgivars(void);
/** @brief Yes we need a main function **/
int main(void) {
char buffer[MAX_DATETIME_LENGTH];
int result = OK;
/* get the arguments passed in the URL */
process_cgivars();
/* reset internal variables */
reset_cgi_vars();
/* read the CGI configuration file */
result = read_cgi_config_file(get_cgi_config_location());
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(get_cgi_config_location(), ERROR_CGI_CFG_FILE, FALSE);
document_footer(CGI_ID);
free_html_request(html_request_list);
return ERROR;
}
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(main_config_file, ERROR_CGI_MAIN_CFG, FALSE);
document_footer(CGI_ID);
free_html_request(html_request_list);
return ERROR;
}
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(NULL, ERROR_CGI_OBJECT_DATA, FALSE);
document_footer(CGI_ID);
free_html_request(html_request_list);
return ERROR;
}
/* This requires the date_format parameter in the main config file */
if (timeperiod_type == TIMEPERIOD_CUSTOM) {
if (strcmp(start_time_string, ""))
string_to_time(start_time_string, &ts_start);
if (strcmp(end_time_string, ""))
string_to_time(end_time_string, &ts_end);
}
/* overwrite config value with amount we got via GET */
result_limit = (get_result_limit != -1) ? get_result_limit : result_limit;
/* for json and csv output return all by default */
if (get_result_limit == -1 && (content_type == JSON_CONTENT || content_type == CSV_CONTENT))
result_limit = 0;
document_header(CGI_ID, TRUE, "Alert Notifications");
/* get authentication information */
get_authentication_information(¤t_authdata);
/* calculate timestamps for reading logs */
convert_timeperiod_to_times(timeperiod_type, &ts_start, &ts_end);
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 == DISPLAY_SERVICES)
display_info_table("Service Notifications", ¤t_authdata, daemon_check);
else if (query_type == DISPLAY_HOSTGROUPS)
display_info_table("Hostgroup Notifications", ¤t_authdata, daemon_check);
else if (query_type == DISPLAY_SERVICEGROUPS)
display_info_table("Servicegroup Notifications", ¤t_authdata, daemon_check);
else if (query_type == DISPLAY_HOSTS) {
if (find_all == TRUE)
display_info_table("Notifications", ¤t_authdata, daemon_check);
else
display_info_table("Host Notifications", ¤t_authdata, daemon_check);
} else
display_info_table("Contact Notifications", ¤t_authdata, daemon_check);
if (query_type == DISPLAY_HOSTS || query_type == DISPLAY_SERVICES || query_type == DISPLAY_HOSTGROUPS || query_type == DISPLAY_SERVICEGROUPS) {
printf("<table border='1' cellpadding='0' cellspacing='0' class='linkBox'>\n");
printf("<tr><td class='linkBox'>\n");
if (query_type == DISPLAY_HOSTS) {
printf("<a href='%s?host=%s'>View <b>Status Detail</b> For <b>%s</b></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 <b>Alert History</b> For <b>%s</b></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 <b>Trends</b> For <b>This Host</b></a><br>\n", TRENDS_CGI, url_encode(query_host_name));
#endif
printf("<a href='%s?type=%d&host=%s'>View <b>Information</b> For <b>This Host</b></a><br>\n", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(query_host_name));
printf("<a href='%s?host=%s&show_log_entries'>View <b>Availability Report</b> For <b>This Host</b></a><br>\n", AVAIL_CGI, url_encode(query_host_name));
} else if (query_type == DISPLAY_SERVICES) {
printf("<a href='%s?host=%s&", HISTORY_CGI, (find_all == TRUE) ? "all" : url_encode(query_host_name));
printf("service=%s'>View <b>Alert History</b> For <b>This Service</b></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 <b>Trends</b> For <b>This Service</b></a><br>\n", url_encode(query_svc_description));
#endif
printf("<a href='%s?type=%d&host=%s&service=%s'>View <b>Information</b> For <b>This Service</b></a><br>\n", EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(query_host_name), url_encode(query_svc_description));
printf("<a href='%s?host=%s&service=%s&show_log_entries'>View <b>Availability Report</b> For <b>This Service</b></a><br>\n", AVAIL_CGI, url_encode(query_host_name), url_encode(query_svc_description));
printf("<a href='%s?host=%s'>View <b>Notifications</b> For <b>This Host</b></a><br>\n", NOTIFICATIONS_CGI, url_encode(query_host_name));
} else if (query_type == DISPLAY_HOSTGROUPS) {
printf("<a href='%s?hostgroup=%s&style=hostdetail'>View <b>Host Status Detail</b> For <b>This Hostgroup</b></a><br>\n", STATUS_CGI, url_encode(query_hostgroup_name));
printf("<a href='%s?hostgroup=%s&style=detail'>View <b>Service Status Detail</b> For <b>This Hostgroup</b></a><br>\n", STATUS_CGI, url_encode(query_hostgroup_name));
printf("<a href='%s?hostgroup=%s'>View <b>Alert History</b> For <b>This Hostgroup</b></a><br>\n", HISTORY_CGI, url_encode(query_hostgroup_name));
} else if (query_type == DISPLAY_SERVICEGROUPS) {
printf("<a href='%s?servicegroup=%s&style=hostdetail'>View <b>Host Status Detail</b> For <b>This Servicegroup</b></a><br>\n", STATUS_CGI, url_encode(query_servicegroup_name));
printf("<a href='%s?servicegroup=%s&style=detail'>View <b>Service Status Detail</b> For <b>This Servicegroup</b></a><br>\n", STATUS_CGI, url_encode(query_servicegroup_name));
printf("<a href='%s?servicegroup=%s'>View <b>Alert History</b> For <b>This Servicegroup</b></a><br>\n", HISTORY_CGI, url_encode(query_servicegroup_name));
}
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 == DISPLAY_SERVICES)
printf("Service '%s' on Host '%s'", query_svc_description, query_host_name);
else if (query_type == DISPLAY_HOSTS) {
if (find_all == TRUE)
printf("All Hosts and Services");
else
printf("Host '%s'", html_encode(query_host_name, TRUE));
} else if (query_type == DISPLAY_HOSTGROUPS) {
printf("Host Group '%s'", html_encode(query_hostgroup_name, TRUE));
} else if (query_type == DISPLAY_SERVICEGROUPS) {
printf("Service Group '%s'", html_encode(query_servicegroup_name, TRUE));
} else {
if (find_all == TRUE)
printf("All Contacts");
else
printf("Contact '%s'", html_encode(query_contact_name, TRUE));
}
printf("</div>\n");
printf("<br>\n");
display_nav_table(ts_start, ts_end);
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 == DISPLAY_SERVICES) {
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 if (query_type == DISPLAY_HOSTGROUPS) {
printf("<input type='hidden' name='hostgroup' value='%s'>\n", escape_string(query_hostgroup_name));
} else if (query_type == DISPLAY_SERVICEGROUPS) {
printf("<input type='hidden' name='servicegroup' value='%s'>\n", escape_string(query_servicegroup_name));
} else
printf("<input type='hidden' name='%s' value='%s'>\n", (query_type == DISPLAY_HOSTS) ? "host" : "contact", (query_type == DISPLAY_HOSTS) ? escape_string(query_host_name) : escape_string(query_contact_name));
printf("<input type='hidden' name='ts_start' value='%lu'>\n", ts_start);
printf("<input type='hidden' name='ts_end' value='%lu'>\n", ts_end);
printf("<input type='hidden' name='limit' value='%d'>\n", result_limit);
printf("<table border='0' class='optBox'>\n");
printf("<tr>\n");
if (query_type == DISPLAY_SERVICES)
printf("<td align='left' colspan='2' class='optBoxItem'>Notification detail level for this service:</td>");
if (query_type == DISPLAY_HOSTGROUPS || query_type == DISPLAY_SERVICEGROUPS)
printf("<td align='left' colspan='2' class='optBoxItem'>Notification detail level for this %sgroup:</td>", (query_type == DISPLAY_HOSTGROUPS) ? "host" : "service");
else
printf("<td align='left' colspan='2' class='optBoxItem'>Notification detail level for %s %s%s:</td>", (find_all == TRUE) ? "all" : "this", (query_type == DISPLAY_HOSTS) ? "host" : "contact", (find_all == TRUE) ? "s" : "");
printf("</tr>\n");
printf("<tr><td></td>\n");
printf("<td align='left' class='optBoxItem'><select name='type'>\n");
printf("<option value='%d' %s>All notifications\n", NOTIFICATION_ALL, (notification_options == NOTIFICATION_ALL) ? "selected" : "");
if (query_type != DISPLAY_SERVICES) {
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 != DISPLAY_SERVICES) {
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");
/* Order */
printf("<tr><td align='right'>Order:</td>");
printf("<td nowrap><input type='radio' name='order' value='new2old' %s> Newer Entries First | <input type='radio' name='order' value='old2new' %s> Older Entries First</td></tr>\n", (reverse == TRUE) ? "" : "checked", (reverse == TRUE) ? "checked" : "");
/* Timeperiod */
printf("<tr><td align='left'>Timeperiod:</td>");
printf("<td align='left'>\n");
printf("<select id='selecttp' name='timeperiod' onChange=\"var i=document.getElementById('selecttp').selectedIndex; if (document.getElementById('selecttp').options[i].value == 'custom') { $( '#custtime' ).toggle( 'blind', {}, 200 ); } else { $( '#custtime' ).toggle( 'blind', {}, 200 ); }\">\n");
printf("<option value='singleday' %s>Single Day\n", (timeperiod_type == TIMEPERIOD_SINGLE_DAY) ? "selected" : "");
printf("<option value='today' %s>Today\n", (timeperiod_type == TIMEPERIOD_TODAY) ? "selected" : "");
printf("<option value='last24hours' %s>Last 24 Hours\n", (timeperiod_type == TIMEPERIOD_LAST24HOURS) ? "selected" : "");
printf("<option value='thisweek' %s>This Week\n", (timeperiod_type == TIMEPERIOD_THISWEEK) ? "selected" : "");
printf("<option value='last7days' %s>Last 7 Days\n", (timeperiod_type == TIMEPERIOD_LAST7DAYS) ? "selected" : "");
printf("<option value='lastweek' %s>Last Week\n", (timeperiod_type == TIMEPERIOD_LASTWEEK) ? "selected" : "");
printf("<option value='thismonth' %s>This Month\n", (timeperiod_type == TIMEPERIOD_THISMONTH) ? "selected" : "");
printf("<option value='last31days' %s>Last 31 Days\n", (timeperiod_type == TIMEPERIOD_LAST31DAYS) ? "selected" : "");
printf("<option value='lastmonth' %s>Last Month\n", (timeperiod_type == TIMEPERIOD_LASTMONTH) ? "selected" : "");
printf("<option value='thisyear' %s>This Year\n", (timeperiod_type == TIMEPERIOD_THISYEAR) ? "selected" : "");
printf("<option value='lastyear' %s>Last Year\n", (timeperiod_type == TIMEPERIOD_LASTYEAR) ? "selected" : "");
printf("<option value='custom' %s>* CUSTOM PERIOD *\n", (timeperiod_type == TIMEPERIOD_CUSTOM) ? "selected" : "");
printf("</select>\n");
printf("<div id='custtime' style='display:%s;'>", (timeperiod_type == TIMEPERIOD_CUSTOM) ? "" : "none");
printf("<br><table border='0' cellspacing='0' cellpadding='0'>\n");
get_time_string(&ts_start, buffer, sizeof(buffer) - 1, SHORT_DATE_TIME);
printf("<tr><td>Start: </td><td><input type='text' class='timepicker' name='start_time' value='%s' size='25'></td></tr>", buffer);
get_time_string(&ts_end, buffer, sizeof(buffer) - 1, SHORT_DATE_TIME);
printf("<tr><td>End: </td><td><input type='text' class='timepicker' name='end_time' value='%s' size='25'></td></tr></table></div>", buffer);
printf("</td></tr>\n");
/* submit Button */
printf("<tr><td><input type='submit' value='Update'></td><td align='right'><input type='reset' value='Reset' onClick=\"window.location.href='%s?order=new2old&timeperiod=singleday&limit=%d'\"> </td></tr>\n", NOTIFICATIONS_CGI, result_limit);
printf("</table>\n");
printf("</form>\n");
printf("</td>\n");
/* end of top table */
printf("</tr>\n");
printf("</table>\n");
}
/* display notifications */
display_notifications();
/* display footer */
document_footer(CGI_ID);
/* free allocated memory */
free_html_request(html_request_list);
free_memory();
return OK;
}
void process_cgivars(void) {
char *key = NULL;
char *value = NULL;
html_request *temp_request_item = NULL;
html_request_list = getcgivars();
for (temp_request_item = html_request_list; temp_request_item != NULL; temp_request_item = temp_request_item->next) {
key = temp_request_item->option;
value = temp_request_item->value;
/* we found the host argument */
if (!strcmp(key, "host") && value != NULL) {
query_type = DISPLAY_HOSTS;
if ((query_host_name = strdup(value)) == NULL)
query_host_name = "";
strip_html_brackets(query_host_name);
if (!strcmp(query_host_name, "all"))
find_all = TRUE;
else
find_all = FALSE;
temp_request_item->is_valid = TRUE;
}
/* we found the contact argument */
else if (!strcmp(key, "contact") && value != NULL) {
query_type = DISPLAY_CONTACTS;
if ((query_contact_name = strdup(value)) == NULL)
query_contact_name = "";
strip_html_brackets(query_contact_name);
if (!strcmp(query_contact_name, "all"))
find_all = TRUE;
else
find_all = FALSE;
temp_request_item->is_valid = TRUE;
}
/* we found the service argument */
else if (!strcmp(key, "service") && value != NULL) {
query_type = DISPLAY_SERVICES;
if ((query_svc_description = strdup(value)) == NULL)
query_svc_description = "";
strip_html_brackets(query_svc_description);
temp_request_item->is_valid = TRUE;
}
/* we found the hostgroup argument */
else if (!strcmp(key, "hostgroup") && value != NULL) {
query_type = DISPLAY_HOSTGROUPS;
if ((query_hostgroup_name = strdup(value)) == NULL)
query_hostgroup_name = "";
strip_html_brackets(query_hostgroup_name);
temp_request_item->is_valid = TRUE;
}
/* we found the servicegroup argument */
else if (!strcmp(key, "servicegroup") && value != NULL) {
query_type = DISPLAY_SERVICEGROUPS;
if ((query_servicegroup_name = strdup(value)) == NULL)
query_servicegroup_name = "";
strip_html_brackets(query_servicegroup_name);
temp_request_item->is_valid = TRUE;
}
/* we found the notification type argument */
else if (!strcmp(key, "type") && value != NULL) {
notification_options = atoi(value);
temp_request_item->is_valid = TRUE;
}
/* we found first time argument */
else if (!strcmp(key, "ts_start") && value != NULL) {
ts_start = (time_t)strtoul(value, NULL, 10);
temp_request_item->is_valid = TRUE;
}
/* we found last time argument */
else if (!strcmp(key, "ts_end") && value != NULL) {
ts_end = (time_t)strtoul(value, NULL, 10);
temp_request_item->is_valid = TRUE;
}
/* we found the start time */
else if (!strcmp(key, "start_time") && value != NULL) {
if ((start_time_string = (char *)strdup(value)) == NULL) {
start_time_string = "";
}
temp_request_item->is_valid = TRUE;
}
/* we found the end time */
else if (!strcmp(key, "end_time") && value != NULL) {
if ((end_time_string = (char *)strdup(value)) == NULL) {
end_time_string = "";
}
temp_request_item->is_valid = TRUE;
}
/* we found the standard timeperiod argument */
else if (!strcmp(key, "timeperiod") && value != NULL) {
if (!strcmp(value, "today"))
timeperiod_type = TIMEPERIOD_TODAY;
else if (!strcmp(value, "singelday"))
timeperiod_type = TIMEPERIOD_SINGLE_DAY;
else if (!strcmp(value, "last24hours"))
timeperiod_type = TIMEPERIOD_LAST24HOURS;
else if (!strcmp(value, "thisweek"))
timeperiod_type = TIMEPERIOD_THISWEEK;
else if (!strcmp(value, "lastweek"))
timeperiod_type = TIMEPERIOD_LASTWEEK;
else if (!strcmp(value, "thismonth"))
timeperiod_type = TIMEPERIOD_THISMONTH;
else if (!strcmp(value, "lastmonth"))
timeperiod_type = TIMEPERIOD_LASTMONTH;
else if (!strcmp(value, "thisyear"))
timeperiod_type = TIMEPERIOD_THISYEAR;
else if (!strcmp(value, "lastyear"))
timeperiod_type = TIMEPERIOD_LASTYEAR;
else if (!strcmp(value, "last7days"))
timeperiod_type = TIMEPERIOD_LAST7DAYS;
else if (!strcmp(value, "last31days"))
timeperiod_type = TIMEPERIOD_LAST31DAYS;
else if (!strcmp(value, "custom"))
timeperiod_type = TIMEPERIOD_CUSTOM;
else
continue;
convert_timeperiod_to_times(timeperiod_type, &ts_start, &ts_end);
temp_request_item->is_valid = TRUE;
}
/* we found the order argument */
else if (!strcmp(key, "order") && value != NULL) {
if (!strcmp(value, "new2old"))
reverse = FALSE;
else if (!strcmp(value, "old2new"))
reverse = TRUE;
temp_request_item->is_valid = TRUE;
}
/* we found the CSV output option */
else if (!strcmp(key, "csvoutput")) {
display_header = FALSE;
content_type = CSV_CONTENT;
temp_request_item->is_valid = TRUE;
my_free(temp_request_item->value);
}
/* we found the JSON output option */
else if (!strcmp(key, "jsonoutput")) {
display_header = FALSE;
content_type = JSON_CONTENT;
temp_request_item->is_valid = TRUE;
my_free(temp_request_item->value);
}
/* we found the embed option */
else if (!strcmp(key, "embedded")) {
embedded = TRUE;
temp_request_item->is_valid = TRUE;
my_free(temp_request_item->value);
}
/* we found the noheader option */
else if (!strcmp(key, "noheader")) {
display_header = FALSE;
temp_request_item->is_valid = TRUE;
my_free(temp_request_item->value);
}
/* we found the nodaemoncheck option */
else if (!strcmp(key, "nodaemoncheck")) {
daemon_check = FALSE;
temp_request_item->is_valid = TRUE;
my_free(temp_request_item->value);
}
/* start num results to skip on displaying statusdata */
else if (!strcmp(key, "start") && value != NULL) {
result_start = atoi(value);
if (result_start < 1)
result_start = 1;
temp_request_item->is_valid = TRUE;
}
/* amount of results to display */
else if (!strcmp(key, "limit") && value != NULL) {
get_result_limit = atoi(value);
temp_request_item->is_valid = TRUE;
my_free(temp_request_item->value);
}
}
/*
* 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 == DISPLAY_HOSTS && strlen(query_host_name) == 0) {
query_host_name = "all";
find_all = TRUE;
}
if (query_type == DISPLAY_CONTACTS && strlen(query_contact_name) == 0) {
query_contact_name = "all";
find_all = TRUE;
}
return;
}
void display_notifications(void) {
char *temp_buffer;
char *error_text = NULL;
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];
char displayed_host_name[MAX_INPUT_BUFFER];
char displayed_service_desc[MAX_INPUT_BUFFER];
int show_entry;
int total_notifications = 0;
int displayed_entries = 0;
int notification_detail_type = NOTIFICATION_SERVICE_CRITICAL;
int status = READLOG_OK;
int odd = 0;
int json_start = TRUE;
host *temp_host = NULL;
service *temp_service = NULL;
hostgroup *temp_hostgroup = NULL;
servicegroup *temp_servicegroup = NULL;
logentry *temp_entry = NULL;
logentry *entry_list = NULL;
logfilter *filter_list = NULL;
if (query_type == DISPLAY_HOSTGROUPS) {
temp_hostgroup = find_hostgroup(query_hostgroup_name);
if (temp_hostgroup == NULL) {
print_generic_error_message("There are no host groups with this name defined.", NULL, 0);
return;
}
/* make sure the user is authorized to view this hostgroup */
if (show_partial_hostgroups == FALSE && is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == FALSE) {
print_generic_error_message("It appears as though you do not have permission to view information for the host group you requested...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
return;
}
}
if (query_type == DISPLAY_SERVICEGROUPS) {
temp_servicegroup = find_servicegroup(query_servicegroup_name);
if (temp_servicegroup == NULL) {
print_generic_error_message("There are no service groups with this name defined.", NULL, 0);
return;
}
/* make sure the user is authorized to view this servicegroup */
if (show_partial_servicegroups == FALSE && is_authorized_for_servicegroup(temp_servicegroup, ¤t_authdata) == FALSE) {
print_generic_error_message("It appears as though you do not have permission to view information for the service group you requested...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
return;
}
}
add_log_filter(&filter_list, LOGENTRY_HOST_NOTIFICATION, LOGFILTER_INCLUDE);
add_log_filter(&filter_list, LOGENTRY_SERVICE_NOTIFICATION, LOGFILTER_INCLUDE);
/* scan the log file for notification data */
status = get_log_entries(&entry_list, &filter_list, &error_text, NULL, reverse, ts_start, ts_end);
free_log_filters(&filter_list);
/* dealing with errors */
if (status == READLOG_ERROR_WARNING) {
if (error_text != NULL) {
print_generic_error_message(error_text, NULL, 0);
my_free(error_text);
} else
print_generic_error_message("Unknown error!", NULL, 0);
}
if (status == READLOG_ERROR_MEMORY)
print_generic_error_message("Out of memory...", "showing all I could get!", 0);
if (status == READLOG_ERROR_FATAL) {
if (error_text != NULL) {
print_generic_error_message(error_text, NULL, 0);
my_free(error_text);
}
return;
/* now we start displaying the notification entries */
} else {
if (content_type == JSON_CONTENT) {
if (status != READLOG_OK)
printf(",\n");
printf("\"notifications\": [\n");
} else if (content_type == CSV_CONTENT) {
printf("%sHOST%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sSERVICE%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sTYPE%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sTIME%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sCONTACT%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sNOTIFICATION_COMMAND%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%sINFORMATION%s\n", csv_data_enclosure, csv_data_enclosure);
} else {
printf("<table border='0' class='notifications' align='center'>\n");
/* add export to csv, json, link */
printf("<tr><td colspan='7'>");
printf("<table width='100%%' cellspacing='0' cellpadding='0'><tr><td width='33%%'></td><td width='33%%' nowrap>");
printf("<div class='page_selector'>\n");
printf("<div id='page_navigation_copy'></div>");
page_limit_selector(result_start);
printf("</div>\n");
printf("</td><td width='33%%' align='right' style='padding-right:2px'>\n");
printf("<div class='csv_export_link'>");
print_export_link(CSV_CONTENT, NOTIFICATIONS_CGI, NULL);
print_export_link(JSON_CONTENT, NOTIFICATIONS_CGI, NULL);
print_export_link(HTML_CONTENT, NOTIFICATIONS_CGI, NULL);
printf("</div></td></tr></table>");
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");
}
/* check all entries */
for (temp_entry = entry_list; temp_entry != NULL; temp_entry = temp_entry->next) {
/* get the date/time */
get_time_string(&temp_entry->timestamp, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
strip(date_time);
/* get the contact name */
temp_buffer = (char *)strtok(temp_entry->entry_text, ":");
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 */
service_name[0] = '\x0';
if (temp_entry->type == LOGENTRY_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 (temp_entry->type == LOGENTRY_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 (strstr(alert_level, "DOWN")) {
strncpy(alert_level, "HOST DOWN", sizeof(alert_level));
strcpy(alert_level_class, "HOSTDOWN");
notification_detail_type = NOTIFICATION_HOST_DOWN;
} else if (strstr(alert_level, "UNREACHABLE")) {
strncpy(alert_level, "HOST UNREACHABLE", sizeof(alert_level));
strcpy(alert_level_class, "HOSTUNREACHABLE");
notification_detail_type = NOTIFICATION_HOST_UNREACHABLE;
} else if (strstr(alert_level, "RECOVERY") || strstr(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 == DISPLAY_CONTACTS) {
if (find_all == TRUE)
show_entry = TRUE;
else if (!strcmp(query_contact_name, contact_name))
show_entry = TRUE;
}
/* search host */
else if (query_type == DISPLAY_HOSTS) {
if (find_all == TRUE)
show_entry = TRUE;
else if (!strcmp(query_host_name, host_name))
show_entry = TRUE;
}
/* searching service */
else if (query_type == DISPLAY_SERVICES) {
if (!strcmp(query_host_name, host_name) && !strcmp(query_svc_description, service_name))
show_entry = TRUE;
}
/* Set TRUE here, get's checked later on */
else if (query_type == DISPLAY_HOSTGROUPS || query_type == DISPLAY_SERVICEGROUPS) {
show_entry = TRUE;
}
if (show_entry == TRUE) {
if (notification_options == NOTIFICATION_ALL)
show_entry = TRUE;
else if (notification_options == NOTIFICATION_HOST_ALL && temp_entry->type == LOGENTRY_HOST_NOTIFICATION)
show_entry = TRUE;
else if (notification_options == NOTIFICATION_SERVICE_ALL && temp_entry->type == LOGENTRY_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 */
temp_host = find_host(host_name);
if (temp_entry->type == LOGENTRY_SERVICE_NOTIFICATION)
temp_service = find_service(host_name, service_name);
if (temp_host != NULL) {
snprintf(displayed_host_name, sizeof(displayed_host_name), "%s", (temp_host->display_name != NULL && content_type == HTML_CONTENT) ? temp_host->display_name : temp_host->name);
displayed_host_name[sizeof(displayed_host_name) - 1] = '\x0';
if (temp_entry->type == LOGENTRY_HOST_NOTIFICATION) {
if (is_authorized_for_host(temp_host, ¤t_authdata) == FALSE)
show_entry = FALSE;
else if (query_type == DISPLAY_HOSTGROUPS && is_host_member_of_hostgroup(temp_hostgroup, temp_host) == FALSE)
show_entry = FALSE;
else if (query_type == DISPLAY_SERVICEGROUPS && is_host_member_of_servicegroup(temp_servicegroup, temp_host) == FALSE)
show_entry = FALSE;
} else {
if (temp_service != NULL) {
snprintf(displayed_service_desc, sizeof(displayed_service_desc), "%s", (temp_service->display_name != NULL && content_type == HTML_CONTENT) ? temp_service->display_name : temp_service->description);
displayed_service_desc[sizeof(displayed_service_desc) - 1] = '\x0';
if (is_authorized_for_service(temp_service, ¤t_authdata) == FALSE)
show_entry = FALSE;
else if (query_type == DISPLAY_HOSTGROUPS && is_host_member_of_hostgroup(temp_hostgroup, temp_host) == FALSE)
show_entry = FALSE;
else if (query_type == DISPLAY_SERVICEGROUPS && is_service_member_of_servicegroup(temp_servicegroup, temp_service) == FALSE)
show_entry = FALSE;
} else {
if (is_authorized_for_all_services(¤t_authdata) == FALSE)
show_entry = FALSE;
snprintf(displayed_service_desc, sizeof(displayed_service_desc), "%s", service_name);
displayed_service_desc[sizeof(displayed_service_desc) - 1] = '\x0';
}
}
} else {
if (temp_entry->type == LOGENTRY_HOST_NOTIFICATION) {
if (is_authorized_for_all_hosts(¤t_authdata) == FALSE)
show_entry = FALSE;
} else {
if (is_authorized_for_all_services(¤t_authdata) == FALSE)
show_entry = FALSE;
snprintf(displayed_service_desc, sizeof(displayed_service_desc), "%s", service_name);
displayed_service_desc[sizeof(displayed_service_desc) - 1] = '\x0';
}
snprintf(displayed_host_name, sizeof(displayed_host_name), "%s", host_name);
displayed_host_name[sizeof(displayed_host_name) - 1] = '\x0';
}
if (show_entry == TRUE) {
if (result_limit != 0 && (((total_notifications + 1) < result_start) || (total_notifications >= ((result_start + result_limit) - 1)))) {
total_notifications++;
continue;
}
displayed_entries++;
total_notifications++;
if (odd)
odd = 0;
else
odd = 1;
if (content_type == JSON_CONTENT) {
if (json_start == FALSE)
printf(",\n");
printf("{\"host_name\": \"%s\", ", json_encode(temp_host->name));
printf("\"host_display_name\": \"%s\", ", (temp_host->display_name != NULL) ? json_encode(temp_host->display_name) : json_encode(temp_host->name));
if (temp_entry->type == LOGENTRY_SERVICE_NOTIFICATION) {
printf("\"service_description\": \"%s\", ", json_encode(temp_service->description));
printf("\"service_display_name\": \"%s\", ", (temp_service->display_name != NULL) ? json_encode(temp_service->display_name) : json_encode(temp_service->description));
} else {
printf("\"service_description\": null, ");
printf("\"service_display_name\": null, ");
}
printf("\"type\": \"%s\", ", alert_level);
printf("\"time\": \"%s\", ", date_time);
printf("\"contact\": \"%s\", ", json_encode(contact_name));
printf("\"notification_command\": \"%s\", ", json_encode(method_name));
printf("\"information\": \"%s\"}", json_encode(escape_newlines(temp_buffer)));
} else if (content_type == CSV_CONTENT) {
printf("%s%s%s%s", csv_data_enclosure, displayed_host_name, csv_data_enclosure, csv_delimiter);
if (temp_entry->type == LOGENTRY_SERVICE_NOTIFICATION)
printf("%s%s%s%s", csv_data_enclosure, displayed_service_desc, csv_data_enclosure, csv_delimiter);
else
printf("%sN/A%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
printf("%s%s%s%s", csv_data_enclosure, alert_level, csv_data_enclosure, csv_delimiter);
printf("%s%s%s%s", csv_data_enclosure, date_time, csv_data_enclosure, csv_delimiter);
printf("%s%s%s%s", csv_data_enclosure, contact_name, csv_data_enclosure, csv_delimiter);
printf("%s%s%s%s", csv_data_enclosure, method_name, csv_data_enclosure, csv_delimiter);
printf("%s%s%s\n", csv_data_enclosure, escape_newlines(temp_buffer), csv_data_enclosure);
} else {
printf("<tr class='notifications%s'>\n", (odd) ? "Even" : "Odd");
if (temp_host != NULL)
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), displayed_host_name);
else
printf("<td class='notifications%s'>%s</td>\n", (odd) ? "Even" : "Odd", displayed_host_name);
if (temp_entry->type == LOGENTRY_SERVICE_NOTIFICATION) {
if (temp_service != NULL) {
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), displayed_service_desc);
} else
printf("<td class='notifications%s'>%s</td>\n", (odd) ? "Even" : "Odd", displayed_service_desc);
} 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");
}
if (json_start == TRUE)
json_start = FALSE;
}
}
}
free_log_entries(&entry_list);
if (content_type != CSV_CONTENT && content_type != JSON_CONTENT) {
printf("</table>\n");
if (total_notifications == 0) {
printf("<div class='errorMessage' style='text-align:center;'>No notifications have been recorded");
if (find_all == FALSE) {
if (query_type == DISPLAY_SERVICES)
printf(" for this service");
else if (query_type == DISPLAY_CONTACTS)
printf(" for this contact");
else
printf(" for this host");
}
printf(" in log files for selected date.</div>");
}
page_num_selector(result_start, total_notifications, displayed_entries);
} else if (content_type == JSON_CONTENT) {
printf("\n]\n");
}
return;
}
|