From 446b063f92cb78657e341e3484b9540b628496cf Mon Sep 17 00:00:00 2001 From: zarzuelo Date: Wed, 7 Dec 2011 17:01:19 +0000 Subject: [PATCH] 2011-12-07 Sergio Martin * include/functions_groups.php operation/agentes/group_view.php: Improved group view with hierarchy to feature request 3444380 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5241 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 6 + pandora_console/include/functions_groups.php | 145 +++++++++++++++++ .../operation/agentes/group_view.php | 148 +++--------------- 3 files changed, 172 insertions(+), 127 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index ceef4b7d79..1f13840e7b 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,9 @@ +2011-12-07 Sergio Martin + + * include/functions_groups.php + operation/agentes/group_view.php: Improved group view + with hierarchy to feature request 3444380 + 2011-12-07 Sergio Martin * operation/agentes/estado_agente.php diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php index 3702db8dc4..e801181021 100644 --- a/pandora_console/include/functions_groups.php +++ b/pandora_console/include/functions_groups.php @@ -605,4 +605,149 @@ function groups_get_users ($id_group, $filter = false) { return $retval; } +/** + * Print a row in the groups view (Recursive function) + * + * @param int $id_group The group id of the row + * @param array $group_all An array of all groups + * @param array $group arrayy The group name and childs + * @param array $printed_groups The printed groups list (by reference) + * + */ +function groups_get_group_row($id_group, $group_all, $group, &$printed_groups) { + global $config; + + if (isset($printed_groups[$id_group])) { + return; + } + + // Store printed group to not print it again + $printed_groups[$id_group] = 1; + + if ($id_group < 1) + return; // Skip group 0 + + // Get stats for this group + $data = reporting_get_group_stats($id_group); + + if ($data["total_agents"] == 0) + return; // Skip empty groups + + // Calculate entire row color + if ($data["monitor_alerts_fired"] > 0){ + echo ""; + } + elseif ($data["monitor_critical"] > 0) { + echo ""; + } + elseif ($data["monitor_warning"] > 0) { + echo ""; + } + elseif (($data["monitor_unknown"] > 0) || ($data["agents_unknown"] > 0)) { + echo ""; + } + elseif ($data["monitor_ok"] > 0) { + echo ""; + } + else { + echo ""; + } + + // Group name + echo "  "; + echo $group['prefix'].ui_print_group_icon ($id_group, true, "groups_small", 'font-size: 7.5pt'); + echo " "; + echo ui_print_truncate_text($group['name'], 35); + echo ""; + echo ""; + echo ""; + if (check_acl ($config['id_user'], $id_group, "AW")) { + echo '' . html_print_image("images/target.png", true, array("border" => '0')) . ''; + } + echo ""; + + // Total agents + echo ""; + if ($data["total_agents"] > 0) + echo $data["total_agents"]; + + // Agents unknown + if ($data["agents_unknown"] > 0) { + echo ""; + echo $data["agents_unknown"]; + echo ""; + } + else { + echo ""; + } + + // Monitors Unknown + if ($data["monitor_unknown"] > 0){ + echo ""; + echo $data["monitor_unknown"]; + echo ""; + } + else { + echo ""; + } + + + // Monitors Not Init + if ($data["monitor_not_init"] > 0){ + echo ""; + echo $data["monitor_not_init"]; + echo ""; + } + else { + echo ""; + } + + + // Monitors OK + echo ""; + if ($data["monitor_ok"] > 0) { + echo $data["monitor_ok"]; + } + else { + echo " "; + } + echo ""; + + // Monitors Warning + if ($data["monitor_warning"] > 0){ + echo ""; + echo $data["monitor_warning"]; + echo ""; + } + else { + echo ""; + } + + // Monitors Critical + if ($data["monitor_critical"] > 0){ + echo ""; + echo $data["monitor_critical"]; + echo ""; + } + else { + echo ""; + } + // Alerts fired + if ($data["monitor_alerts_fired"] > 0){ + echo ""; + echo $data["monitor_alerts_fired"]; + echo ""; + } + else { + echo ""; + } + + + echo ""; + echo " "; + + foreach($group['childs'] as $child) { + groups_get_group_row($child, $group_all, $group_all[$child], $printed_groups); + } +} ?> diff --git a/pandora_console/operation/agentes/group_view.php b/pandora_console/operation/agentes/group_view.php index 64ccaa99a9..d417779d0b 100644 --- a/pandora_console/operation/agentes/group_view.php +++ b/pandora_console/operation/agentes/group_view.php @@ -45,8 +45,23 @@ if (isset ($_GET["update_netgroup"])) { } // Get group list that user has access -$groups = users_get_groups ($config['id_user']); +$groups_full = users_get_groups ($config['id_user'], "AR", true, true); +$groups = array(); +foreach($groups_full as $group) { + $groups[$group['id_grupo']]['name'] = $group['nombre']; + if($group['parent'] != 0) { + $groups[$group['parent']]['childs'][] = $group['id_grupo']; + $groups[$group['id_grupo']]['prefix'] = $groups[$group['parent']]['prefix'].'   '; + } + else { + $groups[$group['id_grupo']]['prefix'] = ''; + } + + if(!isset($groups[$group['id_grupo']]['childs'])) { + $groups[$group['id_grupo']]['childs'] = array(); + } +} if ($config["realtimestats"] == 0){ $updated_time = __('Last update'). " : ". ui_print_timestamp (db_get_sql ("SELECT min(utimestamp) FROM tgroup_stat"), true); @@ -69,8 +84,7 @@ if (count($agents) > 0) { echo ''; echo ""; -echo ""; +echo ""; echo ""; echo ""; @@ -81,131 +95,11 @@ echo ""; echo ""; echo ""; +$printed_groups = array(); + // For each valid group for this user, take data from agent and modules -foreach ($groups as $id_group => $group_name) { - if ($id_group < 1) - continue; // Skip group 0 - - // Get stats for this group - $data = reporting_get_group_stats($id_group); - - if ($data["total_agents"] == 0) - continue; // Skip empty groups - - // Calculate entire row color - if ($data["monitor_alerts_fired"] > 0){ - echo ""; - } - elseif ($data["monitor_critical"] > 0) { - echo ""; - } - elseif ($data["monitor_warning"] > 0) { - echo ""; - } - elseif (($data["monitor_unknown"] > 0) || ($data["agents_unknown"] > 0)) { - echo ""; - } - elseif ($data["monitor_ok"] > 0) { - echo ""; - } - else { - echo ""; - } - - // Group name - echo ""; - echo ""; - echo ""; - - // Total agents - echo ""; - } - else { - echo ""; - } - - // Monitors Unknown - if ($data["monitor_unknown"] > 0){ - echo ""; - } - else { - echo ""; - } - - - // Monitors Not Init - if ($data["monitor_not_init"] > 0){ - echo ""; - } - else { - echo ""; - } - - - // Monitors OK - echo ""; - - // Monitors Warning - if ($data["monitor_warning"] > 0){ - echo ""; - } - else { - echo ""; - } - - // Monitors Critical - if ($data["monitor_critical"] > 0){ - echo ""; - } - else { - echo ""; - } - // Alerts fired - if ($data["monitor_alerts_fired"] > 0){ - echo ""; - } - else { - echo ""; - } - - - echo ""; - echo ""; +foreach ($groups as $id_group => $group) { + groups_get_group_row($id_group, $groups, $group, $printed_groups); } echo "
"; -echo "".__("Group")."".__("Group").""; echo "".__("Agents")."".__("Agent unknown")."".__("Warning")."".__("Critical")."".__("Alert fired")."
"; - echo ui_print_group_icon ($id_group, true, "groups_small", 'font-size: 7.5pt'); - echo ""; - echo ""; - echo ui_print_truncate_text($group_name, 35); - echo ""; - echo ""; - if (check_acl ($config['id_user'], $id_group, "AW")) { - echo '' . html_print_image("images/target.png", true, array("border" => '0')) . ''; - } - echo ""; - if ($data["total_agents"] > 0) - echo $data["total_agents"]; - - // Agents unknown - if ($data["agents_unknown"] > 0) { - echo ""; - echo $data["agents_unknown"]; - echo ""; - echo $data["monitor_unknown"]; - echo ""; - echo $data["monitor_not_init"]; - echo ""; - if ($data["monitor_ok"] > 0) { - echo $data["monitor_ok"]; - } - else { - echo " "; - } - echo ""; - echo $data["monitor_warning"]; - echo ""; - echo $data["monitor_critical"]; - echo ""; - echo $data["monitor_alerts_fired"]; - echo "
";