tags:

views:

41

answers:

2

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.

A: 

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.

BLAKE
A: 

You've already identified that via the command-line you're doing a "walk" rather than a "get". If there's a specific value you want to "get" in your script, put in the full OID identifying the target.

There's something in a table record that you probably want to get at (and it seems like everything in FASTTRAKIDERAID-MIB is in fact tabular), so a simple get isn't enough. Look at the snmpwalk.pl script that comes with Net::SNMP or see if SNMP::Util can easily provide the functionality you're looking for.

medina