[SNMP4J] Could anyone please tell me whats wrong with my program...

Frank Fock fock at agentpp.com
Thu Jul 19 19:14:42 CEST 2007


Hi Sanjay,

You do not provide the address you are listening on
and were you send the trap (what system/program
is sending it).

BTW, why do you create a Target in a trap listener
application?

To all, please do not post complex code snippets!!!
Please make simple and minimal example programs,
otherwise the list degenerates to a Java programming
list rather than a SNMP4J mailing list. Thanks.

Best regards,
Frank

sanjay A wrote:
> Hi all
> By using snmp4j packege I have written a trap listener code for snmpV3, but
> am not able to catch any trap. In etherial i am getting snmp trap.
> Could anyone please tell me whats wrong with my program...
> 
> 
> public class V3trapListen {
> 
> public V3trapListen() { }
> 
> public synchronized void start(String address) throws Exception {
> UdpAddress listenAddress = new UdpAddress(address);
> ThreadPool threadPool = ThreadPool.create("DispatcherPool", 2);//1
> MessageDispatcher mtDispatcher =
> new MultiThreadedMessageDispatcher(threadPool,
> new MessageDispatcherImpl());//2
> 
> // add message processing models
> mtDispatcher.addMessageProcessingModel(new MPv1());
> mtDispatcher.addMessageProcessingModel(new MPv2c());
> mtDispatcher.addMessageProcessingModel(new MPv3());
> 
> // add default security models
> SecurityProtocols.getInstance().addDefaultProtocols();
> 
> Snmp snmp = new Snmp(mtDispatcher);
> 
> CommunityTarget target = new CommunityTarget();
> if(target != null) {
> target.setCommunity(new OctetString("public"));
> target.setAddress(listenAddress);
> target.setVersion(SnmpConstants.version3);
> } else {
> System.out.println("Unable to create Target object");
> System.exit(-1);
> }
> 
> CommandResponder trapPrinter = new CommandResponder() {
> public void processPdu(CommandResponderEvent e) {
> PDU command = e.getPDU();
> if (command != null) {
> System.out.println("\n"+e.getPDU());
> }
> }
> };
> if (snmp.addNotificationListener(listenAddress, trapPrinter)) {
> snmp.listen();
> System.out.println("snmp.addNotificationListener returned TRUE ");
> System.out.println("Waiting for [trap] on "+listenAddress.toString());
> 
> try {
> this.wait();
> 
> }
> catch(InterruptedException ex) {
> System.out.println("Caught InterruptException: "+ex.toString());
> }
> catch(Exception ex) {
> System.out.println("CaughtException: "+ex.toString());
> }
> } else {
> System.out.println("snmp.addNotificationListener returned FALSE");
> System.out.println("TestListener closing...");
> }
> }
> 
> regards
> sanjay
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j

-- 
AGENT++
http://www.agentpp.com
http://www.mibexplorer.com
http://www.mibdesigner.com




More information about the SNMP4J mailing list