/************************************************************************** * * EXTINFO.C - Nagios Extended Information CGI * * * 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/objects.h" #include "../include/macros.h" #include "../include/comments.h" #include "../include/downtime.h" #include "../include/statusdata.h" #include "../include/cgiutils.h" #include "../include/getcgi.h" #include "../include/cgiauth.h" static nagios_macros *mac; extern char nagios_process_info[MAX_INPUT_BUFFER]; extern int nagios_process_state; extern int refresh_rate; extern int enable_page_tour; extern int buffer_stats[1][3]; extern int program_stats[MAX_CHECK_STATS_TYPES][3]; extern char main_config_file[MAX_FILENAME_LENGTH]; extern char url_html_path[MAX_FILENAME_LENGTH]; extern char url_stylesheets_path[MAX_FILENAME_LENGTH]; extern char url_docs_path[MAX_FILENAME_LENGTH]; extern char url_images_path[MAX_FILENAME_LENGTH]; extern char url_logo_images_path[MAX_FILENAME_LENGTH]; extern char url_js_path[MAX_FILENAME_LENGTH]; extern int enable_splunk_integration; extern char *notes_url_target; extern char *action_url_target; extern hoststatus *hoststatus_list; extern servicestatus *servicestatus_list; #define MAX_MESSAGE_BUFFER 4096 #define HEALTH_WARNING_PERCENTAGE 85 #define HEALTH_CRITICAL_PERCENTAGE 75 /* SORTDATA structure */ typedef struct sortdata_struct { int is_service; servicestatus *svcstatus; hoststatus *hststatus; struct sortdata_struct *next; } sortdata; void document_header(int); void document_footer(void); int process_cgivars(void); void show_process_info(void); void show_host_info(void); void show_service_info(void); void show_all_comments(void); void show_performance_data(void); void show_hostgroup_info(void); void show_servicegroup_info(void); void show_all_downtime(void); void show_scheduling_queue(void); void display_comments(int); int sort_data(int, int); int compare_sortdata_entries(int, int, sortdata *, sortdata *); void free_sortdata_list(void); authdata current_authdata; sortdata *sortdata_list = NULL; char *host_name = ""; char *hostgroup_name = ""; char *servicegroup_name = ""; char *service_desc = ""; int display_type = DISPLAY_PROCESS_INFO; int sort_type = SORT_ASCENDING; int sort_option = SORT_NEXTCHECKTIME; int embedded = FALSE; int display_header = TRUE; int main(void) { int found = FALSE; char temp_buffer[MAX_INPUT_BUFFER] = ""; char *processed_string = NULL; host *temp_host = NULL; hostsmember *temp_parenthost = NULL; hostgroup *temp_hostgroup = NULL; service *temp_service = NULL; servicegroup *temp_servicegroup = NULL; mac = get_global_macros(); /* 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, READ_ALL_STATUS_DATA); /* initialize macros */ init_macros(); /* get authentication information */ get_authentication_information(¤t_authdata); document_header(TRUE); if(display_header == TRUE) { /* begin top table */ printf("\n"); printf("\n"); /* left column of the first row */ printf("\n"); /* middle column of top row */ printf("\n"); /* right column of top row */ printf("\n"); /* end of top table */ printf("\n"); printf("
\n"); if(display_type == DISPLAY_HOST_INFO) snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Host Information"); else if(display_type == DISPLAY_SERVICE_INFO) snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Service Information"); else if(display_type == DISPLAY_COMMENTS) snprintf(temp_buffer, sizeof(temp_buffer) - 1, "All Host and Service Comments"); else if(display_type == DISPLAY_PERFORMANCE) snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Performance Information"); else if(display_type == DISPLAY_HOSTGROUP_INFO) snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Hostgroup Information"); else if(display_type == DISPLAY_SERVICEGROUP_INFO) snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Servicegroup Information"); else if(display_type == DISPLAY_DOWNTIME) snprintf(temp_buffer, sizeof(temp_buffer) - 1, "All Host and Service Scheduled Downtime"); else if(display_type == DISPLAY_SCHEDULING_QUEUE) snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Check Scheduling Queue"); else snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Nagios Process Information"); temp_buffer[sizeof(temp_buffer) - 1] = '\x0'; display_info_table(temp_buffer, TRUE, ¤t_authdata); /* find the host */ if(display_type == DISPLAY_HOST_INFO || display_type == DISPLAY_SERVICE_INFO) { temp_host = find_host(host_name); grab_host_macros_r(mac, temp_host); if(display_type == DISPLAY_SERVICE_INFO) { temp_service = find_service(host_name, service_desc); grab_service_macros_r(mac, temp_service); } /* write some Javascript helper functions */ if(temp_host != NULL) { printf("\n"); } } /* find the hostgroup */ else if(display_type == DISPLAY_HOSTGROUP_INFO) { temp_hostgroup = find_hostgroup(hostgroup_name); grab_hostgroup_macros_r(mac, temp_hostgroup); } /* find the servicegroup */ else if(display_type == DISPLAY_SERVICEGROUP_INFO) { temp_servicegroup = find_servicegroup(servicegroup_name); grab_servicegroup_macros_r(mac, temp_servicegroup); } if((display_type == DISPLAY_HOST_INFO && temp_host != NULL) || (display_type == DISPLAY_SERVICE_INFO && temp_host != NULL && temp_service != NULL) || (display_type == DISPLAY_HOSTGROUP_INFO && temp_hostgroup != NULL) || (display_type == DISPLAY_SERVICEGROUP_INFO && temp_servicegroup != NULL)) { printf("\n"); printf("\n"); printf("\n"); } printf("\n"); if((display_type == DISPLAY_HOST_INFO && temp_host != NULL) || (display_type == DISPLAY_SERVICE_INFO && temp_host != NULL && temp_service != NULL) || (display_type == DISPLAY_HOSTGROUP_INFO && temp_hostgroup != NULL) || (display_type == DISPLAY_SERVICEGROUP_INFO && temp_servicegroup != NULL)) { if(display_type == DISPLAY_HOST_INFO) { printf("
Host
\n"); printf("
%s
\n", temp_host->alias); printf("
(%s)

\n", temp_host->name); if(temp_host->parent_hosts != NULL) { /* print all parent hosts */ printf("
Parents:
\n"); for(temp_parenthost = temp_host->parent_hosts; temp_parenthost != NULL; temp_parenthost = temp_parenthost->next) printf("\n", STATUS_CGI, url_encode(temp_parenthost->host_name), temp_parenthost->host_name); printf("
"); } printf("
Member of
"); for(temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) { if(is_host_member_of_hostgroup(temp_hostgroup, temp_host) == TRUE) { if(found == TRUE) printf(", "); printf("%s", STATUS_CGI, url_encode(temp_hostgroup->group_name), temp_hostgroup->group_name); found = TRUE; } } if(found == FALSE) printf("No hostgroups"); printf("

\n"); printf("
%s
\n", temp_host->address); } if(display_type == DISPLAY_SERVICE_INFO) { printf("
Service
%s
On Host
\n", service_desc); printf("
%s
\n", temp_host->alias); printf("
(%s)

\n", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_host->name), temp_host->name); printf("
Member of
"); for(temp_servicegroup = servicegroup_list; temp_servicegroup != NULL; temp_servicegroup = temp_servicegroup->next) { if(is_service_member_of_servicegroup(temp_servicegroup, temp_service) == TRUE) { if(found == TRUE) printf(", "); printf("%s", STATUS_CGI, url_encode(temp_servicegroup->group_name), temp_servicegroup->group_name); found = TRUE; } } if(found == FALSE) printf("No servicegroups."); printf("

\n"); printf("
%s
\n", temp_host->address); } if(display_type == DISPLAY_HOSTGROUP_INFO) { printf("
Hostgroup
\n"); printf("
%s
\n", temp_hostgroup->alias); printf("
(%s)
\n", temp_hostgroup->group_name); if(temp_hostgroup->notes != NULL) { process_macros_r(mac, temp_hostgroup->notes, &processed_string, 0); printf("

%s

", processed_string); free(processed_string); } } if(display_type == DISPLAY_SERVICEGROUP_INFO) { printf("
Servicegroup
\n"); printf("
%s
\n", temp_servicegroup->alias); printf("
(%s)
\n", temp_servicegroup->group_name); if(temp_servicegroup->notes != NULL) { process_macros_r(mac, temp_servicegroup->notes, &processed_string, 0); printf("

%s

", processed_string); free(processed_string); } } if(display_type == DISPLAY_SERVICE_INFO) { if(temp_service->icon_image != NULL) { printf("%s
", (temp_service->icon_image_alt == NULL) ? "" : temp_service->icon_image_alt, (temp_service->icon_image_alt == NULL) ? "" : temp_service->icon_image_alt); } if(temp_service->icon_image_alt != NULL) printf("( %s )\n", temp_service->icon_image_alt); if(temp_service->notes != NULL) { process_macros_r(mac, temp_service->notes, &processed_string, 0); printf("

%s

\n", processed_string); free(processed_string); } } if(display_type == DISPLAY_HOST_INFO) { if(temp_host->icon_image != NULL) { printf("%s
", (temp_host->icon_image_alt == NULL) ? "" : temp_host->icon_image_alt, (temp_host->icon_image_alt == NULL) ? "" : temp_host->icon_image_alt); } if(temp_host->icon_image_alt != NULL) printf("( %s )\n", temp_host->icon_image_alt); if(temp_host->notes != NULL) { process_macros_r(mac, temp_host->notes, &processed_string, 0); printf("

%s

\n", processed_string); free(processed_string); } } } printf("
\n"); if(display_type == DISPLAY_HOST_INFO && temp_host != NULL) { printf("\n"); if(temp_host->action_url != NULL && strcmp(temp_host->action_url, "")) { printf("\n"); } if(temp_host->notes_url != NULL && strcmp(temp_host->notes_url, "")) { printf("\n"); } printf("
\n"); printf("Perform Additional Actions On This Host\n", (action_url_target == NULL) ? "_blank" : action_url_target, url_images_path, ACTION_ICON); printf("
Extra Actions

\n"); printf("
\n"); printf("View Additional Notes For This Host\n", (notes_url_target == NULL) ? "_blank" : notes_url_target, url_images_path, NOTES_ICON); printf("
Extra Notes

\n"); printf("
\n"); } else if(display_type == DISPLAY_SERVICE_INFO && temp_service != NULL) { printf("
\n"); if(temp_service->action_url != NULL && strcmp(temp_service->action_url, "")) { printf("Perform Additional Actions On This Service\n", (action_url_target == NULL) ? "_blank" : action_url_target, url_images_path, ACTION_ICON); printf("
Extra Actions

\n"); } if(temp_service->notes_url != NULL && strcmp(temp_service->notes_url, "")) { printf("View Additional Notes For This Service\n", (notes_url_target == NULL) ? "_blank" : notes_url_target, url_images_path, NOTES_ICON); printf("
Extra Notes

\n"); } printf("
\n"); } if(display_type == DISPLAY_HOSTGROUP_INFO && temp_hostgroup != NULL) { printf("\n"); if(temp_hostgroup->action_url != NULL && strcmp(temp_hostgroup->action_url, "")) { printf("\n"); } if(temp_hostgroup->notes_url != NULL && strcmp(temp_hostgroup->notes_url, "")) { printf("\n"); } printf("
\n"); printf("Perform Additional Actions On This Hostgroup\n", (action_url_target == NULL) ? "_blank" : action_url_target, url_images_path, ACTION_ICON); printf("
Extra Actions

\n"); printf("
\n"); printf("View Additional Notes For This Hostgroup\n", (notes_url_target == NULL) ? "_blank" : notes_url_target, url_images_path, NOTES_ICON); printf("
Extra Notes

\n"); printf("
\n"); } else if(display_type == DISPLAY_SERVICEGROUP_INFO && temp_servicegroup != NULL) { printf("\n"); if(temp_servicegroup->action_url != NULL && strcmp(temp_servicegroup->action_url, "")) { printf("Perform Additional Actions On This Servicegroup\n", (action_url_target == NULL) ? "_blank" : action_url_target, url_images_path, ACTION_ICON); printf("
Extra Actions

\n"); } if(temp_servicegroup->notes_url != NULL && strcmp(temp_servicegroup->notes_url, "")) { printf("View Additional Notes For This Servicegroup\n", (notes_url_target == NULL) ? "_blank" : notes_url_target, url_images_path, NOTES_ICON); printf("
Extra Notes

\n"); } printf("
\n"); } /* display context-sensitive help */ if(display_type == DISPLAY_HOST_INFO) display_context_help(CONTEXTHELP_EXT_HOST); else if(display_type == DISPLAY_SERVICE_INFO) display_context_help(CONTEXTHELP_EXT_SERVICE); else if(display_type == DISPLAY_HOSTGROUP_INFO) display_context_help(CONTEXTHELP_EXT_HOSTGROUP); else if(display_type == DISPLAY_SERVICEGROUP_INFO) display_context_help(CONTEXTHELP_EXT_SERVICEGROUP); else if(display_type == DISPLAY_PROCESS_INFO) display_context_help(CONTEXTHELP_EXT_PROCESS); else if(display_type == DISPLAY_PERFORMANCE) display_context_help(CONTEXTHELP_EXT_PERFORMANCE); else if(display_type == DISPLAY_COMMENTS) display_context_help(CONTEXTHELP_EXT_COMMENTS); else if(display_type == DISPLAY_DOWNTIME) display_context_help(CONTEXTHELP_EXT_DOWNTIME); else if(display_type == DISPLAY_SCHEDULING_QUEUE) display_context_help(CONTEXTHELP_EXT_QUEUE); printf("
\n"); } printf("
\n"); if(display_type == DISPLAY_HOST_INFO) show_host_info(); else if(display_type == DISPLAY_SERVICE_INFO) show_service_info(); else if(display_type == DISPLAY_COMMENTS) show_all_comments(); else if(display_type == DISPLAY_PERFORMANCE) show_performance_data(); else if(display_type == DISPLAY_HOSTGROUP_INFO) show_hostgroup_info(); else if(display_type == DISPLAY_SERVICEGROUP_INFO) show_servicegroup_info(); else if(display_type == DISPLAY_DOWNTIME) show_all_downtime(); else if(display_type == DISPLAY_SCHEDULING_QUEUE) show_scheduling_queue(); else show_process_info(); document_footer(); /* free all allocated memory */ free_memory(); free_comment_data(); free_downtime_data(); return OK; } void document_header(int use_stylesheet) { char date_time[MAX_DATETIME_LENGTH]; char *vidurl = NULL; time_t current_time; time_t expire_time; printf("Cache-Control: no-store\r\n"); printf("Pragma: no-cache\r\n"); printf("Refresh: %d\r\n", refresh_rate); time(¤t_time); get_time_string(¤t_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; charset=utf-8\r\n\r\n"); if(embedded == TRUE) return; printf("\n"); printf("\n"); printf("\n", url_images_path); printf("\n"); printf("Extended Information\n"); printf("\n"); if(use_stylesheet == TRUE) { printf("", url_stylesheets_path, COMMON_CSS); printf("", url_stylesheets_path, EXTINFO_CSS); printf("\n", url_stylesheets_path, NAGFUNCS_CSS); } if (display_type == DISPLAY_HOST_INFO) vidurl = "https://www.youtube.com/embed/n3QEAf-MxY4"; else if(display_type == DISPLAY_SERVICE_INFO) vidurl = "https://www.youtube.com/embed/f_knwQOS6FI"; if (enable_page_tour == TRUE && vidurl) { printf("\n", url_js_path, JQUERY_JS); printf("\n", url_js_path, NAGFUNCS_JS); printf("\n"); } printf("\n"); printf("\n"); /* include user SSI header */ include_ssi_files(EXTINFO_CGI, SSI_HEADER); return; } void document_footer(void) { if(embedded == TRUE) return; /* include user SSI footer */ include_ssi_files(EXTINFO_CGI, SSI_FOOTER); printf("\n"); printf("\n"); return; } int process_cgivars(void) { char **variables; int error = FALSE; int temp_type; int x; variables = getcgivars(); for(x = 0; variables[x]; 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 display type */ else if(!strcmp(variables[x], "type")) { x++; if(variables[x] == NULL) { error = TRUE; break; } temp_type = atoi(variables[x]); if(temp_type == DISPLAY_HOST_INFO) display_type = DISPLAY_HOST_INFO; else if(temp_type == DISPLAY_SERVICE_INFO) display_type = DISPLAY_SERVICE_INFO; else if(temp_type == DISPLAY_COMMENTS) display_type = DISPLAY_COMMENTS; else if(temp_type == DISPLAY_PERFORMANCE) display_type = DISPLAY_PERFORMANCE; else if(temp_type == DISPLAY_HOSTGROUP_INFO) display_type = DISPLAY_HOSTGROUP_INFO; else if(temp_type == DISPLAY_SERVICEGROUP_INFO) display_type = DISPLAY_SERVICEGROUP_INFO; else if(temp_type == DISPLAY_DOWNTIME) display_type = DISPLAY_DOWNTIME; else if(temp_type == DISPLAY_SCHEDULING_QUEUE) display_type = DISPLAY_SCHEDULING_QUEUE; else display_type = DISPLAY_PROCESS_INFO; } /* we found the host name */ else if(!strcmp(variables[x], "host")) { x++; if(variables[x] == NULL) { error = TRUE; break; } host_name = strdup(variables[x]); if(host_name == NULL) host_name = ""; strip_html_brackets(host_name); } /* we found the hostgroup name */ else if(!strcmp(variables[x], "hostgroup")) { x++; if(variables[x] == NULL) { error = TRUE; break; } hostgroup_name = strdup(variables[x]); if(hostgroup_name == NULL) hostgroup_name = ""; strip_html_brackets(hostgroup_name); } /* we found the service name */ else if(!strcmp(variables[x], "service")) { x++; if(variables[x] == NULL) { error = TRUE; break; } service_desc = strdup(variables[x]); if(service_desc == NULL) service_desc = ""; strip_html_brackets(service_desc); } /* we found the servicegroup name */ else if(!strcmp(variables[x], "servicegroup")) { x++; if(variables[x] == NULL) { error = TRUE; break; } servicegroup_name = strdup(variables[x]); if(servicegroup_name == NULL) servicegroup_name = ""; strip_html_brackets(servicegroup_name); } /* we found the sort type argument */ else if(!strcmp(variables[x], "sorttype")) { x++; if(variables[x] == NULL) { error = TRUE; break; } sort_type = atoi(variables[x]); } /* we found the sort option argument */ else if(!strcmp(variables[x], "sortoption")) { x++; if(variables[x] == NULL) { error = TRUE; break; } sort_option = atoi(variables[x]); } /* 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; } /* free memory allocated to the CGI variables */ free_cgivars(variables); return error; } void show_process_info(void) { char date_time[MAX_DATETIME_LENGTH]; time_t current_time; unsigned long run_time; char run_time_string[24]; int days = 0; int hours = 0; int minutes = 0; int seconds = 0; /* make sure the user has rights to view system information */ if(is_authorized_for_system_information(¤t_authdata) == FALSE) { printf("

It appears as though you do not have permission to view process information...

\n"); printf("

If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI
"); printf("and check the authorization options in your CGI configuration file.

\n"); return; } printf("
\n"); printf("
\n"); printf("\n"); printf("
\n"); printf("
Process Information
\n"); printf("\n"); printf("\n"); printf("
\n"); printf("\n"); /* program version */ printf("\n", PROGRAM_VERSION); /* program start time */ get_time_string(&program_start, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("\n", date_time); /* total running time */ time(¤t_time); run_time = (unsigned long)(current_time - program_start); get_time_breakdown(run_time, &days, &hours, &minutes, &seconds); sprintf(run_time_string, "%dd %dh %dm %ds", days, hours, minutes, seconds); printf("\n", run_time_string); /* last log file rotation */ get_time_string(&last_log_rotation, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("\n", (last_log_rotation == (time_t)0) ? "N/A" : date_time); /* PID */ printf("\n", nagios_pid); /* notifications enabled */ printf("\n", (enable_notifications == TRUE) ? "ENABLED" : "DISABLED", (enable_notifications == TRUE) ? "YES" : "NO"); /* service check execution enabled */ printf("\n", (execute_service_checks == TRUE) ? "ENABLED" : "DISABLED", (execute_service_checks == TRUE) ? "YES" : "NO"); /* passive service check acceptance */ printf("\n", (accept_passive_service_checks == TRUE) ? "ENABLED" : "DISABLED", (accept_passive_service_checks == TRUE) ? "YES" : "NO"); /* host check execution enabled */ printf("\n", (execute_host_checks == TRUE) ? "ENABLED" : "DISABLED", (execute_host_checks == TRUE) ? "YES" : "NO"); /* passive host check acceptance */ printf("\n", (accept_passive_host_checks == TRUE) ? "ENABLED" : "DISABLED", (accept_passive_host_checks == TRUE) ? "YES" : "NO"); /* event handlers enabled */ printf("\n", (enable_event_handlers == TRUE) ? "Yes" : "No"); /* obsessing over services */ printf("\n", (obsess_over_services == TRUE) ? "Yes" : "No"); /* obsessing over hosts */ printf("\n", (obsess_over_hosts == TRUE) ? "Yes" : "No"); /* flap detection enabled */ printf("\n", (enable_flap_detection == TRUE) ? "Yes" : "No"); /* process performance data */ printf("\n", (process_performance_data == TRUE) ? "Yes" : "No"); printf("
Program Version:%s
Program Start Time:%s
Total Running Time:%s
Last Log File Rotation:%s
Nagios PID%d
Notifications Enabled?
  %s  
Service Checks Being Executed?
  %s  
Passive Service Checks Being Accepted?
  %s  
Host Checks Being Executed?
  %s  
Passive Host Checks Being Accepted?
  %s  
Event Handlers Enabled?%s
Obsessing Over Services?%s
Obsessing Over Hosts?%s
Flap Detection Enabled?%s
Performance Data Being Processed?%s
\n"); printf("
\n"); printf("
\n"); printf("
Process Commands
\n"); printf("\n"); printf("\n"); printf("
\n"); if(nagios_process_state == STATE_OK) { printf("\n"); #ifndef DUMMY_INSTALL printf("\n", url_images_path, STOP_ICON, COMMAND_CGI, CMD_SHUTDOWN_PROCESS); printf("\n", url_images_path, RESTART_ICON, COMMAND_CGI, CMD_RESTART_PROCESS); #endif if(enable_notifications == TRUE) printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_NOTIFICATIONS); else printf("\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_NOTIFICATIONS); if(execute_service_checks == TRUE) printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_EXECUTING_SVC_CHECKS); else printf("\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_EXECUTING_SVC_CHECKS); if(accept_passive_service_checks == TRUE) printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS); else printf("\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS); if(execute_host_checks == TRUE) printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_EXECUTING_HOST_CHECKS); else printf("\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_EXECUTING_HOST_CHECKS); if(accept_passive_host_checks == TRUE) printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS); else printf("\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS); if(enable_event_handlers == TRUE) printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_EVENT_HANDLERS); else printf("\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_EVENT_HANDLERS); if(obsess_over_services == TRUE) printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_OBSESSING_OVER_SVC_CHECKS); else printf("\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_OBSESSING_OVER_SVC_CHECKS); if(obsess_over_hosts == TRUE) printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_OBSESSING_OVER_HOST_CHECKS); else printf("\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_OBSESSING_OVER_HOST_CHECKS); if(enable_flap_detection == TRUE) printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_FLAP_DETECTION); else printf("\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_FLAP_DETECTION); if(process_performance_data == TRUE) printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_PERFORMANCE_DATA); else printf("\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_PERFORMANCE_DATA); printf("
Shutdown the Nagios ProcessShutdown the Nagios process
Restart the Nagios ProcessRestart the Nagios process
Disable NotificationsDisable notifications
Enable NotificationsEnable notifications
Stop Executing Service ChecksStop executing service checks
Start Executing Service ChecksStart executing service checks
Stop Accepting Passive Service ChecksStop accepting passive service checks
Start Accepting Passive Service ChecksStart accepting passive service checks
Stop Executing Host ChecksStop executing host checks
Start Executing Host ChecksStart executing host checks
Stop Accepting Passive Host ChecksStop accepting passive host checks
Start Accepting Passive Host ChecksStart accepting passive host checks
Disable Event HandlersDisable event handlers
Enable Event HandlersEnable event handlers
Stop Obsessing Over ServicesStop obsessing over services
Start Obsessing Over ServicesStart obsessing over services
Stop Obsessing Over HostsStop obsessing over hosts
Start Obsessing Over HostsStart obsessing over hosts
Disable Flap DetectionDisable flap detection
Enable Flap DetectionEnable flap detection
Disable Performance DataDisable performance data
Enable Performance DataEnable performance data
\n"); } else { printf("
It appears as though Nagios is not running, so commands are temporarily unavailable...\n"); printf("
\n"); } printf("
\n"); printf("
\n"); printf("
\n"); } void show_host_info(void) { hoststatus *temp_hoststatus; host *temp_host; char date_time[MAX_DATETIME_LENGTH]; char state_duration[48]; char status_age[48]; char state_string[MAX_INPUT_BUFFER]; const char *bg_class = ""; char *buf = NULL; int days; int hours; int minutes; int seconds; time_t current_time; time_t t; int duration_error = FALSE; /* get host info */ temp_host = find_host(host_name); /* make sure the user has rights to view host information */ if(is_authorized_for_host(temp_host, ¤t_authdata) == FALSE) { printf("

It appears as though you do not have permission to view information for this host...

\n"); printf("

If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI
"); printf("and check the authorization options in your CGI configuration file.

\n"); return; } /* get host status info */ temp_hoststatus = find_hoststatus(host_name); /* make sure host information exists */ if(temp_host == NULL) { printf("

Error: Host Not Found!

>"); return; } if(temp_hoststatus == NULL) { printf("

Error: Host Status Information Not Found!
\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("
\n"); printf("
Host State Information
\n"); if(temp_hoststatus->has_been_checked == FALSE) printf("

This host has not yet been checked, so status information is not available.

\n"); else { printf("\n"); printf("\n"); printf("\n"); printf("
\n"); printf("\n"); printf("\n"); printf("
\n"); printf("\n"); current_time = time(NULL); t = 0; duration_error = FALSE; if(temp_hoststatus->last_state_change == (time_t)0) { if(program_start > current_time) duration_error = TRUE; else t = current_time - program_start; } else { if(temp_hoststatus->last_state_change > current_time) duration_error = TRUE; else t = current_time - temp_hoststatus->last_state_change; } get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds); if(duration_error == TRUE) snprintf(state_duration, sizeof(state_duration) - 1, "???"); else snprintf(state_duration, sizeof(state_duration) - 1, "%2dd %2dh %2dm %2ds%s", days, hours, minutes, seconds, (temp_hoststatus->last_state_change == (time_t)0) ? "+" : ""); state_duration[sizeof(state_duration) - 1] = '\x0'; if(temp_hoststatus->status == SD_HOST_UP) { strcpy(state_string, "UP"); bg_class = "hostUP"; } else if(temp_hoststatus->status == SD_HOST_DOWN) { strcpy(state_string, "DOWN"); bg_class = "hostDOWN"; } else if(temp_hoststatus->status == SD_HOST_UNREACHABLE) { strcpy(state_string, "UNREACHABLE"); bg_class = "hostUNREACHABLE"; } printf("\n", bg_class, state_string, state_duration, (temp_hoststatus->problem_has_been_acknowledged == TRUE) ? "  (Has been acknowledged)" : ""); printf("\n"); printf("\n", (temp_hoststatus->perf_data == NULL) ? "" : html_encode(temp_hoststatus->perf_data, TRUE)); printf("\n", (temp_hoststatus->state_type == HARD_STATE) ? "HARD" : "SOFT"); get_time_string(&temp_hoststatus->last_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("\n", date_time); printf("\n", (temp_hoststatus->check_type == CHECK_TYPE_ACTIVE) ? "ACTIVE" : "PASSIVE"); printf("\n"); get_time_string(&temp_hoststatus->next_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("\n", (temp_hoststatus->checks_enabled && temp_hoststatus->next_check != (time_t)0 && temp_hoststatus->should_be_scheduled == TRUE) ? date_time : "N/A"); get_time_string(&temp_hoststatus->last_state_change, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("\n", (temp_hoststatus->last_state_change == (time_t)0) ? "N/A" : date_time); get_time_string(&temp_hoststatus->last_notification, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("\n", (temp_hoststatus->last_notification == (time_t)0) ? "N/A" : date_time, temp_hoststatus->current_notification_number); printf("\n"); printf("\n", (temp_hoststatus->scheduled_downtime_depth > 0) ? "ACTIVE" : "INACTIVE", (temp_hoststatus->scheduled_downtime_depth > 0) ? "YES" : "NO"); t = 0; duration_error = FALSE; if(temp_hoststatus->last_check > current_time) duration_error = TRUE; else /*t=current_time-temp_hoststatus->last_check;*/ t = current_time - temp_hoststatus->last_update; get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds); if(duration_error == TRUE) snprintf(status_age, sizeof(status_age) - 1, "???"); else if(temp_hoststatus->last_check == (time_t)0) snprintf(status_age, sizeof(status_age) - 1, "N/A"); else snprintf(status_age, sizeof(status_age) - 1, "%2dd %2dh %2dm %2ds", days, hours, minutes, seconds); status_age[sizeof(status_age) - 1] = '\x0'; get_time_string(&temp_hoststatus->last_update, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("\n", (temp_hoststatus->last_update == (time_t)0) ? "N/A" : date_time, status_age); printf("
Host Status:
  %s  
 (for %s)%s
Status Information:%s", (temp_hoststatus->plugin_output == NULL) ? "" : html_encode(temp_hoststatus->plugin_output, TRUE)); if(enable_splunk_integration == TRUE) { printf("  "); asprintf(&buf, "%s %s", temp_host->name, temp_hoststatus->plugin_output); display_splunk_generic_url(buf, 1); free(buf); } if(temp_hoststatus->long_plugin_output != NULL) printf("
%s", html_encode(temp_hoststatus->long_plugin_output, TRUE)); printf("
Performance Data:%s
Current Attempt:%d/%d", temp_hoststatus->current_attempt, temp_hoststatus->max_attempts); printf("  (%s state)
Last Check Time:%s
Check Type:%s
Check Latency / Duration:"); if(temp_hoststatus->check_type == CHECK_TYPE_ACTIVE) printf("%.3f", temp_hoststatus->latency); else printf("N/A"); printf(" / %.3f seconds", temp_hoststatus->execution_time); printf("
Next Scheduled Active Check:  %s
Last State Change:%s
Last Notification:%s (notification %d)
Is This Host Flapping?"); if(temp_hoststatus->flap_detection_enabled == FALSE || enable_flap_detection == FALSE) printf("N/A"); else printf("
  %s  
 (%3.2f%% state change)", (temp_hoststatus->is_flapping == TRUE) ? "" : "not", (temp_hoststatus->is_flapping == TRUE) ? "YES" : "NO", temp_hoststatus->percent_state_change); printf("
In Scheduled Downtime?
  %s  
Last Update:%s  (%s ago)
\n"); printf("
\n"); printf("
\n"); printf("\n"); printf("\n"); printf("
\n"); printf("\n"); printf("\n", (temp_hoststatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED", (temp_hoststatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED"); printf("\n", (temp_hoststatus->accept_passive_checks == TRUE) ? "ENABLED" : "DISABLED", (temp_hoststatus->accept_passive_checks) ? "ENABLED" : "DISABLED"); printf("\n", (temp_hoststatus->obsess == TRUE) ? "ENABLED" : "DISABLED", (temp_hoststatus->obsess) ? "ENABLED" : "DISABLED"); printf("\n", (temp_hoststatus->notifications_enabled) ? "ENABLED" : "DISABLED", (temp_hoststatus->notifications_enabled) ? "ENABLED" : "DISABLED"); printf("\n", (temp_hoststatus->event_handler_enabled) ? "ENABLED" : "DISABLED", (temp_hoststatus->event_handler_enabled) ? "ENABLED" : "DISABLED"); printf("\n", (temp_hoststatus->flap_detection_enabled == TRUE) ? "ENABLED" : "DISABLED", (temp_hoststatus->flap_detection_enabled == TRUE) ? "ENABLED" : "DISABLED"); printf("
Active Checks:
  %s  
Passive Checks:
  %s  
Obsessing:
  %s  
Notifications:
  %s  
Event Handler:
  %s  
Flap Detection:
  %s  
\n"); printf("
\n"); printf("
\n"); } printf("
\n"); printf("\n"); printf("\n"); printf("\n"); printf("
\n"); printf("
Host Commands
\n"); printf("
\n"); if(nagios_process_state == STATE_OK && is_authorized_for_read_only(¤t_authdata) == FALSE) { printf("\n"); #ifdef USE_STATUSMAP printf("\n", url_images_path, STATUSMAP_ICON, STATUSMAP_CGI, url_encode(host_name), url_encode(host_name)); #endif if(temp_hoststatus->checks_enabled == TRUE) { printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_CHECK, url_encode(host_name)); } else printf("\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_CHECK, url_encode(host_name)); printf("\n", url_images_path, DELAY_ICON, COMMAND_CGI, CMD_SCHEDULE_HOST_CHECK, url_encode(host_name), (temp_hoststatus->checks_enabled == TRUE) ? "&force_check" : ""); if(temp_hoststatus->accept_passive_checks == TRUE) { printf("\n", url_images_path, PASSIVE_ICON, COMMAND_CGI, CMD_PROCESS_HOST_CHECK_RESULT, url_encode(host_name)); printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_PASSIVE_HOST_CHECKS, url_encode(host_name)); } else printf("\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_PASSIVE_HOST_CHECKS, url_encode(host_name)); if(temp_hoststatus->obsess == TRUE) printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_OBSESSING_OVER_HOST, url_encode(host_name)); else printf("\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_OBSESSING_OVER_HOST, url_encode(host_name)); if(temp_hoststatus->status == SD_HOST_DOWN || temp_hoststatus->status == SD_HOST_UNREACHABLE) { if(temp_hoststatus->problem_has_been_acknowledged == FALSE) printf("\n", url_images_path, ACKNOWLEDGEMENT_ICON, COMMAND_CGI, CMD_ACKNOWLEDGE_HOST_PROBLEM, url_encode(host_name)); else printf("\n", url_images_path, REMOVE_ACKNOWLEDGEMENT_ICON, COMMAND_CGI, CMD_REMOVE_HOST_ACKNOWLEDGEMENT, url_encode(host_name)); } if(temp_hoststatus->notifications_enabled == TRUE) printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_NOTIFICATIONS, url_encode(host_name)); else printf("\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_NOTIFICATIONS, url_encode(host_name)); printf("\n", url_images_path, NOTIFICATION_ICON, COMMAND_CGI, CMD_SEND_CUSTOM_HOST_NOTIFICATION, url_encode(host_name)); if(temp_hoststatus->status != SD_HOST_UP) printf("\n", url_images_path, DELAY_ICON, COMMAND_CGI, CMD_DELAY_HOST_NOTIFICATION, url_encode(host_name)); printf("\n", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_HOST_DOWNTIME, url_encode(host_name)); printf("\n", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_HOST_SVC_DOWNTIME, url_encode(host_name)); printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_SVC_NOTIFICATIONS, url_encode(host_name)); printf("\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_SVC_NOTIFICATIONS, url_encode(host_name)); printf("\n", url_images_path, DELAY_ICON, COMMAND_CGI, CMD_SCHEDULE_HOST_SVC_CHECKS, url_encode(host_name)); printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_SVC_CHECKS, url_encode(host_name)); printf("\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_SVC_CHECKS, url_encode(host_name)); if(temp_hoststatus->event_handler_enabled == TRUE) printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_EVENT_HANDLER, url_encode(host_name)); else printf("\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_EVENT_HANDLER, url_encode(host_name)); if(temp_hoststatus->flap_detection_enabled == TRUE) { printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_FLAP_DETECTION, url_encode(host_name)); printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_CLEAR_HOST_FLAPPING_STATE, url_encode(host_name)); } else printf("\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_FLAP_DETECTION, url_encode(host_name)); printf("
Locate Host On MapLocate host on map
Disable Active Checks Of This HostDisable active checks of this host
Enable Active Checks Of This HostEnable active checks of this host
Re-schedule Next Host CheckRe-schedule the next check of this host
Submit Passive Check Result For This HostSubmit passive check result for this host
Stop Accepting Passive Checks For This HostStop accepting passive checks for this host
Start Accepting Passive Checks For This HostStart accepting passive checks for this host
Stop Obsessing Over This HostStop obsessing over this host
Start Obsessing Over This HostStart obsessing over this host
Acknowledge This Host ProblemAcknowledge this host problem
Remove Problem AcknowledgementRemove problem acknowledgement
Disable Notifications For This HostDisable notifications for this host
Enable Notifications For This HostEnable notifications for this host
Send Custom NotificationSend custom host notification
Delay Next Host NotificationDelay next host notification
Schedule Downtime For This HostSchedule downtime for this host
Schedule Downtime For All Services On This HostSchedule downtime for all services on this host
Disable Notifications For All Services On This HostDisable notifications for all services on this host
Enable Notifications For All Services On This HostEnable notifications for all services on this host
Schedule A Check Of All Services On This HostSchedule a check of all services on this host
Disable Checks Of All Services On This HostDisable checks of all services on this host
Enable Checks Of All Services On This HostEnable checks of all services on this host
Disable Event Handler For This HostDisable event handler for this host
Enable Event Handler For This HostEnable event handler for this host
Disable Flap Detection For This HostDisable flap detection for this host
Clear Flapping State For This HostClear flapping state for this host
Enable Flap Detection For This HostEnable flap detection for this host
\n"); } else if(is_authorized_for_read_only(¤t_authdata) == TRUE) { printf("
Your account does not have permissions to execute commands.
\n"); } else { printf("
It appears as though Nagios is not running, so commands are temporarily unavailable...
\n"); printf("Click here to view Nagios process information
\n", EXTINFO_CGI, DISPLAY_PROCESS_INFO); } printf("
\n"); printf("
\n"); /* display comments */ display_comments(HOST_COMMENT); printf("
\n"); printf("\n"); return; } void show_service_info(void) { service *temp_service; char date_time[MAX_DATETIME_LENGTH]; char status_age[48]; char state_duration[48]; servicestatus *temp_svcstatus; char state_string[MAX_INPUT_BUFFER]; const char *bg_class = ""; char *buf = NULL; int days; int hours; int minutes; int seconds; time_t t; time_t current_time; int duration_error = FALSE; /* find the service */ temp_service = find_service(host_name, service_desc); /* make sure the user has rights to view service information */ if(is_authorized_for_service(temp_service, ¤t_authdata) == FALSE) { printf("

It appears as though you do not have permission to view information for this service...

\n"); printf("

If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI
"); printf("and check the authorization options in your CGI configuration file.

\n"); return; } /* get service status info */ temp_svcstatus = find_servicestatus(host_name, service_desc); /* make sure service information exists */ if(temp_service == NULL) { printf("

Error: Service Not Found!

"); return; } if(temp_svcstatus == NULL) { printf("

Error: Service Status Not Found!

"); return; } printf("
\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("
\n"); printf("
Service State Information
\n"); if(temp_svcstatus->has_been_checked == FALSE) printf("

This service has not yet been checked, so status information is not available.

\n"); else { printf("\n"); printf("\n"); printf("\n"); printf("
\n"); printf("\n"); printf("\n"); printf("
\n"); printf("\n"); current_time = time(NULL); t = 0; duration_error = FALSE; if(temp_svcstatus->last_state_change == (time_t)0) { if(program_start > current_time) duration_error = TRUE; else t = current_time - program_start; } else { if(temp_svcstatus->last_state_change > current_time) duration_error = TRUE; else t = current_time - temp_svcstatus->last_state_change; } get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds); if(duration_error == TRUE) snprintf(state_duration, sizeof(state_duration) - 1, "???"); else snprintf(state_duration, sizeof(state_duration) - 1, "%2dd %2dh %2dm %2ds%s", days, hours, minutes, seconds, (temp_svcstatus->last_state_change == (time_t)0) ? "+" : ""); state_duration[sizeof(state_duration) - 1] = '\x0'; if(temp_svcstatus->status == SERVICE_OK) { strcpy(state_string, "OK"); bg_class = "serviceOK"; } else if(temp_svcstatus->status == SERVICE_WARNING) { strcpy(state_string, "WARNING"); bg_class = "serviceWARNING"; } else if(temp_svcstatus->status == SERVICE_CRITICAL) { strcpy(state_string, "CRITICAL"); bg_class = "serviceCRITICAL"; } else { strcpy(state_string, "UNKNOWN"); bg_class = "serviceUNKNOWN"; } printf("\n", bg_class, state_string, state_duration, (temp_svcstatus->problem_has_been_acknowledged == TRUE) ? "  (Has been acknowledged)" : ""); printf("\n"); printf("\n", (temp_svcstatus->perf_data == NULL) ? "" : html_encode(temp_svcstatus->perf_data, TRUE)); printf("\n", (temp_svcstatus->state_type == HARD_STATE) ? "HARD" : "SOFT"); get_time_string(&temp_svcstatus->last_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("\n", date_time); printf("\n", (temp_svcstatus->check_type == CHECK_TYPE_ACTIVE) ? "ACTIVE" : "PASSIVE"); printf("\n"); get_time_string(&temp_svcstatus->next_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("\n", (temp_svcstatus->checks_enabled && temp_svcstatus->next_check != (time_t)0 && temp_svcstatus->should_be_scheduled == TRUE) ? date_time : "N/A"); get_time_string(&temp_svcstatus->last_state_change, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("\n", (temp_svcstatus->last_state_change == (time_t)0) ? "N/A" : date_time); get_time_string(&temp_svcstatus->last_notification, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("\n", (temp_svcstatus->last_notification == (time_t)0) ? "N/A" : date_time, temp_svcstatus->current_notification_number); printf("\n"); printf("\n", (temp_svcstatus->scheduled_downtime_depth > 0) ? "ACTIVE" : "INACTIVE", (temp_svcstatus->scheduled_downtime_depth > 0) ? "YES" : "NO"); t = 0; duration_error = FALSE; if(temp_svcstatus->last_check > current_time) duration_error = TRUE; else /*t=current_time-temp_svcstatus->last_check;*/ t = current_time - temp_svcstatus->last_update; get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds); if(duration_error == TRUE) snprintf(status_age, sizeof(status_age) - 1, "???"); else if(temp_svcstatus->last_check == (time_t)0) snprintf(status_age, sizeof(status_age) - 1, "N/A"); else snprintf(status_age, sizeof(status_age) - 1, "%2dd %2dh %2dm %2ds", days, hours, minutes, seconds); status_age[sizeof(status_age) - 1] = '\x0'; get_time_string(&temp_svcstatus->last_update, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("\n", (temp_svcstatus->last_update == (time_t)0) ? "N/A" : date_time, status_age); printf("
Current Status:
  %s  
 (for %s)%s
Status Information:%s", (temp_svcstatus->plugin_output == NULL) ? "" : html_encode(temp_svcstatus->plugin_output, TRUE)); if(enable_splunk_integration == TRUE) { printf("  "); asprintf(&buf, "%s %s %s", temp_service->host_name, temp_service->description, temp_svcstatus->plugin_output); display_splunk_generic_url(buf, 1); free(buf); } if(temp_svcstatus->long_plugin_output != NULL) printf("
%s", html_encode(temp_svcstatus->long_plugin_output, TRUE)); printf("
Performance Data:%s
Current Attempt:%d/%d", temp_svcstatus->current_attempt, temp_svcstatus->max_attempts); printf("  (%s state)
Last Check Time:%s
Check Type:%s
Check Latency / Duration:"); if(temp_svcstatus->check_type == CHECK_TYPE_ACTIVE) printf("%.3f", temp_svcstatus->latency); else printf("N/A"); printf(" / %.3f seconds", temp_svcstatus->execution_time); printf("
Next Scheduled Check:  %s
Last State Change:%s
Last Notification:%s (notification %d)
Is This Service Flapping?"); if(temp_svcstatus->flap_detection_enabled == FALSE || enable_flap_detection == FALSE) printf("N/A"); else printf("
  %s  
 (%3.2f%% state change)", (temp_svcstatus->is_flapping == TRUE) ? "" : "not", (temp_svcstatus->is_flapping == TRUE) ? "YES" : "NO", temp_svcstatus->percent_state_change); printf("
In Scheduled Downtime?
  %s  
Last Update:%s  (%s ago)
\n"); printf("
\n"); printf("
\n"); printf("\n"); printf("\n"); printf("
\n"); printf("\n"); printf("\n", (temp_svcstatus->checks_enabled) ? "ENABLED" : "DISABLED", (temp_svcstatus->checks_enabled) ? "ENABLED" : "DISABLED"); printf("\n", (temp_svcstatus->accept_passive_checks == TRUE) ? "ENABLED" : "DISABLED", (temp_svcstatus->accept_passive_checks) ? "ENABLED" : "DISABLED"); printf("\n", (temp_svcstatus->obsess == TRUE) ? "ENABLED" : "DISABLED", (temp_svcstatus->obsess) ? "ENABLED" : "DISABLED"); printf("\n", (temp_svcstatus->notifications_enabled) ? "ENABLED" : "DISABLED", (temp_svcstatus->notifications_enabled) ? "ENABLED" : "DISABLED"); printf("\n", (temp_svcstatus->event_handler_enabled) ? "ENABLED" : "DISABLED", (temp_svcstatus->event_handler_enabled) ? "ENABLED" : "DISABLED"); printf("\n", (temp_svcstatus->flap_detection_enabled == TRUE) ? "ENABLED" : "DISABLED", (temp_svcstatus->flap_detection_enabled == TRUE) ? "ENABLED" : "DISABLED"); printf("
Active Checks:
  %s  
Passive Checks:
  %s  
Obsessing:
  %s  
Notifications:
  %s  
Event Handler:
  %s  
Flap Detection:
  %s  
\n"); printf("
\n"); printf("
\n"); } printf("
\n"); printf("\n"); printf("\n"); printf("
\n"); printf("
Service Commands
\n"); printf("\n"); printf("\n"); printf("
\n"); if(nagios_process_state == STATE_OK && is_authorized_for_read_only(¤t_authdata) == FALSE) { printf("\n"); if(temp_svcstatus->checks_enabled) { printf("\n", url_encode(service_desc)); } else { printf("\n", url_encode(service_desc)); } printf("\n", url_encode(service_desc), (temp_svcstatus->checks_enabled == TRUE) ? "&force_check" : ""); if(temp_svcstatus->accept_passive_checks == TRUE) { printf("\n", url_encode(service_desc)); printf("\n", url_encode(service_desc)); } else { printf("\n", url_encode(service_desc)); } if(temp_svcstatus->obsess == TRUE) { printf("\n", url_encode(service_desc)); } else { printf("\n", url_encode(service_desc)); } if((temp_svcstatus->status == SERVICE_WARNING || temp_svcstatus->status == SERVICE_UNKNOWN || temp_svcstatus->status == SERVICE_CRITICAL) && temp_svcstatus->state_type == HARD_STATE) { if(temp_svcstatus->problem_has_been_acknowledged == FALSE) { printf("\n", url_encode(service_desc)); } else { printf("\n", url_encode(service_desc)); } } if(temp_svcstatus->notifications_enabled == TRUE) { printf("\n", url_encode(service_desc)); if(temp_svcstatus->status != SERVICE_OK) { printf("\n", url_encode(service_desc)); } } else { printf("\n", url_encode(service_desc)); } printf("\n", url_encode(service_desc)); printf("\n", url_encode(service_desc)); /* printf("\n",url_encode(service_desc)); */ if(temp_svcstatus->event_handler_enabled == TRUE) { printf("\n", url_encode(service_desc)); } else { printf("\n", url_encode(service_desc)); } if(temp_svcstatus->flap_detection_enabled == TRUE) { printf("\n", url_encode(service_desc)); printf("\n", url_encode(service_desc)); } else { printf("\n", url_encode(service_desc)); } printf("
Disable Active Checks Of This ServiceDisable active checks of this service
Enable Active Checks Of This ServiceEnable active checks of this service
Re-schedule Next Service CheckRe-schedule the next check of this service
Submit Passive Check Result For This ServiceSubmit passive check result for this service
Stop Accepting Passive Checks For This ServiceStop accepting passive checks for this service
Start Accepting Passive Checks For This ServiceStart accepting passive checks for this service
Stop Obsessing Over This ServiceStop obsessing over this service
Start Obsessing Over This ServiceStart obsessing over this service
Acknowledge This Service ProblemAcknowledge this service problem
Remove Problem AcknowledgementRemove problem acknowledgement
Disable Notifications For This ServiceDisable notifications for this service
Delay Next Service NotificationDelay next service notification
Enable Notifications For This ServiceEnable notifications for this service
Send Custom NotificationSend custom service notification
Schedule Downtime For This ServiceSchedule downtime for this service
Cancel Scheduled Downtime For This ServiceCancel scheduled downtime for this service
Disable Event Handler For This ServiceDisable event handler for this service
Enable Event Handler For This ServiceEnable event handler for this service
Disable Flap Detection For This ServiceDisable flap detection for this service
Clear Flapping State For This ServiceClear flapping state for this service
Enable Flap Detection For This ServiceEnable flap detection for this service
\n"); } else if(is_authorized_for_read_only(¤t_authdata) == TRUE) { printf("
Your account does not have permissions to execute commands.
\n"); } else { printf("
It appears as though Nagios is not running, so commands are temporarily unavailable...
\n"); printf("Click here to view Nagios process information
\n", EXTINFO_CGI, DISPLAY_PROCESS_INFO); } printf("
\n"); printf("

\n"); /* display comments */ display_comments(SERVICE_COMMENT); printf("
\n"); printf("
\n"); return; } void show_hostgroup_info(void) { hostgroup *temp_hostgroup; /* get hostgroup info */ temp_hostgroup = find_hostgroup(hostgroup_name); /* make sure the user has rights to view hostgroup information */ if(is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == FALSE) { printf("

It appears as though you do not have permission to view information for this hostgroup...

\n"); printf("

If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI
"); printf("and check the authorization options in your CGI configuration file.

\n"); return; } /* make sure hostgroup information exists */ if(temp_hostgroup == NULL) { printf("

Error: Hostgroup Not Found!

"); return; } printf("
\n"); printf("\n"); printf("\n"); /* top left panel */ printf("\n"); printf("\n"); /* left bottom panel */ printf("\n"); printf("
\n"); /* right top panel */ printf("\n"); printf("
Hostgroup Commands
\n"); if(nagios_process_state == STATE_OK && is_authorized_for_read_only(¤t_authdata) == FALSE) { printf("\n"); printf("\n"); printf("
\n"); printf("\n"); printf("\n", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME, url_encode(hostgroup_name)); printf("\n", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME, url_encode(hostgroup_name)); printf("\n", url_images_path, NOTIFICATION_ICON, COMMAND_CGI, CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS, url_encode(hostgroup_name)); printf("\n", url_images_path, NOTIFICATIONS_DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS, url_encode(hostgroup_name)); printf("\n", url_images_path, NOTIFICATION_ICON, COMMAND_CGI, CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS, url_encode(hostgroup_name)); printf("\n", url_images_path, NOTIFICATIONS_DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS, url_encode(hostgroup_name)); printf("\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOSTGROUP_SVC_CHECKS, url_encode(hostgroup_name)); printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOSTGROUP_SVC_CHECKS, url_encode(hostgroup_name)); printf("
Schedule Downtime For All Hosts In This HostgroupSchedule downtime for all hosts in this hostgroup
Schedule Downtime For All Services In This HostgroupSchedule downtime for all services in this hostgroup
Enable Notifications For All Hosts In This HostgroupEnable notifications for all hosts in this hostgroup
Disable Notifications For All Hosts In This HostgroupDisable notifications for all hosts in this hostgroup
Enable Notifications For All Services In This HostgroupEnable notifications for all services in this hostgroup
Disable Notifications For All Services In This HostgroupDisable notifications for all services in this hostgroup
Enable Active Checks Of All Services In This HostgroupEnable active checks of all services in this hostgroup
Disable Active Checks Of All Services In This HostgroupDisable active checks of all services in this hostgroup
\n"); printf("
\n"); } else if(is_authorized_for_read_only(¤t_authdata) == TRUE) { printf("
Your account does not have permissions to execute commands.
\n"); } else { printf("
It appears as though Nagios is not running, so commands are temporarily unavailable...
\n"); printf("Click here to view Nagios process information
\n", EXTINFO_CGI, DISPLAY_PROCESS_INFO); } printf("
\n"); printf("
\n"); printf("
\n"); printf("\n"); printf("\n"); return; } void show_servicegroup_info() { servicegroup *temp_servicegroup; /* get servicegroup info */ temp_servicegroup = find_servicegroup(servicegroup_name); /* make sure the user has rights to view servicegroup information */ if(is_authorized_for_servicegroup(temp_servicegroup, ¤t_authdata) == FALSE) { printf("

It appears as though you do not have permission to view information for this servicegroup...

\n"); printf("

If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI
"); printf("and check the authorization options in your CGI configuration file.

\n"); return; } /* make sure servicegroup information exists */ if(temp_servicegroup == NULL) { printf("

Error: Servicegroup Not Found!

"); return; } printf("
\n"); printf("\n"); printf("\n"); /* top left panel */ printf("\n"); printf("\n"); /* left bottom panel */ printf("\n"); printf("
\n"); /* right top panel */ printf("\n"); printf("
Servicegroup Commands
\n"); if(nagios_process_state == STATE_OK) { printf("\n"); printf("\n"); printf("
\n"); printf("\n"); printf("\n", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME, url_encode(servicegroup_name)); printf("\n", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME, url_encode(servicegroup_name)); printf("\n", url_images_path, NOTIFICATION_ICON, COMMAND_CGI, CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS, url_encode(servicegroup_name)); printf("\n", url_images_path, NOTIFICATIONS_DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS, url_encode(servicegroup_name)); printf("\n", url_images_path, NOTIFICATION_ICON, COMMAND_CGI, CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS, url_encode(servicegroup_name)); printf("\n", url_images_path, NOTIFICATIONS_DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS, url_encode(servicegroup_name)); printf("\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_SERVICEGROUP_SVC_CHECKS, url_encode(servicegroup_name)); printf("\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_SERVICEGROUP_SVC_CHECKS, url_encode(servicegroup_name)); printf("
Schedule Downtime For All Hosts In This ServicegroupSchedule downtime for all hosts in this servicegroup
Schedule Downtime For All Services In This ServicegroupSchedule downtime for all services in this servicegroup
Enable Notifications For All Hosts In This ServicegroupEnable notifications for all hosts in this servicegroup
Disable Notifications For All Hosts In This ServicegroupDisable notifications for all hosts in this servicegroup
Enable Notifications For All Services In This ServicegroupEnable notifications for all services in this servicegroup
Disable Notifications For All Services In This ServicegroupDisable notifications for all services in this servicegroup
Enable Active Checks Of All Services In This ServicegroupEnable active checks of all services in this servicegroup
Disable Active Checks Of All Services In This ServicegroupDisable active checks of all services in this servicegroup
\n"); printf("
\n"); } else { printf("
It appears as though Nagios is not running, so commands are temporarily unavailable...
\n"); printf("Click here to view Nagios process information
\n", EXTINFO_CGI, DISPLAY_PROCESS_INFO); } printf("
\n"); printf("
\n"); printf("
\n"); printf("\n"); printf("\n"); return; } /* shows all service and host comments */ void show_all_comments(void) { int total_comments = 0; const char *bg_class = ""; int odd = 0; char date_time[MAX_DATETIME_LENGTH]; nagios_comment *temp_comment; host *temp_host; service *temp_service; char *comment_type; char expire_time[MAX_DATETIME_LENGTH]; printf("
\n"); printf("
Host Comments | Service Comments ]
\n"); printf("
\n"); printf("\n"); printf("
Host Comments
\n"); if(is_authorized_for_read_only(¤t_authdata)==FALSE) { printf("
 ", url_images_path, COMMENT_ICON); printf("", COMMAND_CGI, CMD_ADD_HOST_COMMENT); printf("Add a new host comment
