snmpget:此代理在此 OID 上没有可用的此类对象

Chr*_*ian 5 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"));
}
Run Code Online (Sandbox Code Playgroud)

我运行 ./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
Run Code Online (Sandbox Code Playgroud)

现在,使用指定的 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 
Run Code Online (Sandbox Code Playgroud)

看起来 MIB 模块没有正确内置到代理中,但我想不出原因。

我知道之前已经在这里发布过同样的问题,但没有收到任何答案。(snmpget 返回“此 OID 处的此代理上没有此类对象”)所以我想试试运气,希望有人可以帮助我!

ran*_*nsh 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
    
    Run Code Online (Sandbox Code Playgroud)
  2. 将agentx添加到snmpd.conf这是我的snmpd.config

    master  agentx
    
    rocommunity public rwcommunity private
    
    com2sec readonly  default         public 
    com2sec readwrite default     private
    
    Run Code Online (Sandbox Code Playgroud)
  3. 使用 debug 启动 snmpd,以提供更多详细信息:

    snmpd -f -Lo: -Dagentx
    
    Run Code Online (Sandbox Code Playgroud)
  4. 然后启动agentx应用程序

以下教程也有帮助:

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