From e83485ce8c64f12017076f82cbeb35cd4b96abea Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Mon, 8 Nov 2021 18:01:09 +0100 Subject: [PATCH] fixed several counts --- pandora_console/include/functions_agents.php | 2 +- pandora_console/include/functions_servers.php | 7 +-- .../include/functions_tactical.php | 59 ++++++++----------- 3 files changed, 27 insertions(+), 41 deletions(-) diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index fd121a28e2..26ad1c59dc 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -679,7 +679,7 @@ function agents_get_agents( // Add the group filter to $where = db_format_array_where_clause_sql($filter, 'AND', '('.$where_secondary.') AND '); if ($where == '' && $where_secondary != '') { - $where = $where_secondary; + $where = '('.$where_secondary.')'; } $where_nogroup = db_format_array_where_clause_sql( diff --git a/pandora_console/include/functions_servers.php b/pandora_console/include/functions_servers.php index 635281b308..4f405efb00 100644 --- a/pandora_console/include/functions_servers.php +++ b/pandora_console/include/functions_servers.php @@ -177,13 +177,8 @@ function servers_get_performance() WHERE tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente.id_agente = tagente_estado.id_agente AND tagente_modulo.disabled = 0 + AND tagente_modulo.id_modulo <> 0 AND delete_pending = 0 - AND (utimestamp > 0 - OR (id_tipo_modulo = 100 - OR (id_tipo_modulo > 21 - AND id_tipo_modulo < 23) - ) - ) AND tagente.disabled = 0 GROUP BY tagente_modulo.id_modulo' ); diff --git a/pandora_console/include/functions_tactical.php b/pandora_console/include/functions_tactical.php index 269df899d4..e465b20237 100644 --- a/pandora_console/include/functions_tactical.php +++ b/pandora_console/include/functions_tactical.php @@ -292,7 +292,7 @@ function tactical_get_data($id_user=false, $user_strict=false, $acltags, $return $list['_total_agents_'] = $total_agentes[0]['total_agents']; $list['_monitor_alerts_fire_count_'] = $group_stat[0]['alerts_fired']; - $list['_monitors_alerts_'] = tactical_monitor_alerts(explode(',', $user_groups_ids), $user_strict, explode(',', $user_groups_ids)); + $list['_monitors_alerts_'] = tactical_monitor_alerts($user_strict); // Get total count of monitors for this group, except disabled. $list['_monitor_checks_'] = ($list['_monitors_not_init_'] + $list['_monitors_unknown_'] + $list['_monitors_warning_'] + $list['_monitors_critical_'] + $list['_monitors_ok_']); @@ -411,12 +411,12 @@ function tactical_get_data($id_user=false, $user_strict=false, $acltags, $return } $list['_monitors_alerts_fired_'] = tactical_monitor_fired_alerts(explode(',', $user_groups_ids), $user_strict, explode(',', $user_groups_ids)); - $list['_monitors_alerts_'] = tactical_monitor_alerts(explode(',', $user_groups_ids), $user_strict, explode(',', $user_groups_ids)); + $list['_monitors_alerts_'] = tactical_monitor_alerts($user_strict); $total_agentes = agents_get_agents(false, ['count(DISTINCT id_agente) as total_agents'], 'AR', false, false, 1); $list['_total_agents_'] = $total_agentes[0]['total_agents']; - $list['_monitor_checks_'] = ($list['_monitors_unknown_'] + $list['_monitors_warning_'] + $list['_monitors_critical_'] + $list['_monitors_ok_']); + $list['_monitor_checks_'] = ($list['_monitors_not_init_'] + $list['_monitors_unknown_'] + $list['_monitors_warning_'] + $list['_monitors_critical_'] + $list['_monitors_ok_']); // Calculate not_normal monitors $list['_monitor_not_normal_'] = ($list['_monitor_checks_'] - $list['_monitors_ok_']); @@ -442,42 +442,33 @@ function tactical_status_modules_agents($id_user=false, $user_strict=false, $acc } -function tactical_monitor_alerts($group_array, $strict_user=false, $id_group_strict=false) +function tactical_monitor_alerts($strict_user=false) { - // If there are not groups to query, we jump to nextone - if (empty($group_array)) { - return 0; - } else if (!is_array($group_array)) { - $group_array = [$group_array]; - } + $groups = users_get_groups($config['id_user'], 'AR', false); + $id_groups = array_keys($groups); - $group_clause = implode(',', $group_array); - $group_clause = '('.$group_clause.')'; - - if ($strict_user) { - $group_clause_strict = implode(',', $id_group_strict); - $group_clause_strict = '('.$group_clause_strict.')'; - $sql = "SELECT COUNT(talert_template_modules.id) - FROM talert_template_modules, tagente_modulo, tagente_estado, tagente - WHERE tagente.id_grupo IN $group_clause_strict AND tagente_modulo.id_agente = tagente.id_agente - AND tagente.disabled = 0 AND tagente_modulo.disabled = 0 - AND talert_template_modules.disabled = 0 - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo"; - $count = db_get_sql($sql); - return $count; + if (empty($id_groups)) { + $where_clause .= ' AND (1 = 0) '; } else { - // TODO REVIEW ORACLE AND POSTGRES - return db_get_sql( - "SELECT COUNT(talert_template_modules.id) - FROM talert_template_modules, tagente_modulo, tagente_estado, tagente - WHERE tagente.id_grupo IN $group_clause AND tagente_modulo.id_agente = tagente.id_agente - AND tagente.disabled = 0 AND tagente_modulo.disabled = 0 - AND talert_template_modules.disabled = 0 - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo" + $where_clause .= sprintf( + ' AND id_agent_module IN ( + SELECT tam.id_agente_modulo + FROM tagente_modulo tam + WHERE tam.id_agente IN (SELECT ta.id_agente + FROM tagente ta LEFT JOIN tagent_secondary_group tasg ON + ta.id_agente = tasg.id_agent + WHERE (ta.id_grupo IN (%s) OR tasg.id_group IN (%s)))) ', + implode(',', $id_groups), + implode(',', $id_groups) ); } + + $filter_alert = []; + $filter_alert['disabled'] = 'all_enabled'; + + $alert_count = get_group_alerts($id_groups, $filter_alert, false, $where_clause, false, false, false, true, $strict_user); + + return $alert_count; }