[a]如何让net-SNMP加载MIB

2,433 阅读1分钟

玩玩SNMP,第一个命令就是snmptranslate吧。执行下:

snmptranslate .1.3.6.1.4.1

如果返回的是 iso.3.6.1.4.1

就说明MIB没有加载。而且Ubuntu默认是没有MIB的。怎么办?

downloads common SNMP MIBs:

sudo apt-get install snmp-mibs-downloader

tells Ubuntu to load SNMP MIB files:

sudo sed -i 's/mibs :/# mibs :/g' /etc/snmp/snmp.conf

标注掉mibs就可以加载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 :

Now you should be able to lookup your SNMP OIDs and MIBs:

$ snmptranslate -On -IR ifTable
.1.3.6.1.2.1.2.2
$ snmptranslate .1.3.6.1.2.1.2.2
IF-MIB::ifTable

想知道找个下载器把MIB放到哪里了吗?请执行命令查找:

sudo apt install libsnmp-dev
net-snmp-config --default-mibdirs

MIB文件肯定在列出的文件夹中

cont.

gtcsq.readthedocs.io/en/latest/p…

TROUBLESHOOTING : Exposing CPU and Memory Information via SNMP

snmpget -v2c -cpublic localhost  UCD-SNMP-MIB:ssCpuIdle
UCD-SNMP-MIB::ssCpuIdle = No Such Object available on this agent at this OID

RESULT:

Issue
How do I expose CPU and memory statistics via SNMP? What is the MIB/OID?
Environment
Cumulus Linux, all versions
Resolution
The relevant OIDs are:
CPU: .1.3.6.1.4.1.2021.11 (UCD-SNMP-MIB::systemStats)
Memory: .1.3.6.1.4.1.2021.4 (UCD-SNMP-MIB::memory)
To configure SNMP to expose CPU and memory information:

If snmpd has not already been enabled, follow instructions in the technical documentation to enable and start snmpd.
Allow access to the OIDs by editing /etc/snmp/snmpd.conf. The following example adds the relevant MIBs to the systemonly view.

###############################################################################
#
#  ACCESS CONTROL
#
<CONFIGURATION_TRUNCATED/>
# Cumulus specific
view   systemonly  included   .1.3.6.1.4.1.40310.1
view   systemonly  included   .1.3.6.1.4.1.40310.2
# Memory utilization
view   systemonly  included   .1.3.6.1.4.1.2021.4 
# CPU utilization
view   systemonly  included   .1.3.6.1.4.1.2021.11
Restart snmpd to reload the configuration:

cumulus@switch:~$ sudo service snmpd restart