pythonsnmppysnmp

pysnmp Command Responder - handling managed objects value classes


I'm developing a command responder with pysnmp, based on its docs.

My intention is to answer to the get message of my managed objects by reading the snmp data from a text file (updated over time).

I'm polling the responder using snmpB, drawing a graph of the polled object value evolution.

I've successfully modify the example exporting my first Managed Object, adding it with mibBuilder.exportSymbols() and retrieving the values from the txt file in the modified getvalue method. I'm able to poll this object with success. It's a Counter32 type object.

The next step is handle other objects with a value type different from the "supported" classes like Integer32, Counter32, OctetString

I need to handle floating point values or other specific data formats defined within MIB files, because snmpB expect these specific formats for correctly plotting the graph. Unfortunetely I can't figure out a way to do this.

Hope someone can help,

Mark

EDIT 1

The textual-convention I need to implement is the Float32TC defined in FLOAT-TC-MIB from RFC6340:

Float32TC ::= TEXTUAL-CONVENTION
      STATUS       current
      DESCRIPTION  "This type represents a 32-bit (4-octet) IEEE
                    floating-point number in binary interchange format."
      REFERENCE    "IEEE Standard for Floating-Point Arithmetic,
                    Standard 754-2008"
      SYNTAX       OCTET STRING (SIZE(4))

Solution

  • There is no native floating point type in SNMP, and you can't add radically new types to the protocol. But you can put additional constraints on existing types or modify value representation via TEXTUAL-CONVENTION.

    To represent floating point numbers you have two options:

    Whatever values are defined in MIB, they always base on some built-in SNMP type.

    You could automatically generate pysnmp MibScalar classes from your ASN.1 MIB with pysmi tool, then you could manually add MibScalarInstance classes with some system-specific code thus linking pysnmp to your data sources (like text files).