Issue
I would like to use PySNMP as agent under Python 3.x with asyncio. Manager requests value, it takes time to get response from attached device (think Modbus). So in response to Manager, I would like to use somehing like this in my MibScalarInstance:
def getValue(self, name, idx):
result = await func_to_get_value(name, idx)
return result
Of course, that is not going to work, as getValue is not async.
What is the correct asyncio approach?
Solution
Unfortunately, currently released pysnmp does not support any asynchronous operations on the SMI/MIB side. So, the only solution I can think of is to inherit from and override [CommandResponder.handleMgmtOperation](https://github.com/etingof/pysnmp/blob/release-4.4.13/pysnmp/entity/rfc3413/cmdrsp.py#L255, then yield from there if readVars
-like function is going to be slow.
However, the next (yet, unreleased) pysnmp 5 (GitHub master) does support async SMI objects. Although asyncio binding is not yet coded into SMI objects yet, but that should not stop you from yielding I think.
Considering the lack of documentation, here is a Jinja template that can produce pysnmp5 MIB instance classes from a SNMP MIB. Manually created code (for pysnmp 5) could look similarly, but it can yield from any of the stub methods.
There is also a larger effort of making a generic and extendable SNMP command responder. It should work as well, though it definitely needs more time and love.
Answered By - Ilya Etingof
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.