pandorafms/pandora_console/include/functions_groupview.php

200 lines
7.2 KiB
PHP
Raw Normal View History

2015-12-23 09:31:50 +01:00
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; version 2
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
include_once ($config['homedir'] . "/include/functions_groups.php");
include_once ($config['homedir'] . "/include/functions_tags.php");
2018-09-07 14:19:01 +02:00
include_once ($config['homedir'] . "/include/class/Tree.class.php");
include_once ($config['homedir'] . "/include/class/TreeGroup.class.php");
2015-12-23 09:31:50 +01:00
2018-09-07 14:19:01 +02:00
function groupview_plain_groups($groups) {
$group_result = array();
2015-12-23 09:31:50 +01:00
foreach ($groups as $group) {
2018-09-07 14:19:01 +02:00
$plain_child = array();
2015-12-23 09:31:50 +01:00
if (!empty($group['children'])) {
2018-09-07 14:19:01 +02:00
$plain_child = groupview_plain_groups($group['children']);
unset($group['children']);
2015-12-23 09:31:50 +01:00
}
2018-09-07 14:19:01 +02:00
$group_result[] = $group;
$group_result = array_merge($group_result, $plain_child);
2015-12-23 09:31:50 +01:00
}
2018-09-07 14:19:01 +02:00
return $group_result;
2015-12-23 09:31:50 +01:00
}
2018-09-07 14:19:01 +02:00
function groupview_get_modules_counters($groups_ids = false) {
2018-09-10 11:13:31 +02:00
if(empty($groups_ids)){
return array();
}
2018-09-07 14:19:01 +02:00
$groups_ids = implode(',', $groups_ids);
2018-09-10 09:55:31 +02:00
$table = is_metaconsole() ? 'tmetaconsole_agent' : 'tagente';
$table_sec = is_metaconsole()
? 'tmetaconsole_agent_secondary_group'
: 'tagent_secondary_group';
2018-09-07 14:19:01 +02:00
$fields = array (
"g" ,
"SUM(module_normal) AS total_module_normal",
"SUM(module_critical) AS total_module_critical",
"SUM(module_warning) AS total_module_warning",
"SUM(module_unknown) AS total_module_unknown",
"SUM(module_not_init) AS total_module_not_init",
"SUM(module_alerts) AS total_module_alerts",
"SUM(module_total) AS total_module"
);
$fields_impl = implode(',', $fields);
$sql = "SELECT $fields_impl FROM
(
SELECT SUM(ta.normal_count) AS module_normal,
SUM(ta.critical_count) AS module_critical,
SUM(ta.warning_count) AS module_warning,
SUM(ta.unknown_count) AS module_unknown,
SUM(ta.notinit_count) AS module_not_init,
SUM(ta.fired_count) AS module_alerts,
SUM(ta.total_count) AS module_total,
ta.id_grupo AS g
2018-09-10 09:55:31 +02:00
FROM $table ta
2018-09-07 14:19:01 +02:00
WHERE ta.id_grupo IN ($groups_ids)
AND ta.disabled = 0
2018-09-07 14:19:01 +02:00
GROUP BY ta.id_grupo
UNION ALL
SELECT SUM(ta.normal_count) AS module_normal,
SUM(ta.critical_count) AS module_critical,
SUM(ta.warning_count) AS module_warning,
SUM(ta.unknown_count) AS module_unknown,
SUM(ta.notinit_count) AS module_not_init,
SUM(ta.fired_count) AS module_alerts,
SUM(ta.total_count) AS module_total,
tasg.id_group AS g
2018-09-10 09:55:31 +02:00
FROM $table ta
INNER JOIN $table_sec tasg
2018-09-07 14:19:01 +02:00
ON ta.id_agente = tasg.id_agent
WHERE tasg.id_group IN ($groups_ids)
GROUP BY tasg.id_group
) x GROUP BY g";
return db_get_all_rows_sql($sql);
2015-12-23 09:31:50 +01:00
}
2018-09-10 12:08:38 +02:00
function groupview_get_all_counters($tree_group) {
2018-09-07 14:19:01 +02:00
$all_name = __("All");
2018-09-10 12:08:38 +02:00
$group_acl = $tree_group->getGroupAclCondition();
2018-09-10 09:55:31 +02:00
$table = is_metaconsole() ? 'tmetaconsole_agent' : 'tagente';
$table_sec = is_metaconsole()
? 'tmetaconsole_agent_secondary_group'
: 'tagent_secondary_group';
2018-09-07 14:19:01 +02:00
$sql =
"SELECT SUM(ta.critical_count) AS _monitors_critical_,
2018-09-07 14:19:01 +02:00
SUM(ta.warning_count) AS _monitors_warning_,
SUM(ta.unknown_count) AS _monitors_unknown_,
SUM(ta.notinit_count) AS _monitors_not_init_,
SUM(ta.normal_count) AS _monitors_ok_,
2018-09-07 14:19:01 +02:00
SUM(ta.total_count) AS _monitor_checks_,
SUM(ta.fired_count) AS _monitors_alerts_fired_,
2018-09-07 14:19:01 +02:00
SUM(IF(ta.critical_count > 0, 1, 0)) AS _agents_critical_,
SUM(IF(ta.critical_count = 0 AND ta.warning_count > 0, 1, 0)) AS _agents_warning_,
2018-09-07 14:19:01 +02:00
SUM(IF(ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count > 0, 1, 0)) AS _agents_unknown_,
SUM(IF(ta.total_count = ta.notinit_count, 1, 0)) AS _agents_not_init_,
SUM(IF(ta.total_count = ta.normal_count AND ta.total_count <> ta.notinit_count, 1, 0)) AS _agents_ok_,
2018-09-07 14:19:01 +02:00
COUNT(ta.id_agente) AS _total_agents_,
'$all_name' AS _name_,
0 AS _id_,
'' AS _icon_
2018-09-10 09:55:31 +02:00
FROM $table ta
2018-09-10 12:58:10 +02:00
WHERE ta.disabled = 0
AND ta.id_agente IN (
2018-09-10 09:55:31 +02:00
SELECT ta.id_agente FROM $table ta
LEFT JOIN $table_sec tasg
2018-09-07 14:19:01 +02:00
ON ta.id_agente = tasg.id_agent
2018-09-10 12:58:10 +02:00
WHERE ta.disabled = 0
$group_acl
GROUP BY ta.id_agente
2018-09-07 14:19:01 +02:00
)
";
$data = db_get_row_sql($sql);
$data["_monitor_not_normal_"] = $data["_monitor_checks_"] - $data["_monitors_ok_"];
return $data;
}
2018-06-01 12:19:34 +02:00
2018-09-07 14:37:22 +02:00
function groupview_get_groups_list($id_user = false, $access = 'AR', $is_not_paginated = false) {
2018-09-07 14:19:01 +02:00
global $config;
if ($id_user == false) {
$id_user = $config['id_user'];
}
2018-06-01 12:19:34 +02:00
2018-09-07 14:19:01 +02:00
$tree_group = new TreeGroup("group", "group");
$tree_group->setPropagateCounters(false);
$tree_group->setFilter( array(
'searchAgent' => '',
'statusAgent' => AGENT_STATUS_ALL,
'searchModule' => '',
'statusModule' => -1,
'groupID' => 0,
'tagID' => 0,
2018-09-10 12:58:10 +02:00
'show_not_init_agents' => 1,
'show_not_init_modules' => 1
2018-09-07 14:19:01 +02:00
));
$info = $tree_group->getArray();
$info = groupview_plain_groups($info);
$counter = count($info);
$offset = get_parameter('offset', 0);
2018-09-07 14:37:22 +02:00
$groups_view = $is_not_paginated
? $info
: array_slice($info, $offset, $config['block_size']);
2018-09-07 14:19:01 +02:00
$agents_counters = array_reduce($groups_view, function($carry, $item){
$carry[$item['id']] = $item;
return $carry;
}, array());
$modules_counters = groupview_get_modules_counters(array_keys($agents_counters));
$modules_counters = array_reduce($modules_counters, function($carry, $item){
$carry[$item['g']] = $item;
return $carry;
}, array());
$total_counters = array();
foreach ($agents_counters as $id_group => $agent_counter) {
$list[$id_group]['_name_'] = $agent_counter['name'];
$list[$id_group]['_id_'] = $agent_counter['id'];
2018-09-10 09:55:31 +02:00
$list[$id_group]['_iconImg_'] = $agent_counter['icon'];
2018-09-07 14:19:01 +02:00
$list[$id_group]['_agents_critical_'] = $agent_counter['counters']['critical'];
$list[$id_group]['_agents_warning_'] = $agent_counter['counters']['warning'];
$list[$id_group]['_agents_unknown_'] = $agent_counter['counters']['unknown'];
$list[$id_group]['_agents_not_init_'] = $agent_counter['counters']['not_init'];
$list[$id_group]['_agents_ok_'] = $agent_counter['counters']['ok'];
2018-09-07 14:19:01 +02:00
$list[$id_group]['_total_agents_'] = $agent_counter['counters']['total'];
$list[$id_group]['_monitors_critical_'] = (int)$modules_counters[$id_group]['total_module_critical'];
$list[$id_group]['_monitors_warning_'] = (int)$modules_counters[$id_group]['total_module_warning'];
$list[$id_group]['_monitors_unknown_'] = (int)$modules_counters[$id_group]['total_module_unknown'];
$list[$id_group]['_monitors_not_init_'] = (int)$modules_counters[$id_group]['total_module_not_init'];
$list[$id_group]['_monitors_ok_'] = (int)$modules_counters[$id_group]['total_module_normal'];
$list[$id_group]["_monitor_checks_"] = (int)$modules_counters[$id_group]['total_module'];
$list[$id_group]["_monitor_not_normal_"] = $list[$group['id_grupo']]["_monitor_checks_"] - $list[$group['id_grupo']]['_monitors_ok_'];
$list[$id_group]['_monitors_alerts_fired_'] = (int)$modules_counters[$id_group]['total_module_alerts'];
2018-06-01 12:19:34 +02:00
}
2018-09-07 14:19:01 +02:00
2018-09-10 12:08:38 +02:00
array_unshift($list, groupview_get_all_counters($tree_group));
2018-09-07 14:19:01 +02:00
return array(
'groups' => $list,
'counter' => $counter
);
2018-06-01 12:19:34 +02:00
}
2015-12-23 09:31:50 +01:00
?>