\n"); } printf("
\n"); printf("
\n"); printf("\n"); if(is_authorized_for_read_only(¤t_authdata)==FALSE) printf("\n"); else printf("\n"); /* display all the host comments */ for(temp_comment = comment_list, total_comments = 0; temp_comment != NULL; temp_comment = temp_comment->next) { if(temp_comment->comment_type != HOST_COMMENT) continue; temp_host = find_host(temp_comment->host_name); /* make sure the user has rights to view host information */ if(is_authorized_for_host(temp_host, ¤t_authdata) == FALSE) continue; total_comments++; if(odd) { odd = 0; bg_class = "commentOdd"; } else { odd = 1; bg_class = "commentEven"; } switch(temp_comment->entry_type) { case USER_COMMENT: comment_type = "User"; break; case DOWNTIME_COMMENT: comment_type = "Scheduled Downtime"; break; case FLAPPING_COMMENT: comment_type = "Flap Detection"; break; case ACKNOWLEDGEMENT_COMMENT: comment_type = "Acknowledgement"; break; default: comment_type = "?"; } get_time_string(&temp_comment->entry_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); get_time_string(&temp_comment->expire_time, expire_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("", bg_class); printf("", bg_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_comment->host_name), temp_comment->host_name); printf("", bg_class, date_time, bg_class, temp_comment->author, bg_class, temp_comment->comment_data, bg_class, temp_comment->comment_id, bg_class, (temp_comment->persistent) ? "Yes" : "No", bg_class, comment_type, bg_class, (temp_comment->expires == TRUE) ? expire_time : "N/A"); if(is_authorized_for_read_only(¤t_authdata)==FALSE) printf("", COMMAND_CGI, CMD_DEL_HOST_COMMENT, temp_comment->comment_id, url_images_path, DELETE_ICON); printf("\n"); } if(total_comments == 0) printf(""); printf("
Host NameEntry TimeAuthorCommentComment IDPersistentTypeExpiresActions
Host NameEntry TimeAuthorCommentComment IDPersistentTypeExpires
%s%s%s%s%ld%s%s%sDelete This Comment
There are no host comments
\n"); printf("
\n"); printf("


