*** statusmap.c 2011-08-17 07:36:27.000000000 +0000 --- /home/admin/statusmap.c.NEW 2013-08-09 22:28:54.297078916 +0000 *************** void calculate_circular_layer_coords(hos *** 149,154 **** --- 149,155 ---- 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]; *************** double scaling_factor = 1.0; /* scal *** 207,212 **** --- 208,217 ---- 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; *************** void display_page_header(void) { *** 705,711 **** /* right hand column of top row */ printf("\n"); ! printf("
\n", STATUSMAP_CGI); printf("\n"); printf("
\n"); printf("\n", escape_string(host_name)); --- 710,716 ---- /* right hand column of top row */ printf("\n"); ! printf("\n", STATUSMAP_CGI); printf("\n"); printf("
\n"); printf("\n", escape_string(host_name)); *************** void calculate_total_image_bounds(void) *** 1175,1197 **** 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; ! ! /* 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; ! ! coordinates_were_specified = TRUE; } /* add some space for icon size and overlapping text... */ --- 1180,1210 ---- total_image_width = 0; total_image_height = 0; ! 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{ ! ! /* 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; ! coordinates_were_specified=TRUE; ! } } /* add some space for icon size and overlapping text... */ *************** void draw_background_extras(void) { *** 1432,1437 **** --- 1445,1470 ---- 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) { *************** void draw_host_links(void) { *** 1447,1452 **** --- 1480,1486 ---- int dotted_line = FALSE; int x = 0; int y = 0; + int in_layer_list=FALSE; if(create_type == CREATE_HTML) return; *************** void draw_host_links(void) { *** 1466,1471 **** --- 1500,1512 ---- 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) { *************** void draw_host_links(void) { *** 1482,1490 **** if(this_hoststatus != NULL) { if(this_hoststatus->status == HOST_DOWN || this_hoststatus->status == HOST_UNREACHABLE) status_color = color_red; else status_color = color_black; ! } else status_color = color_black; --- 1523,1537 ---- 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; *************** void draw_host_links(void) { *** 1547,1555 **** if(parent_hoststatus != NULL) { if(parent_hoststatus->status == HOST_DOWN || parent_hoststatus->status == HOST_UNREACHABLE) status_color = color_red; else status_color = color_black; ! } else status_color = color_black; --- 1594,1608 ---- 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; *************** void draw_hosts(void) { *** 1646,1653 **** /* 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; /* get coords of host bounding box */ x1 = temp_host->x_2d - canvas_x; --- 1699,1708 ---- /* 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)){ ! /* if (has_host_childs_in_visible_layer(temp_host)==FALSE) */ ! continue; ! } /* get coords of host bounding box */ x1 = temp_host->x_2d - canvas_x; *************** void draw_hosts(void) { *** 1660,1673 **** temp_hoststatus = find_hoststatus(temp_host->name); if(temp_hoststatus != NULL) { ! if(temp_hoststatus->status == HOST_DOWN) ! 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_PENDING) ! status_color = color_grey; } else status_color = color_black; --- 1715,1741 ---- temp_hoststatus = find_hoststatus(temp_host->name); if(temp_hoststatus != NULL) { ! if(temp_hoststatus->status==HOST_DOWN || get_servicestatus_count(temp_host->name,SERVICE_CRITICAL)) status_color = color_red; ! else if(temp_hoststatus->status==HOST_UNREACHABLE ||get_servicestatus_count(temp_host->name,SERVICE_WARNING)) ! status_color=color_yellow; ! else if(temp_hoststatus->status==HOST_UP ||get_servicestatus_count(temp_host->name,SERVICE_OK)) status_color = color_green; ! ! /* THIS SECTION I'M NOT SURE ABOUT! ! 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 ||get_servicestatus_count(temp_host->name,SERVICE_PENDING)||get_servicestatus_count(temp_host->name,SERVICE_UNKNOWN)) ! status_color = color_grey; } else status_color = color_black; *************** void draw_host_text(char *name, int x, i *** 1883,1891 **** strncpy(temp_buffer, "Unreachable", sizeof(temp_buffer)); status_color = color_red; } else if(temp_hoststatus->status == HOST_UP) { 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)); --- 1951,1970 ---- strncpy(temp_buffer, "Unreachable", sizeof(temp_buffer)); status_color = color_red; } + else if(temp_hoststatus->status==HOST_UP && get_servicestatus_count(name,SERVICE_CRITICAL)){ + strncpy(temp_buffer,"Up",sizeof(temp_buffer)); + status_color=color_red; + } + else if(temp_hoststatus->status==HOST_UP && get_servicestatus_count(name,SERVICE_WARNING)){ + strncpy(temp_buffer,"Up",sizeof(temp_buffer)); + status_color=color_yellow; + } else if(temp_hoststatus->status == HOST_UP) { strncpy(temp_buffer, "Up", sizeof(temp_buffer)); ! 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)); *************** int max_child_host_layer_members(host *p *** 2510,2530 **** int max_child_host_drawing_width(host *parent) { host *temp_host; int child_width = 0; ! for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) { ! 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) return 1; ! else ! return child_width; ! } --- 2589,2614 ---- 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); } ! if (child_width<=0) return 1; ! return child_width; ! } *************** void calculate_balanced_tree_coords(host *** 2596,2620 **** 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 */ calculate_circular_layer_coords(NULL, 0.0, 360.0, 1, CIRCULAR_DRAWING_RADIUS); /* 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_2d < min_x) { ! have_min_x = TRUE; ! min_x = temp_host->x_2d; ! } ! if(have_min_y == FALSE || temp_host->y_2d < min_y) { ! have_min_y = TRUE; min_y = temp_host->y_2d; ! } } /* offset all drawing coords by the min x,y coords we found */ --- 2680,2706 ---- void calculate_circular_coords(void) { int min_x = 0; int min_y = 0; 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(temp_host->x_2dx_2d; ! } ! if(temp_host->y_2dy_2d; ! } } /* offset all drawing coords by the min x,y coords we found */ *************** void calculate_circular_layer_coords(hos *** 2653,2666 **** double average_child_angle = 0.0; double x_coord = 0.0; double y_coord = 0.0; ! host *temp_host; ! /* get the total number of immediate children to this host */ immediate_children = number_of_immediate_child_hosts(parent); /* bail out if we're done */ ! if(immediate_children == 0) return; /* calculate total drawing "width" of parent host */ --- 2739,2773 ---- 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) return; /* calculate total drawing "width" of parent host */ *************** void calculate_circular_layer_coords(hos *** 2678,2683 **** --- 2785,2796 ---- 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); *************** void calculate_circular_layer_coords(hos *** 2708,2713 **** --- 2821,2842 ---- 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); *************** void draw_circular_layer_markup(host *pa *** 2753,2764 **** double arc_end_angle = 0.0; int translated_x = 0; int translated_y = 0; /* get the total number of immediate children to this host */ immediate_children = number_of_immediate_child_hosts(parent); /* bail out if we're done */ ! if(immediate_children == 0) return; /* calculate total drawing "width" of parent host */ --- 2882,2908 ---- 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) return; /* calculate total drawing "width" of parent host */ *************** void draw_circular_layer_markup(host *pa *** 2775,2780 **** --- 2919,2930 ---- 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); *************** void draw_circular_layer_markup(host *pa *** 2834,2843 **** /* determine background color */ temp_hoststatus = find_hoststatus(temp_host->name); ! if(temp_hoststatus == NULL) bgcolor = color_lightgrey; ! else if(temp_hoststatus->status == HOST_DOWN || temp_hoststatus->status == HOST_UNREACHABLE) bgcolor = color_lightred; else bgcolor = color_lightgreen; --- 2984,3007 ---- /* determine background color */ temp_hoststatus = find_hoststatus(temp_host->name); ! if(temp_hoststatus==NULL||get_servicestatus_count(temp_host->name,SERVICE_UNKNOWN)) bgcolor = color_lightgrey; ! else if(temp_hoststatus->status==HOST_DOWN || temp_hoststatus->status==HOST_UNREACHABLE || get_servicestatus_count(temp_host->name,SERVICE_CRITICAL)) bgcolor = color_lightred; + else if (get_servicestatus_count(temp_host->name,SERVICE_WARNING) ) + bgcolor=color_yellow; + else if (get_servicestatus_count(temp_host->name,SERVICE_PENDING) ) + bgcolor=color_grey; + + /* THIS SECTION I'M NOT SURE ABOUT! + 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;