diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index c1cc83b98c..0b9dc9082b 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,14 @@ +2010-10-13 Sancho Lerena + + * Core.pm: Force XML::Simple to use XML::Parser instead SAX to manage XML + due a bug processing some XML with blank spaces. + + * DataServer.pm: Checking for BADXML is 2 times with 2 secs of delay now. + Aditional check before deleting / procesing XML. + + * pandora_server: Added handle of BadXML error to avoid see "unhandled" + errors on log, and set to verbose level 2. + 2010-10-07 Sancho Lerena * conf/pandora_server.conf: Removed multicast options diff --git a/pandora_server/bin/pandora_server b/pandora_server/bin/pandora_server index 19ea0aa78a..a049ad1bd6 100755 --- a/pandora_server/bin/pandora_server +++ b/pandora_server/bin/pandora_server @@ -134,9 +134,19 @@ sub pandora_crash () { # will be nice to replace this code, but at this time it's the only way I know foreach my $error_line (@_) { - if ($error_line !~ m/Enterprise/i && $error_line !~ m/Format_XS/i && $error_line !~ m/ConfigLocal/i){ + + # Trap the XML error and exit without nasty messages + if ($error_line =~ m/XML\/Parser/){ + logger (\%Config, "Problem parsing XML file, XML file discarded: $error_line", 2); + return; + } + + elsif ($error_line !~ m/Enterprise/i && $error_line !~ m/Format_XS/i && $error_line !~ m/ConfigLocal/i){ logger (\%Config, '[E] \'' . $Config{'servername'} . "': $error_line", 1); - } else { + } + + + else { if ($error_line !~ m/Can\'t\slocate/) { logger (\%Config, '[E] \'' . $Config{'servername'} . "': $error_line", 1); } else { diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index cf8ed0a1d3..39902d6f16 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -109,6 +109,12 @@ use HTML::Entities; use Time::Local; use POSIX qw(strftime); +# Force XML::Simple to use XML::Parser instead SAX to manage XML +# due a bug processing some XML with blank spaces. +# See http://www.perlmonks.org/?node_id=706838 + +$XML::Simple::PREFERRED_PARSER='XML::Parser'; + # Default lib dir for RPM and DEB packages use lib '/usr/lib/perl5'; diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index 66a2625f59..91c571d5f0 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -145,10 +145,10 @@ sub data_consumer ($$) { # Double check that the file exists return unless (-f $file_name); - # Try to parse the XML 3 times + # Try to parse the XML 2 times, with a delay between tries of 2 seconds my $xml_data; - for (1..3) { + for (0..1) { eval { threads->yield; $xml_data = XMLin ($file_name, forcearray => 'module'); @@ -157,13 +157,16 @@ sub data_consumer ($$) { # Invalid XML if ($@) { $xml_err = $@; - sleep (1); + sleep (2); next; } # Ignore the timestamp in the XML and use the file timestamp instead $xml_data->{'timestamp'} = strftime ("%Y-%m-%d %H:%M:%S", localtime((stat($file_name))[9])) if ($pa_config->{'use_xml_timestamp'} eq '1' || ! defined ($xml_data->{'timestamp'})); + # Double check that the file exists + return unless (-f $file_name); + unlink ($file_name); process_xml_data ($self->getConfig (), $file_name, $xml_data, $self->getServerID (), $self->getDBH ()); return;