SNMPv3 Engine ID Discovery¶
SNMP v3 introduces the concept of the Engine ID, a unique identifier for each SNMP agent in the network.
Gufo SNMP automatically performs Engine ID discovery as needed. However, you can retrieve the actual value for various purposes, such as inventory management or performance optimization, and use it to skip the discovery step later.
Let's see the details.
Gufo SNMP is an async library. In our case
we should run the client from our synchronous script,
so we need to import
asyncio to use
sys module to parse the CLI argument.
sys.argv only for demonstration purposes. Use
argsparse or alternatives
in real-world applications.
SnmpSession object holds all necessary API, so import it from
For SNMPv3 we also need an
Asynchronous code must be executed in the asynchronous functions or coroutines.
So we define our function as
async. We expect the following arguments:
- Address of the agent.
- Valid user name.
First, we need to create
SnmpSession object which wraps the client's session.
SnmpSession may be used as an instance directly or operated as async context manager
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
for further details. In our example, we set the agent's address and create
SNMPv3 user with default settings.
To perform Engine ID discovery, the only mandatory parameter is the username. Authentication and privacy settings can be left at their default values.
SnmpSession.get_engine_id() returns discovered Engine Id as bytes.
Lets run our asynchronous
main() function via
and pass first command-line parameters as address, community, and OID.
Let's check our script. Run example as: