[SNMP4J] getting responseing snmp4j

Shweta shweta_naik at persistent.co.in
Tue Jul 15 12:39:56 CEST 2008


Its ok

But tell wht shd I use INFORM is not suppoted then

I tried this code also

 

Address targetAddress = GenericAddress.parse("udp:localhost/162");

               TransportMapping transport;

               Snmp snmp = null;

            try {

                  transport = new DefaultUdpTransportMapping();

                  

                   snmp = new Snmp(transport);

                   USM usm = new USM(SecurityProtocols.getInstance(),

                                       new
OctetString(MPv3.createLocalEngineID()), 0);

                     SecurityModels.getInstance().addSecurityModel(usm);

                     transport.listen();

                     // add user to the USM

                     snmp.getUSM().addUser(new OctetString("MD5DES"),

                                           new UsmUser(new
OctetString("MD5DES"),

                                                       AuthMD5.ID,

                                                       new
OctetString("MD5DESUserAuthPassword"),

                                                       PrivDES.ID,

                                                       new
OctetString("MD5DESUserPrivPassword")));

            

               

 

            

            

             

               // create the target

                   //CommunityTarget target = new CommunityTarget();

                  // target.setCommunity(new OctetString("public"));

            UserTarget target = new UserTarget();

               target.setAddress(targetAddress);

               target.setRetries(1);

               target.setTimeout(5000);

               target.setVersion(SnmpConstants.version1);

             target.setSecurityLevel(SecurityLevel.AUTH_PRIV);

               target.setSecurityName(new OctetString("MD5DES"));

 

               // create the PDU

               PDU pdu = new ScopedPDU();

               

               pdu.setType(PDU.GETNEXT);

               VariableBinding vb = new VariableBinding();

                  vb.setOid(new OID(".1.3.6.1.2.1.1.1.0"));

                  vb.setVariable(new OctetString("This is just test trap"));

                  pdu.add(vb);

               //pdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.1.0")));

              

 

               System.out.println("next is............"+pdu);

               // send the PDU

               ResponseEvent response;

            //try {

                  response = snmp.send(pdu, target,transport);

                  PDU responsePDU = response.getResponse();

                  // extract the address used by the agent to send the
response:

                     Address peerAddress = response.getPeerAddress();

                     System.out.println("so peeraddress........"+response);

                     snmp.close();

            //}

 

 

But it gives me Message Exception..

Waiting fro reply

 

Thanks,

Shweta Naik.

  _____  

From: Tayyab Akram [mailto:mail.tayyab at gmail.com] 
Sent: Tuesday, July 15, 2008 3:49 PM
To: Shweta
Cc: snmp4j at agentpp.org
Subject: Re: [SNMP4J] getting responseing snmp4j

 

Hi Shweta,

[Sorry for duplicate reply. I forgot to add mailing list in CC in previous
message]

There is nothing wrong with your code except that you are expecting the
response of a V1TRAP.
SNMP Version-1 only supports TRAPs and these traps are not acknowledged. So
when the Trap Listener receives your trap it will not send any response.

If you want to use acknowledged traps where you get the response from the
Trap Listener, then you have to use the Version-2c or Version-3 of SNMP.
These are called INFORMS.

Or in simple words INFORM is acknowledged TRAP and is not supported in SNMP
Version-1.

Regards,
--Muhammad Tayyab





On Tue, Jul 15, 2008 at 3:19 PM, Shweta <shweta_naik at persistent.co.in>
wrote:

HI all, I facing one problem tht getting response always null

I tried following code, when I print response that shows me null but if I
run this code & check in the runnig tool on my machin i.e in trap receiver I
able to seen mag

But I want to handle response programmatically but it showing me null









                       Address targetAddress = GenericAddress.parse("udp:"
+ "localhost"

                                               + "/162");

                       CommunityTarget target = new CommunityTarget();

                       target.setCommunity(new OctetString("public"));

                       target.setAddress(targetAddress);

                       target.setRetries(1);

                       target.setTimeout(2000);

                       target.setVersion(SnmpConstants.version1);

                       PDUv1 pdu1 = new PDUv1();

                       pdu1.setGenericTrap(PDUv1.COLDSTART);

                       pdu1.setSpecificTrap(Integer.parseInt(("0")));

                       pdu1.setEnterprise(new org.snmp4j.smi.OID());

                       //pdu1.setEnterprise(new OID(".1.3.6.1.2.1.1.1.0"));

                       pdu1.setType(PDUv1.V1TRAP);



                       VariableBinding vb = new VariableBinding();

                       vb.setOid(new OID(".1.3.6.1.2.1.1.1.0"));

                       vb.setVariable(new OctetString("This is just test
trap"));

                       pdu1.add(vb);

                       //pdu1.addOID(new VariableBinding(new
OID("1.3.6.1.2.1.1.1.0")));

                       try {

                                   //IpAddress sourceIp = new
IpAddress("10.77.200.82");

                                   IpAddress sourceIp = new
IpAddress(InetAddress.getLocalHost());

                                   pdu1.setAgentAddress(sourceIp);

                                   //System.out.println("so PDU
is......."+pdu1);



                                   DefaultUdpTransportMapping
udpTransportMap = new DefaultUdpTransportMapping();

                                   udpTransportMap.listen();

                                   Snmp snmp = new Snmp(udpTransportMap);

                                   ResponseEvent response = snmp.send(pdu1,
target,udpTransportMap);





                                   System.out.println("SnmpNotificationTrap
: pdu1: " + pdu1);

                                   System.out.println("SnmpNotificationTrap
: response: " + response.getSource());

                                   snmp.close();





                       }

                       catch (Exception e) {

                                   e.printStackTrace();



                       }





Thanks

Shweta


DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the
property of Persistent Systems Ltd. It is intended only for the use of the
individual or entity to which it is addressed. If you are not the intended
recipient, you are not authorized to read, retain, copy, print, distribute
or use this message. If you have received this communication in error,
please notify the sender and delete all copies of this message. Persistent
Systems Ltd. does not accept any liability for virus infected mails.
_______________________________________________
SNMP4J mailing list
SNMP4J at agentpp.org
http://lists.agentpp.org/mailman/listinfo/snmp4j

 


DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.



More information about the SNMP4J mailing list