org.opennms.netmgt.capsd
Class EventUtils

java.lang.Object
  extended by org.opennms.netmgt.capsd.EventUtils

public abstract class EventUtils
extends Object

Provides a collection of utility methods used by the DeleteEvent Processor for dealing with Events

Version:
$Id: $
Author:
brozow

Constructor Summary
EventUtils()
           
 
Method Summary
static void addEventListener(EventListener listener, List<String> ueiList)
          Make the given listener object a listener for the list of events referenced in the ueiList.
static void addParam(Event event, String parmName, Object pollResultId)
          addParam
static void checkEventId(Event e)
          Ensures that the event has a database eventId
static void checkHost(Event e)
          Ensures the given event has a host
static void checkInterface(Event e)
          Ensures the given event has an interface
static void checkInterfaceOrIfIndex(Event e)
          Ensures the given event has an interface or ifIndex
static void checkNodeId(Event e)
          Ensures that the given Event has a node id
static void checkService(Event e)
          Ensures that the given event has a service parameter
static Event createAddInterfaceEvent(String source, String nodeLabel, String ipaddr, String hostName, long txNo)
          This method is responsible for generating an addInterface event and sending it to eventd..
static Event createAndSendDeleteInterfaceEvent(String source, String nodeLabel, String ipaddr, String hostName, long txNo)
          This method is responsible for generating a deleteInterface event and sending it to eventd..
static Event createAndSendDeleteNodeEvent(String source, String nodeLabel, String hostName, long txNo)
          This method is responsible for generating a deleteNode event and sending it to eventd..
static Event createAndSendDeleteServiceEvent(String source, org.opennms.netmgt.capsd.DbNodeEntry nodeEntry, InetAddress ifaddr, String service, String hostName, long txNo)
          This method is responsible for generating a deleteService event and sending it to eventd..
static Event createAndSendInterfaceDeletedEvent(String source, int nodeId, String ipaddr, String hostName, long txNo)
          This method is responsible for generating an interfaceDeleted event and sending it to eventd...
static Event createAssetInfoChangedEvent(String source, long nodeId, long txNo)
          Construct a deleteNode event for the given nodeId.
static Event createChangeServiceEvent(String source, String ipaddr, String service, String action, String hostName, long txNo)
          This method is responsible for generating a changeService event and sending it to eventd..
static Event createDeleteInterfaceEvent(String source, long nodeId, String ipAddr, int ifIndex, long txNo)
          Constructs a deleteInterface event for the given nodeId, ipAddress (or ifIndex) pair.
static Event createDeleteNodeEvent(String source, long nodeId, long txNo)
          Construct a deleteNode event for the given nodeId.
static Event createDeleteServiceEvent(String source, long nodeId, String ipAddr, String service, long txNo)
          Constructs a deleteService event for the given nodeId, ipAddress, serivcename triple.
static Event createForceRescanEvent(String hostName, long nodeId)
          This method is responsible for generating a forceRescan event and sending it to eventd..
static Event createInterfaceDeletedEvent(String source, long nodeId, String ipAddr, int ifIndex, long txNo)
          Construct an interfaceDeleted event for an interface.
static Event createInterfaceDeletedEvent(String source, long nodeId, String ipAddr, long txNo)
          Construct an interfaceDeleted event for an interface.
static Event createNodeAddedEvent(org.opennms.netmgt.capsd.DbNodeEntry nodeEntry)
          This method is responsible for generating a nodeAdded event and sending it to eventd..
static Event createNodeAddedEvent(int nodeId, String nodeLabel, String labelSource)
          createNodeAddedEvent
static Event createNodeAddedEvent(String source, int nodeId, String nodeLabel, String labelSource)
          createNodeAddedEvent
static Event createNodeDeletedEvent(String source, int nodeId, String hostName, String nodeLabel, long txNo)
          This method is responsible for generating a nodeDeleted event and sending it to eventd..
static Event createNodeDeletedEvent(String source, long nodeId, long txNo)
          Construct a nodeDeleteed event for the given nodeId
static Event createNodeGainedInterfaceEvent(org.opennms.netmgt.capsd.DbNodeEntry nodeEntry, InetAddress ifaddr)
          This method is responsible for generating a nodeGainedInterface event and sending it to eventd..
static Event createNodeGainedInterfaceEvent(String source, int nodeId, InetAddress ifaddr)
          createNodeGainedInterfaceEvent
