2015-12-23 09:31:50 +01:00
|
|
|
<?php
|
|
|
|
|
2021-11-04 16:28:15 +01:00
|
|
|
// Pandora FMS - http://pandorafms.com
|
2015-12-23 09:31:50 +01:00
|
|
|
// ==================================================
|
2020-11-27 13:52:35 +01:00
|
|
|
// Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
|
2015-12-23 09:31:50 +01:00
|
|
|
// 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.
|
2019-01-30 16:18:44 +01:00
|
|
|
require_once $config['homedir'].'/include/functions_groups.php';
|
|
|
|
require_once $config['homedir'].'/include/functions_tags.php';
|
|
|
|
require_once $config['homedir'].'/include/class/Tree.class.php';
|
|
|
|
require_once $config['homedir'].'/include/class/TreeGroup.class.php';
|
|
|
|
|
|
|
|
|
|
|
|
function groupview_plain_groups($groups)
|
|
|
|
{
|
|
|
|
$group_result = [];
|
|
|
|
foreach ($groups as $group) {
|
|
|
|
$plain_child = [];
|
|
|
|
if (!empty($group['children'])) {
|
|
|
|
$plain_child = groupview_plain_groups($group['children']);
|
|
|
|
unset($group['children']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$group_result[] = $group;
|
|
|
|
$group_result = array_merge($group_result, $plain_child);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $group_result;
|
2015-12-23 09:31:50 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
function groupview_get_modules_counters($groups_ids=false)
|
|
|
|
{
|
|
|
|
if (empty($groups_ids)) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$groups_ids = implode(',', $groups_ids);
|
|
|
|
$table = is_metaconsole() ? 'tmetaconsole_agent' : 'tagente';
|
|
|
|
$table_sec = is_metaconsole() ? 'tmetaconsole_agent_secondary_group' : 'tagent_secondary_group';
|
|
|
|
|
|
|
|
$fields = [
|
|
|
|
'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
|
2018-09-07 14:19:01 +02:00
|
|
|
(
|
|
|
|
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)
|
2018-10-25 13:18:28 +02:00
|
|
|
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";
|
2022-09-20 09:05:13 +02:00
|
|
|
$data = db_get_all_rows_sql($sql);
|
|
|
|
return $data;
|
2015-12-23 09:31:50 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
function groupview_get_all_counters($tree_group)
|
|
|
|
{
|
|
|
|
$all_name = __('All');
|
|
|
|
$group_acl = $tree_group->getGroupAclCondition();
|
|
|
|
$table = is_metaconsole() ? 'tmetaconsole_agent' : 'tagente';
|
|
|
|
$table_sec = is_metaconsole() ? 'tmetaconsole_agent_secondary_group' : 'tagent_secondary_group';
|
|
|
|
$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_,
|
2018-09-21 15:10:30 +02:00
|
|
|
SUM(ta.normal_count) AS _monitors_ok_,
|
2018-09-07 14:19:01 +02:00
|
|
|
SUM(ta.total_count) AS _monitor_checks_,
|
2018-09-21 15:10:30 +02:00
|
|
|
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_,
|
2018-09-21 15:10:30 +02:00
|
|
|
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_,
|
2018-09-21 15:10:30 +02:00
|
|
|
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
|
|
|
)
|
|
|
|
";
|
2019-01-30 16:18:44 +01:00
|
|
|
$data = db_get_row_sql($sql);
|
|
|
|
$data['_monitor_not_normal_'] = ($data['_monitor_checks_'] - $data['_monitors_ok_']);
|
|
|
|
return $data;
|
2018-09-07 14:19:01 +02:00
|
|
|
}
|
2018-06-01 12:19:34 +02:00
|
|
|
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
function groupview_get_groups_list($id_user=false, $access='AR', $is_not_paginated=false)
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
if ($id_user == false) {
|
|
|
|
$id_user = $config['id_user'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$tree_group = new TreeGroup('group', 'group');
|
|
|
|
$tree_group->setPropagateCounters(false);
|
|
|
|
$tree_group->setFilter(
|
|
|
|
[
|
|
|
|
'searchAgent' => '',
|
|
|
|
'statusAgent' => AGENT_STATUS_ALL,
|
|
|
|
'searchModule' => '',
|
|
|
|
'statusModule' => -1,
|
|
|
|
'groupID' => 0,
|
|
|
|
'tagID' => 0,
|
|
|
|
'show_not_init_agents' => 1,
|
|
|
|
'show_not_init_modules' => 1,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$info = $tree_group->getArray();
|
|
|
|
$info = groupview_plain_groups($info);
|
|
|
|
$counter = count($info);
|
|
|
|
|
|
|
|
$offset = get_parameter('offset', 0);
|
|
|
|
$groups_view = $is_not_paginated ? $info : array_slice($info, $offset, $config['block_size']);
|
|
|
|
$agents_counters = array_reduce(
|
|
|
|
$groups_view,
|
|
|
|
function ($carry, $item) {
|
|
|
|
$carry[$item['id']] = $item;
|
|
|
|
return $carry;
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
|
|
|
$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;
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
|
|
|
$total_counters = [];
|
|
|
|
|
|
|
|
foreach ($agents_counters as $id_group => $agent_counter) {
|
|
|
|
$list[$id_group]['_name_'] = $agent_counter['name'];
|
|
|
|
$list[$id_group]['_id_'] = $agent_counter['id'];
|
|
|
|
$list[$id_group]['_iconImg_'] = $agent_counter['icon'];
|
|
|
|
|
|
|
|
$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'];
|
|
|
|
$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'];
|
|
|
|
}
|
|
|
|
|
|
|
|
array_unshift($list, groupview_get_all_counters($tree_group));
|
|
|
|
return [
|
|
|
|
'groups' => $list,
|
|
|
|
'counter' => $counter,
|
|
|
|
];
|
|
|
|
}
|