Giter Site home page Giter Site logo

aiosnmp's People

Contributors

fthyssen avatar hh-h avatar mzsombor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

aiosnmp's Issues

V3 Support

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.

Timeout issue on Windows 10 Profesional Edition.

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

Exception appear AssertionError, no message, i don't know why to cause this error

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

Exceptions raised within datagram_received difficult to use

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?

Allow setting source address

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.

SNMPv3 support

Please, vote ๐Ÿ‘ if you use snmpv3 on daily basis and ๐Ÿ‘Ž if you use only snmpv2c. Thank you.

bulk_walk does not accept a list of oids

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?

SNMP reply from different IP address than sent to

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.

Please allow close SNMPtrap

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!

Goes into exception with Oid like this iso.3.6.1.2.1.1.1.0

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

`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.