static Event createNodeGainedServiceEvent(org.opennms.netmgt.capsd.DbNodeEntry nodeEntry, InetAddress ifaddr, String service, long txNo)
          This method is responsible for generating a nodeGainedService event and sending it to eventd..
static Event createNodeGainedServiceEvent(String source, int nodeId, InetAddress ifaddr, String service, String nodeLabel, String labelSource, String sysName, String sysDescr)
          createNodeGainedServiceEvent
static Event createServiceDeletedEvent(String source, long nodeId, String ipAddr, String service, long txNo)
          Constructs a serviceDeleted Event for the nodeId, ipAddr, serviceName triple
static long getEventID(Event e)
          Get the eventId for the given event
static int getIntParm(Event e, String parmName)
          getIntParm
static int getIntParm(Event e, String parmName, int defaultValue)
          Retrieve the value associated with an event parameter and parse it to an int.
static long getLongParm(Event e, String parmName, long defaultValue)
          Retrieve the value associated with an event parameter and parse it to a long.
static long getNodeId(Event e)
          Return the nodeId of the node associated with and event, or -1 of no node is associated.
static String getParm(Event e, String parmName)
          Return the value of an event parameter of null if it does not exist.
static String getParm(Event e, String parmName, String defaultValue)
          Retrieve a parameter from and event, returning defaultValue of the parameter is not set.
static boolean isNonIpInterface(String intf)
          Is the given interface a non-IP interface
static void requireParm(Event e, String parmName)
          Throw an exception if an event does have the required parameter
static void sendEvent(Event newEvent, String callerUei, long txNo, boolean isXmlRpcEnabled)
          Send an event to the Event manaager to be broadcast to interested listeners
static String toString(Event event)
          Deprecated. Use org.opennms.netmgt.model.events.EventUtils.toString(event) instead.
static String toString(Parms parms)
          Deprecated. Use org.opennms.netmgt.model.events.EventUtils.toString(snmp) instead.
static String toString(Snmp snmp)
          Deprecated. Use org.opennms.netmgt.model.events.EventUtils.toString(snmp) instead.
static String toString(Value value)
          Deprecated. Use org.opennms.netmgt.model.events.EventUtils.toString(value) instead.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventUtils

public EventUtils()
Method Detail

addEventListener

public static void addEventListener(EventListener listener,
                                    List<String> ueiList)
Make the given listener object a listener for the list of events referenced in the ueiList.

Parameters:
listener - the lister to add
ueiList - the list of events the listener is interested

checkEventId

public static void checkEventId(Event e)
                         throws InsufficientInformationException
Ensures that the event has a database eventId

Parameters:
e - the event
Throws:
InsufficientInformationException - if an event id is not evailable

checkInterface

public static void checkInterface(Event e)
                           throws InsufficientInformationException
Ensures the given event has an interface

Parameters:
e - the event
Throws:
InsufficientInformationException - if an interface is not available

isNonIpInterface

public static boolean isNonIpInterface(String intf)
Is the given interface a non-IP interface

Parameters:
intf - the interface
Returns:
true/false

checkInterfaceOrIfIndex

public static void checkInterfaceOrIfIndex(Event e)
                                    throws InsufficientInformationException
Ensures the given event has an interface or ifIndex

Parameters:
e - the event
Throws:
InsufficientInformationException - if neither an interface nor an ifIndex is available

checkHost

public static void checkHost(Event e)
                      throws InsufficientInformationException
Ensures the given event has a host

Parameters:
e - the event
Throws:
InsufficientInformationException - if an interface is not available

checkNodeId

public static void checkNodeId(Event e)
                        throws InsufficientInformationException
Ensures that the given Event has a node id

Parameters:
e - the event
Throws:
InsufficientInformationException - if a node id is not available

checkService

public static void checkService(Event e)
                         throws InsufficientInformationException
Ensures that the given event has a service parameter

Parameters:
e - the event to check
Throws:
InsufficientInformationException - if the event does not have a service

createDeleteInterfaceEvent

public static Event createDeleteInterfaceEvent(String source,
                                               long nodeId,
                                               String ipAddr,
                                               int ifIndex,
                                               long txNo)
Constructs a deleteInterface event for the given nodeId, ipAddress (or ifIndex) pair.

Parameters:
source - the source for the event
nodeId - the nodeId of the node that owns the interface
ipAddr - the ipAddress of the interface being deleted
ifIndex - the ifIndex of the interface being deleted
txNo - the transaction number to use for processing this event
Returns:
an Event representing a deleteInterface event for the given nodeId, ipaddr

