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.


In reply to Getting SNMPWalk to work with NetSNMP::agent by ebandook

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.