In our previous examples we have relied on existing
and running SNMP agent. But Gufo SNMP offers the useful
Snmpd wrapper to configure and run the local instance
of the snmpd which can be started and terminated
along your application.
Note
This feature in requires an installed Net-SNMP package.
Refer to your operation system's manuals for details.
Asynchronous code must be executed in the asynchronous functions or coroutines.
So we define our function as async. Unlike our get, getmany,
and getnext examples we do not expect any external arguments.
We need to create Snmpd context to run local snmpd instance.
Then we need to create SnmpSession object which wraps the client's session.
Both context manager is asyncronous and can be used within single async with
clause. Refer to the get, getmany,
and getnext examples for additional details.
Both Snmpd and SnmpSession are highly configurable, so refer to the
Snmpd and
SnmpSession
references.
We use SnmpSession.getnext() function to iterate within base OID. The function is an asynchronous
iterator returning pairs of (OID, value), so we use async for construction to iterate over the values.
See SnmpSession.getnext() reference
for further details.