MIB retrievers
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.
- class nav.mibs.mibretriever.MIBObject(mib, name)
Bases:
object
Representation of a MIB object.
Member attributes:
- module
The name of the MIB module where the object originated.
- name
The object’s textual name.
- oid
The full object identifier
- enum
If the object’s syntax indicates it is an enumerated value, this dictionary will hold mappings between the enumerations textual names and integer values. As a simplifying case, SNMPv2-TC::TruthValues will be deciphered as enums of boolean values.
- __init__(mib, name)
- 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.
- class nav.mibs.mibretriever.MibRetriever(agent_proxy)
Bases:
object
Base class for functioning MIB retriever classes.
- __init__(agent_proxy)
Create a new instance tied to an AgentProxy instance.
- get_module_name()
Returns the MIB module
- get_next(object_name, translate_result=False)
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(column, index)
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.
- classmethod 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.
- exception nav.mibs.mibretriever.MibRetrieverError
Bases:
GeneralException
MIB retriever error
- class 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.
- __init__(name, bases, dct)
- class nav.mibs.mibretriever.MibTableDescriptor(table_object, row_object, column_objects)
Bases:
object
Description of a MIB table structure.
- __init__(table_object, row_object, column_objects)
- classmethod 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.
- classmethod build_all(mib)
Build table descriptors for all tables in a mib.
mib – MibRetriever instance
- class 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’.
- __init__(index, columns=None)
Initialize with the row index of this row.
- Parameters:
index – index OID
columns – optional list of column names to pre-allocate with None values.
- class nav.mibs.mibretriever.MultiMibMixIn(agent_proxy, instances)
Bases:
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().
- __init__(agent_proxy, instances)
Initializes a MultiBridgeQuery to perform SNMP requests on multiple BRIDGE-MIB instances on the same host/IP.
- Parameters:
agent_proxy – The base AgentProxy to use for communication. An AgentProxy for each additional BRIDGE-MIB instance will be created based on the properties of this one.
instances – A sequence of tuples describing the MIB instances to query, like [(description, community), …], where description is any object that can be used to identify an instance, and community is the alternate MIB instance’s SNMP read-community.
- nav.mibs.mibretriever.is_text_object(mib_dict, obj_name)
Verifies whether a given MIB object has a syntax that can be considered a text type.