HOME

com.ireasoning.protocol.snmp
Class SnmpTrapSender

java.lang.Object
  extended bycom.ireasoning.protocol.snmp.SnmpTrapSender

public class SnmpTrapSender
extends Object

This class is used for sending SNMPv1, SNMPv2c and SNMPv3 traps.

See Also:
snmptrap.java example

Method Summary
static void addV3Params(String userName, String authProtocol, String authPassword, int privProtocol, String privPassword, byte[] engineID, String host, int port)
          Adds SNMPV3 trap receiver's properties.
static void addV3Params(String userName, String authProtocol, String authPassword, int privProtocol, String privPassword, byte[] engineID, String contextName, String host, int port)
          Adds SNMPV3 trap receiver's properties.
static void addV3Params(String userName, String authProtocol, String authPassword, String privPassword, byte[] engineID, String host, int port)
          Adds SNMPV3 trap receiver's properties.
static void sendTrap(SnmpV1Trap trap, String host, int port, String community)
          Sends out SNMPv1 trap.
static void sendTrap(SnmpV1Trap trap, String host, int port, String community, DatagramSocket socket)
          Sends out SNMPv1 trap.
static void sendTrap(SnmpV1Trap trap, String host, int port, String community, PacketSender sender)
          Sends out SNMPv1 trap.
static void sendTrap(String host, int port, SnmpTrap trap, boolean isV3Trap)
          Sends out SNMPv2c or SNMPv3 trap, using "PUBLIC" as community name.
static void sendTrap(String host, int port, SnmpTrap trap, boolean isV3Trap, String community)
          Sends out SNMPv2c or SNMPv3 trap.
static void sendTrap(String host, int port, SnmpTrap trap, boolean isV3Trap, String community, DatagramSocket socket)
          Sends out SNMPv2c or SNMPv3 trap.
static void sendTrap(String host, int port, SnmpTrap trap, boolean isV3Trap, String community, PacketSender sender)
          Sends out SNMPv2c or SNMPv3 trap.
static void sendTrap(String host, int port, SnmpV1Trap trap)
          Sends out SNMPv1 trap, using "PUBLIC" as community name.
static void setSnmpEngine(String host, byte[] engineID, int engineTime, int engineBoots)
          Sets the SNMPv3 trap sender's engine properties
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

sendTrap

public static void sendTrap(String host,
                            int port,
                            SnmpTrap trap,
                            boolean isV3Trap)
                     throws SnmpEncodingException,
                            UnknownHostException
Sends out SNMPv2c or SNMPv3 trap, using "PUBLIC" as community name.

Parameters:
host - host name or ip address of remote SNMP trap receiver
port - port number of remote SNMP trap receiver
trap - SNMPv2c or SNMPv3 trap object to be sent
isV3Trap - true if the trap to be sent is SNMPv3 trap
Throws:
UnknownHostException - if no IP address for the host could be found.
SnmpEncodingException - if not enough information or some information is wrong for encoding SNMP packet

sendTrap

public static void sendTrap(String host,
                            int port,
                            SnmpTrap trap,
                            boolean isV3Trap,
                            String community)
                     throws SnmpEncodingException,
                            UnknownHostException
Sends out SNMPv2c or SNMPv3 trap.

Parameters:
host - host name or ip address of remote SNMP trap receiver
port - port number of remote SNMP trap receiver
trap - SNMPv2c or SNMPv3 trap object to be sent
isV3Trap - true if the trap to be sent is SNMPv3 trap
community - community name for remote trap receiver. It does not matter if isV3Trap is true
Throws:
UnknownHostException - if no IP address for the host could be found.
SnmpEncodingException - if not enough information or some information is wrong for encoding SNMP packet

sendTrap

public static void sendTrap(String host,
                            int port,
                            SnmpTrap trap,
                            boolean isV3Trap,
                            String community,
                            DatagramSocket socket)
                     throws SnmpEncodingException,
                            UnknownHostException
