/************************************************************************** * * STATUSWML.C - NetSaint Status CGI for WAP-enabled devices * * Copyright (c) 2001 Ethan Galstad (netsaint@netsaint.org) * Last Modified: 11-14-2001 * * 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/statusdata.h" #include "cgiutils.h" #include "getcgi.h" #include "auth.h" extern time_t program_start; extern char main_config_file[MAX_FILENAME_LENGTH]; extern host *host_list; extern hostgroup *hostgroup_list; extern hoststatus *hoststatus_list; extern servicestatus *servicestatus_list; extern service *service_list; extern int program_mode; extern int execute_service_checks; extern int netsaint_process_state; #define DISPLAY_HOST 0 #define DISPLAY_SERVICE 1 #define DISPLAY_HOSTGROUP 2 #define DISPLAY_INDEX 3 #define DISPLAY_PING 4 #define DISPLAY_TRACEROUTE 5 #define DISPLAY_QUICKSTATS 6 #define DISPLAY_PROCESS 7 #define DISPLAY_ALL_PROBLEMS 8 #define DISPLAY_UNHANDLED_PROBLEMS 9 #define DISPLAY_HOSTGROUP_SUMMARY 0 #define DISPLAY_HOSTGROUP_OVERVIEW 1 #define DISPLAY_HOST_SUMMARY 0 #define DISPLAY_HOST_SERVICES 1 void document_header(void); void document_footer(void); int process_cgivars(void); int display_type=DISPLAY_INDEX; int hostgroup_style=DISPLAY_HOSTGROUP_SUMMARY; int host_style=DISPLAY_HOST_SUMMARY; void display_index(void); void display_host(void); void display_host_services(void); void display_service(void); void display_hostgroup_summary(void); void display_hostgroup_overview(void); void display_ping(void); void display_traceroute(void); void display_quick_stats(void); void display_process(void); void display_problems(void); char *host_name=""; char *hostgroup_name=""; char *service_desc=""; char *ping_address=""; char *traceroute_address=""; int show_all_hostgroups=TRUE; authdata current_authdata; int main(void){ int result=OK; /* get the arguments passed in the URL */ process_cgivars(); /* reset internal variables */ reset_cgi_vars(); document_header(); /* read the CGI configuration file */ result=read_cgi_config_file(DEFAULT_CGI_CONFIG_FILE); if(result==ERROR){ printf("

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

\n",DEFAULT_CGI_CONFIG_FILE); document_footer(); return ERROR; } /* 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; } /* get authentication information */ get_authentication_information(¤t_authdata); /* decide what to display to the user */ if(display_type==DISPLAY_HOST && host_style==DISPLAY_HOST_SERVICES) display_host_services(); else if(display_type==DISPLAY_HOST) display_host(); else if(display_type==DISPLAY_SERVICE) display_service(); else if(display_type==DISPLAY_HOSTGROUP && hostgroup_style==DISPLAY_HOSTGROUP_OVERVIEW) display_hostgroup_overview(); else if(display_type==DISPLAY_HOSTGROUP && hostgroup_style==DISPLAY_HOSTGROUP_SUMMARY) display_hostgroup_summary(); else if(display_type==DISPLAY_PING) display_ping(); else if(display_type==DISPLAY_TRACEROUTE) display_traceroute(); else if(display_type==DISPLAY_QUICKSTATS) display_quick_stats(); else if(display_type==DISPLAY_PROCESS) display_process(); else if(display_type==DISPLAY_ALL_PROBLEMS || display_type==DISPLAY_UNHANDLED_PROBLEMS) display_problems(); else display_index(); document_footer(); /* free all allocated memory */ free_memory(); return OK; } void document_header(void){ char date_time[MAX_DATETIME_LENGTH]; time_t expire_time; time_t current_time; time(¤t_time); printf("Cache-Control: no-store\n"); printf("Pragma: no-cache\n"); 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/vnd.wap.wml\n\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); return; } void document_footer(void){ printf("\n"); return; } int process_cgivars(void){ char **variables; int error=FALSE; int x; variables=getcgivars(); for(x=0;variables[x]!=NULL;x++){ /* we found the hostgroup argument */ if(!strcmp(variables[x],"hostgroup")){ display_type=DISPLAY_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]); if(!strcmp(hostgroup_name,"all")) show_all_hostgroups=TRUE; else show_all_hostgroups=FALSE; } /* we found the host argument */ else if(!strcmp(variables[x],"host")){ display_type=DISPLAY_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 service argument */ else if(!strcmp(variables[x],"service")){ display_type=DISPLAY_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 hostgroup style argument */ else if(!strcmp(variables[x],"style")){ x++; if(variables[x]==NULL){ error=TRUE; break; } if(!strcmp(variables[x],"overview")) hostgroup_style=DISPLAY_HOSTGROUP_OVERVIEW; else if(!strcmp(variables[x],"summary")) hostgroup_style=DISPLAY_HOSTGROUP_SUMMARY; else if(!strcmp(variables[x],"servicedetail")) host_style=DISPLAY_HOST_SERVICES; else if(!strcmp(variables[x],"processinfo")) display_type=DISPLAY_PROCESS; else if(!strcmp(variables[x],"aprobs")) display_type=DISPLAY_ALL_PROBLEMS; else if(!strcmp(variables[x],"uprobs")) display_type=DISPLAY_UNHANDLED_PROBLEMS; else display_type=DISPLAY_QUICKSTATS; } /* we found the ping argument */ else if(!strcmp(variables[x],"ping")){ display_type=DISPLAY_PING; x++; if(variables[x]==NULL){ error=TRUE; break; } ping_address=(char *)malloc(strlen(variables[x])+1); if(ping_address==NULL) ping_address=""; else strcpy(ping_address,variables[x]); } /* we found the traceroute argument */ else if(!strcmp(variables[x],"traceroute")){ display_type=DISPLAY_TRACEROUTE; x++; if(variables[x]==NULL){ error=TRUE; break; } traceroute_address=(char *)malloc(strlen(variables[x])+1); if(traceroute_address==NULL) traceroute_address=""; else strcpy(traceroute_address,variables[x]); } } return error; } /* main intro screen */ void display_index(void){ /**** MAIN MENU SCREEN (CARD 1) ****/ printf("\n"); printf("

\n"); printf("NetSaint
WAP Interface
\n"); printf("Quick Stats
\n",STATUSWML_CGI); printf("Status Summary
\n",STATUSWML_CGI); printf("Status Overview
\n",STATUSWML_CGI); printf("All Problems
\n",STATUSWML_CGI); printf("Unhandled Problems
\n",STATUSWML_CGI); printf("Process Info
\n",STATUSWML_CGI); printf("Tools
\n"); printf("About
\n"); printf("

\n"); printf("
\n"); /**** TOOLS SCREEN (CARD 2) ****/ printf("\n"); printf("

\n"); printf("Network Tools:
\n"); printf("Ping
\n",STATUSWML_CGI); printf("Traceroute
\n",STATUSWML_CGI); printf("View Host
\n"); printf("View Hostgroup
\n"); printf("

\n"); printf("
\n"); /**** ABOUT SCREEN (CARD 3) ****/ printf("\n"); printf("

\n"); printf("About
\n"); printf("

\n"); printf("

\n"); printf("NetSaint %s
WAP Interface
\n",PROGRAM_VERSION); printf("Copyright (C) 2001 Ethan Galstad
\n"); printf("netsaint@netsaint.org

\n"); printf("License: GPL

\n"); printf("Based in part on features found in AskAround's Wireless Network Tools
\n"); printf("www.askaround.com
\n"); printf("

\n"); printf("
\n"); /**** VIEW HOST SCREEN (CARD 4) ****/ printf("\n"); printf("

\n"); printf("View Host
\n"); printf("

\n"); printf("

\n"); printf("Host Name:
\n"); printf("\n"); printf("\n"); printf("\n",STATUSWML_CGI); printf("\n"); printf("

\n"); printf("
\n"); /**** VIEW HOSTGROUP SCREEN (CARD 5) ****/ printf("\n"); printf("

\n"); printf("View Hostgroup
\n"); printf("

\n"); printf("

\n"); printf("Hostgroup Name:
\n"); printf("\n"); printf("\n"); printf("\n",STATUSWML_CGI); printf("\n"); printf("

\n"); printf("
\n"); return; } /* displays process info */ void display_process(void){ /**** MAIN SCREEN (CARD 1) ****/ printf("\n"); printf("

\n"); printf("Process Info

\n"); /* check authorization */ if(is_authorized_for_system_information(¤t_authdata)==FALSE){ printf("Error: Not authorized for process info!\n"); printf("

\n"); printf("
\n"); return; } if(netsaint_process_state==STATE_OK) printf("NetSaint process is running
\n"); else printf("NetSaint process may not be running
\n"); if(program_mode==ACTIVE_MODE) printf("Notifications are enabled (active mode)
\n"); else printf("Notifications are disabled (standby mode)
\n"); if(execute_service_checks==TRUE) printf("Check execution is enabled
\n"); else printf("Check execution is disabled
\n"); printf("
\n"); printf("Process Commands\n"); printf("

\n"); printf("\n"); /**** COMMANDS SCREEN (CARD 2) ****/ printf("\n"); printf("

\n"); printf("Process Commands
\n"); if(program_mode==STANDBY_MODE) printf("Enable Notifications (Active Mode)
\n",COMMAND_CGI,CMD_ENTER_ACTIVE_MODE,CMDMODE_COMMIT); else printf("Disable Notifications (Standby Mode)
\n",COMMAND_CGI,CMD_ENTER_STANDBY_MODE,CMDMODE_COMMIT); if(execute_service_checks==FALSE) printf("Enable Check Execution
\n",COMMAND_CGI,CMD_START_EXECUTING_SVC_CHECKS,CMDMODE_COMMIT); else printf("Disable Check Execution
\n",COMMAND_CGI,CMD_STOP_EXECUTING_SVC_CHECKS,CMDMODE_COMMIT); printf("

\n"); printf("
\n"); return; } /* displays quick stats */ void display_quick_stats(void){ host *temp_host; hoststatus *temp_hoststatus; service *temp_service; servicestatus *temp_servicestatus; int hosts_unreachable=0; int hosts_down=0; int hosts_up=0; int hosts_pending=0; int services_critical=0; int services_unknown=0; int services_warning=0; int services_ok=0; int services_pending=0; /**** MAIN SCREEN (CARD 1) ****/ printf("\n"); printf("

\n"); printf("Quick Stats
\n"); printf("

\n"); /* check all hosts */ for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){ if(is_authorized_for_host(temp_host,¤t_authdata)==FALSE) continue; temp_hoststatus=find_hoststatus(temp_host->name); if(temp_hoststatus==NULL) continue; if(temp_hoststatus->status==HOST_UNREACHABLE) hosts_unreachable++; else if(temp_hoststatus->status==HOST_DOWN) hosts_down++; else if(temp_hoststatus->status==HOST_PENDING) hosts_pending++; else hosts_up++; } /* check all services */ for(temp_service=service_list;temp_service!=NULL;temp_service=temp_service->next){ if(is_authorized_for_service(temp_service,¤t_authdata)==FALSE) continue; temp_servicestatus=find_servicestatus(temp_service->host_name,temp_service->description); if(temp_servicestatus==NULL) continue; if(temp_servicestatus->status==SERVICE_CRITICAL) services_critical++; else if(temp_servicestatus->status==SERVICE_UNKNOWN) services_unknown++; else if(temp_servicestatus->status==SERVICE_WARNING) services_warning++; else if(temp_servicestatus->status==SERVICE_PENDING) services_pending++; else services_ok++; } printf("

\n"); printf("Host Totals:
\n"); printf("%d UP
\n",hosts_up); printf("%d DOWN
\n",hosts_down); printf("%d UNREACHABLE
\n",hosts_unreachable); printf("%d PENDING
\n",hosts_pending); printf("
\n"); printf("Service Totals:
\n"); printf("%d OK
\n",services_ok); printf("%d WARNING
\n",services_warning); printf("%d UNKNOWN
\n",services_unknown); printf("%d CRITICAL
\n",services_critical); printf("%d PENDING
\n",services_pending); printf("

\n"); printf("
\n"); return; } /* displays hostgroup status overview */ void display_hostgroup_overview(void){ hostgroup *temp_hostgroup; host *temp_host; hoststatus *temp_hoststatus; /**** MAIN SCREEN (CARD 1) ****/ printf("\n"); printf("

\n"); printf("Status Overview

\n",STATUSWML_CGI,hostgroup_name); /* check all hostgroups */ for(temp_hostgroup=hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){ if(show_all_hostgroups==FALSE && strcmp(temp_hostgroup->group_name,hostgroup_name)) continue; if(is_authorized_for_hostgroup(temp_hostgroup,¤t_authdata)==FALSE) continue; printf("%s\n",temp_hostgroup->alias); printf("\n"); /* check all hosts in this hostgroup */ for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){ if(is_authorized_for_host(temp_host,¤t_authdata)==FALSE) continue; if(is_host_member_of_hostgroup(temp_hostgroup,temp_host)==FALSE) continue; temp_hoststatus=find_hoststatus(temp_host->name); if(temp_hoststatus==NULL) continue; printf("",STATUSWML_CGI,temp_host->name); printf("\n",temp_host->name); } printf("
",temp_host->name); if(temp_hoststatus->status==HOST_UP) printf("UP"); else if(temp_hoststatus->status==HOST_PENDING) printf("PND"); else if(temp_hoststatus->status==HOST_DOWN) printf("DWN"); else if(temp_hoststatus->status==HOST_UNREACHABLE) printf("UNR"); else printf("???"); printf("%s
\n"); printf("
\n"); } if(show_all_hostgroups==FALSE) printf("View All Hostgroups\n",STATUSWML_CGI); printf("

\n"); printf("
\n"); return; } /* displays hostgroup status summary */ void display_hostgroup_summary(void){ hostgroup *temp_hostgroup; host *temp_host; hoststatus *temp_hoststatus; service *temp_service; servicestatus *temp_servicestatus; int hosts_unreachable=0; int hosts_down=0; int hosts_up=0; int hosts_pending=0; int services_critical=0; int services_unknown=0; int services_warning=0; int services_ok=0; int services_pending=0; int found=0; /**** MAIN SCREEN (CARD 1) ****/ printf("\n"); printf("

\n"); printf("Status Summary

\n",STATUSWML_CGI,hostgroup_name); /* check all hostgroups */ for(temp_hostgroup=hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){ if(show_all_hostgroups==FALSE && strcmp(temp_hostgroup->group_name,hostgroup_name)) continue; if(is_authorized_for_hostgroup(temp_hostgroup,¤t_authdata)==FALSE) continue; printf("%s\n",temp_hostgroup->group_name,temp_hostgroup->alias,STATUSWML_CGI,temp_hostgroup->group_name); printf("\n"); hosts_up=0; hosts_pending=0; hosts_down=0; hosts_unreachable=0; services_ok=0; services_pending=0; services_warning=0; services_unknown=0; services_critical=0; /* check all hosts in this hostgroup */ for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){ if(is_authorized_for_host(temp_host,¤t_authdata)==FALSE) continue; if(is_host_member_of_hostgroup(temp_hostgroup,temp_host)==FALSE) continue; temp_hoststatus=find_hoststatus(temp_host->name); if(temp_hoststatus==NULL) continue; if(temp_hoststatus->status==HOST_UNREACHABLE) hosts_unreachable++; else if(temp_hoststatus->status==HOST_DOWN) hosts_down++; else if(temp_hoststatus->status==HOST_PENDING) hosts_pending++; else hosts_up++; /* check all services on this host */ for(temp_service=service_list;temp_service!=NULL;temp_service=temp_service->next){ if(is_authorized_for_service(temp_service,¤t_authdata)==FALSE) continue; if(strcmp(temp_service->host_name,temp_host->name)) continue; temp_servicestatus=find_servicestatus(temp_service->host_name,temp_service->description); if(temp_servicestatus==NULL) continue; if(temp_servicestatus->status==SERVICE_CRITICAL) services_critical++; else if(temp_servicestatus->status==SERVICE_UNKNOWN) services_unknown++; else if(temp_servicestatus->status==SERVICE_WARNING) services_warning++; else if(temp_servicestatus->status==SERVICE_PENDING) services_pending++; else services_ok++; } } printf("\n"); printf("\n"); printf("
Hosts:"); found=0; if(hosts_unreachable>0){ printf("%d UNR",hosts_unreachable); found=1; } if(hosts_down>0){ printf("%s%d DWN",(found==1)?", ":"",hosts_down); found=1; } if(hosts_pending>0){ printf("%s%d PND",(found==1)?", ":"",hosts_pending); found=1; } printf("%s%d UP",(found==1)?", ":"",hosts_up); printf("
Services:"); found=0; if(services_critical>0){ printf("%d CRI",services_critical); found=1; } if(services_warning>0){ printf("%s%d WRN",(found==1)?", ":"",services_warning); found=1; } if(services_unknown>0){ printf("%s%d UNK",(found==1)?", ":"",services_unknown); found=1; } if(services_pending>0){ printf("%s%d PND",(found==1)?", ":"",services_pending); found=1; } printf("%s%d OK",(found==1)?", ":"",services_ok); printf("
\n"); printf("
\n"); } if(show_all_hostgroups==FALSE) printf("View All Hostgroups\n",STATUSWML_CGI); printf("

\n"); printf("
\n"); return; } /* displays host status */ void display_host(void){ host *temp_host; hoststatus *temp_hoststatus; char last_check[MAX_DATETIME_LENGTH]; int days; int hours; int minutes; int seconds; time_t current_time; time_t t; char state_duration[48]; int found; /**** MAIN SCREEN (CARD 1) ****/ printf("\n"); printf("

\n"); printf("Host '%s'
\n",host_name); /* find the host */ temp_host=find_host(host_name,NULL); temp_hoststatus=find_hoststatus(host_name); if(temp_host==NULL || temp_hoststatus==NULL){ printf("Error: Could not find host!\n"); printf("

\n"); printf("
\n"); return; } /* check authorization */ if(is_authorized_for_host(temp_host,¤t_authdata)==FALSE){ printf("Error: Not authorized for host!\n"); printf("

\n"); printf("\n"); return; } printf("\n"); printf("\n"); printf("\n",temp_hoststatus->information); get_time_string(&temp_hoststatus->last_check,last_check,sizeof(last_check)-1,SHORT_DATE_TIME); printf("\n",last_check); current_time=time(NULL); if(temp_hoststatus->last_state_change==(time_t)0) t=current_time-program_start; else t=current_time-temp_hoststatus->last_state_change; get_time_breakdown((unsigned long)t,&days,&hours,&minutes,&seconds); snprintf(state_duration,sizeof(state_duration)-1,"%2dd %2dh %2dm %2ds%s",days,hours,minutes,seconds,(temp_hoststatus->last_state_change==(time_t)0)?"+":""); printf("\n",state_duration); printf("\n"); printf("
Status:"); if(temp_hoststatus->status==HOST_UP) printf("UP"); else if(temp_hoststatus->status==HOST_PENDING) printf("PENDING"); else if(temp_hoststatus->status==HOST_DOWN) printf("DOWN"); else if(temp_hoststatus->status==HOST_UNREACHABLE) printf("UNREACHABLE"); else printf("?"); printf("
Info:%s
Last Check:%s
Duration:%s
Properties:"); found=0; if(temp_hoststatus->checks_enabled==FALSE){ printf("%sChecks disabled",(found==1)?", ":""); found=1; } if(temp_hoststatus->notifications_enabled==FALSE){ printf("%sNotifications disabled",(found==1)?", ":""); found=1; } if(temp_hoststatus->problem_has_been_acknowledged==TRUE){ printf("%sProblem acknowledged",(found==1)?", ":""); found=1; } if(temp_hoststatus->scheduled_downtime_depth>0){ printf("%sIn scheduled downtime",(found==1)?", ":""); found=1; } if(found==0) printf("N/A"); printf("
\n"); printf("
\n"); printf("View Services\n",STATUSWML_CGI,host_name); printf("Host Commands\n"); printf("

\n"); printf("\n"); /**** COMMANDS SCREEN (CARD 2) ****/ printf("\n"); printf("

\n"); printf("Host Commands
\n"); printf("Ping Host\n",STATUSWML_CGI,temp_host->address); printf("Traceroute\n",STATUSWML_CGI,temp_host->address); if(temp_hoststatus->status!=HOST_UP && temp_hoststatus->status!=HOST_PENDING) printf("Acknowledge Problem\n"); if(temp_hoststatus->checks_enabled==FALSE) printf("Enable Host Checks
\n",COMMAND_CGI,host_name,CMD_ENABLE_HOST_CHECK,CMDMODE_COMMIT); else printf("Disable Host Checks
\n",COMMAND_CGI,host_name,CMD_DISABLE_HOST_CHECK,CMDMODE_COMMIT); if(temp_hoststatus->notifications_enabled==FALSE) printf("Enable Host Notifications
\n",COMMAND_CGI,host_name,CMD_ENABLE_HOST_NOTIFICATIONS,CMDMODE_COMMIT); else printf("Disable Host Notifications
\n",COMMAND_CGI,host_name,CMD_DISABLE_HOST_NOTIFICATIONS,CMDMODE_COMMIT); printf("Enable All Service Checks
\n",COMMAND_CGI,host_name,CMD_ENABLE_HOST_SVC_CHECKS,CMDMODE_COMMIT); printf("Disable All Service Checks
\n",COMMAND_CGI,host_name,CMD_DISABLE_HOST_SVC_CHECKS,CMDMODE_COMMIT); printf("Enable All Service Notifications
\n",COMMAND_CGI,host_name,CMD_ENABLE_HOST_SVC_NOTIFICATIONS,CMDMODE_COMMIT); printf("Disable All Service Notifications
\n",COMMAND_CGI,host_name,CMD_DISABLE_HOST_SVC_NOTIFICATIONS,CMDMODE_COMMIT); printf("

\n"); printf("
\n"); /**** ACKNOWLEDGEMENT SCREEN (CARD 3) ****/ printf("\n"); printf("

\n"); printf("Acknowledge Problem
\n"); printf("

\n"); printf("

\n"); printf("Your Name:
\n"); printf("
\n"); printf("Comment:
\n"); printf("\n"); printf("\n"); printf("\n",COMMAND_CGI,host_name,CMD_ACKNOWLEDGE_HOST_PROBLEM,CMDMODE_COMMIT); printf("\n"); printf("

\n"); printf("
\n"); return; } /* displays services on a host */ void display_host_services(void){ service *temp_service; servicestatus *temp_servicestatus; /**** MAIN SCREEN (CARD 1) ****/ printf("\n"); printf("

\n"); printf("Host '%s' Services
\n",host_name,host_name,STATUSWML_CGI,host_name); printf("\n"); /* check all services */ for(temp_service=service_list;temp_service!=NULL;temp_service=temp_service->next){ if(is_authorized_for_service(temp_service,¤t_authdata)==FALSE) continue; if(strcmp(temp_service->host_name,host_name)) continue; temp_servicestatus=find_servicestatus(temp_service->host_name,temp_service->description); if(temp_servicestatus==NULL) continue; printf("",STATUSWML_CGI,temp_service->host_name,temp_service->description); printf("\n",temp_service->description); } printf("
",temp_service->description); if(temp_servicestatus->status==SERVICE_OK || temp_servicestatus->status==SERVICE_RECOVERY) printf("OK"); else if(temp_servicestatus->status==SERVICE_PENDING) printf("PND"); else if(temp_servicestatus->status==SERVICE_WARNING) printf("WRN"); else if(temp_servicestatus->status==SERVICE_UNKNOWN) printf("UNK"); else if(temp_servicestatus->status==SERVICE_CRITICAL) printf("CRI"); else printf("???"); printf("%s
\n"); printf("

\n"); printf("
\n"); return; } /* displays service status */ void display_service(void){ service *temp_service; servicestatus *temp_servicestatus; char last_check[MAX_DATETIME_LENGTH]; int days; int hours; int minutes; int seconds; time_t current_time; time_t t; char state_duration[48]; int found; /**** MAIN SCREEN (CARD 1) ****/ printf("\n"); printf("

\n"); printf("Service '%s' on host '%s'
\n",service_desc,host_name); /* find the service */ temp_service=find_service(host_name,service_desc,NULL); temp_servicestatus=find_servicestatus(host_name,service_desc); if(temp_service==NULL || temp_servicestatus==NULL){ printf("Error: Could not find service!\n"); printf("

\n"); printf("
\n"); return; } /* check authorization */ if(is_authorized_for_service(temp_service,¤t_authdata)==FALSE){ printf("Error: Not authorized for service!\n"); printf("

\n"); printf("\n"); return; } printf("\n"); printf("\n"); printf("\n",temp_servicestatus->information); get_time_string(&temp_servicestatus->last_check,last_check,sizeof(last_check)-1,SHORT_DATE_TIME); printf("\n",last_check); current_time=time(NULL); if(temp_servicestatus->last_state_change==(time_t)0) t=current_time-program_start; else t=current_time-temp_servicestatus->last_state_change; get_time_breakdown((unsigned long)t,&days,&hours,&minutes,&seconds); snprintf(state_duration,sizeof(state_duration)-1,"%2dd %2dh %2dm %2ds%s",days,hours,minutes,seconds,(temp_servicestatus->last_state_change==(time_t)0)?"+":""); printf("\n",state_duration); printf("\n"); printf("
Status:"); if(temp_servicestatus->status==SERVICE_OK || temp_servicestatus->status==SERVICE_RECOVERY) printf("OK"); else if(temp_servicestatus->status==SERVICE_PENDING) printf("PENDING"); else if(temp_servicestatus->status==SERVICE_WARNING) printf("WARNING"); else if(temp_servicestatus->status==SERVICE_UNKNOWN) printf("UNKNOWN"); else if(temp_servicestatus->status==SERVICE_CRITICAL) printf("CRITICAL"); else printf("?"); printf("
Info:%s
Last Check:%s
Duration:%s
Properties:"); found=0; if(temp_servicestatus->checks_enabled==FALSE){ printf("%sChecks disabled",(found==1)?", ":""); found=1; } if(temp_servicestatus->notifications_enabled==FALSE){ printf("%sNotifications disabled",(found==1)?", ":""); found=1; } if(temp_servicestatus->problem_has_been_acknowledged==TRUE){ printf("%sProblem acknowledged",(found==1)?", ":""); found=1; } if(temp_servicestatus->scheduled_downtime_depth>0){ printf("%sIn scheduled downtime",(found==1)?", ":""); found=1; } if(found==0) printf("N/A"); printf("
\n"); printf("
\n"); printf("View Host\n",STATUSWML_CGI,host_name); printf("Svc. Commands\n"); printf("

\n"); printf("\n"); /**** COMMANDS SCREEN (CARD 2) ****/ printf("\n"); printf("

\n"); printf("Service Commands
\n"); if(temp_servicestatus->status!=SERVICE_OK && temp_servicestatus->status!=SERVICE_RECOVERY && temp_servicestatus->status!=SERVICE_PENDING) printf("Acknowledge Problem\n"); if(temp_servicestatus->checks_enabled==FALSE) printf("Enable Checks
\n",COMMAND_CGI,host_name,service_desc,CMD_ENABLE_SVC_CHECK,CMDMODE_COMMIT); else{ printf("Disable Checks
\n",COMMAND_CGI,host_name,service_desc,CMD_DISABLE_SVC_CHECK,CMDMODE_COMMIT); printf("Schedule Immediate Check
\n",COMMAND_CGI,host_name,service_desc,CMD_IMMEDIATE_SVC_CHECK,CMDMODE_COMMIT); } if(temp_servicestatus->notifications_enabled==FALSE) printf("Enable Notifications
\n",COMMAND_CGI,host_name,service_desc,CMD_ENABLE_SVC_NOTIFICATIONS,CMDMODE_COMMIT); else printf("Disable Notifications
\n",COMMAND_CGI,host_name,service_desc,CMD_DISABLE_SVC_NOTIFICATIONS,CMDMODE_COMMIT); printf("

\n"); printf("
\n"); /**** ACKNOWLEDGEMENT SCREEN (CARD 3) ****/ printf("\n"); printf("

\n"); printf("Acknowledge Problem
\n"); printf("

\n"); printf("

\n"); printf("Your Name:
\n"); printf("
\n"); printf("Comment:
\n"); printf("\n"); printf("\n"); printf("\n",COMMAND_CGI,host_name,service_desc,CMD_ACKNOWLEDGE_SVC_PROBLEM,CMDMODE_COMMIT); printf("\n"); printf("

\n"); printf("
\n"); return; } /* displays ping results */ void display_ping(void){ char buffer[MAX_INPUT_BUFFER]; FILE *fp; int odd=0; /**** MAIN SCREEN (CARD 1) ****/ printf("\n"); if(!strcmp(ping_address,"")){ printf("

\n"); printf("Ping Host
\n"); printf("

\n"); printf("

\n"); printf("Host Name/Address:
\n"); printf("\n"); printf("\n"); printf("\n",STATUSWML_CGI); printf("\n"); printf("

\n"); } else{ printf("

\n"); printf("Results For Ping Of %s:
\n",ping_address); printf("

\n"); printf("

\n"); /* send 5 ICMP echo packets */ #ifdef PING_PACKETS_FIRST snprintf(buffer,sizeof(buffer)-1,PING_COMMAND,5,ping_address); #else snprintf(buffer,sizeof(buffer)-1,PING_COMMAND,ping_address,5); #endif buffer[sizeof(buffer)-1]='\x0'; fp=popen(buffer,"r"); if(fp){ while(1){ fgets(buffer,sizeof(buffer)-1,fp); if(feof(fp)) break; strip(buffer); if(odd){ odd=0; printf("%s
\n",buffer); } else{ odd=1; printf("%s
\n",buffer); } } } else printf("Error executing ping!\n"); pclose(fp); printf("

\n"); } printf("
\n"); return; } /* displays traceroute results */ void display_traceroute(void){ char buffer[MAX_INPUT_BUFFER]; FILE *fp; int odd=0; /**** MAIN SCREEN (CARD 1) ****/ printf("\n"); if(!strcmp(traceroute_address,"")){ printf("

\n"); printf("Traceroute
\n"); printf("

\n"); printf("

\n"); printf("Host Name/Address:
\n"); printf("\n"); printf("\n"); printf("\n",STATUSWML_CGI); printf("\n"); printf("

\n"); } else{ printf("

\n"); printf("Results For Traceroute To %s:
\n",traceroute_address); printf("

\n"); printf("

\n"); snprintf(buffer,sizeof(buffer)-1,"%s %s",TRACEROUTE_COMMAND,traceroute_address); buffer[sizeof(buffer)-1]='\x0'; fp=popen(buffer,"r"); if(fp){ while(1){ fgets(buffer,sizeof(buffer)-1,fp); if(feof(fp)) break; strip(buffer); if(odd){ odd=0; printf("%s
\n",buffer); } else{ odd=1; printf("%s
\n",buffer); } } } else printf("Error executing traceroute!\n"); pclose(fp); printf("

\n"); } printf("
\n"); return; } /* displays problems */ void display_problems(void){ host *temp_host; service *temp_service; hoststatus *temp_hoststatus; int total_host_problems=0; servicestatus *temp_servicestatus; int total_service_problems=0; /**** MAIN SCREEN (CARD 1) ****/ printf("\n",(display_type==DISPLAY_ALL_PROBLEMS)?"All":"Unhandled"); printf("

\n"); printf("%s Problems

\n",(display_type==DISPLAY_ALL_PROBLEMS)?"All":"Unhandled"); printf("Host Problems:\n"); printf("\n"); /* check all hosts */ for(temp_hoststatus=hoststatus_list;temp_hoststatus!=NULL;temp_hoststatus=temp_hoststatus->next){ temp_host=find_host(temp_hoststatus->host_name,NULL); if(temp_host==NULL) continue; if(is_authorized_for_host(temp_host,¤t_authdata)==FALSE) continue; if(temp_hoststatus->status==HOST_UP || temp_hoststatus->status==HOST_PENDING) continue; if(display_type==DISPLAY_UNHANDLED_PROBLEMS){ if(temp_hoststatus->problem_has_been_acknowledged==TRUE) continue; if(temp_hoststatus->checks_enabled==FALSE) continue; if(temp_hoststatus->notifications_enabled==FALSE) continue; if(temp_hoststatus->scheduled_downtime_depth>0) continue; } total_host_problems++; printf("",STATUSWML_CGI,temp_host->name); printf("\n",temp_host->name); } if(total_host_problems==0) printf("\n"); printf("
",temp_host->name); if(temp_hoststatus->status==HOST_DOWN) printf("DWN"); else if(temp_hoststatus->status==HOST_UNREACHABLE) printf("UNR"); else printf("???"); printf("%s
No problems
\n"); printf("
\n"); printf("Svc Problems:\n"); printf("\n"); /* check all services */ for(temp_servicestatus=servicestatus_list;temp_servicestatus!=NULL;temp_servicestatus=temp_servicestatus->next){ temp_service=find_service(temp_servicestatus->host_name,temp_servicestatus->description,NULL); if(temp_service==NULL) continue; if(is_authorized_for_service(temp_service,¤t_authdata)==FALSE) continue; if(temp_servicestatus->status==SERVICE_OK || temp_servicestatus->status==SERVICE_RECOVERY || temp_servicestatus->status==SERVICE_PENDING) continue; if(display_type==DISPLAY_UNHANDLED_PROBLEMS){ if(temp_servicestatus->problem_has_been_acknowledged==TRUE) continue; if(temp_servicestatus->checks_enabled==FALSE) continue; if(temp_servicestatus->notifications_enabled==FALSE) continue; if(temp_servicestatus->scheduled_downtime_depth>0) continue; } total_service_problems++; printf("",STATUSWML_CGI,temp_service->host_name,temp_service->description); printf("\n",temp_service->host_name,temp_service->description); } if(total_service_problems==0) printf("\n"); printf("
",temp_servicestatus->description); if(temp_servicestatus->status==SERVICE_CRITICAL) printf("CRI"); else if(temp_servicestatus->status==SERVICE_WARNING) printf("WRN"); else if(temp_servicestatus->status==SERVICE_UNKNOWN) printf("UNK"); else printf("???"); printf("%s/%s
No problems
\n"); printf("

\n"); printf("
\n"); return; }