[SNMP4J] Not able to generate the Trap

gaurava.singhal at wipro.com gaurava.singhal at wipro.com
Wed Jul 11 11:07:48 CEST 2007


Hi,
 
I have written the following program to generate the trap. Can somebody
please point me the problem in the code, as there are no runtime and
compile time error. But I am not able to recieve the trap on another
SNMP listener program.
 
 
 
import java.io.IOException;

import org.snmp4j.Snmp;

import org.snmp4j.TransportMapping;

import org.snmp4j.agent.DefaultMOServer;

import org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl;

import org.snmp4j.agent.mo.snmp.SnmpNotificationMIB;

import org.snmp4j.agent.mo.snmp.SnmpTargetMIB;

import org.snmp4j.agent.mo.snmp.StorageType;

import org.snmp4j.agent.mo.snmp.TransportDomains;

import org.snmp4j.agent.mo.snmp.VacmMIB;

import org.snmp4j.agent.mo.snmp.SNMPv2MIB.SysUpTimeImpl;

import org.snmp4j.mp.MPv3;

import org.snmp4j.mp.MessageProcessingModel;

import org.snmp4j.mp.SnmpConstants;

import org.snmp4j.security.SecurityLevel;

import org.snmp4j.security.SecurityModel;

import org.snmp4j.security.SecurityModels;

import org.snmp4j.security.SecurityProtocols;

import org.snmp4j.security.USM;

import org.snmp4j.smi.OID;

import org.snmp4j.smi.OctetString;

import org.snmp4j.smi.UdpAddress;

import org.snmp4j.smi.VariableBinding;

import org.snmp4j.transport.DefaultUdpTransportMapping;

public class TestNotificationGenerator {

SnmpNotificationMIB snmpNotificationMibObj;

SnmpTargetMIB snmpTargetMibObj;

NotificationOriginatorImpl notifOrignator;

Snmp snmp;

SysUpTimeImpl sysUpTime=new SysUpTimeImpl();

// VacmMIB vacmMIB=new VacmMIB();

void addNotifTargets(SnmpTargetMIB targetMIB,

SnmpNotificationMIB notificationMIB) {

targetMIB.addDefaultTDomains();

targetMIB.addTargetAddress(new OctetString("notification"),

TransportDomains.transportDomainUdpIpv4,new OctetString(new
UdpAddress("192.168.220.29/162").getValue()),

200, 1,new OctetString("notify"),new
OctetString("v2c"),StorageType.permanent);

targetMIB.addTargetParams(new
OctetString("v2c"),MessageProcessingModel.MPv2c,

SecurityModel.SECURITY_MODEL_SNMPv2c,new OctetString("SHADES"),

SecurityLevel.NOAUTH_NOPRIV,StorageType.permanent);

notificationMIB.addNotifyEntry(new OctetString("default"),new
OctetString("notify"),

SnmpNotificationMIB.SnmpNotifyTypeEnum.trap,StorageType.permanent);

}

void generateNotification(){

TransportMapping transport;

try {

transport = new DefaultUdpTransportMapping();

snmp = new Snmp(transport);

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

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

//SecurityModels.getInstance().addSecurityModel(usm);

SecurityProtocols.getInstance().addDefaultProtocols();

snmpNotificationMibObj=new SnmpNotificationMIB();

snmpTargetMibObj=new SnmpTargetMIB(snmp);

addNotifTargets(snmpTargetMibObj, snmpNotificationMibObj);

notifOrignator=new NotificationOriginatorImpl(snmp,new VacmMIB(new
DefaultMOServer()),sysUpTime,snmpTargetMibObj,snmpNotificationMibObj);

VariableBinding [] varBind= new VariableBinding[3];

varBind[0]=new VariableBinding(new OID("1.0.2.3.4"),new
OctetString("Hello"));

notifOrignator.notify(new OctetString("v2c"),SnmpConstants.coldStart,new
VariableBinding[0]);

notifOrignator.notify(new OctetString("v2c"),new
OID("1.2.3.4.5"),varBind);

/*byte[] b={1,0,1,0};

transport.sendMessage(new UdpAddress("192.168.220.29/162"), b);*/

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

public static void main(String[]args){

TestNotificationGenerator testGen=new TestNotificationGenerator();

testGen.generateNotification();

}

}

 

Regards

Gaurav




The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
 
www.wipro.com


More information about the SNMP4J mailing list