I've been trying to query a Motorola device but am not having much luck. I wrote a small test application to send a get request and read the response but the response object is null. I ran a tcpdump and can see both the request and response messages over the wire. Thus it has something to do with the way the code is listening for the packets. I followed the suggestions in the javadocs and invoke snmp.listen() before I call the get method. The code looks something like the following:

        /**
         * @param args
         */
        public static void main(String[] args) throws Exception {
                LogFactory.setLogFactory(new Log4jLogFactory());

                String community = "opennms-Priv";
                String address = "xx.xx.xx.xx/161";   // <<< hide the IP address
                String strOID = "1.3.6.1.4.1.161.19.3.1.4.1.26.3";

                
                CommunityTarget target = new CommunityTarget();
                target.setCommunity(new OctetString(community));
                Address targetAddress = new UdpAddress(address);
                target.setAddress(targetAddress);
                target.setVersion(SnmpConstants.version2c);
                target.setRetries(0);
                target.setTimeout(4000);

                TransportMapping transport = new DefaultUdpTransportMapping();
                Snmp snmp = new Snmp(transport);
                snmp.listen();

                
                PDU pdu = new PDU();
                pdu.add(new VariableBinding(new OID(strOID)));
                pdu.setType(PDU.GET);

                ResponseEvent response = snmp.get(pdu, target);

                if (response.getResponse() == null) {
                        // request timed out
                        System.out.println("request timed out!");

                } else {
                        System.out.println("Received response from: "
                                        + response.getPeerAddress());
                        // dump response PDU
                        System.out.println(response.getResponse().toString());
                }
                snmp.close();
        }

I'm debugging the code from within Eclipse 3.4.1 using JDK 1.5 on MacOS X Leopard. Thanks for any help you may provide.

Cheers,
Mark


_______________________________________________
SNMP4J mailing list
[email protected]
http://lists.agentpp.org/mailman/listinfo/snmp4j

Reply via email to