APIs to create MIB-aware retriever classes for asynchronous SNMP polling.
libsmi provides a command line tool (smidump) which can parse MIB definitions and dump them as Python data structures.
To create a new MIB-aware retriever class, inherit from the MibRetriever class and set the class-variable “mib” to point to a MIB data structure as dumped by libsmi’s smidump command.
The class will be imbued with knowledge of the MIB in question, and several convenience methods to work with data retrieval. An instance of a MibRetriever class is tied to a TwistedSNMP AgentProxy and uses this to allow asynchronous data retrieval.
nav.mibs.mibretriever.
MIBObject
(mib, name)¶Bases: object
Representation of a MIB object.
Member attributes:
to_python
(value)¶Translate an SNMP value into something python-like.
If the syntax of this object is an Enumeration, value will be translated from and int to a str object. If it is an SNMPv2-TC::TruthValue, it will be translated from int to bool.
nav.mibs.mibretriever.
MibRetriever
(agent_proxy)¶Bases: object
Base class for functioning MIB retriever classes.
get_module_name
()¶Returns the MIB module
get_next
(**kwargs)¶Gets next sub-object of the named object
retrieve_column
(column_name)¶Retrieve the contents of a single MIB table column.
Returns a deferred whose result is a dictionary:
{ row_index: column_value }
retrieve_column_by_index
(**kwargs)¶Retrieves the value of a specific column for a given row index
retrieve_columns
(column_names)¶Retrieve a set of table columns.
The table columns may come from different tables, as long as the table rows are indexed the same way.
Returns a deferred whose result is a dictionary:
{ row_index: MibTableResultRow instance }
retrieve_table
(table_name)¶Table retriever and formatter.
Retrieves an entire MIB table. Returns a deferred whose result is a dictionary:
{ row_index: MibTableResultRow instance }
Each dictionary key is a row index (an oid suffix tuple). Each dictionary value is a MibTableResultRow instance, which can be accessed as both a dictionary and a list.
translate_result
(result)¶Translate result values to pythonic values according to object syntax.
Given a table result from one of this object’s retrievers, every column object will have it’s to_python translation rules applied. This is useful to insert into a callback chain for result formatting.
nav.mibs.mibretriever.
MibRetrieverError
¶Bases: nav.errors.GeneralException
MIB retriever error
nav.mibs.mibretriever.
MibRetrieverMaker
(name, bases, dct)¶Bases: type
Metaclass to create new functional MIB retriever classes.
The MibRetriever base class uses this as its metaclass. All new MIB retrievers should inherit inherit directly from the MibRetriever class.
nav.mibs.mibretriever.
MibTableDescriptor
(table_object, row_object, column_objects)¶Bases: object
Description of a MIB table structure.
build
(mib, table_name)¶Build and return a MibTableDescriptor for a MIB table.
mib – a MibRetriever instance. table_name – the name of the table from the mib.
build_all
(mib)¶Build table descriptors for all tables in a mib.
mib – MibRetriever instance
nav.mibs.mibretriever.
MibTableResultRow
(index, columns=None)¶Bases: dict
A result row from a MIB table.
Acts as a dictionary. The row index is available through the integer key 0, or as the member attribute ‘index’.
nav.mibs.mibretriever.
MultiMibMixIn
(agent_proxy, instances)¶Bases: nav.mibs.mibretriever.MibRetriever
Queries and chains the results of multiple MIB instances using community indexing.
Useful for Cisco devices, whose SNMP agents employ multiple BRIDGE-MIB instances, one for each active VLAN, each indexable via a modified SNMP community.
Add the mixin to the list of base classes of a MibRetriever descendant class, and override any querying method that should work across multiple instances. The overriden method should use a call to self._multiquery().
nav.mibs.mibretriever.
convert_oids
(mib)¶Convert a mib data structure’s oid strings to OID objects.
mib is expected to be a data structure as dumped by the smidump utility (using the -python option).