[SNMP4J] sending traps with snmp4j

Eddy Czitrom eddyone at gmail.com
Mon Aug 4 11:51:58 CEST 2008


Hi all,

This is my first post in the list, so how is every body doing ? :-)

I am using the SnmpRequest.java example of snmp4j to send GET requests. I am
trying to use the same example for sending traps.
The trap is being sent, but The thing is I get NullPointerEception on
snmp.close in the send method, and I don't know why.

I will appreciate any help or suggestion,

Thanks in advance,
Eddy

this is the simple calling method:
*

public* *static* *void* internalTrap()

{

String[] snmpArgs = *new* String[9];

snmpArgs[0] = "-c";

snmpArgs[1] = "public";

snmpArgs[2] = "-v";

snmpArgs[3] = "2c";

snmpArgs[4] = "-p";

snmpArgs[5] = "TRAP";

snmpArgs[6] = "-Ct";

snmpArgs[7] = "1.3.6.1.6.3.1.1.5.1.";

snmpArgs[8] = "127.0.0.1/162";

*snmpRequest*(snmpArgs);

}

This is the send method:


*

public* PDU send() *throws* IOException {

Snmp snmp = createSnmpSession();

*this*.target = createTarget();

target.setVersion(version);

target.setAddress(address);

target.setRetries(retries);

target.setTimeout(timeout);

target.setMaxSizeRequestPDU(maxSizeResponsePDU);

snmp.listen();

PDU request = createPDU(target);

*if* (request.getType() == PDU.*GETBULK*) {

request.setMaxRepetitions(maxRepetitions);

request.setNonRepeaters(nonRepeaters);

}

*for* (*int* i=0; i<vbs.size(); i++) {

request.add((VariableBinding)vbs.get(i));

}

PDU response = *null*;

*if* ((operation == *WALK*) || (operation == *SNAPSHOT_CREATION*)) {

ArrayList snapshot = *null*;

*if* (operation == *SNAPSHOT_CREATION*) {

snapshot = *new* ArrayList();

}

walk(snmp, request, target, snapshot);

*if* (snapshot != *null*) {

createSnapshot(snapshot);

}

*return* *null*;

}

*else* {

ResponseEvent responseEvent;

*long* startTime = System.*currentTimeMillis*();

responseEvent = snmp.send(request, target);

*if* (responseEvent != *null*) {

response = responseEvent.getResponse();

IccMain.*getIccLogger*().debug("Received response after "+

(System.*currentTimeMillis*()-startTime)+" millis");

}

}

snmp.close();

*return* response;

}



More information about the SNMP4J mailing list