org.apache.log4j.ext
Class NetSnmpCommandLineTrapSender

java.lang.Object
  extended by org.apache.log4j.ext.NetSnmpCommandLineTrapSender
All Implemented Interfaces:
SnmpTrapSenderFacade

public class NetSnmpCommandLineTrapSender
extends java.lang.Object
implements SnmpTrapSenderFacade

Title: NetSnmpCommandLineTrapSender

Description: This class makes use of the NetSNMP snmptrap utility to send traps that implement the underlying SNMP protocol(s).

NOTE: this class is intended primarily as a "proof-of-concept", and to serve as an example of a possible usage of a command line trap sending utility with the appender. This class is not intended for production-grade environments!

You can get a copy of NetSNMP here.

You will need a copy of the library (e.g. "snmptrap.exe" and "libsnmp.dll" on Win32 platforms, at a minimum) to use this class.

This sender launches a separate process, calling the NetSnmp utility "snmptrap" to send a trap. Because this sender's job is to start an operating system process, it needs to know things that are not readily available to it via the normal avenues open to a Log4J Appender. In particular, it needs to know the location of the NetSnmp binaries (the file system path), and the path to the MIB files used by NetSnmp. You communicate this information to the sender using Java System Properties.

The path to the NetSnmp binaries is set via the property "log4j.ext.snmpTrapAppender.netSnmp.binPath". If not set, the sender defaults to a value of "/usr/local/bin/".

The path to the NetSnmp MIBs is set via the property "log4j.ext.snmpTrapAppender.netSnmp.mibsPath". If not set, the sender defaults to a value of "/usr/local/share/mibs".

You can also get the sender to emit some diagnostic/debugging information by setting the value of the "log4j.ext.snmpTrapAppender.netSnmp.diagnostic" property to "true".

Thus, as an example, the following options to the "java" command line set the binary path, the MIB path and the diagnostic flag for this sender:

-Dlog4j.ext.snmpTrapAppender.netSnmp.binPath="D:\\apps\\ucd-snmp-4.2.3-win32\\usr\\bin\\" -Dlog4j.ext.snmpTrapAppender.netSnmp.mibsPath="D:\\apps\\ucd-snmp-4.2.3-win32\\usr\\mibs" -Dlog4j.ext.snmpTrapAppender.netSnmp.diagnostic="true"

Version:
1.0.1
2002-11-01
changes ---
2002-12-10: mwm : minor tweaks and prettying up of code.
2003-05-24: mwm : minor changes to accomodate the changes in the SnmpTrapSenderFacade interface.
Author:
Mark Masterson (m.masterson@computer.org)
http://www.m2technologies.net/

Constructor Summary
NetSnmpCommandLineTrapSender()
           
 
Method Summary
 void addTrapMessageVariable(java.lang.String applicationTrapOIDValue, java.lang.String value)
          Adds a new Varbind to the SNMP PDU.
 void initialize(SNMPTrapAppender appender)
          This method is called to set the values of all of the class fields used as parameters to the underlying SNMP API.
 void sendTrap()
          Sends the PDU defined by the variables of the fields of this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NetSnmpCommandLineTrapSender

public NetSnmpCommandLineTrapSender()
Method Detail

initialize

public void initialize(SNMPTrapAppender appender)
Description copied from interface: SnmpTrapSenderFacade
This method is called to set the values of all of the class fields used as parameters to the underlying SNMP API. This method must be called prior to calling either of the other methods in this class.

Specified by:
initialize in interface SnmpTrapSenderFacade
Parameters:
appender - - An instance of the SNMPTrapAppender class. All of the values needed to configure the trap sender will be extracted from the Appender, via its getter methods.

addTrapMessageVariable

public void addTrapMessageVariable(java.lang.String applicationTrapOIDValue,
                                   java.lang.String value)
Description copied from interface: SnmpTrapSenderFacade
Adds a new Varbind to the SNMP PDU. The Varbind is made of the value of the application trap OID (applicationTrapOID) parameter, as the key, and the value paramater to this method as the value. A PDU has a collection of Varbind variables -- repeated calls to this method will add to that collection successively.

Specified by:
addTrapMessageVariable in interface SnmpTrapSenderFacade
Parameters:
applicationTrapOIDValue - - formatted as an OID E.g. "1.3.6.1.2.1.1.2.0.0.0.0" -- this OID would point to the standard sysObjectID of the "systemName" node of the standard "system" MIB.
This is the default value, if none is provided.
If you want(need) to use custom OIDs (such as ones from the "private.enterprises" node -- "1.3.6.1.4.1.x.x.x..."), you always need to provide the fully qualified OID as the parameter for this variable.

value - - the text to append to the Varbind that will be added to the SNMP PDU.

sendTrap

public void sendTrap()
Description copied from interface: SnmpTrapSenderFacade
Sends the PDU defined by the variables of the fields of this class. This method should always be called last by an application, after having called the initialization() method once, and the addTrapMessageVariable() method one or more times.

Specified by:
sendTrap in interface SnmpTrapSenderFacade