performance improve view groups
This commit is contained in:
parent
6072cd3dc9
commit
ac0f0536c7
|
@ -278,7 +278,7 @@ class Tree {
|
|||
: " AND $filter ";
|
||||
}
|
||||
|
||||
protected function getGroupAclCondition() {
|
||||
static function getGroupAclCondition() {
|
||||
if (users_can_manage_group_all("AR")) return "";
|
||||
|
||||
$groups_str= implode(",", $this->userGroupsArray);
|
||||
|
@ -301,105 +301,6 @@ class Tree {
|
|||
return " AND tg.nombre LIKE '%" . $this->filter['searchGroup'] . "%'";
|
||||
}
|
||||
|
||||
protected function getAgentCounterColumnsSql ($agent_table) {
|
||||
// Add the agent counters to the columns
|
||||
|
||||
if ($this->filter['statusAgent'] == -1) {
|
||||
// Critical
|
||||
$agent_critical_filter = $this->getAgentStatusFilter(AGENT_STATUS_CRITICAL);
|
||||
$agents_critical_count = "($agent_table
|
||||
$agent_critical_filter) AS total_critical_count";
|
||||
// Warning
|
||||
$agent_warning_filter = $this->getAgentStatusFilter(AGENT_STATUS_WARNING);
|
||||
$agents_warning_count = "($agent_table
|
||||
$agent_warning_filter) AS total_warning_count";
|
||||
// Unknown
|
||||
$agent_unknown_filter = $this->getAgentStatusFilter(AGENT_STATUS_UNKNOWN);
|
||||
$agents_unknown_count = "($agent_table
|
||||
$agent_unknown_filter) AS total_unknown_count";
|
||||
// Normal
|
||||
$agent_normal_filter = $this->getAgentStatusFilter(AGENT_STATUS_NORMAL);
|
||||
$agents_normal_count = "($agent_table
|
||||
$agent_normal_filter) AS total_normal_count";
|
||||
// Not init
|
||||
if($this->filter['show_not_init_agents']){
|
||||
$agent_not_init_filter = $this->getAgentStatusFilter(AGENT_STATUS_NOT_INIT);
|
||||
$agents_not_init_count = "($agent_table
|
||||
$agent_not_init_filter) AS total_not_init_count";
|
||||
}
|
||||
else{
|
||||
$agent_not_init_filter = 0;
|
||||
$agents_not_init_count = 0;
|
||||
}
|
||||
|
||||
// Alerts fired
|
||||
$agents_fired_count = "($agent_table
|
||||
AND ta.fired_count > 0) AS total_fired_count";
|
||||
// Total
|
||||
$agents_total_count = "($agent_table) AS total_count";
|
||||
|
||||
$columns = "$agents_critical_count, $agents_warning_count, "
|
||||
. "$agents_unknown_count, $agents_normal_count, $agents_not_init_count, "
|
||||
. "$agents_fired_count, $agents_total_count";
|
||||
}
|
||||
else {
|
||||
// Alerts fired
|
||||
$agents_fired_count = "($agent_table
|
||||
AND ta.fired_count > 0) AS total_fired_count";
|
||||
// Total
|
||||
$agents_total_count = "($agent_table) AS total_count";
|
||||
|
||||
switch ($this->filter['statusAgent']) {
|
||||
case AGENT_STATUS_NOT_INIT:
|
||||
// Not init
|
||||
$agent_not_init_filter = $this->getAgentStatusFilter(AGENT_STATUS_NOT_INIT);
|
||||
$agents_not_init_count = "($agent_table
|
||||
$agent_not_init_filter) AS total_not_init_count";
|
||||
$columns = "$agents_not_init_count, $agents_fired_count, $agents_total_count";
|
||||
break;
|
||||
case AGENT_STATUS_CRITICAL:
|
||||
// Critical
|
||||
$agent_critical_filter = $this->getAgentStatusFilter(AGENT_STATUS_CRITICAL);
|
||||
$agents_critical_count = "($agent_table
|
||||
$agent_critical_filter) AS total_critical_count";
|
||||
$columns = "$agents_critical_count, $agents_fired_count, $agents_total_count";
|
||||
break;
|
||||
case AGENT_STATUS_WARNING:
|
||||
// Warning
|
||||
$agent_warning_filter = $this->getAgentStatusFilter(AGENT_STATUS_WARNING);
|
||||
$agents_warning_count = "($agent_table
|
||||
$agent_warning_filter) AS total_warning_count";
|
||||
$columns = "$agents_warning_count, $agents_fired_count, $agents_total_count";
|
||||
break;
|
||||
case AGENT_STATUS_UNKNOWN:
|
||||
// Unknown
|
||||
$agent_unknown_filter = $this->getAgentStatusFilter(AGENT_STATUS_UNKNOWN);
|
||||
$agents_unknown_count = "($agent_table
|
||||
$agent_unknown_filter) AS total_unknown_count";
|
||||
$columns = "$agents_unknown_count, $agents_fired_count, $agents_total_count";
|
||||
break;
|
||||
case AGENT_STATUS_NORMAL:
|
||||
// Normal
|
||||
$agent_normal_filter = $this->getAgentStatusFilter(AGENT_STATUS_NORMAL);
|
||||
$agents_normal_count = "($agent_table
|
||||
$agent_normal_filter) AS total_normal_count";
|
||||
$columns = "$agents_normal_count, $agents_fired_count, $agents_total_count";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
protected function getAgentCountersSql ($agent_table) {
|
||||
global $config;
|
||||
|
||||
$columns = $this->getAgentCounterColumnsSql($agent_table);
|
||||
$columns = "SELECT $columns FROM dual LIMIT 1";
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
static function cmpSortNames($a, $b) {
|
||||
return strcmp($a["name"], $b["name"]);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ require_once($config['homedir']."/include/class/Tree.class.php");
|
|||
|
||||
class TreeGroup extends Tree {
|
||||
|
||||
protected $propagateCounters = true;
|
||||
|
||||
public function __construct($type, $rootType = '', $id = -1, $rootID = -1, $serverID = false, $childrenMethod = "on_demand", $access = 'AR') {
|
||||
|
||||
global $config;
|
||||
|
@ -38,6 +40,10 @@ class TreeGroup extends Tree {
|
|||
)";
|
||||
}
|
||||
|
||||
public function setPropagateCounters($value) {
|
||||
$this->propagateCounters = (bool)$value;
|
||||
}
|
||||
|
||||
protected function getData() {
|
||||
if ($this->id == -1) {
|
||||
$this->getFirstLevel();
|
||||
|
@ -126,9 +132,13 @@ class TreeGroup extends Tree {
|
|||
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);
|
||||
if ($this->propagateCounters) {
|
||||
TreeGroup::processCounters($groups);
|
||||
// Filter groups and eliminates the reference to empty groups
|
||||
$groups = TreeGroup::deleteEmptyGroups($groups);
|
||||
} else {
|
||||
$groups = TreeGroup::deleteEmptyGroupsNotPropagate($groups);
|
||||
}
|
||||
|
||||
usort($groups, array("Tree", "cmpSortNames"));
|
||||
return $groups;
|
||||
|
@ -353,6 +363,32 @@ class TreeGroup extends Tree {
|
|||
return $new_groups;
|
||||
}
|
||||
|
||||
protected static function deleteEmptyGroupsNotPropagate ($groups) {
|
||||
$new_groups = array();
|
||||
foreach ($groups as $group) {
|
||||
// Tray to remove the children groups
|
||||
if (!empty($group['children'])) {
|
||||
$children = TreeGroup::deleteEmptyGroupsNotPropagate ($group['children']);
|
||||
if (empty($children)) {
|
||||
unset($group['children']);
|
||||
// If a group is empty, do not add to new_groups.
|
||||
if (isset($group['counters']['total']) && $group['counters']['total'] != 0) {
|
||||
$new_groups[] = $group;
|
||||
}
|
||||
} else {
|
||||
$group['children'] = $children;
|
||||
$new_groups[] = $group;
|
||||
}
|
||||
} else {
|
||||
// If a group is empty, do not add to new_groups.
|
||||
if (isset($group['counters']['total']) && $group['counters']['total'] != 0) {
|
||||
$new_groups[] = $group;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $new_groups;
|
||||
}
|
||||
|
||||
private static function extractGroupsWithIDs ($groups, $ids_hash) {
|
||||
$result_groups = array();
|
||||
foreach ($groups as $group) {
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
include_once ($config['homedir'] . "/include/functions_groups.php");
|
||||
include_once ($config['homedir'] . "/include/functions_tags.php");
|
||||
include_once ($config['homedir'] . "/include/class/Tree.class.php");
|
||||
include_once ($config['homedir'] . "/include/class/TreeGroup.class.php");
|
||||
|
||||
function groupview_get_all_data ($id_user = false, $user_strict = false, $acltags, $returnAllGroup = false, $agent_filter = array(), $module_filter = array(), $access = 'AR') {
|
||||
global $config;
|
||||
|
@ -411,406 +413,158 @@ function groupview_monitor_fired_alerts ($group_array, $strict_user = false, $id
|
|||
AND times_fired > 0");
|
||||
}
|
||||
|
||||
function groupview_plain_groups($groups) {
|
||||
$group_result = array();
|
||||
foreach ($groups as $group) {
|
||||
$plain_child = array();
|
||||
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;
|
||||
}
|
||||
|
||||
function groupview_get_modules_counters($groups_ids = false) {
|
||||
$groups_ids = implode(',', $groups_ids);
|
||||
|
||||
$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
|
||||
FROM tagente ta
|
||||
WHERE ta.id_grupo IN ($groups_ids)
|
||||
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
|
||||
FROM tagente ta
|
||||
INNER JOIN tagent_secondary_group tasg
|
||||
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);
|
||||
}
|
||||
|
||||
function groupview_get_all_counters() {
|
||||
$all_name = __("All");
|
||||
$group_acl = Tree::getGroupAclCondition();
|
||||
$sql =
|
||||
"SELECT SUM(ta.normal_count) AS _monitors_ok_,
|
||||
SUM(ta.critical_count) AS _monitors_critical_,
|
||||
SUM(ta.warning_count) AS _monitors_warning_,
|
||||
SUM(ta.unknown_count) AS _monitors_unknown_,
|
||||
SUM(ta.notinit_count) AS _monitors_not_init_,
|
||||
SUM(ta.fired_count) AS _monitors_alerts_fired_,
|
||||
SUM(ta.total_count) AS _monitor_checks_,
|
||||
SUM(IF(ta.critical_count > 0, 1, 0)) AS _agents_critical_,
|
||||
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_,
|
||||
COUNT(ta.id_agente) AS _total_agents_,
|
||||
'$all_name' AS _name_,
|
||||
0 AS _id_,
|
||||
'' AS _icon_
|
||||
FROM tagente ta
|
||||
WHERE ta.id_agente
|
||||
IN (
|
||||
SELECT ta.id_agente FROM tagente ta
|
||||
LEFT JOIN tagent_secondary_group tasg
|
||||
ON ta.id_agente = tasg.id_agent
|
||||
WHERE 1=1 $group_acl
|
||||
)
|
||||
";
|
||||
$data = db_get_row_sql($sql);
|
||||
$data["_monitor_not_normal_"] = $data["_monitor_checks_"] - $data["_monitors_ok_"];
|
||||
return $data;
|
||||
}
|
||||
|
||||
function groupview_get_groups_list($id_user = false, $access = 'AR') {
|
||||
global $config;
|
||||
if ($id_user == false) {
|
||||
$id_user = $config['id_user'];
|
||||
}
|
||||
|
||||
$user_groups = users_get_groups($id_user, $access, true, false);
|
||||
$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,
|
||||
));
|
||||
$info = $tree_group->getArray();
|
||||
$info = groupview_plain_groups($info);
|
||||
$counter = count($info);
|
||||
|
||||
$groups_with_privileges = implode(',', array_keys($user_groups));
|
||||
$offset = get_parameter('offset', 0);
|
||||
$groups_view = array_slice($info, $offset, $config['block_size']);
|
||||
$agents_counters = array_reduce($groups_view, function($carry, $item){
|
||||
$carry[$item['id']] = $item;
|
||||
return $carry;
|
||||
}, array());
|
||||
|
||||
//change ALL for 0
|
||||
$user_groups[0] = 0;
|
||||
$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());
|
||||
|
||||
$user_groups_ids = implode(',', array_keys($user_groups));
|
||||
$total_counters = array();
|
||||
|
||||
if (!empty($user_groups_ids)) {
|
||||
$table = is_metaconsole() ? 'tmetaconsole_agent' : 'tagente';
|
||||
$table_secondary = is_metaconsole()
|
||||
? 'tmetaconsole_agent_secondary_group'
|
||||
: 'tagent_secondary_group';
|
||||
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]['icon'] = $agent_counter['icon'];
|
||||
|
||||
$list_groups = db_get_all_rows_sql("
|
||||
SELECT *
|
||||
FROM tgrupo
|
||||
WHERE id_grupo IN ($user_groups_ids)
|
||||
AND (
|
||||
id_grupo IN (SELECT id_grupo FROM $table WHERE disabled = 0)
|
||||
OR id_grupo IN (SELECT id_group FROM $table_secondary WHERE id_group IN ($user_groups_ids))
|
||||
)
|
||||
ORDER BY nombre COLLATE utf8_general_ci ASC"
|
||||
);
|
||||
$list[$id_group]['_agents_not_init_'] = $agent_counter['counters']['not_init'];
|
||||
$list[$id_group]['_agents_unknown_'] = $agent_counter['counters']['unknown'];
|
||||
$list[$id_group]['_agents_critical_'] = $agent_counter['counters']['critical'];
|
||||
$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'];
|
||||
}
|
||||
|
||||
//Add the group "All" at first
|
||||
$group_all = array('id_grupo'=>0, 'nombre'=>'All', 'icon'=>'', 'parent'=>'', 'propagate'=>0, 'disabled'=>0,
|
||||
'custom_id'=>'', 'id_skin'=>0, 'description'=>'', 'contact'=>'', 'other'=>'', 'password'=>'');
|
||||
if ($list_groups !== false) {
|
||||
array_unshift($list_groups, $group_all);
|
||||
} else {
|
||||
$list_groups = array($group_all);
|
||||
}
|
||||
|
||||
//Takes the parents even without agents, first ids
|
||||
$fathers_id = '';
|
||||
$list_father_groups = array();
|
||||
foreach ($list_groups as $group) {
|
||||
if ($group['parent'] != '') {
|
||||
$grup = $group['parent'];
|
||||
while ($grup != 0) {
|
||||
$recursive_fathers = db_get_row_sql ("SELECT parent FROM tgrupo
|
||||
WHERE id_grupo = " . $grup);
|
||||
$grup = $recursive_fathers['parent'];
|
||||
if (!strpos($fathers_id, $grup)) {
|
||||
$fathers_id .= ',' . $grup;
|
||||
}
|
||||
}
|
||||
if (!strpos($fathers_id, $group['parent'])) {
|
||||
$fathers_id .= ',' . $group['parent'];
|
||||
}
|
||||
}
|
||||
}
|
||||
//Eliminate the first comma
|
||||
$fathers_id = substr($fathers_id, 1);
|
||||
while ($fathers_id{0} == ',') {
|
||||
$fathers_id = substr($fathers_id, 1);
|
||||
}
|
||||
//Takes the parents even without agents, complete groups
|
||||
if ($fathers_id) {
|
||||
$list_father_groups = db_get_all_rows_sql("
|
||||
SELECT *
|
||||
FROM tgrupo
|
||||
WHERE id_grupo IN (" . $fathers_id . ")
|
||||
AND id_grupo IN (" . $groups_with_privileges . ")
|
||||
ORDER BY nombre COLLATE utf8_general_ci ASC");
|
||||
if (!empty($list_father_groups)) {
|
||||
//Merges the arrays and eliminates the duplicates groups
|
||||
$list_groups = array_merge($list_groups, $list_father_groups);
|
||||
}
|
||||
}
|
||||
$list_groups = groupview_array_unique_multidim($list_groups, 'id_grupo');
|
||||
//Order groups (Father-children)
|
||||
$ordered_groups = groupview_order_groups_for_parents($list_groups);
|
||||
$ordered_ids = array();
|
||||
$ordered_ids = groupview_order_group_ids($ordered_groups, $ordered_ids);
|
||||
$final_list = array();
|
||||
array_push($final_list, $group_all);
|
||||
|
||||
foreach ($ordered_ids as $key) {
|
||||
if ($key == 'All') {
|
||||
continue;
|
||||
}
|
||||
$complete_group = db_get_row_sql("
|
||||
SELECT *
|
||||
FROM tgrupo
|
||||
WHERE nombre = '" . $key . "'");
|
||||
array_push($final_list, $complete_group);
|
||||
}
|
||||
|
||||
$list_groups = $final_list;
|
||||
|
||||
$list = array();
|
||||
foreach ($list_groups as $group) {
|
||||
$list[$group['id_grupo']]['_name_'] = $group['nombre'];
|
||||
$list[$group['id_grupo']]['_id_'] = $group['id_grupo'];
|
||||
$list[$group['id_grupo']]['icon'] = $group['icon'];
|
||||
$list[$group['id_grupo']]['_monitors_critical_'] = 0;
|
||||
$list[$group['id_grupo']]['_monitors_warning_'] = 0;
|
||||
$list[$group['id_grupo']]['_monitors_unknown_'] = 0;
|
||||
$list[$group['id_grupo']]['_monitors_not_init_'] = 0;
|
||||
$list[$group['id_grupo']]['_monitors_ok_'] = 0;
|
||||
$list[$group['id_grupo']]['_agents_not_init_'] = 0;
|
||||
$list[$group['id_grupo']]['_agents_unknown_'] = 0;
|
||||
$list[$group['id_grupo']]['_agents_critical_'] = 0;
|
||||
$list[$group['id_grupo']]['_total_agents_'] = 0;
|
||||
$list[$group['id_grupo']]["_monitor_checks_"] = 0;
|
||||
$list[$group['id_grupo']]["_monitor_not_normal_"] = 0;
|
||||
$list[$group['id_grupo']]['_monitors_alerts_fired_'] = 0;
|
||||
}
|
||||
|
||||
if ($list_groups == false) {
|
||||
$list_groups = array();
|
||||
}
|
||||
|
||||
if (is_metaconsole() || ($config["realtimestats"] == 0)) { // Agent cache
|
||||
$list = group_view_get_cache_stats ($list, $list_groups, $user_groups_ids);
|
||||
} else {
|
||||
foreach ($list_groups as $group) {
|
||||
// If id group is 0 get all accesses groups
|
||||
$group_id = $group['id_grupo'] == 0
|
||||
? $user_groups_ids
|
||||
: $group['id_grupo'];
|
||||
$agent_not_init = agents_get_agents(array (
|
||||
'disabled' => 0,
|
||||
'id_grupo' => $group['id_grupo'],
|
||||
'status' => AGENT_STATUS_NOT_INIT),
|
||||
array ('COUNT(DISTINCT id_agente) as total'), $access, false);
|
||||
$list[$group['id_grupo']]['_agents_not_init_'] = isset ($agent_not_init[0]['total']) ? $agent_not_init[0]['total'] : 0;
|
||||
$agent_unknown = agents_get_agents(array (
|
||||
'disabled' => 0,
|
||||
'id_grupo' => $group['id_grupo'],
|
||||
'status' => AGENT_STATUS_UNKNOWN),
|
||||
array ('COUNT(DISTINCT id_agente) as total'), $access, false);
|
||||
$list[$group['id_grupo']]['_agents_unknown_'] = isset ($agent_unknown[0]['total']) ? $agent_unknown[0]['total'] : 0;
|
||||
$agent_critical = agents_get_agents(array (
|
||||
'disabled' => 0,
|
||||
'id_grupo' => $group['id_grupo'],
|
||||
'status' => AGENT_STATUS_CRITICAL),
|
||||
array ('COUNT(DISTINCT id_agente) as total'), $access, false);
|
||||
$list[$group['id_grupo']]['_agents_critical_'] = isset ($agent_critical[0]['total']) ? $agent_critical[0]['total'] : 0;
|
||||
$agent_total = agents_get_agents(array (
|
||||
'disabled' => 0,
|
||||
'id_grupo' => $group['id_grupo']),
|
||||
array ('COUNT(DISTINCT id_agente) as total'), $access, false);
|
||||
$list[$group['id_grupo']]['_total_agents_'] = isset ($agent_total[0]['total']) ? $agent_total[0]['total'] : 0;
|
||||
$list[$group['id_grupo']]["_monitor_not_normal_"] = $list[$group['id_grupo']]["_monitor_checks_"] - $list[$group['id_grupo']]["_monitors_ok_"];
|
||||
$list[$group['id_grupo']]["_monitor_not_normal_"] = $list[$group['id_grupo']]["_monitor_checks_"] - $list[$group['id_grupo']]["_monitors_ok_"];
|
||||
$list[$group['id_grupo']]['_monitors_alerts_fired_'] = groupview_monitor_fired_alerts ($group['id_grupo'], $user_strict,$group['id_grupo']);
|
||||
$result_list = db_get_all_rows_sql("SELECT COUNT(*) as contado, estado
|
||||
FROM tagente_estado tae INNER JOIN tagente ta
|
||||
ON tae.id_agente = ta.id_agente
|
||||
AND ta.disabled = 0
|
||||
LEFT JOIN tagent_secondary_group tasg
|
||||
ON tasg.id_agent = ta.id_agente
|
||||
INNER JOIN tagente_modulo tam
|
||||
ON tae.id_agente_modulo = tam.id_agente_modulo
|
||||
AND tam.disabled = 0
|
||||
WHERE tae.utimestamp > 0
|
||||
AND (
|
||||
ta.id_grupo IN (" . $group_id . ")
|
||||
OR tasg.id_group IN (" . $group_id . ")
|
||||
)
|
||||
GROUP BY estado");
|
||||
if ($result_list) {
|
||||
foreach ($result_list as $result) {
|
||||
switch ($result['estado']) {
|
||||
case AGENT_MODULE_STATUS_CRITICAL_BAD:
|
||||
$list[$group['id_grupo']]['_monitors_critical_'] = (int)$result['contado'];
|
||||
break;
|
||||
case AGENT_MODULE_STATUS_WARNING_ALERT:
|
||||
break;
|
||||
case AGENT_MODULE_STATUS_WARNING:
|
||||
$list[$group['id_grupo']]['_monitors_warning_'] = (int)$result['contado'];
|
||||
break;
|
||||
case AGENT_MODULE_STATUS_UNKNOWN:
|
||||
$list[$group['id_grupo']]['_monitors_unknown_'] = (int)$result['contado'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result_normal = db_get_row_sql("SELECT COUNT(*) as contado
|
||||
FROM tagente_estado tae INNER JOIN tagente ta
|
||||
ON tae.id_agente = ta.id_agente
|
||||
AND ta.disabled = 0
|
||||
LEFT JOIN tagent_secondary_group tasg
|
||||
ON tasg.id_agent = ta.id_agente
|
||||
INNER JOIN tagente_modulo tam
|
||||
ON tae.id_agente_modulo = tam.id_agente_modulo
|
||||
AND tam.disabled = 0
|
||||
WHERE tae.estado = 0
|
||||
AND (tae.utimestamp > 0 OR tam.id_tipo_modulo IN(21,22,23,100))
|
||||
AND (
|
||||
ta.id_grupo IN (" . $group_id . ")
|
||||
OR tasg.id_group IN (" . $group_id . ")
|
||||
)
|
||||
GROUP BY estado");
|
||||
$list[$group['id_grupo']]['_monitors_ok_'] = isset ($result_normal['contado']) ? $result_normal['contado'] : 0;
|
||||
|
||||
$result_not_init = db_get_row_sql("SELECT COUNT(*) as contado
|
||||
FROM tagente_estado tae INNER JOIN tagente ta
|
||||
ON tae.id_agente = ta.id_agente
|
||||
AND ta.disabled = 0
|
||||
LEFT JOIN tagent_secondary_group tasg
|
||||
ON tasg.id_agent = ta.id_agente
|
||||
INNER JOIN tagente_modulo tam
|
||||
ON tae.id_agente_modulo = tam.id_agente_modulo
|
||||
AND tam.disabled = 0
|
||||
WHERE tae.utimestamp = 0 AND
|
||||
tae.estado IN (".AGENT_MODULE_STATUS_NO_DATA.",".AGENT_MODULE_STATUS_NOT_INIT." )
|
||||
AND tam.id_tipo_modulo NOT IN (21,22,23,100)
|
||||
AND (
|
||||
ta.id_grupo IN (" . $group_id . ")
|
||||
OR tasg.id_group IN (" . $group_id . ")
|
||||
)
|
||||
GROUP BY estado");
|
||||
$list[$group['id_grupo']]['_monitors_not_init_'] = isset ($result_not_init['contado']) ? $result_not_init['contado'] : 0;
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
//Order the groups by parents
|
||||
function groupview_order_groups_for_parents ($view_groups) {
|
||||
$final_groups = array();
|
||||
// Index the groups
|
||||
$groups = array();
|
||||
foreach ($view_groups as $item) {
|
||||
$groups[$item['id_grupo']] = $item;
|
||||
}
|
||||
// Build the group hierarchy
|
||||
foreach ($groups as $id => $group) {
|
||||
$groups[$id]['have_parent'] = false;
|
||||
if (!isset($groups[$id]['parent']))
|
||||
continue;
|
||||
$parent = $groups[$id]['parent'];
|
||||
// Parent exists
|
||||
if (isset($groups[$parent])) {
|
||||
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
|
||||
for ($i = 0; $i < count($groups); $i++) {
|
||||
if (isset($groups[$i]['children']))
|
||||
usort($groups[$i]['children'], function ($a, $b) {
|
||||
return strcmp($a["nombre"], $b["nombre"]);
|
||||
});
|
||||
}
|
||||
// Extract the root groups
|
||||
foreach ($groups as $group) {
|
||||
if (!$group['have_parent'])
|
||||
$final_groups[] = $group;
|
||||
}
|
||||
// Sort the root groups
|
||||
usort($final_groups, function ($a, $b) {
|
||||
return strcmp($a["name"], $b["name"]);
|
||||
});
|
||||
|
||||
return $final_groups;
|
||||
}
|
||||
|
||||
function groupview_order_group_ids($groups, $ordered_ids){
|
||||
foreach ($groups as $group) {
|
||||
if (!empty($group['children'])) {
|
||||
$ordered_ids[$group['id_grupo']] = $group['nombre'];
|
||||
$ordered_ids = groupview_order_group_ids($group['children'], $ordered_ids);
|
||||
}
|
||||
else {
|
||||
$ordered_ids[$group['id_grupo']] = $group['nombre'];
|
||||
}
|
||||
}
|
||||
return $ordered_ids;
|
||||
}
|
||||
|
||||
//Function to eliminate duplicates groups in multidimensional array
|
||||
function groupview_array_unique_multidim($groups, $key){
|
||||
$temp_group = array();
|
||||
$i = 0;
|
||||
$key_group = array();
|
||||
foreach($groups as $group){
|
||||
if(!in_array($group[$key],$key_group)){
|
||||
$key_group[$i] = $group[$key];
|
||||
$temp_group[$i] = $group;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
return $temp_group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stats to group view using the cache
|
||||
*
|
||||
* @param array Skeleton to fill with the group information
|
||||
* @param array Groups information
|
||||
* @param string Groups that user has access separated by commas
|
||||
*/
|
||||
function group_view_get_cache_stats ($list, $list_groups, $user_groups_ids) {
|
||||
|
||||
$table_agent = 'tagente';
|
||||
$table_secondary = 'tagent_secondary_group';
|
||||
// Change the metaconsole tables
|
||||
if (is_metaconsole()) {
|
||||
$table_agent = 'tmetaconsole_agent';
|
||||
$table_secondary = 'tmetaconsole_agent_secondary_group';
|
||||
}
|
||||
|
||||
// Walk for each group
|
||||
foreach ($list_groups as $group) {
|
||||
// If id group is 0 get all accesses groups
|
||||
$group_id = $group['id_grupo'] == 0
|
||||
? $user_groups_ids
|
||||
: $group['id_grupo'];
|
||||
$group_agents = db_get_row_sql("SELECT SUM(warning_count) AS _monitors_warning_,
|
||||
SUM(critical_count) AS _monitors_critical_,
|
||||
SUM(normal_count) AS _monitors_ok_,
|
||||
SUM(unknown_count) AS _monitors_unknown_,
|
||||
SUM(notinit_count) AS _monitors_not_init_,
|
||||
SUM(fired_count) AS _monitors_alerts_fired_,
|
||||
COUNT(*) AS _total_agents_, id_grupo, intervalo,
|
||||
ultimo_contacto, disabled
|
||||
FROM $table_agent ta
|
||||
LEFT JOIN $table_secondary tasg
|
||||
ON tasg.id_agent = ta.id_agente
|
||||
WHERE (
|
||||
ta.id_grupo IN (" . $group_id . ")
|
||||
OR tasg.id_group IN (" . $group_id . ")
|
||||
)
|
||||
AND disabled = 0");
|
||||
|
||||
$list[$group['id_grupo']]['_monitors_critical_'] = (int)$group_agents['_monitors_critical_'];
|
||||
$list[$group['id_grupo']]['_monitors_warning_'] = (int)$group_agents['_monitors_warning_'];
|
||||
$list[$group['id_grupo']]['_monitors_unknown_'] = (int)$group_agents['_monitors_unknown_'];
|
||||
$list[$group['id_grupo']]['_monitors_not_init_'] = (int)$group_agents['_monitors_not_init_'];
|
||||
$list[$group['id_grupo']]['_monitors_ok_'] = (int)$group_agents['_monitors_ok_'];
|
||||
$list[$group['id_grupo']]['_monitors_alerts_fired_'] = (int)$group_agents['_monitors_alerts_fired_'];
|
||||
$list[$group['id_grupo']]['_total_agents_'] = (int)$group_agents['_total_agents_'];
|
||||
$list[$group['id_grupo']]["_monitor_checks_"] = $list[$group['id_grupo']]["_monitors_not_init_"]
|
||||
+ $list[$group['id_grupo']]["_monitors_unknown_"]
|
||||
+ $list[$group['id_grupo']]["_monitors_warning_"]
|
||||
+ $list[$group['id_grupo']]["_monitors_critical_"]
|
||||
+ $list[$group['id_grupo']]["_monitors_ok_"];
|
||||
|
||||
if ($group['icon'])
|
||||
$list[$group['id_grupo']]["_iconImg_"] = html_print_image ("images/".$group['icon'].".png", true, array ("style" => 'vertical-align: middle;'));
|
||||
|
||||
// Calculate not_normal monitors
|
||||
$list[$group['id_grupo']]["_monitor_not_normal_"] = $list["_monitor_checks_"] - $list["_monitors_ok_"];
|
||||
|
||||
$total_agents = $list[$group['id_grupo']]['_total_agents_'];
|
||||
|
||||
if ($total_agents > 0) {
|
||||
$agents = db_get_all_rows_sql(sprintf ("SELECT warning_count,
|
||||
critical_count,
|
||||
normal_count,
|
||||
unknown_count,
|
||||
notinit_count,
|
||||
fired_count,
|
||||
disabled
|
||||
FROM $table_agent ta
|
||||
LEFT JOIN $table_secondary tasg
|
||||
ON ta.id_agente = tasg.id_agent
|
||||
WHERE ta.id_grupo IN (%s) OR tasg.id_group IN (%s)",
|
||||
$group_id, $group_id));
|
||||
foreach ($agents as $agent) {
|
||||
if ($agent['critical_count'] > 0) {
|
||||
$list[$group['id_grupo']]['_agents_critical_'] += 1;
|
||||
}
|
||||
else {
|
||||
if (($agent['critical_count'] == 0) && ($agent['warning_count'] == 0) && ($group_agents['disabled'] == 0) && ($agent['normal_count'] == 0)) {
|
||||
if ($agent['unknown_count'] > 0) {
|
||||
$list[$group['id_grupo']]['_agents_unknown_'] += 1;
|
||||
}
|
||||
}
|
||||
if (($agent['critical_count'] == 0) && ($agent['warning_count'] == 0) && ($group_agents['disabled'] == 0) && ($agent['normal_count'] == 0) && ($agent['unknown_count'] == 0)) {
|
||||
if ($agent['notinit_count'] > 0) {
|
||||
$list[$group['id_grupo']]['_agents_not_init_'] += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
array_unshift($list, groupview_get_all_counters());
|
||||
return array(
|
||||
'groups' => $list,
|
||||
'counter' => $counter
|
||||
);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -30,7 +30,6 @@ if (!$agent_a && !$agent_w) {
|
|||
require ("general/noaccess.php");
|
||||
exit;
|
||||
}
|
||||
$offset = get_parameter('offset', 0);
|
||||
// Update network modules for this group
|
||||
// Check for Network FLAG change request
|
||||
// Made it a subquery, much faster on both the database and server side
|
||||
|
@ -81,12 +80,12 @@ $agents_notinit = 0;
|
|||
$all_alerts_fired = 0;
|
||||
|
||||
//Groups and tags
|
||||
$result_groups = groupview_get_groups_list(
|
||||
$result_groups_info = groupview_get_groups_list(
|
||||
$config['id_user'],
|
||||
($agent_a == true) ? 'AR' : (($agent_w == true) ? 'AW' : 'AR')
|
||||
);
|
||||
|
||||
$count = count($result_groups);
|
||||
$result_groups = $result_groups_info['groups'];
|
||||
$count = $result_groups_info['counter'];
|
||||
|
||||
if ($result_groups[0]["_id_"] == 0) {
|
||||
$total_agentes = $result_groups[0]["_total_agents_"];
|
||||
|
@ -187,10 +186,7 @@ if (!empty($result_groups)) {
|
|||
echo "<th width='10%' style='min-width: 60px;text-align:center;'>" . __("Alert fired") . "</th>";
|
||||
echo "</tr>";
|
||||
|
||||
$result_groups = array_slice($result_groups, $offset, $config['block_size']);
|
||||
|
||||
foreach ($result_groups as $data) {
|
||||
|
||||
$groups_id = $data["_id_"];
|
||||
|
||||
// Calculate entire row color
|
||||
|
@ -454,4 +450,4 @@ if (!empty($result_groups)) {
|
|||
} else {
|
||||
ui_print_info_message ( __('There are no defined agents'));
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue