【发布时间】:2017-05-23 10:28:56
【问题描述】:
我正在使用snmp4j 尝试针对远程代理执行 SNMP 功能。由于我们无法控制的一些限制,我需要执行GETBULK 以在短时间内获得一个大表。
我目前的实现:
public Map<String, String> doGetBulk(@NotNull VariableBinding... vbs)
throws IOException {
Map<String, String> result = new HashMap<>();
Snmp snmp = null;
try {
// Create TransportMapping and Listen
TransportMapping transport = new DefaultUdpTransportMapping();
snmp = new Snmp(transport);
transport.listen();
PDU pdu = new PDU();
pdu.setType(PDU.GETBULK);
pdu.setMaxRepetitions(200);
pdu.setNonRepeaters(0);
pdu.addAll(vbs);
ResponseEvent responseEvent = snmp.send(pdu, this.target);
PDU response = responseEvent.getResponse();
// Process Agent Response
if (response != null) {
for(VariableBinding vb : response.getVariableBindings()) {
result.put("." + vb.getOid().toString(), vb.getVariable().toString());
}
} else {
LOG.error("Error: Agent Timeout... ");
}
} catch (NullPointerException ignore) {
// The variable table is null
} finally {
if (snmp != null) snmp.close();
}
return result;
}
但是,当我知道有 5000+ 个结果时,这只会返回 100 个结果。我知道我不能超过 PDU 的大小,所以我在将响应截断为 100 个块时遇到了问题,但我不知道如何获得句柄来级联请求以获取接下来的 100 个条目。
【问题讨论】: