From 537df06e5e2dad5e50b3ccf6e798d05b455053e1 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Thu, 25 Sep 2014 13:52:11 +0200 Subject: [PATCH] Fixed the slow visualmaps (and maybe in other places) with a item group --- .../visual_console_builder.editor.php | 11 +++++++- pandora_console/include/functions_groups.php | 26 ++++++------------- .../include/functions_visual_map.php | 19 +++++++++----- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/pandora_console/godmode/reporting/visual_console_builder.editor.php b/pandora_console/godmode/reporting/visual_console_builder.editor.php index 9c16f9108c..a9cf7c1c15 100644 --- a/pandora_console/godmode/reporting/visual_console_builder.editor.php +++ b/pandora_console/godmode/reporting/visual_console_builder.editor.php @@ -71,6 +71,11 @@ echo "
"; diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php index 78aa6df80d..20a28f490d 100644 --- a/pandora_console/include/functions_groups.php +++ b/pandora_console/include/functions_groups.php @@ -15,6 +15,7 @@ // GNU General Public License for more details. require_once ($config['homedir'].'/include/functions_users.php'); +require_once ($config['homedir'].'/include/functions_reporting.php'); /** * Check if the group is in use in the Pandora DB. @@ -531,30 +532,18 @@ function groups_get_groups_tree_recursive($groups, $trash = 0, $trash2 = 0) { * @return int Status of the agents. */ function groups_get_status ($id_group = 0) { - $agents = agents_get_group_agents($id_group); + $data = reporting_get_group_stats($id_group); - $agents_status = array(); - foreach ($agents as $key => $agent) { - $agents_status[] = agents_get_status($key); - } - - $childrens = groups_get_childrens($id_group); - - foreach ($childrens as $key => $child) { - $agents_status[] = groups_get_status($key); - } - - // Status is 0 for normal, 1 for critical, 2 for warning and 3/-1 for unknown. 4 for fired alerts - if (is_int(array_search(AGENT_STATUS_ALERT_FIRED, $agents_status))) { + if ($data['monitor_alerts_fired'] > 0) { return AGENT_STATUS_ALERT_FIRED; } - elseif (is_int(array_search(AGENT_STATUS_CRITICAL, $agents_status))) { + elseif ($data['agent_critical'] > 0) { return AGENT_STATUS_CRITICAL; } - elseif (is_int(array_search(AGENT_STATUS_WARNING, $agents_status))) { + elseif ($data['agent_warning'] > 0) { return AGENT_STATUS_WARNING; } - elseif (is_int(array_search(AGENT_STATUS_UNKNOWN, $agents_status))) { + elseif ($data['agent_unknown'] > 0) { return AGENT_STATUS_UNKNOWN; } else { @@ -869,11 +858,12 @@ function groups_get_group_row($id_group, $group_all, $group, &$printed_groups) { // Get stats for this group $data = reporting_get_group_stats($id_group); + if ($data["total_agents"] == 0) { if (!empty($group['childs'])) { $group_childrens = groups_get_childrens($id_group, null, true); $group_childrens_agents = groups_total_agents(array_keys($group_childrens)); - + if (empty($group_childrens_agents)) { return; // Skip empty groups } diff --git a/pandora_console/include/functions_visual_map.php b/pandora_console/include/functions_visual_map.php index 182f309438..3a1060efd0 100644 --- a/pandora_console/include/functions_visual_map.php +++ b/pandora_console/include/functions_visual_map.php @@ -70,7 +70,7 @@ function visual_map_print_item($layoutData) { $text = '' . $label . ''; - $status = visual_map_get_status_element($layoutData); + $status = $layoutData['status_calculated']; switch ($status) { case VISUAL_MAP_STATUS_CRITICAL_BAD: @@ -100,7 +100,8 @@ function visual_map_print_item($layoutData) { switch ($type) { case STATIC_GRAPH: if ($layoutData['image'] != null) { - $img = visual_map_get_image_status_element($layoutData); + $img = visual_map_get_image_status_element($layoutData, + $layoutData['status_calculated']); if (substr($img,0,1) == '4') { $borderStyle ='border: 2px solid ' . COL_ALERTFIRED . ';'; $img = substr_replace($img, '', 0,1); @@ -127,7 +128,8 @@ function visual_map_print_item($layoutData) { case GROUP_ITEM: if ($layoutData['image'] != null) { - $img = visual_map_get_image_status_element($layoutData); + $img = visual_map_get_image_status_element($layoutData, + $layoutData['status_calculated']); if (substr($img,0,1) == '4') { $borderStyle ='border: 2px solid ' . COL_ALERTFIRED . ';'; $img = substr_replace($img, '', 0,1); @@ -294,7 +296,8 @@ function visual_map_print_item($layoutData) { break; case ICON: if ($layoutData['image'] != null) { - $img = visual_map_get_image_status_element($layoutData); + $img = visual_map_get_image_status_element($layoutData, + $layoutData['status_calculated']); } if (($width != 0) && ($height != 0)) { @@ -869,7 +872,7 @@ function visual_map_get_color_line_status($layoutData) { * * @return string The image with the relative path to pandora console directory. */ -function visual_map_get_image_status_element($layoutData) { +function visual_map_get_image_status_element($layoutData, $status = false) { $img = "images/console/icons/" . $layoutData["image"]; if ($layoutData['type'] == 5) { @@ -877,7 +880,11 @@ function visual_map_get_image_status_element($layoutData) { $img .= ".png"; } else { - switch (visual_map_get_status_element($layoutData)) { + if ($status === false) { + $status = visual_map_get_status_element($layoutData); + } + + switch ($status) { case 1: //Critical (BAD) $img .= "_bad.png";