Skip to content

astralblue/pysmi

 
 

Repository files navigation

SNMP MIB parser

PyPI Python Versions Build status Coverage Status GitHub license

This is a pure-Python implementation of SNMP SMI MIB parser. This software is designed to accommodate multiple code generation backends in hope that they could be useful for SNMP MIB format conversions.

As of this moment, the only code generation backend currently implemented is for pysnmp MIB modules generation.

Download

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

Installation

Download pysmi from PyPI or just run:

$ pip install pysmi

How to use pysmi

If you are using pysnmp, you might never notice pysmi presense - pysnmp will call it for MIB download and compilation automatically.

If you want to compile ASN.1 MIB into PySNMP module by hand, use mibdump.py tool like this:

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

You can also turn ASN.1 MIB into a general purpose JSON document:

$ mibdump.py --generate-mib-texts  --destination-format json IF-MIB
Source MIB repositories: file:///usr/share/snmp/mibs, http://mibs.snmplabs.com/asn1/@mib@
Borrow missing/failed MIBs from: http://mibs.snmplabs.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
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: 

Here you could see example JSON documents generated by pysmi from A3COM-HUAWEI-3GMODEM-MIB ASN.1 source with and without human-oriented text data.

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

Documentation

Detailed information on pysmi library interfaces be found at pysmi site.

Feedback

I'm interested in bug reports and fixes, suggestions and improvements. Your pull requests are very welcome as well!

Copyright (c) 2005-2016, Ilya Etingof. All rights reserved.

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%