Question

I've been working on a custom SNMP Mib and I've come up against a wall while trying to get an agent to return the proper data.

MIB (validated by running smilint -l 6):

IDB-MIB DEFINITIONS ::= BEGIN

IMPORTS
        MODULE-IDENTITY, OBJECT-TYPE, Integer32, enterprises
            FROM SNMPv2-SMI
        MODULE-COMPLIANCE, OBJECT-GROUP FROM SNMPv2-CONF;

idb MODULE-IDENTITY
    LAST-UPDATED   "201307300000Z" -- Midnight 30 July 2013
    ORGANIZATION "*********"
    CONTACT-INFO "email: *******"
    DESCRIPTION "description"
    REVISION "201307300000Z" -- Midnight 29 July 2013
    DESCRIPTION "First Draft"
::= { enterprises 42134 }

iDBCompliance MODULE-COMPLIANCE
    STATUS current
    DESCRIPTION
        "Compliance statement for iDB"
    MODULE
        GROUP testGroup
        DESCRIPTION
            "This group is a test group"
::= {idb 1}

test2 OBJECT-TYPE
 SYNTAX         Integer32
 UNITS          "tests"
 MAX-ACCESS     read-write
 STATUS         current
 DESCRIPTION
        "A test object"
 DEFVAL { 5 }
 ::= { idb 3 }

testGroup OBJECT-GROUP
      OBJECTS {
          test2
      }
      STATUS current
      DESCRIPTION "all test objects"
::= { idb 2 }

END

Agent file:

#!/usr/bin/perl

use NetSNMP::OID(':all');
use NetSNMP::agent(':all');
use NetSNMP::ASN(':all');

sub myhandler {
    my  ($handler, $registration_info, $request_info, $requests) = @_;
    print "Handling request\n";
    for ($request = $requests; $request; $request = $request->next()) {
        #
        #  Work through the list of varbinds
        #
        my $oid = $request->getOID();
        print "Got request for oid $oi\n";
        if ($request_info->getMode() == MODE_GET) {
            if ($oid == new NetSNMP::OID($rootOID . ".3")) {
                $request->setValue(ASN_INTEGER, 2);
            }
        }
    }
}

{
    $subagent = 0;

    print "Running new agent\n";
    my $rootOID = ".1.3.6.1.4.1.42134";
    my $regoid = new NetSNMP::OID($rootOID);
    if (!$agent) {
        $agent = new NetSNMP::agent('Name'=>'my_agent_name','AgentX' => 1);
        $subagent = 1;
        print "Starting subagent\n";
    }
    print "Registering agent\n";
    $agent->register("my_agent_name", $regoid, \&myhandler);
    print "Agent registered\n";

    if ($subagent) {
        $SIG{'INT'} = \&shut_it_down;
        $SIG{'QUIT'} = \&shut_it_down;
        $running = 1;

        while ($running) {
            $agent->agent_check_and_process(1);
        }

        $agent->shutdown();
    }
}

sub shut_it_down() {
    $running = 0;
    print "Shutting down agent\n";
}

When I run the agent I get the following:

Running new agent
Starting subagent!
Registering agent with oid idb
Agent registered

So I know that much is working. However when I run the following command:

snmpget -v 1 -c mycommunity localhost:161 test2.0

I get this error message:

Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: IDB-MIB::test2.0

I know from snmptranslate that the mib file is set correctly. I have even looked through the debug for snmpget (using -DALL) to make sure that the mib is being loaded and parsed correctly.

So my question is: Why is my subagent not being passed the request?

Update:

I've been told by @EhevuTov that my MIB file is not valid, however smilint does not report any issues and running snmpget -v 2c -c mycommunity localhost:161 .1.3.6.1.4.1.42134.3.0 does report the NAME of the object (IDB-MIB::test2.0) correctly, but does not find any data for it.

I am getting IDB-MIB::test2 = No Such Object available on this agent at this OID, which makes me think that my agent is not registering properly, however it's not throwing any errors.

Update 2:

I've been fiddling around with the agent code a bit. Based on the CPAN documentation (http://metacpan.org/pod/NetSNMP::agent), it looks like the $agent->register function call is supposed to return 0 if successful. So I checked the return code and got this:

Agent registered. Result: NetSNMP::agent::netsnmp_handler_registration=SCALAR(0x201e688)

Printing it out using Data::Dumper results in:

$VAR1 = bless( do{\(my $o = 34434624)}, 'NetSNMP::agent::netsnmp_handler_registration' );

I vaguely understand what bless does, but even so, I have no idea what this result is supposed to mean. So I'm starting to think that the agent is wrong somehow. Does anyone know how to debug these agents? Is there somewhere I can look to see if it's getting loaded properly into the master snmpd?

Was it helpful?

Solution

And I've solved the problem. It wasn't with the MIB, it was with the agent (which I had THOUGHT was working fine the whole time so I never bothered to check it).

I'd been running the agent stand-alone, because it seemed like it was working fine (never threw any errors when registering the handler). Apparently though, it needs to be run directly by snmpd.

I moved it to a directory that snmpd can access (because also apparently snmpd can't run scripts from /root, even though it's running as root), and added these lines in snmpd.conf:

perl print "\nRunning agents now\n";
perl do "/usr/share/snmp/agent.pl" || print "Problem running agent script: $!\n";
perl print "Agents run\n";

Note that these two lines were already present:

disablePerl false
perlInitFile /usr/share/snmp/snmp_perl.pl

I can now run the snmpget command and get the expected response.

> snmpget -v 2c -c mycommunity localhost:161 .1.3.6.1.4.1.42134.3
IDB-MIB::test2 = INTEGER: 2 tests
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top