Packaged MIBsΒΆ

SNMP command responder discovers pip-installed packages extending the snmpresponder.mibs entry point.

The main advantage of packaged MIBs is easier distribution. That might make more sense for generally useful and reusable MIB implementations such as HOST-RESOURCES-MIB.

This example configuration includes example Python package, which could be used as a blueprint for packaging other MIB implementations.

You could test this configuration by running the following command (you may need to have COFFEE-POT-MIB installed locally):

$ snmpget -v2c -c public 127.0.0.1:1161 COFFEE-POT-MIB::potName.0

SNMP Command Responder is configured to:

  • listen on UDP socket at localhost
  • form a MIB tree out of all objects imported from the examples extension point (provided by installed snmpresponder-mibs-examples package)
  • respond to SNMPv2c queries
  • serve all queries against the configured MIB tree
#
# SNMP Command Responder configuration file
#

config-version: 1
program-name: snmpresponder

snmp-credentials-group {
  snmp-transport-domain: 1.3.6.1.6.1.1.100
  snmp-bind-address: 127.0.0.1:1161

  snmp-engine-id: 0x0102030405070809

  snmp-community-name: public
  snmp-security-name: public
  snmp-security-model: 2
  snmp-security-level: 1

  snmp-credentials-id: snmp-credentials
}

context-group {
  snmp-context-engine-id-pattern: .*?
  snmp-context-name-pattern: .*?

  snmp-context-id: any-context
}

content-group {
  snmp-pdu-type-pattern: .*?
  snmp-pdu-oid-prefix-pattern-list: .*?

  snmp-content-id: any-content
}

peers-group {
  snmp-transport-domain: 1.3.6.1.6.1.1.100
  snmp-bind-address-pattern-list: .*?
  snmp-peer-address-pattern-list: .*?

  snmp-peer-id: 100
}

managed-objects-group {
  mib-text-search-path-list: http://mibs.snmplabs.com/asn1/

  # List of Python packages to import in the MIB builder context
  mib-code-packages-pattern-list: examples\..*

  mib-tree-id: managed-objects-1
}

routing-map {
  matching-snmp-context-id-list: any-context
  matching-snmp-content-id-list: any-content

  matching-snmp-credentials-id-list: snmp-credentials
  matching-snmp-peer-id-list: 100

  using-mib-tree-id: managed-objects-1
}

Download configuration file.

The only implemented, read-only managed object is COFFEE-POT-MIB::potName.0:

  • serves a static value for COFFEE-POT-MIB::potName.0 object
  • only SNMP read operations are implemented
  • write operation are allowed, but has no effect
"""SNMP MIB module (COFFEE-POT-MIB) expressed in pysnmp data model.

This Python module is designed to be imported and executed by the
pysnmp library.

See http://snmplabs.com/pysnmp for further information.

Notes
-----
ASN.1 source http://mibs.snmplabs.com:80/asn1/COFFEE-POT-MIB
Produced by pysmi-0.4.0 at Sat Jan 12 14:01:57 2019
On host igarlic platform Darwin version 17.7.0 by user ilya
Using Python version 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13)
"""
if 'mibBuilder' not in globals():
    import sys

    sys.stderr.write(__doc__)
    sys.exit(1)


mibBuilder = globals()['mibBuilder']

MibScalarInstance, = mibBuilder.importSymbols(
    'SNMPv2-SMI',
    'MibScalarInstance'
)

# Import Managed Objects to base Managed Objects Instances on

potName, = mibBuilder.importSymbols(
    "COFFEE-POT-MIB",
    "potName"
)


# MIB Managed Objects in the order of their OIDs

class PotnameObjectInstance(MibScalarInstance):
    """Scalar Managed Object Instance with MIB instrumentation hooks.

    User can override none, some or all of the method below interfacing
    them to the data source they want to manage through SNMP.
    Non-overridden methods could just be removed from this class.

    See the SMI data model documentation at `http://snmplabs.com/pysnmp`.
    """
    def readTest(self, varBind, **context):
        cbFun = context['cbFun']
        cbFun(varBind, **context)

    def readGet(self, varBind, **context):
        name, value = varBind

        cbFun = context['cbFun']
        value = self.syntax.clone('mypot')
        cbFun((name, value), **context)

    def readTestNext(self, varBind, **context):
        name, value = varBind

        if name >= self.name:
            MibScalarInstance.readTestNext(self, varBind, **context)

        else:
            cbFun = context['cbFun']
            cbFun((self.name, value), **context)

    def readGetNext(self, varBind, **context):
        name, value = varBind

        if name >= self.name:
            MibScalarInstance.readGetNext(self, varBind, **context)

        else:
            value = self.syntax.clone('mypot')

            cbFun = context['cbFun']
            cbFun((self.name, value), **context)


_potName = PotnameObjectInstance(
     potName.name,
     (0,),
     potName.syntax
)

# Export Managed Objects Instances to the MIB builder

mibBuilder.exportSymbols(
    "__COFFEE-POT-MIB",
    **{"potName": _potName}
)

Download MIB implementation.

For more information on MIB implementation refer to the MIB implementation chapter in the documentation.