\n"); printf("\n"); printf("
Service Comments
\n"); if(is_authorized_for_read_only(¤t_authdata)==FALSE){ printf("
 ", url_images_path, COMMENT_ICON); printf("", COMMAND_CGI, CMD_ADD_SVC_COMMENT); printf("Add a new service comment
\n"); } printf("
\n"); printf("
\n"); printf("\n"); if(is_authorized_for_read_only(¤t_authdata)==FALSE) printf("\n"); else printf("\n"); /* display all the service comments */ for(temp_comment = comment_list, total_comments = 0; temp_comment != NULL; temp_comment = temp_comment->next) { if(temp_comment->comment_type != SERVICE_COMMENT) continue; temp_service = find_service(temp_comment->host_name, temp_comment->service_description); /* make sure the user has rights to view service information */ if(is_authorized_for_service(temp_service, ¤t_authdata) == FALSE) continue; total_comments++; if(odd) { odd = 0; bg_class = "commentOdd"; } else { odd = 1; bg_class = "commentEven"; } switch(temp_comment->entry_type) { case USER_COMMENT: comment_type = "User"; break; case DOWNTIME_COMMENT: comment_type = "Scheduled Downtime"; break; case FLAPPING_COMMENT: comment_type = "Flap Detection"; break; case ACKNOWLEDGEMENT_COMMENT: comment_type = "Acknowledgement"; break; default: comment_type = "?"; } get_time_string(&temp_comment->entry_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); get_time_string(&temp_comment->expire_time, expire_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("", bg_class); printf("", bg_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_comment->host_name), temp_comment->host_name); printf("", url_encode(temp_comment->service_description), temp_comment->service_description); printf("", bg_class, date_time, bg_class, temp_comment->author, bg_class, temp_comment->comment_data, bg_class, temp_comment->comment_id, bg_class, (temp_comment->persistent) ? "Yes" : "No", bg_class, comment_type, bg_class, (temp_comment->expires == TRUE) ? expire_time : "N/A"); if(is_authorized_for_read_only(¤t_authdata)==FALSE) printf("", COMMAND_CGI, CMD_DEL_SVC_COMMENT, temp_comment->comment_id, url_images_path, DELETE_ICON); printf("\n"); } if(total_comments == 0) printf(""); printf("
Host NameServiceEntry TimeAuthorCommentComment IDPersistentTypeExpiresActions
Host NameServiceEntry TimeAuthorCommentComment IDPersistentTypeExpires
%s%s%s%s%s%ld%s%s%sDelete This Comment
There are no service comments
\n"); printf("
\n"); return; } void show_performance_data(void) { service *temp_service = NULL; servicestatus *temp_servicestatus = NULL; host *temp_host = NULL; hoststatus *temp_hoststatus = NULL; int total_active_service_checks = 0; int total_passive_service_checks = 0; double min_service_execution_time = 0.0; double max_service_execution_time = 0.0; double total_service_execution_time = 0.0; int have_min_service_execution_time = FALSE; int have_max_service_execution_time = FALSE; double min_service_latency = 0.0; double max_service_latency = 0.0; double long total_service_latency = 0.0; int have_min_service_latency = FALSE; int have_max_service_latency = FALSE; double min_host_latency = 0.0; double max_host_latency = 0.0; double total_host_latency = 0.0; int have_min_host_latency = FALSE; int have_max_host_latency = FALSE; double min_service_percent_change_a = 0.0; double max_service_percent_change_a = 0.0; double total_service_percent_change_a = 0.0; int have_min_service_percent_change_a = FALSE; int have_max_service_percent_change_a = FALSE; double min_service_percent_change_b = 0.0; double max_service_percent_change_b = 0.0; double total_service_percent_change_b = 0.0; int have_min_service_percent_change_b = FALSE; int have_max_service_percent_change_b = FALSE; int active_service_checks_1min = 0; int active_service_checks_5min = 0; int active_service_checks_15min = 0; int active_service_checks_1hour = 0; int active_service_checks_start = 0; int active_service_checks_ever = 0; int passive_service_checks_1min = 0; int passive_service_checks_5min = 0; int passive_service_checks_15min = 0; int passive_service_checks_1hour = 0; int passive_service_checks_start = 0; int passive_service_checks_ever = 0; int total_active_host_checks = 0; int total_passive_host_checks = 0; double min_host_execution_time = 0.0; double max_host_execution_time = 0.0; double total_host_execution_time = 0.0; int have_min_host_execution_time = FALSE; int have_max_host_execution_time = FALSE; double min_host_percent_change_a = 0.0; double max_host_percent_change_a = 0.0; double total_host_percent_change_a = 0.0; int have_min_host_percent_change_a = FALSE; int have_max_host_percent_change_a = FALSE; double min_host_percent_change_b = 0.0; double max_host_percent_change_b = 0.0; double total_host_percent_change_b = 0.0; int have_min_host_percent_change_b = FALSE; int have_max_host_percent_change_b = FALSE; int active_host_checks_1min = 0; int active_host_checks_5min = 0; int active_host_checks_15min = 0; int active_host_checks_1hour = 0; int active_host_checks_start = 0; int active_host_checks_ever = 0; int passive_host_checks_1min = 0; int passive_host_checks_5min = 0; int passive_host_checks_15min = 0; int passive_host_checks_1hour = 0; int passive_host_checks_start = 0; int passive_host_checks_ever = 0; time_t current_time; time(¤t_time); /* check all services */ for(temp_servicestatus = servicestatus_list; temp_servicestatus != NULL; temp_servicestatus = temp_servicestatus->next) { /* find the service */ temp_service = find_service(temp_servicestatus->host_name, temp_servicestatus->description); /* make sure the user has rights to view service information */ if(is_authorized_for_service(temp_service, ¤t_authdata) == FALSE) continue; /* is this an active or passive check? */ if(temp_servicestatus->check_type == CHECK_TYPE_ACTIVE) { total_active_service_checks++; total_service_execution_time += temp_servicestatus->execution_time; if(have_min_service_execution_time == FALSE || temp_servicestatus->execution_time < min_service_execution_time) { have_min_service_execution_time = TRUE; min_service_execution_time = temp_servicestatus->execution_time; } if(have_max_service_execution_time == FALSE || temp_servicestatus->execution_time > max_service_execution_time) { have_max_service_execution_time = TRUE; max_service_execution_time = temp_servicestatus->execution_time; } total_service_percent_change_a += temp_servicestatus->percent_state_change; if(have_min_service_percent_change_a == FALSE || temp_servicestatus->percent_state_change < min_service_percent_change_a) { have_min_service_percent_change_a = TRUE; min_service_percent_change_a = temp_servicestatus->percent_state_change; } if(have_max_service_percent_change_a == FALSE || temp_servicestatus->percent_state_change > max_service_percent_change_a) { have_max_service_percent_change_a = TRUE; max_service_percent_change_a = temp_servicestatus->percent_state_change; } total_service_latency += temp_servicestatus->latency; if(have_min_service_latency == FALSE || temp_servicestatus->latency < min_service_latency) { have_min_service_latency = TRUE; min_service_latency = temp_servicestatus->latency; } if(have_max_service_latency == FALSE || temp_servicestatus->latency > max_service_latency) { have_max_service_latency = TRUE; max_service_latency = temp_servicestatus->latency; } if(temp_servicestatus->last_check >= (current_time - 60)) active_service_checks_1min++; if(temp_servicestatus->last_check >= (current_time - 300)) active_service_checks_5min++; if(temp_servicestatus->last_check >= (current_time - 900)) active_service_checks_15min++; if(temp_servicestatus->last_check >= (current_time - 3600)) active_service_checks_1hour++; if(temp_servicestatus->last_check >= program_start) active_service_checks_start++; if(temp_servicestatus->last_check != (time_t)0) active_service_checks_ever++; } else { total_passive_service_checks++; total_service_percent_change_b += temp_servicestatus->percent_state_change; if(have_min_service_percent_change_b == FALSE || temp_servicestatus->percent_state_change < min_service_percent_change_b) { have_min_service_percent_change_b = TRUE; min_service_percent_change_b = temp_servicestatus->percent_state_change; } if(have_max_service_percent_change_b == FALSE || temp_servicestatus->percent_state_change > max_service_percent_change_b) { have_max_service_percent_change_b = TRUE; max_service_percent_change_b = temp_servicestatus->percent_state_change; } if(temp_servicestatus->last_check >= (current_time - 60)) passive_service_checks_1min++; if(temp_servicestatus->last_check >= (current_time - 300)) passive_service_checks_5min++; if(temp_servicestatus->last_check >= (current_time - 900)) passive_service_checks_15min++; if(temp_servicestatus->last_check >= (current_time - 3600)) passive_service_checks_1hour++; if(temp_servicestatus->last_check >= program_start) passive_service_checks_start++; if(temp_servicestatus->last_check != (time_t)0) passive_service_checks_ever++; } } /* check all hosts */ for(temp_hoststatus = hoststatus_list; temp_hoststatus != NULL; temp_hoststatus = temp_hoststatus->next) { /* find the host */ temp_host = find_host(temp_hoststatus->host_name); /* make sure the user has rights to view host information */ if(is_authorized_for_host(temp_host, ¤t_authdata) == FALSE) continue; /* is this an active or passive check? */ if(temp_hoststatus->check_type == CHECK_TYPE_ACTIVE) { total_active_host_checks++; total_host_execution_time += temp_hoststatus->execution_time; if(have_min_host_execution_time == FALSE || temp_hoststatus->execution_time < min_host_execution_time) { have_min_host_execution_time = TRUE; min_host_execution_time = temp_hoststatus->execution_time; } if(have_max_host_execution_time == FALSE || temp_hoststatus->execution_time > max_host_execution_time) { have_max_host_execution_time = TRUE; max_host_execution_time = temp_hoststatus->execution_time; } total_host_percent_change_a += temp_hoststatus->percent_state_change; if(have_min_host_percent_change_a == FALSE || temp_hoststatus->percent_state_change < min_host_percent_change_a) { have_min_host_percent_change_a = TRUE; min_host_percent_change_a = temp_hoststatus->percent_state_change; } if(have_max_host_percent_change_a == FALSE || temp_hoststatus->percent_state_change > max_host_percent_change_a) { have_max_host_percent_change_a = TRUE; max_host_percent_change_a = temp_hoststatus->percent_state_change; } total_host_latency += temp_hoststatus->latency; if(have_min_host_latency == FALSE || temp_hoststatus->latency < min_host_latency) { have_min_host_latency = TRUE; min_host_latency = temp_hoststatus->latency; } if(have_max_host_latency == FALSE || temp_hoststatus->latency > max_host_latency) { have_max_host_latency = TRUE; max_host_latency = temp_hoststatus->latency; } if(temp_hoststatus->last_check >= (current_time - 60)) active_host_checks_1min++; if(temp_hoststatus->last_check >= (current_time - 300)) active_host_checks_5min++; if(temp_hoststatus->last_check >= (current_time - 900)) active_host_checks_15min++; if(temp_hoststatus->last_check >= (current_time - 3600)) active_host_checks_1hour++; if(temp_hoststatus->last_check >= program_start) active_host_checks_start++; if(temp_hoststatus->last_check != (time_t)0) active_host_checks_ever++; } else { total_passive_host_checks++; total_host_percent_change_b += temp_hoststatus->percent_state_change; if(have_min_host_percent_change_b == FALSE || temp_hoststatus->percent_state_change < min_host_percent_change_b) { have_min_host_percent_change_b = TRUE; min_host_percent_change_b = temp_hoststatus->percent_state_change; } if(have_max_host_percent_change_b == FALSE || temp_hoststatus->percent_state_change > max_host_percent_change_b) { have_max_host_percent_change_b = TRUE; max_host_percent_change_b = temp_hoststatus->percent_state_change; } if(temp_hoststatus->last_check >= (current_time - 60)) passive_host_checks_1min++; if(temp_hoststatus->last_check >= (current_time - 300)) passive_host_checks_5min++; if(temp_hoststatus->last_check >= (current_time - 900)) passive_host_checks_15min++; if(temp_hoststatus->last_check >= (current_time - 3600)) passive_host_checks_1hour++; if(temp_hoststatus->last_check >= program_start) passive_host_checks_start++; if(temp_hoststatus->last_check != (time_t)0) passive_host_checks_ever++; } } printf("
\n"); printf("
Program-Wide Performance Information
\n"); printf("\n"); /***** ACTIVE SERVICE CHECKS *****/ printf("\n"); printf("\n"); printf("\n"); printf("\n"); /***** PASSIVE SERVICE CHECKS *****/ printf("\n"); printf("\n"); printf("\n"); printf("\n"); /***** ACTIVE HOST CHECKS *****/ printf("\n"); printf("\n"); printf("\n"); printf("\n"); /***** PASSIVE HOST CHECKS *****/ printf("\n"); printf("\n"); printf("\n"); printf("\n"); /***** CHECK STATS *****/ printf("\n"); printf("\n"); printf("\n"); printf("\n"); /***** BUFFER STATS *****/ printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("
Services Actively Checked:
\n"); /* fake this so we don't divide by zero for just showing the table */ if(total_active_service_checks == 0) total_active_service_checks = 1; printf("\n"); printf("\n"); printf("
\n"); printf("\n"); printf("\n"); printf("", active_service_checks_1min, (double)(((double)active_service_checks_1min * 100.0) / (double)total_active_service_checks)); printf("", active_service_checks_5min, (double)(((double)active_service_checks_5min * 100.0) / (double)total_active_service_checks)); printf("", active_service_checks_15min, (double)(((double)active_service_checks_15min * 100.0) / (double)total_active_service_checks)); printf("", active_service_checks_1hour, (double)(((double)active_service_checks_1hour * 100.0) / (double)total_active_service_checks)); printf("", active_service_checks_start, (double)(((double)active_service_checks_start * 100.0) / (double)total_active_service_checks)); printf("
Time FrameServices Checked
<= 1 minute:%d (%.1f%%)
<= 5 minutes:%d (%.1f%%)
<= 15 minutes:%d (%.1f%%)
<= 1 hour:%d (%.1f%%)
Since program start:  %d (%.1f%%)
\n"); printf("
\n"); printf("
\n"); printf("\n"); printf("\n"); printf("
\n"); printf("\n"); printf("\n"); printf("\n", min_service_execution_time, max_service_execution_time, (double)((double)total_service_execution_time / (double)total_active_service_checks)); printf("\n", min_service_latency, max_service_latency, (double)((double)total_service_latency / (double)total_active_service_checks)); printf("\n", min_service_percent_change_a, max_service_percent_change_a, (double)((double)total_service_percent_change_a / (double)total_active_service_checks)); printf("
MetricMin.Max.Average
Check Execution Time:  %.2f sec%.2f sec%.3f sec
Check Latency:%.2f sec%.2f sec%.3f sec
Percent State Change:%.2f%%%.2f%%%.2f%%
\n"); printf("
\n"); printf("
Services Passively Checked:
\n"); /* fake this so we don't divide by zero for just showing the table */ if(total_passive_service_checks == 0) total_passive_service_checks = 1; printf("\n"); printf("\n"); printf("
\n"); printf("\n"); printf("\n"); printf("", passive_service_checks_1min, (double)(((double)passive_service_checks_1min * 100.0) / (double)total_passive_service_checks)); printf("", passive_service_checks_5min, (double)(((double)passive_service_checks_5min * 100.0) / (double)total_passive_service_checks)); printf("", passive_service_checks_15min, (double)(((double)passive_service_checks_15min * 100.0) / (double)total_passive_service_checks)); printf("", passive_service_checks_1hour, (double)(((double)passive_service_checks_1hour * 100.0) / (double)total_passive_service_checks)); printf("", passive_service_checks_start, (double)(((double)passive_service_checks_start * 100.0) / (double)total_passive_service_checks)); printf("
Time FrameServices Checked
<= 1 minute:%d (%.1f%%)
<= 5 minutes:%d (%.1f%%)
<= 15 minutes:%d (%.1f%%)
<= 1 hour:%d (%.1f%%)
Since program start:  %d (%.1f%%)
\n"); printf("
\n"); printf("
\n"); printf("\n"); printf("\n"); printf("
\n"); printf("\n"); printf("\n"); printf("\n", min_service_percent_change_b, max_service_percent_change_b, (double)((double)total_service_percent_change_b / (double)total_passive_service_checks)); printf("
MetricMin.Max.Average
Percent State Change:  %.2f%%%.2f%%%.2f%%
\n"); printf("
\n"); printf("
Hosts Actively Checked:
\n"); /* fake this so we don't divide by zero for just showing the table */ if(total_active_host_checks == 0) total_active_host_checks = 1; printf("\n"); printf("\n"); printf("
\n"); printf("\n"); printf("\n"); printf("", active_host_checks_1min, (double)(((double)active_host_checks_1min * 100.0) / (double)total_active_host_checks)); printf("", active_host_checks_5min, (double)(((double)active_host_checks_5min * 100.0) / (double)total_active_host_checks)); printf("", active_host_checks_15min, (double)(((double)active_host_checks_15min * 100.0) / (double)total_active_host_checks)); printf("", active_host_checks_1hour, (double)(((double)active_host_checks_1hour * 100.0) / (double)total_active_host_checks)); printf("", active_host_checks_start, (double)(((double)active_host_checks_start * 100.0) / (double)total_active_host_checks)); printf("
Time FrameHosts Checked
<= 1 minute:%d (%.1f%%)
<= 5 minutes:%d (%.1f%%)
<= 15 minutes:%d (%.1f%%)
<= 1 hour:%d (%.1f%%)
Since program start:  %d (%.1f%%)
\n"); printf("
\n"); printf("
\n"); printf("\n"); printf("\n"); printf("
\n"); printf("\n"); printf("\n"); printf("\n", min_host_execution_time, max_host_execution_time, (double)((double)total_host_execution_time / (double)total_active_host_checks)); printf("\n", min_host_latency, max_host_latency, (double)((double)total_host_latency / (double)total_active_host_checks)); printf("\n", min_host_percent_change_a, max_host_percent_change_a, (double)((double)total_host_percent_change_a / (double)total_active_host_checks)); printf("
MetricMin.Max.Average
Check Execution Time:  %.2f sec%.2f sec%.3f sec
Check Latency:%.2f sec%.2f sec%.3f sec
Percent State Change:%.2f%%%.2f%%%.2f%%
\n"); printf("
\n"); printf("
Hosts Passively Checked:
\n"); /* fake this so we don't divide by zero for just showing the table */ if(total_passive_host_checks == 0) total_passive_host_checks = 1; printf("\n"); printf("\n"); printf("
\n"); printf("\n"); printf("\n"); printf("", passive_host_checks_1min, (double)(((double)passive_host_checks_1min * 100.0) / (double)total_passive_host_checks)); printf("", passive_host_checks_5min, (double)(((double)passive_host_checks_5min * 100.0) / (double)total_passive_host_checks)); printf("", passive_host_checks_15min, (double)(((double)passive_host_checks_15min * 100.0) / (double)total_passive_host_checks)); printf("", passive_host_checks_1hour, (double)(((double)passive_host_checks_1hour * 100.0) / (double)total_passive_host_checks)); printf("", passive_host_checks_start, (double)(((double)passive_host_checks_start * 100.0) / (double)total_passive_host_checks)); printf("
Time FrameHosts Checked
<= 1 minute:%d (%.1f%%)
<= 5 minutes:%d (%.1f%%)
<= 15 minutes:%d (%.1f%%)
<= 1 hour:%d (%.1f%%)
Since program start:  %d (%.1f%%)
\n"); printf("
\n"); printf("
\n"); printf("\n"); printf("\n"); printf("
\n"); printf("\n"); printf("\n"); printf("\n", min_host_percent_change_b, max_host_percent_change_b, (double)((double)total_host_percent_change_b / (double)total_passive_host_checks)); printf("
MetricMin.Max.Average
Percent State Change:  %.2f%%%.2f%%%.2f%%
\n"); printf("
\n"); printf("
Check Statistics:
\n"); printf("\n"); printf("\n"); printf("
\n"); printf("\n"); printf("\n"); printf("", program_stats[ACTIVE_SCHEDULED_HOST_CHECK_STATS][0], program_stats[ACTIVE_SCHEDULED_HOST_CHECK_STATS][1], program_stats[ACTIVE_SCHEDULED_HOST_CHECK_STATS][2]); printf("", program_stats[ACTIVE_ONDEMAND_HOST_CHECK_STATS][0], program_stats[ACTIVE_ONDEMAND_HOST_CHECK_STATS][1], program_stats[ACTIVE_ONDEMAND_HOST_CHECK_STATS][2]); printf("", program_stats[PARALLEL_HOST_CHECK_STATS][0], program_stats[PARALLEL_HOST_CHECK_STATS][1], program_stats[PARALLEL_HOST_CHECK_STATS][2]); printf("", program_stats[SERIAL_HOST_CHECK_STATS][0], program_stats[SERIAL_HOST_CHECK_STATS][1], program_stats[SERIAL_HOST_CHECK_STATS][2]); printf("", program_stats[ACTIVE_CACHED_HOST_CHECK_STATS][0], program_stats[ACTIVE_CACHED_HOST_CHECK_STATS][1], program_stats[ACTIVE_CACHED_HOST_CHECK_STATS][2]); printf("", program_stats[PASSIVE_HOST_CHECK_STATS][0], program_stats[PASSIVE_HOST_CHECK_STATS][1], program_stats[PASSIVE_HOST_CHECK_STATS][2]); printf("", program_stats[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS][0], program_stats[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS][1], program_stats[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS][2]); printf("", program_stats[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS][0], program_stats[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS][1], program_stats[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS][2]); printf("", program_stats[ACTIVE_CACHED_SERVICE_CHECK_STATS][0], program_stats[ACTIVE_CACHED_SERVICE_CHECK_STATS][1], program_stats[ACTIVE_CACHED_SERVICE_CHECK_STATS][2]); printf("", program_stats[PASSIVE_SERVICE_CHECK_STATS][0], program_stats[PASSIVE_SERVICE_CHECK_STATS][1], program_stats[PASSIVE_SERVICE_CHECK_STATS][2]); printf("", program_stats[EXTERNAL_COMMAND_STATS][0], program_stats[EXTERNAL_COMMAND_STATS][1], program_stats[EXTERNAL_COMMAND_STATS][2]); printf("
TypeLast 1 MinLast 5 MinLast 15 Min
Active Scheduled Host Checks%d%d%d
Active On-Demand Host Checks%d%d%d
Parallel Host Checks%d%d%d
Serial Host Checks%d%d%d
Cached Host Checks%d%d%d
Passive Host Checks%d%d%d
Active Scheduled Service Checks%d%d%d
Active On-Demand Service Checks%d%d%d
Cached Service Checks%d%d%d
Passive Service Checks%d%d%d
External Commands%d%d%d
\n"); printf("
\n"); printf("
Buffer Usage:
\n"); printf("\n"); printf("\n"); printf("
\n"); printf("\n"); printf("\n"); printf("", buffer_stats[0][1], buffer_stats[0][2], buffer_stats[0][0]); printf("
TypeIn UseMax UsedTotal Available
External Commands %d%d%d
\n"); printf("
\n"); printf("
\n"); printf("
\n"); return; } void display_comments(int type) { host *temp_host = NULL; service *temp_service = NULL; int total_comments = 0; int display_comment = FALSE; const char *bg_class = ""; int odd = 1; char date_time[MAX_DATETIME_LENGTH]; nagios_comment *temp_comment; scheduled_downtime *temp_downtime; char *comment_type; char expire_time[MAX_DATETIME_LENGTH]; /* find the host or service */ if(type == HOST_COMMENT) { temp_host = find_host(host_name); if(temp_host == NULL) return; } else { temp_service = find_service(host_name, service_desc); if(temp_service == NULL) return; } printf("\n"); printf("
%s Comments
\n", (type == HOST_COMMENT) ? "Host" : "Service"); if(is_authorized_for_read_only(¤t_authdata)==FALSE){ printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("
", url_images_path, COMMENT_ICON); if(type == HOST_COMMENT) printf("", COMMAND_CGI, CMD_ADD_HOST_COMMENT, url_encode(host_name)); else { printf("", url_encode(service_desc)); } printf("Add a new comment", url_images_path, DELETE_ICON); if(type == HOST_COMMENT) printf("", COMMAND_CGI, CMD_DEL_ALL_HOST_COMMENTS, url_encode(host_name)); else { printf("", url_encode(service_desc)); } printf("Delete all comments
\n"); } printf("
\n"); printf("\n"); if(is_authorized_for_read_only(¤t_authdata)==FALSE) printf("\n"); else printf("\n"); /* check all the comments to see if they apply to this host or service */ /* Comments are displayed in the order they are read from the status.dat file */ for(temp_comment = get_first_comment_by_host(host_name); temp_comment != NULL; temp_comment = get_next_comment_by_host(host_name, temp_comment)) { display_comment = FALSE; if(type == HOST_COMMENT && temp_comment->comment_type == HOST_COMMENT) display_comment = TRUE; else if(type == SERVICE_COMMENT && temp_comment->comment_type == SERVICE_COMMENT && !strcmp(temp_comment->service_description, service_desc)) display_comment = TRUE; if(display_comment == TRUE) { if(odd) { odd = 0; bg_class = "commentOdd"; } else { odd = 1; bg_class = "commentEven"; } switch(temp_comment->entry_type) { case USER_COMMENT: comment_type = "User"; break; case DOWNTIME_COMMENT: comment_type = "Scheduled Downtime"; break; case FLAPPING_COMMENT: comment_type = "Flap Detection"; break; case ACKNOWLEDGEMENT_COMMENT: comment_type = "Acknowledgement"; break; default: comment_type = "?"; } if (temp_comment->entry_type == DOWNTIME_COMMENT) { for(temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = temp_downtime->next) { if (temp_downtime->comment_id == temp_comment->comment_id) break; } } else temp_downtime = NULL; get_time_string(&temp_comment->entry_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); get_time_string(&temp_comment->expire_time, expire_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("", bg_class); printf("", bg_class, date_time, bg_class, temp_comment->author); printf("", bg_class, temp_comment->comment_id, bg_class, (temp_comment->persistent) ? "Yes" : "No", bg_class, comment_type, bg_class, (temp_comment->expires == TRUE) ? expire_time : "N/A"); if(is_authorized_for_read_only(¤t_authdata)==FALSE) printf("", COMMAND_CGI, (type == HOST_COMMENT) ? CMD_DEL_HOST_COMMENT : CMD_DEL_SVC_COMMENT, temp_comment->comment_id, url_images_path, DELETE_ICON); printf("\n"); total_comments++; } } /* see if this host or service has any comments associated with it */ if(total_comments == 0) printf("", (type == HOST_COMMENT) ? 9 : 10, (type == HOST_COMMENT) ? "host" : "service"); printf("
Entry TimeAuthorCommentComment IDPersistentTypeExpiresActions
Entry TimeAuthorCommentComment IDPersistentTypeExpires
%s%s%s", bg_class, temp_comment->comment_data); if (temp_downtime) printf("
%s", temp_downtime->comment); printf("
%lu%s%s%sDelete This Comment
This %s has no comments associated with it
\n"); return; } /* shows all service and host scheduled downtime */ void show_all_downtime(void) { int total_downtime = 0; const char *bg_class = ""; int odd = 0; char date_time[MAX_DATETIME_LENGTH]; scheduled_downtime *temp_downtime; host *temp_host; service *temp_service; int days; int hours; int minutes; int seconds; printf("
\n"); printf("
Host Downtime | Service Downtime ]
\n"); printf("
\n"); printf("\n"); printf("
Scheduled Host Downtime
\n"); printf("
 ", url_images_path, DOWNTIME_ICON); printf("", COMMAND_CGI, CMD_SCHEDULE_HOST_DOWNTIME); printf("Schedule host downtime
