2011-07-08 Koichiro Kikuchi <koichiro@rworks.jp>

* 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
This commit is contained in:
koichirok 2011-07-08 10:16:55 +00:00
parent 47b551da9a
commit f7eede5b9e
2 changed files with 15 additions and 11 deletions

View File

@ -1,3 +1,11 @@
2011-07-08 Koichiro Kikuchi <koichiro@rworks.jp>
* 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 <rnovoa@artica.es>
* lib/PandoraFMS/Core.pm: Fixed alert-only planned downtimes.

View File

@ -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;
}