[SNMP4J] trap doubt

Debakanta Behera bdebakanta at gmail.com
Mon Jul 2 13:05:33 CEST 2007


Hello everybody,

 In the  trap program :

I am not able to receive any trap message , also which addresses are to be
passed to .....parse(System.getProperty()) method.

I have anoter dout also: This program is running in my local system. should
I configure my local machine's  IP in the agent as for trap destination.....



Please clear my doubt........



waiting for the reply.....



*public* *class* receiveTrap *implements* CommandResponder {

*private* *void* init() *throws* UnknownHostException,IOException {

threadPool = ThreadPool.*create*("Trap", 2);

dispatcher = *new*
MultiThreadedMessageDispatcher(threadPool,*new*MessageDispatcherImpl());

*listenAddress** = GenericAddress.parse(System.getProperty("address of what
?", "address of what ?"));*

/* 1st address is the address of what and second for ?*/

// listenAddress = GenericAddress.parse(System.getProperty(address ,"udp:
0.0.0.0/162"));

TransportMapping transport;

*if* (listenAddress *instanceof* UdpAddress) {

transport = *new* DefaultUdpTransportMapping((UdpAddress)listenAddress);}

*else* {transport = *new* DefaultTcpTransportMapping((TcpAddress)
listenAddress);}

snmp = *new* Snmp(dispatcher, transport);

snmp.getMessageDispatcher().addMessageProcessingModel(*new* MPv1());

snmp.getMessageDispatcher().addMessageProcessingModel(*new* MPv2c());

snmp.getMessageDispatcher().addMessageProcessingModel(*new* MPv3());

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

*new* OctetString(((MPv3)snmp.getMessageProcessingModel(

MessageProcessingModel.*MPv3*)).*createLocalEngineID*()), 0);

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

snmp.listen();}

*public* *void* run() {*try* {

init();

snmp.addCommandResponder(*this*);

}*catch* (Exception ex) {

ex.printStackTrace();}}

*public* *void* processPdu(CommandResponderEvent event) {

*if* (start < 0) {

start = System.*currentTimeMillis*()-1;}

System.*out*.println(event.toString());

n++;

*if* ((n % 100 == 1)) {

System.*out*.println("Processed " +(n / (*double*)(System.*currentTimeMillis
*() - start)) * 1000 +"/s, total="+n);}}

*public* *static* *void* main(String[] args) {

receiveTrap trapreceiver = *new* receiveTrap();

trapreceiver.run();}}



More information about the SNMP4J mailing list