hh-h / aiosnmp Goto Github PK
View Code? Open in Web Editor NEWaiosnmp is an asynchronous SNMP client and trap server for use with asyncio.
License: MIT License
aiosnmp is an asynchronous SNMP client and trap server for use with asyncio.
License: MIT License
Hello,
We are looking to implement aiosnmp in our project and would like to know if you had any timeline estimation for SNMP v3 support?
Thank you for your time.
Hello,
Thanks for this awesome library. I have an issue on windows 10. It seems that the simple example fails with aiosnmp.exceptions.SnmpTimeoutError . This seems to be an OS specific issue. On ubuntu or any other linux I cannot seem to reproduce.
I spinned up a Wireshark and checked the packets. The communication seems fine. The problem from what I can tell comes from aiosnmp\protocols.py line 142. It seems that the future remains in PENDING state even though the response is received. Couldn't figure it out why. Let me know if you need any other info.
Cheers,
C
async def walk_snmp(self, ip, oid):
"""
request snmp
:param ip:
:param oid:
:return:
"""
items = []
try:
async with aiosnmp.Snmp(
host=ip,
community='xxx',
version=aiosnmp.message.SnmpVersion.v2c,
timeout=self.snmp_timeout,
retries=self.snmp_retry
) as snmp:
items = await snmp.bulk_walk(oid)
except (SnmpTimeoutError, TimeoutError):
self.redis_cli.hset('timeout', f'{ip}-{oid}', 'timeout')
return
except Exception as err:
self.redis_cli.hset('error', f'{ip}-{oid}', str(err))
return
Not an issue, but a feature request.
is it possible to implement support for snmptable?
In production we run asyncio with a custom loop exception handler (https://docs.python.org/3/library/asyncio-eventloop.html#error-handling-api) that causes the process to completely abort for reliability when an unhandled exception occurs.
When an undecodable message is received (we have an item of equipment that sometimes cannot correctly format an Object Identifier(!)), an exception (eg "ASN1 syntax error") is raised from asn1 and never handled - thus the loop exception handler will be called.
Here's the traceback we log:
ERROR Unhandled exception in loop - aborting
ERROR Exception in callback _SelectorDatagramTransport._read_ready()
handle: <Handle _SelectorDatagramTransport._read_ready()>
Traceback (most recent call last):
File "/usr/lib/python3.7/asyncio/events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "/usr/lib/python3.7/asyncio/selector_events.py", line 962, in _read_ready
self._protocol.datagram_received(data, addr)
File "/usr/local/lib/python3.7/dist-packages/aiosnmp/protocols.py", line 95, in datagram_received
message = SnmpResponse.decode(data)
File "/usr/local/lib/python3.7/dist-packages/aiosnmp/message.py", line 178, in decode
_, value = decoder.read()
File "/usr/local/lib/python3.7/dist-packages/aiosnmp/asn1.py", line 380, in read
value = self._read_value(nr, length)
File "/usr/local/lib/python3.7/dist-packages/aiosnmp/asn1.py", line 473, in _read_value
return self._decode_object_identifier(bytes_data)
File "/usr/local/lib/python3.7/dist-packages/aiosnmp/asn1.py", line 561, in _decode_object_identifier
raise Error("ASN1 syntax error")
aiosnmp.asn1.Error: ASN1 syntax error
Because this is corrupt data from a remote system, I think it should not cause an exception to be raised all the way to the loop, instead the data should be dropped, perhaps logging a message.
The default asyncio loop exception handler will log the exception details, drop the task and continue on.
Would you consider alterations to SnmpTrapProtocol.datagram_received & SnmpProtocol.datagram_received to capture exceptions raised by SnmpMessage.decode and simply log a message much like the default asyncio loop exception handler does?
Hi,
First of all I would like to thank you for the work you have done. I often have to work with machines that have multiple interfaces to reach different networks so I'm constantly looking for packages that allow setting the source address.
Inspecting the aiosnmp code, I found that it is using class asyncio.DatagramTransport ng loop.create_datagram_endpoint for the snmp request which actually allows setting the local_addr:
https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.create_datagram_endpoint
I forked the aiosnmp code and made some small adjustments to enable the use of local_addr and it seems to work just fine:
master...mzsombor:local_addr
I hope you don't mind and if you find it useful it would be nice to have this feature in the original project. If not, I hope this will be helpful for others who are looking for similar functionalities.
Please, vote ๐ if you use snmpv3 on daily basis and ๐ if you use only snmpv2c. Thank you.
Hi,
As far as I understand, bulk_walk should accept a list of oids to optimize network calls, but I'm not sure... My guess is based on easysnmp (I can't use this repo, because is not async).
Could you help to clarify?
Does aiosnmp compare the source ip of the received snmp packet to the destination address of the sent snmp packet?
I'm dealing with an unusual network scenario where the polled device might reply with a different IP Address, see example below:
08:46:54.952262 IP 172.21.32.33.46818 > 192.168.2.1.161: C="TEST" GetRequest(28) system.sysDescr.0
08:46:54.984631 IP 10.168.1.1.171 > 172.21.32.33.46818: C="TEST" GetResponse(68) system.sysDescr.0="Software Version ..."
I can see the snmp reply in tcpdump but aiosnmp does not seem to detect it, I get the default Timeout behavior. I don't know if this is a justified use case but other linux snmp tools support it. I looked in the source code but I was unable to change the behavior of the received datagram.
I would like to know if this is even possible and if yes some hints on what to modify would be helpful.
Thank you.
The SNMP trap class does not allow closing of the endpoint.
run callable can be changed to return the transport, which can be closed:
async def run(self) -> None:
loop = asyncio.get_event_loop()
transport, _ = await loop.create_datagram_endpoint(
lambda: SnmpTrapProtocol(self.communities, self.handler),
local_addr=(self.host, self.port),
)
return transport
Thanks for the library!
It is going into exception with a valid oid like this iso.3.6.1.2.1.1.1.0. Is oids like that not supported?
`Traceback (most recent call last):
File "/home/humayun/PycharmProjects/asynciotesting/snmp/asyncio_snmp_testing.py", line 21, in
loop.run_until_complete(main())
File "/usr/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete
return future.result()
File "/home/humayun/PycharmProjects/asynciotesting/snmp/asyncio_snmp_testing.py", line 16, in main
for res in await snmp.get("iso.3.6.1.2.1.1.1.0"):
File "/home/humayun/PycharmProjects/asynciotesting/.env/lib/python3.7/site-packages/aiosnmp/snmp.py", line 63, in get
return await self._send(message)
File "/home/humayun/PycharmProjects/asynciotesting/.env/lib/python3.7/site-packages/aiosnmp/snmp.py", line 55, in _send
return await self._protocol._send(message, *self._peername[:2])
File "/home/humayun/PycharmProjects/asynciotesting/.env/lib/python3.7/site-packages/aiosnmp/protocols.py", line 138, in _send
self.transport.sendto(message.encode())
File "/home/humayun/PycharmProjects/asynciotesting/.env/lib/python3.7/site-packages/aiosnmp/message.py", line 147, in encode
self.data.encode(encoder)
File "/home/humayun/PycharmProjects/asynciotesting/.env/lib/python3.7/site-packages/aiosnmp/message.py", line 80, in encode
varbind.encode(encoder)
File "/home/humayun/PycharmProjects/asynciotesting/.env/lib/python3.7/site-packages/aiosnmp/message.py", line 57, in encode
encoder.write(self._oid, Number.ObjectIdentifier)
File "/home/humayun/PycharmProjects/asynciotesting/.env/lib/python3.7/site-packages/aiosnmp/asn1.py", line 168, in write
value = self._encode_value(nr, value)
File "/home/humayun/PycharmProjects/asynciotesting/.env/lib/python3.7/site-packages/aiosnmp/asn1.py", line 245, in _encode_value
return self._encode_object_identifier(value)
File "/home/humayun/PycharmProjects/asynciotesting/.env/lib/python3.7/site-packages/aiosnmp/asn1.py", line 304, in _encode_object_identifier
raise Error("Illegal object identifier")
aiosnmp.asn1.Error: Illegal object identifier
`
Would it be possible to build Python3.10 wheels?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.