createDeleteNodeEvent

public static Event createDeleteNodeEvent(String source,
                                          long nodeId,
                                          long txNo)
Construct a deleteNode event for the given nodeId.

Parameters:
source - the source for the event
nodeId - the node to be deleted.
txNo - the transaction number associated with deleting the node
Returns:
an Event object representing a delete node event.

createAssetInfoChangedEvent

public static Event createAssetInfoChangedEvent(String source,
                                                long nodeId,
                                                long txNo)
Construct a deleteNode event for the given nodeId.

Parameters:
source - the source for the event
nodeId - the node to be deleted.
txNo - the transaction number associated with deleting the node
Returns:
an Event object representing a delete node event.

createInterfaceDeletedEvent

public static Event createInterfaceDeletedEvent(String source,
                                                long nodeId,
                                                String ipAddr,
                                                long txNo)
Construct an interfaceDeleted event for an interface.

Parameters:
source - the source of the event
nodeId - the nodeId of the node the interface resides in
ipAddr - the ipAdddr of the event
txNo - a transaction number associated with the event
Returns:
Event an interfaceDeleted event for the given interface

createInterfaceDeletedEvent

public static Event createInterfaceDeletedEvent(String source,
                                                long nodeId,
                                                String ipAddr,
                                                int ifIndex,
                                                long txNo)
Construct an interfaceDeleted event for an interface.

Parameters:
source - the source of the event
nodeId - the nodeId of the node the interface resides in
ipAddr - the ipAdddr of the event
ifIndex - the ifIndex of the event
txNo - a transaction number associated with the event
Returns:
Event an interfaceDeleted event for the given interface

createNodeDeletedEvent

public static Event createNodeDeletedEvent(String source,
                                           long nodeId,
                                           long txNo)
Construct a nodeDeleteed event for the given nodeId

Parameters:
source - the source for the event
nodeId - the id of the node being deleted
txNo - a transaction number associated with the event
Returns:
an Event representing a nodeDeleted event for the given node

createServiceDeletedEvent

public static Event createServiceDeletedEvent(String source,
                                              long nodeId,
                                              String ipAddr,
                                              String service,
                                              long txNo)
Constructs a serviceDeleted Event for the nodeId, ipAddr, serviceName triple

Parameters:
source - the source of the event
nodeId - the nodeId that the service resides on
ipAddr - the interface that the service resides on
service - the name of the service that was deleted
txNo - a transaction number associated with the event
Returns:
an Event that represents the serviceDeleted event for the give triple

getEventID

public static long getEventID(Event e)
Get the eventId for the given event

Parameters:
e - the event to get the eventId for
Returns:
the eventId of the event or -1 of no eventId is assigned

getLongParm

public static long getLongParm(Event e,
                               String parmName,
                               long defaultValue)
Retrieve the value associated with an event parameter and parse it to a long. If the value can not be found, return a default value.

Parameters:
e - the Event to retrieve the parameter from
parmName - the name of the parameter to retrieve
defaultValue - the value to return if the paramter can not be retrieved or parsed
Returns:
the value of the parameter as a long

getIntParm

public static int getIntParm(Event e,
                             String parmName,
                             int defaultValue)
Retrieve the value associated with an event parameter and parse it to an int. If the value can not be found, return a default value.

Parameters:
e - the Event to retrieve the parameter from
parmName - the name of the parameter to retrieve
defaultValue - the value to return if the paramter can not be retrieved or parsed
Returns:
the value of the parameter as a long

getIntParm

public static int getIntParm(Event e,
                             String parmName)

getIntParm

Parameters:
e - a Event object.
parmName - a String object.
Returns:
a int.

getNodeId

public static long getNodeId(Event e)
Return the nodeId of the node associated with and event, or -1 of no node is associated.

Parameters:
e - the event
Returns:
the nodeId or -1 if no nodeId is set

getParm

public static String getParm(Event e,
                             String parmName)
Return the value of an event parameter of null if it does not exist.

Parameters:
e - the Event to get the parameter for
parmName - the name of the parameter to retrieve
Returns:
the value of the parameter, or null of the parameter is not set

getParm

public static String getParm(Event e,
                             String parmName,
                             String defaultValue)
Retrieve a parameter from and event, returning defaultValue of the parameter is not set.

