Added ajax call for the stats. And fixed the function 'groups_agent_ok' in functions_groups.php

This commit is contained in:
mdtrooper 2014-12-18 14:22:10 +01:00
parent 13fdccde1f
commit c18b0b6066
3 changed files with 97 additions and 18 deletions

View File

@ -20,9 +20,11 @@ if (is_ajax ()) {
// 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');
@ -30,9 +32,16 @@ if (is_ajax ()) {
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']));
@ -40,6 +49,52 @@ if (is_ajax ()) {
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;
}
?>

View File

@ -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, $root = null,
$childrenMethod = "on_demand",
$countModuleStatusMethod = "on_demand",
$countAgentStatusMethod = "on_demand") {
public function __construct($type, $childrenMethod = "on_demand", $root = null) {
$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) {

View File

@ -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");