Skip to main content

A pure-Python implementation of SNMP/SMI MIB parsing and conversion library.

Project description

SNMP MIB Compiler

Become a Sponsor PyPI PyPI Downloads Python Versions GitHub license

PySMI is a pure-Python implementation of SNMP SMI MIB parser. This tool is designed to turn ASN.1 MIBs into various formats. As of this moment, JSON and PySNMP modules can be generated from ASN.1 MIBs.

Features

  • Understands SMIv1, SMIv2 and de-facto SMI dialects
  • Turns MIBs into PySNMP classes and JSON documents
  • Maintains an index of MIB objects over many MIB modules
  • Automatically pulls ASN.1 MIBs from local directories, ZIP archives, and HTTP servers
  • 100% Python, works with Python 3.8+

Rendered PySMI documentation can be found at PySMI site.

How to use PySMI

If you are using PySNMP, you might never notice PySMI presence - PySNMP calls PySMI for MIB download and compilation behind the scenes (you can still can do that manually by invoking mibdump tool).

To turn ASN.1 MIB into a JSON document, call mibdump tool like this:

$ mibdump --generate-mib-texts  --destination-format json IF-MIB
Source MIB repositories: file:///usr/share/snmp/mibs, https://mibs.pysnmp.com/asn1/@mib@
Borrow missing/failed MIBs from: https://mibs.pysnmp.com/json/fulltexts/@mib@
Existing/compiled MIB locations:
Compiled MIBs destination directory: .
MIBs excluded from code generation: RFC-1212, RFC-1215, RFC1065-SMI, RFC1155-SMI,
RFC1158-MIB, RFC1213-MIB, SNMPv2-CONF, SNMPv2-SMI, SNMPv2-TC, SNMPv2-TM
MIBs to compile: IF-MIB
Destination format: json
Parser grammar cache directory: not used
Also compile all relevant MIBs: yes
Rebuild MIBs regardless of age: yes
Do not create/update MIBs: no
Byte-compile Python modules: no (optimization level no)
Ignore compilation errors: no
Generate OID->MIB index: no
Generate texts in MIBs: yes
Keep original texts layout: no
Try various filenames while searching for MIB module: yes
Created/updated MIBs: IANAifType-MIB, IF-MIB, SNMPv2-MIB
Pre-compiled MIBs borrowed:
Up to date MIBs: SNMPv2-CONF, SNMPv2-SMI, SNMPv2-TC
Missing source MIBs:
Ignored MIBs:
Failed MIBs:

JSON document build from IF-MIB module would hold information such as:

   {
      "ifMIB": {
          "name": "ifMIB",
          "oid": "1.3.6.1.2.1.31",
          "class": "moduleidentity",
          "revisions": [
            "2007-02-15 00:00",
            "1996-02-28 21:55",
            "1993-11-08 21:55"
          ]
        },
      // ...
      "ifTestTable": {
        "name": "ifTestTable",
        "oid": "1.3.6.1.2.1.31.1.3",
        "nodetype": "table",
        "class": "objecttype",
        "maxaccess": "not-accessible"
      },
      "ifTestEntry": {
        "name": "ifTestEntry",
        "oid": "1.3.6.1.2.1.31.1.3.1",
        "nodetype": "row",
        "class": "objecttype",
        "maxaccess": "not-accessible",
        "augmention": {
          "name": "ifTestEntry",
          "module": "IF-MIB",
          "object": "ifEntry"
        }
      },
      "ifTestId": {
        "name": "ifTestId",
        "oid": "1.3.6.1.2.1.31.1.3.1.1",
        "nodetype": "column",
        "class": "objecttype",
        "syntax": {
          "type": "TestAndIncr",
          "class": "type"
        },
        "maxaccess": "read-write"
      },
      // ...
   }

In general, converted MIBs capture all aspects of original (ASN.1) MIB contents and layout. The snippet above is just a partial example, but here is the complete IF-MIB.json file.

Besides one-to-one MIB conversion, PySMI library can produce JSON index to facilitate fast MIB information lookup across large collection of MIB files.

For example, JSON index for IP-MIB.json, TCP-MIB.json and UDP-MIB.json modules would keep information like this:

   {
      "compliance": {
         "1.3.6.1.2.1.48.2.1.1": [
           "IP-MIB"
         ],
         "1.3.6.1.2.1.49.2.1.1": [
           "TCP-MIB"
         ],
         "1.3.6.1.2.1.50.2.1.1": [
           "UDP-MIB"
         ]
      },
      "identity": {
          "1.3.6.1.2.1.48": [
            "IP-MIB"
          ],
          "1.3.6.1.2.1.49": [
            "TCP-MIB"
          ],
          "1.3.6.1.2.1.50": [
            "UDP-MIB"
          ]
      },
      "oids": {
          "1.3.6.1.2.1.4": [
            "IP-MIB"
          ],
          "1.3.6.1.2.1.5": [
            "IP-MIB"
          ],
          "1.3.6.1.2.1.6": [
            "TCP-MIB"
          ],
          "1.3.6.1.2.1.7": [
            "UDP-MIB"
          ],
          "1.3.6.1.2.1.49": [
            "TCP-MIB"
          ],
          "1.3.6.1.2.1.50": [
            "UDP-MIB"
          ]
      }
   }

With this example, compliance and identity keys point to MODULE-COMPLIANCE and MODULE-IDENTITY MIB objects, oids list top-level OIDs branches defined in MIB modules. Full index build over thousands of MIBs could be seen here.

The PySMI library can automatically fetch required MIBs from HTTP sites or local directories. You could configure any MIB source available to you (including https://mibs.pysnmp.com/asn1/) for that purpose.

How to get PySMI

The pysmi package is distributed under terms and conditions of 2-clause BSD license. Source code is freely available as a GitHub repo.

You could pip install pysmi-lextudio or download it from PyPI.

If something does not work as expected, open an issue at GitHub or post your question on Stack Overflow.

Copyright (c) 2015-2020, Ilya Etingof. Copyright (c) 2022-2024, LeXtudio Inc.. All rights reserved.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysmi_lextudio-1.4.3.tar.gz (108.7 kB view details)

Uploaded Source

Built Distribution

pysmi_lextudio-1.4.3-py3-none-any.whl (83.7 kB view details)

Uploaded Python 3

File details

Details for the file pysmi_lextudio-1.4.3.tar.gz.

File metadata

  • Download URL: pysmi_lextudio-1.4.3.tar.gz
  • Upload date:
  • Size: 108.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.0 Darwin/23.4.0

File hashes

Hashes for pysmi_lextudio-1.4.3.tar.gz
Algorithm Hash digest
SHA256 7d255fb38669410835acf6c2e8ab41975a6d8e64593b119552e36ecba004054f
MD5 64c721cfe25497a60b252c2f554700c0
BLAKE2b-256 c80cbec628167236bfea4bdf780f573f9c16f8977d1fe1e9123100abb1e7b683

See more details on using hashes here.

File details

Details for the file pysmi_lextudio-1.4.3-py3-none-any.whl.

File metadata

  • Download URL: pysmi_lextudio-1.4.3-py3-none-any.whl
  • Upload date:
  • Size: 83.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.0 Darwin/23.4.0

File hashes

Hashes for pysmi_lextudio-1.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cb629c6386a30c976f83c29fc71e53b06d60f15094d0c0114cf8d095351b76e5
MD5 4f2160670e62fc5a1dc2d5c5eed2bbb5
BLAKE2b-256 0ef48a64590456991348c99b526aec421ced5d0b4e7c1f05baf02a8338be4464

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page