Possibility to abort SNMPWalk after specified time?

Hello,

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!
Sebastian

Hi Sebastian,

Sure, simply use the asynchronous interface with callback:
https://www.agentpp.com/doc/snmp4j/org/snmp4j/util/TreeUtils.html#getSubtree-org.snmp4j.Target-org.snmp4j.smi.OID-java.lang.Object-org.snmp4j.util.TreeListener-

When the method next is called on the callback interface, you can return false to abort the walk:
https://www.agentpp.com/doc/snmp4j/org/snmp4j/util/TreeListener.html#next-org.snmp4j.util.TreeEvent-

Best regards,
Frank

Hi Frank,

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

Best regards,
Sebastian