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

This commit is contained in:
Ramon Novoa 2016-11-15 11:28:52 +01:00
parent cf10377385
commit 11e1f5eb1f
2 changed files with 30 additions and 0 deletions
pandora_server/lib/PandoraFMS

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

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