0%

How to import SNMP MIB files on Ubuntu

One of my systems uses Telegraf’s snmp_trap input plugin to collect SNMP trap alerts and then forward them as HTTP for the next stage of processing.

The plugin itself is easy enough to configure, but translating OIDs into readable names depends on snmptranslate, and snmptranslate in turn depends on having the correct MIB files installed and configured properly.

I recently used this setup to collect alerts from H3C switches, so I thought it would be useful to record how to import MIB files on Ubuntu.

Before configuration

Before changing anything, try running snmptranslate first. The -L n option simply suppresses error output:

1
snmptranslate -L n .1.3.6.1.4.1.25506.2.38.1.6.3.0.1

This example OID comes from an H3C switch. If the MIB files are not installed, the result will only look like this:

1
SNMPv2-SMI::enterprises.25506.2.38.1.6.3.0.1

That is obviously not very helpful if you want to know what the device actually sent.

Import and configure

First, obtain the MIB files from H3C and extract them into a directory. In this example, I put them under:

/usr/share/mibs/h3c_mibs

After placing the MIB files there, edit the snmp.conf file:

1
vim /etc/snmp/snmp.conf

If the file does not exist, you may need to install the required package first:

1
apt install snmp

The original configuration usually looks like this:

1
2
3
4
# 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 :

To enable your custom MIB files, change it like this:

1
2
3
4
5
6
# mibs :

mibdirs +/usr/share/mibs/h3c_mibs
mibdirs +/usr/share/mibs/another_mib_dir # for example

mibs +ALL

A quick explanation:

  • Comment out the original mibs : line so the system is allowed to load third-party MIBs.
  • Use mibdirs to specify directories that contain MIB files. You can use it multiple times if needed.
  • Use mibs +ALL to search through all available MIB files.

Once the file is updated, save and exit. No service restart is required.

Test

Now try translating the OID again. If the MIB files are placed correctly and the config is right, it should work:

1
2
root@knktc.com:/root# snmptranslate -L n .1.3.6.1.4.1.25506.2.38.1.6.3.0.1
HH3C-TRAP-MIB::hh3cPeriodicalTrap

References

如果我的文字帮到了您,那么可不可以请我喝罐可乐?