Search code examples
perlsnmpnagios

Perl Net::SNMP returns noSuchName when snmpwalk works


I am new to perl, but I am trying to write a plug-in for nagios. I have a simple get request that fails, but if I try the same request with snmpwalk it works.

My code is:

#!/usr/bin/perl -w

use strict;
use Net::SNMP;

my $host = '10.10.10.203';  
my $community = 'myComm';  
my $session;  
my $error;    
my $response = undef;  

($session, $error) = Net::SNMP->session(  
  -hostname => $host,  
  -version => 2,  
  -community =>$community,  
  -port => 161,  
  -timeout => 20  
);

my $uptimeOID = '1.3.6.1.2.1.1.3.0';
my $myOID = '1.3.6.1.4.1.7933';

if( !defined( $response = $session->get_request($myOID)))
{
  if( $session->error_status == 2)
  {
    my $sessionError = $session->error;
    print ("($sessionError) OID not supported ($myOID).\n");
  }
}
else
{
  print ("$response");
}

If I run this script it will fail saying noSuchName, but if a run:

snmpwalk -v 2c -c myComm 10.10.10.203 1.3.6.1.4.1.7933

I get the response I want. Does anybody know why this wont work?
If I check the uptime OID with this script it will work the way it should.


Solution

  • I found my problem. When I use snmpwalk, it will grab the whole tree and return a value. The perl module will not. It doesn't traverse the tree to the end even thought there is only one thing below it, it just says no.