2.0b1 statusmap patches

Joe Pruett joey at clean.q7.com
Wed Feb 16 00:48:17 CET 2005


here are some patches (all rolled together unfortunately) that provide the 
following changes:

cleans up graph layout with multi-parent objects.  the original code 
created multiple upstream spots and propogated that throught the rest of 
the graph.

adds some extra coloring for hosts that are sick (up but have some
fail/warning services), or waiting (up but have uknown/pending services).  
the names and colors are certainly open to critique.  i like to be able to 
look at the statusmap and have things not be green if there is something 
to look at.

adds a sort_order tag to let you control how things sort for display.  
currently only hosts have it, but it would be trivial to add to services 
as well if wanted.  basically the sort number is the primary key and 
hostname is the secondary key.  if you don't specifiy a sort order it is 
the same as before.  i just use simple numbers like:
10 switches
20 routers
30 term servers
100 servers
200 clients

feedback or inclusion in cvs would be great.

diff -u -r nagios-2.0b1/cgi/statusmap.c nagios-2.0b1.spire/cgi/statusmap.c
--- nagios-2.0b1/cgi/statusmap.c	2004-11-05 21:44:12.000000000 -0800
+++ nagios-2.0b1.spire/cgi/statusmap.c	2005-01-08 17:39:05.000000000 -0800
@@ -165,6 +165,7 @@
 int color_green=0;
 int color_lightgreen=0;
 int color_blue=0;
+int color_lightblue=0;
 int color_yellow=0;
 int color_orange=0;
 int color_grey=0;
@@ -1934,8 +1935,18 @@
 			status_color=color_red;
                         }
 		else if(temp_hoststatus->status==HOST_UP){
-			strncpy(temp_buffer,"Up",sizeof(temp_buffer));
-			status_color=color_green;
+			if (get_servicestatus_count(name,SERVICE_CRITICAL) > 0 || get_servicestatus_count(name, SERVICE_WARNING) > 0) {
+				strncpy(temp_buffer, "Sick", sizeof(temp_buffer));
+				status_color=color_orange;
+				}
+			else if(get_servicestatus_count(name,SERVICE_PENDING) > 0 || get_servicestatus_count(name, SERVICE_UNKNOWN) > 0) {
+				strncpy(temp_buffer, "Waiting", sizeof(temp_buffer));
+				status_color=color_orange;
+				}
+			else {
+				strncpy(temp_buffer,"Up",sizeof(temp_buffer));
+				status_color=color_green;
+				}
                         }
 		else if(temp_hoststatus->status==HOST_PENDING){
 			strncpy(temp_buffer,"Pending",sizeof(temp_buffer));
@@ -2168,6 +2179,7 @@
 	color_green=gdImageColorAllocate(map_image,0,175,0);
 	color_lightgreen=gdImageColorAllocate(map_image,210,255,215);
 	color_blue=gdImageColorAllocate(map_image,0,0,255);
+	color_lightblue=gdImageColorAllocate(map_image,210,210,255);
 	color_yellow=gdImageColorAllocate(map_image,255,255,0);
 	color_orange=gdImageColorAllocate(map_image,255,100,25);
 
@@ -2544,7 +2556,7 @@
 
 	for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
 		
-		if(is_host_immediate_child_of_host(parent,temp_host)==TRUE)
+		if(is_host_primary_immediate_child_of_host(parent,temp_host)==TRUE)
 			child_width+=max_child_host_drawing_width(temp_host);
 	        }
 
@@ -2693,7 +2705,7 @@
 
 
 	/* get the total number of immediate children to this host */
-	immediate_children=number_of_immediate_child_hosts(parent);
+	immediate_children=number_of_primary_immediate_child_hosts(parent);
 
 	/* bail out if we're done */
 	if(immediate_children==0)
@@ -2716,7 +2728,7 @@
 		if(temp_hostextinfo==NULL)
 			continue;
 
