java.lang.Object
org.sentrysoftware.metricshub.engine.strategy.utils.PslUtils

public class PslUtils extends Object
Utility class for handling PSL (PATROL Script Language) regular expressions and formatting data in an extended JSON format.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    formatExtendedJSON(@NonNull String row, @NonNull SourceTable tableResult)
    Converts an entry and its result into an extended JSON format: { "Entry":{ "Full":"<entry>", "Column(1)":"<1st field value>", "Column(2)":"<2nd field value>", "Column(3)":"<3rd field value>", "Value":<result> <- Result must be properly formatted (either "result" or {"property":"value"} } }
    static String
    nthArg(String text, String selectColumns, String separators, String resultSeparator)
    Extracts and formats the nth group in the given text based on the specified columns, separators, and result separator.
    static String
    nthArgf(String text, String selectColumns, String separators, String resultSeparator)
    Extracts and formats the nth group in the given text based on the specified columns, separators, and result separator.
    static String
    Converts a PSL regex into its Java equivalent.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • psl2JavaRegex

      public static String psl2JavaRegex(String pslRegex)
      Converts a PSL regex into its Java equivalent. Method shamelessly taken from somewhere else.
      Parameters:
      pslRegex - Regular expression as used in PSL's grep() function.
      Returns:
      Regular expression that can be used in Java's Pattern.compile.
    • formatExtendedJSON

      public static String formatExtendedJSON(@NonNull @NonNull String row, @NonNull @NonNull SourceTable tableResult) throws IllegalArgumentException
      Converts an entry and its result into an extended JSON format: { "Entry":{ "Full":"<entry>", "Column(1)":"<1st field value>", "Column(2)":"<2nd field value>", "Column(3)":"<3rd field value>", "Value":<result> <- Result must be properly formatted (either "result" or {"property":"value"} } }
      Parameters:
      row - The row of values.
      tableResult - The output returned by the SourceVisitor.
      Returns:
      String value
      Throws:
      IllegalArgumentException
    • nthArgf

      public static String nthArgf(String text, String selectColumns, String separators, String resultSeparator)
      Extracts and formats the nth group in the given text based on the specified columns, separators, and result separator.
      Parameters:
      text - The text that should be parsed.
      selectColumns - The list/range(s) of columns that should be extracted from the text.
      separators - The set of characters used to split the given text.
      resultSeparator - The separator used to join the resulting elements.
      Returns:
      The nth group in the given text, formatted according to the given separators and column numbers.
    • nthArg

      public static String nthArg(String text, String selectColumns, String separators, String resultSeparator)
      Extracts and formats the nth group in the given text based on the specified columns, separators, and result separator.
      Parameters:
      text - The text that should be parsed.
      selectColumns - The list/range(s) of columns that should be extracted from the text.
      separators - The set of characters used to split the given text.
      resultSeparator - The separator used to join the resulting elements.
      Returns:
      The nth group in the given text, formatted according to the given separators and column numbers.