Hello,
I’m new to snmp4j.
I’ve used v 2.8.6 and the recipe at http://techdive.in/snmp/snmp4j-trap-receiver to implement a CommandResponder to receive traps on port 162 from a UPS device. Using tcpdump, I see traffic from the agent to the host/port where I’m running the snmp4j program. However, the processPdu method is never called. I tried both addCommandResponder and addNotificationListener to no avail.
Any assistance would be appreciated.
Source code snippet:
public synchronized void listen(String address, String community) throws IOException
{
TransportMapping<?> transport;
//TRANSPORT
Address listenAddress = GenericAddress.parse(System.getProperty(
“snmp4j.listenAddress”, address));
if (listenAddress instanceof UdpAddress) {
transport = new DefaultUdpTransportMapping(
(UdpAddress) listenAddress);
} else {
transport = new DefaultTcpTransportMapping(
(TcpAddress) listenAddress);
}
ThreadPool threadPool = ThreadPool.create("DispatcherPool", 10);
MessageDispatcher mtDispatcher = new MultiThreadedMessageDispatcher(threadPool, new MessageDispatcherImpl());
// add message processing models
mtDispatcher.addMessageProcessingModel(new MPv1());
mtDispatcher.addMessageProcessingModel(new MPv2c());
// add all security protocols
SecurityProtocols.getInstance().addDefaultProtocols();
SecurityProtocols.getInstance().addPrivacyProtocol(new Priv3DES());
//Create Target
CommunityTarget target = new CommunityTarget();
target.setCommunity( new OctetString(community));
Snmp snmp = new Snmp(mtDispatcher, transport);
snmp.addCommandResponder(this);
transport.listen();
System.out.println("Listening on " + transport.getListenAddress() + " - community " + community);
try
{
this.wait();
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
}
/**
- This method will be called whenever a pdu is received on the given port specified in the listen() method
*/
public synchronized void processPdu(CommandResponderEvent cmdRespEvent)
{
System.out.println(“Received PDU…”);
…
}