/************************************************************************** * * 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("
\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");
/* 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)){
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("",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(" ",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");
/* right column of top row */
printf("\n");
if(display_type==DISPLAY_HOST_INFO){
if(temp_hostextinfo!=NULL && temp_hostextinfo->notes_url!=NULL && strcmp(temp_hostextinfo->notes_url,"")){
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(" There Are Additional Notes For This Service...\n"); } } printf(" | \n");
/* end of top table */
printf("
\n"); printf("
| \n");
printf(" Program Information \n");
printf("
| \n");
printf(" \n");
printf(" Process Commands \n");
printf("
|
"); printf("
| Variable | Value |
|---|---|
| Process Status | %s |
| Process Check Command | %s |
| Check Command Output | %s |
| \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"); /* display comments */ display_comments(HOST_COMMENT); 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");
printf("
| \n");
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| \n"); /* display comments */ display_comments(SERVICE_COMMENT); printf(" | \n"); printf("|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| \n"); printf("Something..."); printf(" | \n"); */ printf("\n");
printf(" Hostgroup Commands \n");
if(netsaint_process_state==STATE_OK){
printf("
It appears as though NetSaint is not running, so commands are temporarily unavailable... \n",EXTINFO_CGI,DISPLAY_PROCESS_INFO);
}
printf("\n"); printf("Click here to view NetSaint process information | \n");
printf("
| Host Name | Entry Time | Author | Comment | Comment ID | Persistent | Actions |
|---|---|---|---|---|---|---|
| %s | ",bg_class,EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_comment->host_name),temp_comment->host_name); printf("%s | %s | %s | %d | %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"); printf("
| Host Name | Service | Entry Time | Author | Comment | Comment ID | Persistent | 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 | %d | %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"); printf("
\n");
printf("
| \n");
printf("
|
\n");
printf("
| \n");
printf("
|
| ",url_images_path,COMMENT_ICON); if(type==HOST_COMMENT) printf("",COMMAND_CGI,CMD_ADD_HOST_COMMENT,url_encode(host_name)); else{ printf("",url_encode(service_desc)); } printf("Add a new comment | |
| ",url_images_path,DELETE_ICON); if(type==HOST_COMMENT) printf("",COMMAND_CGI,CMD_DEL_ALL_HOST_COMMENTS,url_encode(host_name)); else{ printf("",url_encode(service_desc)); } printf("Delete all comments |
\n"); printf("