From 51ca2de1e544999e07eaa03ceda5544c0e27aab7 Mon Sep 17 00:00:00 2001 From: Calvo Date: Thu, 22 Jul 2021 11:34:07 +0200 Subject: [PATCH 1/2] Get command field if it is not defined in alert or action --- pandora_server/lib/PandoraFMS/Core.pm | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index d4483046fa..61084010a3 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -1051,6 +1051,15 @@ sub pandora_execute_action ($$$$$$$$$;$) { my ($field1, $field2, $field3, $field4, $field5, $field6, $field7, $field8, $field9, $field10); my ($field11, $field12, $field13, $field14, $field15, $field16, $field17, $field18, $field19, $field20); + # Check for empty alert fields and assign command field. + my $index = 1; + my @command_fields = split(/,|\[|\]/, $action->{'fields_values'}); + foreach my $field (@command_fields) { + unless (defined($action->{'field'.$index}) && $action->{'field'.$index} ne "") { + $action->{'field'.$index} = defined($field) ? $field : "" ; + } + } + if (!defined($alert->{'snmp_alert'})) { # Regular alerts $field1 = defined($action->{'field1'}) && $action->{'field1'} ne "" ? $action->{'field1'} : $alert->{'field1'}; @@ -1097,6 +1106,8 @@ sub pandora_execute_action ($$$$$$$$$;$) { $field20 = defined($alert->{'field20'}) && $alert->{'field20'} ne "" ? $alert->{'field20'} : $action->{'field20'}; } + print Dumper($field1); + # Recovery fields, thanks to Kato Atsushi if ($alert_mode == RECOVERED_ALERT) { # Field 1 is a special case where [RECOVER] prefix is not added even when it is defined @@ -4145,9 +4156,9 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) { # Execute alert my $action = get_db_single_row ($dbh, 'SELECT * - FROM talert_actions, talert_commands - WHERE talert_actions.id_alert_command = talert_commands.id - AND talert_actions.id = ?', $alert->{'id_alert'}); + FROM talert_actions taa JOIN talert_commands tac + ON taa.id_alert_command = tac.id + WHERE tac.id = ?', $alert->{'id_alert'}); my $trap_rcv_full = $trap_oid . " " . $trap_value. " ". $trap_type. " " . $trap_custom_oid; From 72d57bc06704dd3540e75989a17723e1cdce5f84 Mon Sep 17 00:00:00 2001 From: Calvo Date: Thu, 22 Jul 2021 11:39:00 +0200 Subject: [PATCH 2/2] Get command field if it is not defined in alert or action --- pandora_server/lib/PandoraFMS/Core.pm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 61084010a3..8a18caced9 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -1106,8 +1106,7 @@ sub pandora_execute_action ($$$$$$$$$;$) { $field20 = defined($alert->{'field20'}) && $alert->{'field20'} ne "" ? $alert->{'field20'} : $action->{'field20'}; } - print Dumper($field1); - + # Recovery fields, thanks to Kato Atsushi if ($alert_mode == RECOVERED_ALERT) { # Field 1 is a special case where [RECOVER] prefix is not added even when it is defined