remove group cache in tree view
This commit is contained in:
parent
4781809e14
commit
f3a2bda1a5
|
@ -135,98 +135,81 @@ class TreeGroup extends Tree {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getGroupCounters() {
|
protected function getGroupCounters() {
|
||||||
//FIXME PLEASE
|
$fields = $this->getFirstLevelFields();
|
||||||
if (true) {
|
$inside_fields = $this->getFirstLevelFieldsInside();
|
||||||
$fields = $this->getFirstLevelFields();
|
|
||||||
$inside_fields = $this->getFirstLevelFieldsInside();
|
|
||||||
|
|
||||||
$group_acl = "";
|
$group_acl = "";
|
||||||
$secondary_group_acl = "";
|
$secondary_group_acl = "";
|
||||||
if (!users_can_manage_group_all("AR")) {
|
if (!users_can_manage_group_all("AR")) {
|
||||||
$user_groups_str = implode(",", $this->userGroupsArray);
|
$user_groups_str = implode(",", $this->userGroupsArray);
|
||||||
$group_acl = " AND ta.id_grupo IN ($user_groups_str)";
|
$group_acl = " AND ta.id_grupo IN ($user_groups_str)";
|
||||||
$secondary_group_acl = " AND tasg.id_group 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{
|
$agent_search_filter = $this->getAgentSearchFilter();
|
||||||
$stats = db_get_all_rows_sql(
|
$agent_search_filter = preg_replace("/%/", "%%", $agent_search_filter);
|
||||||
'SELECT tgs.agents AS total_count, tgs.critical AS total_critical_count,
|
$agent_status_filter = $this->getAgentStatusFilter();
|
||||||
tgs.unknown AS total_unknown_count, tgs.warning AS total_warning_count,
|
$module_status_filter = $this->getModuleStatusFilter();
|
||||||
`non-init` AS total_not_init_count, tgs.normal AS total_normal_count,
|
|
||||||
tgs.alerts_fired AS total_alerts_count,
|
$module_search_inner = "";
|
||||||
tg.nombre AS name, tg.parent, tg.icon, tg.id_grupo AS gid
|
$module_search_filter = "";
|
||||||
FROM tgroup_stat tgs
|
if (!empty($this->filter['searchModule'])) {
|
||||||
INNER JOIN tgrupo tg
|
$module_search_inner = "
|
||||||
ON tg.id_grupo = tgs.id_group
|
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()
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Update the group cache (from db or calculated).
|
$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);
|
||||||
|
|
||||||
$group_stats = array();
|
$group_stats = array();
|
||||||
|
|
||||||
foreach ($stats as $group) {
|
foreach ($stats as $group) {
|
||||||
$group_stats[$group['gid']]['total_count'] = (int)$group['total_count'];
|
$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_critical_count'] = (int)$group['total_critical_count'];
|
||||||
|
@ -242,10 +225,6 @@ class TreeGroup extends Tree {
|
||||||
$group_stats[$group['gid']] = $this->getProcessedItem($group_stats[$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;
|
return $group_stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue