/************************************************************************** * * EXTINFO.C - Nagios Extended Information CGI * * Copyright (c) 1999-2007 Ethan Galstad (nagios@nagios.org) * Last Modified: 10-21-2007 * * 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/comments.h" #include "../include/downtime.h" #include "../include/statusdata.h" #include "../include/cgiutils.h" #include "../include/getcgi.h" #include "../include/cgiauth.h" extern char nagios_check_command[MAX_INPUT_BUFFER]; extern char nagios_process_info[MAX_INPUT_BUFFER]; extern int nagios_process_state; extern int refresh_rate; extern time_t program_start; extern int nagios_pid; extern int daemon_mode; extern time_t last_command_check; extern time_t last_log_rotation; extern int enable_notifications; extern int execute_service_checks; extern int accept_passive_service_checks; extern int execute_host_checks; extern int accept_passive_host_checks; extern int enable_event_handlers; extern int obsess_over_services; extern int obsess_over_hosts; extern int enable_flap_detection; extern int enable_failure_prediction; extern int process_performance_data; 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; extern scheduled_downtime *scheduled_downtime_list; extern hoststatus *hoststatus_list; extern servicestatus *servicestatus_list; extern hostgroup *hostgroup_list; extern servicegroup *servicegroup_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 result=OK; int found=FALSE; char temp_buffer[MAX_INPUT_BUFFER]; hostextinfo *temp_hostextinfo=NULL; serviceextinfo *temp_serviceextinfo=NULL; host *temp_host=NULL; hostgroup *temp_hostgroup=NULL; service *temp_service=NULL; servicegroup *temp_servicegroup=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(get_cgi_config_location()); if(result==ERROR){ document_header(FALSE); cgi_config_file_error(main_config_file); document_footer(); return ERROR; } /* read the main configuration file */ result=read_main_config_file(main_config_file); if(result==ERROR){ document_header(FALSE); main_config_file_error(main_config_file); document_footer(); return ERROR; } /* read all object configuration data */ result=read_all_object_configuration_data(main_config_file,READ_ALL_OBJECT_DATA); if(result==ERROR){ document_header(FALSE); object_data_error(); document_footer(); return ERROR; } /* read all status data */ result=read_all_status_data(get_cgi_config_location(),READ_ALL_STATUS_DATA); if(result==ERROR){ document_header(FALSE); status_data_error(); document_footer(); free_memory(); return ERROR; } document_header(TRUE); /* get authentication information */ get_authentication_information(¤t_authdata); if(display_header==TRUE){ /* begin top table */ 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);
if(display_type==DISPLAY_SERVICE_INFO)
temp_service=find_service(host_name,service_desc);
/* 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);
/* find the servicegroup */
else if(display_type==DISPLAY_SERVICEGROUP_INFO)
temp_servicegroup=find_servicegroup(servicegroup_name);
if(((display_type==DISPLAY_HOST_INFO || display_type==DISPLAY_SERVICE_INFO) && temp_host!=NULL) || (display_type==DISPLAY_HOSTGROUP_INFO && temp_hostgroup!=NULL) || (display_type==DISPLAY_SERVICEGROUP_INFO && temp_servicegroup!=NULL)){
printf("
| \n");
/* middle column of top row */
printf("\n");
if(((display_type==DISPLAY_HOST_INFO || display_type==DISPLAY_SERVICE_INFO) && temp_host!=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); 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(display_type==DISPLAY_SERVICEGROUP_INFO){
printf("Servicegroup \n");
printf("%s \n",temp_servicegroup->alias);
printf("(%s) \n",temp_servicegroup->group_name);
}
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("",(temp_serviceextinfo->icon_image_alt==NULL)?"":temp_serviceextinfo->icon_image_alt,(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(temp_serviceextinfo->notes!=NULL) printf(" %s \n",temp_serviceextinfo->notes); } } if(display_type==DISPLAY_HOST_INFO){ temp_hostextinfo=find_hostextinfo(host_name); if(temp_hostextinfo!=NULL){ if(temp_hostextinfo->icon_image!=NULL){ printf("",(temp_hostextinfo->icon_image_alt==NULL)?"":temp_hostextinfo->icon_image_alt,(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); if(temp_hostextinfo->notes!=NULL) printf(" %s \n",temp_hostextinfo->notes); } } } printf(" | \n");
/* right column of top row */
printf("\n"); if(display_type==DISPLAY_HOST_INFO){ if(temp_hostextinfo!=NULL){ printf(" | \n"); /* end of top table */ printf("
\n"); printf("
| \n");
printf(" Process Information \n");
printf("
| \n");
printf(" Process Commands \n");
printf("
|
"); 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"); /* display comments */ display_comments(HOST_COMMENT); 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"); /* display comments */ display_comments(SERVICE_COMMENT); printf(" | \n"); printf("|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| \n"); /* right top panel */ printf(" | \n");
printf(" Hostgroup Commands \n");
if(nagios_process_state==STATE_OK){
printf("
It appears as though Nagios is not running, so commands are temporarily unavailable... \n",EXTINFO_CGI,DISPLAY_PROCESS_INFO);
}
printf("\n"); printf("Click here to view Nagios process information | |||||||||||||||||
| \n"); printf(" |
| \n"); /* right top panel */ printf(" | \n");
printf(" Servicegroup Commands \n");
if(nagios_process_state==STATE_OK){
printf("
It appears as though Nagios is not running, so commands are temporarily unavailable... \n",EXTINFO_CGI,DISPLAY_PROCESS_INFO);
}
printf("\n"); printf("Click here to view Nagios process information | |||||||||||||||||
| \n"); printf(" |
\n"); printf("
\n"); printf("
| Host Name | Entry Time | Author | Comment | Comment ID | Persistent | Type | Expires | Actions |
|---|---|---|---|---|---|---|---|---|
| %s | ",bg_class,EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_comment->host_name),temp_comment->host_name); printf("%s | %s | %s | %ld | %s | %s | %s | ",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"); printf("|
| There are no host comments | ||||||||
\n"); printf("
| Host Name | Service | Entry Time | Author | Comment | Comment ID | Persistent | Type | Expires | Actions |
|---|---|---|---|---|---|---|---|---|---|
| %s | ",bg_class,EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_comment->host_name),temp_comment->host_name); printf("%s | ",url_encode(temp_comment->service_description),temp_comment->service_description); printf("%s | %s | %s | %ld | %s | %s | %s | ",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"); printf("|
| There are no service comments | |||||||||
Active Service Checks: | \n");
printf("\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("||||||||||||||||||||||||||||||
Passive Service Checks: | \n");
printf("\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("||||||||||||||||||||||||||||||
Active Host Checks: | \n");
printf("\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("||||||||||||||||||||||||||||||
Passive Host Checks: | \n");
printf("\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("
| ",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("
| Host Name | Entry Time | Author | Comment | Start Time | End Time | Type | Duration | Downtime ID | Trigger ID | Actions |
|---|---|---|---|---|---|---|---|---|---|---|
| %s | ",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("%s | ",bg_class,date_time); printf("%s | ",bg_class,(temp_downtime->author==NULL)?"N/A":temp_downtime->author); printf("%s | ",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("%s | ",bg_class,date_time); get_time_string(&temp_downtime->end_time,date_time,(int)sizeof(date_time),SHORT_DATE_TIME); printf("%s | ",bg_class,date_time); printf("%s | ",bg_class,(temp_downtime->fixed==TRUE)?"Fixed":"Flexible"); get_time_breakdown(temp_downtime->duration,&days,&hours,&minutes,&seconds); printf("%dd %dh %dm %ds | ",bg_class,days,hours,minutes,seconds); printf("%lu | ",bg_class,temp_downtime->downtime_id); printf("",bg_class); if(temp_downtime->triggered_by==0) printf("N/A"); else printf("%lu",temp_downtime->triggered_by); printf(" | \n"); printf("|
| There are no hosts with scheduled downtime | ||||||||||
\n"); printf("
| Host Name | Service | Entry Time | Author | Comment | Start Time | End Time | Type | Duration | Downtime ID | Trigger ID | Actions |
|---|---|---|---|---|---|---|---|---|---|---|---|
| %s | ",bg_class,EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_downtime->host_name),temp_downtime->host_name); printf("%s | ",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("%s | ",bg_class,date_time); printf("%s | ",bg_class,(temp_downtime->author==NULL)?"N/A":temp_downtime->author); printf("%s | ",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("%s | ",bg_class,date_time); get_time_string(&temp_downtime->end_time,date_time,(int)sizeof(date_time),SHORT_DATE_TIME); printf("%s | ",bg_class,date_time); printf("%s | ",bg_class,(temp_downtime->fixed==TRUE)?"Fixed":"Flexible"); get_time_breakdown(temp_downtime->duration,&days,&hours,&minutes,&seconds); printf("%dd %dh %dm %ds | ",bg_class,days,hours,minutes,seconds); printf("%lu | ",bg_class,temp_downtime->downtime_id); printf("",bg_class); if(temp_downtime->triggered_by==0) printf("N/A"); else printf("%lu",temp_downtime->triggered_by); printf(" | \n"); printf("|
| There are no services with scheduled downtime | |||||||||||
\n"); printf("
| Host | ",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("Service | ",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("Last Check | ",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("Next Check | ",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("Active Checks | Actions | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| %s | ",bgclass,EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_svcstatus->host_name),temp_svcstatus->host_name); printf("%s | ",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("%s | ",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("%s | ",bgclass,(temp_svcstatus->next_check==(time_t)0)?"N/A":date_time); printf("%s | ",(temp_svcstatus->checks_enabled==TRUE)?"ENABLED":"DISABLED",(temp_svcstatus->checks_enabled==TRUE)?"ENABLED":"DISABLED"); printf("",bgclass);
if(temp_svcstatus->checks_enabled==TRUE){
printf(" | \n");
}
/* get the host status */
else{
printf("%s | ",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(" | %s | ",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("%s | ",bgclass,(temp_hststatus->next_check==(time_t)0)?"N/A":date_time); printf("%s | ",(temp_hststatus->checks_enabled==TRUE)?"ENABLED":"DISABLED",(temp_hststatus->checks_enabled==TRUE)?"ENABLED":"DISABLED"); printf("",bgclass);
if(temp_hststatus->checks_enabled==TRUE){
printf(" | \n");
}
printf("