Convert MIBs Files to Zabbix Templates

Video Lecture

Convert MIBs Files to Zabbix Templates Convert MIBs Files to Zabbix Templates Convert MIBs Files to Zabbix Templates

Description

MIB files can be analysed and converted to Zabbix templates containing Items, Discovery Rules and Value Types.

One script for doing this is called mib2zabbix and can be downloaded from https://github.com/cavaliercoder/mib2zabbix.

Before running this script, you should already have the required SNMP dependencies installed and configured correctly.

On Ubuntu and other Debian based systems,

1
2
3
sudo apt-get update
sudo apt install snmp
sudo apt install snmp-mibs-downloader

On Centos and other Red-Hat based systems

1
2
3
yum check-update
yum install net-snmp-utils
yum install net-snmp-libs

Now configure the snmp.conf to return MIBs descriptions.

1
sudo nano /etc/snmp/snmp.conf

Comment out the mibs line like this,

1
#mibs

Do a simple test.

1
snmptranslate 1.3.6.1.2.1.1

The response should be

1
SNMPv2-MIB::system

This is a MIB description of the OID 1.3.6.1.2.1.1

snmptranslate is now able to translate, and this is required before you can continue.

mib2zabbix.pl is written in perl, so you will need to install the perl dependencies.

On Ubuntu

1
apt-get install perl libxml-simple-perl libsnmp-perl

On Centos

1
yum install "perl(SNMP)" "perl(XML::Simple)"

Next, get the mib2zabbix perl script

1
curl https://raw.githubusercontent.com/cavaliercoder/mib2zabbix/master/mib2zabbix.pl > mib2zabbix

or

1
wget -O mib2zabbix https://raw.githubusercontent.com/cavaliercoder/mib2zabbix/master/mib2zabbix.pl

Give the mib2zabbix file execute permissions.

1
chmod a+x mib2zabbix

Test it

1
./mib2zabbix -h

The response should be

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 get anything else then perl was not installed properly or it cannot find mib2zabbix. Check the error in the console.

Now to ensure you have the required MIB file that you want to convert.

A good example may be the HUAWEI-MIB.mib.

You can usually find the MIB files you need on the internet.

You can download the HUAWEI-MIB.mib from here.

1
curl http://www.circitor.fr/Mibs/Mib/H/HUAWEI-MIB.mib > HUAWEI-MIB.mib 

or

1
wget -O HUAWEI-MIB.mib http://www.circitor.fr/Mibs/Mib/H/HUAWEI-MIB.mib

Next, see if snmptranslate can read this file.

1
snmptranslate -Tz -m ./HUAWEI-MIB.mib

You should see this plus many more lines showing the MIBs and their OIDs,

1
2
3
4
5
6
7
"org"                   "1.3"
"dod"                   "1.3.6"
"internet"              "1.3.6.1"
"directory"             "1.3.6.1.1"
"mgmt"                  "1.3.6.1.2"
"mib-2"                 "1.3.6.1.2.1"
...

Now it is time to convert it to a template for Zabbix by piping the snmptranslate response into mib2zabbix.

1
snmptranslate -Tz -m ./HUAWEI-MIB.mib | ./mib2zabbix -o .1.3.6.1.4.1 -f template-huawei-mib.xml -N huawei-mib

This will create a new file called template-huawei-mib.xml with the name huawei-mib within the xml.

Eg,

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
  <date>2020-04-03T10:20:58Z</date>
  <groups>
    <group>
      <name>Templates</name>
    </group>
  </groups>
  <templates>
    <template>
      <name>huawei-mib</name>
      <applications>
...

This new xml file can be imported into Zabbix

Notes

See video for a more detailed demonstration and recommendations. Also note that all items, discovery rules and their item prototypes will be disabled by default. You should decide which is important to enable for your needs based on the devices official documentation. Enabling all items, discovery rules and their item prototypes may put unnecessary strain on your Zabbix server resources and the SNMP device so it is important to check what you actually need.

Cisco SNMP V2 Public Mibs

Circitor.fr MIB files repository