Windows下使用net-snmp-5.4.1扩展代理所遇问题及解决

       SNMP代理的开发包有很多,本人选择了net-snmp-5.4.1,开发过程中所遇到的文档及帮助文件多是unix或linux平台的,因此步步维艰,遇到了不少问题。本人扩展代理的方法是将自定义的mib文件编译到snmpd代理中,编译mib文件的工具是mib2c。以下所列的问题及解决方法有些是共性的,有些是特定条件下产生的,仅供参考。

1) 通过vc运行代理后,DOS窗口一闪就关闭,通过命令行窗口运行,提示信息:
       Error opening specified endpoint ""
       Server Exiting with code 1
      解决:windows系统的snmp服务需要关闭,因为UDP端口已经被占用。代理默认的端口都是162,也可以通过配置进行修改。

2) 启动snmpd代理如下C:/usr/bin>snmpd -f -Le –d,出现以下内容:
      netsnmp_assert x failed C:/net-snmp-5.4.1/net-snmp-5.4.1/agent/agent_registry.c: 535
      netsnmp_assert x failed C:/net-snmp-5.4.1/net-snmp-5.4.1/agent/agent_registry.c: 535
      netsnmp_assert x failed C:/net-snmp-5.4.1/net-snmp-5.4.1/agent/agent_registry.c: 535
      NET-SNMP version 5.4.1
      但不影响使用。

     解决:这是开发包中的一个bug,agent_registry.c中第535行代码存在问题,官方补丁代码方法:
     a) 将/agent/agent_registry.c文件中从第535行
              netsnmp_assert(!"registration != duplicate"); /* always false */
         修改为:
             if (new_sub->namelen != 1) /* ignore root OID dups */
                   netsnmp_assert(!"registration != duplicate"); /* always false */

        也就是加上一个是否为根节点OID的判断。
     b) 重新编译libagent.lib
     c) 重新编译snmpd.exe
     d) 重新启动,OK!

3) 编译win32下的工程时出现以下提示不能通过:
     :/agent-dev/zht/bbeagent/britgw-mib.c(35) : fatal error C1010: unexpected end of file while looking for precompiled header directive
     解决:设置一下编译选项project->settings->C/C++选项卡->Precompiled Headers->Automatic use of precompiled headers。

4) 使用mib2c工具时遇到以下提示:
You didn't give mib2c a valid OID to start with.  IE, I could not find
any information about the mib node "".  This could be caused
because you supplied an incorrectly node, or by the MIB that you're
trying to generate code from isn't loaded.  To make sure your mib is
loaded, run mib2c using this as an example:

    env MIBS="+MY-PERSONAL-MIB" mib2c -c BitSyn

You might wish to start by reading the MIB loading tutorial at:
    http://www.net-snmp.org/tutorial-5/commands/mib-options.html
And making sure you can get snmptranslate to display information about
your MIB node.  Once snmptranslate works, then come back and try mib2c
again.
     解决:mib2c的参数为对象名称,不是MIB文件名,也不是节点名称。

5) 使用mib2c工具时出现以下提示:
       You didn't give mib2c a valid OID to start with.
     解决:该提示可能意味着MIB文件未被有效搜索到,参数中的对象工具不能识别。在命令窗口运行snmpconf
    出现: 1: snmpd.conf
                  2: snmptrapd.conf
                  3: snmp.conf
    选3出现:
                 1: Default Authentication Options
                2: Debugging output options
                3: Textual mib parsing
                4: Output style options
   选3出现:
               1: Specifies directories to be searched for mibs.
               2: Specifies a list of mibs to be searched for and loaded.
               3: Loads a particular mib file from a particualar path
               4: Should errors in mibs be displayed when the mibs are loaded
               5: Should warnings about mibs be displayed when the mibs are loaded
               6: Be strict about about mib comment termination.
               7: Should underlines be allowed in mib symbols (illegal)
               8: Force replacement of older mibs with known updated ones

    选2出现:
        Select section: 2

       Configuring: mibs
       Description:
       Specifies a list of mibs to be searched for and loaded.
       Adding a '+' sign to the front of the argument appends the new
      mib name to the list of mibs already being searched for.
      arguments: [+]mibname[:mibname...]

     这里就是在帮助文件中出现的"MIBS+my-mib"的地方了
    输入自定义的MIB文件名:+TEST-MIB
    在设置finished后生成或覆盖原snmp.conf。然后拷贝到 c:/usr/etc/snmp/下。

6) 运行查询工具snmpget出现以下提示:
      No Such Object available on this agent at this OID
      解决:检查mib-module-inits.h文件是否修改正确,本人遇到的问题就是参考readme.win32文件进行配置时没有修改正确,导致自定义对象的初始化动作未被调用。可以使用断点跟踪来验证是否被调用。
      最好使用记事本进行修改,不可在vc中直接修改。

7)使用snmpget远程访问时出现以下提示:
     No Such Object available on this agent at this OID
     解决:需要共同体配置文件snmpd.conf,相应地方添加内容如下:
                #定义安全体名称
                com2sec mynetwork 129.26.20.4 mysoft
                #定义安全组
                group mygroup v2c mynetwork
                #定义视图,使用默认
                view all    included  .1   80
                #向安全组授权相应的视图
               access mygroup "" v2c noauth exact all all none
   

              使用工具访问格式:
              snmpget -v2c -c mysoft 129.26.20.. ...

     这几个问题困扰本人相对较多的时间,希望大家避免在此多作无谓的逗留。祝大家好运

你可能感兴趣的:(Windows下使用net-snmp-5.4.1扩展代理所遇问题及解决)