mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 16:24:54 +02:00
Merge branch '2611-Cache_de_vista_de_arbol_y_vista_de_grupos' into 'develop'
fixed errors in tree view See merge request artica/pandorafms!1710
This commit is contained in:
commit
aa98b62e5c
@ -38,7 +38,13 @@ if (is_ajax ()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
require_once($config['homedir'] . "/include/class/Tree.class.php");
|
require_once($config['homedir'] . "/include/class/Tree.class.php");
|
||||||
enterprise_include_once("include/class/Tree.class.php");
|
require_once($config['homedir'] . "/include/class/TreeOS.class.php");
|
||||||
|
require_once($config['homedir'] . "/include/class/TreeModuleGroup.class.php");
|
||||||
|
require_once($config['homedir'] . "/include/class/TreeModule.class.php");
|
||||||
|
require_once($config['homedir'] . "/include/class/TreeTag.class.php");
|
||||||
|
require_once($config['homedir'] . "/include/class/TreeGroup.class.php");
|
||||||
|
enterprise_include_once("include/class/TreePolicies.class.php");
|
||||||
|
enterprise_include_once("include/class/TreeGroupMeta.class.php");
|
||||||
require_once($config['homedir'] . "/include/functions_reporting.php");
|
require_once($config['homedir'] . "/include/functions_reporting.php");
|
||||||
require_once($config['homedir'] . "/include/functions_os.php");
|
require_once($config['homedir'] . "/include/functions_os.php");
|
||||||
|
|
||||||
@ -71,11 +77,36 @@ if (is_ajax ()) {
|
|||||||
$agent_a = check_acl ($config['id_user'], 0, "AR");
|
$agent_a = check_acl ($config['id_user'], 0, "AR");
|
||||||
$agent_w = check_acl ($config['id_user'], 0, "AW");
|
$agent_w = check_acl ($config['id_user'], 0, "AW");
|
||||||
$access = ($agent_a == true) ? 'AR' : (($agent_w == true) ? 'AW' : 'AR');
|
$access = ($agent_a == true) ? 'AR' : (($agent_w == true) ? 'AW' : 'AR');
|
||||||
if (class_exists('TreeEnterprise')) {
|
$switch_type = !empty($rootType) ? $rootType : $type;
|
||||||
$tree = new TreeEnterprise($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
|
switch ($switch_type) {
|
||||||
|
case 'os':
|
||||||
|
$tree = new TreeOS($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
|
||||||
|
break;
|
||||||
|
case 'module_group':
|
||||||
|
$tree = new TreeModuleGroup($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
|
||||||
|
break;
|
||||||
|
case 'module':
|
||||||
|
$tree = new TreeModule($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
|
||||||
|
break;
|
||||||
|
case 'tag':
|
||||||
|
$tree = new TreeTag($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
|
||||||
|
break;
|
||||||
|
case 'group':
|
||||||
|
if(is_metaconsole()){
|
||||||
|
if (!class_exists('TreeGroupMeta')) break;
|
||||||
|
$tree = new TreeGroupMeta($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
|
||||||
}
|
}
|
||||||
else {
|
else{
|
||||||
$tree = new Tree($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
|
$tree = new TreeGroup($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'policies':
|
||||||
|
if (!class_exists('TreePolicies')) break;
|
||||||
|
$tree = new TreePolicies($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// FIXME. No error handler
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tree->setFilter($filter);
|
$tree->setFilter($filter);
|
||||||
|
File diff suppressed because it is too large
Load Diff
429
pandora_console/include/class/TreeGroup.class.php
Normal file
429
pandora_console/include/class/TreeGroup.class.php
Normal file
@ -0,0 +1,429 @@
|
|||||||
|
<?php
|
||||||
|
//Pandora FMS- http://pandorafms.com
|
||||||
|
// ==================================================
|
||||||
|
// Copyright (c) 2005-2018 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.
|
||||||
|
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
require_once($config['homedir']."/include/class/Tree.class.php");
|
||||||
|
|
||||||
|
class TreeGroup extends Tree {
|
||||||
|
|
||||||
|
public function __construct($type, $rootType = '', $id = -1, $rootID = -1, $serverID = false, $childrenMethod = "on_demand", $access = 'AR') {
|
||||||
|
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
parent::__construct($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
|
||||||
|
|
||||||
|
$this->L1fieldName = "id_group";
|
||||||
|
$this->L1extraFields = array(
|
||||||
|
"tg.nombre AS `name`",
|
||||||
|
$this->getDisplayHierarchy() ? 'tg.parent' : '0 as parent',
|
||||||
|
"tg.icon",
|
||||||
|
"tg.id_grupo AS gid"
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->L2conditionInside = "AND (
|
||||||
|
ta.id_grupo = " . $this->id . "
|
||||||
|
OR tasg.id_group = " . $this->id . "
|
||||||
|
)";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getData() {
|
||||||
|
if ($this->id == -1) {
|
||||||
|
$this->getFirstLevel();
|
||||||
|
} elseif ($this->type == 'group') {
|
||||||
|
$this->getSecondLevel();
|
||||||
|
} elseif ($this->type == 'agent') {
|
||||||
|
$this->getThirdLevel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getGroupSearchFilter() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getFirstLevel() {
|
||||||
|
$processed_items = $this->getProcessedGroups();
|
||||||
|
|
||||||
|
if (!empty($processed_items)) {
|
||||||
|
// Filter by group name. This should be done after rerieving the items cause we need the possible items descendants
|
||||||
|
if (!empty($this->filter['searchGroup'])) {
|
||||||
|
// Save the groups which intersect with the user groups
|
||||||
|
$groups = db_get_all_rows_filter('tgrupo', array('nombre' => '%' . $this->filter['searchGroup'] . '%'));
|
||||||
|
if ($groups == false) $groups = array();
|
||||||
|
$userGroupsACL = $this->userGroupsACL;
|
||||||
|
$ids_hash = array_reduce($groups, function ($userGroups, $group) use ($userGroupsACL) {
|
||||||
|
$group_id = $group['id_grupo'];
|
||||||
|
if (isset($userGroupsACL[$group_id])) {
|
||||||
|
$userGroups[$group_id] = $userGroupsACL[$group_id];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $userGroups;
|
||||||
|
}, array());
|
||||||
|
|
||||||
|
$result = self::extractGroupsWithIDs($processed_items, $ids_hash);
|
||||||
|
|
||||||
|
$processed_items = ($result === false) ? array() : $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// groupID filter. To access the view from tactical views f.e.
|
||||||
|
if (!empty($this->filter['groupID'])) {
|
||||||
|
$result = self::extractItemWithID($processed_items, $this->filter['groupID'], "group", $this->strictACL);
|
||||||
|
|
||||||
|
$processed_items = ($result === false) ? array() : array($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->tree = $processed_items;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getProcessedGroups () {
|
||||||
|
$processed_groups = array();
|
||||||
|
// Index and process the groups
|
||||||
|
$groups = $this->getGroupCounters(0);
|
||||||
|
|
||||||
|
// If user have not permissions in parent, set parent node to 0 (all)
|
||||||
|
// Avoid to do foreach for admins
|
||||||
|
if (!users_can_manage_group_all("AR")) {
|
||||||
|
foreach ($groups as $id => $group) {
|
||||||
|
if (!isset($this->userGroups[$groups[$id]['parent']])) {
|
||||||
|
$groups[$id]['parent'] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Build the group hierarchy
|
||||||
|
foreach ($groups as $id => $group) {
|
||||||
|
if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) {
|
||||||
|
$parent = $groups[$id]['parent'];
|
||||||
|
// Parent exists
|
||||||
|
if (!isset($groups[$parent]['children'])) {
|
||||||
|
$groups[$parent]['children'] = array();
|
||||||
|
}
|
||||||
|
// Store a reference to the group into the parent
|
||||||
|
$groups[$parent]['children'][] = &$groups[$id];
|
||||||
|
// This group was introduced into a parent
|
||||||
|
$groups[$id]['have_parent'] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Sort the children groups
|
||||||
|
foreach ($groups as $id => $group) {
|
||||||
|
if (isset($groups[$id]['children'])) {
|
||||||
|
usort($groups[$id]['children'], array("Tree", "cmpSortNames"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Filter groups and eliminates the reference to children groups out of her parent
|
||||||
|
$groups = array_filter($groups, function ($group) {
|
||||||
|
return !$group['have_parent'];
|
||||||
|
});
|
||||||
|
// Propagate child counters to her parents
|
||||||
|
TreeGroup::processCounters($groups);
|
||||||
|
// Filter groups and eliminates the reference to empty groups
|
||||||
|
$groups = TreeGroup::deleteEmptyGroups($groups);
|
||||||
|
|
||||||
|
usort($groups, array("Tree", "cmpSortNames"));
|
||||||
|
return $groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getGroupCounters() {
|
||||||
|
//FIXME PLEASE
|
||||||
|
if (true) {
|
||||||
|
$fields = $this->getFirstLevelFields();
|
||||||
|
$inside_fields = $this->getFirstLevelFieldsInside();
|
||||||
|
|
||||||
|
$group_acl = "";
|
||||||
|
$secondary_group_acl = "";
|
||||||
|
if (!users_can_manage_group_all("AR")) {
|
||||||
|
$user_groups_str = implode(",", $this->userGroupsArray);
|
||||||
|
$group_acl = " AND ta.id_grupo IN ($user_groups_str)";
|
||||||
|
$secondary_group_acl = " AND tasg.id_group IN ($user_groups_str)";
|
||||||
|
}
|
||||||
|
$agent_search_filter = $this->getAgentSearchFilter();
|
||||||
|
$agent_search_filter = preg_replace("/%/", "%%", $agent_search_filter);
|
||||||
|
$agent_status_filter = $this->getAgentStatusFilter();
|
||||||
|
$module_status_filter = $this->getModuleStatusFilter();
|
||||||
|
|
||||||
|
$module_search_inner = "";
|
||||||
|
$module_search_filter = "";
|
||||||
|
if (!empty($this->filter['searchModule'])) {
|
||||||
|
$module_search_inner = "
|
||||||
|
INNER JOIN tagente_modulo tam
|
||||||
|
ON ta.id_agente = tam.id_agente
|
||||||
|
INNER JOIN tagente_estado tae
|
||||||
|
ON tae.id_agente_modulo = tam.id_agente_modulo";
|
||||||
|
$module_search_filter = "AND tam.disabled = 0
|
||||||
|
AND tam.nombre LIKE '%%" . $this->filter['searchModule'] . "%%' " .
|
||||||
|
$this->getModuleStatusFilterFromTestado()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
$table = is_metaconsole() ? "tmetaconsole_agent" : "tagente";
|
||||||
|
$table_sec = is_metaconsole() ? "tmetaconsole_agent_secondary_group" : "tagent_secondary_group";
|
||||||
|
|
||||||
|
$sql_model = "SELECT %s FROM
|
||||||
|
(
|
||||||
|
SELECT COUNT(DISTINCT(ta.id_agente)) AS total, id_grupo AS g
|
||||||
|
FROM $table ta
|
||||||
|
$module_search_inner
|
||||||
|
WHERE ta.disabled = 0
|
||||||
|
%s
|
||||||
|
$agent_search_filter
|
||||||
|
$agent_status_filter
|
||||||
|
$module_status_filter
|
||||||
|
$module_search_filter
|
||||||
|
$group_acl
|
||||||
|
GROUP BY id_grupo
|
||||||
|
UNION ALL
|
||||||
|
SELECT COUNT(DISTINCT(ta.id_agente)) AS total, id_group AS g
|
||||||
|
FROM $table ta INNER JOIN $table_sec tasg
|
||||||
|
ON ta.id_agente = tasg.id_agent
|
||||||
|
$module_search_inner
|
||||||
|
WHERE ta.disabled = 0
|
||||||
|
%s
|
||||||
|
$agent_search_filter
|
||||||
|
$agent_status_filter
|
||||||
|
$module_status_filter
|
||||||
|
$module_search_filter
|
||||||
|
$secondary_group_acl
|
||||||
|
GROUP BY id_group
|
||||||
|
) x GROUP BY g";
|
||||||
|
$sql_array = array();
|
||||||
|
foreach ($inside_fields as $inside_field) {
|
||||||
|
$sql_array[] = sprintf(
|
||||||
|
$sql_model,
|
||||||
|
$inside_field['header'],
|
||||||
|
$inside_field['condition'],
|
||||||
|
$inside_field['condition']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$sql = "SELECT $fields FROM (" . implode(" UNION ALL ", $sql_array) . ") x2
|
||||||
|
RIGHT JOIN tgrupo tg
|
||||||
|
ON x2.g = tg.id_grupo
|
||||||
|
GROUP BY tg.id_grupo";
|
||||||
|
$stats = db_get_all_rows_sql($sql);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$stats = db_get_all_rows_sql(
|
||||||
|
'SELECT tgs.agents AS total_count, tgs.critical AS total_critical_count,
|
||||||
|
tgs.unknown AS total_unknown_count, tgs.warning AS total_warning_count,
|
||||||
|
`non-init` AS total_not_init_count, tgs.normal AS total_normal_count,
|
||||||
|
tgs.alerts_fired AS total_alerts_count,
|
||||||
|
tg.nombre AS name, tg.parent, tg.icon, tg.id_grupo AS gid
|
||||||
|
FROM tgroup_stat tgs
|
||||||
|
INNER JOIN tgrupo tg
|
||||||
|
ON tg.id_grupo = tgs.id_group
|
||||||
|
');
|
||||||
|
}
|
||||||
|
|
||||||
|
# Update the group cache (from db or calculated).
|
||||||
|
$group_stats = array();
|
||||||
|
|
||||||
|
foreach ($stats as $group) {
|
||||||
|
$group_stats[$group['gid']]['total_count'] = (int)$group['total_count'];
|
||||||
|
$group_stats[$group['gid']]['total_critical_count'] = (int)$group['total_critical_count'];
|
||||||
|
$group_stats[$group['gid']]['total_unknown_count'] = (int)$group['total_unknown_count'];
|
||||||
|
$group_stats[$group['gid']]['total_warning_count'] = (int)$group['total_warning_count'];
|
||||||
|
$group_stats[$group['gid']]['total_not_init_count'] = (int)$group['total_not_init_count'];
|
||||||
|
$group_stats[$group['gid']]['total_normal_count'] = (int)$group['total_normal_count'];
|
||||||
|
$group_stats[$group['gid']]['total_fired_count'] = (int)$group['total_alerts_count'];
|
||||||
|
$group_stats[$group['gid']]['name'] = $group['name'];
|
||||||
|
$group_stats[$group['gid']]['parent'] = $group['parent'];
|
||||||
|
$group_stats[$group['gid']]['icon'] = $group['icon'];
|
||||||
|
$group_stats[$group['gid']]['id'] = $group['gid'];
|
||||||
|
$group_stats[$group['gid']] = $this->getProcessedItem($group_stats[$group['gid']]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($group_stats[$group_id])) {
|
||||||
|
return $group_stats[$group_id];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $group_stats;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getProcessedModules($modules_tree) {
|
||||||
|
|
||||||
|
$groups = array();
|
||||||
|
foreach ($modules_tree as $group) {
|
||||||
|
$groups[$group["id"]] = $group;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build the module hierarchy
|
||||||
|
foreach ($groups as $id => $group) {
|
||||||
|
if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) {
|
||||||
|
$parent = $groups[$id]['parent'];
|
||||||
|
// Parent exists
|
||||||
|
if (!isset($groups[$parent]['children'])) {
|
||||||
|
$groups[$parent]['children'] = array();
|
||||||
|
}
|
||||||
|
// Store a reference to the group into the parent
|
||||||
|
$groups[$parent]['children'][] = &$groups[$id];
|
||||||
|
// This group was introduced into a parent
|
||||||
|
$groups[$id]['have_parent'] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort the children groups
|
||||||
|
foreach ($groups as $id => $group) {
|
||||||
|
if (isset($groups[$id]['children'])) {
|
||||||
|
usort($groups[$id]['children'], array("Tree", "cmpSortNames"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Filter groups and eliminates the reference to children groups out of her parent
|
||||||
|
$groups = array_filter($groups, function ($group) {
|
||||||
|
return !$group['have_parent'];
|
||||||
|
});
|
||||||
|
|
||||||
|
return array_values($groups);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Hierarchy lops is broken
|
||||||
|
protected function getProcessedModules_old($modules_tree) {
|
||||||
|
|
||||||
|
$tree_modules = array();
|
||||||
|
$new_modules_root = array_filter($modules_tree, function ($module) {
|
||||||
|
return (isset($module['parent']) && ($module['parent'] == 0));
|
||||||
|
});
|
||||||
|
|
||||||
|
$new_modules_child = array_filter($modules_tree, function ($module) {
|
||||||
|
return (isset($module['parent']) && ($module['parent'] != 0));
|
||||||
|
});
|
||||||
|
|
||||||
|
$i = 0;
|
||||||
|
while (!empty($new_modules_child)) {
|
||||||
|
foreach ($new_modules_child as $i => $child) {
|
||||||
|
TreeGroup::recursive_modules_tree_view($new_modules_root, $new_modules_child, $i, $child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($new_modules_root as $m) {
|
||||||
|
$tree_modules[] = $m;
|
||||||
|
}
|
||||||
|
return $tree_modules;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME with getProcessedModules_old
|
||||||
|
static function recursive_modules_tree_view (&$new_modules, &$new_modules_child, $i, $child) {
|
||||||
|
foreach ($new_modules as $index => $module) {
|
||||||
|
if ($module['id'] == $child['parent']) {
|
||||||
|
$new_modules[$index]['children'][] = $child;
|
||||||
|
unset($new_modules_child[$i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (isset($new_modules[$index]['children'])) {
|
||||||
|
TreeGroup::recursive_modules_tree_view ($new_modules[$index]['children'], $new_modules_child, $i, $child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static function processCounters(&$groups) {
|
||||||
|
$all_counters = array();
|
||||||
|
foreach ($groups as $id => $group) {
|
||||||
|
$child_counters = array();
|
||||||
|
if (!empty($groups[$id]['children'])) {
|
||||||
|
$child_counters = TreeGroup::processCounters($groups[$id]['children']);
|
||||||
|
}
|
||||||
|
if (!empty($child_counters)) {
|
||||||
|
foreach($child_counters as $type => $value) {
|
||||||
|
$groups[$id]['counters'][$type] += $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach($groups[$id]['counters'] as $type => $value) {
|
||||||
|
$all_counters[$type] += $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $all_counters;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Recursive function to remove the empty groups
|
||||||
|
*
|
||||||
|
* @param groups All groups structure
|
||||||
|
*
|
||||||
|
* @return new_groups A new groups structure without empty groups
|
||||||
|
*/
|
||||||
|
protected static function deleteEmptyGroups ($groups) {
|
||||||
|
$new_groups = array();
|
||||||
|
foreach ($groups as $group) {
|
||||||
|
// If a group is empty, do not add to new_groups.
|
||||||
|
if (!isset($group['counters']['total']) || $group['counters']['total'] == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Tray to remove the children groups
|
||||||
|
if (!empty($group['children'])) {
|
||||||
|
$children = TreeGroup::deleteEmptyGroups ($group['children']);
|
||||||
|
if (empty($children)) unset($group['children']);
|
||||||
|
else $group['children'] = $children;
|
||||||
|
}
|
||||||
|
$new_groups[] = $group;
|
||||||
|
}
|
||||||
|
return $new_groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function extractGroupsWithIDs ($groups, $ids_hash) {
|
||||||
|
$result_groups = array();
|
||||||
|
foreach ($groups as $group) {
|
||||||
|
if (isset($ids_hash[$group['id']])) {
|
||||||
|
$result_groups[] = $group;
|
||||||
|
}
|
||||||
|
else if (!empty($group['children'])) {
|
||||||
|
$result = self::extractGroupsWithIDs($group['children'], $ids_hash);
|
||||||
|
|
||||||
|
// Item found on children
|
||||||
|
if (!empty($result)) {
|
||||||
|
$result_groups = array_merge($result_groups, $result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result_groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function extractItemWithID ($items, $item_id, $item_type = "group", $strictACL = false) {
|
||||||
|
foreach ($items as $item) {
|
||||||
|
if ($item["type"] != $item_type)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Item found
|
||||||
|
if ($strictACL && is_metaconsole()) {
|
||||||
|
foreach ($item["id"] as $server_id => $id) {
|
||||||
|
if ($id == $item_id)
|
||||||
|
return $item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if ($item["id"] == $item_id)
|
||||||
|
return $item;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($item["type"] == "group" && !empty($item["children"])) {
|
||||||
|
$result = self::extractItemWithID($item["children"], $item_id, $item_type, $strictACL);
|
||||||
|
|
||||||
|
// Item found on children
|
||||||
|
if ($result !== false)
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Item not found
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getDisplayHierarchy() {
|
||||||
|
return $this->filter['searchHirearchy'] ||
|
||||||
|
(empty($this->filter['searchAgent']) && empty($this->filter['searchModule']));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
60
pandora_console/include/class/TreeModule.class.php
Normal file
60
pandora_console/include/class/TreeModule.class.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
//Pandora FMS- http://pandorafms.com
|
||||||
|
// ==================================================
|
||||||
|
// Copyright (c) 2005-2018 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.
|
||||||
|
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
require_once($config['homedir']."/include/class/Tree.class.php");
|
||||||
|
|
||||||
|
class TreeModule extends Tree {
|
||||||
|
|
||||||
|
public function __construct($type, $rootType = '', $id = -1, $rootID = -1, $serverID = false, $childrenMethod = "on_demand", $access = 'AR') {
|
||||||
|
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
parent::__construct($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
|
||||||
|
|
||||||
|
$this->L1fieldName = 'name';
|
||||||
|
$this->L1fieldNameSql = 'tam.nombre';
|
||||||
|
$this->L1inner = '';
|
||||||
|
$this->L1orderByFinal = 'name';
|
||||||
|
|
||||||
|
$this->L2condition = "AND tam.nombre = '" . $this->symbol2name($this->rootID) . "'";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getData() {
|
||||||
|
if ($this->id == -1) {
|
||||||
|
$this->getFirstLevel();
|
||||||
|
} elseif ($this->type == 'module') {
|
||||||
|
$this->getSecondLevel();
|
||||||
|
} elseif ($this->type == 'agent') {
|
||||||
|
$this->getThirdLevel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getProcessedItemsFirstLevel($items){
|
||||||
|
$processed_items = array();
|
||||||
|
foreach ($items as $key => $item) {
|
||||||
|
$name = $this->name2symbol($item['name']);
|
||||||
|
$processed_item = $this->getProcessedItem($item);
|
||||||
|
$processed_item['id'] = $name;
|
||||||
|
$processed_item['rootID'] = $name;
|
||||||
|
$processed_items[] = $processed_item;
|
||||||
|
}
|
||||||
|
return $processed_items;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
49
pandora_console/include/class/TreeModuleGroup.class.php
Normal file
49
pandora_console/include/class/TreeModuleGroup.class.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
//Pandora FMS- http://pandorafms.com
|
||||||
|
// ==================================================
|
||||||
|
// Copyright (c) 2005-2018 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.
|
||||||
|
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
require_once($config['homedir']."/include/class/Tree.class.php");
|
||||||
|
|
||||||
|
class TreeModuleGroup extends Tree {
|
||||||
|
|
||||||
|
public function __construct($type, $rootType = '', $id = -1, $rootID = -1, $serverID = false, $childrenMethod = "on_demand", $access = 'AR') {
|
||||||
|
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
parent::__construct($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
|
||||||
|
|
||||||
|
$this->L1fieldName = 'id_module_group';
|
||||||
|
$this->L1fieldNameSql = 'tam.id_module_group';
|
||||||
|
$this->L1extraFields = array('tmg.name', 'tmg.id_mg AS id');
|
||||||
|
$this->L1inner = 'INNER JOIN tmodule_group tmg ON tmg.id_mg = x2.g';
|
||||||
|
$this->L1orderByFinal = 'tmg.name';
|
||||||
|
|
||||||
|
$this->L2condition = "AND tam.id_module_group = " . $this->rootID;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getData() {
|
||||||
|
if ($this->id == -1) {
|
||||||
|
$this->getFirstLevel();
|
||||||
|
} elseif ($this->type == 'module_group') {
|
||||||
|
$this->getSecondLevel();
|
||||||
|
} elseif ($this->type == 'agent') {
|
||||||
|
$this->getThirdLevel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
49
pandora_console/include/class/TreeOS.class.php
Normal file
49
pandora_console/include/class/TreeOS.class.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
//Pandora FMS- http://pandorafms.com
|
||||||
|
// ==================================================
|
||||||
|
// Copyright (c) 2005-2018 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.
|
||||||
|
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
require_once($config['homedir']."/include/class/Tree.class.php");
|
||||||
|
|
||||||
|
class TreeOS extends Tree {
|
||||||
|
|
||||||
|
public function __construct($type, $rootType = '', $id = -1, $rootID = -1, $serverID = false, $childrenMethod = "on_demand", $access = 'AR') {
|
||||||
|
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
parent::__construct($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
|
||||||
|
|
||||||
|
$this->L1fieldName = 'id_os';
|
||||||
|
$this->L1fieldNameSql = 'ta.id_os';
|
||||||
|
$this->L1extraFields = array('tco.name', 'tco.id_os AS id', 'tco.icon_name AS iconHTML');
|
||||||
|
$this->L1inner = 'INNER JOIN tconfig_os tco ON tco.id_os = x2.g';
|
||||||
|
$this->L1orderByFinal = 'tco.name';
|
||||||
|
|
||||||
|
$this->L2condition = "AND ta.id_os = " . $this->rootID;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getData() {
|
||||||
|
if ($this->id == -1) {
|
||||||
|
$this->getFirstLevel();
|
||||||
|
} elseif ($this->type == 'os') {
|
||||||
|
$this->getSecondLevel();
|
||||||
|
} elseif ($this->type == 'agent') {
|
||||||
|
$this->getThirdLevel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
54
pandora_console/include/class/TreeTag.class.php
Normal file
54
pandora_console/include/class/TreeTag.class.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
//Pandora FMS- http://pandorafms.com
|
||||||
|
// ==================================================
|
||||||
|
// Copyright (c) 2005-2018 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.
|
||||||
|
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
require_once($config['homedir']."/include/class/Tree.class.php");
|
||||||
|
|
||||||
|
class TreeTag extends Tree {
|
||||||
|
|
||||||
|
public function __construct($type, $rootType = '', $id = -1, $rootID = -1, $serverID = false, $childrenMethod = "on_demand", $access = 'AR') {
|
||||||
|
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
parent::__construct($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
|
||||||
|
|
||||||
|
$this->L1fieldName = 'id_tag';
|
||||||
|
$this->L1fieldNameSql = 'ttm.id_tag';
|
||||||
|
$this->L1innerInside = '
|
||||||
|
INNER JOIN ttag_module ttm
|
||||||
|
ON ttm.id_agente_modulo = tam.id_agente_modulo
|
||||||
|
';
|
||||||
|
$this->L1extraFields = array('tt.name', 'tt.id_tag AS id');
|
||||||
|
$this->L1inner = 'INNER JOIN ttag tt ON tt.id_tag = x2.g';
|
||||||
|
$this->L1orderByFinal = 'tt.name';
|
||||||
|
|
||||||
|
$this->L2condition = "AND ttm.id_tag = " . $this->rootID;
|
||||||
|
$this->L2inner = $this->L1innerInside;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getData() {
|
||||||
|
if ($this->id == -1) {
|
||||||
|
$this->getFirstLevel();
|
||||||
|
} elseif ($this->type == 'tag') {
|
||||||
|
$this->getSecondLevel();
|
||||||
|
} elseif ($this->type == 'agent') {
|
||||||
|
$this->getThirdLevel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -2684,6 +2684,9 @@ function agents_generate_name ($alias, $address = '') {
|
|||||||
* @return Array with the main and secondary groups
|
* @return Array with the main and secondary groups
|
||||||
*/
|
*/
|
||||||
function agents_get_all_groups_agent ($id_agent, $group = false) {
|
function agents_get_all_groups_agent ($id_agent, $group = false) {
|
||||||
|
// Cache the agent id groups
|
||||||
|
static $cache = array();
|
||||||
|
if (isset($cache[$id_agent])) return $cache[$id_agent];
|
||||||
// Get the group if is not defined
|
// Get the group if is not defined
|
||||||
if ($group === false) $group = agents_get_agent_group($id_agent);
|
if ($group === false) $group = agents_get_agent_group($id_agent);
|
||||||
|
|
||||||
@ -2697,6 +2700,7 @@ function agents_get_all_groups_agent ($id_agent, $group = false) {
|
|||||||
|
|
||||||
// Add a list of groups
|
// Add a list of groups
|
||||||
$secondary_groups['plain'][] = $group;
|
$secondary_groups['plain'][] = $group;
|
||||||
|
$cache[$id_agent] = $secondary_groups['plain'];
|
||||||
return $secondary_groups['plain'];
|
return $secondary_groups['plain'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2336,13 +2336,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
|
|||||||
|
|
||||||
$user_groups = array();
|
$user_groups = array();
|
||||||
$user_tags = array();
|
$user_tags = array();
|
||||||
$groups_without_tags = array();
|
|
||||||
foreach ($acltags as $group => $tags) {
|
foreach ($acltags as $group => $tags) {
|
||||||
if ($user_strict) { //Remove groups with tags
|
|
||||||
if ($tags == '') {
|
|
||||||
$groups_without_tags[$group] = $group;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$user_groups[$group] = groups_get_name($group);
|
$user_groups[$group] = groups_get_name($group);
|
||||||
if ($tags != '') {
|
if ($tags != '') {
|
||||||
$tags_group = explode(',', $tags);
|
$tags_group = explode(',', $tags);
|
||||||
@ -2353,37 +2347,15 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($user_strict) {
|
|
||||||
$user_groups_ids = implode(',', array_keys($groups_without_tags));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$user_groups_ids = implode(',', array_keys($acltags));
|
$user_groups_ids = implode(',', array_keys($acltags));
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($user_groups_ids)) {
|
if (!empty($user_groups_ids)) {
|
||||||
switch ($config["dbtype"]) {
|
|
||||||
case "mysql":
|
|
||||||
$list_groups = db_get_all_rows_sql("
|
$list_groups = db_get_all_rows_sql("
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM tgrupo
|
FROM tgrupo
|
||||||
WHERE id_grupo IN (" . $user_groups_ids . ")
|
WHERE id_grupo IN (" . $user_groups_ids . ")
|
||||||
ORDER BY nombre COLLATE utf8_general_ci ASC");
|
ORDER BY nombre COLLATE utf8_general_ci ASC"
|
||||||
break;
|
);
|
||||||
case "postgresql":
|
|
||||||
$list_groups = db_get_all_rows_sql("
|
|
||||||
SELECT *
|
|
||||||
FROM tgrupo
|
|
||||||
WHERE id_grupo IN (" . $user_groups_ids . ")
|
|
||||||
ORDER BY nombre ASC");
|
|
||||||
break;
|
|
||||||
case "oracle":
|
|
||||||
$list_groups = db_get_all_rows_sql("
|
|
||||||
SELECT *
|
|
||||||
FROM tgrupo
|
|
||||||
WHERE id_grupo IN (" . $user_groups_ids . ")
|
|
||||||
ORDER BY nombre ASC");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$list = array();
|
$list = array();
|
||||||
@ -2422,10 +2394,11 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
|
|||||||
* Agent cache for metaconsole.
|
* Agent cache for metaconsole.
|
||||||
* Retrieve the statistic data from the cache table.
|
* Retrieve the statistic data from the cache table.
|
||||||
*/
|
*/
|
||||||
if (!$user_strict && is_metaconsole() && !empty($list_groups)) {
|
if (is_metaconsole() && !empty($list_groups)) {
|
||||||
$cache_table = 'tmetaconsole_agent';
|
$cache_table = 'tmetaconsole_agent';
|
||||||
|
|
||||||
$sql_stats = "SELECT id_grupo, COUNT(id_agente) AS agents_total,
|
$sql_stats =
|
||||||
|
"SELECT id_grupo, COUNT(id_agente) AS agents_total,
|
||||||
SUM(total_count) AS monitors_total,
|
SUM(total_count) AS monitors_total,
|
||||||
SUM(normal_count) AS monitors_ok,
|
SUM(normal_count) AS monitors_ok,
|
||||||
SUM(warning_count) AS monitors_warning,
|
SUM(warning_count) AS monitors_warning,
|
||||||
@ -2436,29 +2409,35 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
|
|||||||
FROM $cache_table
|
FROM $cache_table
|
||||||
WHERE disabled = 0
|
WHERE disabled = 0
|
||||||
AND id_grupo IN ($user_groups_ids)
|
AND id_grupo IN ($user_groups_ids)
|
||||||
GROUP BY id_grupo";
|
GROUP BY id_grupo"
|
||||||
|
;
|
||||||
$data_stats = db_get_all_rows_sql($sql_stats);
|
$data_stats = db_get_all_rows_sql($sql_stats);
|
||||||
|
|
||||||
$sql_stats_unknown = "SELECT id_grupo, COUNT(id_agente) AS agents_unknown
|
$sql_stats_unknown =
|
||||||
|
"SELECT id_grupo, COUNT(id_agente) AS agents_unknown
|
||||||
FROM $cache_table
|
FROM $cache_table
|
||||||
WHERE disabled = 0
|
WHERE disabled = 0
|
||||||
AND id_grupo IN ($user_groups_ids)
|
AND id_grupo IN ($user_groups_ids)
|
||||||
AND critical_count = 0
|
AND critical_count = 0
|
||||||
AND warning_count = 0
|
AND warning_count = 0
|
||||||
AND unknown_count > 0
|
AND unknown_count > 0
|
||||||
GROUP BY id_grupo";
|
GROUP BY id_grupo"
|
||||||
|
;
|
||||||
$data_stats_unknown = db_get_all_rows_sql($sql_stats_unknown);
|
$data_stats_unknown = db_get_all_rows_sql($sql_stats_unknown);
|
||||||
|
|
||||||
$sql_stats_not_init = "SELECT id_grupo, COUNT(id_agente) AS agents_not_init
|
$sql_stats_not_init =
|
||||||
|
"SELECT id_grupo, COUNT(id_agente) AS agents_not_init
|
||||||
FROM $cache_table
|
FROM $cache_table
|
||||||
WHERE disabled = 0
|
WHERE disabled = 0
|
||||||
AND id_grupo IN ($user_groups_ids)
|
AND id_grupo IN ($user_groups_ids)
|
||||||
AND (total_count = 0 OR total_count = notinit_count)
|
AND (total_count = 0 OR total_count = notinit_count)
|
||||||
GROUP BY id_grupo";
|
GROUP BY id_grupo"
|
||||||
|
;
|
||||||
$data_stats_not_init = db_get_all_rows_sql($sql_stats_not_init);
|
$data_stats_not_init = db_get_all_rows_sql($sql_stats_not_init);
|
||||||
|
|
||||||
if ($mode == 'tactical' || $mode == 'tree') {
|
if ($mode == 'tactical' || $mode == 'tree') {
|
||||||
$sql_stats_ok = "SELECT id_grupo, COUNT(id_agente) AS agents_ok
|
$sql_stats_ok =
|
||||||
|
"SELECT id_grupo, COUNT(id_agente) AS agents_ok
|
||||||
FROM $cache_table
|
FROM $cache_table
|
||||||
WHERE disabled = 0
|
WHERE disabled = 0
|
||||||
AND id_grupo IN ($user_groups_ids)
|
AND id_grupo IN ($user_groups_ids)
|
||||||
@ -2466,24 +2445,29 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
|
|||||||
AND warning_count = 0
|
AND warning_count = 0
|
||||||
AND unknown_count = 0
|
AND unknown_count = 0
|
||||||
AND normal_count > 0
|
AND normal_count > 0
|
||||||
GROUP BY id_grupo";
|
GROUP BY id_grupo"
|
||||||
|
;
|
||||||
$data_stats_ok = db_get_all_rows_sql($sql_stats_ok);
|
$data_stats_ok = db_get_all_rows_sql($sql_stats_ok);
|
||||||
|
|
||||||
$sql_stats_warning = "SELECT id_grupo, COUNT(id_agente) AS agents_warning
|
$sql_stats_warning =
|
||||||
|
"SELECT id_grupo, COUNT(id_agente) AS agents_warning
|
||||||
FROM $cache_table
|
FROM $cache_table
|
||||||
WHERE disabled = 0
|
WHERE disabled = 0
|
||||||
AND id_grupo IN ($user_groups_ids)
|
AND id_grupo IN ($user_groups_ids)
|
||||||
AND critical_count = 0
|
AND critical_count = 0
|
||||||
AND warning_count > 0
|
AND warning_count > 0
|
||||||
GROUP BY id_grupo";
|
GROUP BY id_grupo"
|
||||||
|
;
|
||||||
$data_stats_warning = db_get_all_rows_sql($sql_stats_warning);
|
$data_stats_warning = db_get_all_rows_sql($sql_stats_warning);
|
||||||
|
|
||||||
$sql_stats_critical = "SELECT id_grupo, COUNT(id_agente) AS agents_critical
|
$sql_stats_critical =
|
||||||
|
"SELECT id_grupo, COUNT(id_agente) AS agents_critical
|
||||||
FROM $cache_table
|
FROM $cache_table
|
||||||
WHERE disabled = 0
|
WHERE disabled = 0
|
||||||
AND id_grupo IN ($user_groups_ids)
|
AND id_grupo IN ($user_groups_ids)
|
||||||
AND critical_count > 0
|
AND critical_count > 0
|
||||||
GROUP BY id_grupo";
|
GROUP BY id_grupo"
|
||||||
|
;
|
||||||
$data_stats_critical = db_get_all_rows_sql($sql_stats_critical);
|
$data_stats_critical = db_get_all_rows_sql($sql_stats_critical);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2552,7 +2536,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
|
|||||||
foreach ($list_groups as $key => $item) {
|
foreach ($list_groups as $key => $item) {
|
||||||
$id = $item['id_grupo'];
|
$id = $item['id_grupo'];
|
||||||
|
|
||||||
if (!$user_strict && is_metaconsole()) { // Agent cache
|
if (is_metaconsole()) { // Agent cache
|
||||||
$group_stat = array();
|
$group_stat = array();
|
||||||
if (isset($stats_by_group[$id]))
|
if (isset($stats_by_group[$id]))
|
||||||
$group_stat = $stats_by_group[$id];
|
$group_stat = $stats_by_group[$id];
|
||||||
@ -2660,7 +2644,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (($config["realtimestats"] == 0) && !$user_strict) {
|
else if (($config["realtimestats"] == 0)) {
|
||||||
$group_stat = db_get_all_rows_sql ("SELECT *
|
$group_stat = db_get_all_rows_sql ("SELECT *
|
||||||
FROM tgroup_stat, tgrupo
|
FROM tgroup_stat, tgrupo
|
||||||
WHERE tgrupo.id_grupo = tgroup_stat.id_group
|
WHERE tgrupo.id_grupo = tgroup_stat.id_group
|
||||||
@ -2773,7 +2757,6 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$list[$i]['_id_'] = $id;
|
$list[$i]['_id_'] = $id;
|
||||||
@ -2882,112 +2865,6 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
|
|||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($user_strict) {
|
|
||||||
foreach ($user_tags as $group_id => $tag_name) {
|
|
||||||
$id = db_get_value('id_tag', 'ttag', 'name', $tag_name);
|
|
||||||
|
|
||||||
$list[$i]['_id_'] = $id;
|
|
||||||
$list[$i]['_name_'] = $tag_name;
|
|
||||||
$list[$i]['_iconImg_'] = html_print_image ("images/tag_red.png", true, array ("style" => 'vertical-align: middle;'));
|
|
||||||
$list[$i]['_is_tag_'] = 1;
|
|
||||||
|
|
||||||
$list[$i]['_total_agents_'] = (int) tags_get_total_agents ($id, $acltags, $agent_filter, $module_filter, $config["realtimestats"]);
|
|
||||||
$list[$i]['_agents_unknown_'] = (int) tags_get_unknown_agents ($id, $acltags, $agent_filter, $module_filter, $config["realtimestats"]);
|
|
||||||
$list[$i]['_agents_not_init_'] = (int) tags_get_not_init_agents ($id, $acltags, $agent_filter, $module_filter, $config["realtimestats"]);
|
|
||||||
$list[$i]['_monitors_ok_'] = (int) tags_get_normal_monitors ($id, $acltags, $agent_filter, $module_filter);
|
|
||||||
$list[$i]['_monitors_critical_'] = (int) tags_get_critical_monitors ($id, $acltags, $agent_filter, $module_filter);
|
|
||||||
$list[$i]['_monitors_warning_'] = (int) tags_get_warning_monitors ($id, $acltags, $agent_filter, $module_filter);
|
|
||||||
$list[$i]['_monitors_not_init_'] = (int) tags_get_not_init_monitors ($id, $acltags, $agent_filter, $module_filter);
|
|
||||||
$list[$i]['_monitors_unknown_'] = (int) tags_get_unknown_monitors ($id, $acltags, $agent_filter, $module_filter);
|
|
||||||
$list[$i]['_monitors_alerts_fired_'] = tags_monitors_fired_alerts($id, $acltags);
|
|
||||||
|
|
||||||
if ($mode == 'tactical' || $mode == 'tree') {
|
|
||||||
$list[$i]['_agents_ok_'] = (int) tags_get_normal_agents ($id, $acltags, $agent_filter, $module_filter, $config["realtimestats"]);
|
|
||||||
$list[$i]['_agents_warning_'] = (int) tags_get_warning_agents ($id, $acltags, $agent_filter, $module_filter, $config["realtimestats"]);
|
|
||||||
$list[$i]['_agents_critical_'] = (int) tags_get_critical_agents ($id, $acltags, $agent_filter, $module_filter, $config["realtimestats"]);
|
|
||||||
$list[$i]['_monitors_alerts_'] = tags_get_monitors_alerts ($id, $acltags);
|
|
||||||
}
|
|
||||||
if ($mode == 'tactical') {
|
|
||||||
// Get total count of monitors for this group, except disabled.
|
|
||||||
$list[$i]["_monitor_checks_"] = $list[$i]["_monitors_not_init_"] + $list[$i]["_monitors_unknown_"] + $list[$i]["_monitors_warning_"] + $list[$i]["_monitors_critical_"] + $list[$i]["_monitors_ok_"];
|
|
||||||
|
|
||||||
// Calculate not_normal monitors
|
|
||||||
$list[$i]["_monitor_not_normal_"] = $list[$i]["_monitor_checks_"] - $list[$i]["_monitors_ok_"];
|
|
||||||
|
|
||||||
if ($list[$i]["_monitor_not_normal_"] > 0 && $list[$i]["_monitor_checks_"] > 0) {
|
|
||||||
$list[$i]["_monitor_health_"] = format_numeric (100 - ($list[$i]["_monitor_not_normal_"] / ($list[$i]["_monitor_checks_"] / 100)), 1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$list[$i]["_monitor_health_"] = 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($list[$i]["_monitors_not_init_"] > 0 && $list[$i]["_monitor_checks_"] > 0) {
|
|
||||||
$list[$i]["_module_sanity_"] = format_numeric (100 - ($list[$i]["_monitors_not_init_"] / ($list[$i]["_monitor_checks_"] / 100)), 1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$list[$i]["_module_sanity_"] = 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($list[$i]["_monitors_alerts_"])) {
|
|
||||||
if ($list[$i]["_monitors_alerts_fired_"] > 0 && $list[$i]["_monitors_alerts_"] > 0) {
|
|
||||||
$list[$i]["_alert_level_"] = format_numeric (100 - ($list[$i]["_monitors_alerts_fired_"] / ($list[$i]["_monitors_alerts_"] / 100)), 1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$list[$i]["_alert_level_"] = 100;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$list[$i]["_alert_level_"] = 100;
|
|
||||||
$list[$i]["_monitors_alerts_"] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$list[$i]["_monitor_bad_"] = $list[$i]["_monitors_critical_"] + $list[$i]["_monitors_warning_"];
|
|
||||||
|
|
||||||
if ($list[$i]["_monitor_bad_"] > 0 && $list[$i]["_monitor_checks_"] > 0) {
|
|
||||||
$list[$i]["_global_health_"] = format_numeric (100 - ($list[$i]["_monitor_bad_"] / ($list[$i]["_monitor_checks_"] / 100)), 1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$list[$i]["_global_health_"] = 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
$list[$i]["_server_sanity_"] = format_numeric (100 - $list[$i]["_module_sanity_"], 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($returnAllGroup) {
|
|
||||||
$list[0]['_agents_unknown_'] += $list[$i]['_agents_unknown_'];
|
|
||||||
$list[0]['_monitors_alerts_fired_'] += $list[$i]['_monitors_alerts_fired_'];
|
|
||||||
$list[0]['_total_agents_'] += $list[$i]['_total_agents_'];
|
|
||||||
$list[0]['_monitors_ok_'] += $list[$i]['_monitors_ok_'];
|
|
||||||
$list[0]['_monitors_critical_'] += $list[$i]['_monitors_critical_'];
|
|
||||||
$list[0]['_monitors_warning_'] += $list[$i]['_monitors_warning_'];
|
|
||||||
$list[0]['_monitors_unknown_'] += $list[$i]['_monitors_unknown_'];
|
|
||||||
$list[0]['_agents_not_init_'] += $list[$i]['_agents_not_init_'];
|
|
||||||
$list[0]['_monitors_not_init_'] += $list[$i]['_monitors_not_init_'];
|
|
||||||
|
|
||||||
if ($mode == 'tactical' || $mode == 'tree') {
|
|
||||||
$list[0]['_agents_ok_'] += $list[$i]['_agents_ok_'];
|
|
||||||
$list[0]['_agents_warning_'] += $list[$i]['_agents_warning_'];
|
|
||||||
$list[0]['_agents_critical_'] += $list[$i]['_agents_critical_'];
|
|
||||||
$list[0]['_monitors_alerts_'] += $list[$i]['_monitors_alerts_'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($mode == 'group') {
|
|
||||||
if (! defined ('METACONSOLE')) {
|
|
||||||
if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0) && ($list[$i]['_monitors_unknown_'] == 0) && ($list[$i]['_monitors_not_init_'] == 0) && ($list[$i]['_agents_not_init_'] == 0)) {
|
|
||||||
unset($list[$i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0)) {
|
|
||||||
unset($list[$i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2751,4 +2751,28 @@ function modules_get_modules_status ($mod_status_id) {
|
|||||||
|
|
||||||
return $mod_status_desc;
|
return $mod_status_desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function modules_get_counter_by_states($state) {
|
||||||
|
switch ($state) {
|
||||||
|
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
|
||||||
|
case AGENT_MODULE_STATUS_CRITICAL_BAD:
|
||||||
|
return "critical_count";
|
||||||
|
case AGENT_MODULE_STATUS_WARNING_ALERT:
|
||||||
|
case AGENT_MODULE_STATUS_WARNING:
|
||||||
|
return "warning_count";
|
||||||
|
break;
|
||||||
|
case AGENT_MODULE_STATUS_UNKNOWN:
|
||||||
|
return "unknown_count";
|
||||||
|
case AGENT_MODULE_STATUS_NO_DATA:
|
||||||
|
case AGENT_MODULE_STATUS_NOT_INIT:
|
||||||
|
return "notinit_count";
|
||||||
|
case AGENT_MODULE_STATUS_NORMAL_ALERT:
|
||||||
|
case AGENT_MODULE_STATUS_NORMAL:
|
||||||
|
return "normal_count";
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the state is not an expected state, return condition
|
||||||
|
// to not show any data
|
||||||
|
return false;
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user