0

I am getting "Incorrect Version or decode error" on manager side. I was just wondering if there is something missing with the following sample trap sender code.

public class SampleTrapSender {

         public static void main(String[] args) {

              String address = "172.27.41.101";
              String port = "162";

             address = address + "/" + port;
              System.out.println("Target adddress ...." + address);

              try{

                    Snmp snmp = new Snmp(new
                    DefaultUdpTransportMapping());

                    PDU trap = new PDU();
                    trap.setType(PDU.TRAP);

                    OID oid = new OID("1.3.6.1.4.1.4976.2.1.1.0");

                    Variable var = new OctetString("Test Message");



                     trap.add(new VariableBinding(oid, var));

                    Address targetAddress = new UdpAddress(address);
                     CommunityTarget target = new CommunityTarget();
                     target.setCommunity(new OctetString(""));
                     target.setVersion(SnmpConstants.version2c);
                     target.setAddress(targetAddress);

                     snmp.send(trap, target, null, null);
                     System.out.println("DONE......");

               }catch(IOException exception){
                    exception.printStackTrace();
               }

         }
}
MByD
  • 135,866
  • 28
  • 264
  • 277
santro
  • 373
  • 1
  • 6
  • 22

1 Answers1

0

Try with,

PDUv1 pdu = new PDUv1();

I think your code is right. But you can try using my code:

try {
            Address targetAddress = GenericAddress.parse("udp:"+serverIp+"/162");
            TransportMapping    transport = new DefaultUdpTransportMapping();
            transport.listen();
            Snmp snmp = new Snmp(transport);

            CommunityTarget target = new CommunityTarget();
            target.setCommunity(new OctetString("public"));
            target.setAddress(targetAddress);
            target.setVersion(SnmpConstants.version2c);

            PDUv1 pdu = new PDUv1();
            pdu.setType(PDU.TRAP);

            OID trap = new OID("1.3.6.1.6.3.1.1.4.1.0");
            VariableBinding vb = new VariableBinding();
            vb.setOid(trap);
            vb.setVariable(new OctetString("1.3.6.1.4.1.9.9.46.2.0.11"));//11,10
            pdu.add(vb);


            VariableBinding vb2 = new VariableBinding();
            vb2.setOid(new OID("1.3.6.1.4.1.9.9.46.1.3.1.1.4.1.80"));
            vb2.setVariable(new OctetString("VLAN0080"));
            pdu.add(vb2);

            snmp.send(pdu, target);         
} catch (IOException e) {
            e.printStackTrace();
}

I hope it will help.

Nikunj
  • 3,100
  • 2
  • 20
  • 19