Send a SNMP Trap

T

tmcsc

hy,
I'm using wengsoft snmp implementation to send a snmp trap. But the
information sent by the trap isn't as I would expect.

My code:
static void sendTrap(String contextID, String contextName)
throws java.io.IOException {
// Create SNMP message object, it may contain one of the following
// protocol data unit : GET, SET, TRAP, GET-NEXT.
snmpMessage = new SnmpMessage();

// create a Set Protocol Data Unit.
trapPdu = new SnmpGetSetPdu();
trapPdu.setMsgType(AsnObject.SNMPV2_TRAP);
trapPdu.setReqId(1);


snmpMessage.setPdu(trapPdu);
snmpMessage.setSnmpVersion(3);

//snmpMessage.setUserName ("SLCC".getBytes());

snmpMessage.setEncryptionMode(false);
snmpMessage.setAuthMode(false); //true
//snmpMessage.setAuthAlgorithm (SecurityInterface.SHA);
//snmpMessage.setAuthPassword ("testtest".getBytes ());

// Remove temporary
// snmpMessage.setEncryptionMode (true);
// snmpMessage.setEncryptPassword ("testtest".getBytes ());

snmpMessage.setContextEngineID(contextID);
snmpMessage.setContextName(contextName);

// Add system up time.
trapPdu.addNameValuePair(new AsnNameValuePair("1.3.6.1.2.1.1.3",
new AsnInteger(999)));

// Add trap OID
trapPdu.addNameValuePair(new AsnNameValuePair("1.3.6.1.6.3.1.1.4.1",
new AsnOID("1.3.6.1.4.1.8888.100")));

// Add trap message 1
trapPdu.addNameValuePair ( new AsnNameValuePair
("1.3.6.1.4.1.8888.100.1.1.0", new AsnInteger(1)));

/*
// Add trap message 2 trapPdu.addNameValuePair ( new
AsnNameValuePair ("1.3.6.1.4.1.8888.100.1.3.0", new
AsnOctets("dummy"));

// Add trap message 3 trapPdu.addNameValuePair ( new
AsnNameValuePair ("1.3.6.1.4.1.8888.100.1.4.0", new AsnOctets("test
message 1"));
// Add trap message 4 trapPdu.addNameValuePair ( new
AsnNameValuePair ("1.3.6.1.4.1.8888.100.1.5.0", new AsnOctets("test
message 2"));
// Add enterprise OID trapPdu.addNameValuePair ( new
AsnNameValuePair ("1.3.6.1.6.3.1.1.4.3", new AsnOID
("1.3.6.1.4.1.8888"));
*/
System.out.println("Sending ... ");
SnmpClient client = new SnmpClient();
client.sendSnmpMessage(defaultIP, defaultPort, snmpMessage);
//System.out.println(snmpMessage);
System.out.println("... finished");
}

=================================== End
=====================================

the result is:
20050928 151756 SNMP 127.0.0.1 Int:3 Int:0 Int:484 00 Int:3
01104000201000204433a9804040004000400 firstPart secondPart

The first two integers are okay - also the last two Strings: firstPart
and secondPart. But I also want to be able to change the other
information (starting with Int:3 Int:0 .... 4000400).

Has anyone a solution?

best regards
tmcsc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,470
Messages
2,571,807
Members
48,797
Latest member
PeterSimpson
Top