2014-09-03 Ramon Novoa <rnovoa@artica.es>

* pandora_agent: Added support for global macros.
This commit is contained in:
Ramon Novoa 2014-09-03 18:03:13 +02:00
parent b387104d24
commit c07e6f14b1
2 changed files with 31 additions and 2 deletions

View File

@ -1,3 +1,7 @@
2014-09-03 Ramon Novoa <rnovoa@artica.es>
* pandora_agent: Added support for global macros.
2014-08-18 Ramon Novoa <rnovoa@artica.es> 2014-08-18 Ramon Novoa <rnovoa@artica.es>
* Linux/pandora_agent.conf, * Linux/pandora_agent.conf,

View File

@ -199,6 +199,9 @@ my $DevNull = '/dev/null';
# Shell command separator # Shell command separator
my $CmdSep = ';'; my $CmdSep = ';';
# Global macros
my %Macros;
# PID of tentacle proxy, used in proxy mode # PID of tentacle proxy, used in proxy mode
my $tentacle_pid = undef; my $tentacle_pid = undef;
@ -634,6 +637,12 @@ sub read_config (;$) {
$Customfields{$1} = $2; $Customfields{$1} = $2;
next; next;
} }
# Save global macros
if ($line =~ m/^macro(\S+)\s+(.*)/) {
$Macros{$1} = $2;
next;
}
# Token search # Token search
if (defined ($token)) { if (defined ($token)) {
@ -898,7 +907,8 @@ sub check_remote_config () {
# Save the new configuration # Save the new configuration
move ("$Conf{'temporal'}/$RemoteConfFile", "$ConfDir/$ConfFile"); move ("$Conf{'temporal'}/$RemoteConfFile", "$ConfDir/$ConfFile");
# Empty modules, plugins and collections # Empty macros, modules, plugins and collections
%Macros = ();
@Modules = (); @Modules = ();
%Collections = (); %Collections = ();
%Conf = %DefaultConf; %Conf = %DefaultConf;
@ -1878,11 +1888,18 @@ sub replace_macros ($) {
# Simple configuration token # Simple configuration token
if(ref($module->{$token}) eq ''){ if(ref($module->{$token}) eq ''){
# Module macros
while (my ($macro, $subst) = each (%{$module->{'macros'}})) { while (my ($macro, $subst) = each (%{$module->{'macros'}})) {
eval { eval {
$module->{$token} =~ s/$macro/$subst/g; $module->{$token} =~ s/$macro/$subst/g;
}; };
} }
# Global macros
while (my ($macro, $subst) = each (%Macros)) {
eval {
$module->{$token} =~ s/$macro/$subst/g;
};
}
} }
# Hash array # Hash array
elsif (ref($module->{$token}) eq 'ARRAY'){ elsif (ref($module->{$token}) eq 'ARRAY'){
@ -1891,12 +1908,19 @@ sub replace_macros ($) {
# Array of configuration tokens # Array of configuration tokens
foreach my $key (keys (%{$module->{$token}->[$i]})) { 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'}})) { while (my ($macro, $subst) = each (%{$module->{'macros'}})) {
eval { eval {
$module->{$token}->[$i]->{$key} =~ s/$macro/$subst/g; $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'); start_log ('quiet');
# Read configuration file # Read configuration file
%Macros = ();
@Modules = (); @Modules = ();
%Collections = (); %Collections = ();
%Conf = %DefaultConf; %Conf = %DefaultConf;