2012-08-01 Sergio Martin <sergio.martin@artica.es>

* 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
This commit is contained in:
zarzuelo 2012-08-01 16:35:40 +00:00
parent c138c42bc9
commit b2fad9d913
2 changed files with 20 additions and 2 deletions

View File

@ -1,3 +1,7 @@
2012-08-01 Sergio Martin <sergio.martin@artica.es>
* pandora_agent: Add the macros support in module_exec
2012-06-27 Koichiro Kikuchi <koichiro@rworks.jp>
* pandora_agent.redhat.spec: Merged from 4.0 branch. Don't create

View File

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