pysnmp.sourceforge.net
HOME QUICK START DOCUMENTATION EXAMPLES DOWNLOAD
DEVELOPMENT | CONTACT |

MIB services

MIB builder
MIB View Controller
Management Instrumentation
Miscellaneous

See also

MIB variable

WARNING: you are reading historical documentation! Please, refer here.

Data model for Managed Objects

PySNMP supports both Manager and Agent-side operations on Managed Objects, including MIB lookup and custom Managed Objects implementation.

Managed Objects, implemented in Python code, is the basis for PySNMP MIB services. Managed Objects are collected into a pool and then managed by a MIB builder. Both Manager and Agent applications deal with their Managed Objects through role-specific MIB view and MIB instrumentation. The same set of Managed Objects could serve both Manager and Agent purposes within a single SNMP entity.

In PySNMP, Managed Objects specified in MIBs take shape of Python objects that implement various kinds of SMIv2 definitions. Managed Objects specified in a MIB file translate in a one-to-one fashion into Python modules.

Automated conversion of MIB text files into Python modules can be done through the use of smidump tool of libsmi package and "build-pysnmp-mib" script shipped with PySNMP.

The pysnmp.smi.mibs.SNMPv2-SMI module implements the following classes:

class MibScalar( name, syntax )

A representation of a scalar Managed Object specification identified by name with associated value of type syntax. Objects of this kind never hold actual values, rather they serve the following purposes:

  • Logically bind Managed Object Name with Value
  • Specify value type (including TEXTUAL-CONVENTION-based constraints)
  • Provide human-friendly Managed Object name and value representation

The name parameter represents an Object Identifier which can be expressed as either a tuple of integers or tuple-like Object Identifier class instance.

The syntax parameter represents Managed Object Instance value type.

The MibScalar class implements the following methods:

getName()

Return the name initializer an OctetIdentifier object.

getSyntax()

Return the syntax initializer which is a PyASN1 object including its TEXTUAL-CONVENTION derivative. The syntax object does not carry any value, it denotes an acceptable type specifier and may be used for cloning compliant objects for building SNMP messages or pretty printing concrete values.

getUnits()

Return value units in form of a Python string. This is mostly used for pretty printing things like "10 seconds", not just "10".

getDescription()

Return a textual, human-readable description of the Managed Object semantics, meaning, uses and restrictions. Since these descriptions may be quite large, they are not loaded into memory by default. This setting can be altered through a property of MibBuilder.

class MibScalarInstance( name, syntax )

A representation of scalar Managed Object Instance or Conceptual Table element with name and associated value carried by the syntax object. This class is a subclass of MibScalar but, unlike MibScalar, it represents existing Managed Object holding a value.

The name of Managed Object Instance is a concatination of name of a Managed Object and instance identifier. For scalar Managed Objects, instance identifier is always a single zero (0,). For Conceptual Table elements instance identifier is a concatination of table indices.

The name and syntax parameters have the same meaning as in MibScalar class.

class MibTableColumn( name, syntax )

A representation of Conceptual Table Column specification with name and associated value of type syntax. This class is a subclass of MibScalar.

The name parameter has the same meaning as in MibScalar class.

The syntax parameter represents type of the value associated with columnar Managed Object.

The MibTableColumn class implements the following methods:

setProtoInstance( instanceClass )

Configure MibTableColumn object to instantiate instanceClass when creating Columnar Objects. By default, MibScalarInstance is instantiated.

class MibTableRow( name )

A representation of a Conceptual Table Row specification with name. This class is a subclass of MibScalar although it can't have any associated value.

The name parameter has the same meaning as in MibScalar class.

The MibTableRow class implements the following methods:

getInstIdFromIndices( *indices )

Compute and return Conceptual Table Column instance identifier from *indices using MIB Table Index definition.

Types of *indices must coerce into Table Index syntax.

getIndicesFromInstId( instanceId )

Compute and return a tuple of Conceptual Table Index values from Column instance identifier instanceId using MIB Table Index definition.

The number of types of returned index values depend on MIB Table definition.

class MibTable( name )

Represents Conceptual Table specification with name. This class is a subclass of MibScalar although it can't have any associated value.

The name parameter has the same meaning as in MibScalar class.

The following examples explain how MIB text could be expressed in terms of PySNMP SMI data model. First example is on a scalar:

myManagedObject = MibScalar((1, 3, 6, 1, 4, 1, 20408, 2, 1),
                            OctetString()).setMaxAccess("readonly")

Managed Object Instance can be put into a stand-alone PySNMP SMI module or be implemented inside Agent application. Managed Object Instance will be associated with its parent Managed Object, by the MIB building part of PySNMP, on the basis of their names relation.

myManagedObjectInstance = MibScalarInstance(myManagedObject.getName() + (0,), 
    myManagedObject.getSyntax().clone('my string'))

Let's consider SNMP Conceptual Table created in an "MY-MIB.py" file:

myTable = MibTable((1, 3, 6, 1, 4, 1, 20408, 2, 1))
myTableEntry = MibTableRow(myTable.getName() + (1,)).setIndexNames(
                   (0, "MY-MIB", "myTableIndex")
               )
myTableIndex = MibTableColumn(myTableEntry.getName() + (1,), Integer())
myTableValue = MibTableColumn(myTableEntry.getName() + (2,), OctetString())

Populate Managed Objects table with Managed Objects Instance in the first column.

myTableValueInstance = MibScalarInstance(myTableValue.getName() + (1,), 
    myTableValue.getSyntax().clone('my value'))

For more real-life cases, refer to modules in pysnmp.smi.mibs sub-package.


Need help? Try PySNMP mailing lists or report to library maintainers.
SourceForge Logo