Merge branch 'ent-7972-funcionalidad-historico-de-alertas-lanzadas' into 'develop'

Fix SQL errors in action queries.

See merge request artica/pandorafms!4502
This commit is contained in:
Daniel Rodriguez 2021-10-27 15:45:33 +00:00
commit 0ec2bf30ce
1 changed files with 36 additions and 9 deletions

View File

@ -881,7 +881,8 @@ sub pandora_execute_alert ($$$$$$$$$;$$) {
# Get default action
if ($#actions < 0) {
@actions = get_db_rows ($dbh, 'SELECT talert_actions.name as action_name, * FROM talert_actions, talert_commands
@actions = get_db_rows ($dbh, 'SELECT talert_actions.name as action_name, talert_actions.*, talert_commands.*
FROM talert_actions, talert_commands
WHERE talert_actions.id = ?
AND talert_actions.id_alert_command = talert_commands.id',
$alert->{'id_alert_action'});
@ -890,7 +891,8 @@ sub pandora_execute_alert ($$$$$$$$$;$$) {
# Event alert
else {
if ($alert_mode == RECOVERED_ALERT) {
@actions = get_db_rows ($dbh, 'SELECT talert_actions.name as action_name, * FROM tevent_alert_action, talert_actions, talert_commands
@actions = get_db_rows ($dbh, 'SELECT talert_actions.name as action_name, tevent_alert_action.*, talert_actions.*, talert_commands.*
FROM tevent_alert_action, talert_actions, talert_commands
WHERE tevent_alert_action.id_alert_action = talert_actions.id
AND talert_actions.id_alert_command = talert_commands.id
AND tevent_alert_action.id_event_alert = ?
@ -898,7 +900,8 @@ sub pandora_execute_alert ($$$$$$$$$;$$) {
OR ? >= fires_min)',
$alert->{'id'}, $alert->{'times_fired'});
} else {
@actions = get_db_rows ($dbh, 'SELECT talert_actions.name as action_name, * FROM tevent_alert_action, talert_actions, talert_commands
@actions = get_db_rows ($dbh, 'SELECT talert_actions.name as action_name, tevent_alert_action.*, talert_actions.*, talert_commands.*
FROM tevent_alert_action, talert_actions, talert_commands
WHERE tevent_alert_action.id_alert_action = talert_actions.id
AND talert_actions.id_alert_command = talert_commands.id
AND tevent_alert_action.id_event_alert = ?
@ -910,7 +913,8 @@ sub pandora_execute_alert ($$$$$$$$$;$$) {
# Get default action
if ($#actions < 0) {
@actions = get_db_rows ($dbh, 'SELECT talert_actions.name as action_name, * FROM talert_actions, talert_commands
@actions = get_db_rows ($dbh, 'SELECT talert_actions.name as action_name, talert_actions.*, talert_commands.*
FROM talert_actions, talert_commands
WHERE talert_actions.id = ?
AND talert_actions.id_alert_command = talert_commands.id',
$alert->{'id_alert_action'});
@ -4218,7 +4222,7 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) {
}
# Execute alert
my $action = get_db_single_row ($dbh, 'SELECT talert_actions.name as action_name, *
my $action = get_db_single_row ($dbh, 'SELECT talert_actions.name as action_name, talert_actions.*, talert_commands.*
FROM talert_actions, talert_commands
WHERE talert_actions.id_alert_command = talert_commands.id
AND talert_actions.id = ?', $alert->{'id_alert'});
@ -4235,8 +4239,26 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) {
# Generate an event, ONLY if our alert action is different from generate an event.
if ($action->{'id_alert_command'} != 3 && $alert->{'disable_event'} == 0){
pandora_event ($pa_config, "SNMP alert fired (" . safe_output($alert->{'description'}) . ")",
0, 0, $alert->{'priority'}, 0, 0, 'alert_fired', 0, $dbh);
pandora_event (
$pa_config,
"SNMP alert fired (" . safe_output($alert->{'description'}) . ")",
0,
0,
$alert->{'priority'},
0,
0,
'alert_fired',
0,
$dbh,
undef,
undef,
undef,
undef,
undef,
undef,
undef,
undef,
p_encode_json($pa_config, $custom_data));
}
# Update alert status
@ -4252,7 +4274,7 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) {
$alert->{'id_as'});
foreach my $other_alert (@more_actions_snmp) {
my $other_action = get_db_single_row ($dbh, 'SELECT talert_actions.name as action_name, *
my $other_action = get_db_single_row ($dbh, 'SELECT talert_actions.name as action_name, talert_actions.*, talert_commands.*
FROM talert_actions, talert_commands
WHERE talert_actions.id_alert_command = talert_commands.id
AND talert_actions.id = ?', $other_alert->{'alert_type'});
@ -4292,6 +4314,11 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) {
'disable_event' => $alert->{'disable_event'}
);
# Additional execution information for the console.
my $custom_data = {
'actions' => [],
};
pandora_execute_action ($pa_config, $trap_rcv_full, \%agent, \%alert_action, 1, $other_action, undef, $dbh, $timestamp, \%macros) if (defined ($other_action));
push(@{$custom_data->{'actions'}}, safe_output($other_action->{'action_name'}));
@ -4314,7 +4341,7 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) {
undef,
undef,
undef,
undef,,
undef,
undef,
p_encode_json($pa_config, $custom_data));
}