Skip to content

Convert MIBs Files to Zabbix Templates

Video Lecture

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,

sudo apt-get update
sudo apt install snmp
sudo apt install snmp-mibs-downloader

On Centos and other Red-Hat based systems

yum check-update
yum install net-snmp-utils
yum install net-snmp-libs

Now configure the snmp.conf to return MIBs descriptions.

sudo nano /etc/snmp/snmp.conf

Comment out the mibs line like this,

#mibs

Do a simple test.

snmptranslate 1.3.6.1.2.1.1

The response should be

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

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

On Centos

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

Note

On CentOS 8, you may get the error that the perl snmp libs cannot be found. You can download the rpm first from rpm -ivh http://repo.okay.com.mx/centos/8/x86_64/release/okay-release-1-3.el8.noarch.rpm and then try again.

Next, get the mib2zabbix perl script

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

or

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

Give the mib2zabbix file execute permissions.

chmod a+x mib2zabbix

Test it

./mib2zabbix -h

The response should be

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.

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

or

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

Next, see if snmptranslate can read this file.

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

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

"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.

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>
... etc, many more lines of xml

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

Comments