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

标签 snmp net-snmp snmpd

我正在尝试按照本教程将我自己的 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 returns "No Such Object available on this agent at this OID")
所以我想试试运气,希望有人能帮助我!

最佳答案

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

我是如何解决的:

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

  • 使用 --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
    
  • 将 agentx 添加到 snmpd.conf
    这是我的 snmpd.config
    master  agentx
    
    rocommunity public rwcommunity private
    
    com2sec readonly  default         public 
    com2sec readwrite default     private
    
  • 使用调试启动 snmpd,以提供更多详细信息:
    snmpd -f -Lo: -Dagentx
    
  • 然后启动agentx应用

  • 以下教程也有帮助:

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

    关于snmpget : No such object available on this agent at this OID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29823789/

    相关文章:

    tcp - 使用 SNMP 检查开放的 TCP/UDP 端口

    c - 在 C 中使用 Net-SNMP 的简单 snmp 陷阱生成器程序?

    windows - SNMP 子代理开发

    SNMP net-snmp 与预期的 OID 转换不同

    snmp - snmpd 和 net-snmp 之间的区别

    php - 我可以在后台模式下运行 php 脚本吗?

    snmp - snmpv3 中上下文名称的意义

    linux - SNMP 代理配置 windows/linux

    c - Net-SNMP 自定义 MIB 处理程序

    使用 unix 套接字地址时 snmpget 超时