pysnmp command responder - Handle get/set requests with external data (not mib)

733 views Asked by At

I want develop a SNMP agent for get/set requests that "talks" with a complex python program using a protocol.

It's quite difficult to explain, so I try to make an example:

SNMP receives a get request for param x It asks to my program the current value of x It sends the answer to client

I'd like a hint about how to "intercept" the get/set request in a single method where I can make the decodeMsg-sendToPython-receiveFromPython-encodeMsg-sendToClient process.

1

There are 1 answers

1
Ilya Etingof On BEST ANSWER

Various designs of such application is possible with pysnmp, all are based on CommandResponder class. Perhaps the most straightforward approach would be to create your own MibInstrumentationController class that will receive GET/SET/GETNEXT queries synchronously and is expected to return response variable-bindings:

class EchoMibInstrumController(instrum.AbstractMibInstrumController):
    def readVars(self, vars, acInfo=(None, None)):
        return vars
    def readNextVars(self, vars, acInfo=(None, None)):
        return vars
    def writeVars(self, vars, acInfo=(None, None)):
        return vars

Another solution would be to compile your MIB into pysnmp format (with the PySMI compiler) and specialize MIB variables (AKA Managed Objects Instances) so that they would talk to your backend data store (program) via some protocol.

However, both approaches work synchronously meaning you would block SNMP engine till you retrieve data from your backend and return from your request processing function. If you expect highly concurrent load and/or slow data store, you may have to use lower level API of CommandResponder class which runs asynchronously.

It is also possible to tap on SNMP engine workflow via a collection of hooks placed at strategic locations of SNMP message processing code. But that feature is mostly aimed at getting very specific data from SNMP engine internals, not guiding its operations.