Skip Menu |

This queue is for tickets about the Net-SNMP CPAN distribution.

Report information
The Basics
Id: 62651
Status: resolved
Worked: 5 min
Priority: 0/
Queue: Net-SNMP

People
Owner: dtown [...] cpan.org
Requestors: leslie [...] richardsononline.net
Cc:
AdminCc:

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



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; }
Subject: Re: [rt.cpan.org #62651] AutoReply: Bug in error session error checking
Date: Tue, 2 Nov 2010 15:47:01 -0700
To: bug-Net-SNMP [...] rt.cpan.org
From: Leslie Richardson <leslie [...] richardsononline.net>
Tested Module Versions: 5.2.0 6.0.1 Tested Perl Versions: 5.8.8 5.10.1 5.12.2 On Tue, Nov 2, 2010 at 3:41 PM, Bugs in Net-SNMP via RT < bug-Net-SNMP@rt.cpan.org> wrote: Show quoted text
> > Greetings, > > This message has been automatically generated in response to the > creation of a trouble ticket regarding: > "Bug in error session error checking", > a summary of which appears below. > > There is no need to reply to this message right now. Your ticket has been > assigned an ID of [rt.cpan.org #62651]. Your ticket is accessible > on the web at: > > https://rt.cpan.org/Ticket/Display.html?id=62651 > > Please include the string: > > [rt.cpan.org #62651] > > in the subject line of all future correspondence about this issue. To do > so, > you may reply to this message. > > Thank you, > bug-Net-SNMP@rt.cpan.org > > ------------------------------------------------------------------------- > 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; > } > >
When a SNMPv1/v2c session is created, no communication with the remote agent is performed. The $session object will be created and defined even if the remote host does not support SNMP. It would only not be defined if you passed in incorrect arguments. You need to check the $result variable that is returned from $session->get_request(). if (!defined $result) { printf "ERROR: %s\n", $session->error(); }