Subject: | Bug in error session error checking |
Date: | Tue, 2 Nov 2010 15:41:01 -0700 |
To: | bug-Net-SNMP [...] rt.cpan.org |
From: | Leslie Richardson <leslie [...] richardsononline.net> |
Using the code example below, $session is never left undefined, invalidating
the if statement / session error checking.
I've been testing with different versions of the module, different versions
of perl, and different operating systems. The result appears the same in all
scenarios.
Here is the output from my script when run against two different servers,
one that doesn't respond to SNMP, and one that does.
[root@nagios]# ./test.pl 192.168.1.1
System Name;
Session: Net::SNMP=HASH(0x13a44f60)
Test:
Error: ""
Error Status: 0
ERROR: .
[root@nagios]# ./test.pl 192.168.1.2
System Name; SYLVESTER
Session: Net::SNMP=HASH(0x19ab0f60)
Test:
Error: ""
Error Status: 0
[root@nagios]#
and here is my test code.
#!/usr/bin/perl
use Net::SNMP;
($session, $error) = Net::SNMP->session(
-hostname => shift || '10.6.1.117',
-community => shift || 'public',
-version => '2',
-nonblocking => '0',
-port => shift || 161
);
my %OID;
$OID{sysName} = ".1.3.6.1.2.1.1.5.0";
my $sysNameOID = ".1.3.6.1.2.1.1.5.0";
my @oids;
push(@oids, $sysNameOID);
my $result = $session->get_request(-varbindlist => \@oids);
my $sysname = $result->{$sysNameOID};
my $test = $session->{$session};
print "System Name; $sysname\n";
print "Session: $session\n";
print "Test: $test\n";
print "Error: \"$error\"\n";
my $error_status = $session->error_status();
print "Error Status: $error_status\n";
if (!defined($sysname)) {
printf("ERROR: %s.\n", $error);
exit 1;
}