Possibility to abort SNMPWalk after specified time?


first of all, I am a huge fan of your libraries, using SNMP4J as well as the licensed SMI-PRO extensively - thanks for your great work! :slight_smile:

Currently I face a use case where we need to query a huge MIB table. The table is too large to wait for the query to terminate, hence we would like to abort it after a specified time and verify that we received some results. For the walking procedure I use:

TreeUtils treeUtils = new TreeUtils(this.snmp, new DefaultPDUFactory());
List<TreeEvent> treeEvents = treeUtils.getSubtree(this.target, new OID(((Polling.WalkRequest) this.pollingRequest).getRootOidString()));

Unfortunately, I did not find a way to manipulate the getSubtree or walk methods to abort at some criterion and still return me the OIDs walked across so far…

Is there some possibility to achieve this kind of behavior?

Thanks in advance!

Hi Sebastian,

Sure, simply use the asynchronous interface with callback:

When the method next is called on the callback interface, you can return false to abort the walk:

Best regards,

Hi Frank,

thank you very much for the fast and helpful reply - works like a charm.

Best regards,