pysnmp icon indicating copy to clipboard operation
pysnmp copied to clipboard

Polling fails after reboot of target

Open FredericMa opened this issue 4 years ago • 0 comments

I'm having a very strange issue. I'm running Home Assistant on a Windows Server 2019.

I poll the state of an interface on my router via SNMP. The strange thing is that as long as everything is up and running, all is updating fine. If I restart the router, the polling keeps on failing and never processes the responses anymore. On another PC that is running Windows 10, same python version and same version of pysnmp, it works fine and responses are properly processed after the reboot. On the server, I checked with wireshark and the responses are arriving correctly. Only a restart of Home Assistant solves the issue.

Now, to exclude Home Assistant I took a demo script and modified it a bit to simulate the Home Assistant behavior:

import asyncio
from pysnmp.hlapi.asyncio import *
import time

@asyncio.coroutine
def run():
    
    request_args = [
            SnmpEngine(),
            CommunityData('rocommunity', mpModel=0),
            UdpTransportTarget(('192.168.xxx.xxx', 161)),
            ContextData(),
        ]
    while True:
        
        errorIndication, errorStatus, errorIndex, varBinds = yield from getCmd(
            *request_args,
            ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.8.9'))
        )

        if errorIndication:
            print(errorIndication)
        elif errorStatus:
            print('%s at %s' % (
                errorStatus.prettyPrint(),
                errorIndex and varBinds[int(errorIndex) - 1][0] or '?'
            )
                  )
        else:
            for varBind in varBinds:
                print(' = '.join([x.prettyPrint() for x in varBind]))

        time.sleep(2)


asyncio.get_event_loop().run_until_complete(run())

This is the output on the server:

c:\Temp\test-snmp.py:6: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
  def run():
SNMPv2-SMI::mib-2.2.2.1.8.9 = 2
SNMPv2-SMI::mib-2.2.2.1.8.9 = 2
SNMPv2-SMI::mib-2.2.2.1.8.9 = 2
SNMPv2-SMI::mib-2.2.2.1.8.9 = 2
SNMPv2-SMI::mib-2.2.2.1.8.9 = 2
SNMPv2-SMI::mib-2.2.2.1.8.9 = 2
SNMPv2-SMI::mib-2.2.2.1.8.9 = 2
SNMPv2-SMI::mib-2.2.2.1.8.9 = 2
SNMPv2-SMI::mib-2.2.2.1.8.9 = 2
No SNMP response received before timeout
No SNMP response received before timeout
No SNMP response received before timeout

Even if the SNMP target is back online, it keeps printing timeouts. I ran the same script on a Windows 10 PC and there it give a few timeouts and when the target is up again, it gives the correct output.

I'm using Python 3.8.1 64 bit on both machines and using pysnmp 4.4.12 Any idea why the responses are not processed correctly after the target went offline and came back online?

FredericMa avatar May 04 '20 20:05 FredericMa