Skip Menu |

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

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

People
Owner: duncan_j_ferguson [...] yahoo.co.uk
Requestors: cpan [...] askneil.com
Cc:
AdminCc:

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



Subject: Undefined value in Nagios::ServiceGroup::set_members
This is based on the code from github, modified on 20 Feb 2009. I tried using Nagios::Object::Config to read in my nagios 2.0 objects.cache file. It worked well (thanks!), but I found a small error in the parsing code. The code generated a series of errors like: Use of uninitialized value in array dereference at lib/Nagios/Object.pm line 1064, <GEN1> line 472 (the line number is from my edited version of the file, so it won't match yours...) Investigating further, it turns out the members field of Nagios::ServiceGroup objects is never being initialized. The fix is a one line change: $ diff -c Object.pm.orig Object.pm *** Object.pm.orig Thu Mar 5 16:33:36 2009 --- Object.pm Thu Mar 5 16:30:44 2009 *************** *** 1056,1061 **** --- 1056,1063 ---- } # also, before resolution, append to the list rather than replace it else { + + $self->{members} = [] if ! defined($self->{members}); @members = @{ $self->{members} }; foreach my $item ( @_ ) { if ( ref($item) eq 'ARRAY' && @$item == 2 ) {
Do you have any suitable tests to catch and prevent this being a problem in the future at all? Thanks Duncs
From: cpan [...] askneil.com
On Fri Mar 06 04:24:44 2009, duncs wrote: Show quoted text
> Do you have any suitable tests to catch and prevent this being a > problem in the future at all?
You ask an interesting question. The problem is: the "error" just results in warnings. I looked at the tests; there were no servicegroup tests at all. I added some servicegroup test, and servicegroup definitions to the v2config directory. I've attached it all as a patch to this comment. However, the old code "passed" the test; as a bit of a hack I overrode $SIG{__WARN__} to catch warnings, and fail the test if any warnings were emitted. Let me know if you need anything else.
Download patch.out
application/octet-stream 4.4k

Message body not shown because it is not plain text.

Thanks for the patch - much appreciated. By chance I happened across Test::NoWarnings so I modified the test slightly to use it. Duncs