\n"); printf("
\n"); printf("
\n"); printf("\n"); printf("\n"); /* display all the host downtime */ for(temp_downtime = scheduled_downtime_list, total_downtime = 0; temp_downtime != NULL; temp_downtime = temp_downtime->next) { if(temp_downtime->type != HOST_DOWNTIME) continue; temp_host = find_host(temp_downtime->host_name); /* make sure the user has rights to view host information */ if(is_authorized_for_host(temp_host, ¤t_authdata) == FALSE) continue; total_downtime++; if(odd) { odd = 0; bg_class = "downtimeOdd"; } else { odd = 1; bg_class = "downtimeEven"; } printf("", bg_class); printf("", bg_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_downtime->host_name), temp_downtime->host_name); get_time_string(&temp_downtime->entry_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("", bg_class, date_time); printf("", bg_class, (temp_downtime->author == NULL) ? "N/A" : temp_downtime->author); printf("", bg_class, (temp_downtime->comment == NULL) ? "N/A" : temp_downtime->comment); get_time_string(&temp_downtime->start_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("", bg_class, date_time); get_time_string(&temp_downtime->end_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("", bg_class, date_time); printf("", bg_class, (temp_downtime->fixed == TRUE) ? "Fixed" : "Flexible"); get_time_breakdown(temp_downtime->duration, &days, &hours, &minutes, &seconds); printf("", bg_class, days, hours, minutes, seconds); printf("", bg_class, temp_downtime->downtime_id); printf("\n"); printf("", COMMAND_CGI, CMD_DEL_HOST_DOWNTIME, temp_downtime->downtime_id, url_images_path, DELETE_ICON); printf("\n"); } if(total_downtime == 0) printf(""); printf("
Host NameEntry TimeAuthorCommentStart TimeEnd TimeTypeDurationDowntime IDTrigger IDActions
%s%s%s%s%s%s%s%dd %dh %dm %ds%lu", bg_class); if(temp_downtime->triggered_by == 0) printf("N/A"); else printf("%lu", temp_downtime->triggered_by); printf("Delete/Cancel This Scheduled Downtime Entry
There are no hosts with scheduled downtime
\n"); printf("
\n"); printf("


