com.sun.management.snmp.agent
Class SnmpTrap

java.lang.Object
  extended by com.sun.management.snmp.agent.SnmpTrap
All Implemented Interfaces:
Serializable

public class SnmpTrap
extends Object
implements Serializable

This class represents an SNMP trap. It is not protocol-dependent. Once created, any SNMP trap can be sent in either SNMP V1, V2 or V3. SNMP traps use a SnmpAdaptorServer to send, which you must provide. (SnmpAdaptorServer implements the notification dispatching interface).

An instance of SnmpTrap can be reused multiple time with the same parameters.

Since:
Java DMK 5.1
See Also:
Serialized Form

Field Summary
static SnmpOid authenticationFailureOid
          authenticationFailure Oid as defined in RFC 1907.
static SnmpOid coldStartOid
          coldStart Oid as defined in RFC 1907.
static SnmpOid egpNeighborLossOid
          egpNeighborLoss Oid as defined in RFC 1907.
static SnmpOid linkDownOid
          linkDown Oid as defined in RFC 1907.
static SnmpOid linkUpOid
          linkUp Oid as defined in RFC 1907.
static SnmpOid snmpTrapAddressOid
          snmpTrapAddress Oid as defined in RFC 2576.
static SnmpOid snmpTrapCommunityOid
          snmpTrapCommunity Oid as defined in RFC 2576.
static SnmpOid snmpTrapEnterpriseOid
          snmpTrapEnterprise Oid as defined in RFC 1907.
static SnmpOid snmpTrapOid
          snmpTrapOid Oid as defined in RFC 1907.
static SnmpOid snmpTrapsOid
          snmpTraps Oid as defined in RFC 1907.
static SnmpOid snmpTrapSysUpTimeOid
          snmpSysUpTime Oid as defined in RFC 1907.
static SnmpOid warmStartOid
          warmStart Oid as defined in RFC 1907.
 
Constructor Summary
SnmpTrap(InetAddress addr, String cs, int gen, int specific, SnmpVarBindList varBindList)
          Initializes this SNMP trap with SNMP V1 style parameters.
SnmpTrap(InetAddress addr, String cs, SnmpOid trapOid, SnmpVarBindList varBindList)
          Initializes this SNMP trap with SNMP V2 style parameters.
SnmpTrap(int gen, int specific, SnmpVarBindList varBindList)
          Initializes this SNMP trap with SNMP V1 style parameters
SnmpTrap(SnmpOid trapOid, SnmpVarBindList varBindList)
          Initializes this SNMP trap with SNMP V2 style parameters.
SnmpTrap(SnmpPduRequest trap)
          Initializes this SNMP trap with an SNMP request PDU.
SnmpTrap(SnmpPduTrap trap)
          Initializes this SNMP trap with an SNMP V1 trap PDU.
SnmpTrap(SnmpScopedPduRequest scopedTrap)
          Initializes this SNMP trap with an SNMP V3 scoped PDU.
 
Method Summary
 SnmpPdu getPdu()
          If the trap has been created with a PDU (SNMP V1 / V2 or V3), the received PDU is returned.
 InetAddress getSourceAddress()
          If the trap has been created with a PDU (SNMP V1 / V2 or V3), the source address located in this PDU is returned.
 boolean isOriginatorWay()
          By default a trap is sent as a notification originator.
 boolean isProxyWay()
          By default a trap is sent as a notification originator.
 void sendAsNotificationOriginator()
          By default a trap is sent as a notification originator.
 void sendAsProxy()
          By default a trap is sent as a notification originator.
 void sendV1(SnmpAdaptorServer server)
          Send this trap.
 void sendV2(SnmpAdaptorServer server)
          Send as a V2 trap.
 void sendV3(SnmpV3AdaptorServer server)
          Send as a V3 trap.
 void sendV3Usm(SnmpV3AdaptorServer server, String principal, int securityLevel, String contextName)
          Send as a V3 trap.
 void setCommunityString(String cs)
          Sets the community string.
 void setDestinationAddress(InetAddress address)
          Sets the trap destination address.
 void setDestinationPort(int port)
          Sets the trap destination port.
 void setEnterpriseOid(String oid)
          Sets the enterprise OID.
 void setPduSourceAddress(InetAddress addr)
          When a trap is received, localhost is set as the source of the sent trap.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