Parameters:
e - The Event to retrieve the parameter from
parmName - the name of the parameter to retrieve
defaultValue - the default value to return if the parameter is not set
Returns:
the value of the parameter, or defalutValue if the parameter is not set

requireParm

public static void requireParm(Event e,
                               String parmName)
                        throws InsufficientInformationException
Throw an exception if an event does have the required parameter

Parameters:
e - the event the parameter must reside on
parmName - a String object.
Throws:
InsufficientInformationException - if the paramter is not set on the event or if its value has no content

sendEvent

public static void sendEvent(Event newEvent,
                             String callerUei,
                             long txNo,
                             boolean isXmlRpcEnabled)
Send an event to the Event manaager to be broadcast to interested listeners

Parameters:
newEvent - the event to send
isXmlRpcEnabled - a boolean.
callerUei - a String object.
txNo - a long.

createNodeAddedEvent

public static Event createNodeAddedEvent(org.opennms.netmgt.capsd.DbNodeEntry nodeEntry)
This method is responsible for generating a nodeAdded event and sending it to eventd..

Parameters:
nodeEntry - The node Added.
Returns:
a Event object.

createNodeAddedEvent

public static Event createNodeAddedEvent(int nodeId,
                                         String nodeLabel,
                                         String labelSource)

createNodeAddedEvent

Parameters:
nodeId - a int.
nodeLabel - a String object.
labelSource - a String object.
Returns:
a Event object.

createNodeAddedEvent

public static Event createNodeAddedEvent(String source,
                                         int nodeId,
                                         String nodeLabel,
                                         String labelSource)

createNodeAddedEvent

Parameters:
source - a String object.
nodeId - a int.
nodeLabel - a String object.
labelSource - a String object.
Returns:
a Event object.

createNodeGainedInterfaceEvent

public static Event createNodeGainedInterfaceEvent(org.opennms.netmgt.capsd.DbNodeEntry nodeEntry,
                                                   InetAddress ifaddr)
This method is responsible for generating a nodeGainedInterface event and sending it to eventd..

Parameters:
nodeEntry - The node that gained the interface.
ifaddr - the interface gained on the node.
Returns:
a Event object.

createNodeGainedInterfaceEvent

public static Event createNodeGainedInterfaceEvent(String source,
                                                   int nodeId,
                                                   InetAddress ifaddr)

createNodeGainedInterfaceEvent

Parameters:
source - a String object.
nodeId - a int.
ifaddr - a InetAddress object.
Returns:
a Event object.

createNodeDeletedEvent

public static Event createNodeDeletedEvent(String source,
                                           int nodeId,
                                           String hostName,
                                           String nodeLabel,
                                           long txNo)
This method is responsible for generating a nodeDeleted event and sending it to eventd..

Parameters:
source - A string representing the source of the event
nodeId - Nodeid of the node got deleted.
hostName - the Host server name.
nodeLabel - the node label of the deleted node.
txNo - a long.
Returns:
a Event object.

createAndSendDeleteNodeEvent

public static Event createAndSendDeleteNodeEvent(String source,
                                                 String nodeLabel,
                                                 String hostName,
                                                 long txNo)
This method is responsible for generating a deleteNode event and sending it to eventd..

Parameters:
source - the source of the event
nodeLabel - the nodelabel of the deleted node.
hostName - the Host server name.
txNo - the external transaction No of the event.
Returns:
a Event object.

createForceRescanEvent

public static Event createForceRescanEvent(String hostName,
                                           long nodeId)
This method is responsible for generating a forceRescan event and sending it to eventd..

Parameters:
hostName - the Host server name.
nodeId - the node ID of the node to rescan.
Returns:
a Event object.

createAndSendInterfaceDeletedEvent

public static Event createAndSendInterfaceDeletedEvent(String source,
                                                       int nodeId,
                                                       String ipaddr,
                                                       String hostName,
                                                       long txNo)
This method is responsible for generating an interfaceDeleted event and sending it to eventd...

Parameters:
source - the source of the event
nodeId - Nodeid of the node that the deleted interface resides on.
ipaddr - the ipaddress of the deleted Interface.
hostName - the Host server name.
txNo - the external transaction No. of the original event.
Returns:
a Event object.

createNodeGainedServiceEvent

public static Event createNodeGainedServiceEvent(org.opennms.netmgt.capsd.DbNodeEntry nodeEntry,
                                                 InetAddress ifaddr,
                                                 String service,
                                                 long txNo)
This method is responsible for generating a nodeGainedService event and sending it to eventd..

