From 3760e7b6388a95c01c70292259759f75ef767a6d Mon Sep 17 00:00:00 2001 From: "Mike C. Fletcher" Date: Sat, 13 Jan 2018 13:09:10 -0500 Subject: Some documentation clarifications (#125) * Doc Update: in resolveWithMib docstring, document getting controller * Expand on the "use mibbuilder" comment as to *how* to use it Basically how to make the modules you compile with mibbuilder available to your application via MibBuilder settings * Add a note explaining that "ASN.1 MIB" means the textual format Users of the library seeing "ASN.1" may assume (as I did) that the meaning is "ASN.1 encoded binary version of the MIB" (i.e. a precompiled version of the MIB in compact internal format). * Describe how to configure all OIDs to use the ASN.1 mib directories --- docs/source/docs/pysnmp-hlapi-tutorial.rst | 7 +++++++ docs/source/faq/pass-custom-mib-to-manager.rst | 29 +++++++++++++++++++++++++- pysnmp/smi/rfc1902.py | 2 ++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/docs/source/docs/pysnmp-hlapi-tutorial.rst b/docs/source/docs/pysnmp-hlapi-tutorial.rst index 54bb6e5e..60814578 100644 --- a/docs/source/docs/pysnmp-hlapi-tutorial.rst +++ b/docs/source/docs/pysnmp-hlapi-tutorial.rst @@ -247,6 +247,13 @@ in the examples. We maintain a `collection `_ of ASN.1 MIB modules that you can use in your SNMP projects. +.. note:: + + An "ASN.1 MIB" is a plain-text description of identifiers and + types. It is the common format that is distributed by manufacturers + to describe their SNMP services, and is the same format used by + Perl's Net::SNMP and almost all SNMP tools. + Reading scalar value -------------------- diff --git a/docs/source/faq/pass-custom-mib-to-manager.rst b/docs/source/faq/pass-custom-mib-to-manager.rst index a83e9307..51c59ba6 100644 --- a/docs/source/faq/pass-custom-mib-to-manager.rst +++ b/docs/source/faq/pass-custom-mib-to-manager.rst @@ -21,9 +21,36 @@ A. Starting from PySNMP 4.3.x, plain-text (ASN.1) MIBs can be :start-after: """# :language: python +.. code: + :language: python + + # Configure the SNMP engine with access to the + # common Linux ASN.1 (Textual) MIB directories... + from pysnmp import hlapi + from pysnmp.smi import compiler + engine = hlapi.Engine() + builder = engine.getMibBuilder() + compiler.addMibCompiler(builder, sources=[ + '/usr/share/snmp/mibs', + os.path.expanduser('~/.snmp/mibs'), + 'http://mibs.snmplabs.com/asn1/@mib@', + ]) + :download:`Download` script. Alternatively, you can invoke the `mibdump.py `_ (shipped with PySMI) by hand and this way compile plain-text MIB -into PySNMP format. +into PySNMP format. Once the compiled MIBs are stored in a directory, +add the directory to your MibBuilder's MibSources. + +.. code:: + :language: python + + builder = engine.getMibBuilder() + # Make ./mibs available to all OIDs that are created + # e.g. with "MIB-NAME-MIB::identifier" + builder.addMibSources(builder_module.DirMibSource( + os.path.join( HERE, 'mibs') + )) + diff --git a/pysnmp/smi/rfc1902.py b/pysnmp/smi/rfc1902.py index 13a9b486..07cea1e5 100644 --- a/pysnmp/smi/rfc1902.py +++ b/pysnmp/smi/rfc1902.py @@ -831,6 +831,8 @@ class ObjectType(object): Examples -------- + >>> from pysmi.hlapi import varbinds + >>> mibViewController = varbinds.AbstractVarBinds.getMibViewController( engine ) >>> objectType = ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr'), 'Linux i386') >>> objectType.resolveWithMib(mibViewController) ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr'), DisplayString('Linux i386')) -- cgit v1.2.1