PATCH: terse display in service status details screen for downed hosts

Jonathan Chen jon+nagios at spock.org
Thu Dec 8 21:54:47 CET 2005


Hello all,

When a host is down or unreachable, it logically follows that any services 
running on that host would have the same fate.  Currently, the service 
status detail screen will list all the downed services for a host even when 
the host itself is down.  The following patch adds a configurable option to 
not list any services in the service detail screen when the host is down.


diff -ur nagios-2.0b6~/cgi/cgiutils.c nagios-2.0b6/cgi/cgiutils.c
--- nagios-2.0b6~/cgi/cgiutils.c	Wed Nov 16 03:49:35 2005
+++ nagios-2.0b6/cgi/cgiutils.c	Thu Dec  8 15:35:53 2005
@@ -89,6 +89,8 @@
 
 int             show_context_help=FALSE;
 
+int             collapse_downed_host_services=TRUE;
+
 int             hosts_have_been_read=FALSE;
 int             hostgroups_have_been_read=FALSE;
 int             servicegroups_have_been_read=FALSE;
@@ -313,6 +315,17 @@
 				use_authentication=TRUE;
 		        }
 
+		else if((strstr(input,"collapse_downed_host_services=")==input)){
+			temp_buffer=strtok(input,"=");
+			temp_buffer=strtok(NULL,"\n");
+			if(temp_buffer==NULL)
+				collapse_downed_host_services=TRUE;
+			else if(atoi(temp_buffer)==0)
+				collapse_downed_host_services=FALSE;
+			else
+				collapse_downed_host_services=TRUE;
+		        }
+
 		else if(strstr(input,"nagios_check_command=")==input){
 			temp_buffer=strtok(input,"=");
 			temp_buffer=strtok(NULL,"\x0");
diff -ur nagios-2.0b6~/cgi/status.c nagios-2.0b6/cgi/status.c
--- nagios-2.0b6~/cgi/status.c	Wed Nov 16 03:49:35 2005
+++ nagios-2.0b6/cgi/status.c	Thu Dec  8 15:35:53 2005
@@ -52,6 +52,8 @@
 
 extern int suppress_alert_window;
 
+extern int collapse_downed_host_services;
+
 extern host *host_list;
 extern service *service_list;
 extern hostgroup *hostgroup_list;
@@ -1213,6 +1215,8 @@
 	int duration_error=FALSE;
 	int total_entries=0;
 	int show_service=FALSE;
+	int show_downed_host_services=TRUE;
+	int thishost_down=FALSE;
 
 
 	/* sort the service list if necessary */
@@ -1243,10 +1247,14 @@
 
 	printf("<DIV ALIGN=CENTER CLASS='statusTitle'>Service Status Details For ");
 	if(display_type==DISPLAY_HOSTS){
-		if(show_all_hosts==TRUE)
+		if(show_all_hosts==TRUE){
+			if (collapse_downed_host_services)
+				show_downed_host_services = FALSE;
 			printf("All Hosts");
-		else
+			}
+		else{
 			printf("Host '%s'",host_name);
+			}
 	        }
 	else if(display_type==DISPLAY_SERVICEGROUPS){
 		if(show_all_servicegroups==TRUE)
@@ -1255,10 +1263,14 @@
 			printf("Service Group '%s'",servicegroup_name);
 	        }
 	else{
-		if(show_all_hostgroups==TRUE)
+		if(show_all_hostgroups==TRUE){
+			if (collapse_downed_host_services)
+				show_downed_host_services = FALSE;
 			printf("All Host Groups");
-		else
+			}
+		else{
 			printf("Host Group '%s'",hostgroup_name);
+			}
 	        }
 	printf("</DIV>\n");
 
@@ -1516,6 +1528,8 @@
 		                }
 			status[sizeof(status)-1]='\x0';
 
+			if (!show_downed_host_services && thishost_down && !new_host)
+				continue;
 
 			printf("<TR>\n");
 
@@ -1525,6 +1539,7 @@
 				/* find extended information for this host */
 				temp_hostextinfo=find_hostextinfo(temp_status->host_name);
 
+				thishost_down = FALSE;
 				if(temp_hoststatus->status==HOST_DOWN){
 					if(temp_hoststatus->problem_has_been_acknowledged==TRUE)
 						host_status_bg_class="HOSTDOWNACK";
@@ -1532,6 +1547,7 @@
 						host_status_bg_class="HOSTDOWNSCHED";
 					else
 						host_status_bg_class="HOSTDOWN";
+					thishost_down = TRUE;
 				        }
 				else if(temp_hoststatus->status==HOST_UNREACHABLE){
 					if(temp_hoststatus->problem_has_been_acknowledged==TRUE)
@@ -1540,6 +1556,7 @@
 						host_status_bg_class="HOSTUNREACHABLESCHED";
 					else
 						host_status_bg_class="HOSTUNREACHABLE";
+					thishost_down = TRUE;
 				        }
 				else
 					host_status_bg_class=(odd)?"Even":"Odd";
@@ -1608,6 +1625,90 @@
 				printf("</TD>\n");
 				printf("</TR>\n");
 				printf("</TABLE>\n");
