Alert report (group) Group + secondary groups + recursion
This commit is contained in:
parent
ff8aaf18fe
commit
0deff70f8b
|
@ -2830,3 +2830,83 @@ function alerts_ui_update_or_create_actions($update=true)
|
|||
$update ? __('Could not be updated') : __('Could not be created')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve all agent_modules with configured alerts filtered by group.
|
||||
*
|
||||
* @param integer|null $id_grupo Filter by group.
|
||||
* @param boolean $recursion Filter by group recursive.
|
||||
*
|
||||
* @return array With agent module ids.
|
||||
*/
|
||||
function alerts_get_agent_modules(
|
||||
?int $id_grupo,
|
||||
bool $recursion=false
|
||||
) : array {
|
||||
if ($id_grupo === null) {
|
||||
$agent_modules = db_get_all_rows_sql(
|
||||
'SELECT distinct(atm.id_agent_module)
|
||||
FROM talert_template_modules atm
|
||||
INNER JOIN tagente_modulo am
|
||||
ON am.id_agente_modulo = atm.id_agent_module
|
||||
WHERE atm.disabled = 0'
|
||||
);
|
||||
} else if ($recursion !== true) {
|
||||
$sql = sprintf(
|
||||
'SELECT distinct(atm.id_agent_module)
|
||||
FROM talert_template_modules atm
|
||||
INNER JOIN tagente_modulo am
|
||||
ON am.id_agente_modulo = atm.id_agent_module
|
||||
INNER JOIN tagente ta
|
||||
ON am.id_agente = ta.id_agente
|
||||
LEFT JOIN tagent_secondary_group tasg
|
||||
ON tasg.id_agent = ta.id_agente
|
||||
WHERE atm.disabled = 0
|
||||
AND (tasg.id_group = %d
|
||||
OR ta.id_grupo = %d)
|
||||
',
|
||||
$id_grupo,
|
||||
$id_grupo
|
||||
);
|
||||
$agent_modules = db_get_all_rows_sql($sql);
|
||||
} else {
|
||||
$groups = groups_get_children($id_grupo, true);
|
||||
if (empty($groups) === false) {
|
||||
$groups = array_reduce(
|
||||
$groups,
|
||||
function ($carry, $item) {
|
||||
$carry[] = $item['id_grupo'];
|
||||
return $carry;
|
||||
},
|
||||
[$id_grupo]
|
||||
);
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT distinct(atm.id_agent_module)
|
||||
FROM talert_template_modules atm
|
||||
INNER JOIN tagente_modulo am
|
||||
ON am.id_agente_modulo = atm.id_agent_module
|
||||
INNER JOIN tagente ta
|
||||
ON am.id_agente = ta.id_agente
|
||||
LEFT JOIN tagent_secondary_group tasg
|
||||
ON tasg.id_agent = ta.id_agente
|
||||
WHERE atm.disabled = 0
|
||||
AND (tasg.id_group IN (%s)
|
||||
OR ta.id_grupo IN (%s))
|
||||
',
|
||||
implode(',', $groups),
|
||||
implode(',', $groups)
|
||||
);
|
||||
}
|
||||
|
||||
$agent_modules = db_get_all_rows_sql($sql);
|
||||
}
|
||||
|
||||
if ($agent_modules === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $agent_modules;
|
||||
|
||||
}
|
||||
|
|
|
@ -1317,14 +1317,14 @@ function events_get_all(
|
|||
if (is_array($groups)) {
|
||||
$tgrupo_join_filters[] = sprintf(
|
||||
' (te.id_grupo = tg.id_grupo AND tg.id_grupo IN (%s))
|
||||
OR (te.id_agente = tasg.id_agent AND tasg.id_group IN (%s))',
|
||||
OR (tg.id_grupo = tasg.id_group AND tasg.id_group IN (%s))',
|
||||
join(', ', $groups),
|
||||
join(', ', $groups)
|
||||
);
|
||||
} else {
|
||||
$tgrupo_join_filters[] = sprintf(
|
||||
' (te.id_grupo = tg.id_grupo AND tg.id_grupo = %s)
|
||||
OR (te.id_agente = tasg.id_agent AND tasg.id_group = %s)',
|
||||
OR (tg.id_grupo = tasg.id_group AND tasg.id_group = %s)',
|
||||
$groups,
|
||||
$groups
|
||||
);
|
||||
|
@ -2992,7 +2992,7 @@ function events_get_agent(
|
|||
$sql_where .= sprintf(
|
||||
' INNER JOIN tgrupo tg
|
||||
ON (te.id_grupo = tg.id_grupo AND tg.id_grupo = %s)
|
||||
OR (te.id_agente = tasg.id_agent AND tasg.id_group = %s)
|
||||
OR (tg.id_grupo = tasg.id_group AND tasg.id_group = %s)
|
||||
WHERE utimestamp > %d
|
||||
AND utimestamp <= %d ',
|
||||
join(',', $id_group),
|
||||
|
@ -5042,7 +5042,7 @@ function events_get_count_events_by_agent(
|
|||
ON te.id_agente = ta.id_agente
|
||||
INNER JOIN tgrupo tg
|
||||
ON (te.id_grupo = tg.id_grupo AND tg.id_grupo IN (%s))
|
||||
OR (te.id_agente = tasg.id_agent AND tasg.id_group IN (%s))
|
||||
OR (tg.id_grupo = tasg.id_group AND tasg.id_group IN (%s))
|
||||
WHERE utimestamp > %d AND utimestamp <= %d
|
||||
GROUP BY ta.id_agente',
|
||||
$tevento,
|
||||
|
@ -5118,7 +5118,7 @@ function events_get_count_events_validated_by_user(
|
|||
'%s
|
||||
INNER JOIN tgrupo tg
|
||||
ON (te.id_grupo = tg.id_grupo AND tg.id_grupo IN (%s))
|
||||
OR (te.id_agente = tasg.id_agent AND tasg.id_group IN (%s))',
|
||||
OR (tg.id_grupo = tasg.id_group AND tasg.id_group IN (%s))',
|
||||
events_get_secondary_groups_left_join($tevento),
|
||||
implode(',', $id_group),
|
||||
implode(',', $id_group)
|
||||
|
@ -5308,7 +5308,7 @@ function events_get_count_events_by_criticity(
|
|||
'%s
|
||||
INNER JOIN tgrupo tg
|
||||
ON (te.id_grupo = tg.id_grupo AND tg.id_grupo IN (%s))
|
||||
OR (te.id_agente = tasg.id_agent AND tasg.id_group IN (%s))',
|
||||
OR (tg.id_grupo = tasg.id_group AND tasg.id_group IN (%s))',
|
||||
events_get_secondary_groups_left_join($tevento),
|
||||
implode(',', $id_group),
|
||||
implode(',', $id_group)
|
||||
|
@ -5490,7 +5490,7 @@ function events_get_count_events_validated(
|
|||
'%s
|
||||
INNER JOIN tgrupo tg
|
||||
ON (te.id_grupo = tg.id_grupo AND tg.id_grupo IN (%s))
|
||||
OR (te.id_agente = tasg.id_agent AND tasg.id_group IN (%s))',
|
||||
OR (tg.id_grupo = tasg.id_group AND tasg.id_group IN (%s))',
|
||||
events_get_secondary_groups_left_join($tevento),
|
||||
implode(',', $id_group),
|
||||
implode(',', $id_group)
|
||||
|
|
|
@ -3909,30 +3909,10 @@ function reporting_alert_report_group($report, $content)
|
|||
$return['description'] = $content['description'];
|
||||
$return['date'] = reporting_get_date_text($report, $content);
|
||||
|
||||
if ($content['id_group'] == 0) {
|
||||
$agent_modules = db_get_all_rows_sql(
|
||||
'
|
||||
SELECT distinct(id_agent_module)
|
||||
FROM talert_template_modules
|
||||
WHERE disabled = 0
|
||||
AND id_agent_module IN (
|
||||
SELECT id_agente_modulo
|
||||
FROM tagente_modulo)'
|
||||
);
|
||||
} else {
|
||||
$agent_modules = db_get_all_rows_sql(
|
||||
'
|
||||
SELECT distinct(id_agent_module)
|
||||
FROM talert_template_modules
|
||||
WHERE disabled = 0
|
||||
AND id_agent_module IN (
|
||||
SELECT id_agente_modulo
|
||||
FROM tagente_modulo
|
||||
WHERE id_agente IN (
|
||||
SELECT id_agente
|
||||
FROM tagente WHERE id_grupo = '.$content['id_group'].'))'
|
||||
);
|
||||
}
|
||||
$agent_modules = alerts_get_agent_modules(
|
||||
$content['id_group'],
|
||||
$content['recursion']
|
||||
);
|
||||
|
||||
if (empty($alerts)) {
|
||||
$alerts = [];
|
||||
|
|
Loading…
Reference in New Issue