coldStartOid

public static final SnmpOid coldStartOid
coldStart Oid as defined in RFC 1907.


warmStartOid

public static final SnmpOid warmStartOid
warmStart Oid as defined in RFC 1907.


linkDownOid

public static final SnmpOid linkDownOid
linkDown Oid as defined in RFC 1907.


linkUpOid

public static final SnmpOid linkUpOid
linkUp Oid as defined in RFC 1907.


authenticationFailureOid

public static final SnmpOid authenticationFailureOid
authenticationFailure Oid as defined in RFC 1907.


egpNeighborLossOid

public static final SnmpOid egpNeighborLossOid
egpNeighborLoss Oid as defined in RFC 1907.


snmpTrapSysUpTimeOid

public static final SnmpOid snmpTrapSysUpTimeOid
snmpSysUpTime Oid as defined in RFC 1907.


snmpTrapOid

public static final SnmpOid snmpTrapOid
snmpTrapOid Oid as defined in RFC 1907.


snmpTrapAddressOid

public static final SnmpOid snmpTrapAddressOid
snmpTrapAddress Oid as defined in RFC 2576.


snmpTrapEnterpriseOid

public static final SnmpOid snmpTrapEnterpriseOid
snmpTrapEnterprise Oid as defined in RFC 1907.


snmpTrapsOid

public static final SnmpOid snmpTrapsOid
snmpTraps Oid as defined in RFC 1907.


snmpTrapCommunityOid

public static final SnmpOid snmpTrapCommunityOid
snmpTrapCommunity Oid as defined in RFC 2576.

Constructor Detail

SnmpTrap

public SnmpTrap(int gen,
                int specific,
                SnmpVarBindList varBindList)
Initializes this SNMP trap with SNMP V1 style parameters

Parameters:
gen - The generic number of the trap.
specific - The specific number of the trap.
varBindList - A list of SnmpVarBind.

SnmpTrap

public SnmpTrap(InetAddress addr,
                String cs,
                int gen,
                int specific,
                SnmpVarBindList varBindList)
Initializes this SNMP trap with SNMP V1 style parameters.

Parameters:
addr - The InetAddress destination of the trap.
cs - The community string to be used for the trap.
gen - The generic number of the trap.
specific - The specific number of the trap.
varBindList - A list of SnmpVarBind.

SnmpTrap

public SnmpTrap(SnmpOid trapOid,
                SnmpVarBindList varBindList)
Initializes this SNMP trap with SNMP V2 style parameters.

Parameters:
trapOid - The trap oid.
varBindList - A list of SnmpVarBind.

SnmpTrap

public SnmpTrap(InetAddress addr,
                String cs,
                SnmpOid trapOid,
                SnmpVarBindList varBindList)
Initializes this SNMP trap with SNMP V2 style parameters.

Parameters:
addr - The InetAddress destination of the trap.
cs - The community string to be used for the trap.
trapOid - The trap oid.
varBindList - A list of SnmpVarBind.

SnmpTrap

public SnmpTrap(SnmpPduTrap trap)
Initializes this SNMP trap with an SNMP V1 trap PDU. Trap PDUs are received by SnmpTrapListener.

Parameters:
trap - The SNMP V1 trap pdu.

SnmpTrap

public SnmpTrap(SnmpScopedPduRequest scopedTrap)
Initializes this SNMP trap with an SNMP V3 scoped PDU. Trap PDUs are received by SnmpTrapListener.

Parameters:
scopedTrap - The SNMP V3 trap pdu.

SnmpTrap

public SnmpTrap(SnmpPduRequest trap)
Initializes this SNMP trap with an SNMP request PDU. SNMP request PDUs are received by SnmpTrapListener.

Parameters:
trap - The SNMP request pdu.
Method Detail

getSourceAddress

public InetAddress getSourceAddress()
If the trap has been created with a PDU (SNMP V1 / V2 or V3), the source address located in this PDU is returned. Null is returned if no source address can be defined.

Returns:
The trap source address or null if no source address defined

getPdu

