[SNMP4J] Problem with SNMP Receiver
Adam Brons
abrons at us.ibm.com
Thu Mar 29 15:04:36 CEST 2007
I realized my last paragraph was a but difficult to understand so I'll
state what's going on a bit better here (I hope).
I'm using the snmp4j command-line tool to send snmp messages to my SNMP
Trap receiver. I'm doing all of this on a local box. During this process
I'm running tcpdump for port 16200 (above 1024 for testing). I see the
tcp 3-way handshake and some data being pushed to the SNMP Trap receiver,
but what I don't see is any indication that my
CommandResponder.processPdu() was called.
Here's the CommandLine I'm using to send SNMP Packets:
./SNMP4J-linux -p TRAP -v 1 tcp:127.0.0.1/16200
Also while my SNMP Trap receiver is running I see see listening ports for
16200 for both tcp and udp via a "netstat -an" command. I'm event able to
telnet to the tcp port 16200 and get connected.
I've looked a numerous examples on the mailing list, the SnmpRequest, and
the Snmp class itself for using the addNotificationListener and still seem
to be running up against a brick wall.
Oh and to point out the obvious... Yes my logging does work. All log
messages are reported except for the ones in "processPdu()".
Any help would be most appreciated.
Adam Brons/Atlanta/IBM at IBMUS
Sent by: snmp4j-bounces at agentpp.org
03/28/07 08:22 PM
To
snmp4j at agentpp.org
cc
Subject
[SNMP4J] Problem with SNMP Receiver
Hey Everyone, I'm trying to put together a SNMP Trap receiver and I am
having some trouble with the CommandResponder. I'm hoping you guys can
point out what I'm doing wrong.
Thanks - in advance:
public class SNMPListener {
// Number of SNMP Dispatcher Threads
private static final int DISPATHER_THREAD_NUMBER = 2;
private static Logger logger =
Logger.getLogger(SNMPListener.class);
private Snmp snmp = null;
private USM usm = null;
private InetAddress bindAddress;
private Integer port;
private Collection users;
protected SNMPListener() throws UnknownHostException {
this("0.0.0.0", 162, null);
}
protected SNMPListener(String bindAddress, Integer port,
Collection users) throws UnknownHostException {
this.bindAddress = InetAddress.getByName(bindAddress);
this.port = port;
this.users = users;
// Create a thread pool to handle inbound SNMP events
ThreadPool threadPool = ThreadPool.create("SNMPTrap",
DISPATHER_THREAD_NUMBER);
MessageDispatcher mtDispatcher =
new MultiThreadedMessageDispatcher(threadPool, new
MessageDispatcherImpl());
// Add the SNMP versions we wish to monitor for
mtDispatcher.addMessageProcessingModel(new MPv1());
mtDispatcher.addMessageProcessingModel(new MPv2c());
mtDispatcher.addMessageProcessingModel(new MPv3());
snmp = new Snmp(mtDispatcher);
// Setup Authentication and Encryption protocols for
SNMPv3
SecurityProtocols.getInstance().addDefaultProtocols();
usm = new USM(SecurityProtocols.getInstance(),
new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
}
public synchronized void listen() throws IOException {
// Make a tcp and udp based address for listening
UdpAddress udpAddr = new UdpAddress(bindAddress,port);
TcpAddress tcpAddr = new TcpAddress(bindAddress,port);
SNMPEventDispatcher dispatcher = new
SNMPEventDispatcher();
// Add transport mapping and command handler to Snmp
Engine
if (snmp.addNotificationListener(udpAddr, dispatcher) &&
snmp.addNotificationListener(tcpAddr, dispatcher))
{
// Start listening
snmp.listen();
logger.info("Listening on
UDP:"+udpAddr.toString()+"...");
logger.info("Listening on
TCP:"+tcpAddr.toString()+"...");
// Just wait for something to happen.
try { this.wait(); }
catch (InterruptedException ex) { }
} else {
logger.error("Unable to bind
address("+udpAddr.toString()+") to snmp listener");
}
}
public static void main(String[] args) throws Exception {
SNMPListener listener = new SNMPListener();
listener.listen();
}
}
public class SNMPEventDispatcher implements CommandResponder,
AuthenticationFailureListener {
private static Logger logger =
Logger.getLogger(SNMPEventDispatcher.class);
public SNMPEventDispatcher() {
logger.debug("Instaniated SNMPEventDispatcher");
}
public synchronized void processPdu(CommandResponderEvent event) {
logger.debug("ProcessPdu called for event
["+event.toString()+"]");
if (event.isProcessed()) {
logger.debug("Snmp Event ["+event.toString()+"]
processed.");
return;
}
PDU pdu = event.getPDU();
logger.debug("Received PDU: "+ pdu.toString());
// This must be set when an CommandResponderEvent has been
processed.
event.setProcessed(true);
}
public void authenticationFailure(AuthenticationFailureEvent
event) {
logger.warn("Inbound SNMP event failed authentication");
}
}
What's not happening is even with tcpdump traces and using tcp to show two
way communication I never see logging from
SNMPEventDispather.processPdu(CommandResponderEvent event).
As an added tidbit I'm running this in a JUNIT test in Eclipse so I don't
know if that has anything to do with it.
Adam
_______________________________________________
SNMP4J mailing list
SNMP4J at agentpp.org
http://lists.agentpp.org/mailman/listinfo/snmp4j
More information about the SNMP4J
mailing list