org.apache.log4j.ext
Class JoeSNMPTrapSender

java.lang.Object
  extended by org.apache.log4j.ext.JoeSNMPTrapSender
All Implemented Interfaces:
SnmpTrapSenderFacade, org.opennms.protocols.snmp.SnmpTrapHandler

public class JoeSNMPTrapSender
extends java.lang.Object
implements org.opennms.protocols.snmp.SnmpTrapHandler, SnmpTrapSenderFacade

This class makes use of the JoeSNMP library to implement the underlying SNMP protocol(s). The JoeSNMP library is a part of the OpenNMS project, and is available/distributed under the GNU Lesser General Public License (LGPL).

To quote the JoeSNMP FAQ:

 "What license is JoeSNMP released under?

JoeSNMP is released under the GNU Lesser General Public License (LGPL),
documented fully at http://www.fsf.org/copyleft/lesser.html.
Effectively, this means that JoeSNMP is free to distribute and modify as
long as you provide your modified code back to the community. And if
you'd like to use JoeSNMP as a library within your commercial product,
you are welcome to do so as well, but again, any changes to the
library itself need to be contributed back."

You can get more information about OpenNMS here. You can get a copy of JoeSNMP here.
You will need a copy of the library ("joesnmp-0.2.6.jar" at a minimum) to use and/or compile this class.
WARNING: The JoeSNMP library requires a minimum of JDK 1.2.

Version:
2.0.3
2002-10-03
changes ---
2001-09-31: mwm : cleaned up the coding style errors, modified the addTrapMessageVariable(String value) to addTrapMessageVariable(String value, String applicationTrapOIDValue) so that the Facade is more flexible.
2001-10-03: mwm : swapped the SNMP library out, replacing the AdventNet commercial library with the one from OpenNMS. Thanks to Jin Zhao for pointing me towards this!
2001-11-04: mwm : fixed a minor bug with use of the SnmpTrapSession object. General tidying up.
2002-10-03: mwm : changed the name of the class to "JoeSNMPTrapSender", to reflect the fact that this is now simply the concrete implementation of the new "SnmpTrapSenderFacade" interface that uses JoeSNMP as it's underlying library. Made changes to deal with the new architecture.
2002-10-15: mwm : fixed a bug that caused some NMS software to receive a the IP address of the sending host incorrectly formatted.
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 : fixed a big, nasty, RTFM bug in #sendTrap
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
JoeSNMPTrapSender()
          Default constructor.
 
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.
 void snmpReceivedTrap(org.opennms.protocols.snmp.SnmpTrapSession parm1, java.net.InetAddress parm2, int parm3, org.opennms.protocols.snmp.SnmpOctetString parm4, org.opennms.protocols.snmp.SnmpPduPacket parm5)
          Skeleton method, implemented only to satisfy the requirements of the JoeSNMP API.
 void snmpReceivedTrap(org.opennms.protocols.snmp.SnmpTrapSession parm1, java.net.InetAddress parm2, int parm3, org.opennms.protocols.snmp.SnmpOctetString parm4, org.opennms.protocols.snmp.SnmpPduTrap parm5)
          Skeleton method, implemented only to satisfy the requirements of the JoeSNMP API.
 void snmpTrapSessionError(org.opennms.protocols.snmp.SnmpTrapSession parm1, int parm2, java.lang.Object parm3)
          Skeleton method, implemented only to satisfy the requirements of the JoeSNMP API.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JoeSNMPTrapSender

public JoeSNMPTrapSender()
Default constructor.

Method Detail

snmpReceivedTrap

public void snmpReceivedTrap(org.opennms.protocols.snmp.SnmpTrapSession parm1,
                             java.net.InetAddress parm2,
                             int parm3,
                             org.opennms.protocols.snmp.SnmpOctetString parm4,
                             org.opennms.protocols.snmp.SnmpPduPacket parm5)
Skeleton method, implemented only to satisfy the requirements of the JoeSNMP API. Does nothing except spit out an error message via LogLog.

Specified by:
snmpReceivedTrap in interface org.opennms.protocols.snmp.SnmpTrapHandler

snmpReceivedTrap

public void snmpReceivedTrap(org.opennms.protocols.snmp.SnmpTrapSession parm1,
                             java.net.InetAddress parm2,
                             int parm3,
                             org.opennms.protocols.snmp.SnmpOctetString parm4,
                             org.opennms.protocols.snmp.SnmpPduTrap parm5)
Skeleton method, implemented only to satisfy the requirements of the JoeSNMP API. Does nothing except spit out an error message via LogLog.

Specified by:
snmpReceivedTrap in interface org.opennms.protocols.snmp.SnmpTrapHandler

snmpTrapSessionError

public void snmpTrapSessionError(org.opennms.protocols.snmp.SnmpTrapSession parm1,
                                 int parm2,
                                 java.lang.Object parm3)
Skeleton method, implemented only to satisfy the requirements of the JoeSNMP API. Does nothing except spit out an error message via LogLog.

Specified by:
snmpTrapSessionError in interface org.opennms.protocols.snmp.SnmpTrapHandler

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