/************************************************************************ * * NOTIFICATIONS.C - Nagios Notifications CGI * * Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org) * Last Modified: 01-08-2008 * * 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]; extern int log_rotation_method; #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) { int result = OK; 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(); /* read the CGI configuration file */ result = read_cgi_config_file(get_cgi_config_location()); if(result == ERROR) { document_header(FALSE); cgi_config_file_error(get_cgi_config_location()); document_footer(); return ERROR; } /* read the main configuration file */ result = read_main_config_file(main_config_file); if(result == ERROR) { document_header(FALSE); main_config_file_error(main_config_file); document_footer(); 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(FALSE); object_data_error(); document_footer(); return ERROR; } document_header(TRUE); /* get authentication information */ get_authentication_information(¤t_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("
\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, ¤t_authdata);
if(query_type == FIND_HOST || query_type == FIND_SERVICE) {
printf("
| \n");
/* middle column of top row */
printf("\n");
printf(" \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(" \n");
printf("\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(" | \n");
/* right hand column of top row */
printf("\n"); printf("\n"); printf(" | \n"); /* end of top table */ printf("
\n"); printf("
Host | \n"); printf("Service | \n"); printf("Type | \n"); printf("Time | \n"); printf("Contact | \n"); printf("Notification Command | \n"); printf("Information | \n"); printf("|
---|---|---|---|---|---|---|---|
%s | \n", (odd) ? "Even" : "Odd", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(host_name), host_name); if(notification_type == SERVICE_NOTIFICATION) { printf("%s | \n", url_encode(service_name), service_name); } else printf("N/A | \n", (odd) ? "Even" : "Odd"); printf("%s | \n", alert_level_class, alert_level); printf("%s | \n", (odd) ? "Even" : "Odd", date_time); printf("%s | \n", (odd) ? "Even" : "Odd", CONFIG_CGI, url_encode(contact_name), contact_name); printf("%s | \n", (odd) ? "Even" : "Odd", CONFIG_CGI, url_encode(method_name), method_name); printf("%s | \n", (odd) ? "Even" : "Odd", html_encode(temp_buffer, FALSE)); printf("