Added support for loading .enc files for XML::Parser.

(cherry picked from commit 11e1f5eb1f)
This commit is contained in:
Ramon Novoa 2016-11-15 11:28:52 +01:00
parent ddf4366017
commit f81af8b437
2 changed files with 30 additions and 0 deletions

View File

@ -426,6 +426,9 @@ sub pandora_load_config {
$pa_config->{"warmup_unknown_on"} = 1; # 6.1
#$pa_config->{'include_agents'} = 0; #6.1
#
# External .enc files for XML::Parser.
$pa_config->{"enc_dir"} = ""; # > 6.0SP4
# Check for UID0
if ($pa_config->{"quiet"} != 0){
@ -956,6 +959,9 @@ sub pandora_load_config {
#elsif ($parametro =~ m/^include_agents\s+([0-1])/i) {
# $pa_config->{'include_agents'}= clean_blank($1);
#}
elsif ($parametro =~ m/^enc_dir\s+(.*)/i) {
$pa_config->{'enc_dir'} = clean_blank($1);
}
} # end of loop for parameter #
# Set to RDBMS' standard port

View File

@ -25,6 +25,7 @@ use threads::shared;
use Thread::Semaphore;
use Time::Local;
use XML::Parser::Expat;
use XML::Simple;
use POSIX qw(setsid strftime);
@ -71,6 +72,29 @@ sub new ($$;$) {
# Call the constructor of the parent class
my $self = $class->SUPER::new($config, DATASERVER, \&PandoraFMS::DataServer::data_producer, \&PandoraFMS::DataServer::data_consumer, $dbh);
# Load external .enc files for XML::Parser.
if ($config->{'enc_dir'} ne '') {
if (opendir(my $dh, $config->{'enc_dir'})) {
while (my $enc_file = readdir($dh)) {
# Ignore unknown files.
next unless ($enc_file =~ m/.enc$/);
# Load the .enc file.
eval {
local $SIG{__DIE__} = {};
XML::Parser::Expat::load_encoding($config->{'enc_dir'} . '/' . $enc_file);
};
if ($@) {
print_message ($config, " [WARNING] Error loading encoding file: $enc_file", 1);
}
}
closedir($dh);
} else {
print_message($config, " [WARNING] Error opening directory " . $config->{'enc_dir'} . ": $!", 1);
}
}
bless $self, $class;
return $self;
}