-		if(is_host_immediate_child_of_host(parent,temp_host)==TRUE){
+		if(is_host_primary_immediate_child_of_host(parent,temp_host)==TRUE){
 
 			/* get drawing width of child host */
 			this_drawing_width=max_child_host_drawing_width(temp_host);
@@ -2796,7 +2808,7 @@
 	int translated_y=0;
 
 	/* get the total number of immediate children to this host */
-	immediate_children=number_of_immediate_child_hosts(parent);
+	immediate_children=number_of_primary_immediate_child_hosts(parent);
 
 	/* bail out if we're done */
 	if(immediate_children==0)
@@ -2818,7 +2830,7 @@
 		if(temp_hostextinfo==NULL)
 			continue;
 
-		if(is_host_immediate_child_of_host(parent,temp_host)==TRUE){
+		if(is_host_primary_immediate_child_of_host(parent,temp_host)==TRUE){
 
 			/* get drawing width of child host */
 			this_drawing_width=max_child_host_drawing_width(temp_host);
@@ -2884,7 +2896,12 @@
 			else if(temp_hoststatus->status==HOST_DOWN || temp_hoststatus->status==HOST_UNREACHABLE)
 				bgcolor=color_lightred;
 			else
-				bgcolor=color_lightgreen;
+				if (get_servicestatus_count(temp_host->name,SERVICE_CRITICAL) > 0 || get_servicestatus_count(temp_host->name, SERVICE_WARNING) > 0)
+					bgcolor=color_yellow;
+				else if(get_servicestatus_count(temp_host->name,SERVICE_PENDING) > 0 || get_servicestatus_count(temp_host->name, SERVICE_UNKNOWN) > 0)
+					bgcolor=color_lightblue;
+				else
+					bgcolor=color_lightgreen;
 
 			/* fill slice with background color */
 			/* the fill function only works with coordinates that are in bounds of the actual image */
diff -u -r nagios-2.0b1/common/objects.c nagios-2.0b1.spire/common/objects.c
--- nagios-2.0b1/common/objects.c	2004-11-30 09:16:23.000000000 -0800
+++ nagios-2.0b1.spire/common/objects.c	2005-01-08 10:12:30.000000000 -0800
@@ -5270,6 +5270,34 @@
 	}
 
 
+/* returns a count of the immediate, primary children for a given host */
+int number_of_primary_immediate_child_hosts(host *hst){
+	int children=0;
+	host *temp_host;
+
+	for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
+		if(is_host_primary_immediate_child_of_host(hst,temp_host)==TRUE)
+			children++;
+		}
+
+	return children;
+	}
+
+
+/* returns a count of the total primarychildren for a given host */
+int number_of_total_primary_child_hosts(host *hst){
+	int children=0;
+	host *temp_host;
+
+	for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
+		if(is_host_primary_immediate_child_of_host(hst,temp_host)==TRUE)
+			children+=number_of_total_child_hosts(temp_host)+1;
+		}
+
+	return children;
+	}
+
+
 /* get the number of immediate parent hosts for a given host */
 int number_of_immediate_parent_hosts(host *hst){
 	int parents=0;
diff -u -r nagios-2.0b1/xdata/xodtemplate.c nagios-2.0b1.spire/xdata/xodtemplate.c
--- nagios-2.0b1/xdata/xodtemplate.c	2004-12-04 15:54:13.000000000 -0800
+++ nagios-2.0b1.spire/xdata/xodtemplate.c	2005-01-13 14:15:52.000000000 -0800
@@ -1271,6 +1271,7 @@
 		new_host->have_retain_nonstatus_information=FALSE;
 		new_host->has_been_resolved=FALSE;
 		new_host->register_object=TRUE;
+		new_host->sort_order=0;
 		new_host->_config_file=config_file;
 		new_host->_start_line=start_line;
 
@@ -2765,6 +2766,8 @@
 		        }
 		else if(!strcmp(variable,"register"))
 			temp_host->register_object=(atoi(value)>0)?TRUE:FALSE;
+		else if(!strcmp(variable,"sort_order"))
+			temp_host->sort_order=atoi(value);
 		else{
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Invalid host object directive '%s'.\n",variable);
@@ -8246,6 +8249,23 @@
 
 
 /* used to compare two strings (object names) */
+int xodtemplate_compare_strings1_with_sort_order(int sort1, int sort2, char *string1, char *string2){
+	
+	if(sort1 < sort2)
+		return -1;
+	else if(sort1 > sort2)
+		return 1;
+	else if(string1==NULL && string2==NULL)
+		return 0;
+	else if(string1==NULL)
+		return -1;
+	else if(string2==NULL)
+		return 1;
+	else
+		return strcmp(string1,string2);
+	}
+
+/* used to compare two strings (object names) */
 int xodtemplate_compare_strings1(char *string1, char *string2){
 	
 	if(string1==NULL && string2==NULL)
@@ -8633,7 +8653,7 @@
 		last_host=new_host_list;
 		for(temp_host=new_host_list;temp_host!=NULL;temp_host=temp_host->next){
 
-			if(xodtemplate_compare_strings1(temp_host_orig->host_name,temp_host->host_name)<=0)
+			if(xodtemplate_compare_strings1_with_sort_order(temp_host_orig->sort_order,temp_host->sort_order,temp_host_orig->host_name,temp_host->host_name)<=0)
 				break;
 			else
 				last_host=temp_host;
diff -u -r nagios-2.0b1/xdata/xodtemplate.h nagios-2.0b1.spire/xdata/xodtemplate.h
--- nagios-2.0b1/xdata/xodtemplate.h	2004-10-24 22:05:57.000000000 -0700
+++ nagios-2.0b1.spire/xdata/xodtemplate.h	2005-01-13 14:04:58.000000000 -0800
@@ -207,6 +207,7 @@
 
 	int       has_been_resolved;
 	int       register_object;
+	int		  sort_order;
 	struct xodtemplate_host_struct *next;
         }xodtemplate_host;
 
diff -u -r nagios-2.0b1/xdata/xsddefault.c nagios-2.0b1.spire/xdata/xsddefault.c
--- nagios-2.0b1/xdata/xsddefault.c	2004-10-31 14:23:27.000000000 -0800
+++ nagios-2.0b1.spire/xdata/xsddefault.c	2005-01-04 06:22:38.000000000 -0800
@@ -638,7 +638,7 @@
 					else if(!strcmp(var,"check_latency"))
 						temp_hoststatus->latency=strtod(val,NULL);
 					else if(!strcmp(var,"current_state"))
-						temp_hoststatus->status=(atoi(val)>0)?TRUE:FALSE;
+						temp_hoststatus->status=atoi(val);
 					else if(!strcmp(var,"last_hard_state"))
 						temp_hoststatus->last_hard_state=atoi(val);
 					else if(!strcmp(var,"plugin_output"))



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click




More information about the Developers mailing list