Skip to content

Convert SNMPWALK to Zabbix Template

Video Lecture

Convert SNMPWALK to Zabbix Template

Description

Creating a Zabbix template from an SNMPWALK response.

GitHub Repository : https://github.com/Sean-Bradley/SNMPWALK2ZABBIX

Requirements

  • Linux (Tested on Debian 11 and Ubuntu 20.04)
  • Python3 (use python3 -V to check)
  • SNMP (uses SNMPv2 to query)
  • SNMP-MIBS-Downloader, plus any other custom or proprietary MIBs you may want to use. It will use the MIB descriptions of OIDs as it generates the templates items and discovery rules.
  • A working SNMP device that responds to an snmpwalk command
  • Final template is Zabbix 6 LTS compatible

Download

wget https://raw.githubusercontent.com/Sean-Bradley/SNMPWALK2ZABBIX/master/snmpwalk2zabbix.py

Install SNMP and SNMP-MIBS-Downloader

The server where you will run the script from, needs the SNMP tools and MIBs. You can get a good set of common MIBs when installing snmp-mibs-downloader on Debian/Ubuntu.

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

Usage

python3 snmpwalk2zabbix.py community-string IP-address root-OID
  • community-string : This is the v2c community name. Most systems default to use public as the community name.
  • IP-address : The IP address of the SNMP device that returns a valid snmpwalk response.
  • root-OID : Indicates which OID to start creating items from. An OID very low, e.g, 1, will result in a much larger template, versus using 1.3 or 1.3.6 or 1.3.6.1 or 1.3.6.1.2 or 1.3.6.1.2.1, etc.

Example

Before running the script, ensure that you can at least do a simple snmpwalk from the server that you are running this script from.

E.g., I can snmpwalk my network router, and it responds.

snmpwalk -v 2c -c public 192.168.1.1 1.3.6.1.2.1

Example output

SNMPv2-MIB::sysDescr.0 = STRING: 1.2.0 0.9.1 v0001.0 Build 201203 Rel.59032n
SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.16972
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (292015000) 33 days, 19:09:10.00
SNMPv2-MIB::sysContact.0 = STRING: unknown
SNMPv2-MIB::sysName.0 = STRING: Archer MR600
SNMPv2-MIB::sysLocation.0 = STRING: unknown
... and many more lines

Now to generate the template.

python3 snmpwalk2zabbix.py public 192.168.1.1 1.3.6.1.2.1

It will try to produce a Zabbix 6 LTS compatible XML template that you can import.

E.g.,

<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
    <version>6.0</version>
    <templates>
        <template>
            <uuid>612e6942006545ad90f9962eb1ccce14</uuid>
            <template>Archer MR600 SNMP</template>
            <name>Archer MR600 SNMP</name>
            <description>Template built by SNMPWALK2ZABBIX script from https://github.com/Sean-Bradley/SNMPWALK2ZABBIX</description>
            <groups>
                <group>
                    <name>Templates</name>
                </group>
            </groups>
            <items>
                <item>
                    <uuid>5d438a37f38f484fa387a6eb455113fd</uuid>
                    <name>sysDescr</name>
                    <type>SNMP_AGENT</type>
                    <snmp_oid>.1.3.6.1.2.1.1.1.0</snmp_oid>
                    <key>SNMPv2-MIB.sysDescr.0</key>
                    <value_type>CHAR</value_type>
                    <description>A textual description of the entity. This value should include the full name and version identification of the system's hardware type, software operating-system, and networking software.</description>
                    <history>7d</history>
                    <trends>0</trends>
                    <status>DISABLED</status>
                </item>
                ... and many more XML nodes

The XML file will be saved into the same folder as where the script was run. It named my example output file as template-Archer-MR600.xml

Note that the generated template is not perfect. It is up to you if you want to make it better. The items and discovery rules are created as DISABLED by default. This is to minimize the possibility that assigning this template to a host won't overload your Zabbix server/proxy or your SNMP host/device.

After importing the template, you should review which items and discovery rules that you want enabled. If a MIB description can be found for an OID, then it will use it in the name and description of the item and discovery rule. And hopefully that will make the process of deciding if you want it enabled or not, a little easier.

When you assign your new template to a host in Zabbix. Make sure that your Zabbix server, or Zabbix proxy (if monitored by proxy) can also access your SNMP host/device.

Also note that despite the creation of the template requiring SNMPv2, you can actually still use the resulting template with an SNMPv3 configured host provided that you've configured your host correctly in Zabbix to use SNMPv3. See Configure an SNMPv3 Host in Zabbix for more information about setting up SNMPv3 Hosts.

Comments