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!