\n"); printf("\n"); printf("
Scheduled Service Downtime
\n"); printf("
 ", url_images_path, DOWNTIME_ICON); printf("", COMMAND_CGI, CMD_SCHEDULE_SVC_DOWNTIME); printf("Schedule service downtime
\n"); printf("
\n"); printf("
\n"); printf("\n"); printf("\n"); /* display all the service downtime */ for(temp_downtime = scheduled_downtime_list, total_downtime = 0; temp_downtime != NULL; temp_downtime = temp_downtime->next) { if(temp_downtime->type != SERVICE_DOWNTIME) continue; temp_service = find_service(temp_downtime->host_name, temp_downtime->service_description); /* make sure the user has rights to view service information */ if(is_authorized_for_service(temp_service, ¤t_authdata) == FALSE) continue; total_downtime++; if(odd) { odd = 0; bg_class = "downtimeOdd"; } else { odd = 1; bg_class = "downtimeEven"; } printf("", bg_class); printf("", bg_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_downtime->host_name), temp_downtime->host_name); printf("", url_encode(temp_downtime->service_description), temp_downtime->service_description); get_time_string(&temp_downtime->entry_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("", bg_class, date_time); printf("", bg_class, (temp_downtime->author == NULL) ? "N/A" : temp_downtime->author); printf("", bg_class, (temp_downtime->comment == NULL) ? "N/A" : temp_downtime->comment); get_time_string(&temp_downtime->start_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("", bg_class, date_time); get_time_string(&temp_downtime->end_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("", bg_class, date_time); printf("", bg_class, (temp_downtime->fixed == TRUE) ? "Fixed" : "Flexible"); get_time_breakdown(temp_downtime->duration, &days, &hours, &minutes, &seconds); printf("", bg_class, days, hours, minutes, seconds); printf("", bg_class, temp_downtime->downtime_id); printf("\n"); printf("", COMMAND_CGI, CMD_DEL_SVC_DOWNTIME, temp_downtime->downtime_id, url_images_path, DELETE_ICON); printf("\n"); } if(total_downtime == 0) printf(""); printf("
Host NameServiceEntry TimeAuthorCommentStart TimeEnd TimeTypeDurationDowntime IDTrigger IDActions
%s%s%s%s%s%s%s%s%dd %dh %dm %ds%lu", bg_class); if(temp_downtime->triggered_by == 0) printf("N/A"); else printf("%lu", temp_downtime->triggered_by); printf("Delete/Cancel This Scheduled Downtime Entry
There are no services with scheduled downtime
\n"); printf("
\n"); return; } /* shows check scheduling queue */ void show_scheduling_queue(void) { sortdata *temp_sortdata; servicestatus *temp_svcstatus = NULL; hoststatus *temp_hststatus = NULL; char date_time[MAX_DATETIME_LENGTH]; char temp_url[MAX_INPUT_BUFFER]; int odd = 0; const char *bgclass = ""; /* make sure the user has rights to view system information */ if(is_authorized_for_system_information(¤t_authdata) == FALSE) { printf("

