com.mccrory.scott.spumoni
Class SnmpTrapAgent

java.lang.Object
  |
  +--com.mccrory.scott.spumoni.SnmpTrapAgent
All Implemented Interfaces:
org.opennms.protocols.snmp.SnmpHandler

public class SnmpTrapAgent
extends java.lang.Object
implements org.opennms.protocols.snmp.SnmpHandler

SnmpTrapAgent is a class that sends SNMP V1 or V2 traps to one (and only one) SNMP manager defined by its IP address and port number. SnmpTrapAgent is an adaptation of JoeSNMP's SnmpAgent test class, which is a part of the OpenNMS project. Thanks go out to Brian Weaver and the rest of the OpenNMS crew for their excellent work.

Version:
CVS $Id: SnmpTrapAgent.java,v 1.8 2002/08/04 22:04:53 smccrory Exp $
Author:
Brian Weaver
, OpenNMS , Scott McCrory.

Constructor Summary
SnmpTrapAgent(java.lang.String managerAddress, int managerPort, java.lang.String trapOid)
          Builds an snmpagent object for sending SNMP V1 or V2 traps.
 
Method Summary
 java.lang.Object clone()
          We override the clone method here to prevent cloning of our class.
 void close()
          Closes the SNMP session.
static void main(java.lang.String[] args)
          For unit testing.
 void sendV1Trap(java.lang.String message)
          Sends a formatted message as SNMP V1 trap.
 void sendV2Trap(java.lang.String message)
          Sends a formatted message as SNMP V2 trap.
 void snmpInternalError(org.opennms.protocols.snmp.SnmpSession session, int err, org.opennms.protocols.snmp.SnmpSyntax pdu)
          Stubbed out since we are only sending
 void snmpReceivedPdu(org.opennms.protocols.snmp.SnmpSession session, int cmd, org.opennms.protocols.snmp.SnmpPduPacket pdu)
          Stubbed out since we are only sending
 void snmpTimeoutError(org.opennms.protocols.snmp.SnmpSession session, org.opennms.protocols.snmp.SnmpSyntax pdu)
          Stubbed out since we are only sending
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SnmpTrapAgent

public SnmpTrapAgent(java.lang.String managerAddress,
                     int managerPort,
                     java.lang.String trapOid)
              throws java.lang.Exception
Builds an snmpagent object for sending SNMP V1 or V2 traps.

Remark : The SNMP trap type (V1 or V2) will be set every time a trap is sent in the respectie send method.

Parameters:
managerAddress - the IP address where the traps are sent
managerPort - the port number where the traps are sent (e.g. 162)
trapOid - the complete OID for the trap (e.g. "1.3.6.1.2.1.1232.1.1")
Throws:
java.lang.Exception - if an error occurs during the initialization of the object
Method Detail

clone

public final java.lang.Object clone()
                             throws java.lang.CloneNotSupportedException
We override the clone method here to prevent cloning of our class.

Overrides:
clone in class java.lang.Object
Returns:
Nothing ever really returned since we throw a CloneNotSupportedException
Throws:
java.lang.CloneNotSupportedException - To indicate cloning is not allowed

close

public void close()
Closes the SNMP session.


main

public static void main(java.lang.String[] args)
For unit testing.

Parameters:
args - an array of command-line arguments

sendV1Trap

public void sendV1Trap(java.lang.String message)
                throws java.lang.Exception
Sends a formatted message as SNMP V1 trap.

Parameters:
message - the formatted text to send
Throws:
java.lang.Exception - if an error occurs during the sending of the trap

sendV2Trap

public void sendV2Trap(java.lang.String message)
                throws java.lang.Exception
Sends a formatted message as SNMP V2 trap.

Parameters:
message - the formatted text to send
Throws:
java.lang.Exception - if an error occurs during the sending of the trap

snmpInternalError

public void snmpInternalError(org.opennms.protocols.snmp.SnmpSession session,
                              int err,
                              org.opennms.protocols.snmp.SnmpSyntax pdu)
Stubbed out since we are only sending

Specified by:
snmpInternalError in interface org.opennms.protocols.snmp.SnmpHandler
Parameters:
session - The SnmpSession we're communicating with
err - The error number
pdu - The SNMP Packet Data Unit

snmpReceivedPdu

public void snmpReceivedPdu(org.opennms.protocols.snmp.SnmpSession session,
                            int cmd,
                            org.opennms.protocols.snmp.SnmpPduPacket pdu)
Stubbed out since we are only sending

Specified by:
snmpReceivedPdu in interface org.opennms.protocols.snmp.SnmpHandler
Parameters:
session - The SnmpSession we're communicating with
cmd - The SNMP command
pdu - The SNMP Packet Data Unit

snmpTimeoutError

public void snmpTimeoutError(org.opennms.protocols.snmp.SnmpSession session,
                             org.opennms.protocols.snmp.SnmpSyntax pdu)
Stubbed out since we are only sending

Specified by:
snmpTimeoutError in interface org.opennms.protocols.snmp.SnmpHandler
Parameters:
session - The SnmpSession we're communicating with
pdu - The SNMP Packet Data Unit


Copyright © 2002 Scott McCrory as part of the Spumoni project. All Rights Reserved.