Class EventUtils


  • public abstract class EventUtils
    extends java.lang.Object

    Abstract EventUtils class.

    Version:
    $Id: $
    Author:
    ranger
    • Constructor Summary

      Constructors 
      Constructor Description
      EventUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void checkInterface​(IEvent e)  
      static void checkInterface​(Event e)
      Ensures the given event has an interface
      static void checkNodeId​(IEvent e)  
      static void checkNodeId​(Event e)
      Ensures that the given Event has a node id
      static void checkService​(IEvent e)  
      static void checkService​(Event e)
      Ensures that the given event has a service parameter
      static Event createApplicationDeletedEvent​(java.lang.String source, int applicationId, java.lang.String applicationName)
      Constructs a applicationDeleted Event for a given application id and name
      static Event createAssetInfoChangedEvent​(java.lang.String source, long nodeId, long txNo)
      Construct a deleteNode event for the given nodeId.
      static Event createDeleteInterfaceEvent​(java.lang.String source, long nodeId, java.lang.String ipAddr, int ifIndex, long txNo)
      Constructs a deleteInterface event for the given nodeId, ipAddress (or ifIndex) pair.
      static Event createDeleteNodeEvent​(java.lang.String source, long nodeId, long txNo)  
      static Event createDeleteServiceEvent​(java.lang.String source, long nodeId, java.lang.String ipAddr, java.lang.String service, long txNo)
      Constructs a deleteService event for the given nodeId, ipAddress, serviceName triple.
      static Event createInterfaceDeletedEvent​(java.lang.String source, int nodeId, java.net.InetAddress addr)
      Construct an interfaceDeleted event for an interface.
      static Event createNodeAddedEvent​(java.lang.String source, int nodeId, java.lang.String nodeLabel, OnmsNode.NodeLabelSource labelSource)
      createNodeAddedEvent
      static Event createNodeCategoryMembershipChangedEvent​(java.lang.String source, java.lang.Integer nodeId, java.lang.String nodeLabel, java.lang.String[] categoriesAdded, java.lang.String[] categoriesDeleted)  
      static Event createNodeDeletedEvent​(java.lang.String source, int nodeId, java.lang.String hostName, java.lang.String nodeLabel, OnmsMonitoringLocation nodeLocation, java.lang.String nodeForeignId, java.lang.String nodeForeignSource, OnmsIpInterface nodePrimaryInterface)
      This method is responsible for generating a nodeDeleted event and sending it to eventd..
      static Event createNodeGainedInterfaceEvent​(java.lang.String source, int nodeId, java.net.InetAddress ifaddr)
      createNodeGainedInterfaceEvent
      static Event createNodeGainedServiceEvent​(java.lang.String source, int nodeId, java.net.InetAddress ifaddr, java.lang.String service, java.lang.String nodeLabel, OnmsNode.NodeLabelSource labelSource, java.lang.String sysName, java.lang.String sysDescr)
      createNodeGainedServiceEvent
      static Event createNodeLocationChangedEvent​(java.lang.String source, java.lang.Integer nodeId, java.lang.String nodeLabel, java.lang.String prevLocation, java.lang.String currentLocation)
      createNodeLocationChangedEvent
      static Event createNodeUpdatedEvent​(java.lang.String source, java.lang.Integer nodeId, java.lang.String nodeLabel, OnmsNode.NodeLabelSource labelSource, java.lang.String rescanExisting)
      createNodeUpdatedEvent
      static Event createServiceDeletedEvent​(java.lang.String source, int nodeId, java.net.InetAddress addr, java.lang.String service)
      Constructs a serviceDeleted Event for the nodeId, ipAddr, serviceName triple
      static boolean eventsMatch​(IEvent e1, IEvent e2)
      eventsMatch
      static boolean eventsMatch​(Event e1, Event e2)
      eventsMatch
      static int getIntParm​(IEvent e, java.lang.String parmName, int defaultValue)  
      static int getIntParm​(Event e, java.lang.String parmName, int defaultValue)
      Retrieve the value associated with an event parameter and parse it to an int.
      static long getLongParm​(Event e, java.lang.String parmName, long defaultValue)
      Retrieve the value associated with an event parameter and parse it to a long.
      static java.lang.String getParm​(IEvent e, java.lang.String parmName)  
      static java.lang.String getParm​(IEvent e, java.lang.String parmName, java.lang.String defaultValue)  
      static java.lang.String getParm​(Event e, java.lang.String parmName)
      Return the value of an event parameter of null if it does not exist.
      static java.lang.String getParm​(Event e, java.lang.String parmName, java.lang.String defaultValue)
      Retrieve a parameter from and event, returning defaultValue of the parameter is not set.
      static boolean isNonIpInterface​(java.lang.String intf)
      Is the given interface a non-IP interface
      static void requireParm​(IEvent e, java.lang.String parmName)  
      static void requireParm​(Event e, java.lang.String parmName)
      Throw an exception if an event does have the required parameter
      static java.lang.String toString​(java.util.Collection<Parm> parms)  
      static java.lang.String toString​(Event event)
      toString
      static java.lang.String toString​(Snmp snmp)
      toString
      static java.lang.String toString​(Value value)
      toString
      • 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

      • createNodeAddedEvent

        public static Event createNodeAddedEvent​(java.lang.String source,
                                                 int nodeId,
                                                 java.lang.String nodeLabel,
                                                 OnmsNode.NodeLabelSource 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​(java.lang.String source,
                                                           int nodeId,
                                                           java.net.InetAddress ifaddr)

        createNodeGainedInterfaceEvent

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

        public static Event createNodeGainedServiceEvent​(java.lang.String source,
                                                         int nodeId,
                                                         java.net.InetAddress ifaddr,
                                                         java.lang.String service,
                                                         java.lang.String nodeLabel,
                                                         OnmsNode.NodeLabelSource labelSource,
                                                         java.lang.String sysName,
                                                         java.lang.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.
      • createNodeDeletedEvent

        public static Event createNodeDeletedEvent​(java.lang.String source,
                                                   int nodeId,
                                                   java.lang.String hostName,
                                                   java.lang.String nodeLabel,
                                                   OnmsMonitoringLocation nodeLocation,
                                                   java.lang.String nodeForeignId,
                                                   java.lang.String nodeForeignSource,
                                                   OnmsIpInterface nodePrimaryInterface)
        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.
        Returns:
        a Event object.
      • createInterfaceDeletedEvent

        public static Event createInterfaceDeletedEvent​(java.lang.String source,
                                                        int nodeId,
                                                        java.net.InetAddress addr)
        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
        Returns:
        an Event represent an interfaceDeleted event for the given interface
      • createServiceDeletedEvent

        public static Event createServiceDeletedEvent​(java.lang.String source,
                                                      int nodeId,
                                                      java.net.InetAddress addr,
                                                      java.lang.String service)
        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
        Returns:
        an Event that represents the serviceDeleted event for the give triple
      • createApplicationDeletedEvent

        public static Event createApplicationDeletedEvent​(java.lang.String source,
                                                          int applicationId,
                                                          java.lang.String applicationName)
        Constructs a applicationDeleted Event for a given application id and name
        Parameters:
        source - the source of the event
        applicationId - the id of the deleted application
        applicationName - the name of the deleted application
        Returns:
        an Event that represents the applicationDeleted event for the given id and name
      • getLongParm

        public static long getLongParm​(Event e,
                                       java.lang.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,
                                     java.lang.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
      • getParm

        public static java.lang.String getParm​(Event e,
                                               java.lang.String parmName,
                                               java.lang.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
      • getParm

        public static java.lang.String getParm​(Event e,
                                               java.lang.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
      • createNodeUpdatedEvent

        public static Event createNodeUpdatedEvent​(java.lang.String source,
                                                   java.lang.Integer nodeId,
                                                   java.lang.String nodeLabel,
                                                   OnmsNode.NodeLabelSource labelSource,
                                                   java.lang.String rescanExisting)

        createNodeUpdatedEvent

        Parameters:
        source - a String object.
        nodeId - a Integer object.
        nodeLabel - a String object.
        labelSource - a String object.
        rescanExisting - a String object.
        Returns:
        a Event object.
      • createNodeLocationChangedEvent

        public static Event createNodeLocationChangedEvent​(java.lang.String source,
                                                           java.lang.Integer nodeId,
                                                           java.lang.String nodeLabel,
                                                           java.lang.String prevLocation,
                                                           java.lang.String currentLocation)

        createNodeLocationChangedEvent

        Parameters:
        source - a String object.
        nodeId - a Integer object.
        nodeLabel - a String object.
        prevLocation - a String object.
        currentLocation - a String object.
        Returns:
        a Event object.
      • createNodeCategoryMembershipChangedEvent

        public static Event createNodeCategoryMembershipChangedEvent​(java.lang.String source,
                                                                     java.lang.Integer nodeId,
                                                                     java.lang.String nodeLabel,
                                                                     java.lang.String[] categoriesAdded,
                                                                     java.lang.String[] categoriesDeleted)
      • toString

        public static java.lang.String toString​(Event event)

        toString

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

        public static java.lang.String toString​(java.util.Collection<Parm> parms)
      • toString

        public static java.lang.String toString​(Value value)

        toString

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

        public static java.lang.String toString​(Snmp snmp)

        toString

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

        public static boolean eventsMatch​(Event e1,
                                          Event e2)

        eventsMatch

        Parameters:
        e1 - a Event object.
        e2 - a Event object.
        Returns:
        a boolean.
      • eventsMatch

        public static boolean eventsMatch​(IEvent e1,
                                          IEvent e2)

        eventsMatch

        Parameters:
        e1 - a IEvent object.
        e2 - a IEvent object.
        Returns:
        a boolean.
      • isNonIpInterface

        public static boolean isNonIpInterface​(java.lang.String intf)
        Is the given interface a non-IP interface
        Parameters:
        intf - the interface
        Returns:
        true/false
      • createDeleteInterfaceEvent

        public static Event createDeleteInterfaceEvent​(java.lang.String source,
                                                       long nodeId,
                                                       java.lang.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​(java.lang.String source,
                                                  long nodeId,
                                                  long txNo)
      • createAssetInfoChangedEvent

        public static Event createAssetInfoChangedEvent​(java.lang.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.
      • createDeleteServiceEvent

        public static Event createDeleteServiceEvent​(java.lang.String source,
                                                     long nodeId,
                                                     java.lang.String ipAddr,
                                                     java.lang.String service,
                                                     long txNo)
        Constructs a deleteService event for the given nodeId, ipAddress, serviceName 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
      • requireParm

        public static void requireParm​(Event e,
                                       java.lang.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:
        org.opennms.netmgt.capsd.InsufficientInformationException - if the paramter is not set on the event or if its value has no content
        InsufficientInformationException
      • getParm

        public static java.lang.String getParm​(IEvent e,
                                               java.lang.String parmName)
      • getParm

        public static java.lang.String getParm​(IEvent e,
                                               java.lang.String parmName,
                                               java.lang.String defaultValue)
      • getIntParm

        public static int getIntParm​(IEvent e,
                                     java.lang.String parmName,
                                     int defaultValue)