From df28fc326b6a753cd75c71825a465a03d5ff743a Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Thu, 18 Dec 2014 14:22:10 +0100 Subject: [PATCH] Added ajax call for the stats. And fixed the function 'groups_agent_ok' in functions_groups.php --- pandora_console/include/ajax/tree.ajax.php | 69 ++++++++++++++++++-- pandora_console/include/class/Tree.class.php | 45 +++++++++---- pandora_console/include/functions_groups.php | 1 + 3 files changed, 97 insertions(+), 18 deletions(-) diff --git a/pandora_console/include/ajax/tree.ajax.php b/pandora_console/include/ajax/tree.ajax.php index 7ae8529cf3..3eb37e4ad2 100644 --- a/pandora_console/include/ajax/tree.ajax.php +++ b/pandora_console/include/ajax/tree.ajax.php @@ -16,30 +16,85 @@ // Only accesible by ajax if (is_ajax ()) { global $config; - + // Login check check_login (); - require_once("include/class/Tree.class.php"); - + require_once($config['homedir'] . "/include/class/Tree.class.php"); + require_once($config['homedir'] . "/include/functions_reporting.php"); + $getChildren = (bool)get_parameter('getChildren', 0); - + $getGroupStatus = (bool)get_parameter('getGroupStatus', 0); + if ($getChildren) { $type = get_parameter('type', 'group'); $filter = get_parameter('filter', array('search' => '', 'status' => AGENT_STATUS_ALL)); $id = (int)get_parameter('id', 0); - $method = get_parameter('method', 'on_demand'); + $childrenMethod = get_parameter('childrenMethod', 'on_demand'); + $countModuleStatusMethod = get_parameter('countModuleStatusMethod', 'on_demand'); + $countAgentStatusMethod = get_parameter('countAgentStatusMethod', 'on_demand'); - $tree = new Tree($type, $method, $id); + $tree = new Tree($type, + $id, + $childrenMethod, + $countModuleStatusMethod, + $countAgentStatusMethod + ); $tree->setFilter(array( 'status' => $filter['status'], 'search' => $filter['search'])); echo json_encode(array('success' => 1, 'tree' => $tree->getArray())); return; } - + + if ($getGroupStatus) { + $id = (int)get_parameter('id', 0); + $type = get_parameter('type', 'group'); + $id = 0; + + $status = array(); + + switch ($type) { + case 'group': + $data = reporting_get_group_stats($id); + + $status['unknown'] = $data['agents_unknown']; + $status['critical'] = $data['agent_critical']; + $status['warning'] = $data['agent_warning']; + $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'; + } + + echo json_encode($status); + break; + } + return; + } + return; } ?> \ No newline at end of file diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 289ce15203..e347604275 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -19,11 +19,19 @@ class Tree { private $filter = array(); private $root = null; private $childrenMethod = "on_demand"; + private $countModuleStatusMethod = "on_demand"; + private $countAgentStatusMethod = "on_demand"; - public function __construct($type, $childrenMethod = "on_demand", $root = null) { + public function __construct($type, $root = null, + $childrenMethod = "on_demand", + $countModuleStatusMethod = "on_demand", + $countAgentStatusMethod = "on_demand") { + $this->type = $type; $this->root = $root; $this->childrenMethod = $childrenMethod; + $this->countModuleStatusMethod = $countModuleStatusMethod; + $this->countAgentStatusMethod = $countAgentStatusMethod; } public function setType($type) { @@ -85,16 +93,16 @@ class Tree { if ($status != AGENT_STATUS_ALL) { foreach ($groups as $iterator => $group) { - $count_ok = groups_monitor_ok( - array($group['id_grupo'])); - $count_critical = groups_monitor_critical( - array($group['id_grupo'])); - $count_warning = groups_monitor_warning( - array($group['id_grupo'])); - $count_unknown = groups_monitor_unknown( - array($group['id_grupo'])); - $count_not_init = groups_monitor_not_init( - array($group['id_grupo'])); + $groups[$iterator]['count_ok'] = + groups_monitor_ok(array($group['id_grupo'])); + $groups[$iterator]['count_critical'] = + groups_monitor_critical(array($group['id_grupo'])); + $groups[$iterator]['count_warning'] = + groups_monitor_warning(array($group['id_grupo'])); + $groups[$iterator]['count_unknown'] = + groups_monitor_unknown(array($group['id_grupo'])); + $groups[$iterator]['count_not_init'] = + groups_monitor_not_init(array($group['id_grupo'])); $remove_group = true; switch ($status) { @@ -185,7 +193,22 @@ class Tree { } } break; + } + + switch ($this->countAgentStatusMethod) { + case 'on_demand': + // I hate myself + unset($groups[$iterator]['count_ok']); + unset($groups[$iterator]['count_critical']); + unset($groups[$iterator]['count_warning']); + unset($groups[$iterator]['count_unknown']); + unset($groups[$iterator]['count_not_init']); + + $groups[$iterator]['count_agent_status_method'] = 'on_demand'; + break; + } + // Make the data $this->tree = array(); foreach ($groups as $group) { diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php index 33c24f5e7d..81420d664e 100644 --- a/pandora_console/include/functions_groups.php +++ b/pandora_console/include/functions_groups.php @@ -1217,6 +1217,7 @@ function groups_agent_ok ($group_array) { FROM tagente WHERE tagente.disabled = 0 AND normal_count = total_count + AND total_count != 0 AND id_grupo IN $group_clause");