Mam problem z wysłaniem trapa. Wygląda jakby port był zamykany za szybko, bo jak się podłącze debugiem miedzy snmp.send() snmp.close() to trap wychodzi, tak samo jak dam w tym miejscu thread.sleep(1000). Jeśli program leci bez przerwania miedzy send a close to trap nie wychodzi z portu (sprawdzone RawCap i WireSharkiem). Gdy ustawie pdu na inny typ niż -88, -94, -89, -92 wtedy trap dochodzi ale nie jest już typowym trapem tylko information lub czyms innym.
Może ktoś dostrzeże co może być źle:
try {
TransportMapping<?> transport = new DefaultUdpTransportMapping();
transport.listen();
Snmp snmp = new Snmp(transport);
AbstractTarget target = null;
PDU pdu = null;
if (enableSNMPv3) {
if (engineID == null) {
SecurityModels.getInstance().addSecurityModel(new USM(SecurityProtocols.getInstance(),
new OctetString( MPv3.createLocalEngineID()), 0));
} else {
SecurityModels.getInstance().addSecurityModel(new USM(SecurityProtocols.getInstance(),
new OctetString(engineID), 0));
}
snmp.getUSM().addUser(new OctetString(userAuthName), usmUser);
target = new UserTarget();
target.setAddress(targetAddress);
target.setRetries(0);
target.setTimeout(SEND_TIMEOUT);
target.setVersion(SnmpConstants.version3);
target.setSecurityModel(SecurityModel.SECURITY_MODEL_USM);
pdu = new ScopedPDU();
pdu.setType(ScopedPDU.TRAP);
} else {
CommunityTarget tar = new CommunityTarget();
tar.setAddress(targetAddress);
tar.setCommunity(new OctetString("public"));
tar.setVersion(SnmpConstants.version2c);
tar.setRetries(0);
tar.setTimeout(SEND_TIMEOUT);
pdu = new PDU();
pdu.setType(PDU.NOTIFICATION);
target = tar;
}
if (enableSNMPv3) {
target.setSecurityLevel(securityLevel);
target.setSecurityName(new OctetString(userAuthName));
}
Long time = new Date().getTime();
pdu.add(new VariableBinding(SnmpConstants.sysUpTime, new OctetString(time.toString())));
pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID(trapOid)));
pdu.add(new VariableBinding(SnmpConstants.snmpTrapAddress, new IpAddress(ipAddress)));
for (VariableBinding item : pduList) {
pdu.add(item);
}
snmp.send(pdu, target);
log.debug("Trap sent");
snmp.close();
return true;
} catch (IOException e) {
log.error(e.getMessage());
}
return false;