Parameters:
nodeEntry - The node that gained the service.
ifaddr - the interface gained the service.
service - the service gained.
txNo - the transaction no.
Returns:
a Event object.

createNodeGainedServiceEvent

public static Event createNodeGainedServiceEvent(String source,
                                                 int nodeId,
                                                 InetAddress ifaddr,
                                                 String service,
                                                 String nodeLabel,
                                                 String labelSource,
                                                 String sysName,
                                                 String sysDescr)

createNodeGainedServiceEvent

Parameters:
source - a String object.
nodeId - a int.
ifaddr - a InetAddress object.
service - a String object.
nodeLabel - a String object.
labelSource - a String object.
sysName - a String object.
sysDescr - a String object.
Returns:
a Event object.

createAndSendDeleteServiceEvent

public static Event createAndSendDeleteServiceEvent(String source,
                                                    org.opennms.netmgt.capsd.DbNodeEntry nodeEntry,
                                                    InetAddress ifaddr,
                                                    String service,
                                                    String hostName,
                                                    long txNo)
This method is responsible for generating a deleteService event and sending it to eventd..

Parameters:
source - the source of the event
nodeEntry - The node that the service to get deleted on.
ifaddr - the interface the service to get deleted on.
service - the service to delete.
hostName - set to the host field in the event
txNo - the transaction no.
Returns:
a Event object.

createAddInterfaceEvent

public static Event createAddInterfaceEvent(String source,
                                            String nodeLabel,
                                            String ipaddr,
                                            String hostName,
                                            long txNo)
This method is responsible for generating an addInterface event and sending it to eventd..

Parameters:
source - the source of the event
nodeLabel - the node label of the node where the interface resides.
ipaddr - IP address of the interface to be added.
hostName - the Host server name.
txNo - the exteranl transaction number
Returns:
a Event object.

createAndSendDeleteInterfaceEvent

public static Event createAndSendDeleteInterfaceEvent(String source,
                                                      String nodeLabel,
                                                      String ipaddr,
                                                      String hostName,
                                                      long txNo)
This method is responsible for generating a deleteInterface event and sending it to eventd..

Parameters:
source - the source of the event
nodeLabel - the node label of the node where the interface resides.
ipaddr - IP address of the interface to be deleted.
hostName - the Host server name.
txNo - the external transaction No.
Returns:
a Event object.

createChangeServiceEvent

public static Event createChangeServiceEvent(String source,
                                             String ipaddr,
                                             String service,
                                             String action,
                                             String hostName,
                                             long txNo)
This method is responsible for generating a changeService event and sending it to eventd..

Parameters:
source - the source of the event
ipaddr - IP address of the interface where the service resides.
service - the service to be changed(add or remove).
action - what operation to perform for the service/interface pair.
hostName - sets the host field of the event
txNo - the external transaction No.
Returns:
a Event object.

createDeleteServiceEvent

public static Event createDeleteServiceEvent(String source,
                                             long nodeId,
                                             String ipAddr,
                                             String service,
                                             long txNo)
Constructs a deleteService event for the given nodeId, ipAddress, serivcename triple.

Parameters:
source - the source for the event
nodeId - the nodeId of the node that service resides on
ipAddr - the ipAddress of the interface the service resides on
service - the service that is being deleted
txNo - the transaction number to use for processing this event
Returns:
an Event representing a deleteInterface event for the given nodeId, ipaddr

toString

public static String toString(Event event)
Deprecated. Use org.opennms.netmgt.model.events.EventUtils.toString(event) instead.

toString

Parameters:
event - a Event object.
Returns:
a String object.

toString

public static String toString(Value value)
Deprecated. Use org.opennms.netmgt.model.events.EventUtils.toString(value) instead.

toString

Parameters:
value - a Value object.
Returns:
a String object.

toString

public static String toString(Snmp snmp)
Deprecated. Use org.opennms.netmgt.model.events.EventUtils.toString(snmp) instead.

toString

Parameters:
snmp - a Snmp object.
Returns:
a String object.

toString

public static String toString(Parms parms)
Deprecated. Use org.opennms.netmgt.model.events.EventUtils.toString(snmp) instead.

toString

Parameters:
parms - a Parms object.
Returns:
a String object.

addParam

public static void addParam(Event event,
                            String parmName,
                            Object pollResultId)

addParam

Parameters:
event - a Event object.
parmName - a String object.
pollResultId - a Object object.


Copyright © 2011. All Rights Reserved.