【发布时间】:2018-01-10 16:51:46
【问题描述】:
我需要在 java 中使用 snmp4j 模拟 GETBULK 请求。但我不明白该怎么做。更具体地说,我不明白如何创建 TreeEvent 以创建响应列表以及如何回答客户。
我有一个这样的 snmpwalk
public void sendWalk(String community, String ipAddress, int port, String oidValue, int retries, long timeoutMillis) throws IOException {
CommunityTarget comtarget = new CommunityTarget();
comtarget.setCommunity(new OctetString(community));
comtarget.setAddress(new UdpAddress(ipAddress + "/" + port));
comtarget.setRetries(retries);
comtarget.setTimeout(timeoutMillis);
comtarget.setVersion(snmpVersion);
OID oid = new OID(oidValue);
TreeUtils treeUtils = new TreeUtils(snmp, new DefaultPDUFactory());
List<TreeEvent> events = treeUtils.walk(comtarget, new OID[]{oid});
if(events == null || events.size() == 0) {
// TODO inserire in allarm manager ???
log.warn(" No events . Request[Oid:"+oidValue+"]");
}else{
parseWalkResult(events);
}
}
SNMP4J 上的 snmpwalk 是一个 GETBULK 请求,然后我想在 treeUtils.walk 方法中实现一个模拟以响应,并将 TreeEvents 列表作为模型的答案。
提前谢谢你。
【问题讨论】:
-
请edit您的问题显示the code you have so far。您应该至少包含您遇到问题的代码的大纲(但最好是minimal reproducible example),然后我们可以尝试帮助解决具体问题。您还应该阅读How to Ask。