# imports asyncio for asynchronous programming
import asyncio
# relevant components from pysnmp.hlapi.v3arch.asyncio for SNMP communication.
from pysnmp.hlapi.v3arch.asyncio import *
# run is defined as an async function, allowing it to execute asynchronously with asyncio.
async def run():
snmpEngine = SnmpEngine() # Initializes the SNMP engine that handles SNMP operations.
# get_cmd is used to initiate an SNMP GET request. It asks the SNMP agent for the value of a specific object.
iterator = get_cmd(
snmpEngine,
CommunityData("public", mpModel = 0),
# Specifies the target SNMP agent and its IP address/hostname (demo.pysnmp.com) and port (161, which is the default SNMP port).
await UdpTransportTarget.create(("192.168.1.60",161)),
ContextData(),
ObjectType(ObjectIdentity("SNMPv2-MIB", "lldpLocChassisId", 0))
)
#The await iterator sends the GET request asynchronously and retrieves the result, which includes any error indication or the value of the requested object.
errorIndication, errorStatus, errorIndex, varBinds = await iterator
if errorIndication:
print(errorIndication)
elif errorStatus:
print(
"{} at {}".format(
errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or "?",
)
)
else:
# If the request is successful, it loops over varBinds (the response from the SNMP agent), and prints the object and its value in a readable format.
for varBind in varBinds:
print(" = ".join([x.prettyPrint() for x in varBind]))
# snmpEngine.close_dispatcher() ensures the SNMP engine is properly closed after the operation.
snmpEngine.close_dispatcher()
#This executes the asynchronous run() function.
asyncio.run(run())
Do you see a error? What exactly are you asking for help with?
Share the error you see please.
raise error.SmiError(f"No symbol {modName}::{symName} at {self}")
pysnmp.smi.error.SmiError: No symbol SNMPv2-MIB::lldpLocChassisId at <pysnmp.smi.builder.MibBuilder object at 0x000001E34B8DBEE0>
The device with the IP address 192.168.1.60 is SNMP and LLDP enabled, and I want to retrieve LLDP data for this IP. Could you please help me with this issue?
Sorry no I do not the answer, but you have now provided info that someone else hopefully might help.
However as this is about snmp you might need to ask the community around pysnmp for help.
FYI the pysnmp docs have a section on support options.