org.apache.log4j.ext

Class SnmpDelimitedConversionPatternLayout

public class SnmpDelimitedConversionPatternLayout extends PatternLayout

This layout allows you to embed trap specific OID's in the conversion pattern defined in the configuration script, assigning each embedded OID to a specific element of the LoggingEvent. Each element obtained this way will be appended as a separate VarBind to the trap's PDU. Thus, you can have the Level (DEBUG, WARN, ERROR, etc.) as one VarBind, the logging message as another, the class name, or date, or whatever, as yet more.. Each VarBind thus defined will typically be displayed by the SNMP managment application that receives the trap as a discrete element -- this makes the trap much more readable and can dramatically increase the usefulness of the appender.

When using this Layout class, the appender assumes that the conversion pattern string in the properties file will be in the following format:

(LoggingEvent element)(Value of the varDelim parameter of this class)(trap OID)(Value of the valuePairDelim parameter of this class)....(pattern repeats n+ times).

... where value pairs of conversion characters and applicationTrapOIDs are delimited by the valuePairDelim variable (defined in log4j config, default is /). Within these value pairs the values are delimited by the varDelim variable (defined in log4j config, default is ;).

Each conversion character is then formatted into the specific logging information data it represents. It is then bound to the SNMP PDU as a VarBind, with the applicationTrapOID as the name, and the logging data string as the value...

Thus, in the following example:

"p;1.3.6.1.4.1.24.100.1/%m;1.3.6.1.4.1.24.100.2/%C;1.3.6.1.4.1.24.100.3"

... the "p" element of the LoggingEvent (the Level) is mapped with the OID "1.3.6.1.4.1.24.100.1" to a discrete VarBind, the "m" element of the LoggingEvent (the message) is mapped with the OID "1.3.6.1.4.1.24.100.2" to another discrete VarBind, and so on.

Version 1.0.1
2001-09-29
changes --- 2003.03.23: mwm : moved the #formatMultipleVarBinds method from the Appender, where it didn't seem to belong, to this class. Given the details of the task that this method resolves, and the means that it uses to do so, it seems a better fit as a responsibility of this class.

Author: Mark Masterson (m.masterson@computer.org),
Matt Monks (Matthew.Monks@netdecisions.com)

Method Summary
voidformatMultipleVarBinds(LoggingEvent event, SnmpTrapSenderFacade out)
Breaks the conversion pattern string itself up and, using the tokens thus found, builds distinct VarBinds out of the OID's embedded in the conversion pattern string and the escaped elements of the LoggingEvent.
StringgetValuePairDelim()
Gets the value of the delimiter used in the conversion pattern string to delimit value pairs that should be added as separate VarBind variables to the trap.
StringgetVarDelim()
Gets the value of the delimiter used in the conversion pattern string to delimit the key and value in a value pair embedded within the string.
booleanignoresThrowable()
Override this to insulate us from potential changes to the super class.
voidsetValuePairDelim(String valuePairDelim)
Sets the value of the delimiter used in the conversion pattern string to delimit value pairs that should be added as separate VarBind variables to the trap.
voidsetVarDelim(String varDelim)
Sets the value of the delimiter used in the conversion pattern string to delimit the key and value in a value pair embedded within the string.

Method Detail

formatMultipleVarBinds

public void formatMultipleVarBinds(LoggingEvent event, SnmpTrapSenderFacade out)
Breaks the conversion pattern string itself up and, using the tokens thus found, builds distinct VarBinds out of the OID's embedded in the conversion pattern string and the escaped elements of the LoggingEvent.

Parameters: event to log out logging target

getValuePairDelim

public String getValuePairDelim()
Gets the value of the delimiter used in the conversion pattern string to delimit value pairs that should be added as separate VarBind variables to the trap. Default is "/".

Returns: the delimiter character used

getVarDelim

public String getVarDelim()
Gets the value of the delimiter used in the conversion pattern string to delimit the key and value in a value pair embedded within the string. Default is ";".

Returns: the delimiter character used

ignoresThrowable

public boolean ignoresThrowable()
Override this to insulate us from potential changes to the super class.

Returns: true

setValuePairDelim

public void setValuePairDelim(String valuePairDelim)
Sets the value of the delimiter used in the conversion pattern string to delimit value pairs that should be added as separate VarBind variables to the trap. Default is "/".

Parameters: valuePairDelim delimiter value pairs

setVarDelim

public void setVarDelim(String varDelim)
Sets the value of the delimiter used in the conversion pattern string to delimit the key and value in a value pair embedded within the string. Default is ";".

Parameters: varDelim delimiter within value pairs