欢迎光临!
若无相欠,怎会相见

Linux导入SNMP私有mib库

序言

因工作需要,需要在Linux中导入公司的SNMP私有库,方便执行自动化。

详情

首先,在Linux中安装SNMP客户端,由于我用的是Ubuntu,因此只需要执行 sudo apt install snmp 。

一般来说,snmp的配置文件为snmp.conf,路径为 /etc/snmp/ ,mib库的目录为:default: /home/username/.snmp/mibs:/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf:/usr/share/mibs/site:/usr/share/snmp/mibs:/usr/share/mibs/iana:/usr/share/mibs/ietf:/usr/share/mibs/netsnmp 。

接下来,开始导入私有mib库。将私有库上传到/usr/share/snmp/mibs 目录下,我一般使用这个目录,所有的用户都可以使用,如果是在用户目录下,只能是当前用户使用。

例如我使用的私有库是 HILLSTONE-SYSTEM-MIB.my,将其传到上述的目录中,然后修改一下 /etc/snmp/snmp.conf

原始的snmp.conf

# As the snmp packages come without MIB files due to license reasons, loading
# of MIBs is disabled by default. If you added the MIBs you can reenable
# loading them by commenting out the following line.
mibs :

修改为:

# As the snmp packages come without MIB files due to license reasons, loading
# of MIBs is disabled by default. If you added the MIBs you can reenable
# loading them by commenting out the following line.
mibs :
mibs  +/usr/share/snmp/mibs/HILLSTONE-SYSTEM-MIB.my

如果需要增加多个,接着在后面添加就行:

# As the snmp packages come without MIB files due to license reasons, loading
# of MIBs is disabled by default. If you added the MIBs you can reenable
# loading them by commenting out the following line.
mibs :
mibs  +/usr/share/snmp/mibs/HILLSTONE-SMI.my
mibs  +/usr/share/snmp/mibs/HILLSTONE-SYSTEM-MIB.my

我在网上查找资料的时候,发现可以直接不用添加路径,不过我还是添加了。

然后就可以执行 snmptest 命令,如果没有报错,perfect~,但是我用的时候报错了,报错包含如下信息:

Cannot find module (SNMPv2-SMI): At line 18 in /usr/share/snmp/mibs/HILLSTONE-SMI.my
Did not find 'enterprises' in module #-1 (/usr/share/snmp/mibs/HILLSTONE-SMI.my)
Unlinked OID in HILLSTONE-SMI: hillstone ::= { enterprises 28557 }
Undefined identifier: enterprises near line 24 of /usr/share/snmp/mibs/HILLSTONE-SMI.my
Cannot find module (SNMPv2-TC): At line 18 in /usr/share/snmp/mibs/HILLSTONE-SYSTEM-MIB.myl
Did not find 'TruthValue' in module #-1 (/usr/share/snmp/mibs/HILLSTONE-SYSTEM-MIB.my)
Did not find 'hillstoneSys' in module HILLSTONE-SMI (/usr/share/snmp/mibs/HILLSTONE-SYSTEM-MIB.my)

初步看是缺少了SNMPv2-SMI 和 SNMPv2-TC 这两个库,由于我也是第一次在 Linux 中使用 SNMP 获取设备信息,我就随便在 Windows 中的MIB Broswer中把这两个库文件搂出来,并上传到Linux中,可是并没有卵用,只能继续寻找,不过还好,竟然找到了cisco的ftp服务器,在上面下载了这两个库文件,上传后正常使用。

结语

这个问题折腾了一天,在这里记录一下自己的解决方案,以供需要的人参考。之前在V2EX中询问,没有答案,还是靠自己。

另外cisco的ftp服务器是 ftp://ftp.cisco.com/pub/mibs

上文中我用的文件链接为:

ftp://ftp.cisco.com/pub/mibs/v2/SNMPv2-SMI.my

ftp://ftp.cisco.com/pub/mibs/v2/SNMPv2-TC.my

这两个文件上传到上文中的目录中就可用了。

如有错误,敬请指出,感谢指正!            — 2019-07-31  10:56:05     于苏州

赞(2) 打赏
转载请注明:飘零博客 » Linux导入SNMP私有mib库
分享到: 更多 (0)

评论 1

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #1

    居然看到自己公司的MIB库,诚惶诚恐

    zixiaohao 3年前 (2021-02-22) 来自天朝的朋友 谷歌浏览器 Windows 10 回复

欢迎光临