[SNMP4J] how i use snmp4j in my application...

Deon van der Merwe dvdm at truteq.co.za
Fri Oct 21 15:22:50 CEST 2005


Hi Jay,

At 09:08 AM 10/21/2005, janmejay kumar vishwakarma wrote:
>
>Hi,
>
>I am new to snmp and i don't have much idea about snmp.
>And i want to use SNMP4J to send my application message via snmp.
>application message means any problem which arise in application,let 
>say server goes down than at that time i want to send message server 
>goes down now please check your server.
>So i want to send this message ..
>
>So guide me what i need to do..
>
>Please Help me On that.

The message that you want to send from your application is a TRAP message.
You will also need a service that will receive/accept the TRAP message.

Here is snippet example of sending a SNMPv1 TRAP message:


   protected org.snmp4j.Snmp mSnmp = null;


   org.snmp4j.TransportMapping vTransport = new 
org.snmp4j.transport.DefaultUdpTransportMapping();
   mSnmp = new org.snmp4j.Snmp(vTransport);
   vTransport.listen();
   mCommunityTarget.setCommunity(new 
org.snmp4j.smi.OctetString("yourcommunitystring"));
   mCommunityTarget.setAddress(new 
org.snmp4j.smi.UdpAddress(java.net.InetAddress.getByName("yourTrapServerAddress"), 
"YourTrapServerPort"));
   mCommunityTarget.setRetries(4);
   mCommunityTarget.setTimeout(4096);
   mCommunityTarget.setVersion(org.snmp4j.mp.SnmpConstants.version1);



     org.snmp4j.PDUv1 vTrapPdu = new org.snmp4j.PDUv1();
     vTrapPdu.setType(org.snmp4j.PDU.V1TRAP);
     vTrapPdu.setGenericTrap(6);
     vTrapPdu.setSpecificTrap(org.snmp4j.PDUv1.ENTERPRISE_SPECIFIC);
     vTrapPdu.setEnterprise(new org.snmp4j.smi.OID("yourOID"));
     vTrapPdu.setTimestamp((long)(java.lang.System.currentTimeMillis() 
- mStartTime)/10l);
     vTrapPdu.add(new org.snmp4j.smi.VariableBinding(new 
org.snmp4j.smi.OID("yourOID"), new org.snmp4j.smi.OctetString("your 
message")));
     mSnmp.send(vTrapPdu, mCommunityTarget);



>Thanks in Advance.
>
>With Regards,
>jay....
>
>
>_______________________________________________
>SNMP4J mailing list
>SNMP4J at agentpp.org
>http://lists.agentpp.org/mailman/listinfo/snmp4j


-Deon
_____________________________________________________
TruTeq Wireless (Pty) Ltd.  | Tel: +27 (0)12 667 1530
http://www.truteq.co.za     | Fax: +27 (0)12 667 1531
Wireless communications for remote machine management




More information about the SNMP4J mailing list