Net-snmp perl subagent does not start snmpget

I was working on a custom SNMP-Mib, and I leaned against the wall, trying to get the agent to return the correct data.

MIB (confirmed 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 start the agent, I get the following:

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

So, I know a lot works. 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 installed correctly. I even looked at debug for snmpget (using -DALL) to make sure mib loads and parses correctly.

So my question is: why did my subagent not pass the request?

Update:

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

I get 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 does not throw any errors.

Update 2:

I was looking a bit for agent code. Based on the CPAN documentation ( http://metacpan.org/pod/NetSNMP::agent ), it seems that calling the $agent->register function should return 0 if successful. So I checked the return code and got the following:

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

A listing using Data::Dumper results in:

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

I dimly understand what the blessing does, but even then I have no idea what this result means. So I'm starting to think that the agent is somehow wrong. Does anyone know how to debug these agents? Somewhere I can see if the snmpd wizard loads correctly?

+8
perl snmp mib
source share
1 answer

And I solved the problem. It was not with the MIB, it was with the agent (which I THOUGHT worked fine all the time, so I never bothered to check it).

I started the agent autonomously, because it seemed to work fine (I never threw any errors when registering the handler). Apparently, though this should be running snmpd directly.

I moved it to a directory that snmpd can access (because apparently snmpd cannot run scripts from / root, even if it runs as root) and added these lines to 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 

Now I can 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 
+2
source share

All Articles