3

我正在尝试按照本教程将我自己的 MIB 模块添加到 snmp 代理中: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 的此代理上没有可用的此类对象”)所以我想试试运气,希望有人能帮助我!

4

1 回答 1

0

我有完全相同的问题,它不适用于 5.6.2。

我是如何解决的:

我已经升级到 5.7.3 ,然后它开始工作了。您需要注意以下事项:

  1. 使用 --with-mib-modules=agentx 配置包(在构建时)以支持 agentx)这是我的配置:

      ./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. 将 agentx 添加到 snmpd.conf 这是我的 snmpd.config

    master  agentx
    
    rocommunity public rwcommunity private
    
    com2sec readonly  default         public 
    com2sec readwrite default     private
    
  3. 使用调试启动 snmpd,以提供更多详细信息:

    snmpd -f -Lo: -Dagentx
    
  4. 然后启动agentx应用

以下教程也有帮助:

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

于 2018-04-23T09:38:19.397 回答