+				if (!show_downed_host_services && thishost_down){
+					/* make sure user has rights to see this... */
+					if(is_authorized_for_host(temp_host,&current_authdata)==FALSE){
+						thishost_down = FALSE;
+						}
+					else{
+						status_class="";
+						status_bg_class="";
+
+						/* get the last host check time */
+						t=temp_hoststatus->last_check;
+						get_time_string(&t,date_time,(int)sizeof(date_time),SHORT_DATE_TIME);
+						if((unsigned long)temp_hoststatus->last_check==0L)
+							strcpy(date_time,"N/A");
+
+						if(temp_hoststatus->status==HOST_PENDING){
+							strncpy(status,"PENDING",sizeof(status));
+							status_class="PENDING";
+							status_bg_class=(odd)?"Even":"Odd";
+							}
+						else if(temp_hoststatus->status==HOST_UP){
+							strncpy(status,"UP",sizeof(status));
+							status_class="HOSTUP";
+							status_bg_class=(odd)?"Even":"Odd";
+							}
+						else if(temp_hoststatus->status==HOST_DOWN){
+							strncpy(status,"DOWN",sizeof(status));
+							status_class="HOSTDOWN";
+							if(temp_hoststatus->problem_has_been_acknowledged==TRUE)
+								status_bg_class="BGDOWNACK";
+							else if(temp_hoststatus->scheduled_downtime_depth>0)
+								status_bg_class="BGDOWNSCHED";
+							else
+								status_bg_class="BGDOWN";
+							}
+						else if(temp_hoststatus->status==HOST_UNREACHABLE){
+							strncpy(status,"UNREACHABLE",sizeof(status));
+							status_class="HOSTUNREACHABLE";
+							if(temp_hoststatus->problem_has_been_acknowledged==TRUE)
+								status_bg_class="BGUNREACHABLEACK";
+							else if(temp_hoststatus->scheduled_downtime_depth>0)
+								status_bg_class="BGUNREACHABLESCHED";
+							else
+								status_bg_class="BGUNREACHABLE";
+							}
+						status[sizeof(status)-1]='\x0';
+
+
+						/* state duration calculation... */
+						t=0;
+						duration_error=FALSE;
+						if(temp_hoststatus->last_state_change==(time_t)0){
+							if(program_start>current_time)
+								duration_error=TRUE;
+							else
+								t=current_time-program_start;
+							}
+						else{
+							if(temp_hoststatus->last_state_change>current_time)
+								duration_error=TRUE;
+							else
+								t=current_time-temp_hoststatus->last_state_change;
+							}
+						get_time_breakdown((unsigned long)t,&days,&hours,&minutes,&seconds);
+						if(duration_error==TRUE)
+							snprintf(state_duration,sizeof(state_duration)-1,"???");
+						else
+							snprintf(state_duration,sizeof(state_duration)-1,"%2dd %2dh %2dm %2ds%s",days,hours,minutes,seconds,(temp_hoststatus->last_state_change==(time_t)0)?"+":"");
+						state_duration[sizeof(state_duration)-1]='\x0';
+
+						/* the rest of the columns... */
+						printf("</TD>\n");
+						printf("<TD CLASS='status%s'><A HREF='%s?host=%s'>(DETAIL)</A></TD>\n",status_bg_class,STATUS_CGI,url_encode(temp_hoststatus->host_name));
+						printf("<TD CLASS='status%s'>%s</TD>\n",status_class,status);
+						printf("<TD CLASS='status%s' nowrap>%s</TD>\n",status_bg_class,date_time);
+						printf("<TD CLASS='status%s' nowrap>%s</TD>\n",status_bg_class,state_duration);
+						printf("<TD CLASS='status%s'>%d/%d</>\n",status_bg_class,temp_hoststatus->current_attempt,temp_hoststatus->max_attempts);
+						printf("<TD CLASS='status%s'>%s </TD>\n",status_bg_class,(temp_hoststatus->plugin_output==NULL)?"":temp_hoststatus->plugin_output);
+
+						printf("</TR>\n");
+						last_host=temp_hoststatus->host_name;
+						continue;
+						}
+					}
 			        }
 			else
 				printf("<TD>");
diff -ur nagios-2.0b6~/sample-config/cgi.cfg.in nagios-2.0b6/sample-config/cgi.cfg.in
--- nagios-2.0b6~/sample-config/cgi.cfg.in	Thu May  5 17:37:25 2005
+++ nagios-2.0b6/sample-config/cgi.cfg.in	Thu Dec  8 15:35:53 2005
@@ -47,6 +47,19 @@
 
 
 
+# COLLAPSE DOWNED HOST SERVICES
+# This option determines whether individual services are displayed
+# in the service status detail screen, when the host on which the
+# services are running is down or unreachable.  This only affects
+# service status detail screens where multiple hosts can be
+# displayed.
+# Values: 0 = display all services
+#         1 = hide services on downed hosts
+
+collapse_downed_host_services=1
+
+
+
 # NAGIOS PROCESS CHECK COMMAND
 # This is the full path and filename of the program used to check
 # the status of the Nagios process.  It is used only by the CGIs


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click




More information about the Developers mailing list