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 | # As the snmp packages come without MIB files due to license reasons, loading |
To enable your custom MIB files, change it like this:
1 | # mibs : |
A quick explanation:
- Comment out the original
mibs :line so the system is allowed to load third-party MIBs. - Use
mibdirsto specify directories that contain MIB files. You can use it multiple times if needed. - Use
mibs +ALLto 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 | root@knktc.com:/root# snmptranslate -L n .1.3.6.1.4.1.25506.2.38.1.6.3.0.1 |
References
- Telegraf
snmp_trapplugin: https://github.com/influxdata/telegraf/tree/master/plugins/inputs/snmp_trap snmp.confman page: https://linux.die.net/man/5/snmp.conf