org.apache.log4j.ext
public class SNMPTrapAppender extends AppenderSkeleton
This appender does not attempt to provide full access to the SNMP API. In particular, use of this appender does not make an SNMP agent out of the calling application. You cannot use this appender as an interface to do SNMP GET or SET calls -- all it does is pass on your logging event as a TRAP.
This appender uses a helper class which serves as the interface to the SNMP
sub-system. This class must implement the SnmpTrapSenderFacade interface. The
concrete implementation class you want to use must be specified in your properties
file -- see the examples below. The implementation class must provide a
parameterless constructor -- this is the constructor that Log4J will use to
instantiate the class using the class name in the properties file.
There are three implementation classes provided with this appender; the JoeSNMPTrapSender,
the WengsoftSNMPTrapSender and the NetSnmpCommandLineTrapSender classes.
If you fail to specify an implementation in your properties file, or if there
is a problem finding, loading or instantiating the implementation that you do specify,
the appender will fall back to using the JoeSNMPTrapSender implementation as a default.
You can and should, as your needs dictate, write your own implementation of SnmpTrapSenderFacade, using the underlying SNMP library of your choice. In this case, the implementations provided with the appender should serve as adequate examples for how this might be done.
Here's a sample of what you would need in an XML configuration file to configure
this appender:
Here's a sample of what you would need in a properties configuration file to
configure this appender:
log4j.appender.TRAP_LOG=org.apache.log4j.ext.SNMPTrapAppender
log4j.appender.TRAP_LOG.ImplementationClassName=org.apache.log4j.ext.JoeSNMPTrapSender
log4j.appender.TRAP_LOG.ManagementHost=127.0.0.1
log4j.appender.TRAP_LOG.ManagementHostTrapListenPort=162
log4j.appender.TRAP_LOG.EnterpriseOID=1.3.6.1.4.1.24.0
log4j.appender.TRAP_LOG.LocalIPAddress=127.0.0.1
log4j.appender.TRAP_LOG.LocalTrapSendPort=161
log4j.appender.TRAP_LOG.GenericTrapType=6
log4j.appender.TRAP_LOG.SpecificTrapType=12345678
log4j.appender.TRAP_LOG.ApplicationTrapOID=1.3.6.1.4.1.24.12.10.22.64
log4j.appender.TRAP_LOG.CommunityString=public
log4j.appender.TRAP_LOG.ForwardStackTraceWithTrap=true
log4j.appender.TRAP_LOG.Threshold=DEBUG
log4j.appender.TRAP_LOG.layout=org.apache.log4j.PatternLayout
log4j.appender.TRAP_LOG.layout.ConversionPattern=%d,%p,[%t],[%c],%m%n
Here's an example using the properties file format the uses the delimited conversion pattern
technique to allow multiple VarBinds:
log4j.appender.TRAP_LOG=org.apache.log4j.ext.SNMPTrapAppender
log4j.appender.TRAP_LOG.ImplementationClassName=org.apache.log4j.ext.JoeSNMPTrapSender
log4j.appender.TRAP_LOG.ManagementHost=127.0.0.1
log4j.appender.TRAP_LOG.ManagementHostTrapListenPort=162
log4j.appender.TRAP_LOG.EnterpriseOID=1.3.6.1.4.1.24.0
log4j.appender.TRAP_LOG.LocalIPAddress=127.0.0.1
log4j.appender.TRAP_LOG.LocalTrapSendPort=161
log4j.appender.TRAP_LOG.GenericTrapType=6
log4j.appender.TRAP_LOG.SpecificTrapType=12345678
log4j.appender.TRAP_LOG.CommunityString=public
log4j.appender.TRAP_LOG.ForwardStackTraceWithTrap=true
log4j.appender.TRAP_LOG.Threshold=DEBUG
log4j.appender.TRAP_LOG.layout=org.apache.log4j.ext.SnmpDelimitedConversionPatternLayout
log4j.appender.TRAP_LOG.layout.ValuePairDelim=/
log4j.appender.TRAP_LOG.layout.VarDelim=;
log4j.appender.TRAP_LOG.layout.ConversionPattern=
%p;1.3.6.1.4.1.24.100.1/%m;1.3.6.1.4.1.24.100.2/%C{1};1.3.6.1.4.1.24.100.3
This software is based on the log4j software provided by the Apache Jakrta log4j project. This software is released under a version of the Apache license version 1.1 -- please see the LICENSE.TXT file included with this distribution for details.
Version 1.2.9.1
2001-09-29
changes ---
2001-10-03: mwm : made changes needed to support v.1.1.1 of the SNMPTrapSenderFacade
2002-09-02: mwm : changed to be compatible with Log4J v. 1.2.x
2002-10-03: mwm : Made changes, mainly in #append, to deal with the
new SnmpTrapSenderFacade interface architecture.
2002-10-15: mwm: Included the SysUpTimeResolver contributed by Thomas Muller.
2002-10-15: mwm : changed the sysUpTime value to a long, to cope with the SysUpTimeResolver mechanism.
2002-12-10: mwm : minor tweaks and prettying up of code.
2003-03-21: mwm : incorporated the first cut of Matt Monks's code to use a delimited conversion pattern
string to allow mutliple VarBinds to be attached to the trap PDU.
2003-03-22: mwm : after reading Ceki's fine new book on Log4J, made several changes (for example, to
the implementation of #close) to correct deficiencies in this class as an implementation of
AppenderSkeleton. Also improved/added handling of the stack trace of the Throwable associated with
the LoggingEvent, again inspired by Ceki's example in the new book.
2003-03-23: mwm : building on Matt Monks's ideas, added the SnmpDelimitedConversionPatternLayout, and used
it to refactor the handling of the delimited conversion pattern case.
2003-05-24: mwm : minor changes to accomodate the change in the SnmpTrapSenderFacade interface, and added
two new properties.
2003-07-05: mwm : some improvement in the exception handling of #loadImplementationClass
Constructor Summary | |
---|---|
SNMPTrapAppender()
Default constructor. | |
SNMPTrapAppender(Layout layoutValue)
Construct the appender with the specified Layout. |
Method Summary | |
---|---|
protected void | append(LoggingEvent event)
Uses an instance of SnmpTrapSenderFacade to send the String returned by Layout.format() as the message(s)
of an SNMP trap. |
void | close()
Sets the state of the Appender to "closed". |
String | getApplicationTrapOID()
Get the trap OID that will be sent in the SNMP PDU for this app. |
String | getCommunityString()
Get the community string set for the SNMP session this appender will use. |
String | getEnterpriseOID()
Get the enterprise OID that will be sent in the SNMP PDU.
|
String | getForwardStackTraceWithTrap()
Gets the flag that determines if the contents of the stack trace of any Throwable in the LoggingEvent should be
added as VarBinds to the trap PDU. Default is FALSE. |
int | getGenericTrapType()
Get the generic trap type set for this SNMP PDU. |
String | getImplementationClassName()
Get the value of the concrete class that implements the SnmpTrapSenderFacade interface. |
String | getLocalIPAddress()
Get the IP address of the host that is using this appender to send SNMP traps. |
int | getLocalTrapSendPort()
Get the value of the port that will be used to send traps out from the local host. |
String | getManagementHost()
Get the numeric, dotted-decimal IP address of the remote host that traps will be sent to, as a String. |
int | getManagementHostTrapListenPort()
Get the port used on the remote host to listen for SNMP traps. |
int | getSpecificTrapType()
Get the specific trap type set for this SNMP PDU. |
long | getSysUpTime()
Get the value of the system up time that will be used for the SNMP PDU. |
SysUpTimeResolver | getSysUpTimeResolver()
Gets the concrete instance of an implementation of the SysUpTimeResolver interface that is being used by the
appender.
|
int | getTrapVersion() |
boolean | requiresLayout()
Implemented to return "true" . |
void | setApplicationTrapOID(String applicationTrapOIDValue)
Set the trap OID that will be sent in the SNMP PDU for this app.
|
void | setCommunityString(String communityStringValue)
Set the community string set for the SNMP session this appender will use. |
void | setEnterpriseOID(String enterpriseOIDValue)
Set the enterprise OID that will be sent in the SNMP PDU.
|
void | setForwardStackTraceWithTrap(String forwardStackTraceWithTrap)
Sets the flag that determines if the contents of the stack trace of any Throwable in the LoggingEvent should be
added as VarBinds to the trap PDU. Default is FALSE. |
void | setGenericTrapType(int genericTrapTypeValue)
Set the generic trap type for this SNMP PDU. |
void | setImplementationClassName(String implementationClassNameValue)
Set the value of the concrete class that implements the SnmpTrapSenderFacade interface.
|
void | setLocalIPAddress(String localIPAddressValue)
Set the IP address of the host that is using this appender to send SNMP traps. |
void | setLocalTrapSendPort(int localTrapSendPortValue)
Set the value of the port that will be used to send traps out from the local host.
|
void | setManagementHost(String managementHostValue)
Set the IP address of the remote host that traps should be sent to.
|
void | setManagementHostTrapListenPort(int managementHostTrapListenPortValue)
Set the port used on the remote host to listen for SNMP traps. |
void | setSpecificTrapType(int specificTrapTypeValue)
Set the specific trap type for this SNMP PDU. |
void | setSysUpTime(long sysUpTimeValue)
Set the value of the system up time that will be used for the SNMP PDU.
|
void | setSysUpTimeResolver(String value)
See SysUpTimeResolver. |
void | setTrapVersion(int trapVersion) |
Parameters: layoutValue a Layout
Returns: application OID currently set
Returns: the current community string
Returns: A String, formatted as an OID E.g. "1.3.6.1.2.1.1.2.0" -- this OID would point to the standard sysObjectID of the "systemName" node of the standard "system" MIB.
Returns: the current value of this flag.
Returns: the trap type currently set
Returns: the FQN of the class currently configured as the delegate for sending traps
Returns: IP address of the local host
Returns: local trap send port
Returns: numeric IP address of the trap target
Returns: target trap port
Returns: specific trap type currently set
Returns: current system up time
Returns: a concrete instance of an implementation of the SysUpTimeResolver interface
Parameters: applicationTrapOIDValue -- formatted as an OID E.g. "1.3.6.1.2.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 to this method.
Parameters: communityStringValue -- E.g. "public". This is the default, if none is provided.
Parameters: enterpriseOIDValue -- formatted as an OID E.g. "1.3.6.1.2.1.1.2.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 to this method.
Parameters: forwardStackTraceWithTrap true or false
Parameters: genericTrapTypeValue -- One of the following values: 0 -- cold start
1 -- warm start
2 -- link
down
3 -- link up
4 -- authentification failure
5 -- EGP neighbor
loss
6 -- enterprise specific
Parameters: implementationClassNameValue -- a String containing the fully qualified class name of the concrete implementation class, e.g. "org.apache.log4j.ext.JoeSNMPTrapSender".
Parameters: localIPAddressValue -- an IP address, as a String, in numeric, dotted decimal format. E.g. "10.255.255.2".
Parameters: localTrapSendPortValue -- any valid IP port number. The default is 161, if none is provided.
Parameters: managementHostValue -- the IP address of the remote host, in numeric, dotted-decimal format, as a String. E.g. "10.255.255.1"
Parameters: managementHostTrapListenPortValue -- any valid TCP/IP port
Parameters: specificTrapTypeValue -- any value within the range defined for an INTEGER in the ASN.1/BER notation; i.e. -128 to 127
Deprecated: Now using the excellent SysUpTimeResolver idea from Thomas Muller, but if you set this value in the properties file, the appender will use that value, to maintain backwards compatibility.
Set the value of the system up time that will be used for the SNMP PDU.Parameters: sysUpTimeValue -- this is meant to be the amount of time, in seconds, elapsed since the last re-start or re-initialization of the calling application. Of course, to set this, your application needs to keep track of the value. The default is 0, if none is provided.
Parameters: value -- a String containing the fully qualified class name of the concrete implementation class, e.g. "org.apache.log4j.ext.MySysUpTimeResolver".