From c07e6f14b196309ebf827f5ab81ed289e552c86a Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Wed, 3 Sep 2014 18:03:13 +0200 Subject: [PATCH] 2014-09-03 Ramon Novoa * pandora_agent: Added support for global macros. --- pandora_agents/unix/ChangeLog | 4 ++++ pandora_agents/unix/pandora_agent | 29 +++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pandora_agents/unix/ChangeLog b/pandora_agents/unix/ChangeLog index 58d0cd613c..0c5339d0b1 100644 --- a/pandora_agents/unix/ChangeLog +++ b/pandora_agents/unix/ChangeLog @@ -1,3 +1,7 @@ +2014-09-03 Ramon Novoa + + * pandora_agent: Added support for global macros. + 2014-08-18 Ramon Novoa * Linux/pandora_agent.conf, diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index e66a29da4f..2c10086bd6 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -199,6 +199,9 @@ my $DevNull = '/dev/null'; # Shell command separator my $CmdSep = ';'; +# Global macros +my %Macros; + # PID of tentacle proxy, used in proxy mode my $tentacle_pid = undef; @@ -634,6 +637,12 @@ sub read_config (;$) { $Customfields{$1} = $2; next; } + + # Save global macros + if ($line =~ m/^macro(\S+)\s+(.*)/) { + $Macros{$1} = $2; + next; + } # Token search if (defined ($token)) { @@ -898,7 +907,8 @@ sub check_remote_config () { # Save the new configuration move ("$Conf{'temporal'}/$RemoteConfFile", "$ConfDir/$ConfFile"); - # Empty modules, plugins and collections + # Empty macros, modules, plugins and collections + %Macros = (); @Modules = (); %Collections = (); %Conf = %DefaultConf; @@ -1878,11 +1888,18 @@ sub replace_macros ($) { # Simple configuration token if(ref($module->{$token}) eq ''){ + # Module macros while (my ($macro, $subst) = each (%{$module->{'macros'}})) { eval { $module->{$token} =~ s/$macro/$subst/g; }; } + # Global macros + while (my ($macro, $subst) = each (%Macros)) { + eval { + $module->{$token} =~ s/$macro/$subst/g; + }; + } } # Hash array elsif (ref($module->{$token}) eq 'ARRAY'){ @@ -1891,12 +1908,19 @@ sub replace_macros ($) { # Array of configuration tokens foreach my $key (keys (%{$module->{$token}->[$i]})) { - # Each configuration token is a hash + # Module macros (each configuration token is a hash) while (my ($macro, $subst) = each (%{$module->{'macros'}})) { eval { $module->{$token}->[$i]->{$key} =~ s/$macro/$subst/g; } } + + # Global macros (each configuration token is a hash) + while (my ($macro, $subst) = each (%Macros)) { + eval { + $module->{$token}->[$i]->{$key} =~ s/$macro/$subst/g; + } + } } } } @@ -2099,6 +2123,7 @@ while (1) { start_log ('quiet'); # Read configuration file + %Macros = (); @Modules = (); %Collections = (); %Conf = %DefaultConf;