public SnmpPdu getPdu()
If the trap has been created with a PDU (SNMP V1 / V2 or V3), the received PDU is returned. Otherwise null is returned. The returned SnmpPdu can be of the class : SnmpPduRequest, SnmpScopedPduRequest or SnmpPduTrap.

Returns:
the PDU or null.

setEnterpriseOid

public void setEnterpriseOid(String oid)
Sets the enterprise OID. It will be used when sending the trap.

Parameters:
oid - The OID in string format "x.x.x.x".
Throws:
IllegalArgumentException - The string format is incorrect

setDestinationAddress

public void setDestinationAddress(InetAddress address)
Sets the trap destination address. It will be used when sending the trap.

Parameters:
address - The trap destination address.

setDestinationPort

public void setDestinationPort(int port)
Sets the trap destination port. It will be used when sending the trap. If no port is provided, the SNMP adaptor's port is used.

Parameters:
port - The trap destination port.

setCommunityString

public void setCommunityString(String cs)
Sets the community string. It will be used when sending the trap.

Parameters:
cs - The community string to use.

sendV3

public void sendV3(SnmpV3AdaptorServer server)
            throws IOException,
                   SnmpStatusException
Send as a V3 trap. The passed SNMP adaptor is used by the trap to send itself. This method can only be called if the current SnmpTrap has been instantiated with the constructor SnmpTrap(SnmpScopedPduRequest)

Parameters:
server - The SNMP V3 adaptor to use.
Throws:
IOException
SnmpStatusException

sendV3Usm

public void sendV3Usm(SnmpV3AdaptorServer server,
                      String principal,
                      int securityLevel,
                      String contextName)
               throws IOException,
                      SnmpStatusException
Send as a V3 trap. The passed SNMP adaptor is used by the trap to send itself. USM is used in order to secure the trap.

Parameters:
server - The SNMP V3 adaptor to use.
principal - The user name to use.
securityLevel - The V3 message flags.
contextName - The V3 context name. If null is provided and if a community string has been provided, it will be reused as the contextName. The contextEngineId is the local engine Id.
Throws:
IOException
SnmpStatusException

sendV2

public void sendV2(SnmpAdaptorServer server)
            throws IOException,
                   SnmpStatusException
Send as a V2 trap. The passed SNMP adaptor is used by the trap to send itself.

Parameters:
server - The SNMP adaptor to use.
Throws:
IOException - An I/O error occurred while sending the trap.
SnmpStatusException - If the trap exceeds the limit defined by bufferSize.

sendV1

public void sendV1(SnmpAdaptorServer server)
            throws IOException,
                   SnmpStatusException
Send this trap. The passed SNMP adaptor is used by the trap to send itself.

Parameters:
server - The SNMP adaptor to use.
Throws:
IOException - An I/O error occurred while sending the trap.
SnmpStatusException - If the trap exceeds the limit defined by bufferSize.

sendAsNotificationOriginator

public void sendAsNotificationOriginator()
By default a trap is sent as a notification originator. The difference between acting as a notification originator or a proxy when forwarding the trap is detailed in rfc 2576 section 3.1 and 3.2.


sendAsProxy

public void sendAsProxy()
By default a trap is sent as a notification originator. The difference between acting as a notification originator or a proxy when forwarding the trap is detailed in rfc 2576 section 3.1 and 3.2.


isOriginatorWay

public boolean isOriginatorWay()
By default a trap is sent as a notification originator. The difference between acting as a notification originator or a proxy when forwarding the trap is detailed in rfc 2576 section 3.1 and 3.2.


isProxyWay

public boolean isProxyWay()
By default a trap is sent as a notification originator. The difference between acting as a notification originator or a proxy when forwarding the trap is detailed in rfc 2576 section 3.1 and 3.2.


setPduSourceAddress

public void setPduSourceAddress(InetAddress addr)
When a trap is received, localhost is set as the source of the sent trap. In case you want a specific address, call this method providing it an IP address. If isProxyWay returns true, the source address is the one received.

Parameters:
addr - The source address to use when forwarding the trap.

Open Source build 02
opendmk-1.0-b02 2007.10.01_19:17:46_MEST

Copyright 1998-2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.