Merge pull request #28 from Robert-Nelson/unix-agent-fixes

Pandora unix agent bug fixes
This commit is contained in:
Ramón Novoa 2015-06-12 11:27:04 +02:00
commit 6dbfb22b20
1 changed files with 28 additions and 20 deletions

View File

@ -510,6 +510,9 @@ sub parse_conf_modules($) {
# Make the module run the first time # Make the module run the first time
$module->{'counter'} = $module->{'intensive_interval'}; $module->{'counter'} = $module->{'intensive_interval'};
# Replace macros
replace_macros ($module);
push (@Modules, {%{$module}}); push (@Modules, {%{$module}});
} else { } else {
$module->{'func'} = \&module_plugin; $module->{'func'} = \&module_plugin;
@ -601,15 +604,19 @@ sub write_broker_conf($){
my ($broker_agent) = @_; my ($broker_agent) = @_;
my $content = ''; my $content = '';
# I don't think the following should be copied either: proxy_*
my %ignored_tokens = (
'broker_agent' => 1, 'agent_name_cmd' => 1, 'udp_server' => 1, 'cron_mode' => 1
);
open (CONF_FILE, "$ConfDir/$ConfFile") or error ("Could not open file '$ConfDir/$ConfFile': $!."); open (CONF_FILE, "$ConfDir/$ConfFile") or error ("Could not open file '$ConfDir/$ConfFile': $!.");
open (BROKER_FILE, ">$ConfDir/${broker_agent}.conf") or error ("Could not write configuration file: $!"); open (BROKER_FILE, ">$ConfDir/${broker_agent}.conf") or error ("Could not write configuration file: $!");
while (my $line = <CONF_FILE>){ while (my $line = <CONF_FILE>) {
# Skip broker definitions my ( $token ) = $line =~ m/^\s*(\S+)(\s.*)?$/;
if ($line =~ m/^\s*broker_agent/) { # Skip tokens which should not be copied to broker configuration
next; next if defined $ignored_tokens{$token};
}
# Change the agent name # Change the agent name
if ($line =~ m/^\s*#*\s*agent_name\s+/) { if ($line =~ m/^\s*#*\s*agent_name\s+/) {
@ -647,19 +654,6 @@ sub read_config (;$) {
# Replace CRLF with LF # Replace CRLF with LF
$line =~ s/\r\n/\n/g; $line =~ s/\r\n/\n/g;
# Store the custom fields
if (($line =~ m/^(custom_field\d+_name)\s+(.*)/) or ($line =~ m/^(custom_field\d+_value)\s+(.*)/)) {
$Customfields{$1} = $2;
next;
}
# Save global macros
if ($line =~ m/^macro(\S+)\s+(.*)/) {
$Macros{$1} = $2;
next;
}
# Token search # Token search
if (defined ($token)) { if (defined ($token)) {
if ($line =~ /^\s*(\S+)\s+(.*)$/ && $1 eq $token) { if ($line =~ /^\s*(\S+)\s+(.*)$/ && $1 eq $token) {
@ -675,6 +669,20 @@ sub read_config (;$) {
} }
next; next;
} }
# Store the custom fields
if (($line =~ m/^(custom_field\d+_name)\s+(.*)/) or ($line =~ m/^(custom_field\d+_value)\s+(.*)/)) {
$Customfields{$1} = $2;
next;
}
# Save global macros
if ($line =~ m/^macro(\S+)\s+(.*)/) {
$Macros{$1} = $2;
next;
}
next if ($line =~ /^module\s*\w*/); next if ($line =~ /^module\s*\w*/);
#Configuration token #Configuration token
@ -872,7 +880,7 @@ sub send_buffered_xml_files () {
while (my $xml_file = readdir(TEMPORAL)) { while (my $xml_file = readdir(TEMPORAL)) {
# Skip non data files and symlinks # Skip non data files and symlinks
next if ($xml_file !~ m/\.data$/ || -l "$Conf{'temporal'}/$xml_file"); next if ($xml_file !~ m/^$Conf{'agent_name'}\.[0-9]+\.data$/ || -l "$Conf{'temporal'}/$xml_file");
my $rc = send_file ("$Conf{'temporal'}/$xml_file", 1); my $rc = send_file ("$Conf{'temporal'}/$xml_file", 1);
unlink ("$Conf{'temporal'}/$xml_file") if ($rc == 0); unlink ("$Conf{'temporal'}/$xml_file") if ($rc == 0);