[SNMP4J] Using SNMP4J in a java program
Neil Cohen
ncohen at verisign.com
Mon Feb 28 20:28:52 CET 2011
Hi,
I am writing a Java program which needs to send SNMP traps to a remote
server. This is a one-way communication - I'm sending the traps but not
expecting to receive a response. Right now, I'm using snmp v1.
Can someone point me at some simple example code that will do this?
Right now, we fork a shell script which runs a command like this:
/usr/local/bin/snmptrap -v 1 -c public mysourcehost enterprises.1.2.3
11.22.33.44 6 1 '' enterprises.1.2.3.4.5.6 s "the text of the trap goes
here...."
I would like to use snmp4j to replace the shell script and just generate
the trap.
I'm an expert Java programmer, but not particularly experienced with SNMP.
So far, I have started with this:
private void sendTrap(String alertMsg){
PDUv1 pdu = new PDUv1();
pdu.setAgentAddress(new IpAddress("1.1.1.1"));
pdu.setSpecificTrap(6);
pdu.setGenericTrap(1);
pdu.setEnterprise(new OID("1.2.3"));
Logger.info("SNMP: " + pdu.toString());
}
This prints at least some of the information I need to send. I think I
need to create a Target and set things like the destination address and
community string. But then how do I send the trap itself? The only
example I've seen so far looked like it needed a listener, and I'm not
expecting any response (or am I)??
Thanks in advance,
nbc
--
NAME: Neil B. Cohen (Verisign Inc.)
PHONE: 703-948-4471
DOMAIN: ncohen at verisign.com
**********************************************************
* Murphy's Philosophy: Smile - tomorrow will be worse...
*
* O'Tooles Commentary: Murphy was an optimist!
**********************************************************
More information about the SNMP4J
mailing list