/************************************************************************** * * EXTINFO.C - NetSaint Extended Information CGI * * Copyright (c) 1999-2002 Ethan Galstad (netsaint@netsaint.org) * Last Modified: 01-10-2002 * * License: * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * 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 "../common/config.h" #include "../common/locations.h" #include "../common/common.h" #include "../common/objects.h" #include "../common/comments.h" #include "../common/statusdata.h" #include "cgiutils.h" #include "getcgi.h" #include "auth.h" #include "edata.h" extern char netsaint_check_command[MAX_INPUT_BUFFER]; extern char netsaint_process_info[MAX_INPUT_BUFFER]; extern int netsaint_process_state; extern int refresh_rate; extern time_t program_start; extern int netsaint_pid; extern int daemon_mode; extern int program_mode; extern time_t last_mode_change; extern time_t last_command_check; extern time_t last_log_rotation; extern int execute_service_checks; extern int accept_passive_service_checks; extern int enable_event_handlers; extern int obsess_over_services; extern int enable_flap_detection; 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 log_file[MAX_FILENAME_LENGTH]; extern comment *comment_list; #define MAX_MESSAGE_BUFFER 4096 #define HEALTH_WARNING_PERCENTAGE 85 #define HEALTH_CRITICAL_PERCENTAGE 75 void document_header(int); void document_footer(void); int process_cgivars(void); authdata current_authdata; char *host_name=""; char *hostgroup_name=""; char *service_desc=""; int display_type=DISPLAY_PROCESS_INFO; 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 display_comments(int); extern hoststatus *hoststatus_list; extern servicestatus *servicestatus_list; int embedded=FALSE; int display_header=TRUE; int main(void){ int result=OK; char temp_buffer[MAX_INPUT_BUFFER]; hostextinfo *temp_hostextinfo=NULL; serviceextinfo *temp_serviceextinfo=NULL; host *temp_host=NULL; hostgroup *temp_hostgroup=NULL; /* get the arguments passed in the URL */ process_cgivars(); /* reset internal variables */ reset_cgi_vars(); /* read the CGI configuration file */ result=read_cgi_config_file(DEFAULT_CGI_CONFIG_FILE); if(result==ERROR){ document_header(FALSE); printf("

Error: Could not open CGI configuration file '%s' for reading!

\n",DEFAULT_CGI_CONFIG_FILE); document_footer(); return ERROR; } document_header(TRUE); /* read the main configuration file */ result=read_main_config_file(main_config_file); if(result==ERROR){ printf("

Error: Could not open main configuration file '%s' for reading!

\n",main_config_file); document_footer(); return ERROR; } /* read all object configuration data */ result=read_all_object_configuration_data(main_config_file,READ_HOSTGROUPS|READ_CONTACTGROUPS|READ_HOSTS|READ_SERVICES); if(result==ERROR){ printf("

Error: Could not read some or all object configuration data!

\n"); document_footer(); return ERROR; } /* read all status data */ result=read_all_status_data(DEFAULT_CGI_CONFIG_FILE,READ_PROGRAM_STATUS|READ_HOST_STATUS|READ_SERVICE_STATUS); if(result==ERROR){ printf("

Error: Could not read host and service status information!

\n"); document_footer(); free_memory(); return ERROR; } /* read in extended host information */ read_extended_object_config_data(DEFAULT_CGI_CONFIG_FILE,READ_EXTENDED_HOST_INFO|READ_EXTENDED_SERVICE_INFO); /* get authentication information */ get_authentication_information(¤t_authdata); 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,"Information For Host %s",host_name); else if(display_type==DISPLAY_SERVICE_INFO) snprintf(temp_buffer,sizeof(temp_buffer)-1,"Information For Service %s On Host %s",service_desc,host_name); 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,"Information For Hostgroup %s",hostgroup_name); else snprintf(temp_buffer,sizeof(temp_buffer)-1,"NetSaint 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,NULL); /* find the hostgroup */ else if(display_type==DISPLAY_HOSTGROUP_INFO) temp_hostgroup=find_hostgroup(hostgroup_name,NULL); if(((display_type==DISPLAY_HOST_INFO || display_type==DISPLAY_SERVICE_INFO) && temp_host!=NULL) || (display_type==DISPLAY_HOSTGROUP_INFO && temp_hostgroup!=NULL)){ printf("\n"); printf("\n"); printf("\n"); } printf("\n"); if(((display_type==DISPLAY_HOST_INFO || display_type==DISPLAY_SERVICE_INFO) && temp_host!=NULL) || (display_type==DISPLAY_HOSTGROUP_INFO && temp_hostgroup!=NULL)){ if(display_type==DISPLAY_SERVICE_INFO) printf("
%s
on
\n",service_desc); if(display_type==DISPLAY_SERVICE_INFO || display_type==DISPLAY_HOST_INFO){ printf("
%s
\n",temp_host->alias); printf("
%s
\n",temp_host->address); } if(display_type==DISPLAY_HOSTGROUP_INFO) printf("
%s
\n",temp_hostgroup->alias); if(display_type==DISPLAY_SERVICE_INFO){ temp_serviceextinfo=find_serviceextinfo(host_name,service_desc); if(temp_serviceextinfo!=NULL){ if(temp_serviceextinfo->icon_image!=NULL) printf("%s
",url_logo_images_path,temp_serviceextinfo->icon_image,(temp_serviceextinfo->icon_image_alt==NULL)?"":temp_serviceextinfo->icon_image_alt); if(temp_serviceextinfo->icon_image_alt!=NULL) printf("( %s )\n",temp_serviceextinfo->icon_image_alt); } } if(display_type==DISPLAY_HOST_INFO || temp_serviceextinfo==NULL){ temp_hostextinfo=find_hostextinfo(host_name); if(temp_hostextinfo!=NULL){ if(temp_hostextinfo->icon_image!=NULL) printf("%s
",url_logo_images_path,temp_hostextinfo->icon_image,(temp_hostextinfo->icon_image_alt==NULL)?"":temp_hostextinfo->icon_image_alt); if(temp_hostextinfo->icon_image_alt!=NULL) printf("( %s )\n",temp_hostextinfo->icon_image_alt); } } } printf("
\n"); if(display_type==DISPLAY_HOST_INFO){ if(temp_hostextinfo!=NULL && temp_hostextinfo->notes_url!=NULL && strcmp(temp_hostextinfo->notes_url,"")){ printf("View Additional Notes For This Host\n",url_images_path,NOTES_ICON); printf("
There Are Additional
Notes For This Host...
\n"); } } else if(display_type==DISPLAY_SERVICE_INFO){ if(temp_serviceextinfo!=NULL && temp_serviceextinfo->notes_url!=NULL && strcmp(temp_serviceextinfo->notes_url,"")){ printf("View Additional Notes For This Service\n",url_images_path,NOTES_ICON); printf("
There Are Additional
Notes For This Service...
\n"); } } 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 show_process_info(); document_footer(); /* free all allocated memory */ free_memory(); free_extended_data(); free_comment_data(); return OK; } void document_header(int use_stylesheet){ char date_time[MAX_DATETIME_LENGTH]; time_t current_time; time_t expire_time; printf("Cache-Control: no-store\n"); printf("Pragma: no-cache\n"); printf("Refresh: %d\n",refresh_rate); time(¤t_time); get_time_string(¤t_time,date_time,(int)sizeof(date_time),HTTP_DATE_TIME); printf("Last-Modified: %s\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\n",date_time); printf("Content-type: text/html\r\n\r\n"); if(embedded==TRUE) return; printf("\n"); printf("\n"); printf("\n"); printf("Extended Information\n"); printf("\n"); if(use_stylesheet==TRUE) printf("",url_stylesheets_path,EXTINFO_CSS); printf("\n"); printf("\n"); return; } void document_footer(void){ if(embedded==TRUE) return; 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]!=NULL;x++){ /* do some basic length checking on the variable identifier to prevent buffer overflows */ if(strlen(variables[x])>=MAX_INPUT_BUFFER-1){ x++; 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 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=(char *)malloc(strlen(variables[x])+1); if(host_name==NULL) host_name=""; else strcpy(host_name,variables[x]); } /* we found the hostgroup name */ else if(!strcmp(variables[x],"hostgroup")){ x++; if(variables[x]==NULL){ error=TRUE; break; } hostgroup_name=(char *)malloc(strlen(variables[x])+1); if(hostgroup_name==NULL) hostgroup_name=""; else strcpy(hostgroup_name,variables[x]); } /* we found the service name */ else if(!strcmp(variables[x],"service")){ x++; if(variables[x]==NULL){ error=TRUE; break; } service_desc=(char *)malloc(strlen(variables[x])+1); if(service_desc==NULL) service_desc=""; else strcpy(service_desc,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; } return error; } void show_process_info(void){ char state_string[MAX_INPUT_BUFFER]; char *state_class=""; 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("
Program Information
\n"); printf("\n"); printf("\n"); /* program start time */ get_time_string(&program_start,date_time,(int)sizeof(date_time),LONG_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,"%d days %d hrs %d min %d sec",days,hours,minutes,seconds); printf("\n",run_time_string); /* PID */ printf("\n",netsaint_pid); /* current program mode */ printf("\n",(program_mode==ACTIVE_MODE)?"ACTIVE":"STANDBY",(program_mode==ACTIVE_MODE)?"ACTIVE":"STANDBY"); /* last mode change*/ get_time_string(&last_mode_change,date_time,(int)sizeof(date_time),LONG_DATE_TIME); printf("\n",date_time); /* service check execution */ 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"); /* event handlers enabled */ printf("\n",(enable_event_handlers==TRUE)?"ENABLED":"DISABLED",(enable_event_handlers==TRUE)?"YES":"NO"); /* obsessing over services */ printf("\n",(obsess_over_services==TRUE)?"Yes":"No"); /* flap detection enabled */ printf("\n",(enable_flap_detection==TRUE)?"ENABLED":"DISABLED",(enable_flap_detection==TRUE)?"YES":"NO"); /* daemon mode */ printf("\n",(daemon_mode==TRUE)?"Yes":"No"); /* last external check */ get_time_string(&last_command_check,date_time,(int)sizeof(date_time),LONG_DATE_TIME); printf("\n",(last_command_check==(time_t)0)?"N/A":date_time); /* last log file rotation */ get_time_string(&last_log_rotation,date_time,(int)sizeof(date_time),LONG_DATE_TIME); printf("\n",(last_log_rotation==(time_t)0)?"N/A":date_time); printf("
VariableValue
Program Start Time%s
Total Running Time%s
NetSaint PID%d
Current Program Mode
  %s  
Last Program Mode Change%s
Service Checks Being Executed?
  %s  
Passive Service Checks Being Accepted?
  %s  
Event Handlers Enabled?
  %s  
Obsessing Over Services?%s
Flap Detection Enabled?
  %s  
Running As A Daemon?%s
Last External Command Check%s
Last Log File Rotation%s
\n"); printf("
\n"); printf("
\n"); printf("
Process Commands
\n"); printf("\n"); printf("\n"); printf("
\n"); if(netsaint_process_state==STATE_OK){ printf("\n"); printf("\n",url_images_path,STOP_ICON,COMMAND_CGI,CMD_SHUTDOWN_PROCESS); printf("\n",url_images_path,RESTART_ICON,COMMAND_CGI,CMD_RESTART_PROCESS); if(program_mode==ACTIVE_MODE) printf("\n",url_images_path,STANDBY_ICON,COMMAND_CGI,CMD_ENTER_STANDBY_MODE); else printf("\n",url_images_path,ACTIVE_ICON,COMMAND_CGI,CMD_ENTER_ACTIVE_MODE); 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(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(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); printf("
Shutdown the NetSaint ProcessShutdown the NetSaint process
Restart the NetSaint ProcessRestart the NetSaint process
Switch To Standby ModeSwitch to standby mode
Switch To Active ModeSwitch to active mode
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
Disable Event HandlersDisable event handlers
Enable Event HandlersEnable event handlers
Stop Obsessing Over ServicesStop obsessing over services
Start Obsessing Over ServicesStart obsessing over services
Disable Flap DetectionDisable flap detection
Enable Flap DetectionEnable flap detection
\n"); } else{ printf("
It appears as though NetSaint is not running, so commands are temporarily unavailable...\n"); if(!strcmp(netsaint_check_command,"")){ printf("

\n"); printf("Hint: It looks as though you have not defined a command for checking the process state by supplying a value for the netsaint_check_command option in the CGI configuration file.
\n"); printf("Read the documentation for more information on checking the status of the NetSaint process in the CGIs.\n"); } printf("
\n"); } printf("
\n"); printf("
\n"); printf("

"); printf("

\n"); printf("
Process State Information
\n"); printf("\n"); printf("\n"); if(netsaint_process_state==STATE_OK){ strcpy(state_string,"OK"); state_class="processOK"; } else if(netsaint_process_state==STATE_WARNING){ strcpy(state_string,"WARNING"); state_class="processWARNING"; } else if(netsaint_process_state==STATE_CRITICAL){ strcpy(state_string,"CRITICAL"); state_class="processCRITICAL"; } else{ strcpy(state_string,"UNKNOWN"); state_class="processUNKNOWN"; } /* process state */ printf("\n",state_class,state_string); /* process check command */ printf("\n",netsaint_check_command); /* process check command result */ printf("\n",netsaint_process_info); printf("
VariableValue
Process Status
  %s  
Process Check Command%s
Check Command Output%s
\n"); printf("
\n"); printf("

\n"); return; } void show_host_info(void){ hoststatus *temp_hoststatus; host *temp_host; char date_time[MAX_DATETIME_LENGTH]; char state_duration[48]; char state_string[MAX_INPUT_BUFFER]; char *bg_class=""; unsigned long total_monitored_time; unsigned long time_up; unsigned long time_down; unsigned long time_unreachable; float percent_time_up; float percent_time_down; float percent_time_unreachable; char time_up_string[48]; char time_down_string[48]; char time_unreachable_string[48]; char total_time_string[48]; 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,NULL); /* 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->last_check==0L) printf("

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

\n"); else{ if(temp_hoststatus->status==HOST_UP){ strcpy(state_string,"UP"); bg_class="hostUP"; } else if(temp_hoststatus->status==HOST_DOWN){ strcpy(state_string,"DOWN"); bg_class="hostDOWN"; } else if(temp_hoststatus->status==HOST_UNREACHABLE){ strcpy(state_string,"UNREACHABLE"); bg_class="hostUNREACHABLE"; } printf("\n"); printf("\n"); printf("\n",bg_class,state_string,(temp_hoststatus->problem_has_been_acknowledged==TRUE)?"(Has been acknowledged)":""); printf("\n",temp_hoststatus->information); get_time_string(&temp_hoststatus->last_check,date_time,(int)sizeof(date_time),SHORT_DATE_TIME); printf("\n",date_time); printf("\n",(temp_hoststatus->checks_enabled==TRUE)?"ENABLED":"DISABLED",(temp_hoststatus->checks_enabled==TRUE)?"YES":"NO"); 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); t=0; current_time=time(NULL); 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'; printf("\n",state_duration); 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); printf("\n",temp_hoststatus->current_notification_number); printf("\n",(temp_hoststatus->notifications_enabled)?"ENABLED":"DISABLED",(temp_hoststatus->notifications_enabled)?"YES":"NO"); printf("\n",(temp_hoststatus->event_handler_enabled)?"ENABLED":"DISABLED",(temp_hoststatus->event_handler_enabled)?"YES":"NO"); printf("\n",(temp_hoststatus->flap_detection_enabled==TRUE)?"ENABLED":"DISABLED",(temp_hoststatus->flap_detection_enabled==TRUE)?"YES":"NO"); printf("\n"); printf("\n"); printf("\n",(temp_hoststatus->scheduled_downtime_depth>0)?"ACTIVE":"INACTIVE",(temp_hoststatus->scheduled_downtime_depth>0)?"YES":"NO"); 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); printf("
VariableValue
Host Status
  %s  %s  
Status Information%s
Last Status Check%s
Host Checks Enabled?
  %s  
Last State Change%s
Current State Duration%s
Last Host Notification%s
Current Notification Number  %d  
Host Notifications Enabled?
  %s  
Event Handler Enabled?
  %s  
Flap Detection Enabled?
  %s  
Is This Host Flapping?"); if(temp_hoststatus->flap_detection_enabled==FALSE || enable_flap_detection==FALSE) printf("N/A"); else printf("
  %s  
",(temp_hoststatus->is_flapping==TRUE)?"":"not",(temp_hoststatus->is_flapping==TRUE)?"YES":"NO"); printf("
Percent State Change"); if(temp_hoststatus->flap_detection_enabled==FALSE || enable_flap_detection==FALSE) printf("N/A"); else printf("%3.2f%%",temp_hoststatus->percent_state_change); printf("
In Scheduled Downtime?
  %s  
Last Update%s
\n"); } printf("
\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("
\n"); printf("
Host State Statistics
\n"); if(temp_hoststatus->last_check==0L) printf("

This host has not yet been checked, so state statistics are not available.

\n"); else{ /* calculate host state times */ calculate_host_state_times(temp_host->name,&total_monitored_time,&time_up,&percent_time_up,&time_down,&percent_time_down,&time_unreachable,&percent_time_unreachable); get_time_breakdown(total_monitored_time,&days,&hours,&minutes,&seconds); snprintf(total_time_string,sizeof(total_time_string)-1,"%dd %dh %dm %ds",days,hours,minutes,seconds); get_time_breakdown(time_up,&days,&hours,&minutes,&seconds); snprintf(time_up_string,sizeof(time_up_string)-1,"%dd %dh %dm %ds",days,hours,minutes,seconds); get_time_breakdown(time_down,&days,&hours,&minutes,&seconds); snprintf(time_down_string,sizeof(time_down_string)-1,"%dd %dh %dm %ds",days,hours,minutes,seconds); get_time_breakdown(time_unreachable,&days,&hours,&minutes,&seconds); snprintf(time_unreachable_string,sizeof(time_unreachable_string)-1,"%dd %dh %dm %ds",days,hours,minutes,seconds); printf("\n"); printf("\n"); printf("\n",time_up_string,percent_time_up); printf("\n",time_down_string,percent_time_down); printf("\n",time_unreachable_string,percent_time_unreachable); printf("\n"); printf("\n",total_time_string); printf("
StateTime%% Time
UP%s%2.1f%%
DOWN%s%2.1f%%
UNREACHABLE%s%2.1f%%
All States%s100.0%%
\n"); } printf("
\n"); printf("
Host Commands
\n"); printf("
\n"); if(netsaint_process_state==STATE_OK){ printf("\n"); 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)); if(temp_hoststatus->status!=HOST_UP && temp_hoststatus->last_notification!=(time_t)0){ 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,NOTIFICATIONS_DISABLED_ICON,COMMAND_CGI,CMD_DISABLE_HOST_NOTIFICATIONS,url_encode(host_name)); else printf("\n",url_images_path,NOTIFICATION_ICON,COMMAND_CGI,CMD_ENABLE_HOST_NOTIFICATIONS,url_encode(host_name)); if(temp_hoststatus->status!=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,SCHEDULED_DOWNTIME_ICON,COMMAND_CGI,CMD_CANCEL_HOST_DOWNTIME,url_encode(host_name)); printf("\n",url_images_path,NOTIFICATIONS_DISABLED_ICON,COMMAND_CGI,CMD_DISABLE_HOST_SVC_NOTIFICATIONS,url_encode(host_name)); printf("\n",url_images_path,NOTIFICATION_ICON,COMMAND_CGI,CMD_ENABLE_HOST_SVC_NOTIFICATIONS,url_encode(host_name)); printf("\n",url_images_path,DELAY_ICON,COMMAND_CGI,CMD_IMMEDIATE_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,HOST_EVENT_ICON,COMMAND_CGI,CMD_DISABLE_HOST_EVENT_HANDLER,url_encode(host_name)); else printf("\n",url_images_path,HOST_EVENT_ICON,COMMAND_CGI,CMD_ENABLE_HOST_EVENT_HANDLER,url_encode(host_name)); if(temp_hoststatus->flap_detection_enabled==TRUE) printf("\n",url_images_path,FLAPPING_ICON,COMMAND_CGI,CMD_DISABLE_HOST_FLAP_DETECTION,url_encode(host_name)); else printf("\n",url_images_path,FLAPPING_ICON,COMMAND_CGI,CMD_ENABLE_HOST_FLAP_DETECTION,url_encode(host_name)); printf("
Disable Checks Of This HostDisable checks of this host
Enable Checks Of This HostEnable checks of 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
Delay Next Host NotificationDelay next host notification
Schedule Downtime For This HostSchedule downtime for this host
Cancel Scheduled Downtime For This HostCancel scheduled downtime for 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 An Immediate Check Of All Services On This HostSchedule an immediate 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
Enable Flap Detection For This HostEnable flap detection for this host
\n"); } else{ printf("
It appears as though NetSaint is not running, so commands are temporarily unavailable...
\n"); printf("Click here to view NetSaint 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 state_duration[48]; servicestatus *temp_svcstatus; char state_string[MAX_INPUT_BUFFER]; char *bg_class=""; float percent_time_ok; float percent_time_warning; float percent_time_unknown; float percent_time_critical; char time_ok_string[48]; char time_warning_string[48]; char time_unknown_string[48]; char time_critical_string[48]; char total_time_string[48]; unsigned long time_ok; unsigned long time_warning; unsigned long time_unknown; unsigned long time_critical; unsigned long total_monitored_time; 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,NULL); /* 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("
Service State Information
\n"); if(temp_svcstatus->last_check==0L) printf("

This service has not yet been checked, so its current status information and state statistics are not available.

\n"); else{ printf("\n"); printf("\n"); if(temp_svcstatus->status==SERVICE_OK || temp_svcstatus->status==SERVICE_RECOVERY){ 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 || temp_svcstatus->status==SERVICE_UNREACHABLE || temp_svcstatus->status==SERVICE_HOST_DOWN){ strcpy(state_string,"CRITICAL"); bg_class="serviceCRITICAL"; } else{ strcpy(state_string,"UNKNOWN"); bg_class="serviceUNKNOWN"; } printf("\n",bg_class,state_string,(temp_svcstatus->problem_has_been_acknowledged==TRUE)?"(Has been acknowledged)":""); printf("\n",temp_svcstatus->information); printf("\n",temp_svcstatus->current_attempt,temp_svcstatus->max_attempts); printf("\n",(temp_svcstatus->state_type==HARD_STATE)?"HARD":"SOFT"); printf("\n",(temp_svcstatus->check_type==SERVICE_CHECK_ACTIVE)?"ACTIVE":"PASSIVE"); get_time_string(&temp_svcstatus->last_check,date_time,(int)sizeof(date_time),SHORT_DATE_TIME); printf("\n",date_time); 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)?date_time:"N/A"); printf("\n"); printf("\n",temp_svcstatus->execution_time); printf("\n",(temp_svcstatus->checks_enabled)?"ENABLED":"DISABLED",(temp_svcstatus->checks_enabled)?"YES":"NO"); printf("\n",(temp_svcstatus->accept_passive_service_checks==TRUE)?"ENABLED":"DISABLED",(temp_svcstatus->accept_passive_service_checks)?"YES":"NO"); 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); t=0; current_time=time(NULL); 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'; printf("\n",state_duration); 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); get_time_string(&temp_svcstatus->last_notification,date_time,(int)sizeof(date_time),SHORT_DATE_TIME); printf("\n",temp_svcstatus->current_notification_number); printf("\n",(temp_svcstatus->notifications_enabled)?"ENABLED":"DISABLED",(temp_svcstatus->notifications_enabled)?"YES":"NO"); printf("\n",(temp_svcstatus->event_handler_enabled)?"ENABLED":"DISABLED",(temp_svcstatus->event_handler_enabled)?"YES":"NO"); printf("\n",(temp_svcstatus->flap_detection_enabled==TRUE)?"ENABLED":"DISABLED",(temp_svcstatus->flap_detection_enabled==TRUE)?"YES":"NO"); printf("\n"); printf("\n"); printf("\n",(temp_svcstatus->scheduled_downtime_depth>0)?"ACTIVE":"INACTIVE",(temp_svcstatus->scheduled_downtime_depth>0)?"YES":"NO"); 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); printf("
VariableValue
Current Status
  %s  %s  
Status Information%s
Current Attempt%d/%d
State Type%s
Last Check Type%s
Last Check Time%s
Next Scheduled Active Check%s
Latency"); if(temp_svcstatus->check_type==SERVICE_CHECK_ACTIVE) printf("%d seconds",temp_svcstatus->latency); else printf("N/A"); printf("
Check Duration%d seconds
Service Checks Enabled?
  %s  
Passive Checks Being Accepted?
  %s  
Last State Change%s
Current State Duration%s
Last Service Notification%s
Current Notification Number%d
Service Notifications Enabled?
  %s  
Event Handler Enabled?
  %s  
Flap Detection Enabled?
  %s  
Is This Service Flapping?"); if(temp_svcstatus->flap_detection_enabled==FALSE || enable_flap_detection==FALSE) printf("N/A"); else printf("
  %s  
",(temp_svcstatus->is_flapping==TRUE)?"":"not",(temp_svcstatus->is_flapping==TRUE)?"YES":"NO"); printf("
Percent State Change"); if(temp_svcstatus->flap_detection_enabled==FALSE || enable_flap_detection==FALSE) printf("N/A"); else printf("%3.2f%%",temp_svcstatus->percent_state_change); printf("
In Scheduled Downtime?
  %s  
Last Update%s
\n"); } printf("
\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("
\n"); printf("
Service State Statistics
\n"); if(temp_svcstatus->last_check==0L) printf("

This service has not yet been checked, so state statistics are not available.

\n"); else{ /* calculate service state times */ calculate_service_state_times(temp_service->host_name,temp_service->description,&total_monitored_time,&time_ok,&percent_time_ok,&time_warning,&percent_time_warning,&time_unknown,&percent_time_unknown,&time_critical,&percent_time_critical); get_time_breakdown(time_ok,&days,&hours,&minutes,&seconds); snprintf(time_ok_string,sizeof(time_ok_string)-1,"%dd %dh %dm %ds",days,hours,minutes,seconds); get_time_breakdown(time_warning,&days,&hours,&minutes,&seconds); snprintf(time_warning_string,sizeof(time_warning_string)-1,"%dd %dh %dm %ds",days,hours,minutes,seconds); get_time_breakdown(time_unknown,&days,&hours,&minutes,&seconds); snprintf(time_unknown_string,sizeof(time_unknown_string)-1,"%dd %dh %dm %ds",days,hours,minutes,seconds); get_time_breakdown(time_critical,&days,&hours,&minutes,&seconds); snprintf(time_critical_string,sizeof(time_critical_string)-1,"%dd %dh %dm %ds",days,hours,minutes,seconds); get_time_breakdown(total_monitored_time,&days,&hours,&minutes,&seconds); snprintf(total_time_string,sizeof(total_time_string)-1,"%dd %dh %dm %ds",days,hours,minutes,seconds); printf("\n"); printf("\n"); printf("\n",time_ok_string,percent_time_ok); printf("\n",time_warning_string,percent_time_warning); printf("\n",time_unknown_string,percent_time_unknown); printf("\n",time_critical_string,percent_time_critical); printf("\n"); printf("\n",total_time_string); printf("
StateTime%% Time
OK%s%2.1f%%
WARNING%s%2.1f%%
UNKNOWN%s%2.1f%%
CRITICAL%s%2.1f%%
All States%s100.0%%
\n"); if(temp_svcstatus->state_type==SOFT_STATE) printf("

NOTE: This service is currently in a soft state, so the state statistics may be temporarily inaccurate. When the service returns to a hard state, the statistics will be correct.

\n"); } printf("
\n"); printf("
Service Commands
\n"); printf("\n"); printf("\n"); printf("
\n"); if(netsaint_process_state==STATE_OK){ printf("\n"); if(temp_svcstatus->checks_enabled){ if(temp_svcstatus->status!=SERVICE_OK && temp_svcstatus->status!=SERVICE_RECOVERY && temp_svcstatus->status!=SERVICE_PENDING && temp_svcstatus->state_type==HARD_STATE && temp_svcstatus->last_notification!=(time_t)0){ 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){ 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)); printf("\n",url_encode(service_desc)); printf("\n",url_encode(service_desc)); } else{ printf("\n",url_encode(service_desc)); } if(temp_svcstatus->accept_passive_service_checks==TRUE){ printf("\n",url_encode(service_desc)); printf("\n",url_encode(service_desc)); } else{ 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)); } else{ printf("\n",url_encode(service_desc)); } printf("
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
Schedule Downtime For This ServiceSchedule downtime for this service
Cancel Scheduled Downtime For This ServiceCancel scheduled downtime for this service
Disable Checks Of This ServiceDisable checks of this service
Delay Next Service CheckDelay next service check
Schedule an Immediate Check of this ServiceSchedule an immediate check of this service
Enable Checks Of This ServiceEnable checks 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
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
Enable Flap Detection For This ServiceEnable flap detection for this service
\n"); } else{ printf("
It appears as though NetSaint is not running, so commands are temporarily unavailable...
\n"); printf("Click here to view NetSaint 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 host info */ temp_hostgroup=find_hostgroup(hostgroup_name,NULL); /* 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"); /* printf("\n"); */ printf("\n"); printf("\n"); printf("
\n"); printf("Something..."); printf("\n"); printf("
Hostgroup Commands
\n"); if(netsaint_process_state==STATE_OK){ printf("\n"); printf("\n"); printf("
\n"); printf("\n"); 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("
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 Checks Of All Services In This HostgroupEnable checks of all services in this hostgroup
Disable Checks Of All Services In This HostgroupDisable checks of all services in this hostgroup
\n"); printf("
\n"); } else{ printf("
It appears as though NetSaint is not running, so commands are temporarily unavailable...
\n"); printf("Click here to view NetSaint process information
\n",EXTINFO_CGI,DISPLAY_PROCESS_INFO); } printf("
\n"); return; } /* shows all service and host comments */ void show_all_comments(void){ int total_comments=0; char *bg_class=""; int odd=0; char date_time[MAX_DATETIME_LENGTH]; comment *temp_comment; host *temp_host; service *temp_service; /* read in all comments */ read_comment_data(DEFAULT_CGI_CONFIG_FILE); printf("
Host Comments
\n"); printf("\n"); printf("

\n"); printf("

\n"); printf("
\n"); 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,NULL); /* 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"; } get_time_string(&temp_comment->entry_time,date_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"); printf("",COMMAND_CGI,CMD_DEL_HOST_COMMENT,temp_comment->comment_id,url_images_path,DELETE_ICON); printf("\n"); } printf("
Host NameEntry TimeAuthorCommentComment IDPersistentActions
%s%s%s%s%d%sDelete This Comment
\n"); if(total_comments==0) printf("There are no host comments"); printf("


\n"); printf("
Service Comments
\n"); printf("\n"); printf("

\n"); printf("

\n"); printf("
\n"); 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,NULL); /* 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"; } get_time_string(&temp_comment->entry_time,date_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"); printf("",COMMAND_CGI,CMD_DEL_SVC_COMMENT,temp_comment->comment_id,url_images_path,DELETE_ICON); printf("\n"); } printf("
Host NameServiceEntry TimeAuthorCommentComment IDPersistentActions
%s%s%s%s%s%d%sDelete This Comment
\n"); if(total_comments==0) printf("There are no service comments"); return; } void show_performance_data(void){ service *temp_service=NULL; servicestatus *temp_servicestatus=NULL; int total_active_checks=0; int total_passive_checks=0; int min_execution_time=0; int max_execution_time=0; unsigned long total_execution_time=0L; int have_min_execution_time=FALSE; int have_max_execution_time=FALSE; int min_latency=0; int max_latency=0; unsigned long total_latency=0L; int have_min_latency=FALSE; int have_max_latency=FALSE; double min_percent_change_a=0.0; double max_percent_change_a=0.0; double total_percent_change_a=0.0; int have_min_percent_change_a=FALSE; int have_max_percent_change_a=FALSE; double min_percent_change_b=0.0; double max_percent_change_b=0.0; double total_percent_change_b=0.0; int have_min_percent_change_b=FALSE; int have_max_percent_change_b=FALSE; int active_checks_1min=0; int active_checks_5min=0; int active_checks_15min=0; int active_checks_1hour=0; int passive_checks_1min=0; int passive_checks_5min=0; int passive_checks_15min=0; int passive_checks_1hour=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,NULL); /* 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==SERVICE_CHECK_ACTIVE){ total_active_checks++; total_execution_time+=temp_servicestatus->execution_time; if(have_min_execution_time==FALSE || temp_servicestatus->execution_timeexecution_time; } if(have_max_execution_time==FALSE || temp_servicestatus->execution_time>max_execution_time){ have_max_execution_time=TRUE; max_execution_time=temp_servicestatus->execution_time; } total_percent_change_a+=temp_servicestatus->percent_state_change; if(have_min_percent_change_a==FALSE || temp_servicestatus->percent_state_changepercent_state_change; } if(have_max_percent_change_a==FALSE || temp_servicestatus->percent_state_change>max_percent_change_a){ have_max_percent_change_a=TRUE; max_percent_change_a=temp_servicestatus->percent_state_change; } total_latency+=temp_servicestatus->latency; if(have_min_latency==FALSE || temp_servicestatus->latencylatency; } if(have_max_latency==FALSE || temp_servicestatus->latency>max_latency){ have_max_latency=TRUE; max_latency=temp_servicestatus->latency; } if(temp_servicestatus->last_check>=(current_time-60)) active_checks_1min++; if(temp_servicestatus->last_check>=(current_time-300)) active_checks_5min++; if(temp_servicestatus->last_check>=(current_time-900)) active_checks_15min++; if(temp_servicestatus->last_check>=(current_time-3600)) active_checks_1hour++; } else{ total_passive_checks++; total_percent_change_b+=temp_servicestatus->percent_state_change; if(have_min_percent_change_b==FALSE || temp_servicestatus->percent_state_changepercent_state_change; } if(have_max_percent_change_b==FALSE || temp_servicestatus->percent_state_change>max_percent_change_b){ have_max_percent_change_b=TRUE; max_percent_change_b=temp_servicestatus->percent_state_change; } if(temp_servicestatus->last_check>=(current_time-60)) passive_checks_1min++; if(temp_servicestatus->last_check>=(current_time-300)) passive_checks_5min++; if(temp_servicestatus->last_check>=(current_time-900)) passive_checks_15min++; if(temp_servicestatus->last_check>=(current_time-3600)) passive_checks_1hour++; } } printf("
\n"); printf("
Active Checks (%d total)
\n",total_active_checks); if(total_active_checks>0){ printf("\n"); printf("\n"); printf("
\n"); printf("\n"); printf("\n"); printf("",(double)(((double)active_checks_1min*100.0)/(double)total_active_checks),active_checks_1min); printf("",(double)(((double)active_checks_5min*100.0)/(double)total_active_checks),active_checks_5min); printf("",(double)(((double)active_checks_15min*100.0)/(double)total_active_checks),active_checks_15min); printf("",(double)(((double)active_checks_1hour*100.0)/(double)total_active_checks),active_checks_1hour); printf("
Checks Completed In Last:Percent CompletedTotal Completed
1 minute%.1f%%%d
5 minutes%.1f%%%d
15 minutes%.1f%%%d
1 hour%.1f%%%d
\n"); printf("
\n"); printf("\n"); printf("\n"); printf("\n",min_execution_time,max_execution_time,(double)((double)total_execution_time/(double)total_active_checks)); printf("\n",min_latency,max_latency,(double)((double)total_latency/(double)total_active_checks)); printf("\n",min_percent_change_a,max_percent_change_a,(double)((double)total_percent_change_a/(double)total_active_checks)); printf("
MetricMin.Max.Average
Check Execution Time%d sec%d sec%.3f sec
Check Latency%d sec%d sec%.3f sec
Percent State Change%.2f%%%.2f%%%.2f%%
\n"); printf("
\n"); } printf("

\n"); printf("
Passive Checks (%d total)
\n",total_passive_checks); if(total_passive_checks>0){ printf("\n"); printf("\n"); printf("
\n"); printf("\n"); printf("\n"); printf("",(double)(((double)passive_checks_1min*100.0)/(double)total_passive_checks),passive_checks_1min); printf("",(double)(((double)passive_checks_5min*100.0)/(double)total_passive_checks),passive_checks_5min); printf("",(double)(((double)passive_checks_15min*100.0)/(double)total_passive_checks),passive_checks_15min); printf("",(double)(((double)passive_checks_1hour*100.0)/(double)total_passive_checks),passive_checks_1hour); printf("
Checks Completed In Last:Percent CompletedTotal Completed
1 minute%.1f%%%d
5 minutes%.1f%%%d
15 minutes%.1f%%%d
1 hour%.1f%%%d
\n"); printf("
\n"); printf("\n"); printf("\n"); printf("\n",min_percent_change_b,max_percent_change_b,(double)((double)total_percent_change_b/(double)total_passive_checks)); printf("
MetricMin.Max.Average
Percent State Change%.2f%%%.2f%%%.2f%%
\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; char *bg_class=""; int odd=0; char date_time[MAX_DATETIME_LENGTH]; comment *temp_comment; /* find the host or service */ if(type==HOST_COMMENT){ temp_host=find_host(host_name,NULL); if(temp_host==NULL) return; } else{ temp_service=find_service(host_name,service_desc,NULL); if(temp_service==NULL) return; } printf("
%s Comments
\n",(type==HOST_COMMENT)?"Host":"Service"); 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"); printf("

\n"); printf("

\n"); printf("\n"); printf("\n"); /* read in all comments */ read_comment_data(DEFAULT_CGI_CONFIG_FILE); /* check all the comments to see if they apply to this host or service */ for(temp_comment=comment_list;temp_comment!=NULL;temp_comment=temp_comment->next){ display_comment=FALSE; if(type==HOST_COMMENT && temp_comment->comment_type==HOST_COMMENT && !strcmp(temp_comment->host_name,host_name)) display_comment=TRUE; else if(type==SERVICE_COMMENT && temp_comment->comment_type==SERVICE_COMMENT && !strcmp(temp_comment->host_name,host_name) && !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"; } get_time_string(&temp_comment->entry_time,date_time,(int)sizeof(date_time),SHORT_DATE_TIME); printf("",bg_class); 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"); 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"); } } printf("
Entry TimeAuthorCommentComment IDPersistentActions
%s%s%s%d%sDelete This Comment
\n"); /* see if this host or service has any comments associated with it */ if(type==HOST_COMMENT) total_comments=number_of_host_comments(temp_host->name); else total_comments=number_of_service_comments(temp_service->host_name,temp_service->description); if(total_comments==0) printf("This %s has no comments associated with it",(type==HOST_COMMENT)?"host":"service"); return; }