Merge branch 'ent-8200-Conteos-incorrectos-vista-tactica-en-FENIX-en-v758' into 'develop'

fixed several counts

See merge request artica/pandorafms!4527
This commit is contained in:
Daniel Rodriguez 2021-11-19 10:46:15 +00:00
commit 7b4c6848f7
3 changed files with 29 additions and 41 deletions

View File

@ -679,7 +679,7 @@ function agents_get_agents(
// Add the group filter to // Add the group filter to
$where = db_format_array_where_clause_sql($filter, 'AND', '('.$where_secondary.') AND '); $where = db_format_array_where_clause_sql($filter, 'AND', '('.$where_secondary.') AND ');
if ($where == '' && $where_secondary != '') { if ($where == '' && $where_secondary != '') {
$where = $where_secondary; $where = '('.$where_secondary.')';
} }
$where_nogroup = db_format_array_where_clause_sql( $where_nogroup = db_format_array_where_clause_sql(

View File

@ -177,13 +177,8 @@ function servers_get_performance()
WHERE tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo WHERE tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND tagente.id_agente = tagente_estado.id_agente AND tagente.id_agente = tagente_estado.id_agente
AND tagente_modulo.disabled = 0 AND tagente_modulo.disabled = 0
AND tagente_modulo.id_modulo <> 0
AND delete_pending = 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 AND tagente.disabled = 0
GROUP BY tagente_modulo.id_modulo' GROUP BY tagente_modulo.id_modulo'
); );

View File

@ -347,7 +347,7 @@ function tactical_get_data($id_user=false, $user_strict=false, $acltags, $return
$list['_total_agents_'] = $total_agentes[0]['total_agents']; $list['_total_agents_'] = $total_agentes[0]['total_agents'];
$list['_monitor_alerts_fire_count_'] = $group_stat[0]['alerts_fired']; $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. // 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_']); $list['_monitor_checks_'] = ($list['_monitors_not_init_'] + $list['_monitors_unknown_'] + $list['_monitors_warning_'] + $list['_monitors_critical_'] + $list['_monitors_ok_']);
@ -466,12 +466,14 @@ 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_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); $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['_total_agents_'] = $total_agentes[0]['total_agents'];
$list['_monitor_checks_'] = ($list['_monitors_not_init_'] + $list['_monitors_unknown_'] + $list['_monitors_warning_'] + $list['_monitors_critical_'] + $list['_monitors_ok_']);
$list['_monitor_total_'] = ($list['_monitors_not_init_'] + $list['_monitors_unknown_'] + $list['_monitors_warning_'] + $list['_monitors_critical_'] + $list['_monitors_ok_']); $list['_monitor_total_'] = ($list['_monitors_not_init_'] + $list['_monitors_unknown_'] + $list['_monitors_warning_'] + $list['_monitors_critical_'] + $list['_monitors_ok_']);
$list['_monitor_checks_'] = ($list['_monitors_unknown_'] + $list['_monitors_warning_'] + $list['_monitors_critical_'] + $list['_monitors_ok_']);
// Calculate not_normal monitors // Calculate not_normal monitors
$list['_monitor_not_normal_'] = ($list['_monitor_checks_'] - $list['_monitors_ok_']); $list['_monitor_not_normal_'] = ($list['_monitor_checks_'] - $list['_monitors_ok_']);
@ -497,42 +499,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 $groups = users_get_groups($config['id_user'], 'AR', false);
if (empty($group_array)) { $id_groups = array_keys($groups);
return 0;
} else if (!is_array($group_array)) {
$group_array = [$group_array];
}
$group_clause = implode(',', $group_array); if (empty($id_groups)) {
$group_clause = '('.$group_clause.')'; $where_clause .= ' AND (1 = 0) ';
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;
} else { } else {
// TODO REVIEW ORACLE AND POSTGRES $where_clause .= sprintf(
return db_get_sql( ' AND id_agent_module IN (
"SELECT COUNT(talert_template_modules.id) SELECT tam.id_agente_modulo
FROM talert_template_modules, tagente_modulo, tagente_estado, tagente FROM tagente_modulo tam
WHERE tagente.id_grupo IN $group_clause AND tagente_modulo.id_agente = tagente.id_agente WHERE tam.id_agente IN (SELECT ta.id_agente
AND tagente.disabled = 0 AND tagente_modulo.disabled = 0 FROM tagente ta LEFT JOIN tagent_secondary_group tasg ON
AND talert_template_modules.disabled = 0 ta.id_agente = tasg.id_agent
AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo WHERE (ta.id_grupo IN (%s) OR tasg.id_group IN (%s)))) ',
AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo" 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;
} }