/**************************************************************************
*
* STATUS.C - Nagios Status 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/statusdata.h"
#include "../include/cgiutils.h"
#include "../include/getcgi.h"
#include "../include/cgiauth.h"
extern int refresh_rate;
extern time_t program_start;
extern char main_config_file[MAX_FILENAME_LENGTH];
extern char url_html_path[MAX_FILENAME_LENGTH];
extern char url_docs_path[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH];
extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
extern char url_logo_images_path[MAX_FILENAME_LENGTH];
extern char url_media_path[MAX_FILENAME_LENGTH];
extern char log_file[MAX_FILENAME_LENGTH];
extern char *service_critical_sound;
extern char *service_warning_sound;
extern char *service_unknown_sound;
extern char *host_down_sound;
extern char *host_unreachable_sound;
extern char *normal_sound;
extern int suppress_alert_window;
extern host *host_list;
extern service *service_list;
extern hostgroup *hostgroup_list;
extern servicegroup *servicegroup_list;
extern hoststatus *hoststatus_list;
extern servicestatus *servicestatus_list;
#define MAX_MESSAGE_BUFFER 4096
#define DISPLAY_HOSTS 0
#define DISPLAY_HOSTGROUPS 1
#define DISPLAY_SERVICEGROUPS 2
#define STYLE_OVERVIEW 0
#define STYLE_DETAIL 1
#define STYLE_SUMMARY 2
#define STYLE_GRID 3
#define STYLE_HOST_DETAIL 4
/* HOSTSORT structure */
typedef struct hostsort_struct{
hoststatus *hststatus;
struct hostsort_struct *next;
}hostsort;
/* SERVICESORT structure */
typedef struct servicesort_struct{
servicestatus *svcstatus;
struct servicesort_struct *next;
}servicesort;
hostsort *hostsort_list=NULL;
servicesort *servicesort_list=NULL;
int sort_services(int,int); /* sorts services */
int sort_hosts(int,int); /* sorts hosts */
int compare_servicesort_entries(int,int,servicesort *,servicesort *); /* compares service sort entries */
int compare_hostsort_entries(int,int,hostsort *,hostsort *); /* compares host sort entries */
void free_servicesort_list(void);
void free_hostsort_list(void);
void show_host_status_totals(void);
void show_service_status_totals(void);
void show_service_detail(void);
void show_host_detail(void);
void show_servicegroup_overviews(void);
void show_servicegroup_overview(servicegroup *);
void show_servicegroup_summaries(void);
void show_servicegroup_summary(servicegroup *,int);
void show_servicegroup_host_totals_summary(servicegroup *);
void show_servicegroup_service_totals_summary(servicegroup *);
void show_servicegroup_grids(void);
void show_servicegroup_grid(servicegroup *);
void show_hostgroup_overviews(void);
void show_hostgroup_overview(hostgroup *);
void show_servicegroup_hostgroup_member_overview(hoststatus *,int,void *);
void show_servicegroup_hostgroup_member_service_status_totals(char *,void *);
void show_hostgroup_summaries(void);
void show_hostgroup_summary(hostgroup *,int);
void show_hostgroup_host_totals_summary(hostgroup *);
void show_hostgroup_service_totals_summary(hostgroup *);
void show_hostgroup_grids(void);
void show_hostgroup_grid(hostgroup *);
void show_filters(void);
int passes_host_properties_filter(hoststatus *);
int passes_service_properties_filter(servicestatus *);
void document_header(int);
void document_footer(void);
int process_cgivars(void);
authdata current_authdata;
time_t current_time;
char alert_message[MAX_MESSAGE_BUFFER];
char *host_name=NULL;
char *hostgroup_name=NULL;
char *servicegroup_name=NULL;
char *service_filter=NULL;
int host_alert=FALSE;
int show_all_hosts=TRUE;
int show_all_hostgroups=TRUE;
int show_all_servicegroups=TRUE;
int display_type=DISPLAY_HOSTS;
int overview_columns=3;
int max_grid_width=8;
int group_style_type=STYLE_OVERVIEW;
int navbar_search=FALSE;
int service_status_types=SERVICE_PENDING|SERVICE_OK|SERVICE_UNKNOWN|SERVICE_WARNING|SERVICE_CRITICAL;
int all_service_status_types=SERVICE_PENDING|SERVICE_OK|SERVICE_UNKNOWN|SERVICE_WARNING|SERVICE_CRITICAL;
int host_status_types=HOST_PENDING|HOST_UP|HOST_DOWN|HOST_UNREACHABLE;
int all_host_status_types=HOST_PENDING|HOST_UP|HOST_DOWN|HOST_UNREACHABLE;
int all_service_problems=SERVICE_UNKNOWN|SERVICE_WARNING|SERVICE_CRITICAL;
int all_host_problems=HOST_DOWN|HOST_UNREACHABLE;
unsigned long host_properties=0L;
unsigned long service_properties=0L;
int sort_type=SORT_NONE;
int sort_option=SORT_HOSTNAME;
int problem_hosts_down=0;
int problem_hosts_unreachable=0;
int problem_services_critical=0;
int problem_services_warning=0;
int problem_services_unknown=0;
int embedded=FALSE;
int display_header=TRUE;
int main(void){
int result=OK;
char *sound=NULL;
host *temp_host=NULL;
hostgroup *temp_hostgroup=NULL;
servicegroup *temp_servicegroup=NULL;
time(¤t_time);
/* 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(get_cgi_config_location());
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);
/* read in all host and service comments */
read_comment_data(get_cgi_config_location());
/* get authentication information */
get_authentication_information(¤t_authdata);
/* if a navbar search was performed, find the host by name, address or partial name */
if(navbar_search==TRUE){
if((temp_host=find_host(host_name))==NULL){
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(!strcmp(host_name,temp_host->address)){
free(host_name);
host_name=strdup(temp_host->name);
break;
}
}
if(temp_host==NULL){
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((strstr(temp_host->name,host_name)==temp_host->name) || !strncasecmp(temp_host->name,host_name,strlen(host_name))){
free(host_name);
host_name=strdup(temp_host->name);
break;
}
}
}
}
/* last effort, search hostgroups then servicegroups */
if(temp_host==NULL){
if((temp_hostgroup=find_hostgroup(host_name))!=NULL){
display_type=DISPLAY_HOSTGROUPS;
show_all_hostgroups=FALSE;
free(host_name);
hostgroup_name=strdup(temp_hostgroup->group_name);
}
else if((temp_servicegroup=find_servicegroup(host_name))!=NULL){
display_type=DISPLAY_SERVICEGROUPS;
show_all_servicegroups=FALSE;
free(host_name);
servicegroup_name=strdup(temp_servicegroup->group_name);
}
}
}
if(display_header==TRUE){
/* begin top table */
printf("
\n");
printf("
\n");
/* left column of the first row */
printf("
\n");
/* info table */
display_info_table("Current Network Status",TRUE,¤t_authdata);
printf("
\n");
printf("
\n");
if(display_type==DISPLAY_HOSTS){
printf("View History For %s \n",HISTORY_CGI,(show_all_hosts==TRUE)?"all":url_encode(host_name),(show_all_hosts==TRUE)?"all hosts":"This Host");
printf("View Notifications For %s\n",NOTIFICATIONS_CGI,(show_all_hosts==TRUE)?"all":url_encode(host_name),(show_all_hosts==TRUE)?"All Hosts":"This Host");
if(show_all_hosts==FALSE)
printf(" View Service Status Detail For All Hosts\n",STATUS_CGI);
else
printf(" View Host Status Detail For All Hosts\n",STATUS_CGI);
}
else if(display_type==DISPLAY_SERVICEGROUPS){
if(show_all_servicegroups==FALSE){
if(group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_GRID || group_style_type==STYLE_SUMMARY)
printf("View Service Status Detail For This Service Group \n",STATUS_CGI,url_encode(servicegroup_name));
if(group_style_type==STYLE_DETAIL || group_style_type==STYLE_GRID || group_style_type==STYLE_SUMMARY)
printf("View Status Overview For This Service Group \n",STATUS_CGI,url_encode(servicegroup_name));
if(group_style_type==STYLE_DETAIL || group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_GRID)
printf("View Status Summary For This Service Group \n",STATUS_CGI,url_encode(servicegroup_name));
if(group_style_type==STYLE_DETAIL || group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_SUMMARY)
printf("View Service Status Grid For This Service Group \n",STATUS_CGI,url_encode(servicegroup_name));
if(group_style_type==STYLE_DETAIL)
printf("View Service Status Detail For All Service Groups \n",STATUS_CGI);
if(group_style_type==STYLE_OVERVIEW)
printf("View Status Overview For All Service Groups \n",STATUS_CGI);
if(group_style_type==STYLE_SUMMARY)
printf("View Status Summary For All Service Groups \n",STATUS_CGI);
if(group_style_type==STYLE_GRID)
printf("View Service Status Grid For All Service Groups \n",STATUS_CGI);
}
else{
if(group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_GRID || group_style_type==STYLE_SUMMARY)
printf("View Service Status Detail For All Service Groups \n",STATUS_CGI);
if(group_style_type==STYLE_DETAIL || group_style_type==STYLE_GRID || group_style_type==STYLE_SUMMARY)
printf("View Status Overview For All Service Groups \n",STATUS_CGI);
if(group_style_type==STYLE_DETAIL || group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_GRID)
printf("View Status Summary For All Service Groups \n",STATUS_CGI);
if(group_style_type==STYLE_DETAIL || group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_SUMMARY)
printf("View Service Status Grid For All Service Groups \n",STATUS_CGI);
}
}
else{
if(show_all_hostgroups==FALSE){
if(group_style_type==STYLE_DETAIL)
printf("View Service Status Detail For All Host Groups \n",STATUS_CGI);
if(group_style_type==STYLE_HOST_DETAIL)
printf("View Host Status Detail For All Host Groups \n",STATUS_CGI);
if(group_style_type==STYLE_OVERVIEW)
printf("View Status Overview For All Host Groups \n",STATUS_CGI);
if(group_style_type==STYLE_SUMMARY)
printf("View Status Summary For All Host Groups \n",STATUS_CGI);
if(group_style_type==STYLE_GRID)
printf("View Status Grid For All Host Groups \n",STATUS_CGI);
if(group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_SUMMARY || group_style_type==STYLE_GRID || group_style_type==STYLE_HOST_DETAIL)
printf("View Service Status Detail For This Host Group \n",STATUS_CGI,url_encode(hostgroup_name));
if(group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_DETAIL || group_style_type==STYLE_SUMMARY || group_style_type==STYLE_GRID)
printf("View Host Status Detail For This Host Group \n",STATUS_CGI,url_encode(hostgroup_name));
if(group_style_type==STYLE_DETAIL || group_style_type==STYLE_SUMMARY || group_style_type==STYLE_GRID || group_style_type==STYLE_HOST_DETAIL)
printf("View Status Overview For This Host Group \n",STATUS_CGI,url_encode(hostgroup_name));
if(group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_DETAIL || group_style_type==STYLE_GRID || group_style_type==STYLE_HOST_DETAIL)
printf("View Status Summary For This Host Group \n",STATUS_CGI,url_encode(hostgroup_name));
if(group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_DETAIL || group_style_type==STYLE_SUMMARY || group_style_type==STYLE_HOST_DETAIL)
printf("View Status Grid For This Host Group \n",STATUS_CGI,url_encode(hostgroup_name));
}
else{
if(group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_SUMMARY || group_style_type==STYLE_GRID || group_style_type==STYLE_HOST_DETAIL)
printf("View Service Status Detail For All Host Groups \n",STATUS_CGI);
if(group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_DETAIL || group_style_type==STYLE_SUMMARY || group_style_type==STYLE_GRID)
printf("View Host Status Detail For All Host Groups \n",STATUS_CGI);
if(group_style_type==STYLE_DETAIL || group_style_type==STYLE_SUMMARY || group_style_type==STYLE_GRID || group_style_type==STYLE_HOST_DETAIL)
printf("View Status Overview For All Host Groups \n",STATUS_CGI);
if(group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_DETAIL || group_style_type==STYLE_GRID || group_style_type==STYLE_HOST_DETAIL)
printf("View Status Summary For All Host Groups \n",STATUS_CGI);
if(group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_DETAIL || group_style_type==STYLE_SUMMARY || group_style_type==STYLE_HOST_DETAIL)
printf("View Status Grid For All Host Groups \n",STATUS_CGI);
}
}
printf("
\n");
printf("
\n");
printf("
\n");
/* middle column of top row */
printf("
\n");
show_host_status_totals();
printf("
\n");
/* right hand column of top row */
printf("
\n");
show_service_status_totals();
printf("
\n");
/* display context-sensitive help */
printf("
\n",(total_problems>0)?"PROBLEMS":"",total_problems);
/* total hosts */
printf("
%d
\n",total_hosts);
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
printf("\n");
return;
}
/* display a detailed listing of the status of all services... */
void show_service_detail(void){
regex_t preg;
time_t t;
char date_time[MAX_DATETIME_LENGTH];
char state_duration[48];
char status[MAX_INPUT_BUFFER];
char temp_buffer[MAX_INPUT_BUFFER];
char temp_url[MAX_INPUT_BUFFER];
char *status_class="";
char *status_bg_class="";
char *host_status_bg_class="";
char *last_host="";
int new_host=FALSE;
servicestatus *temp_status=NULL;
hostgroup *temp_hostgroup=NULL;
servicegroup *temp_servicegroup=NULL;
hostextinfo *temp_hostextinfo=NULL;
serviceextinfo *temp_serviceextinfo=NULL;
hoststatus *temp_hoststatus=NULL;
host *temp_host=NULL;
service *temp_service=NULL;
int odd=0;
int total_comments=0;
int user_has_seen_something=FALSE;
servicesort *temp_servicesort=NULL;
int use_sort=FALSE;
int result=OK;
int first_entry=TRUE;
int days;
int hours;
int minutes;
int seconds;
int duration_error=FALSE;
int total_entries=0;
int show_service=FALSE;
/* sort the service list if necessary */
if(sort_type!=SORT_NONE){
result=sort_services(sort_type,sort_option);
if(result==ERROR)
use_sort=FALSE;
else
use_sort=TRUE;
}
else
use_sort=FALSE;
printf("
\n");
if(service_filter!=NULL)
regcomp(&preg,service_filter,0);
temp_hostgroup=find_hostgroup(hostgroup_name);
temp_servicegroup=find_servicegroup(servicegroup_name);
/* check all services... */
while(1){
/* get the next service to display */
if(use_sort==TRUE){
if(first_entry==TRUE)
temp_servicesort=servicesort_list;
else
temp_servicesort=temp_servicesort->next;
if(temp_servicesort==NULL)
break;
temp_status=temp_servicesort->svcstatus;
}
else{
if(first_entry==TRUE)
temp_status=servicestatus_list;
else
temp_status=temp_status->next;
}
if(temp_status==NULL)
break;
first_entry=FALSE;
/* find the service */
temp_service=find_service(temp_status->host_name,temp_status->description);
/* if we couldn't find the service, go to the next service */
if(temp_service==NULL)
continue;
/* find the host */
temp_host=find_host(temp_service->host_name);
/* make sure user has rights to see this... */
if(is_authorized_for_service(temp_service,¤t_authdata)==FALSE)
continue;
user_has_seen_something=TRUE;
/* get the host status information */
temp_hoststatus=find_hoststatus(temp_service->host_name);
/* see if we should display services for hosts with tis type of status */
if(!(host_status_types & temp_hoststatus->status))
continue;
/* see if we should display this type of service status */
if(!(service_status_types & temp_status->status))
continue;
/* check host properties filter */
if(passes_host_properties_filter(temp_hoststatus)==FALSE)
continue;
/* check service properties filter */
if(passes_service_properties_filter(temp_status)==FALSE)
continue;
/* servicefilter cgi var */
if(service_filter!=NULL)
if(regexec(&preg,temp_status->description,0,NULL,0))
continue;
show_service=FALSE;
if(display_type==DISPLAY_HOSTS){
if(show_all_hosts==TRUE)
show_service=TRUE;
else if(!strcmp(host_name,temp_status->host_name))
show_service=TRUE;
}
else if(display_type==DISPLAY_HOSTGROUPS){
if(show_all_hostgroups==TRUE)
show_service=TRUE;
else if(is_host_member_of_hostgroup(temp_hostgroup,temp_host)==TRUE)
show_service=TRUE;
}
else if(display_type==DISPLAY_SERVICEGROUPS){
if(show_all_servicegroups==TRUE)
show_service=TRUE;
else if(is_service_member_of_servicegroup(temp_servicegroup,temp_service)==TRUE)
show_service=TRUE;
}
if(show_service==TRUE){
if(strcmp(last_host,temp_status->host_name))
new_host=TRUE;
else
new_host=FALSE;
if(new_host==TRUE){
if(strcmp(last_host,"")){
printf("
\n");
printf("
\n");
}
}
if(odd)
odd=0;
else
odd=1;
/* keep track of total number of services we're displaying */
total_entries++;
/* get the last service check time */
t=temp_status->last_check;
get_time_string(&t,date_time,(int)sizeof(date_time),SHORT_DATE_TIME);
if((unsigned long)temp_status->last_check==0L)
strcpy(date_time,"N/A");
if(temp_status->status==SERVICE_PENDING){
strncpy(status,"PENDING",sizeof(status));
status_class="PENDING";
status_bg_class=(odd)?"Even":"Odd";
}
else if(temp_status->status==SERVICE_OK){
strncpy(status,"OK",sizeof(status));
status_class="OK";
status_bg_class=(odd)?"Even":"Odd";
}
else if(temp_status->status==SERVICE_WARNING){
strncpy(status,"WARNING",sizeof(status));
status_class="WARNING";
if(temp_status->problem_has_been_acknowledged==TRUE)
status_bg_class="BGWARNINGACK";
else if(temp_status->scheduled_downtime_depth>0)
status_bg_class="BGWARNINGSCHED";
else
status_bg_class="BGWARNING";
}
else if(temp_status->status==SERVICE_UNKNOWN){
strncpy(status,"UNKNOWN",sizeof(status));
status_class="UNKNOWN";
if(temp_status->problem_has_been_acknowledged==TRUE)
status_bg_class="BGUNKNOWNACK";
else if(temp_status->scheduled_downtime_depth>0)
status_bg_class="BGUNKNOWNSCHED";
else
status_bg_class="BGUNKNOWN";
}
else if(temp_status->status==SERVICE_CRITICAL){
strncpy(status,"CRITICAL",sizeof(status));
status_class="CRITICAL";
if(temp_status->problem_has_been_acknowledged==TRUE)
status_bg_class="BGCRITICALACK";
else if(temp_status->scheduled_downtime_depth>0)
status_bg_class="BGCRITICALSCHED";
else
status_bg_class="BGCRITICAL";
}
status[sizeof(status)-1]='\x0';
printf("
\n");
/* host name column */
if(new_host==TRUE){
/* find extended information for this host */
temp_hostextinfo=find_hostextinfo(temp_status->host_name);
if(temp_hoststatus->status==HOST_DOWN){
if(temp_hoststatus->problem_has_been_acknowledged==TRUE)
host_status_bg_class="HOSTDOWNACK";
else if(temp_hoststatus->scheduled_downtime_depth>0)
host_status_bg_class="HOSTDOWNSCHED";
else
host_status_bg_class="HOSTDOWN";
}
else if(temp_hoststatus->status==HOST_UNREACHABLE){
if(temp_hoststatus->problem_has_been_acknowledged==TRUE)
host_status_bg_class="HOSTUNREACHABLEACK";
else if(temp_hoststatus->scheduled_downtime_depth>0)
host_status_bg_class="HOSTUNREACHABLESCHED";
else
host_status_bg_class="HOSTUNREACHABLE";
}
else
host_status_bg_class=(odd)?"Even":"Odd";
printf("
\n");
/* if user couldn't see anything, print out some helpful info... */
if(user_has_seen_something==FALSE){
if(servicestatus_list!=NULL){
printf("
It appears as though you do not have permission to view information for any of the services you requested...
\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");
}
else{
printf("
There doesn't appear to be any service status information in the status log...
\n");
printf("Make sure that Nagios is running and that you have specified the location of you status log correctly in the configuration files.
\n");
}
}
else
printf("
%d Matching Service Entries Displayed
\n",total_entries);
return;
}
/* display a detailed listing of the status of all hosts... */
void show_host_detail(void){
time_t t;
char date_time[MAX_DATETIME_LENGTH];
char state_duration[48];
char status[MAX_INPUT_BUFFER];
char temp_buffer[MAX_INPUT_BUFFER];
char temp_url[MAX_INPUT_BUFFER];
char *status_class="";
char *status_bg_class="";
hoststatus *temp_status=NULL;
hostgroup *temp_hostgroup=NULL;
hostextinfo *temp_hostextinfo=NULL;
host *temp_host=NULL;
hostsort *temp_hostsort=NULL;
int odd=0;
int total_comments=0;
int user_has_seen_something=FALSE;
int use_sort=FALSE;
int result=OK;
int first_entry=TRUE;
int days;
int hours;
int minutes;
int seconds;
int duration_error=FALSE;
int total_entries=0;
/* sort the host list if necessary */
if(sort_type!=SORT_NONE){
result=sort_hosts(sort_type,sort_option);
if(result==ERROR)
use_sort=FALSE;
else
use_sort=TRUE;
}
else
use_sort=FALSE;
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
show_filters();
printf("
");
printf("
\n");
printf("
Host Status Details For ");
if(show_all_hostgroups==TRUE)
printf("All Host Groups");
else
printf("Host Group '%s'",hostgroup_name);
printf("
\n");
/* check all hosts... */
while(1){
/* get the next service to display */
if(use_sort==TRUE){
if(first_entry==TRUE)
temp_hostsort=hostsort_list;
else
temp_hostsort=temp_hostsort->next;
if(temp_hostsort==NULL)
break;
temp_status=temp_hostsort->hststatus;
}
else{
if(first_entry==TRUE)
temp_status=hoststatus_list;
else
temp_status=temp_status->next;
}
if(temp_status==NULL)
break;
first_entry=FALSE;
/* find the host */
temp_host=find_host(temp_status->host_name);
/* if we couldn't find the host, go to the next status entry */
if(temp_host==NULL)
continue;
/* make sure user has rights to see this... */
if(is_authorized_for_host(temp_host,¤t_authdata)==FALSE)
continue;
user_has_seen_something=TRUE;
/* see if we should display services for hosts with this type of status */
if(!(host_status_types & temp_status->status))
continue;
/* check host properties filter */
if(passes_host_properties_filter(temp_status)==FALSE)
continue;
/* see if this host is a member of the hostgroup */
if(show_all_hostgroups==FALSE){
temp_hostgroup=find_hostgroup(hostgroup_name);
if(temp_hostgroup==NULL)
continue;
if(is_host_member_of_hostgroup(temp_hostgroup,temp_host)==FALSE)
continue;
}
total_entries++;
if(display_type==DISPLAY_HOSTGROUPS){
if(odd)
odd=0;
else
odd=1;
/* get the last host check time */
t=temp_status->last_check;
get_time_string(&t,date_time,(int)sizeof(date_time),SHORT_DATE_TIME);
if((unsigned long)temp_status->last_check==0L)
strcpy(date_time,"N/A");
if(temp_status->status==HOST_PENDING){
strncpy(status,"PENDING",sizeof(status));
status_class="PENDING";
status_bg_class=(odd)?"Even":"Odd";
}
else if(temp_status->status==HOST_UP){
strncpy(status,"UP",sizeof(status));
status_class="HOSTUP";
status_bg_class=(odd)?"Even":"Odd";
}
else if(temp_status->status==HOST_DOWN){
strncpy(status,"DOWN",sizeof(status));
status_class="HOSTDOWN";
if(temp_status->problem_has_been_acknowledged==TRUE)
status_bg_class="BGDOWNACK";
else if(temp_status->scheduled_downtime_depth>0)
status_bg_class="BGDOWNSCHED";
else
status_bg_class="BGDOWN";
}
else if(temp_status->status==HOST_UNREACHABLE){
strncpy(status,"UNREACHABLE",sizeof(status));
status_class="HOSTUNREACHABLE";
if(temp_status->problem_has_been_acknowledged==TRUE)
status_bg_class="BGUNREACHABLEACK";
else if(temp_status->scheduled_downtime_depth>0)
status_bg_class="BGUNREACHABLESCHED";
else
status_bg_class="BGUNREACHABLE";
}
status[sizeof(status)-1]='\x0';
printf("
\n");
/**** host name column ****/
/* find extended information for this host */
temp_hostextinfo=find_hostextinfo(temp_status->host_name);
printf("
\n");
/* if user couldn't see anything, print out some helpful info... */
if(user_has_seen_something==FALSE){
if(hoststatus_list!=NULL){
printf("
It appears as though you do not have permission to view information for any of the hosts you requested...
\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");
}
else{
printf("
There doesn't appear to be any host status information in the status log...
\n");
printf("Make sure that Nagios is running and that you have specified the location of you status log correctly in the configuration files.
\n");
}
}
else
printf("
%d Matching Host Entries Displayed
\n",total_entries);
return;
}
/* show an overview of servicegroup(s)... */
void show_servicegroup_overviews(void){
servicegroup *temp_servicegroup=NULL;
int current_column;
int user_has_seen_something=FALSE;
int servicegroup_error=FALSE;
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
show_filters();
printf("
");
printf("
\n");
printf("
Service Overview For ");
if(show_all_servicegroups==TRUE)
printf("All Service Groups");
else
printf("Service Group '%s'",servicegroup_name);
printf("
\n");
printf(" ");
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
printf("\n");
/* display status overviews for all servicegroups */
if(show_all_servicegroups==TRUE){
printf("
\n");
printf("
\n");
current_column=1;
/* loop through all servicegroups... */
for(temp_servicegroup=servicegroup_list;temp_servicegroup!=NULL;temp_servicegroup=temp_servicegroup->next){
/* make sure the user is authorized to view at least one host in this servicegroup */
if(is_authorized_for_servicegroup(temp_servicegroup,¤t_authdata)==FALSE)
continue;
if(current_column==1)
printf("
\n");
}
/* else display overview for just a specific servicegroup */
else{
temp_servicegroup=find_servicegroup(servicegroup_name);
if(temp_servicegroup!=NULL){
printf("
Sorry, but service group '%s' doesn't seem to exist...
",servicegroup_name);
servicegroup_error=TRUE;
}
}
/* if user couldn't see anything, print out some helpful info... */
if(user_has_seen_something==FALSE && servicegroup_error==FALSE){
printf("
\n");
printf("
\n");
if(servicegroup_list!=NULL){
printf("
It appears as though you do not have permission to view information for any of the hosts you requested...
\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");
}
else{
printf("
There are no service groups defined.
\n");
}
printf("
\n");
printf("\n");
}
return;
}
/* shows an overview of a specific servicegroup... */
void show_servicegroup_overview(servicegroup *temp_servicegroup){
servicegroupmember *temp_member;
host *temp_host;
host *last_host;
hoststatus *temp_hoststatus=NULL;
int odd=0;
printf("
\n");
/* find all hosts that have services that are members of the servicegroup */
last_host=NULL;
for(temp_member=temp_servicegroup->members;temp_member!=NULL;temp_member=temp_member->next){
/* find the host */
temp_host=find_host(temp_member->host_name);
if(temp_host==NULL)
continue;
/* skip this if it isn't a new host... */
if(temp_host==last_host)
continue;
/* find the host status */
temp_hoststatus=find_hoststatus(temp_host->name);
if(temp_hoststatus==NULL)
continue;
/* make sure we only display hosts of the specified status levels */
if(!(host_status_types & temp_hoststatus->status))
continue;
/* make sure we only display hosts that have the desired properties */
if(passes_host_properties_filter(temp_hoststatus)==FALSE)
continue;
if(odd)
odd=0;
else
odd=1;
show_servicegroup_hostgroup_member_overview(temp_hoststatus,odd,temp_servicegroup);
last_host=temp_host;
}
printf("
\n");
printf("
\n");
return;
}
/* show a summary of servicegroup(s)... */
void show_servicegroup_summaries(void){
servicegroup *temp_servicegroup=NULL;
int user_has_seen_something=FALSE;
int servicegroup_error=FALSE;
int odd=0;
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
show_filters();
printf("
");
printf("
\n");
printf("
Status Summary For ");
if(show_all_servicegroups==TRUE)
printf("All Service Groups");
else
printf("Service Group '%s'",servicegroup_name);
printf("
\n");
printf(" ");
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
printf("\n");
printf("
\n");
printf("
\n");
printf("
\n");
printf("
Service Group
Host Status Totals
Service Status Totals
\n");
printf("
\n");
/* display status summary for all servicegroups */
if(show_all_servicegroups==TRUE){
/* loop through all servicegroups... */
for(temp_servicegroup=servicegroup_list;temp_servicegroup!=NULL;temp_servicegroup=temp_servicegroup->next){
/* make sure the user is authorized to view at least one host in this servicegroup */
if(is_authorized_for_servicegroup(temp_servicegroup,¤t_authdata)==FALSE)
continue;
if(odd==0)
odd=1;
else
odd=0;
/* show summary for this servicegroup */
show_servicegroup_summary(temp_servicegroup,odd);
user_has_seen_something=TRUE;
}
}
/* else just show summary for a specific servicegroup */
else{
temp_servicegroup=find_servicegroup(servicegroup_name);
if(temp_servicegroup==NULL)
servicegroup_error=TRUE;
else{
show_servicegroup_summary(temp_servicegroup,1);
user_has_seen_something=TRUE;
}
}
printf("
\n");
printf("
\n");
/* if user couldn't see anything, print out some helpful info... */
if(user_has_seen_something==FALSE && servicegroup_error==FALSE){
printf("
\n");
if(servicegroup_list!=NULL){
printf("
It appears as though you do not have permission to view information for any of the hosts you requested...
\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");
}
else{
printf("
There are no service groups defined.
\n");
}
printf("
\n");
}
/* we couldn't find the servicegroup */
else if(servicegroup_error==TRUE){
printf("
\n");
printf("
Sorry, but servicegroup '%s' doesn't seem to exist...
\n",servicegroup_name);
printf("
\n");
}
return;
}
/* displays status summary information for a specific servicegroup */
void show_servicegroup_summary(servicegroup *temp_servicegroup,int odd){
char *status_bg_class="";
if(odd==1)
status_bg_class="Even";
else
status_bg_class="Odd";
printf("
\n");
return;
}
/* shows host total summary information for a specific servicegroup */
void show_servicegroup_host_totals_summary(servicegroup *temp_servicegroup){
servicegroupmember *temp_member;
int total_up=0;
int total_down=0;
int total_unreachable=0;
int total_pending=0;
hoststatus *temp_hoststatus;
host *temp_host;
host *last_host;
last_host=NULL;
for(temp_member=temp_servicegroup->members;temp_member!=NULL;temp_member=temp_member->next){
/* find the host */
temp_host=find_host(temp_member->host_name);
if(temp_host==NULL)
continue;
/* skip this if it isn't a new host... */
if(temp_host==last_host)
continue;
/* find the host status */
temp_hoststatus=find_hoststatus(temp_host->name);
if(temp_hoststatus==NULL)
continue;
/* make sure we only display hosts of the specified status levels */
if(!(host_status_types & temp_hoststatus->status))
continue;
/* make sure we only display hosts that have the desired properties */
if(passes_host_properties_filter(temp_hoststatus)==FALSE)
continue;
if(temp_hoststatus->status==HOST_UP)
total_up++;
else if(temp_hoststatus->status==HOST_DOWN)
total_down++;
else if(temp_hoststatus->status==HOST_UNREACHABLE)
total_unreachable++;
else
total_pending++;
last_host=temp_host;
}
printf("
\n");
if((total_up + total_down + total_unreachable + total_pending)==0)
printf("No matching hosts");
return;
}
/* shows service total summary information for a specific servicegroup */
void show_servicegroup_service_totals_summary(servicegroup *temp_servicegroup){
servicegroupmember *temp_member;
int total_ok=0;
int total_warning=0;
int total_unknown=0;
int total_critical=0;
int total_pending=0;
servicestatus *temp_servicestatus;
service *temp_service;
hoststatus *temp_hoststatus;
/* check all services... */
for(temp_member=temp_servicegroup->members;temp_member!=NULL;temp_member=temp_member->next){
/* find the service */
temp_service=find_service(temp_member->host_name,temp_member->service_description);
if(temp_service==NULL)
continue;
/* find the service status */
temp_servicestatus=find_servicestatus(temp_service->host_name,temp_service->description);
if(temp_servicestatus==NULL)
continue;
/* find the status of the associated host */
temp_hoststatus=find_hoststatus(temp_servicestatus->host_name);
if(temp_hoststatus==NULL)
continue;
/* make sure we only display hosts of the specified status levels */
if(!(host_status_types & temp_hoststatus->status))
continue;
/* make sure we only display hosts that have the desired properties */
if(passes_host_properties_filter(temp_hoststatus)==FALSE)
continue;
/* make sure we only display services of the specified status levels */
if(!(service_status_types & temp_servicestatus->status))
continue;
/* make sure we only display services that have the desired properties */
if(passes_service_properties_filter(temp_servicestatus)==FALSE)
continue;
if(temp_servicestatus->status==SERVICE_CRITICAL)
total_critical++;
else if(temp_servicestatus->status==SERVICE_WARNING)
total_warning++;
else if(temp_servicestatus->status==SERVICE_UNKNOWN)
total_unknown++;
else if(temp_servicestatus->status==SERVICE_OK)
total_ok++;
else if(temp_servicestatus->status==SERVICE_PENDING)
total_pending++;
else
total_ok++;
}
printf("
\n");
if((total_ok + total_warning + total_unknown + total_critical + total_pending)==0)
printf("No matching services");
return;
}
/* show a grid layout of servicegroup(s)... */
void show_servicegroup_grids(void){
servicegroup *temp_servicegroup=NULL;
int user_has_seen_something=FALSE;
int servicegroup_error=FALSE;
int odd=0;
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
show_filters();
printf("
");
printf("
\n");
printf("
Status Grid For ");
if(show_all_servicegroups==TRUE)
printf("All Service Groups");
else
printf("Service Group '%s'",servicegroup_name);
printf("
\n");
printf(" ");
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
printf("\n");
/* display status grids for all servicegroups */
if(show_all_servicegroups==TRUE){
/* loop through all servicegroups... */
for(temp_servicegroup=servicegroup_list;temp_servicegroup!=NULL;temp_servicegroup=temp_servicegroup->next){
/* make sure the user is authorized to view at least one host in this servicegroup */
if(is_authorized_for_servicegroup(temp_servicegroup,¤t_authdata)==FALSE)
continue;
if(odd==0)
odd=1;
else
odd=0;
/* show grid for this servicegroup */
show_servicegroup_grid(temp_servicegroup);
user_has_seen_something=TRUE;
}
}
/* else just show grid for a specific servicegroup */
else{
temp_servicegroup=find_servicegroup(servicegroup_name);
if(temp_servicegroup==NULL)
servicegroup_error=TRUE;
else{
show_servicegroup_grid(temp_servicegroup);
user_has_seen_something=TRUE;
}
}
/* if user couldn't see anything, print out some helpful info... */
if(user_has_seen_something==FALSE && servicegroup_error==FALSE){
printf("
\n");
if(servicegroup_list!=NULL){
printf("
It appears as though you do not have permission to view information for any of the hosts you requested...
\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");
}
else{
printf("
There are no service groups defined.
\n");
}
printf("
\n");
}
/* we couldn't find the servicegroup */
else if(servicegroup_error==TRUE){
printf("
\n");
printf("
Sorry, but servicegroup '%s' doesn't seem to exist...
\n",servicegroup_name);
printf("
\n");
}
return;
}
/* displays status grid for a specific servicegroup */
void show_servicegroup_grid(servicegroup *temp_servicegroup){
char *status_bg_class="";
char *host_status_class="";
char *service_status_class="";
servicegroupmember *temp_member;
servicegroupmember *temp_member2;
host *temp_host;
host *last_host;
hoststatus *temp_hoststatus;
servicestatus *temp_servicestatus;
hostextinfo *temp_hostextinfo;
int odd=0;
int current_item;
printf("
\n");
/* find all hosts that have services that are members of the servicegroup */
last_host=NULL;
for(temp_member=temp_servicegroup->members;temp_member!=NULL;temp_member=temp_member->next){
/* find the host */
temp_host=find_host(temp_member->host_name);
if(temp_host==NULL)
continue;
/* get the status of the host */
temp_hoststatus=find_hoststatus(temp_host->name);
if(temp_hoststatus==NULL)
continue;
/* skip this if it isn't a new host... */
if(temp_host==last_host)
continue;
if(odd==1){
status_bg_class="Even";
odd=0;
}
else{
status_bg_class="Odd";
odd=1;
}
printf("
",host_status_class);
/* display all services on the host that are part of the hostgroup */
current_item=1;
for(temp_member2=temp_member;temp_member2!=NULL;temp_member2=temp_member2->next){
/* bail out if we've reached the end of the services that are associated with this servicegroup */
if(strcmp(temp_member2->host_name,temp_host->name))
break;
if(current_item>max_grid_width && max_grid_width>0){
printf(" \n");
current_item=1;
}
/* get the status of the service */
temp_servicestatus=find_servicestatus(temp_member2->host_name,temp_member2->service_description);
if(temp_servicestatus==NULL)
service_status_class="NULL";
else if(temp_servicestatus->status==SERVICE_OK)
service_status_class="OK";
else if(temp_servicestatus->status==SERVICE_WARNING)
service_status_class="WARNING";
else if(temp_servicestatus->status==SERVICE_UNKNOWN)
service_status_class="UNKNOWN";
else if(temp_servicestatus->status==SERVICE_CRITICAL)
service_status_class="CRITICAL";
else
service_status_class="PENDING";
printf("%s ",url_encode(temp_servicestatus->description),service_status_class,temp_servicestatus->description);
current_item++;
}
/* actions */
printf("
\n");
printf("\n");
return;
}
/* show an overview of hostgroup(s)... */
void show_hostgroup_overviews(void){
hostgroup *temp_hostgroup=NULL;
int current_column;
int user_has_seen_something=FALSE;
int hostgroup_error=FALSE;
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
show_filters();
printf("
");
printf("
\n");
printf("
Service Overview For ");
if(show_all_hostgroups==TRUE)
printf("All Host Groups");
else
printf("Host Group '%s'",hostgroup_name);
printf("
\n");
printf(" ");
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
printf("\n");
/* display status overviews for all hostgroups */
if(show_all_hostgroups==TRUE){
printf("
\n");
printf("
\n");
current_column=1;
/* loop through all hostgroups... */
for(temp_hostgroup=hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){
/* make sure the user is authorized to view this hostgroup */
if(is_authorized_for_hostgroup(temp_hostgroup,¤t_authdata)==FALSE)
continue;
if(current_column==1)
printf("
\n");
}
/* else display overview for just a specific hostgroup */
else{
temp_hostgroup=find_hostgroup(hostgroup_name);
if(temp_hostgroup!=NULL){
printf("
Sorry, but host group '%s' doesn't seem to exist...
",hostgroup_name);
hostgroup_error=TRUE;
}
}
/* if user couldn't see anything, print out some helpful info... */
if(user_has_seen_something==FALSE && hostgroup_error==FALSE){
printf("
\n");
printf("
\n");
if(hoststatus_list!=NULL){
printf("
It appears as though you do not have permission to view information for any of the hosts you requested...
\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");
}
else{
printf("
There doesn't appear to be any host status information in the status log...
\n");
printf("Make sure that Nagios is running and that you have specified the location of you status log correctly in the configuration files.
\n");
}
printf("
\n");
printf("\n");
}
return;
}
/* shows an overview of a specific hostgroup... */
void show_hostgroup_overview(hostgroup *hstgrp){
hostgroupmember *temp_member;
host *temp_host;
hoststatus *temp_hoststatus=NULL;
int odd=0;
/* make sure the user is authorized to view this hostgroup */
if(is_authorized_for_hostgroup(hstgrp,¤t_authdata)==FALSE)
return;
printf("
\n");
/* find all the hosts that belong to the hostgroup */
for(temp_member=hstgrp->members;temp_member!=NULL;temp_member=temp_member->next){
/* find the host... */
temp_host=find_host(temp_member->host_name);
if(temp_host==NULL)
continue;
/* find the host status */
temp_hoststatus=find_hoststatus(temp_host->name);
if(temp_hoststatus==NULL)
continue;
/* make sure we only display hosts of the specified status levels */
if(!(host_status_types & temp_hoststatus->status))
continue;
/* make sure we only display hosts that have the desired properties */
if(passes_host_properties_filter(temp_hoststatus)==FALSE)
continue;
if(odd)
odd=0;
else
odd=1;
show_servicegroup_hostgroup_member_overview(temp_hoststatus,odd,NULL);
}
printf("
\n");
return;
}
void show_servicegroup_hostgroup_member_service_status_totals(char *host_name,void *data){
int total_ok=0;
int total_warning=0;
int total_unknown=0;
int total_critical=0;
int total_pending=0;
servicestatus *temp_servicestatus;
service *temp_service;
servicegroup *temp_servicegroup=NULL;
char temp_buffer[MAX_INPUT_BUFFER];
if(display_type==DISPLAY_SERVICEGROUPS)
temp_servicegroup=(servicegroup *)data;
/* check all services... */
for(temp_servicestatus=servicestatus_list;temp_servicestatus!=NULL;temp_servicestatus=temp_servicestatus->next){
if(!strcmp(host_name,temp_servicestatus->host_name)){
/* make sure the user is authorized to see this service... */
temp_service=find_service(temp_servicestatus->host_name,temp_servicestatus->description);
if(is_authorized_for_service(temp_service,¤t_authdata)==FALSE)
continue;
if(display_type==DISPLAY_SERVICEGROUPS){
/* is this service a member of the servicegroup? */
if(is_service_member_of_servicegroup(temp_servicegroup,temp_service)==FALSE)
continue;
}
/* make sure we only display services of the specified status levels */
if(!(service_status_types & temp_servicestatus->status))
continue;
/* make sure we only display services that have the desired properties */
if(passes_service_properties_filter(temp_servicestatus)==FALSE)
continue;
if(temp_servicestatus->status==SERVICE_CRITICAL)
total_critical++;
else if(temp_servicestatus->status==SERVICE_WARNING)
total_warning++;
else if(temp_servicestatus->status==SERVICE_UNKNOWN)
total_unknown++;
else if(temp_servicestatus->status==SERVICE_OK)
total_ok++;
else if(temp_servicestatus->status==SERVICE_PENDING)
total_pending++;
else
total_ok++;
}
}
printf("
\n");
if((total_ok + total_warning + total_unknown + total_critical + total_pending)==0)
printf("No matching services");
return;
}
/* show a summary of hostgroup(s)... */
void show_hostgroup_summaries(void){
hostgroup *temp_hostgroup=NULL;
int user_has_seen_something=FALSE;
int hostgroup_error=FALSE;
int odd=0;
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
show_filters();
printf("
");
printf("
\n");
printf("
Status Summary For ");
if(show_all_hostgroups==TRUE)
printf("All Host Groups");
else
printf("Host Group '%s'",hostgroup_name);
printf("
\n");
printf(" ");
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
printf("\n");
printf("
\n");
printf("
\n");
printf("
\n");
printf("
Host Group
Host Status Totals
Service Status Totals
\n");
printf("
\n");
/* display status summary for all hostgroups */
if(show_all_hostgroups==TRUE){
/* loop through all hostgroups... */
for(temp_hostgroup=hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){
/* make sure the user is authorized to view this hostgroup */
if(is_authorized_for_hostgroup(temp_hostgroup,¤t_authdata)==FALSE)
continue;
if(odd==0)
odd=1;
else
odd=0;
/* show summary for this hostgroup */
show_hostgroup_summary(temp_hostgroup,odd);
user_has_seen_something=TRUE;
}
}
/* else just show summary for a specific hostgroup */
else{
temp_hostgroup=find_hostgroup(hostgroup_name);
if(temp_hostgroup==NULL)
hostgroup_error=TRUE;
else{
show_hostgroup_summary(temp_hostgroup,1);
user_has_seen_something=TRUE;
}
}
printf("
\n");
printf("
\n");
/* if user couldn't see anything, print out some helpful info... */
if(user_has_seen_something==FALSE && hostgroup_error==FALSE){
printf("
\n");
if(hoststatus_list!=NULL){
printf("
It appears as though you do not have permission to view information for any of the hosts you requested...
\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");
}
else{
printf("
There doesn't appear to be any host status information in the status log...
\n");
printf("Make sure that Nagios is running and that you have specified the location of you status log correctly in the configuration files.
\n");
}
printf("
\n");
}
/* we couldn't find the hostgroup */
else if(hostgroup_error==TRUE){
printf("
\n");
printf("
Sorry, but hostgroup '%s' doesn't seem to exist...
\n",hostgroup_name);
printf("
\n");
}
return;
}
/* displays status summary information for a specific hostgroup */
void show_hostgroup_summary(hostgroup *temp_hostgroup,int odd){
char *status_bg_class="";
if(odd==1)
status_bg_class="Even";
else
status_bg_class="Odd";
printf("
\n");
return;
}
/* shows host total summary information for a specific hostgroup */
void show_hostgroup_host_totals_summary(hostgroup *temp_hostgroup){
hostgroupmember *temp_member;
int total_up=0;
int total_down=0;
int total_unreachable=0;
int total_pending=0;
hoststatus *temp_hoststatus;
host *temp_host;
/* find all the hosts that belong to the hostgroup */
for(temp_member=temp_hostgroup->members;temp_member!=NULL;temp_member=temp_member->next){
/* find the host... */
temp_host=find_host(temp_member->host_name);
if(temp_host==NULL)
continue;
/* find the host status */
temp_hoststatus=find_hoststatus(temp_host->name);
if(temp_hoststatus==NULL)
continue;
/* make sure we only display hosts of the specified status levels */
if(!(host_status_types & temp_hoststatus->status))
continue;
/* make sure we only display hosts that have the desired properties */
if(passes_host_properties_filter(temp_hoststatus)==FALSE)
continue;
if(temp_hoststatus->status==HOST_UP)
total_up++;
else if(temp_hoststatus->status==HOST_DOWN)
total_down++;
else if(temp_hoststatus->status==HOST_UNREACHABLE)
total_unreachable++;
else
total_pending++;
}
printf("
\n");
if((total_up + total_down + total_unreachable + total_pending)==0)
printf("No matching hosts");
return;
}
/* shows service total summary information for a specific hostgroup */
void show_hostgroup_service_totals_summary(hostgroup *temp_hostgroup){
int total_ok=0;
int total_warning=0;
int total_unknown=0;
int total_critical=0;
int total_pending=0;
servicestatus *temp_servicestatus;
hoststatus *temp_hoststatus;
host *temp_host;
/* check all services... */
for(temp_servicestatus=servicestatus_list;temp_servicestatus!=NULL;temp_servicestatus=temp_servicestatus->next){
/* find the host this service is associated with */
temp_host=find_host(temp_servicestatus->host_name);
if(temp_host==NULL)
continue;
/* see if this service is associated with a host in the specified hostgroup */
if(is_host_member_of_hostgroup(temp_hostgroup,temp_host)==FALSE)
continue;
/* find the status of the associated host */
temp_hoststatus=find_hoststatus(temp_servicestatus->host_name);
if(temp_hoststatus==NULL)
continue;
/* make sure we only display hosts of the specified status levels */
if(!(host_status_types & temp_hoststatus->status))
continue;
/* make sure we only display hosts that have the desired properties */
if(passes_host_properties_filter(temp_hoststatus)==FALSE)
continue;
/* make sure we only display services of the specified status levels */
if(!(service_status_types & temp_servicestatus->status))
continue;
/* make sure we only display services that have the desired properties */
if(passes_service_properties_filter(temp_servicestatus)==FALSE)
continue;
if(temp_servicestatus->status==SERVICE_CRITICAL)
total_critical++;
else if(temp_servicestatus->status==SERVICE_WARNING)
total_warning++;
else if(temp_servicestatus->status==SERVICE_UNKNOWN)
total_unknown++;
else if(temp_servicestatus->status==SERVICE_OK)
total_ok++;
else if(temp_servicestatus->status==SERVICE_PENDING)
total_pending++;
else
total_ok++;
}
printf("
\n");
if((total_ok + total_warning + total_unknown + total_critical + total_pending)==0)
printf("No matching services");
return;
}
/* show a grid layout of hostgroup(s)... */
void show_hostgroup_grids(void){
hostgroup *temp_hostgroup=NULL;
int user_has_seen_something=FALSE;
int hostgroup_error=FALSE;
int odd=0;
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
show_filters();
printf("
");
printf("
\n");
printf("
Status Grid For ");
if(show_all_hostgroups==TRUE)
printf("All Host Groups");
else
printf("Host Group '%s'",hostgroup_name);
printf("
\n");
printf(" ");
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
printf("\n");
/* display status grids for all hostgroups */
if(show_all_hostgroups==TRUE){
/* loop through all hostgroups... */
for(temp_hostgroup=hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){
/* make sure the user is authorized to view this hostgroup */
if(is_authorized_for_hostgroup(temp_hostgroup,¤t_authdata)==FALSE)
continue;
if(odd==0)
odd=1;
else
odd=0;
/* show grid for this hostgroup */
show_hostgroup_grid(temp_hostgroup);
user_has_seen_something=TRUE;
}
}
/* else just show grid for a specific hostgroup */
else{
temp_hostgroup=find_hostgroup(hostgroup_name);
if(temp_hostgroup==NULL)
hostgroup_error=TRUE;
else{
show_hostgroup_grid(temp_hostgroup);
user_has_seen_something=TRUE;
}
}
/* if user couldn't see anything, print out some helpful info... */
if(user_has_seen_something==FALSE && hostgroup_error==FALSE){
printf("
\n");
if(hoststatus_list!=NULL){
printf("
It appears as though you do not have permission to view information for any of the hosts you requested...
\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");
}
else{
printf("
There doesn't appear to be any host status information in the status log...
\n");
printf("Make sure that Nagios is running and that you have specified the location of you status log correctly in the configuration files.
\n");
}
printf("
\n");
}
/* we couldn't find the hostgroup */
else if(hostgroup_error==TRUE){
printf("
\n");
printf("
Sorry, but hostgroup '%s' doesn't seem to exist...
\n",hostgroup_name);
printf("
\n");
}
return;
}
/* displays status grid for a specific hostgroup */
void show_hostgroup_grid(hostgroup *temp_hostgroup){
hostgroupmember *temp_member;
char *status_bg_class="";
char *host_status_class="";
char *service_status_class="";
host *temp_host;
service *temp_service;
hoststatus *temp_hoststatus;
servicestatus *temp_servicestatus;
hostextinfo *temp_hostextinfo;
int odd=0;
int current_item;
printf("
\n");
/* find all the hosts that belong to the hostgroup */
for(temp_member=temp_hostgroup->members;temp_member!=NULL;temp_member=temp_member->next){
/* find the host... */
temp_host=find_host(temp_member->host_name);
if(temp_host==NULL)
continue;
/* find the host status */
temp_hoststatus=find_hoststatus(temp_host->name);
if(temp_hoststatus==NULL)
continue;
if(odd==1){
status_bg_class="Even";
odd=0;
}
else{
status_bg_class="Odd";
odd=1;
}
printf("
\n",status_bg_class);
/* get the status of the host */
if(temp_hoststatus->status==HOST_DOWN)
host_status_class="HOSTDOWN";
else if(temp_hoststatus->status==HOST_UNREACHABLE)
host_status_class="HOSTUNREACHABLE";
else
host_status_class=status_bg_class;
printf("
",host_status_class);
/* display all services on the host */
current_item=1;
for(temp_service=service_list;temp_service;temp_service=temp_service->next){
/* skip this service if it's not associate with the host */
if(strcmp(temp_service->host_name,temp_host->name))
continue;
if(current_item>max_grid_width && max_grid_width>0){
printf(" \n");
current_item=1;
}
/* get the status of the service */
temp_servicestatus=find_servicestatus(temp_service->host_name,temp_service->description);
if(temp_servicestatus==NULL)
service_status_class="NULL";
else if(temp_servicestatus->status==SERVICE_OK)
service_status_class="OK";
else if(temp_servicestatus->status==SERVICE_WARNING)
service_status_class="WARNING";
else if(temp_servicestatus->status==SERVICE_UNKNOWN)
service_status_class="UNKNOWN";
else if(temp_servicestatus->status==SERVICE_CRITICAL)
service_status_class="CRITICAL";
else
service_status_class="PENDING";
printf("%s ",url_encode(temp_servicestatus->description),service_status_class,temp_servicestatus->description);
current_item++;
}
printf("