mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-29 08:45:12 +02:00
Added ajax call for the stats. And fixed the function 'groups_agent_ok' in functions_groups.php
This commit is contained in:
parent
13fdccde1f
commit
c18b0b6066
@ -16,30 +16,85 @@
|
|||||||
// Only accesible by ajax
|
// Only accesible by ajax
|
||||||
if (is_ajax ()) {
|
if (is_ajax ()) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
// Login check
|
// Login check
|
||||||
check_login ();
|
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);
|
$getChildren = (bool)get_parameter('getChildren', 0);
|
||||||
|
$getGroupStatus = (bool)get_parameter('getGroupStatus', 0);
|
||||||
|
|
||||||
if ($getChildren) {
|
if ($getChildren) {
|
||||||
$type = get_parameter('type', 'group');
|
$type = get_parameter('type', 'group');
|
||||||
$filter = get_parameter('filter',
|
$filter = get_parameter('filter',
|
||||||
array('search' => '',
|
array('search' => '',
|
||||||
'status' => AGENT_STATUS_ALL));
|
'status' => AGENT_STATUS_ALL));
|
||||||
$id = (int)get_parameter('id', 0);
|
$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(
|
$tree->setFilter(array(
|
||||||
'status' => $filter['status'],
|
'status' => $filter['status'],
|
||||||
'search' => $filter['search']));
|
'search' => $filter['search']));
|
||||||
echo json_encode(array('success' => 1, 'tree' => $tree->getArray()));
|
echo json_encode(array('success' => 1, 'tree' => $tree->getArray()));
|
||||||
return;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
@ -19,11 +19,19 @@ class Tree {
|
|||||||
private $filter = array();
|
private $filter = array();
|
||||||
private $root = null;
|
private $root = null;
|
||||||
private $childrenMethod = "on_demand";
|
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->type = $type;
|
||||||
$this->root = $root;
|
$this->root = $root;
|
||||||
$this->childrenMethod = $childrenMethod;
|
$this->childrenMethod = $childrenMethod;
|
||||||
|
$this->countModuleStatusMethod = $countModuleStatusMethod;
|
||||||
|
$this->countAgentStatusMethod = $countAgentStatusMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setType($type) {
|
public function setType($type) {
|
||||||
@ -85,16 +93,16 @@ class Tree {
|
|||||||
|
|
||||||
if ($status != AGENT_STATUS_ALL) {
|
if ($status != AGENT_STATUS_ALL) {
|
||||||
foreach ($groups as $iterator => $group) {
|
foreach ($groups as $iterator => $group) {
|
||||||
$count_ok = groups_monitor_ok(
|
$groups[$iterator]['count_ok'] =
|
||||||
array($group['id_grupo']));
|
groups_monitor_ok(array($group['id_grupo']));
|
||||||
$count_critical = groups_monitor_critical(
|
$groups[$iterator]['count_critical'] =
|
||||||
array($group['id_grupo']));
|
groups_monitor_critical(array($group['id_grupo']));
|
||||||
$count_warning = groups_monitor_warning(
|
$groups[$iterator]['count_warning'] =
|
||||||
array($group['id_grupo']));
|
groups_monitor_warning(array($group['id_grupo']));
|
||||||
$count_unknown = groups_monitor_unknown(
|
$groups[$iterator]['count_unknown'] =
|
||||||
array($group['id_grupo']));
|
groups_monitor_unknown(array($group['id_grupo']));
|
||||||
$count_not_init = groups_monitor_not_init(
|
$groups[$iterator]['count_not_init'] =
|
||||||
array($group['id_grupo']));
|
groups_monitor_not_init(array($group['id_grupo']));
|
||||||
|
|
||||||
$remove_group = true;
|
$remove_group = true;
|
||||||
switch ($status) {
|
switch ($status) {
|
||||||
@ -185,7 +193,22 @@ class Tree {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
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
|
// Make the data
|
||||||
$this->tree = array();
|
$this->tree = array();
|
||||||
foreach ($groups as $group) {
|
foreach ($groups as $group) {
|
||||||
|
@ -1217,6 +1217,7 @@ function groups_agent_ok ($group_array) {
|
|||||||
FROM tagente
|
FROM tagente
|
||||||
WHERE tagente.disabled = 0
|
WHERE tagente.disabled = 0
|
||||||
AND normal_count = total_count
|
AND normal_count = total_count
|
||||||
|
AND total_count != 0
|
||||||
AND id_grupo IN $group_clause");
|
AND id_grupo IN $group_clause");
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user