Convert a MIB file to a Zabbix template¶
- Table of contents
- Convert a MIB file to a Zabbix template
Synopsis¶
Did you ever have to monitor a new device by SNMP? Do you have a MIB file that describes what that device can report, but you don't feel like translating that MIB by hand to Zabbix monitoring? Fear not, some hero has written a script that takes a MIB file and spits out a Zabbix template, ready for import!
Read on to find out how to do this.
Procedure¶
This guide is based on https://sbcode.net/zabbix/mib-to-zabbix-template/.
Install and configure SNMP tools¶
First, the SNMP tools and Perl SNMP library must be installed.
Debian/Ubuntu | CentOS/Red Hat/Rocky Linux |
---|---|
sudo apt-get update sudo apt install snmp sudo apt install snmp-mibs-downloader |
yum check-update yum install net-snmp-utils yum install net-snmp-libs |
To enable parsing of MIB files (it's disabled by default), edit /etc/snmp/snmp.conf
and comment out the line "mibs
" or "mibs :
".
Success | Failure |
---|---|
$ snmptranslate 1.3.6.1.2.1.1 SNMPv2-MIB::system |
$ snmptranslate 1.3.6.1.2.1.1 iso.3.6.1.2.1.1 |
Install Perl and the mib2zabbix conversion script¶
The mib2zabbix.pl
script is written in Perl, so we need to install it and some Perl modules that are used by the script.
Debian/Ubuntu | CentOS/Red Hat/Rocky Linux |
---|---|
apt-get install perl libxml-simple-perl libsnmp-perl |
yum install "perl(SNMP)" "perl(XML::Simple)" |
The mib2zabbix.pl
script was originally written by someone else (https://github.com/zabbix-tools/mib2zabbix), but the last activity on that repo was in December 2017.
I have forked the project and made some improvements to the code, so it works without warnings on a modern version of Perl.
Using git |
Just the script |
---|---|
git clone https://github.com/sputtene/mib2zabbix.git cd mib2zabbix |
curl https://raw.githubusercontent.com/sputtene/mib2zabbix/master/mib2zabbix.pl |
Make the script executable:
chmod +x mib2zabbix.pl
Test it by showing the usage information:
$ ./mib2zabbix.pl --help Usage: mib2zabbix.pl -o <OID> [OPTIONS]... Export loaded SNMP MIB OIDs to Zabbix Template XML -f, --filename=PATH output filename (default: stdout) -N, --name=STRING template name (default: OID label) -G, --group=STRING template group (default: 'Templates') -e, --enable-items enable all template items (default: disabled) -o, --oid=STRING OID tree root to export -v, --snmpver=1|2|3 SNMP version (default: 2) -p, --port=PORT SNMP UDP port number (default: 161) SNMP Version 1 or 2c specific -c, --community=STRING SNMP community string (default: 'public') SNMP Version 3 specific -L, --level=LEVEL security level (noAuthNoPriv|authNoPriv|authPriv) -n, --context=CONTEXT context name -u, --username=USERNAME security name -a, --auth=PROTOCOL authentication protocol (MD5|SHA) -A, --authpass=PASSPHRASE authentication protocol passphrase -x, --privacy=PROTOCOL privacy protocol (DES|AES) -X, --privpass=PASSPHRASE privacy passphrase Zabbix item configuration --check-delay=SECONDS check interval in seconds (default: 60) --disc-delay=SECONDS discovery interval in seconds (default: 3600) --history=DAYS history retention in days (default: 7) --trends=DAYS trends retention in days (default: 365) -h, --help print this message
If you see the usage information, everything is ok. If you get an error, make sure you installed all dependencies (SNMP tools and the Perl modules) in the previous steps.
(Original instructions) Use a single command to generate the Zabbix template XML file¶
From here on, the instructions on the original webpage and these instructions start to differ. The original instructions pipe the list of OIDs directly into the mib2zabbix
script.
These instructions use multiple steps with explicit intermediate files; I found that much easier to debug the whole procedure.
Also, I had to do some extra stuff (like setting environment variables) to make it work; I have not tested the one-line command below, so I don't know if it works.
If you have a single MIB file that you want to convert to a Zabbix template, you might be successful using the one-liner on the original page:
snmptranslate -Tz -m ./HUAWEI-MIB.mib | ./mib2zabbix.pl -o .1.3.6.1.4.1 -f template-huawei-mib.xml -N huawei-mib
Change the name of your MIB file, the top-level OID you want to export from, the name of the output XML file and the template name in the above command according to your situation.
Step by step Zabbix template XML file generation¶
I have followed this step by step procedure.
Set environment variables with MIB file paths¶
To start, we must set some environment variables that will be used by the SNMP tools and the mib2zabbix
script to determine which MIB files to load.
For the first step (generating a list of all OIDs) this is not strictly necessary, because we can specify the settings trough command line parameters (-m
and -M
parameters for the snmptranslate
command). The mib2zabbix.pl
doesn't provide command line switches for these settings though, so we must pass the configuration trough the environment or it will complain about missing MIB files.
In this example, I assume the MIB file(s) you want to convert to a Zabbix template are in the directory mib_files/
.
Execute this in the shell that you will use to run all following commands:
export MIBS=ALL export MIBDIRS="+mib_files/"
Pay attention to the + sign as the first character of the MIBDIRS
value, it is important.
Generate a list of OIDs¶
First, we will generate a list of all OIDs known to the system (this includes the MIB-file(s) that we actually want to use for the Zabbix template, because of the environment variables that were just set).
Execute:
snmptranslate -Tz > all_oids.list
to generate a file all_oids.list
in the correct format for mib2zabbix.pl
.
Generate the Zabbix template¶
Finally, we can generate the Zabbix template. You need the top-level OID (SNMP agent and SNMP trapper items will be created for all entries in the OID subtree under this top-level OID); I'll use .1.3.6.1.4.1.6431 here as an example.
Execute:
./mib2zabbix.pl --name 'Example Template from MIB' --group 'Templates/Examples' --enable-items --check-delay=5m --disc-delay=1h --oid .1.3.6.1.4.1.6431.1 -f Example_template_from_MIB.xml < all_oids.list
Adjust parameter values as required. Pay special attention to the --enable-items
parameter: without it, all items and discovery rules will be created disabled and that may not be what you want.
The file Example_template_from_MIB.xml
can now be imported in Zabbix through Configuration → Templates and then the Import button in the top right.
Updated by offbyone almost 3 years ago · 1 revisions