Re: [SNMP4J] A Simple Trap Receiver using snmp4j
Hi, I had also the same problem, i had uses the the same methodology, but when i change the TRAP_ADRESS to 0.0.0.0/162, the it starts receiving TRAPS. try this may this will help you. Thanks & Regards Jaikar Gupta On Tue, Aug 17, 2010 at 2:06 PM, Tsiyona wrote: > Hello, > > I am trying to write a simple snmp manager that listens to traps on port > 162 > and processes them. This manager will only handle traps, and does not need > to send commands to agents. > > Attached is the code I wrote. It is straightforward, but it does not work - > I do not get any snmp traps. > I make sure that the snmp agent really constantly generates traps, by using > a network sniffer, so my > problem is not lack of traps on the agent side. I am probably doing > something wrong. > > Can anyone please help me? > > Thanks, > Tsiyona > > > > - >My code: > > - > > package snmpmanager; > > import java.io.IOException; > > import org.snmp4j.CommandResponder; > import org.snmp4j.CommandResponderEvent; > import org.snmp4j.PDU; > import org.snmp4j.Snmp; > import org.snmp4j.TransportMapping; > import org.snmp4j.smi.UdpAddress; > import org.snmp4j.transport.DefaultUdpTransportMapping; > import org.snmp4j.transport.TransportMappings; > > /** > * A Simple Trap receiver using snmp4j. > */ > public class SnmpClient > { > > public static final String TRAP_ADDRESS = "127.0.0.1/162";//"udp: > 127.0.0.1/162"; > private TransportMapping transport; > private String listeningAddress; > private Snmp snmp; > > public SnmpClient(String address) > { > this.listeningAddress = address; > try { > start(); > } catch (IOException e) { > e.printStackTrace(); > throw new RuntimeException(e); > } > } > > private void start() throws IOException > { > UdpAddress udpAddress = new UdpAddress(this.listeningAddress); > transport = new DefaultUdpTransportMapping(udpAddress); > snmp = new Snmp(transport); > transport.listen(); > CommandResponder pduHandler = new CommandResponder() { > public synchronized void processPdu(CommandResponderEvent e) { > PDU pdu = e.getPDU(); > if (pdu != null) { > System.out.println(pdu); > } > } > }; > snmp.addCommandResponder(pduHandler); > } > public void stop() throws IOException > { > snmp.close(); > } > > public static void main(String[] args) > { > SnmpClient client = new SnmpClient(TRAP_ADDRESS); > System.out.println("Listening for traps on address " + TRAP_ADDRESS); > } > } > > ___ > SNMP4J mailing list > SNMP4J@agentpp.org > http://lists.agentpp.org/mailman/listinfo/snmp4j > > ___ SNMP4J mailing list SNMP4J@agentpp.org http://lists.agentpp.org/mailman/listinfo/snmp4j
Re: [SNMP4J] A Simple Trap Receiver using snmp4j
Hi, I used : http://code.google.com/p/snmphibernate/source/browse/trunk/project/org.opengoss.snmphibernate.impl.snmp4j/src/org/snmp4j/test/MultiThreadedTrapReceiver.java?spec=svn15&r=15 As a reference for my SNMP trap receiver and it works fine. How are you sending traps themselves? are you sure the traps are being sent? I used a UNIX script I found somewhere for sending traps: classdir=/home/snmp4j/snmp4j/1.10.1 classpath="-classpath ${classdir}/snmp4j-1.10.1.jar" snmpRequest=org.snmp4j.tools.console.SnmpRequest uptime="-Cu 42420" community="-c public" trapoid="-Ct 1.3.6.1.4069.5.6.7.8.0.9" target="10.101.2.212/9000" version_v2c="-v 2c" pdutype_v2c="-p TRAP" pdutype_v2c_inform="-p INFORM" version_v1="-v 1" pdutype_v1="-p V1TRAP" specific="-Cs 9" generic="-Cg 6" enterprise="-Ce 1.3.6.1.4.1.4069" options_v1="${version_v1} ${pdutype_v1} ${community} ${uptime} ${enterprise} ${generic} ${specific}" options_v2c="${version_v2c} ${pdutype_v2c} ${community} ${uptime} ${trapoid}" options_v2c_inform="${version_v2c} ${pdutype_v2c_inform} ${community} ${uptime} ${trapoid}" java ${classpath} ${snmpRequest} ${options_v2c} ${target} "1.3.6.1.4.4.4.4.23={i}42" "1.3.6.1.4.5.6.7.8.0={s}simple trap sender" Hope it helps you, or you can use the org.snmp4j.tools.console.SnmpRequest class directly from java. On Tue, Aug 17, 2010 at 8:36 AM, Tsiyona wrote: > Hello, > > I am trying to write a simple snmp manager that listens to traps on port > 162 > and processes them. This manager will only handle traps, and does not need > to send commands to agents. > > Attached is the code I wrote. It is straightforward, but it does not work - > I do not get any snmp traps. > I make sure that the snmp agent really constantly generates traps, by using > a network sniffer, so my > problem is not lack of traps on the agent side. I am probably doing > something wrong. > > Can anyone please help me? > > Thanks, > Tsiyona > > > > - >My code: > > - > > package snmpmanager; > > import java.io.IOException; > > import org.snmp4j.CommandResponder; > import org.snmp4j.CommandResponderEvent; > import org.snmp4j.PDU; > import org.snmp4j.Snmp; > import org.snmp4j.TransportMapping; > import org.snmp4j.smi.UdpAddress; > import org.snmp4j.transport.DefaultUdpTransportMapping; > import org.snmp4j.transport.TransportMappings; > > /** > * A Simple Trap receiver using snmp4j. > */ > public class SnmpClient > { > > public static final String TRAP_ADDRESS = "127.0.0.1/162";//"udp: > 127.0.0.1/162"; > private TransportMapping transport; > private String listeningAddress; > private Snmp snmp; > > public SnmpClient(String address) > { > this.listeningAddress = address; > try { > start(); > } catch (IOException e) { > e.printStackTrace(); > throw new RuntimeException(e); > } > } > > private void start() throws IOException > { > UdpAddress udpAddress = new UdpAddress(this.listeningAddress); > transport = new DefaultUdpTransportMapping(udpAddress); > snmp = new Snmp(transport); > transport.listen(); > CommandResponder pduHandler = new CommandResponder() { > public synchronized void processPdu(CommandResponderEvent e) { > PDU pdu = e.getPDU(); > if (pdu != null) { > System.out.println(pdu); > } > } > }; > snmp.addCommandResponder(pduHandler); > } > public void stop() throws IOException > { > snmp.close(); > } > > public static void main(String[] args) > { > SnmpClient client = new SnmpClient(TRAP_ADDRESS); > System.out.println("Listening for traps on address " + TRAP_ADDRESS); > } > } > > ___ > SNMP4J mailing list > SNMP4J@agentpp.org > http://lists.agentpp.org/mailman/listinfo/snmp4j > > ___ SNMP4J mailing list SNMP4J@agentpp.org http://lists.agentpp.org/mailman/listinfo/snmp4j
[SNMP4J] A Simple Trap Receiver using snmp4j
Hello, I am trying to write a simple snmp manager that listens to traps on port 162 and processes them. This manager will only handle traps, and does not need to send commands to agents. Attached is the code I wrote. It is straightforward, but it does not work - I do not get any snmp traps. I make sure that the snmp agent really constantly generates traps, by using a network sniffer, so my problem is not lack of traps on the agent side. I am probably doing something wrong. Can anyone please help me? Thanks, Tsiyona - My code: - package snmpmanager; import java.io.IOException; import org.snmp4j.CommandResponder; import org.snmp4j.CommandResponderEvent; import org.snmp4j.PDU; import org.snmp4j.Snmp; import org.snmp4j.TransportMapping; import org.snmp4j.smi.UdpAddress; import org.snmp4j.transport.DefaultUdpTransportMapping; import org.snmp4j.transport.TransportMappings; /** * A Simple Trap receiver using snmp4j. */ public class SnmpClient { public static final String TRAP_ADDRESS = "127.0.0.1/162";//"udp: 127.0.0.1/162"; private TransportMapping transport; private String listeningAddress; private Snmp snmp; public SnmpClient(String address) { this.listeningAddress = address; try { start(); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } } private void start() throws IOException { UdpAddress udpAddress = new UdpAddress(this.listeningAddress); transport = new DefaultUdpTransportMapping(udpAddress); snmp = new Snmp(transport); transport.listen(); CommandResponder pduHandler = new CommandResponder() { public synchronized void processPdu(CommandResponderEvent e) { PDU pdu = e.getPDU(); if (pdu != null) { System.out.println(pdu); } } }; snmp.addCommandResponder(pduHandler); } public void stop() throws IOException { snmp.close(); } public static void main(String[] args) { SnmpClient client = new SnmpClient(TRAP_ADDRESS); System.out.println("Listening for traps on address " + TRAP_ADDRESS); } } ___ SNMP4J mailing list SNMP4J@agentpp.org http://lists.agentpp.org/mailman/listinfo/snmp4j