ebandook has asked for the wisdom of the Perl Monks concerning the following question:
I am using agent extension on Redhat Linux 6 to run a Perl SNMP agent. I am using NetSNMP::agent to extend the agent functionality using the following directive :perl do "/home/ebandook/cut17/agent.pl" I have gotten SNMPGET to work with the following script but I am unable to get SNMPWALK to work with it.
#!/usr/bin/perl use NetSNMP::OID; use NetSNMP::ASN; use NetSNMP::agent; my $rootOID = '.1.3.6.1.4.1.303.3.3.12.1.1.55.1'; # netSnmp.999 my $perl = '/usr/bin/perl'; my $script = '/home/ebandook/cut17/poll2.pl'; my $numQueriesToConfigure = 7; my @oids; for(my $i = 1;$i<=$numQueriesToConfigure; $i++ ) { $oids[$i] = new NetSNMP::OID($rootOID . "$i.0"); } sub myhandler { my ($handler, $registration_info, $request_info, $requests) = @_; for ($request = $requests; $request; $request = $request->next()) +{ my $oid = $request->getOID(); my $mode = $request_info->getMode(); if($mode == MODE_GET) { my $count; if ( $oid =~ /(\d).0$/ ) { $count = `$perl $script $1`; } $request->setValue(ASN_INTEGER, $count); } elsif ($mode == MODE_GETNEXT) { my $oidnum; if ( $oid < new NetSNMP::OID("$rootOID.1.0") ) { $request->setOID("$rootOID.1.0"); my $count = `$perl $script 1`; $request->setValue(ASN_INTEGER, $count); } elsif ( $oid == new NetSNMP::OID("$rootOID.1.0") ) { $request->setOID("$rootOID.2.0"); my $count = `$perl $script 7`; $request->setValue(ASN_INTEGER, $count); } else { $oidnum =+ 1; my $thisOID = new NetSNMP::OID($rootOID."$oidn +um.0"); $request->setOID($thisOID); my $count = `$perl $script $oidnum`; $request->setValue(ASN_INTEGER, $count +); } } } } my $regoid = new NetSNMP::OID($rootOID); $agent->register("ubnms", $regoid, \&myhandler);
The code above fetches the second last number from the incoming OID and processes a script passing that number to the script as an input.
For the SNMPWALK I am using the following logic :
if ($mode == MODE_GETNEXT) { check if the OID < ROOT OID.1.0 set the OID to ROOT OID.1.0 return the value of ROOT OID.1.0 check if the OID == ROOT OID.1.0 set the OID to ROOT OID.2.0 # Next request return the value of ROOT OID.1.0 . . .
when I run SNMPGET :
snmpget -v2c -cpublic 66.82.145.226 .1.3.6.1.4.1.303.3.3.12.1.1.55.1.7.0
SNMPv2-SMI::enterprises.303.3.3.12.1.1.55.1.7.0 = INTEGER: 16243
I get the desired response.
when I run SNMPWALK against the root OID :
I get only the first OID :
snmpwalk -v2c -cpublic 66.82.145.226 .1.3.6.1.4.1.303.3.3.12.1.1.55.1.1.0
SNMPv2-SMI::enterprises.303.3.3.12.1.1.55.1.1.0 = INTEGER: 0
Any help with this is appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getting SNMPWalk to work with NetSNMP::agent
by NetWallah (Canon) on Jun 04, 2012 at 04:22 UTC | |
by ebandook (Initiate) on Jun 04, 2012 at 22:16 UTC |