diff --git a/pandora_agents/unix/ChangeLog b/pandora_agents/unix/ChangeLog index 3475ce6c2d..e5987ffe85 100644 --- a/pandora_agents/unix/ChangeLog +++ b/pandora_agents/unix/ChangeLog @@ -1,3 +1,8 @@ +2013-04-12 Ramon Novoa + + * pandora_agent: Added macro support to all module configuration + tokens. + 2013-04-03 Koichiro KIKUCHI * pandora_agent: Adjust sleep interval so that each interval *starts* diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 407d3ae4d9..ee198f071b 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -496,7 +496,47 @@ sub parse_conf_modules($) { # Make the module run the first time $module->{'counter'} = $module->{'intensive_interval'}; + + # Replace macros + foreach my $token (keys (%{$module})) { + # No need to skip macros for now, since it's a hash ref and only array refs + # are searched for macros. + #if ($token eq 'macros') { + # next; + #} + + # No defined value for conf token + if (! defined ($module->{$token})) { + next; + } + + # Simple configuration token + if(ref($module->{$token}) eq ''){ + while (my ($macro, $subst) = each (%{$module->{'macros'}})) { + eval { + $module->{$token} =~ s/$macro/$subst/g; + }; + } + } + # Hash array + elsif (ref($module->{$token}) eq 'ARRAY'){ + for (my $i = 0; $i <= $#{$module->{$token}}; $i++) { + + # Array of configuration tokens + foreach my $key (keys ($module->{$token}->[$i])) { + + # Each configuration token is a hash + while (my ($macro, $subst) = each (%{$module->{'macros'}})) { + eval { + $module->{$token}->[$i]->{$key} =~ s/$macro/$subst/g; + } + } + } + } + } + } + push (@Modules, $module); # Plugin } elsif ($line =~ /^\s*module_plugin\s+(.+)$/) { @@ -1312,13 +1352,6 @@ sub module_exec ($) { return () unless ($module->{'params'} ne ''); my $params = $module->{'params'}; - - # If there are macros, we apply it on params - eval { - foreach my $macro (keys(%{$module->{'macros'}})) { - $params =~ s/$macro/$module->{'macros'}{$macro}/g; - } - }; # Execute the command if ($module->{'timeout'} == 0) {