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 <tsiy...@gmail.com> 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

Reply via email to