--- statusmap.c 2010-01-04 14:28:49.000000000 +0100 +++ /tmp/statusmap.c 2010-01-04 14:37:03.000000000 +0100 @@ -147,6 +147,7 @@ void draw_circular_markup(void); void draw_circular_layer_markup(host *,double,double,int,int); +int has_host_childs_in_visible_layer(host *); char physical_logo_images_path[MAX_FILENAME_LENGTH]; @@ -201,6 +202,10 @@ double user_scaling_factor=1.0; /* user-supplied scaling factor */ int background_image_width=0; int background_image_height=0; +int max_circular_markup_x=0; +int min_circular_markup_x=0; +int max_circular_markup_y=0; +int min_circular_markup_y=0; int canvas_x=0; /* upper left coords of drawing canvas */ int canvas_y=0; @@ -1167,23 +1172,32 @@ total_image_width=0; total_image_height=0; - /* check all extended host information entries... */ - for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){ - /* only check entries that have 2-D coords specified */ - if(temp_host->have_2d_coords==FALSE) - continue; + if(layout_method==LAYOUT_CIRCULAR_MARKUP){ + coordinates_were_specified=TRUE; + total_image_width=max_circular_markup_x-min_circular_markup_x; + total_image_height=max_circular_markup_y-min_circular_markup_y; + } + else{ - /* skip hosts we shouldn't be drawing */ - if(temp_host->should_be_drawn==FALSE) - continue; + /* check all extended host information entries... */ + for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){ + + /* only check entries that have 2-D coords specified */ + if(temp_host->have_2d_coords==FALSE) + continue; + + /* skip hosts we shouldn't be drawing */ + if(temp_host->should_be_drawn==FALSE) + continue; - if(temp_host->x_2d>total_image_width) - total_image_width=temp_host->x_2d; - if(temp_host->y_2d>total_image_height) - total_image_height=temp_host->y_2d; + if(temp_host->x_2d>total_image_width) + total_image_width=temp_host->x_2d; + if(temp_host->y_2d>total_image_height) + total_image_height=temp_host->y_2d; - coordinates_were_specified=TRUE; + coordinates_were_specified=TRUE; + } } /* add some space for icon size and overlapping text... */ @@ -1267,7 +1281,7 @@ canvas_width=zoom_width; if(canvas_width>=total_image_width) canvas_x=0; - else + else canvas_x=(temp_host->x_2d-(zoom_width/2)); canvas_height=zoom_height; @@ -1424,6 +1438,26 @@ return; } +int has_host_childs_in_visible_layer(host *hst){ + + host *child_host; + int in_layer_list=FALSE; + + for(child_host=host_list;child_host!=NULL;child_host=child_host->next){ + if(child_host == hst) + continue; + if(is_host_immediate_child_of_host(hst,child_host)==TRUE){ + in_layer_list = is_host_in_layer_list(child_host); + if((in_layer_list==TRUE && exclude_layers==TRUE) || (in_layer_list==FALSE && exclude_layers==FALSE)){ + if(has_host_childs_in_visible_layer(child_host)){ + return TRUE; + } + } + else return TRUE; + } + } + return FALSE; + } /* draws host links */ void draw_host_links(void){ @@ -1439,6 +1473,7 @@ int dotted_line=FALSE; int x=0; int y=0; + int in_layer_list=FALSE; if(create_type==CREATE_HTML) return; @@ -1458,6 +1493,13 @@ if(is_authorized_for_host(this_host,¤t_authdata)==FALSE) continue; + in_layer_list=is_host_in_layer_list(this_host); + + if((in_layer_list==TRUE && exclude_layers==TRUE) || (in_layer_list==FALSE && exclude_layers==FALSE)){ + if (has_host_childs_in_visible_layer(this_host)==FALSE) + continue; + } + /* this is a "root" host, so draw link to Nagios process icon if using auto-layout mode */ if(this_host->parent_hosts==NULL && layout_method!=LAYOUT_USER_SUPPLIED && draw_nagios_icon==TRUE){ @@ -1474,9 +1516,15 @@ if(this_hoststatus!=NULL){ if(this_hoststatus->status==HOST_DOWN || this_hoststatus->status==HOST_UNREACHABLE) status_color=color_red; + else if((get_servicestatus_count(this_host->name,SERVICE_CRITICAL)>0) || (get_servicestatus_count(this_host->name,SERVICE_WARNING)>0)){ + if((in_layer_list==TRUE && exclude_layers==TRUE) || (in_layer_list==FALSE && exclude_layers==FALSE)) + status_color=color_black; + else + status_color=color_orange; + } else status_color=color_black; - } + } else status_color=color_black; @@ -1539,9 +1587,15 @@ if(parent_hoststatus!=NULL){ if(parent_hoststatus->status==HOST_DOWN || parent_hoststatus->status==HOST_UNREACHABLE) status_color=color_red; + else if ((get_servicestatus_count(parent_host->name,SERVICE_CRITICAL)>0) || (get_servicestatus_count(parent_host->name,SERVICE_WARNING)>0)){ + if((in_layer_list==TRUE && exclude_layers==TRUE) || (in_layer_list==FALSE && exclude_layers==FALSE)) + status_color=color_black; + else + status_color=color_orange; + } else status_color=color_black; - } + } else status_color=color_black; @@ -1638,8 +1692,10 @@ /* is this host in the layer inclusion/exclusion list? */ in_layer_list=is_host_in_layer_list(temp_host); - if((in_layer_list==TRUE && exclude_layers==TRUE) || (in_layer_list==FALSE && exclude_layers==FALSE)) - continue; + if((in_layer_list==TRUE && exclude_layers==TRUE) || (in_layer_list==FALSE && exclude_layers==FALSE)){ + /* if (has_host_childs_in_visible_layer(temp_host)==FALSE) */ + continue; + } /* get coords of host bounding box */ x1=temp_host->x_2d-canvas_x; @@ -1656,8 +1712,16 @@ status_color=color_red; else if(temp_hoststatus->status==HOST_UNREACHABLE) status_color=color_red; - else if(temp_hoststatus->status==HOST_UP) - status_color=color_green; + else if(temp_hoststatus->status==HOST_UP){ + if ((get_servicestatus_count(temp_host->name,SERVICE_CRITICAL)>0) || (get_servicestatus_count(temp_host->name,SERVICE_WARNING)>0)){ + if((in_layer_list==TRUE && exclude_layers==TRUE) || (in_layer_list==FALSE && exclude_layers==FALSE)) + status_color=color_black; + else + status_color=color_orange; + } + else + status_color=color_green; + } else if(temp_hoststatus->status==HOST_PENDING) status_color=color_grey; } @@ -1877,7 +1941,10 @@ } 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)) + status_color=color_orange; + else + status_color=color_green; } else if(temp_hoststatus->status==HOST_PENDING){ strncpy(temp_buffer,"Pending",sizeof(temp_buffer)); @@ -2490,20 +2557,26 @@ int max_child_host_drawing_width(host *parent){ host *temp_host; int child_width=0; - + int in_layer_list=FALSE; for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){ - + + in_layer_list=is_host_in_layer_list(temp_host); + + if((in_layer_list==TRUE && exclude_layers==TRUE) || (in_layer_list==FALSE && exclude_layers==FALSE)){ + if (has_host_childs_in_visible_layer(temp_host)==FALSE) + continue; + } + if(is_host_immediate_child_of_host(parent,temp_host)==TRUE) child_width+=max_child_host_drawing_width(temp_host); + } - /* no children, so set width to 1 for this host */ - if(child_width==0) + if (child_width<=0) return 1; - else - return child_width; + return child_width; } @@ -2576,23 +2649,25 @@ void calculate_circular_coords(void){ int min_x=0; int min_y=0; - int have_min_x=FALSE; - int have_min_y=FALSE; host *temp_host; /* calculate all host coords, starting with first layer */ + max_circular_markup_x=0; + min_circular_markup_x=0; + max_circular_markup_y=0; + min_circular_markup_y=0; calculate_circular_layer_coords(NULL,0.0,360.0,1,CIRCULAR_DRAWING_RADIUS); + min_x=min_circular_markup_x; + min_y=min_circular_markup_y; /* adjust all calculated coords so none are negative in x or y axis... */ /* calculate min x, y coords */ for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){ - if(have_min_x==FALSE || temp_host->x_2dx_2dx_2d; } - if(have_min_y==FALSE || temp_host->y_2dy_2dy_2d; } } @@ -2633,14 +2708,36 @@ double average_child_angle=0.0; double x_coord=0.0; double y_coord=0.0; + double tmp_x_coord; + double tmp_y_coord; + double sampling=0.0; + int i=0; host *temp_host; + int in_layer_list=FALSE; /* get the total number of immediate children to this host */ immediate_children=number_of_immediate_child_hosts(parent); + for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){ + + if (parent == temp_host) + continue; + + if(is_host_immediate_child_of_host(parent,temp_host)==TRUE){ + in_layer_list=is_host_in_layer_list(temp_host); + + if((in_layer_list==TRUE && exclude_layers==TRUE)||(in_layer_list==FALSE && exclude_layers==FALSE)){ + if (has_host_childs_in_visible_layer(temp_host)==FALSE) + immediate_children--; + } + } + + } + + /* bail out if we're done */ - if(immediate_children==0) + if(immediate_children<=0) return; /* calculate total drawing "width" of parent host */ @@ -2658,6 +2755,12 @@ if(is_host_immediate_child_of_host(parent,temp_host)==TRUE){ + in_layer_list=is_host_in_layer_list(temp_host); + if((in_layer_list==TRUE && exclude_layers==TRUE)||(in_layer_list==FALSE && exclude_layers==FALSE)){ + if (has_host_childs_in_visible_layer(temp_host)==FALSE) + continue; + } + /* get drawing width of child host */ this_drawing_width=max_child_host_drawing_width(temp_host); @@ -2688,6 +2791,22 @@ temp_host->have_2d_coords=TRUE; temp_host->should_be_drawn=TRUE; + /* calculate drawing coords of "leftmost" divider using good ol' geometry... */ + for(sampling=0;sampling<=1;sampling+=0.5){ + for(i=-1;i<2;i+=2){ + tmp_x_coord=-(sin((-(current_drawing_angle+(sampling*available_angle)))*(M_PI/180.0))*(radius+i*(CIRCULAR_DRAWING_RADIUS/2))); + tmp_y_coord=-(sin((90+current_drawing_angle+(sampling*available_angle))*(M_PI/180.0))*(radius+i*(CIRCULAR_DRAWING_RADIUS/2))); + if(tmp_x_coordmax_circular_markup_x) + max_circular_markup_x=tmp_x_coord; + if(tmp_y_coordmax_circular_markup_y) + max_circular_markup_y=tmp_y_coord; + } + } + /* recurse into child host ... */ calculate_circular_layer_coords(temp_host,current_drawing_angle+((available_angle-clipped_available_angle)/2),clipped_available_angle,layer+1,radius+CIRCULAR_DRAWING_RADIUS); @@ -2733,12 +2852,27 @@ double arc_end_angle=0.0; int translated_x=0; int translated_y=0; + int in_layer_list=FALSE; /* get the total number of immediate children to this host */ immediate_children=number_of_immediate_child_hosts(parent); + for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){ + + if (parent == temp_host) + continue; + + if (is_host_immediate_child_of_host(parent,temp_host)==TRUE){ + in_layer_list=is_host_in_layer_list(temp_host); + if((in_layer_list==TRUE && exclude_layers==TRUE)||(in_layer_list==FALSE && exclude_layers==FALSE)){ + if (has_host_childs_in_visible_layer(temp_host)==FALSE) + immediate_children--; + } + } + } + /* bail out if we're done */ - if(immediate_children==0) + if(immediate_children<=0) return; /* calculate total drawing "width" of parent host */ @@ -2755,6 +2889,12 @@ if(is_host_immediate_child_of_host(parent,temp_host)==TRUE){ + in_layer_list=is_host_in_layer_list(temp_host); + if((in_layer_list==TRUE && exclude_layers==TRUE)||(in_layer_list==FALSE && exclude_layers==FALSE)){ + if (has_host_childs_in_visible_layer(temp_host)==FALSE) + continue; + } + /* get drawing width of child host */ this_drawing_width=max_child_host_drawing_width(temp_host); @@ -2818,6 +2958,12 @@ bgcolor=color_lightgrey; else if(temp_hoststatus->status==HOST_DOWN || temp_hoststatus->status==HOST_UNREACHABLE) bgcolor=color_lightred; + else if((get_servicestatus_count(temp_host->name,SERVICE_CRITICAL)>0) || (get_servicestatus_count(temp_host->name,SERVICE_WARNING)>0)){ + if((in_layer_list==TRUE && exclude_layers==TRUE)||(in_layer_list==FALSE && exclude_layers==FALSE)) + bgcolor=color_lightgreen; + else + bgcolor=color_yellow; + } else bgcolor=color_lightgreen;