Sends out SNMPv2c or SNMPv3 trap.

Parameters:
host - host name or ip address of remote SNMP trap receiver
port - port number of remote SNMP trap receiver
trap - SNMPv2c or SNMPv3 trap object to be sent
isV3Trap - true if the trap to be sent is SNMPv3 trap
community - community name for remote trap receiver. It does not matter if isV3Trap is true
socket - A DatagramSocket instance which is used to send out UDP packet
Throws:
UnknownHostException - if no IP address for the host could be found.
SnmpEncodingException - if not enough information or some information is wrong for encoding SNMP packet

sendTrap

public static void sendTrap(String host,
                            int port,
                            SnmpTrap trap,
                            boolean isV3Trap,
                            String community,
                            PacketSender sender)
                     throws SnmpEncodingException,
                            UnknownHostException
Sends out SNMPv2c or SNMPv3 trap.

Parameters:
host - host name or ip address of remote SNMP trap receiver
port - port number of remote SNMP trap receiver
trap - SNMPv2c or SNMPv3 trap object to be sent
isV3Trap - true if the trap to be sent is SNMPv3 trap
community - community name for remote trap receiver. It does not matter if isV3Trap is true
sender - an implementation of PacketSender for sending out packet.
Throws:
UnknownHostException - if no IP address for the host could be found.
SnmpEncodingException - if not enough information or some information is wrong for encoding SNMP packet

sendTrap

public static void sendTrap(String host,
                            int port,
                            SnmpV1Trap trap)
                     throws SnmpEncodingException,
                            UnknownHostException
Sends out SNMPv1 trap, using "PUBLIC" as community name.

Parameters:
host - host name or ip address of remote SNMP trap receiver
port - port number of remote SNMP trap receiver
trap - SNMPv1 trap object to be sent
Throws:
UnknownHostException - if no IP address for the host could be found.
SnmpEncodingException - if not enough information or some information is wrong for encoding SNMP packet
See Also:
sendTrap(SnmpV1Trap trap, String host, int port, String community)

sendTrap

public static void sendTrap(SnmpV1Trap trap,
                            String host,
                            int port,
                            String community)
                     throws SnmpEncodingException,
                            UnknownHostException
Sends out SNMPv1 trap.

Parameters:
host - host name or ip address of remote SNMP trap receiver
port - port number of remote SNMP trap receiver
community - community name for remote trap receiver
trap - SNMPv1 trap object to be sent
Throws:
UnknownHostException - if no IP address for the host could be found.
SnmpEncodingException - if not enough information or some information is wrong for encoding SNMP packet
See Also:
sendTrap(String host, int port, SnmpV1Trap trap)

sendTrap

public static void sendTrap(SnmpV1Trap trap,
                            String host,
                            int port,
                            String community,
                            DatagramSocket socket)
                     throws SnmpEncodingException,
                            UnknownHostException
Sends out SNMPv1 trap.

Parameters:
host - host name or ip address of remote SNMP trap receiver
port - port number of remote SNMP trap receiver
community - community name for remote trap receiver
trap - SNMPv1 trap object to be sent
Throws:
UnknownHostException - if no IP address for the host could be found.
SnmpEncodingException - if not enough information or some information is wrong for encoding SNMP packet
See Also:
sendTrap(String host, int port, SnmpV1Trap trap)

sendTrap

public static void sendTrap(SnmpV1Trap trap,
                            String host,
                            int port,
                            String community,
                            PacketSender sender)
                     throws SnmpEncodingException,
                            UnknownHostException
Sends out SNMPv1 trap.

Parameters:
host - host name or ip address of remote SNMP trap receiver
port - port number of remote SNMP trap receiver
community - community name for remote trap receiver
trap - SNMPv1 trap object to be sent
Throws:
UnknownHostException - if no IP address for the host could be found.
SnmpEncodingException - if not enough information or some information is wrong for encoding SNMP packet
See Also:
sendTrap(String host, int port, SnmpV1Trap trap)

