We have mastered the requesting of single item in our get example.
But SNMP allows to query multiple keys in single request. Let's consider
the example.
First, we need to create SnmpSession object which wraps the client's session.
The SnmpSession may be used as an instance directly or operated as async context manager
with the async with clause. When used as a context manager,
the client automatically closes all connections on the exit of context,
so its lifetime is defined explicitly.
SnmpSession constructor offers lots of configuration variables for fine-tuning. Refer to the
SnmpSession reference
for further details. In our example, we set the agent's address and SNMP community
to the given values.
We use SnmpSession.get_many() function to query multiple OIDs. The function is asynchronous and
must be awaited. See SnmpSession.get() reference for further details.
get_many() returns a dict, where keys are the requested OIDs, and values are the query results.
Note
get_many() ignores non-existent OIDs, so it is up to the application to check
the resulting dict for missed keys.
Let's run our asynchronous main() function via asyncio.run
and pass first command-line parameters as address, community and OIDs.
We use the rest of command line as the list of OIDs to query.
$ python3 examples/aio/getmany.py 127.0.0.1 public 1.3.6.1.2.1.1.6.0 1.3.6.1.2.1.1.4.0
1.3.6.1.2.1.1.6.0: Gufo SNMP Test
1.3.6.1.2.1.1.4.0: test <me@example.com>