Skip Menu |

This queue is for tickets about the Nagios-Object CPAN distribution.

Report information
The Basics
Id: 52398
Status: resolved
Priority: 0/
Queue: Nagios-Object

People
Owner: Nobody in particular
Requestors: TOMDAAE [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.21.8
Fixed in: (no value)



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
I've added a patch-file created with the command LC_ALL=C TZ=UTC0 diff -Naur Nagios-Object-0.21.8/lib/Nagios/ Nagios-Object-0.21.8.1/lib/Nagios/ Please note that this patch only fixes the update_v3 method. I have no installation of Nagios 2.x to test whether or not the same bug affects the update_v2 method as well. Regards Tom Daae University of Oslo
diff -Naur Nagios-Object-0.21.8/lib/Nagios/StatusLog.pm Nagios-Object-0.21.8.1/lib/Nagios/StatusLog.pm --- Nagios-Object-0.21.8/lib/Nagios/StatusLog.pm 2009-12-10 07:51:15.261389000 +0000 +++ Nagios-Object-0.21.8.1/lib/Nagios/StatusLog.pm 2009-12-10 07:59:48.123271000 +0000 @@ -471,18 +471,16 @@ (.*)$ /xs; - 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 ); + 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 ); + } } close($log_fh);
This should now be fixed and uploaded to CPAN as 0.21.9