From e94b6852319284bfbe3e91bbb441c4ae7c7e8ce7 Mon Sep 17 00:00:00 2001 From: mdtrooper <tres.14159@gmail.com> Date: Thu, 18 Dec 2014 18:49:57 +0100 Subject: [PATCH] Added status of group nodes --- pandora_console/include/ajax/tree.ajax.php | 24 +--------- pandora_console/include/class/Tree.class.php | 44 +++++-------------- .../include/functions_reporting.php | 26 +++++++++++ 3 files changed, 39 insertions(+), 55 deletions(-) diff --git a/pandora_console/include/ajax/tree.ajax.php b/pandora_console/include/ajax/tree.ajax.php index bdd209c033..0c0088386c 100644 --- a/pandora_console/include/ajax/tree.ajax.php +++ b/pandora_console/include/ajax/tree.ajax.php @@ -67,28 +67,8 @@ if (is_ajax ()) { $status['not_init'] = $data['agent_not_init']; $status['ok'] = $data['agent_ok']; $status['total'] = $data['total_agents']; - - if ($data["monitor_alerts_fired"] > 0) { - $status['status'] = 'alert_fired'; - } - elseif ($data["monitor_critical"] > 0) { - $status['status'] = 'critical'; - } - elseif ($data["monitor_warning"] > 0) { - $status['status'] = 'warning'; - } - elseif (($data["monitor_unknown"] > 0) || ($data["agents_unknown"] > 0)) { - $status['status'] = 'unknown'; - } - elseif ($data["monitor_ok"] > 0) { - $status['status'] = 'ok'; - } - elseif ($data["agent_not_init"] > 0) { - $status['status'] = 'not_init'; - } - else { - $status['status'] = 'none'; - } + $status['status'] = $data['status']; + $status['alert_fired'] = $data['alert_fired']; echo json_encode($status); break; diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index afa6ad806a..b0bb41367c 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -68,6 +68,7 @@ class Tree { private function getRecursiveGroup($parent, $limit = null) { $filter = array(); + $filter['parent'] = $parent; if (!empty($this->filter['search'])) { @@ -77,16 +78,19 @@ class Tree { // First filter by name and father $groups = db_get_all_rows_filter('tgrupo', $filter, - array('id_grupo', 'nombre', 'icon')); + array('id_grupo', 'nombre')); if (empty($groups)) $groups = array(); + // Filter by status $filter_status = AGENT_STATUS_ALL; if (!empty($this->filter['status'])) { $filter_status = $this->filter['status']; } + + foreach ($groups as $iterator => $group) { $groups[$iterator]['counters'] = array(); $groups[$iterator]['counters']['ok'] = @@ -181,38 +185,12 @@ class Tree { // I hate myself unset($data[$iterator]['children']); } - } - break; - - } - - switch ($this->countAgentStatusMethod) { - case 'on_demand': - foreach ($groups as $iterator => $group) { - if (!empty($group['counters'])) { - $groups[$iterator]['searchCounters'] = 1; - // I hate myself - unset($groups[$iterator]['counters']); - } - else { - $groups[$iterator]['searchCounters'] = 0; - // I hate myself - unset($groups[$iterator]['counters']); - } - } - break; - } - - // Make the data - $this->tree = array(); - foreach ($data as $item) { - $temp = array(); - $temp['id'] = $item['id_grupo']; - $temp['type'] = 'group'; - $temp['name'] = $item['nombre']; - $temp['icon'] = $item['icon']; - $temp['searchChildren'] = $item['searchChildren']; - $temp['searchCounters'] = $item['searchCounters']; + break; + case 'live': + $temp['searchChildren'] = 0; + $temp['children'] = $item['children']; + break; + } $this->tree[] = $temp; } diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 9f3bcb8853..1665fe1999 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2017,6 +2017,32 @@ function reporting_get_group_stats ($id_group = 0, $access = 'AR') { $data["server_sanity"] = format_numeric (100 - $data["module_sanity"], 1); + + $data['alert_fired'] = 0; + if ($data["monitor_alerts_fired"] > 0) { + $data['alert_fired'] = 1; + } + + + if ($data["monitor_critical"] > 0) { + $data['status'] = 'critical'; + } + elseif ($data["monitor_warning"] > 0) { + $data['status'] = 'warning'; + } + elseif (($data["monitor_unknown"] > 0) || ($data["agents_unknown"] > 0)) { + $data['status'] = 'unknown'; + } + elseif ($data["monitor_ok"] > 0) { + $data['status'] = 'ok'; + } + elseif ($data["agent_not_init"] > 0) { + $data['status'] = 'not_init'; + } + else { + $data['status'] = 'none'; + } + return ($data); }