org.opennms.bb.dp.trapd
Class Trapd

java.lang.Object
  |
  +--org.opennms.bb.dp.common.components.PollerClient
        |
        +--org.opennms.bb.dp.trapd.Trapd
All Implemented Interfaces:
com.sun.media.jsdt.Client, Serializable, SnmpTrapHandler

public class Trapd
extends PollerClient
implements SnmpTrapHandler

The Trapd listens for SNMP traps on the standard port(162). Creates a SnmpTrapSession and implements the SnmpTrapHandler to get callbacks when traps are received

The received traps are converted into XML and sent to eventd via JSDT

Version:
$Revision: 1.1 $
Author:
Sowmya Kumaraswamy, Brian Weaver, OpenNMS.org
See Also:
Serialized Form

Field Summary
private  com.sun.media.jsdt.Channel m_channel
          The JSDT channel on which eventd is listening for messages
private  com.sun.media.jsdt.Session m_session
          The JSDT session on which messages are sent to eventd
private  SnmpTrapSession m_trapSession
          The trap session used by Trapd to receive traps
private static long trapCount
           
 
Fields inherited from class org.opennms.bb.dp.common.components.PollerClient
m_name
 
Constructor Summary
Trapd()
          Constructs a new Trapd object that receives and forwards trap messages via JSDT.
Trapd(int port)
          Constructs a new Trapd object that receives and forwards trap messages via JSDT.
Trapd(String clientName)
          Constructs a new Trapd object that receives and forwards trap messages via JSDT.
Trapd(String clientName, int port)
          Constructs a new Trapd object that receives and forwards trap messages via JSDT.
 
Method Summary
 void close()
          Closes the JSDT channel and the trap session
private  void connect()
          Connect to the eventd JSDT channel
static void main(String[] args)
          Instantiate a trap listener
 void snmpReceivedTrap(SnmpTrapSession session, InetAddress agent, int port, SnmpOctetString community, SnmpPduPacket pdu)
          Process the recieved SNMP v2c trap that was received by the underlying trap session.
 void snmpReceivedTrap(SnmpTrapSession session, InetAddress agent, int port, SnmpOctetString community, SnmpPduTrap pdu)
          Process the recieved SNMP v1 trap that was received by the underlying trap session.
 void snmpTrapSessionError(SnmpTrapSession session, int error, Object ref)
          Processes an error condition that occurs in the SnmpTrapSession.
private  void trapdInit(int port)
          Create the SNMP trap session and create the JSDT communication channel to communicate with eventd.
 
Methods inherited from class org.opennms.bb.dp.common.components.PollerClient
authenticate, getName
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

m_trapSession

private SnmpTrapSession m_trapSession
The trap session used by Trapd to receive traps

m_session

private com.sun.media.jsdt.Session m_session
The JSDT session on which messages are sent to eventd

m_channel

private com.sun.media.jsdt.Channel m_channel
The JSDT channel on which eventd is listening for messages

trapCount

private static long trapCount
Constructor Detail

Trapd

public Trapd()
      throws SocketException,
             com.sun.media.jsdt.JSDTException

Constructs a new Trapd object that receives and forwards trap messages via JSDT. The session is initialized with the default client name of OpenNMS.trapd. The trap session is started on the default port, as defined by the SNMP libarary.

Throws:
SocketException - Thrown when the SnmpTrapSession cannot create the datagram socket
SecurityException - Thrown if the security manager disallows the creation of the handler
See Also:
SnmpTrapSession

Trapd

public Trapd(String clientName)
      throws SocketException,
             com.sun.media.jsdt.JSDTException

Constructs a new Trapd object that receives and forwards trap messages via JSDT. The trap session is started on the default port, as defined by the SNMP libarary.

Parameters:
clientName - The JSDT client identifier for Trapd
Throws:
SocketException - Thrown when the SnmpTrapSession cannot create the datagram socket
SecurityException - Thrown if the security manager disallows the creation of the handler

Trapd

public Trapd(int port)
      throws SocketException,
             com.sun.media.jsdt.JSDTException

Constructs a new Trapd object that receives and forwards trap messages via JSDT. The session is initialized with the client name of OpenNMS.trapd:<port>. The trap session is started on the passed number.

Parameters:
port - The port number for the trap session.
Throws:
SocketException - Thrown when the SnmpTrapSession cannot create the datagram socket
SecurityException - Thrown if the security manager disallows the creation of the handler

Trapd

public Trapd(String clientName,
             int port)
      throws SocketException,
             com.sun.media.jsdt.JSDTException

Constructs a new Trapd object that receives and forwards trap messages via JSDT. The new session is initialized with the passed JSDT client name and the defined trap port number.

Parameters:
clientName - The name for this JSDT client.
port - The port number for the trap session.
Throws:
SocketException - Thrown when the SnmpTrapSession cannot create the datagram socket
SecurityException - Thrown if the security manager disallows the creation of the handler
Method Detail

connect

private void connect()
              throws com.sun.media.jsdt.JSDTException
Connect to the eventd JSDT channel
Throws:
InterruptedException - Thrown if the running thread is interrupted by another thread.

trapdInit

private void trapdInit(int port)
                throws SocketException,
                       com.sun.media.jsdt.JSDTException
Create the SNMP trap session and create the JSDT communication channel to communicate with eventd.
Parameters:
port - The port number where SNMP traps should be received. If the port number is equal to -1 then the default port is used.
Throws:
SocketException - Thrown when the SnmpTrapSession cannot create the datagram socket
SecurityException - Thrown if the security manager disallows the creation of the handler
See Also:
SnmpTrapSession, SnmpTrapHandler

snmpReceivedTrap

public void snmpReceivedTrap(SnmpTrapSession session,
                             InetAddress agent,
                             int port,
                             SnmpOctetString community,
                             SnmpPduPacket pdu)

Process the recieved SNMP v2c trap that was received by the underlying trap session.

Specified by:
snmpReceivedTrap in interface SnmpTrapHandler
Parameters:
session - The trap session that received the datagram.
agent - The remote agent that sent the datagram.
port - The remmote port the trap was sent from.
community - The community string contained in the message.
pdu - The protocol data unit containing the data

snmpReceivedTrap

public void snmpReceivedTrap(SnmpTrapSession session,
                             InetAddress agent,
                             int port,
                             SnmpOctetString community,
                             SnmpPduTrap pdu)

Process the recieved SNMP v1 trap that was received by the underlying trap session.

Specified by:
snmpReceivedTrap in interface SnmpTrapHandler
Parameters:
session - The trap session that received the datagram.
agent - The remote agent that sent the datagram.
port - The remmote port the trap was sent from.
community - The community string contained in the message.
pdu - The protocol data unit containing the data

snmpTrapSessionError

public void snmpTrapSessionError(SnmpTrapSession session,
                                 int error,
                                 Object ref)

Processes an error condition that occurs in the SnmpTrapSession. The errors are logged and ignored by the trapd class.

Specified by:
snmpTrapSessionError in interface SnmpTrapHandler
See Also:
Log

close

public void close()
Closes the JSDT channel and the trap session

main

public static void main(String[] args)
Instantiate a trap listener