From b2fad9d91394c64c92c1df78f784d3280b4aaf16 Mon Sep 17 00:00:00 2001 From: zarzuelo Date: Wed, 1 Aug 2012 16:35:40 +0000 Subject: [PATCH] 2012-08-01 Sergio Martin * pandora_agent: Add the macros support in module_exec git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6838 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_agents/unix/ChangeLog | 4 ++++ pandora_agents/unix/pandora_agent | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pandora_agents/unix/ChangeLog b/pandora_agents/unix/ChangeLog index 4e2e536c88..9f7e911d88 100644 --- a/pandora_agents/unix/ChangeLog +++ b/pandora_agents/unix/ChangeLog @@ -1,3 +1,7 @@ +2012-08-01 Sergio Martin + + * pandora_agent: Add the macros support in module_exec + 2012-06-27 Koichiro Kikuchi * pandora_agent.redhat.spec: Merged from 4.0 branch. Don't create diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 1b4a064ffa..26046dcb62 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -30,6 +30,7 @@ use File::Basename; use File::Copy; use IO::Socket; + # Agent XML data my $Xml; @@ -373,6 +374,7 @@ sub parse_conf_modules($) { 'intensive_match' => 0, 'timestamp' => 0, 'unit' => '', + 'macros' => {}, }; } elsif ($line =~ /^\s*module_name\s+(.+)$/) { $module->{'name'} = $1; @@ -530,6 +532,9 @@ sub parse_conf_modules($) { # Unit } elsif ($line =~ /^\s*module_unit\s+(\S+)\s*$/) { $module->{'unit'} = $1; + # Macros + } elsif ($line =~ /^\s*module_macro(\S+)\s+(\S+)\s*$/) { + $module->{'macros'}{$1} = $2; } } return; @@ -1255,11 +1260,20 @@ sub module_exec ($) { # Check module parameters 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) { - @data = `$module->{'params'} 2> $DevNull`; + @data = `$params 2> $DevNull`; } else { - my $cmd = quotemeta ($module->{'params'}); + my $cmd = quotemeta ($params); @data = `$Conf{'pandora_exec'} $module->{'timeout'} $cmd 2> $DevNull`; }