Class AbstractEventUtil

  • All Implemented Interfaces:
    EventUtil
    Direct Known Subclasses:
    EventUtilDaoImpl

    public abstract class AbstractEventUtil
    extends 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
    • 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 String escape​(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 String getAllParmValues​(Event event)
        Helper method.
        Parameters:
        event -
        Returns:
        All event parameter values as a String.
      • getAllParmNames

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

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

        protected static String getNumParmName​(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 String splitAndExtract​(String src,
                                             String sep,
                                             int offset,
                                             boolean doRange,
                                             int rangeLen)
      • getNumParmValue

        protected static String getNumParmValue​(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 String getNamedParmValue​(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..
      • expandParms

        public String expandParms​(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 String expandParms​(String input,
                                  Event event,
                                  Map<String,​Map<String,​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