0

I use snmp4j ver 1.10.1 from org.snmp4j and this is my trap receiver code to catch data from snmp trap.

public class TrapReceiver extends Thread implements CommandResponder {

//@Autowired
private CarService carService;
List<PDUv1> listPdu = new ArrayList<PDUv1>();
List<PDUv1> temp = new ArrayList<PDUv1>();  
String message = "";
int totReceivedTrap = 0;

public TrapReceiver(CarService carService){
    this.carService = carService;
}

public synchronized void processPdu(CommandResponderEvent cmdRespEvent) {
    PDUv1 pdu = (PDUv1) cmdRespEvent.getPDU();
    if (pdu != null) {
        System.out.println(pdu.getVariableBindings().toString());           
    }
    totReceivedTrap++;
    System.out.println("total received trap "+totReceivedTrap);
}

public void run() {
    while (true) {
        try { 
            this.listen(new UdpAddress("192.168.1.5/162")); //alamat PDU akan listen
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }
}

public synchronized void listen(TransportIpAddress address) throws IOException {
    AbstractTransportMapping transport;
    if (address instanceof TcpAddress) {
        transport = new DefaultTcpTransportMapping((TcpAddress) address);
    } else {
        transport = new DefaultUdpTransportMapping((UdpAddress) address);
    }

    ThreadPool threadPool = ThreadPool.create("DispatcherPool", 10);
    MessageDispatcher mDispathcher = new MultiThreadedMessageDispatcher(
            threadPool, new MessageDispatcherImpl());

    // add message processing models
    mDispathcher.addMessageProcessingModel(new MPv1());
    mDispathcher.addMessageProcessingModel(new MPv2c());

    // add all security protocols
    SecurityProtocols.getInstance().addDefaultProtocols();
    SecurityProtocols.getInstance().addPrivacyProtocol(new Priv3DES());

    // Create Target
    CommunityTarget target = new CommunityTarget();
    target.setCommunity(new OctetString("public"));

    Snmp snmp = new Snmp(mDispathcher, transport);
    snmp.addCommandResponder(this);

    transport.listen();
    message ="Listening on " + address;
    System.out.println(message);

    try {
        this.wait();
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
    }
}

public String getMessage(){
    return this.message;
}   
}

But one variable value is missing, the value of this variable is latitude and longitude (format : -903849323.20384;+230349402.03000). And when i catch the data using wireshark, I got the value is missing too.

The screenshot http://www.mediafire.com/view/?kjz1drb9jhda88a http://www.mediafire.com/view/?ov6lqn6u9n669my

Why the data is null, what wrong.

Mahadi Siregar
  • 615
  • 3
  • 17
  • 38

1 Answers1

1

If you do not see the value inside the packet captured by wireshark, then it is completely valid that you get the null value in the code. What else would you expect?

This seems to be more likely a problem/feature of the SNMP agent running on the device (e.g. geo location was not set, GPS signal is not available, etc.)

L.R.
  • 977
  • 6
  • 22