Patch for Nagios 3.0a5 - increase radius of circular layout when required to stop hosts overlapping

Jeff Turner (Nagios Devel List) nagios at jetsoft.no-ip.com
Mon Jul 23 10:37:44 CEST 2007


Hi All,

I have found that when I have a lot of hosts the circular layout
statusmap.cgi output makes the host icons overlap, this made reading their
names and details difficult. 

I have made some changes to the source to increase the radius of the circle
if the hosts are too close together, this "closeness" value is defined in
the config file so you can play with it to find one that looks correct. For
my map a value of 60 seemed OK (measuring the icons I got 72 as about right
but the smaller you make it the smaller the map is).

The diff for this against the 3.0a5 CSV is below. If anyone would like to
see the difference the patch makes I could post the JPG's to the list but
will wait to see if anyone wants them. 

I also removed the redundant second "default_statusmap_layout_method=0;"
line from the cgiutils.c file.



diff -d -b -B -C 3 -r cvs-3-orig/nagios/cgi/cgiutils.c
cvs-3/nagios/cgi/cgiutils.c
*** cvs-3-orig/nagios/cgi/cgiutils.c	2007-07-23 11:21:33.000000000 +0800
--- cvs-3/nagios/cgi/cgiutils.c	2007-07-23 11:52:36.000000000 +0800
***************
*** 109,114 ****
--- 109,116 ----
  int             refresh_rate=DEFAULT_REFRESH_RATE;
  
  int             default_statusmap_layout_method=0;
+ int		default_statusmap_circular_layout_minimum_host_diameter=0;
+ 
  int             default_statuswrl_layout_method=0;
  
  extern hostgroup       *hostgroup_list;
***************
*** 179,185 ****
  	refresh_rate=DEFAULT_REFRESH_RATE;
  
  	default_statusmap_layout_method=0;
! 	default_statusmap_layout_method=0;
  
  	service_critical_sound=NULL;
  	service_warning_sound=NULL;
--- 181,187 ----
  	refresh_rate=DEFAULT_REFRESH_RATE;
  
  	default_statusmap_layout_method=0;
+ 	default_statusmap_circular_layout_minimum_host_diameter=0;
  
  	service_critical_sound=NULL;
  	service_warning_sound=NULL;
***************
*** 435,440 ****
--- 437,448 ----
 
default_statusmap_layout_method=atoi((temp_buffer==NULL)?"0":temp_buffer);
  		        }
  
+ 		else
if(strstr(input,"default_statusmap_circular_layout_minimum_host_diameter=")=
=input){
+ 			temp_buffer=strtok(input,"=");
+ 			temp_buffer=strtok(NULL,"\x0");
+
default_statusmap_circular_layout_minimum_host_diameter=atoi((temp_buffer==N
ULL)?"0":temp_buffer);
+ 		        }
+ 
  		else if(strstr(input,"default_statuswrl_layout=")==input){
  			temp_buffer=strtok(input,"=");
  			temp_buffer=strtok(NULL,"\x0");
diff -d -b -B -C 3 -r cvs-3-orig/nagios/cgi/statusmap.c
cvs-3/nagios/cgi/statusmap.c
*** cvs-3-orig/nagios/cgi/statusmap.c	2007-07-23 11:21:35.000000000 +0800
--- cvs-3/nagios/cgi/statusmap.c	2007-07-23 11:32:33.000000000 +0800
***************
*** 62,67 ****
--- 62,68 ----
  extern char *statusmap_background_image;
  
  extern int default_statusmap_layout_method;
+ extern int default_statusmap_circular_layout_minimum_host_diameter;
  
  #define DEFAULT_NODE_WIDTH		40
  #define DEFAULT_NODE_HEIGHT		65
***************
*** 2556,2561 ****
--- 2557,2588 ----
          }
  
  