It appears as though you do not have permission to view process information...

\n"); printf("

If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI
"); printf("and check the authorization options in your CGI configuration file.

\n"); return; } /* sort hosts and services */ sort_data(sort_type, sort_option); printf("
Entries sorted by "); if(sort_option == SORT_HOSTNAME) printf("host name"); else if(sort_option == SORT_SERVICENAME) printf("service name"); else if(sort_option == SORT_SERVICESTATUS) printf("service status"); else if(sort_option == SORT_LASTCHECKTIME) printf("last check time"); else if(sort_option == SORT_NEXTCHECKTIME) printf("next check time"); printf(" (%s)\n", (sort_type == SORT_ASCENDING) ? "ascending" : "descending"); printf("
\n"); printf("

\n"); printf("

\n"); printf("\n"); printf(""); snprintf(temp_url, sizeof(temp_url) - 1, "%s?type=%d", EXTINFO_CGI, DISPLAY_SCHEDULING_QUEUE); temp_url[sizeof(temp_url) - 1] = '\x0'; printf("", temp_url, SORT_ASCENDING, SORT_HOSTNAME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_HOSTNAME, url_images_path, DOWN_ARROW_ICON); printf("", temp_url, SORT_ASCENDING, SORT_SERVICENAME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_SERVICENAME, url_images_path, DOWN_ARROW_ICON); printf("", temp_url, SORT_ASCENDING, SORT_LASTCHECKTIME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_LASTCHECKTIME, url_images_path, DOWN_ARROW_ICON); printf("", temp_url, SORT_ASCENDING, SORT_NEXTCHECKTIME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_NEXTCHECKTIME, url_images_path, DOWN_ARROW_ICON); printf("\n"); /* display all services and hosts */ for(temp_sortdata = sortdata_list; temp_sortdata != NULL; temp_sortdata = temp_sortdata->next) { /* skip hosts and services that shouldn't be scheduled */ if(temp_sortdata->is_service == TRUE) { temp_svcstatus = temp_sortdata->svcstatus; if(temp_svcstatus->should_be_scheduled == FALSE) { /* passive-only checks should appear if they're being forced */ if(!(temp_svcstatus->checks_enabled == FALSE && temp_svcstatus->next_check != (time_t)0L && (temp_svcstatus->check_options & CHECK_OPTION_FORCE_EXECUTION))) continue; } } else { temp_hststatus = temp_sortdata->hststatus; if(temp_hststatus->should_be_scheduled == FALSE) { /* passive-only checks should appear if they're being forced */ if(!(temp_hststatus->checks_enabled == FALSE && temp_hststatus->next_check != (time_t)0L && (temp_hststatus->check_options & CHECK_OPTION_FORCE_EXECUTION))) continue; } } if(odd) { odd = 0; bgclass = "Even"; } else { odd = 1; bgclass = "Odd"; } printf("", bgclass); /* get the service status */ if(temp_sortdata->is_service == TRUE) { printf("", bgclass, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_svcstatus->host_name), temp_svcstatus->host_name); printf("", url_encode(temp_svcstatus->description), temp_svcstatus->description); get_time_string(&temp_svcstatus->last_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("", bgclass, (temp_svcstatus->last_check == (time_t)0) ? "N/A" : date_time); get_time_string(&temp_svcstatus->next_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("", bgclass, (temp_svcstatus->next_check == (time_t)0) ? "N/A" : date_time); printf(""); printf("", (temp_svcstatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED", (temp_svcstatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED"); printf("\n"); } /* get the host status */ else { printf("", bgclass, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_hststatus->host_name), temp_hststatus->host_name); printf("", bgclass); get_time_string(&temp_hststatus->last_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("", bgclass, (temp_hststatus->last_check == (time_t)0) ? "N/A" : date_time); get_time_string(&temp_hststatus->next_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("", bgclass, (temp_hststatus->next_check == (time_t)0) ? "N/A" : date_time); printf(""); printf("", (temp_hststatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED", (temp_hststatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED"); printf("\n"); } printf("\n"); } printf("
Host Sort by host name (ascending)Sort by host name (descending)Service Sort by service name (ascending)Sort by service name (descending)Last Check Sort by last check time (ascending)Sort by last check time (descending)Next Check Sort by next check time (ascending)Sort by next check time (descending)TypeActive ChecksActions
%s%s%s%s", bgclass); if(temp_svcstatus->check_options == CHECK_OPTION_NONE) printf("Normal "); else { if(temp_svcstatus->check_options & CHECK_OPTION_FORCE_EXECUTION) printf("Forced "); if(temp_svcstatus->check_options & CHECK_OPTION_FRESHNESS_CHECK) printf("Freshness "); if(temp_svcstatus->check_options & CHECK_OPTION_ORPHAN_CHECK) printf("Orphan "); } printf("%s", bgclass); if(temp_svcstatus->checks_enabled == TRUE) { printf("Disable Active Checks Of This Service\n", url_encode(temp_svcstatus->description), url_images_path, DISABLED_ICON); } else { printf("Enable Active Checks Of This Service\n", url_encode(temp_svcstatus->description), url_images_path, ENABLED_ICON); } printf("Re-schedule This Service Check\n", url_encode(temp_svcstatus->description), (temp_svcstatus->checks_enabled == TRUE) ? "&force_check" : "", url_images_path, DELAY_ICON); printf("%s %s%s", bgclass); if(temp_hststatus->check_options == CHECK_OPTION_NONE) printf("Normal "); else { if(temp_hststatus->check_options & CHECK_OPTION_FORCE_EXECUTION) printf("Forced "); if(temp_hststatus->check_options & CHECK_OPTION_FRESHNESS_CHECK) printf("Freshness "); if(temp_hststatus->check_options & CHECK_OPTION_ORPHAN_CHECK) printf("Orphan "); } printf("%s", bgclass); if(temp_hststatus->checks_enabled == TRUE) { printf("Disable Active Checks Of This Host\n", url_images_path, DISABLED_ICON); } else { printf("Enable Active Checks Of This Host\n", url_images_path, ENABLED_ICON); } printf("Re-schedule This Host Check\n", url_images_path, DELAY_ICON); printf("
\n"); printf("
\n"); printf("

\n"); /* free memory allocated to sorted data list */ free_sortdata_list(); return; } /* sorts host and service data */ int sort_data(int s_type, int s_option) { sortdata *new_sortdata; sortdata *last_sortdata; sortdata *temp_sortdata; servicestatus *temp_svcstatus; hoststatus *temp_hststatus; if(s_type == SORT_NONE) return ERROR; /* sort all service status entries */ for(temp_svcstatus = servicestatus_list; temp_svcstatus != NULL; temp_svcstatus = temp_svcstatus->next) { /* allocate memory for a new sort structure */ new_sortdata = (sortdata *)malloc(sizeof(sortdata)); if(new_sortdata == NULL) return ERROR; new_sortdata->is_service = TRUE; new_sortdata->svcstatus = temp_svcstatus; new_sortdata->hststatus = NULL; last_sortdata = sortdata_list; for(temp_sortdata = sortdata_list; temp_sortdata != NULL; temp_sortdata = temp_sortdata->next) { if(compare_sortdata_entries(s_type, s_option, new_sortdata, temp_sortdata) == TRUE) { new_sortdata->next = temp_sortdata; if(temp_sortdata == sortdata_list) sortdata_list = new_sortdata; else last_sortdata->next = new_sortdata; break; } else last_sortdata = temp_sortdata; } if(sortdata_list == NULL) { new_sortdata->next = NULL; sortdata_list = new_sortdata; } else if(temp_sortdata == NULL) { new_sortdata->next = NULL; last_sortdata->next = new_sortdata; } } /* sort all host status entries */ for(temp_hststatus = hoststatus_list; temp_hststatus != NULL; temp_hststatus = temp_hststatus->next) { /* allocate memory for a new sort structure */ new_sortdata = (sortdata *)malloc(sizeof(sortdata)); if(new_sortdata == NULL) return ERROR; new_sortdata->is_service = FALSE; new_sortdata->svcstatus = NULL; new_sortdata->hststatus = temp_hststatus; last_sortdata = sortdata_list; for(temp_sortdata = sortdata_list; temp_sortdata != NULL; temp_sortdata = temp_sortdata->next) { if(compare_sortdata_entries(s_type, s_option, new_sortdata, temp_sortdata) == TRUE) { new_sortdata->next = temp_sortdata; if(temp_sortdata == sortdata_list) sortdata_list = new_sortdata; else last_sortdata->next = new_sortdata; break; } else last_sortdata = temp_sortdata; } if(sortdata_list == NULL) { new_sortdata->next = NULL; sortdata_list = new_sortdata; } else if(temp_sortdata == NULL) { new_sortdata->next = NULL; last_sortdata->next = new_sortdata; } } return OK; } int compare_sortdata_entries(int s_type, int s_option, sortdata *new_sortdata, sortdata *temp_sortdata) { hoststatus *temp_hststatus = NULL; servicestatus *temp_svcstatus = NULL; time_t last_check[2]; time_t next_check[2]; int current_attempt[2]; int status[2]; char *hname[2]; char *service_description[2]; if(new_sortdata->is_service == TRUE) { temp_svcstatus = new_sortdata->svcstatus; last_check[0] = temp_svcstatus->last_check; next_check[0] = temp_svcstatus->next_check; status[0] = temp_svcstatus->status; hname[0] = temp_svcstatus->host_name; service_description[0] = temp_svcstatus->description; current_attempt[0] = temp_svcstatus->current_attempt; } else { temp_hststatus = new_sortdata->hststatus; last_check[0] = temp_hststatus->last_check; next_check[0] = temp_hststatus->next_check; status[0] = temp_hststatus->status; hname[0] = temp_hststatus->host_name; service_description[0] = ""; current_attempt[0] = temp_hststatus->current_attempt; } if(temp_sortdata->is_service == TRUE) { temp_svcstatus = temp_sortdata->svcstatus; last_check[1] = temp_svcstatus->last_check; next_check[1] = temp_svcstatus->next_check; status[1] = temp_svcstatus->status; hname[1] = temp_svcstatus->host_name; service_description[1] = temp_svcstatus->description; current_attempt[1] = temp_svcstatus->current_attempt; } else { temp_hststatus = temp_sortdata->hststatus; last_check[1] = temp_hststatus->last_check; next_check[1] = temp_hststatus->next_check; status[1] = temp_hststatus->status; hname[1] = temp_hststatus->host_name; service_description[1] = ""; current_attempt[1] = temp_hststatus->current_attempt; } if(s_type == SORT_ASCENDING) { if(s_option == SORT_LASTCHECKTIME) { if(last_check[0] <= last_check[1]) return TRUE; else return FALSE; } if(s_option == SORT_NEXTCHECKTIME) { if(next_check[0] <= next_check[1]) return TRUE; else return FALSE; } else if(s_option == SORT_CURRENTATTEMPT) { if(current_attempt[0] <= current_attempt[1]) return TRUE; else return FALSE; } else if(s_option == SORT_SERVICESTATUS) { if(status[0] <= status[1]) return TRUE; else return FALSE; } else if(s_option == SORT_HOSTNAME) { if(strcasecmp(hname[0], hname[1]) < 0) return TRUE; else return FALSE; } else if(s_option == SORT_SERVICENAME) { if(strcasecmp(service_description[0], service_description[1]) < 0) return TRUE; else return FALSE; } } else { if(s_option == SORT_LASTCHECKTIME) { if(last_check[0] > last_check[1]) return TRUE; else return FALSE; } if(s_option == SORT_NEXTCHECKTIME) { if(next_check[0] > next_check[1]) return TRUE; else return FALSE; } else if(s_option == SORT_CURRENTATTEMPT) { if(current_attempt[0] > current_attempt[1]) return TRUE; else return FALSE; } else if(s_option == SORT_SERVICESTATUS) { if(status[0] > status[1]) return TRUE; else return FALSE; } else if(s_option == SORT_HOSTNAME) { if(strcasecmp(hname[0], hname[1]) > 0) return TRUE; else return FALSE; } else if(s_option == SORT_SERVICENAME) { if(strcasecmp(service_description[0], service_description[1]) > 0) return TRUE; else return FALSE; } } return TRUE; } /* free all memory allocated to the sortdata structures */ void free_sortdata_list(void) { sortdata *this_sortdata; sortdata *next_sortdata; /* free memory for the sortdata list */ for(this_sortdata = sortdata_list; this_sortdata != NULL; this_sortdata = next_sortdata) { next_sortdata = this_sortdata->next; free(this_sortdata); } return; }