Merge branch 'ent-8168-La-vista-tactica-de-metaconsola-no-tiene-en-cuenta-el-propagate-ACL-de-los-grupos' into 'develop'

fixed propagation in agents count

See merge request artica/pandorafms!4529
This commit is contained in:
Daniel Rodriguez 2021-11-18 16:36:55 +00:00
commit 04e6e875b3
1 changed files with 103 additions and 48 deletions

View File

@ -105,64 +105,119 @@ function tactical_get_data($id_user=false, $user_strict=false, $acltags, $return
if (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, if (users_is_admin() === false) {
SUM(total_count) AS monitors_total, $user_groups_ids_array = explode(',', $user_groups_ids);
SUM(normal_count) AS monitors_ok,
SUM(warning_count) AS monitors_warning, $user_group_children_ids = [];
SUM(critical_count) AS monitors_critical,
SUM(unknown_count) AS monitors_unknown, foreach ($user_groups_ids_array as $user_group_id) {
SUM(notinit_count) AS monitors_not_init, $group_children_ids = groups_get_children_ids($user_group_id);
SUM(fired_count) AS alerts_fired $user_group_children_ids = array_merge($user_group_children_ids, $group_children_ids);
FROM $cache_table }
WHERE disabled = 0
AND id_grupo IN ($user_groups_ids) $user_groups_ids = implode(',', array_unique($user_group_children_ids));
GROUP BY id_grupo"; }
$sql_stats = sprintf(
'SELECT tma.id_grupo, COUNT(tma.id_agente) AS agents_total,
SUM(tma.total_count) AS monitors_total,
SUM(tma.normal_count) AS monitors_ok,
SUM(tma.warning_count) AS monitors_warning,
SUM(tma.critical_count) AS monitors_critical,
SUM(tma.unknown_count) AS monitors_unknown,
SUM(tma.notinit_count) AS monitors_not_init,
SUM(tma.fired_count) AS alerts_fired
FROM tmetaconsole_agent tma
LEFT JOIN tmetaconsole_agent_secondary_group tmasg
ON tma.id_agente = tmasg.id_agent
WHERE tma.disabled = 0
AND tma.id_grupo IN (%s) OR tmasg.id_group IN (%s)
GROUP BY tma.id_grupo',
$user_groups_ids,
$user_groups_ids
);
$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 = sprintf(
FROM $cache_table 'SELECT tma.id_grupo, COUNT(tma.id_agente) AS agents_unknown
WHERE disabled = 0 FROM tmetaconsole_agent tma
AND id_grupo IN ($user_groups_ids) LEFT JOIN tmetaconsole_agent_secondary_group tmasg
AND critical_count = 0 ON tma.id_agente = tmasg.id_agent
AND warning_count = 0 WHERE tma.disabled = 0
AND unknown_count > 0 AND (tma.id_grupo IN (%s) OR tmasg.id_group IN (%s))
GROUP BY id_grupo"; AND tma.critical_count = 0
AND tma.warning_count = 0
AND tma.unknown_count > 0
GROUP BY tma.id_grupo',
$user_groups_ids,
$user_groups_ids
);
$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 = sprintf(
FROM $cache_table 'SELECT tma.id_grupo, COUNT(tma.id_agente) AS agents_not_init
WHERE disabled = 0 FROM tmetaconsole_agent tma
AND id_grupo IN ($user_groups_ids) LEFT JOIN tmetaconsole_agent_secondary_group tmasg
AND (total_count = 0 OR total_count = notinit_count) ON tma.id_agente = tmasg.id_agent
GROUP BY id_grupo"; WHERE tma.disabled = 0
AND (tma.id_grupo IN (%s) OR tmasg.id_group IN (%s))
AND (tma.total_count = 0 OR tma.total_count = tma.notinit_count)
GROUP BY tma.id_grupo',
$user_groups_ids,
$user_groups_ids
);
$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);
$sql_stats_ok = "SELECT id_grupo, COUNT(id_agente) AS agents_ok $sql_stats_ok = sprintf(
FROM $cache_table 'SELECT tma.id_grupo, COUNT(tma.id_agente) AS agents_ok
WHERE disabled = 0 FROM tmetaconsole_agent tma
AND id_grupo IN ($user_groups_ids) LEFT JOIN tmetaconsole_agent_secondary_group tmasg
AND critical_count = 0 ON tma.id_agente = tmasg.id_agent
AND warning_count = 0 WHERE tma.disabled = 0
AND unknown_count = 0 AND (tma.id_grupo IN (%s) OR tmasg.id_group IN (%s))
AND normal_count > 0 AND tma.critical_count = 0
GROUP BY id_grupo"; AND tma.warning_count = 0
AND tma.unknown_count = 0
AND tma.normal_count > 0
GROUP BY tma.id_grupo',
$user_groups_ids,
$user_groups_ids
);
$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 = sprintf(
FROM $cache_table 'SELECT tma.id_grupo, COUNT(tma.id_agente) AS agents_warning
WHERE disabled = 0 FROM tmetaconsole_agent tma
AND id_grupo IN ($user_groups_ids) LEFT JOIN tmetaconsole_agent_secondary_group tmasg
AND critical_count = 0 ON tma.id_agente = tmasg.id_agent
AND warning_count > 0 WHERE tma.disabled = 0
GROUP BY id_grupo"; AND (tma.id_grupo IN (%s) OR tmasg.id_group IN (%s))
AND tma.critical_count = 0
AND tma.warning_count > 0
GROUP BY tma.id_grupo',
$user_groups_ids,
$user_groups_ids
);
$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 = sprintf(
FROM $cache_table 'SELECT tma.id_grupo, COUNT(tma.id_agente) AS agents_critical
WHERE disabled = 0 FROM tmetaconsole_agent tma
AND id_grupo IN ($user_groups_ids) LEFT JOIN tmetaconsole_agent_secondary_group tmasg
AND critical_count > 0 ON tma.id_agente = tmasg.id_agent
GROUP BY id_grupo"; WHERE tma.disabled = 0
AND (tma.id_grupo IN (%s) OR tmasg.id_group IN (%s))
AND tma.critical_count > 0
GROUP BY tma.id_grupo',
$user_groups_ids,
$user_groups_ids
);
$data_stats_critical = db_get_all_rows_sql($sql_stats_critical); $data_stats_critical = db_get_all_rows_sql($sql_stats_critical);
if (!empty($data_stats)) { if (!empty($data_stats)) {