snmpget: No such object available on this agent at this OID

Christian picture Christian · Apr 23, 2015 · Viewed 9.6k times · Source

I am trying to add my own MIB-Module into a snmp agent, following this tutorial: http://www.net-snmp.org/wiki/index.php/TUT:Writing_a_MIB_Module Now, I followed the tutorial step by step and doubled checked everything, searched a really long time but nothing helped me fixing my problem!

I am using net-snmp version 5.7.3

I implemented the following code into the net-snmp/agent/mibgroup directory:

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "nstAgentModuleObject.h"

/*
* the variable we want to tie an OID to.  The agent will handle all
** GET and SET requests to this variable changing it's value as needed.
*/

static long nstAgentModuleObject = 42;

/*
* our initialization routine, automatically called by the agent 
* (to get called, the function name must match init_FILENAME()) 
*/
void
init_nstAgentModuleObject(void)
{
static oid      nstAgentModuleObject_oid[] =
    { 1, 3, 6, 1, 4, 1, 8072, 2, 4, 1, 1, 1, 0 };

/*
 * a debugging statement.  Run the agent with -DnstAgentModuleObject to see
 * the output of this debugging statement. 
 */
DEBUGMSGTL(("nstAgentModuleObject",
            "Initializing the nstAgentModuleObject module\n"));


/*
 * the line below registers our variables defined above as
 * accessible and makes it writable.  A read only version of any
 * of these registration would merely call
 * register_read_only_int_instance() instead.  The functions
 * called below should be consistent with your MIB, however.
 */

DEBUGMSGTL(("nstAgentModuleObject",
            "Initalizing nstAgentModuleObject scalar integer.  Default value = %d\n",
            nstAgentModuleObject));

netsnmp_register_long_instance("nstAgentModuleObject",
                              nstAgentModuleObject_oid,
                              OID_LENGTH(nstAgentModuleObject_oid),
                              &nstAgentModuleObject, NULL);

DEBUGMSGTL(("nstAgentModuleObject",
            "Done initalizing nstAgentModuleObject module\n"));
}

I ran ./configure --with-mib-modules="nstAgentModuleObject", followed by make and make install. So the nstAgentModuleObject should be integrated in the snmpd agent.

The associated MIB NET-SNMP-TUTORIAL-MIB is saved in /usr/local/snmp/mbis, as well as /~/.snmp/mibs.

I added mibs +ALL in the snmpd.conf to make sure the MIB is loaded correctly. Also I used export MIBS=+all, just in case another .conf is read which should not be the case.

Using following commands I get the results shown below:

snmptranslate -Of NET-SNMP-TUTORIAL-MIB:nstAgentModuleObject
.iso.org.dod.internet.private.enterprises.netSnmp.netSnmpExamples.netSnmpTutorialMIB.nstMIBObjects.nstAgentModulesObject

snmptranslate -On NET-SNMP-TUTORIAL-MIB:nstAgentModuleObject
.1.3.6.1.4.1.8072.2.4.1.1.1

Now, running snmpget with the specified OID gives me this error(appending a 0 on the end since its a scalar. Results in the same error without it as well).

snmpget -v2c -c public localhost .1.3.6.1.4.1.8072.2.4.1.1.1.0
NET-SNMPEXAMPLES-MIB::netSnmpExamples.4.1.1.1.0 = No Such Object availaible on this agent at this OID 

It seems like the MIB-module is not properly build-in to the agent, but I can't think of a reason why.

I know the same question has been posted before here, but it didn't receive any answer.(snmpget returns "No Such Object available on this agent at this OID") So I want to try my luck and hope someone can help me out!

Answer

ransh picture ransh · Apr 23, 2018

I had the exact same issue, It didn't work with 5.6.2.

How I solved it:

I've upgraded to 5.7.3 , then it started working. you need to take care for the following:

  1. configure the package (on build) to support agentx) with --with-mib-modules=agentx this is my configure:

      ./configure --prefix=/usr --build=i386-linux --host=arm-linux --target=arm-linux --with-ar=arm-arago-linux-gnueabi-ar --with-cc=arm-arago-linux-gnueabi-gcc --with-ld=arm-arago-linux-gnueabi-ld --with-cflags="-O3 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp" --with-endianness=big --with-ldflags=-Bstatic --enable-mini-agent --with-mib-modules="mibII ip-mib if-mib tcp-mib udp-mib ucd_snmp target agent_mibs notification-log-mib snmpv3mibs notification agentx" --without-openssl --without-perl-modules --disable-embedded-perl --disable-shared --with-default-snmp-version="2" --with-sys-contact="root" --with-sys-location="unknown" --with-logfile="/var/log/snmpd.log" --with-persistent-directory="/var/net-snmp" --disable-manuals
    
  2. add agentx to snmpd.conf This is my snmpd.config

    master  agentx
    
    rocommunity public rwcommunity private
    
    com2sec readonly  default         public 
    com2sec readwrite default     private
    
  3. started snmpd with debug, to give more details:

    snmpd -f -Lo: -Dagentx
    
  4. Then start the agentx application

The following tutorial also helped:

http://net-snmp.sourceforge.net/wiki/index.php/TUT:Writing_a_Subagent