[SNMP4J] Device sending Trap with Inform
John Money
john.money at gmail.com
Fri Sep 19 21:12:00 CEST 2014
Hi Frank,
I am using snmp4j to listen for traps from multiple devices and it works
great! Recently, I started receiving traps from a device that is expecting
an Inform response to know that the trap has been received. Right now, the
device just continues to resend the traps and I receive all of them but I
only need each trap once.
I have been doing a lot of googling and I haven't found an example of how
to setup snmp4j to respond to the Trap/Inform so that the device will know
that the trap was received. Right now I have a CommandResponder
implementation that receives the Trap PDUs, but it is not receiving the
Inform PDUs that are being sent on the same port. If I configure my linux
server snmptrapd it receives the Traps and Inform messages, so it does not
appear to be an issue with the network. I am not sure why my snmp4j
configuration can receive the Traps but not the Informs.
Questions:
1. Any idea why I am receiving Traps by not Informs?
2. Do you have an example for how to use snmp4j to acknowledge Traps sent
be a device that is expecting a response?
Here is my code:
public void start() {
try {
String address = LOCALHOST + port;
logger.info("startSnmpServer at " + address);
Address _listenAddress = GenericAddress.parse(address);
if (!_listenAddress.isValid()) {
throw new IllegalArgumentException();
}
MessageDispatcher mDispathcher = new MessageDispatcherImpl();
DefaultUdpTransportMapping transport = new
DefaultUdpTransportMapping((UdpAddress) _listenAddress);
snmp = new Snmp(mDispathcher, transport);
//Add SNMP v1 and v2c support
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv1());
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv2c());
// Create Specific USM for local SNMP Event Trap Receiver (Create
// Local Engine ID should only be used once)
OctetString os = new OctetString(MPv3.createLocalEngineID());
usm = new USM(SecurityProtocols.getInstance(), os, 0);
// Bind specific USM (v3) to Snmp message processing model
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3(usm));
snmp.addCommandResponder(commandResponder);
snmp.listen();
logger.info("snmpServer started... [" + address);
} catch (Exception e) {
logger.error("Error while trying to start the SNMP Server", e);
}
}
I am thinking about using the following code in my CommandResponder
implementation to respond to the Informs:
public void processPdu(CommandResponderEvent event) {
try {
callback.doWork(event);
//Respond to Inform
PDU pdu = event.getPDU();
if (pdu != null && pdu.getType() == PDU.INFORM) {
pdu.setErrorIndex(0);
pdu.setErrorStatus(0);
pdu.setType(PDU.RESPONSE);
try {
event.getMessageDispatcher().returnResponsePdu(
event.getMessageProcessingModel(),
event.getSecurityModel(), event.getSecurityName(),
event.getSecurityLevel(), pdu,
event.getMaxSizeResponsePDU(),
event.getStateReference(), new StatusInformation());
logger.info("PDU INFORM response sent.");
} catch (Exception e) {
logger.error("Error while sending INFORM response", e);
}
}
} catch (Exception e) {
logger.error("Error while processing the PDU", e);
}
}
Thank you for your time!
Thanks,
John Money
More information about the SNMP4J
mailing list