[SNMP4J] Device sending Trap with Inform

Frank Fock fock at agentpp.com
Sat Sep 20 01:04:27 CEST 2014


Hi John,

The SNMP4J trap listener is already responding to INFORM requests
as required by the SNMP(v3) standard. The standard requires the
protocol level to respond the INFORM request. It is thus not the
application that is responding.

Best regards,
Frank

Am 20.09.2014 00:10, schrieb John Money:
> Hi Frank,
>
> No need to respond to my last email. I answered both questions. There was a
> port forwarding rule on my linux server that was blocking inform messages
> but not traps and I found some sample code in your SnmpRequest class so I
> will use that as an example for responding to an Inform request.
>
> Thanks,
> John Money
>
> On Fri, Sep 19, 2014 at 12:12 PM, John Money <john.money at gmail.com> wrote:
>
>> 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
>>
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> https://oosnmp.net/mailman/listinfo/snmp4j

-- 
---
AGENT++
Maximilian-Kolbe-Str. 10
73257 Koengen, Germany
https://agentpp.com
Phone: +49 7024 8688230
Fax:   +49 7024 8688231



More information about the SNMP4J mailing list