Subject: | Nagios::StatusLog update method is partially broken |
I'm using Nagios v 3.1.2 and perl 5.8.8 with Nagios::Object 0.21.8.
It seems to me, that your optimization of the update methods (update_v1,
update_v2 and update_v3) in StatusLog.pm has broken the module, at least
for the status.dat file I've tested with.
Where the code earlier looked like this (at least until version 0.21.3):
my $entry = '';
while ( my $line = <$log_fh> ) {
next if ( $line =~ /^\s*#/ );
$entry .= $line;
if ( $entry =~ m/$entry_re/ ) {
( my $type, my $text, $entry ) = ( $1, $2, $3 );
$text =~ s/[\r\n]+\s*/\n/g; # clean up whitespace and newlines
my %item = map { split /\s*=\s*/, $_, 2 } split /\n/, $text;
$handlers{$type}->( \%item );
}
}
It now looks like this (as of version 0.21.8):
my @lines = <$log_fh>;
my $file = "@lines";
#Drop comments if we don't need them as it should speed things up a
little bit.
#Comment out the line below if you do want to keep comments
$file =~ s/#.*\n//mg;
$file =~ s/[\r\n]+\s*/\n/g; # clean up whitespace and newlines
while ( $file =~ /$entry_re/g ) {
( my $type, my $text ) = ( $1, $2 );
my %item = map { split /\s*=\s*/, $_, 2 } split /\n/, $text;
$handlers{$type}->( \%item );
}
The latter version, in addition to using far more memory, seems not to
parse more than the first block of data from the status.dat file. The
only information I end up with in my log-object, is that first
"info"-type block which contains data about the status.dat file itself.
I tried replacing the latter, quoted code with the former version, and
it works perfectly again.
Do you have any explanation as to why I'm experiencing these problems
with the new code?
Regards
Tom Daae
University of Oslo