Sending Notifications

 

Sending notifications are normally the functions of the SNMP agents. This functionality should be used only for testing and simulating purposes. A full-fledged notification functionality is the responsibility of the agent.

 

Using High-Level API explains the usage of high-level API in sending SNMP notifications.

 

Using Low-Level API explains the usage of low-level API in sending SNMP notifications.

 

Using High-Level API

 

To send notifications, we can use the snmpSendNotification() method of SnmpTarget class. Following are the steps involved in sending notifications.

 

//instantiate the SnmpTarget bean

SnmpTarget target = new SnmpTarget();

target.settargetHost("hostname");

 

//set the Target Port on which the target host would be listening to receive traps.

target.setTargetPort(162)

 

//Set the SNMP version.

target.setSnmpVersion(target.VERSION2C);

 

//Set the community.

target.setCommunity(community)

 

//Set the oids for snmpTrapOID and sysUpTime

//Send the SNMP v2 Trap

String values[] = {"testing"}

target.snmpSendNotification(1000,trapOID, values);

 

View the complete example present in <tutorials/highlevelapi/Sendv2Trap.java>.

 

Using Low-Level API

 

Following are the steps involved in sending notifications.

 

/Instantiate an SnmpPDU class

SnmpPDU pdu = new SnmpPDU();

 

//Set the SNMP command on the SnmpPDU class as v1 trap

SnmpAPI api = new SnmpAPI();

UDPProtocolOptions option = new UDPProtocolOptions(remoteHost);

pdu.setProtocolOptions(option);

 

//Build SNMPv2c trap

pdu.setCommand(SnmpAPI.TRP2_REQ_MSG);

 

//Add the Up time variable binding - mandatory

SnmpOID oid = new SnmpOID(".1.3.6.1.2.1.1.3.0");

SnmpVar var = SnmpVar.createVariable(systemuptime, SnmpAPI.TIMETICKS);

...

SnmpVarBind varbind = new SnmpVarBind(oid,var);

pdu.addVariableBinding(varbind);

 

//Add the Trap OID variable binding - mandatory

oid = new SnmpOID(".1.3.6.1.6.3.1.1.4.1.0");

var = SnmpVar.createVariable(trapoidvalue,SnmpAPI.OBJID);

...

SnmpVarBind varbind = new SnmpVarBind(oid,var);

pdu.addVariableBinding(varbind);

 

//Add additional variable bindings, if required

 

//Send the Trap PDU

SnmpSession session = new SnmpSession(api);

session.open();

session.send(pdu);

 

View the complete example present in <tutorials/lowlevelapi/Sendv2cTrap.java>.

 

 



Copyright © 1996-2006, AdventNet Inc. All Rights Reserved.