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

Jeff Turner (Nagios Devel List) nagios at jetsoft.no-ip.com
Wed Jul 11 08:31:27 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 on
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 2.9 tar file is below, I will post a diff
against the 3.0 CVS as soon as I get a chance. I havent done any C
programing for a lot of years so I hope my style isn't too ugly. 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. 

 diff -bB -C 3 -r nagios-2.9/cgi/cgiutils.c nagios-2.9-dev/cgi/cgiutils.c
*** nagios-2.9/cgi/cgiutils.c	2007-04-10 22:50:22.000000000 +0800
--- nagios-2.9-dev/cgi/cgiutils.c	2007-07-11 08:50:55.000000000 +0800
***************
*** 111,116 ****
--- 111,117 ----
  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;
***************
*** 182,187 ****
--- 183,189 ----
  
  	default_statusmap_layout_method=0;
  	default_statusmap_layout_method=0;
+ 	default_statusmap_circular_layout_minimum_host_diameter=0;
  
  	service_critical_sound=NULL;
  	service_warning_sound=NULL;
***************
*** 437,442 ****
--- 439,450 ----
 
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 -bB -C 3 -r nagios-2.9/cgi/statusmap.c nagios-2.9-dev/cgi/statusmap.c
*** nagios-2.9/cgi/statusmap.c	2006-03-22 05:31:46.000000000 +0800
--- nagios-2.9-dev/cgi/statusmap.c	2007-07-11 14:17:09.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
***************
*** 2674,2684 ****
--- 2675,2711 ----
          }
  
  
+ /* 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;
+ 	}
+ 
  /* calculates coords of all hosts in a particular "layer" in circular
layout method */
  void calculate_circular_layer_coords(host *parent, double start_angle,
double useable_angle, int layer, int radius){
  	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;
***************
*** 2722,2727 ****
--- 2749,2757 ----
  			/* 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;
***************
*** 2751,2756 ****
--- 2781,2787 ----
  
  			/* increment current drawing angle */
  			current_drawing_angle+=available_angle;
+ 			radius=saveradius;
  		        }
  	        }
  
***************
*** 2774,2779 ****
--- 2805,2811 ----
  	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;
***************
*** 2824,2829 ****
--- 2856,2865 ----
  			/* 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;
***************
*** 2894,2899 ****
--- 2930,2936 ----
  
  			/* increment current drawing angle */
  			current_drawing_angle+=available_angle;
+ 			radius=saveradius;
  		        }
  	        }
  
diff -bB -C 3 -r nagios-2.9/sample-config/cgi.cfg
nagios-2.9-dev/sample-config/cgi.cfg
*** nagios-2.9/sample-config/cgi.cfg	2007-07-11 14:08:37.000000000 +0800
--- nagios-2.9-dev/sample-config/cgi.cfg	2007-07-11
08:35:37.000000000 +0800
***************
*** 200,205 ****
--- 200,208 ----
  
  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 DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/




More information about the Developers mailing list