addV3Params

public static void addV3Params(String userName,
                               String authProtocol,
                               String authPassword,
                               String privPassword,
                               byte[] engineID,
                               String host,
                               int port)
Adds SNMPV3 trap receiver's properties.

Security level is determined by the passed authPassword and privPassword, if both of them are null or empty strings, security level is noAuthNoPriv. If privPassword is null or empty string, security level is authNoPriv. If both of them are non-empty strings, security level is authPriv.

Parameters:
userName - user name
authProtocol - authentication protocol, one of {SnmpConst.MD5, SnmpConst.SHA, SnmpConst.SHA224, SnmpConst.SHA256, SnmpConst.SHA384, SnmpConst.SHA512}
engineID - engine ID of trap sender
host - host name or ip address of trap receiver
port - port number of trap receiver
authPassword - authentication password. It will be used to generate localized authentication key.
privPassword - privacy protocol password. It will be used to generate localized privacy key.
Since:
SnmpV3

addV3Params

public static void addV3Params(String userName,
                               String authProtocol,
                               String authPassword,
                               int privProtocol,
                               String privPassword,
                               byte[] engineID,
                               String host,
                               int port)
Adds SNMPV3 trap receiver's properties.

Security level is determined by the passed authPassword and privPassword, if both of them are null or empty strings, security level is noAuthNoPriv. If privPassword is null or empty string, security level is authNoPriv. If both of them are non-empty strings, security level is authPriv.

Parameters:
userName - user name
authProtocol - authentication protocol, one of {SnmpConst.MD5, SnmpConst.SHA, SnmpConst.SHA224, SnmpConst.SHA256, SnmpConst.SHA384, SnmpConst.SHA512}
engineID - engine ID of trap sender
host - host name or ip address of trap receiver
port - port number of trap receiver
authPassword - authentication password. It will be used to generate localized authentication key.
privProtocol - privacy protocol. One of {SnmpConst.DES, SnmpConst.AES, SnmpConst.AES192, SnmpConst.AES256}. Default value is SnmpConst.DES
privPassword - privacy protocol password. It will be used to generate localized privacy key.
Since:
SnmpV3

addV3Params

public static void addV3Params(String userName,
                               String authProtocol,
                               String authPassword,
                               int privProtocol,
                               String privPassword,
                               byte[] engineID,
                               String contextName,
                               String host,
                               int port)
Adds SNMPV3 trap receiver's properties.

Security level is determined by the passed authPassword and privPassword, if both of them are null or empty strings, security level is noAuthNoPriv. If privPassword is null or empty string, security level is authNoPriv. If both of them are non-empty strings, security level is authPriv.

Parameters:
userName - user name
authProtocol - authentication protocol, one of {SnmpConst.MD5, SnmpConst.SHA, SnmpConst.SHA224, SnmpConst.SHA256, SnmpConst.SHA384, SnmpConst.SHA512}
engineID - engine ID of trap sender
host - host name or ip address of trap receiver
port - port number of trap receiver
authPassword - authentication password. It will be used to generate localized authentication key.
privProtocol - privacy protocol. One of {SnmpConst.DES, SnmpConst.AES, SnmpConst.AES192, SnmpConst.AES256}. Default value is SnmpConst.DES
privPassword - privacy protocol password. It will be used to generate localized privacy key.
contextName - SNMPv3 context name. Usually it is "".
Since:
SnmpV3

setSnmpEngine

public static void setSnmpEngine(String host,
                                 byte[] engineID,
                                 int engineTime,
                                 int engineBoots)
Sets the SNMPv3 trap sender's engine properties

Parameters:
host - local host name or ip address. If null, "localhost" will be used
engineID - trap sender engine ID
engineTime - snmp engine time
engineBoots - snmpv3 engine boots

HOME

Copyright © 2002 iReasoning Inc. All Rights Reserved.