[SNMP4J] SENDING TRAPS

snmp girl snmp.girl at gmail.com
Tue Apr 15 11:25:46 CEST 2008


Hello,

I am using the snmp4j api for my programme to use it in order to send traps
from my program, but something is wrong in my code , and I didn't arrive to
know it
this is my code


import org.snmp4j.*;
import org.snmp4j.event.*;
import org.snmp4j.smi.*;
import org.snmp4j.transport.*;
import java.io.*;
import org.snmp4j.CommunityTarget;
import org.snmp4j.util.*;

public class Test
{
    public static void main(String[] args)throws IOException {
        // TODO code application logic here
        CommunityTarget target = new CommunityTarget();
        Address targetaddress = new UdpAddress("172.17.200.19/161");
        target.setAddress(targetaddress);
        target.setCommunity(new OctetString("public"));
        target.setTimeout (1000);
        target.setVersion(0);
        target.setRetries(1);

       PDU pdu = new PDU();
       pdu.setType(PDU.V1TRAP);



       pdu.add(new VariableBinding(new OID(".1.3.6.1.2.1.25.3.3.1.2")));
       TransportMapping transport = new DefaultUdpTransportMapping();
       transport.listen();
       try
       {

           Snmp snmp = new Snmp(transport);

           ResponseEvent respEv = snmp.send(pdu, target);

           PDU response = respEv.getResponse();



       }

       catch (Exception e)
       {
           System.out.println("Errror in snmp");
       }
      }
}



More information about the SNMP4J mailing list