yuval
yuval

Reputation: 3088

pysnmp nextcmd stops on timeout

I am trying to perform a snmp walk on certain networking devices.
On some netwroking devices I succeed to go through all the devices oids and on some networking devices I don't succeed to go through all the devices oids.
Here is my code:

cmdGen = cmdgen.AsynCommandGenerator()
cmdGen.asyncNextCmd(
    cmdgen.CommunityData('public', mpModel=0),
    cmdgen.UdpTransportTarget(('ip', 161),timeout=timeout,retries=retries),
    ((1,3),),
    (cbFun_Walk, None))
cmdGen.snmpEngine.transportDispatcher.runDispatcher() 

The problem is that sometimes asyncCommandGenerator gets a timeout on a certaion oid and exists out of the thread.

enter image description here

As you can see the thread reaches some oid, gets a timeout error, and then quits the thread.
So i would like to know how to continue the snmpwalk even if a timed out oid was reached.
Basically if asyncCommandGenerator reaches a timed out oid, it should just continue with the walk and get the rest of the oids.
How could I achieve this?

Upvotes: 0

Views: 1158

Answers (1)

Ilya Etingof
Ilya Etingof

Reputation: 5555

Logically speaking, you can't skip the "next" OID on request timeout, as you will not know what is the next OID then. I can see two workarounds here:

  1. Repeat your GETNEXT request for the same OID for as long as it takes to get a response. By increasing request timeout and retry count. Proper SNMP responder should ultimately respond to all valid requests.
  2. Try to guess what is the "next" OID past the one you can't get response for. This is generally MIB-dependent and in many cases may require a non-trivial fuzziness. Once you somehow picked the next OID, just re-start your original code with the guessed OID. That would effectively "skip" the problem OID (or many of them at once if your guess is not perfect). In case of another timeout you may consider changing your next OID selection logic -- chances are you are still hitting the same timing out OID.

Upvotes: 1

Related Questions