我正在尝试按照本教程将我自己的 MIB 模块添加到 snmp 代理中:http://www.net-snmp.org/wiki/index.php/TUT:Writing_a_MIB_Module http://www.net-snmp.org/wiki/index.php/TUT:Writing_a_MIB_Module现在,我一步步按照教程进行操作,仔细检查所有内容,搜索了很长时间,但没有任何帮助我解决我的问题!
我使用的是net-snmp版本5.7.3
我在 net-snmp/agent/mibgroup 目录中实现了以下代码:
#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"));
}
我运行 ./configure --with-mib-modules="nstAgentModuleObject",然后运行 make 和 make install。因此 nstAgentModuleObject 应该集成在 snmpd 代理中。
关联的 MIB NET-SNMP-TUTORIAL-MIB 保存在 /usr/local/snmp/mbis 以及 /~/.snmp/mibs 中。
我在 snmpd.conf 中添加了 mibs +ALL 以确保 MIB 正确加载。我还使用了export MIBS=+all,以防万一读取另一个.conf,但事实并非如此。
使用以下命令我得到如下所示的结果:
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
现在,使用指定的 OID 运行 snmpget 会出现此错误(由于它是标量,所以在末尾附加 0。没有它也会导致相同的错误)。
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
看起来 MIB 模块没有正确内置到代理中,但我想不出原因。
我知道之前已经在这里发布过同样的问题,但没有收到任何答案。(snmpget 返回“此代理在此 OID 处没有可用的此类对象” https://stackoverflow.com/questions/20974249/snmpget-returns-no-such-object-available-on-this-agent-at-this-oid?s=1%7C1.5045)
所以我想试试运气,希望有人能帮助我!