use of org.snmp4j.mp.StatusInformation in project camel by apache.
the class SnmpTrapConsumer method processPdu.
public void processPdu(CommandResponderEvent event) {
PDU pdu = event.getPDU();
// check PDU not null
if (pdu != null) {
// code take from the book "Essential SNMP"
if ((pdu.getType() != PDU.TRAP) && (pdu.getType() != PDU.V1TRAP) && (pdu.getType() != PDU.REPORT) && (pdu.getType() != PDU.RESPONSE)) {
// first response the inform-message and then process the
// message
pdu.setErrorIndex(0);
pdu.setErrorStatus(0);
pdu.setType(PDU.RESPONSE);
StatusInformation statusInformation = new StatusInformation();
StateReference ref = event.getStateReference();
try {
event.getMessageDispatcher().returnResponsePdu(event.getMessageProcessingModel(), event.getSecurityModel(), event.getSecurityName(), event.getSecurityLevel(), pdu, event.getMaxSizeResponsePDU(), ref, statusInformation);
if (LOG.isDebugEnabled()) {
LOG.debug("response to INFORM sent");
}
} catch (MessageException ex) {
getExceptionHandler().handleException(ex);
}
}
processPDU(pdu, event);
} else {
LOG.debug("Received invalid trap PDU");
}
}
use of org.snmp4j.mp.StatusInformation in project opennms by OpenNMS.
the class Snmp4JTrapNotifier method processPdu.
@Override
public void processPdu(CommandResponderEvent e) {
PDU command = e.getPDU();
if (command != null) {
IpAddress addr = ((IpAddress) e.getPeerAddress());
if (command.getType() == PDU.INFORM) {
// Backing up original content
int errorIndex = command.getErrorIndex();
int errorStatus = command.getErrorStatus();
int type = command.getType();
// Prepare resopnse
command.setErrorIndex(0);
command.setErrorStatus(0);
command.setType(PDU.RESPONSE);
StatusInformation statusInformation = new StatusInformation();
StateReference ref = e.getStateReference();
// Send the response
try {
e.getMessageDispatcher().returnResponsePdu(e.getMessageProcessingModel(), e.getSecurityModel(), e.getSecurityName(), e.getSecurityLevel(), command, e.getMaxSizeResponsePDU(), ref, statusInformation);
LOG.debug("Sent RESPONSE PDU to peer {} acknowledging receipt of INFORM (reqId={})", addr, command.getRequestID());
} catch (MessageException ex) {
LOG.error("Error while sending RESPONSE PDU to peer {}: {} acknowledging receipt of INFORM (reqId={})", addr, ex.getMessage(), command.getRequestID());
} finally {
// Restoring original settings
command.setErrorIndex(errorIndex);
command.setErrorStatus(errorStatus);
command.setType(type);
}
}
if (command instanceof PDUv1) {
m_listener.trapReceived(new Snmp4JV1TrapInformation(addr.getInetAddress(), new String(e.getSecurityName()), (PDUv1) command));
} else {
m_listener.trapReceived(new Snmp4JV2TrapInformation(addr.getInetAddress(), new String(e.getSecurityName()), command));
}
}
}
use of org.snmp4j.mp.StatusInformation in project opennms by OpenNMS.
the class MockProxy method processPdu.
@Override
public void processPdu(CommandResponderEvent e) {
PDU command = e.getPDU();
if (command == null)
return;
PDU response = processRequest(command);
if (response == null)
return;
StatusInformation statusInformation = new StatusInformation();
StateReference ref = e.getStateReference();
try {
LOG.debug("Replying with: {}", command);
e.setProcessed(true);
e.getMessageDispatcher().returnResponsePdu(e.getMessageProcessingModel(), e.getSecurityModel(), e.getSecurityName(), e.getSecurityLevel(), command, e.getMaxSizeResponsePDU(), ref, statusInformation);
} catch (MessageException ex) {
LOG.error("Error while sending response", ex);
}
}
Aggregations