Class AbstractEventUtil

  • All Implemented Interfaces:
    EventUtil
    Direct Known Subclasses:
    EventUtilDaoImpl

    public abstract class AbstractEventUtil
    extends java.lang.Object
    implements EventUtil
    EventUtil is used primarily for the event parm expansion - has methods used by all the event components to send in the event and the element to expanded and have the 'expanded' value sent back
    Author:
    Sowmya Kumaraswamy , Brain Weaver , OpenNMS
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.lang.String ASSET_BEGIN
      The string that starts the expansion for an asset field - used to lookup values of asset fields by their names
      protected static java.lang.String ASSET_END_SUFFIX
      The string that ends the expansion of a parm
      protected static char ATTRIB_DELIM
      The values and the corresponding attributes of an element are added delimited by ATTRIB_DELIM
      protected static java.lang.String HARDWARE_BEGIN
      The string that starts the expansion for a hardware field - used to lookup values of hardware attributes by their index|name
      protected static java.lang.String HARDWARE_END_SUFFIX
      The string that ends the expansion of a hardware
      protected static char NAME_VAL_DELIM
      For expansion of the '%parms[all]%' - the parm name and value are added as delimiter separated list of ' = ' strings
      protected static java.lang.String NUM_PARMS_STR
      The string that should be expanded to the number of parms
      protected static java.lang.String PARM_BEGIN
      The string that starts the expansion for a parm - used to lookup values of parameters by their names
      protected static int PARM_BEGIN_LENGTH
      The length of PARM_BEGIN
      protected static java.lang.String PARM_END_SUFFIX
      The string that ends the expansion of a parm
      protected static java.lang.String PARM_NAME_NUMBERED_PREFIX
      The string that starts a request for the name of a numbered parm
      protected static int PARM_NAME_NUMBERED_PREFIX_LENGTH
      The length of PARM_NAME_NUMBERED_PREFIX
      protected static java.lang.String PARM_NUM_PREFIX
      The string that starts a parm number - used to lookup values of parameters by their position
      protected static int PARM_NUM_PREFIX_LENGTH
      The length of PARM_NUM_PREFIX
      protected static java.util.regex.Pattern PARM_REGEX
      Pattern used to match and parse 'parm' tokens.
      protected static java.lang.String PARMS_ALL
      The string that should be expanded to a list of all parms
      protected static java.lang.String PARMS_NAMES
      The string that should be expanded to a list of all parm names
      protected static java.lang.String PARMS_VALUES
      The string that should be expanded to a list of all parm values
      protected static char SPACE_DELIM  
      protected static java.lang.String TAG_DESCR
      The event descr xml tag
      protected static java.lang.String TAG_DPNAME
      The event dpname xml tag
      protected static java.lang.String TAG_EVENT_DB_ID
      The Event ID xml
      protected static java.lang.String TAG_FOREIGNID
      The foreignid for the event's nodeid xml tag
      protected static java.lang.String TAG_FOREIGNSOURCE
      The foreignsource for the event's nodeid xml tag
      protected static java.lang.String TAG_HOST
      The event host xml tag
      protected static java.lang.String TAG_IFALIAS
      The reverse DNS lookup of the interface
      protected static java.lang.String TAG_IFINDEX
      The event ifindex xml tag
      protected static java.lang.String TAG_INTERFACE
      The event interface xml tag
      protected static java.lang.String TAG_INTERFACE_RESOLVE
      The reverse DNS lookup of the interface
      protected static java.lang.String TAG_LOGMSG
      The event logmsg xml tag
      protected static java.lang.String TAG_MOUSEOVERTEXT
      The event mouseovertext xml tag
      protected static java.lang.String TAG_NODEID
      The event nodeid xml tag
      protected static java.lang.String TAG_NODELABEL
      The event nodelabel xml tag
      protected static java.lang.String TAG_NODELOCATION
      The event nodelocation xml tag
      protected static java.lang.String TAG_OPERINSTR
      The event operinstruct xml tag
      protected static java.lang.String TAG_PERCENT_SIGN
      Substitute the actual percent sign
      protected static java.lang.String TAG_PRIMARY_INTERFACE_ADDRESS
      The primary interface
      protected static java.lang.String TAG_SERVICE
      The event service xml tag
      protected static java.lang.String TAG_SEVERITY
      The event severity xml tag
      protected static java.lang.String TAG_SHORT_TIME
      The event time xml tag, short format
      protected static java.lang.String TAG_SNMP
      The SNMP xml tag
      protected static java.lang.String TAG_SNMP_COMMUNITY
      The event snmp community xml tag
      protected static java.lang.String TAG_SNMP_GENERIC
      The event snmp generic xml tag
      protected static java.lang.String TAG_SNMP_ID
      The event snmp id xml tag
      protected static java.lang.String TAG_SNMP_IDTEXT
      The event snmp idtext xml tag
      protected static java.lang.String TAG_SNMP_SPECIFIC
      The event snmp specific xml tag
      protected static java.lang.String TAG_SNMP_VERSION
      The event snmp version xml tag
      protected static java.lang.String TAG_SNMPHOST
      The event snmp host xml tag
      protected static java.lang.String TAG_SOURCE
      The event source xml tag
      protected static java.lang.String TAG_TIME
      The event time xml tag
      protected static java.lang.String TAG_TTICKET_ID  
      protected static java.lang.String TAG_UEI
      The UEI xml tag
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Date decodeSnmpV2TcDateAndTime​(java.math.BigInteger octetStringValue)  
      static java.lang.String escape​(java.lang.String inStr, char delimchar)
      This method is used to escape required values from strings that may contain those values.
      void expandMapValues​(java.util.Map<java.lang.String,​java.lang.String> map, Event event)
      expandMapValues
      java.lang.String expandParms​(java.lang.String inp, Event event)
      Expand the value if it has parms in one of the following formats - %element% values are expanded to have the value of the element where 'element' is an element in the event DTD - %parm[values-all]% is expanded to a delimited list of all parmblock values - %parm[names-all]% is expanded to a list of all parm names - %parm[all]% is expanded to a full dump of all parmblocks - %parm[name]% is expanded to the value of the parameter named 'name' - %parm[ ]% is replaced by the value of the parameter named 'name', if present - %parm[# ]% is replaced by the value of the parameter number 'num', if present - %parm[##]% is replaced by the number of parameters
      java.lang.String expandParms​(java.lang.String input, Event event, java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​java.lang.String>> decode)
      Expand the value if it has parms in one of the following formats - %element% values are expanded to have the value of the element where 'element' is an element in the event DTD - %parm[values-all]% is expanded to a delimited list of all parmblock values - %parm[names-all]% is expanded to a list of all parm names - %parm[all]% is expanded to a full dump of all parmblocks - %parm[name]% is expanded to the value of the parameter named 'name' - %parm[ ]% is replaced by the value of the parameter named 'name', if present - %parm[# ]% is replaced by the value of the parameter number 'num', if present - %parm[##]% is replaced by the number of parameters
      protected static java.lang.String getAllParamValues​(Event event)
      Helper method.
      protected static java.lang.String getAllParmNames​(Event event)
      Helper method.
      protected static java.lang.String getAllParmValues​(Event event)
      Helper method.
      java.lang.String getEventHost​(Event event)
      getEventHost
      static EventUtil getInstance()  
      java.lang.String getNamedParmValue​(java.lang.String parm, Event event)
      Helper method.
      protected static java.lang.String getNumParmName​(java.lang.String parm, Event event)
      Helper method.
      protected static java.lang.String getNumParmValue​(java.lang.String parm, Event event)
      Helper method.
      ExpandableParameterResolver getResolver​(java.lang.String token)  
      static void setInstance​(EventUtil instance)
      Used only for unit testing.
      static java.lang.String splitAndExtract​(java.lang.String src, java.lang.String sep, int offset, boolean doRange, int rangeLen)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • TAG_EVENT_DB_ID

        protected static final java.lang.String TAG_EVENT_DB_ID
        The Event ID xml
        See Also:
        Constant Field Values
      • TAG_UEI

        protected static final java.lang.String TAG_UEI
        The UEI xml tag
        See Also:
        Constant Field Values
      • TAG_SOURCE

        protected static final java.lang.String TAG_SOURCE
        The event source xml tag
        See Also:
        Constant Field Values
      • TAG_DESCR

        protected static final java.lang.String TAG_DESCR
        The event descr xml tag
        See Also:
        Constant Field Values
      • TAG_LOGMSG

        protected static final java.lang.String TAG_LOGMSG
        The event logmsg xml tag
        See Also:
        Constant Field Values
      • TAG_TIME

        protected static final java.lang.String TAG_TIME
        The event time xml tag
        See Also:
        Constant Field Values
      • TAG_SHORT_TIME

        protected static final java.lang.String TAG_SHORT_TIME
        The event time xml tag, short format
        See Also:
        Constant Field Values
      • TAG_DPNAME

        protected static final java.lang.String TAG_DPNAME
        The event dpname xml tag
        See Also:
        Constant Field Values
      • TAG_NODEID

        protected static final java.lang.String TAG_NODEID
        The event nodeid xml tag
        See Also:
        Constant Field Values
      • TAG_NODELABEL

        protected static final java.lang.String TAG_NODELABEL
        The event nodelabel xml tag
        See Also:
        Constant Field Values
      • TAG_NODELOCATION

        protected static final java.lang.String TAG_NODELOCATION
        The event nodelocation xml tag
        See Also:
        Constant Field Values
      • TAG_HOST

        protected static final java.lang.String TAG_HOST
        The event host xml tag
        See Also:
        Constant Field Values
      • TAG_INTERFACE

        protected static final java.lang.String TAG_INTERFACE
        The event interface xml tag
        See Also:
        Constant Field Values
      • TAG_FOREIGNSOURCE

        protected static final java.lang.String TAG_FOREIGNSOURCE
        The foreignsource for the event's nodeid xml tag
        See Also:
        Constant Field Values
      • TAG_FOREIGNID

        protected static final java.lang.String TAG_FOREIGNID
        The foreignid for the event's nodeid xml tag
        See Also:
        Constant Field Values
      • TAG_IFINDEX

        protected static final java.lang.String TAG_IFINDEX
        The event ifindex xml tag
        See Also:
        Constant Field Values
      • TAG_INTERFACE_RESOLVE

        protected static final java.lang.String TAG_INTERFACE_RESOLVE
        The reverse DNS lookup of the interface
        See Also:
        Constant Field Values
      • TAG_PRIMARY_INTERFACE_ADDRESS

        protected static final java.lang.String TAG_PRIMARY_INTERFACE_ADDRESS
        The primary interface
        See Also:
        Constant Field Values
      • TAG_IFALIAS

        protected static final java.lang.String TAG_IFALIAS
        The reverse DNS lookup of the interface
        See Also:
        Constant Field Values
      • TAG_SNMP_ID

        protected static final java.lang.String TAG_SNMP_ID
        The event snmp id xml tag
        See Also:
        Constant Field Values
      • TAG_SNMP

        protected static final java.lang.String TAG_SNMP
        The SNMP xml tag
        See Also:
        Constant Field Values
      • TAG_SNMP_IDTEXT

        protected static final java.lang.String TAG_SNMP_IDTEXT
        The event snmp idtext xml tag
        See Also:
        Constant Field Values
      • TAG_SNMP_VERSION

        protected static final java.lang.String TAG_SNMP_VERSION
        The event snmp version xml tag
        See Also:
        Constant Field Values
      • TAG_SNMP_SPECIFIC

        protected static final java.lang.String TAG_SNMP_SPECIFIC
        The event snmp specific xml tag
        See Also:
        Constant Field Values
      • TAG_SNMP_GENERIC

        protected static final java.lang.String TAG_SNMP_GENERIC
        The event snmp generic xml tag
        See Also:
        Constant Field Values
      • TAG_SNMP_COMMUNITY

        protected static final java.lang.String TAG_SNMP_COMMUNITY
        The event snmp community xml tag
        See Also:
        Constant Field Values
      • TAG_SNMPHOST

        protected static final java.lang.String TAG_SNMPHOST
        The event snmp host xml tag
        See Also:
        Constant Field Values
      • TAG_SERVICE

        protected static final java.lang.String TAG_SERVICE
        The event service xml tag
        See Also:
        Constant Field Values
      • TAG_SEVERITY

        protected static final java.lang.String TAG_SEVERITY
        The event severity xml tag
        See Also:
        Constant Field Values
      • TAG_OPERINSTR

        protected static final java.lang.String TAG_OPERINSTR
        The event operinstruct xml tag
        See Also:
        Constant Field Values
      • TAG_MOUSEOVERTEXT

        protected static final java.lang.String TAG_MOUSEOVERTEXT
        The event mouseovertext xml tag
        See Also:
        Constant Field Values
      • ASSET_BEGIN

        protected static final java.lang.String ASSET_BEGIN
        The string that starts the expansion for an asset field - used to lookup values of asset fields by their names
        See Also:
        Constant Field Values
      • ASSET_END_SUFFIX

        protected static final java.lang.String ASSET_END_SUFFIX
        The string that ends the expansion of a parm
        See Also:
        Constant Field Values
      • PARMS_NAMES

        protected static final java.lang.String PARMS_NAMES
        The string that should be expanded to a list of all parm names
        See Also:
        Constant Field Values
      • PARMS_VALUES

        protected static final java.lang.String PARMS_VALUES
        The string that should be expanded to a list of all parm values
        See Also:
        Constant Field Values
      • PARMS_ALL

        protected static final java.lang.String PARMS_ALL
        The string that should be expanded to a list of all parms
        See Also:
        Constant Field Values
      • PARM_BEGIN

        protected static final java.lang.String PARM_BEGIN
        The string that starts the expansion for a parm - used to lookup values of parameters by their names
        See Also:
        Constant Field Values
      • PARM_REGEX

        protected static final java.util.regex.Pattern PARM_REGEX
        Pattern used to match and parse 'parm' tokens.
      • PARM_BEGIN_LENGTH

        protected static final int PARM_BEGIN_LENGTH
        The length of PARM_BEGIN
        See Also:
        Constant Field Values
      • NUM_PARMS_STR

        protected static final java.lang.String NUM_PARMS_STR
        The string that should be expanded to the number of parms
        See Also:
        Constant Field Values
      • PARM_NUM_PREFIX

        protected static final java.lang.String PARM_NUM_PREFIX
        The string that starts a parm number - used to lookup values of parameters by their position
        See Also:
        Constant Field Values
      • PARM_NUM_PREFIX_LENGTH

        protected static final int PARM_NUM_PREFIX_LENGTH
        The length of PARM_NUM_PREFIX
        See Also:
        Constant Field Values
      • PARM_NAME_NUMBERED_PREFIX

        protected static final java.lang.String PARM_NAME_NUMBERED_PREFIX
        The string that starts a request for the name of a numbered parm
        See Also:
        Constant Field Values
      • PARM_NAME_NUMBERED_PREFIX_LENGTH

        protected static final int PARM_NAME_NUMBERED_PREFIX_LENGTH
        The length of PARM_NAME_NUMBERED_PREFIX
        See Also:
        Constant Field Values
      • PARM_END_SUFFIX

        protected static final java.lang.String PARM_END_SUFFIX
        The string that ends the expansion of a parm
        See Also:
        Constant Field Values
      • NAME_VAL_DELIM

        protected static final char NAME_VAL_DELIM
        For expansion of the '%parms[all]%' - the parm name and value are added as delimiter separated list of ' = ' strings
        See Also:
        Constant Field Values
      • ATTRIB_DELIM

        protected static final char ATTRIB_DELIM
        The values and the corresponding attributes of an element are added delimited by ATTRIB_DELIM
        See Also:
        Constant Field Values
      • TAG_PERCENT_SIGN

        protected static final java.lang.String TAG_PERCENT_SIGN
        Substitute the actual percent sign
        See Also:
        Constant Field Values
      • HARDWARE_BEGIN

        protected static final java.lang.String HARDWARE_BEGIN
        The string that starts the expansion for a hardware field - used to lookup values of hardware attributes by their index|name
        See Also:
        Constant Field Values
      • HARDWARE_END_SUFFIX

        protected static final java.lang.String HARDWARE_END_SUFFIX
        The string that ends the expansion of a hardware
        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractEventUtil

        public AbstractEventUtil()
      • AbstractEventUtil

        public AbstractEventUtil​(com.codahale.metrics.MetricRegistry registry)
    • Method Detail

      • getInstance

        public static EventUtil getInstance()
      • setInstance

        public static void setInstance​(EventUtil instance)
        Used only for unit testing.
        Parameters:
        instance -
      • escape

        public static java.lang.String escape​(java.lang.String inStr,
                                              char delimchar)

        This method is used to escape required values from strings that may contain those values. If the passed string contains the passed value then the character is reformatted into its %dd format.

        Parameters:
        inStr - string that might contain the delimiter
        delimchar - delimiter to escape
        Returns:
        The string with the delimiter escaped as in URLs
        See Also:
        ATTRIB_DELIM
      • getAllParmValues

        protected static java.lang.String getAllParmValues​(Event event)
        Helper method.
        Parameters:
        event -
        Returns:
        All event parameter values as a String.
      • getAllParmNames

        protected static java.lang.String getAllParmNames​(Event event)
        Helper method.
        Parameters:
        event -
        Returns:
        The names of all the event parameters.
      • getAllParamValues

        protected static java.lang.String getAllParamValues​(Event event)
        Helper method.
        Parameters:
        event -
        Returns:
        All event parameter values as a String
      • getNumParmName

        protected static java.lang.String getNumParmName​(java.lang.String parm,
                                                         Event event)
        Helper method.
        Parameters:
        parm -
        event -
        Returns:
        The name of a parameter based on its ordinal position in the event's list of parameters
      • splitAndExtract

        public static java.lang.String splitAndExtract​(java.lang.String src,
                                                       java.lang.String sep,
                                                       int offset,
                                                       boolean doRange,
                                                       int rangeLen)
      • getNumParmValue

        protected static java.lang.String getNumParmValue​(java.lang.String parm,
                                                          Event event)
        Helper method.
        Parameters:
        parm -
        event -
        Returns:
        The value of a parameter based on its ordinal position in the event's list of parameters
      • getNamedParmValue

        public java.lang.String getNamedParmValue​(java.lang.String parm,
                                                  Event event)
        Helper method.
        Specified by:
        getNamedParmValue in interface EventUtil
        Parameters:
        parm - a String object.
        event - a Event object.
        Returns:
        A parameter's value as a String using the parameter's name..
      • expandMapValues

        public void expandMapValues​(java.util.Map<java.lang.String,​java.lang.String> map,
                                    Event event)

        expandMapValues

        Specified by:
        expandMapValues in interface EventUtil
        Parameters:
        map - a Map object.
        event - a Event object.
      • expandParms

        public java.lang.String expandParms​(java.lang.String inp,
                                            Event event)
        Expand the value if it has parms in one of the following formats - %element% values are expanded to have the value of the element where 'element' is an element in the event DTD - %parm[values-all]% is expanded to a delimited list of all parmblock values - %parm[names-all]% is expanded to a list of all parm names - %parm[all]% is expanded to a full dump of all parmblocks - %parm[name]% is expanded to the value of the parameter named 'name' - %parm[ ]% is replaced by the value of the parameter named 'name', if present - %parm[# ]% is replaced by the value of the parameter number 'num', if present - %parm[##]% is replaced by the number of parameters
        Specified by:
        expandParms in interface EventUtil
        Parameters:
        inp - the input string in which parm values are to be expanded
        event - a Event object.
        Returns:
        expanded value if the value had any parameter to expand, null otherwise
      • expandParms

        public java.lang.String expandParms​(java.lang.String input,
                                            Event event,
                                            java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​java.lang.String>> decode)
        Expand the value if it has parms in one of the following formats - %element% values are expanded to have the value of the element where 'element' is an element in the event DTD - %parm[values-all]% is expanded to a delimited list of all parmblock values - %parm[names-all]% is expanded to a list of all parm names - %parm[all]% is expanded to a full dump of all parmblocks - %parm[name]% is expanded to the value of the parameter named 'name' - %parm[ ]% is replaced by the value of the parameter named 'name', if present - %parm[# ]% is replaced by the value of the parameter number 'num', if present - %parm[##]% is replaced by the number of parameters
        Specified by:
        expandParms in interface EventUtil
        Parameters:
        input - the input string in which parm values are to be expanded
        decode - the varbind decode for this
        event - a Event object.
        Returns:
        expanded value if the value had any parameter to expand, null otherwise
      • getEventHost

        public java.lang.String getEventHost​(Event event)

        getEventHost

        Specified by:
        getEventHost in interface EventUtil
        Parameters:
        event - a Event object.
        Returns:
        a String object.
      • decodeSnmpV2TcDateAndTime

        public java.util.Date decodeSnmpV2TcDateAndTime​(java.math.BigInteger octetStringValue)
        Specified by:
        decodeSnmpV2TcDateAndTime in interface EventUtil