From f7eede5b9e94c9782a263862cab2cd1a63b5f3d1 Mon Sep 17 00:00:00 2001 From: koichirok Date: Fri, 8 Jul 2011 10:16:55 +0000 Subject: [PATCH] 2011-07-08 Koichiro Kikuchi * lib/PandoraFMS/Core.pm: Fixed alert macro substitution. Now alert_macro_substitute() does not substitute already substituted part of string. Also fixed alert macro substitution for user defined alerts to avoid alert macros other than _field[1-3]_ substituted twice. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4535 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 8 ++++++++ pandora_server/lib/PandoraFMS/Core.pm | 18 +++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index b9f1240577..43607e3aa6 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,11 @@ +2011-07-08 Koichiro Kikuchi + + * lib/PandoraFMS/Core.pm: Fixed alert macro substitution. Now + alert_macro_substitute() does not substitute already substituted + part of string. Also fixed alert macro substitution for user + defined alerts to avoid alert macros other than _field[1-3]_ + substituted twice. + 2011-07-08 Ramon Novoa * lib/PandoraFMS/Core.pm: Fixed alert-only planned downtimes. diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 6eb69219dc..93cf71ce23 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -725,8 +725,10 @@ sub pandora_execute_action ($$$$$$$$$;$) { # User defined alerts if ($action->{'internal'} == 0) { + $macros{_field1_} = subst_alert_macros ($field1, \%macros); + $macros{_field2_} = subst_alert_macros ($field2, \%macros); + $macros{_field3_} = subst_alert_macros ($field3, \%macros); my $command = subst_alert_macros (decode_entities ($action->{'command'}), \%macros); - $command = subst_alert_macros ($command, \%macros); logger($pa_config, "Executing command '$command' for action '" . $action->{'name'} . "' alert '". $alert->{'name'} . "' agent '" . (defined ($agent) ? $agent->{'nombre'} : 'N/A') . "'.", 8); eval { @@ -1693,16 +1695,10 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) { sub subst_alert_macros ($$) { my ($string, $macros) = @_; - while ((my $macro, my $value) = each (%{$macros})) { - - # Undefined macro value - next unless defined ($value); - - # Macro data may contain HTML entities - my $decoded_value = decode_entities ($value); - - $string =~ s/($macro)/$decoded_value/ig; - } + my $macro_regexp = join('|', grep { defined $macros->{$_} } keys %{$macros}); + + # Macro data may contain HTML entities + $string =~ s/($macro_regexp)/decode_entities($macros->{$1})/ige; return $string; }