+  /* calculate radius necessary to give each host enough room - value of
enough set in config file - if set to 0 do nothing */
+ int calculate_radius_for_host(double anglewidth, int oldradius)
+  	{
+  	int newradius;
+  	double tmp1;
+  	newradius=oldradius;
+  	/* for this angle and radius see what the width is - if it is less
than the minimum then return the new value */
+  	if ( default_statusmap_circular_layout_minimum_host_diameter !=  0 )
{
+  		/* now do something - diam = angle/360  2 PI R  
+  		make 2 PI / 360 a constant 0.17453 (close enough) 
+  		then if diam is too small radius should become 
+  		DIAMWANTED * 360 / 2 PI ANGLE  */
+  
+  		tmp1=0.017453 * anglewidth * (double) oldradius ;
+  		if ( (int) tmp1 <
default_statusmap_circular_layout_minimum_host_diameter ) 
+  			{
+  			tmp1 = (double)
default_statusmap_circular_layout_minimum_host_diameter / ( 0.017453 *
anglewidth) ;
+  			newradius = (int) tmp1;
+  			/* now round up to nearest "standard" radius */
+  			newradius = CIRCULAR_DRAWING_RADIUS * ( 1 + (int)
(newradius / CIRCULAR_DRAWING_RADIUS) ) ;
+  			} 
+  		}
+  	return newradius;
+  	}
+  
+ 
  /* calculate coords of all hosts in circular layout method */
  void calculate_circular_coords(void){
  	int min_x=0;
***************
*** 2610,2615 ****
--- 2637,2643 ----
  	int parent_drawing_width=0;
  	int this_drawing_width=0;
  	int immediate_children=0;
+  	int saveradius=0;
  	double current_drawing_angle=0.0;
  	double this_drawing_angle=0.0;
  	double available_angle=0.0;
***************
*** 2648,2653 ****
--- 2676,2684 ----
  			/* calculate angle this host gets for drawing */
 
available_angle=useable_angle*((double)this_drawing_width/(double)parent_dra
wing_width);
  
+  			saveradius=radius;
+  			radius=calculate_radius_for_host(available_angle,
radius);
+ 
  			/* clip available angle if necessary */
  			/* this isn't really necessary, but helps keep
things looking a bit more sane with less potential connection crossover */
  			clipped_available_angle=360.0/layer;
***************
*** 2677,2682 ****
--- 2708,2714 ----
  
  			/* increment current drawing angle */
  			current_drawing_angle+=available_angle;
+ 			radius=saveradius;
  		        }
  	        }
  
***************
*** 2700,2705 ****
--- 2732,2738 ----
  	int parent_drawing_width=0;
  	int this_drawing_width=0;
  	int immediate_children=0;
+  	int saveradius=0;
  	double current_drawing_angle=0.0;
  	double available_angle=0.0;
  	double clipped_available_angle=0.0;
***************
*** 2745,2750 ****
--- 2778,2786 ----
  			/* calculate angle this host gets for drawing */
 
available_angle=useable_angle*((double)this_drawing_width/(double)parent_dra
wing_width);
  
+  			saveradius=radius;
+  			radius=calculate_radius_for_host(available_angle,
radius);
+ 
  			/* clip available angle if necessary */
  			/* this isn't really necessary, but helps keep
things looking a bit more sane with less potential connection crossover */
  			clipped_available_angle=360.0/layer;
***************
*** 2815,2820 ****
--- 2851,2857 ----
  
  			/* increment current drawing angle */
  			current_drawing_angle+=available_angle;
+  			radius=saveradius;
  		        }
  	        }
  

diff -d -b -B -C 3 -r cvs-3-orig/nagios/sample-config/cgi.cfg.in
cvs-3/nagios/sample-config/cgi.cfg.in
*** cvs-3-orig/nagios/sample-config/cgi.cfg.in	2007-07-23
11:21:36.000000000 +0800
--- cvs-3/nagios/sample-config/cgi.cfg.in	2007-07-23
11:37:01.000000000 +0800
***************
*** 200,205 ****
--- 200,207 ----
  
  default_statusmap_layout=5
  
+ # JET 2007 minimum width for icons - if not this much will increase radius
+ default_statusmap_circular_layout_minimum_host_diameter=60+ 
  
  
  # DEFAULT STATUSWRL LAYOUT METHOD



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/




More information about the Developers mailing list