various fixes

This commit is contained in:
Marian Novotny
2022-11-17 15:15:39 +00:00
parent 72c6b449b5
commit 746472df88
41 changed files with 97 additions and 98 deletions

View File

@@ -5,8 +5,7 @@ import org.slf4j.LoggerFactory;
import uk.co.gresearch.siembol.parsers.common.ParserResult;
import uk.co.gresearch.siembol.parsers.common.SerializableSiembolParser;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;
/**
* An object for parsing application that integrates a single parser
*

View File

@@ -6,7 +6,7 @@ import java.util.Map;
* An object for representing a parser result
*
* <p>This class contains a list of parsed messages and
* exception in case a parser throws an error.
* exception if a parser throws an error.
* It provides metadata about the parsed messages such as the source type.
*
* @author Marian Novotny

View File

@@ -18,7 +18,7 @@ public interface SiembolParser {
* Parses the message along with metadata
*
* @param metadata Metadata about the message as a json string
* @param message Message as a byte array. Both binary and text logs are possible to parse.
* @param message Message as a byte array. Both binary and text logs are supported.
* @return list of parsed messages - maps of Strings to Objects
*/
default List<Map<String, Object>> parse(String metadata, byte[] message) {
@@ -28,7 +28,7 @@ public interface SiembolParser {
/**
* Parses the message along with metadata
*
* @param message Message as a byte array. Both binary and text logs are possible to parse.
* @param message Message as a byte array. Both binary and text logs are supported.
* @return list of parsed messages - maps of Strings to Objects
*/
List<Map<String, Object>> parse(byte[] message);
@@ -37,7 +37,7 @@ public interface SiembolParser {
* Parses the message along with metadata into a ParserResult structure
*
* @param metadata Metadata about the message as a json string
* @param message Message as a byte array. Both binary and text logs are possible to parse.
* @param message Message as a byte array. Both binary and text logs are supported.
* @return parser result with list of parsed messages and metadata about the parsing result
* @see ParserResult
*/

View File

@@ -8,7 +8,7 @@ import java.util.stream.Collectors;
* An object for extracting fields using CSV extracting
*
* <p>This derived class of ParserExtractor provides functionality for CSV (Comma Separated Values) extracting.
* It uses column names list for adding field names with possibility to skip some columns.
* It uses column names list for adding field names supporting to skip some columns.
* It supports handling quotas.
*
* @author Marian Novotny
@@ -129,7 +129,7 @@ public class CSVExtractor extends ParserExtractor {
*/
public static Builder<CSVExtractor> builder() {
return new Builder<CSVExtractor>() {
return new Builder<>() {
@Override
public CSVExtractor build() {
if (this.columnNamesList == null ||
@@ -161,7 +161,7 @@ public class CSVExtractor extends ParserExtractor {
protected List<ColumnNames> columnNamesList = new ArrayList<>();
/**
* Sets word delimiter for delimiting a row value - ',' by default
* Sets word delimiter for delimiting a row value (',' by default)
*
* @param wordDelimiter word delimiter for delimiting a row value
* @return this builder

View File

@@ -6,7 +6,7 @@ import java.util.List;
/**
* An object that represents structure for column names
*
* <p>This object represents helper structure for column names used in CSV parser extractor
* <p>This object represents helper structure for representing column names used in CSV parser extractor.
*
* @author Marian Novotny
*/

View File

@@ -12,10 +12,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* An object for extracting fields from the message using json parser
* An object for extracting fields from the message using json parsing
*
* <p>This derived class of ParserExtractor class is using json parsing to extract fields from the massage.
* The extractor is parsing json string recursively in order to create a flat map of extracting fields.
* The extractor is parsing a json string recursively in order to create a flat map of extracting fields.
*
* @author Marian Novotny
* @see ParserExtractor
@@ -74,7 +74,7 @@ public class JsonExtractor extends ParserExtractor {
}
/**
* Extracts a message string using json parser
* Extracts a message string using a json parser
*
* @param message input message to be extracted
* @return map of string to object with extracted fields
@@ -107,7 +107,7 @@ public class JsonExtractor extends ParserExtractor {
*/
public static Builder<JsonExtractor> builder() {
return new Builder<JsonExtractor>() {
return new Builder<>() {
@Override
public JsonExtractor build() {
return new JsonExtractor(this);

View File

@@ -16,7 +16,7 @@ import java.lang.invoke.MethodHandles;
import java.util.*;
/**
* An object for extracting fields from the message using json path queries
* An object for extracting fields from the message by evaluating json path queries
*
* <p>This derived class of ParserExtractor class is using json path query to extract fields from the massage.
* The extractor is evaluating json path queries in order to create a map of extracting fields.
@@ -116,7 +116,7 @@ public class JsonPathExtractor extends ParserExtractor {
}
/**
* Extracts a message string using json path queries
* Extracts fields from a message string using json path queries
*
* @param message input message to be extracted
* @return map of string to object with extracted fields
@@ -179,8 +179,9 @@ public class JsonPathExtractor extends ParserExtractor {
protected EnumSet<JsonPathExtractorFlags> jsonPathExtractorFlags = EnumSet.noneOf(JsonPathExtractorFlags.class);
/**
* Adds a json path query string
* It supports a dot and a bracket notation using syntax from https://github.com/json-path/JsonPath#readme
* Adds a json path query string.
* It supports a dot and a bracket notation using syntax from
* <a href="https://github.com/json-path/JsonPath#readme">https://github.com/json-path/JsonPath#readme</a> .
*
* @param field A field name for storing query result
* @param query A json path query

View File

@@ -40,7 +40,7 @@ public class KeyValueExtractor extends ParserExtractor {
}
/**
* Extracts a message string using key value extracting
* Extracts fields from a message string using key value extracting
*
* @param message input message to be extracted
* @return map of string to object with extracted fields
@@ -184,9 +184,9 @@ public class KeyValueExtractor extends ParserExtractor {
}
/**
* Sets the function for returning an end index of key-value pair
* Sets the function for returning the ending index of key-value pair
*
* @param indexOf the function for returning end index of the key-value pair
* @param indexOf the function for returning the ending index of the key-value pair
* @return this builder
*/
public Builder<T> indexOfEnd(KeyValueIndices.IndexOf indexOf) {

View File

@@ -3,7 +3,7 @@ package uk.co.gresearch.siembol.parsers.extractors;
/**
* An object that represents structure for handling key value indices
*
* <p>This object represents helper structure for handling key value indices used in KeyValueExctractor
* <p>This object represents helper structure for handling key value indices used in KeyValueExtractor
*
* @author Marian Novotny
* @see KeyValueExtractor.Builder

View File

@@ -10,10 +10,10 @@ import java.util.List;
import java.util.Optional;
import java.util.regex.Pattern;
/**
* An object that formats a string timestamps into millisecond epoch time
* An object that formats a string timestamps into a millisecond epoch time
*
* <p>This object validates, parses and formats a string timestamps into millisecond epoch time.
* It supports list of formatters that are executed in a chain until the first formatter will be successful.
* <p>This object validates, parses and formats a string timestamps into a millisecond epoch time.
* It supports list of formatters that are executed in a chain until the first formatter is successful.
*
* @author Marian Novotny
*/

View File

@@ -8,7 +8,7 @@ import static uk.co.gresearch.siembol.parsers.extractors.ParserExtractor.ParserE
* An object for extracting fields from the message
*
* <p>This abstract class is using template pattern for handling common functionality of all extractors.
* The extractor is registered on a field and extracting the key value pairs after processing the field value.
* The extractor is registered on a field and extracting the key value pairs during processing the field value.
*
* @author Marian Novotny
* @see JsonExtractor
@@ -108,11 +108,11 @@ public abstract class ParserExtractor {
}
/**
* Applies a pre-processing function.
* Extracts key value pairs from an input string.
* Applies the post-processing functions.
* Applies a pre-processing function on an input string.
* Extracts key value pairs from the input string.
* Applies the post-processing functions on extracted pairs.
*
* @param str Input string
* @param str an input string
* @return extracted key value pairs as a map of String to Object
*/
public Map<String, Object> extract(String str) {
@@ -155,7 +155,7 @@ public abstract class ParserExtractor {
}
/**
* An abstract builder for parser extractor
* An abstract builder for a parser extractor
*
* <p>This abstract class is using Builder pattern.
*
@@ -172,9 +172,9 @@ public abstract class ParserExtractor {
new ArrayList<>();
/**
* Sets name of the extractor
* Sets the name of the extractor
*
* @param name name of the extractor
* @param name the name of the extractor
* @return this builder
*/
public Builder<T> name(String name) {
@@ -183,9 +183,9 @@ public abstract class ParserExtractor {
}
/**
* Sets field name of the extractor
* Sets a field name of the extractor
*
* @param field field name of the extractor
* @param field a field name of the extractor
* @return this builder
*/
public Builder<T> field(String field) {
@@ -208,7 +208,7 @@ public abstract class ParserExtractor {
/**
* Sets a pre-processing function of the extractor
*
* @param preProcessing Pre-processing function of the extractor
* @param preProcessing A pre-processing function of the extractor
* @return this builder
*/
public Builder<T> preProcessing(Function<String, String> preProcessing) {
@@ -219,7 +219,7 @@ public abstract class ParserExtractor {
/**
* Sets a list of post-processing functions of the extractor
*
* @param postProcessing List of post-processing functions of the extractor
* @param postProcessing A list of post-processing functions of the extractor
* @return this builder
*/
public Builder<T> postProcessing(List<Function<Map<String, Object>,
@@ -232,11 +232,11 @@ public abstract class ParserExtractor {
}
/**
* Extracts a message by executing a list of extractors
* Extracts pairs from a message object by executing a list of extractors
*
* @param extractors List fo extractors to be executed in a chain
* @param messageObject initial message that will be extended by calling a chain of extractors
* @return message after executing all extractors
* @param extractors List of extractors to be executed in a chain
* @param messageObject an initial message object that will be extended by calling a chain of extractors
* @return the message object after executing all extractors
*/
public static Map<String, Object> extract(
List<ParserExtractor> extractors,

View File

@@ -9,7 +9,7 @@ import static uk.co.gresearch.siembol.common.constants.SiembolMessageFields.TIME
/**
* A library of helper static functions used in parsing extractors
*
* <p>This class provides placeholder of helper static functions used in parsing extractors
* <p>This class provides placeholder for helper static functions used in parsing extractors
*
* @author Marian Novotny
*/

View File

@@ -42,9 +42,9 @@ public class PatternExtractor extends ParserExtractor {
/**
* Implementation of template method for extracting key value pairs from an input string.
* The list of regular expression named groups are executed in a chain.
* The pattern needs to match in order to be extracted and included in the result.
* The fields are extracted and included in the result only if the pattern matches the input string.
*
* @param str Input string
* @param str An input string
* @return extracted key value pairs as a map of String to Object
*/
@Override
@@ -107,7 +107,7 @@ public class PatternExtractor extends ParserExtractor {
}
/**
* Creates pattern extractor builder instance
* Creates a pattern extractor builder instance
*
* @return pattern extractor builder
*/

View File

@@ -42,11 +42,11 @@ public class RegexSelectExtractor extends ParserExtractor {
}
public static Builder<RegexSelectExtractor> builder() {
return new Builder<RegexSelectExtractor>() {
return new Builder<>() {
@Override
public RegexSelectExtractor build() {
if (this.outputField == null
|| patterns == null){
|| patterns == null) {
throw new IllegalArgumentException(MISSING_ARGUMENTS);
}
return new RegexSelectExtractor(this);

View File

@@ -2,8 +2,8 @@ package uk.co.gresearch.siembol.parsers.factory;
/**
* An object for compiling parsers
*
* <p>This interface is for creating a parser, testing a parser on input, validating parser configuration and
* providing json schema for parser configurations.
* <p>This interface is for creating a parser, testing a parser on an input, validating a parser configuration and
* providing a json schema for parser configurations.
*
* @author Marian Novotny
* @see ParserFactoryResult
@@ -12,9 +12,9 @@ package uk.co.gresearch.siembol.parsers.factory;
public interface ParserFactory {
/**
* Gets json schema of parser configurations
* Gets the json schema of parser configurations
*
* @return parser factory result with json schema of parser configurations
* @return parser factory result with the json schema of parser configurations
* @see ParserFactoryResult
*/
ParserFactoryResult getSchema();

View File

@@ -31,8 +31,8 @@ import static uk.co.gresearch.siembol.parsers.model.PreProcessingFunctionDto.STR
* An object for compiling parsers
*
* <p>This class is an implementation of ParserFactory interface.
* It is used for creating a parser, testing a parser on input, validating parser configuration and
* providing json schema for parser configurations.
* It is used for creating a parser, testing a parser on input, validating a parser configuration and
* providing the json schema for parser configurations.
*
* @author Marian Novotny
* @see ParserFactory

View File

@@ -14,7 +14,7 @@ public class ParserFactoryResult {
public enum StatusCode {
OK,
ERROR
};
}
private final StatusCode statusCode;
private final ParserFactoryAttributes attributes;

View File

@@ -17,9 +17,9 @@ import static java.nio.charset.StandardCharsets.UTF_8;
*
* <p>This class is an implementation of SiembolParser interface.
* It is used for parsing a log by creating two fields:
* - 'original_string; with the message,
* - 'timestamp' with the current time in milliseconds.
* It evaluates chain of extractors and transformations if registered.
* - 'original_string' field with the input message,
* - 'timestamp' field with the current time in milliseconds.
* It evaluates the chain of extractors and transformations if registered.
* @author Marian Novotny
* @see SiembolParser
*

View File

@@ -3,7 +3,7 @@ package uk.co.gresearch.siembol.parsers.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.reinert.jjschema.Attributes;
/**
* A data transfer object for representing column filter in csv extractor
* A data transfer object for representing column filter in a csv extractor
*
* <p>This class is used for json (de)serialisation of a column filter and
* for generating json schema from this class using annotations.

View File

@@ -4,7 +4,7 @@ import com.github.reinert.jjschema.Attributes;
import java.util.List;
/**
* A data transfer object for representing column names in csv extractor
* A data transfer object for representing column names in a csv extractor
*
* <p>This class is used for json (de)serialisation of a column names and
* for generating json schema from this class using annotations.

View File

@@ -3,7 +3,6 @@ package uk.co.gresearch.siembol.parsers.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.reinert.jjschema.Attributes;
import java.util.List;
/**
* A data transfer object for representing attributes for json path query
*

View File

@@ -4,7 +4,7 @@ import com.github.reinert.jjschema.Attributes;
import java.util.List;
/**
* A data transfer object for representing attributes for message filter transformation
* A data transfer object for representing attributes for a message filter transformation
*
* <p>This class is used for json (de)serialisation of a message filter transformation and
* for generating json schema from this class using annotations.

View File

@@ -3,9 +3,9 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.reinert.jjschema.Attributes;
import java.util.List;
/**
* A data transfer object for representing attributes for a parser config
* A data transfer object for representing attributes for a parser configuration
*
* <p>This class is used for json (de)serialisation of a parser config and
* <p>This class is used for json (de)serialisation of a parser configuration and
* for generating json schema from this class using annotations.
*
* @author Marian Novotny

View File

@@ -5,7 +5,7 @@ import com.github.reinert.jjschema.Attributes;
import java.util.List;
/**
* A data transfer object for representing attributes of a regex select
* A data transfer object for representing attributes of a regex select extractor
*
* <p>This class is used for json (de)serialisation of a regex select used in a regex select extractor and
* for generating json schema from this class using annotations.

View File

@@ -3,7 +3,7 @@ package uk.co.gresearch.siembol.parsers.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.reinert.jjschema.Attributes;
/**
* An enum for representing a syslog verson
* An enum for representing a syslog version
*
* <p>This enum is used for json (de)serialisation of case type.
*

View File

@@ -5,7 +5,7 @@ import com.github.reinert.jjschema.Attributes;
import java.util.List;
/**
* A data transfer object for representing a transformation function attribute
* A data transfer object for representing a transformation attributes
*
* <p>This class is used for json (de)serialisation of attributes of a transformation and
* for generating json schema from this class using annotations.

View File

@@ -5,7 +5,7 @@ import com.github.reinert.jjschema.Attributes;
/**
* An enum for representing a transformation type
*
* <p>This enum is used for json (de)serialisation of transformation type.
* <p>This enum is used for json (de)serialisation of a transformation type.
*
* @author Marian Novotny
* @see com.fasterxml.jackson.annotation.JsonProperty

View File

@@ -2,7 +2,7 @@ package uk.co.gresearch.siembol.parsers.netflow;
/**
* An interface for reading from a binary buffer
*
* <p>This functional interface is used for reading form binary buffer.
* <p>This functional interface is used for reading form a binary buffer.
*
* @author Marian Novotny
*
@@ -10,4 +10,4 @@ package uk.co.gresearch.siembol.parsers.netflow;
@FunctionalInterface
public interface NetflowBufferReader {
Object read(BinaryBuffer buffer, int fieldLength);
};
}

View File

@@ -13,7 +13,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
* An enum of netflow v9 data types
*
* <p>This enum represent a netflow v9 data types.
* It provides a function for parsing a binary buffer.
* A data type includes a function for reading a binary buffer.
*
* @author Marian Novotny
* @see NetflowBufferReader
@@ -99,8 +99,8 @@ public enum NetflowDataType implements NetflowBufferReader {
try {
return Inet4Address.getByAddress(dst).getHostAddress();
} catch (Exception e) {
LOG.error(String.format("Invalid Ipv4 address: %s"),
new String(dst, UTF_8));
LOG.error(String.format("Invalid Ipv4 address: %s",
new String(dst, UTF_8)));
return UNKNOWN_IPV4;
}
}
@@ -115,8 +115,8 @@ public enum NetflowDataType implements NetflowBufferReader {
try {
return Inet6Address.getByAddress(dst).getHostAddress();
} catch (Exception e) {
LOG.error(String.format("Invalid Ipv6 address: %s"),
new String(dst, UTF_8));
LOG.error(String.format("Invalid Ipv6 address: %s",
new String(dst, UTF_8)));
return UNKNOWN_IPV6;
}
}

View File

@@ -35,7 +35,7 @@ public class NetflowField {
try {
return dataType.read(buffer, length);
} catch (Exception e) {
LOG.error(String.format("Exception during parsing field %s type: %d, len: %d, exception: %s, buffer: %s",
LOG.error(String.format("Exception during parsing field %s type: %s, len: %d, exception: %s, buffer: %s",
ExceptionUtils.getStackTrace(e),
getName(),
type,

View File

@@ -7,8 +7,8 @@ import static uk.co.gresearch.siembol.parsers.netflow.NetflowDataType.*;
/**
* An enum of netflow v9 field types
*
* <p>This enum represent a netflow v9 field types.
* It provides a name, type code and data type for parsing a field.
* <p>This enum represents a netflow v9 field types.
* It provides a name, a type code and a data type used for parsing a field.
*
* @author Marian Novotny
* @see NetflowBufferReader

View File

@@ -2,7 +2,7 @@ package uk.co.gresearch.siembol.parsers.netflow;
/**
* An object for representing a netflow header
*
* <p>This class represents netflow header used by a netflow parser.
* <p>This class represents a netflow header used by a netflow parser.
*
* @author Marian Novotny
*

View File

@@ -1,9 +1,9 @@
package uk.co.gresearch.siembol.parsers.netflow;
/**
* An object for providing netflow transport message
* An object for providing a netflow transport message
*
* <p>This class is implementing NetflowTransportMessage interface.
* It uses string identification of device such as its IP address that is unique per device.
* It uses a string identification of a device such as its IP address that must be unique per a device.
*
* @author Marian Novotny
* @see NetflowTransportMessage

View File

@@ -8,11 +8,13 @@ import java.util.*;
/**
* An object for parsing a netflow v9 message
*
* <p>This class implements a fault-tolerant netflow v 9 parser.
* Netflow v9 is parsing data using netflow templates messages that are identified by a device and template id.
* Network devices are using template id field as a counter rather than a unique id on the network and
* collisions of template id between devices is common on a network with multiple collectors.
* This way we are using NetflowTransportProvider interface to provide global id of the template.
* <p>This class implements a fault-tolerant netflow v9 parser.
* Parsing of fields in Netflow v9 protocol is based on the netflow template messages that
* are identified by a device and template id.
* Network devices are using template id field as a counter rather than as a unique id on the network and
* collisions of template id values on a network with multiple collectors are common.
* This way we are using NetflowTransportProvider interface to provide global id of the template in order
* to avoid collisions.
*
* @author Marian Novotny
* @see NetflowParsingResult

View File

@@ -6,7 +6,7 @@ import java.util.List;
/**
* An object for representing a netflow parsing result
*
* <p>This class represents netflow parsing result used by a netflow parser.
* <p>This class represents a netflow parsing result used by a netflow parser.
* It includes a status code of the result along with a netflow parsed message.
*
* @author Marian Novotny

View File

@@ -2,7 +2,7 @@ package uk.co.gresearch.siembol.parsers.netflow;
/**
* An interface for representing a netflow message used by NetflowTransportProvider
*
* <p>This interface is used for representing netflow transport message
* <p>This interface is used for representing a netflow transport message
*
* @author Marian Novotny
*
@@ -13,7 +13,7 @@ public interface NetflowTransportMessage<T> {
* Gets a unique global ID that identifies the template in the global template store
* @param header a netflow header
* @param templateId id of the template
* @return Object of the type T that will be used as a key in a templates store
* @return an object of the type T that will be used as a key in a templates store
*/
public T getGlobalTemplateId(NetflowHeader header, int templateId);
@@ -28,14 +28,14 @@ public interface NetflowTransportMessage<T> {
/**
* Gets a global identifier of the device which sent the netflow message
*
* @return returns String that identifies the device on the network that produces the netflow packet
* @return a string that identifies the device on the network that produces the netflow packet
*/
public String getGlobalSource();
/**
* Gets the original string used in parsed message.
*
* @return returns String that should be used for original string.
* @return a string that should be used in 'original_string' field
*/
public String getOriginalString();
}

View File

@@ -9,9 +9,9 @@ import java.util.*;
* An object for providing netflow templates
*
* <p>This class is implementing NetflowTransportProvider interface.
* It uses in memory map for storing and obtaining templates.
* It uses an in-memory map for storing and obtaining templates.
* It uses NetflowMessageWithSource implementation.
* This map is not synchronised since it is not shared between threads in Storm integration.
* This map is not synchronised since it is not shared between threads in the storm integration.
*
* @author Marian Novotny
* @see NetflowTransportProvider

View File

@@ -6,7 +6,6 @@ import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.DateTimeFormatterBuilder;
import org.joda.time.format.DateTimeParser;
import uk.co.gresearch.siembol.parsers.common.SiembolParser;
import java.time.ZonedDateTime;
import java.time.format.DateTimeParseException;

View File

@@ -6,9 +6,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* An object for representing a syslog message after syslog parsing
* An object for representing a syslog message used in syslog parsing
*
* <p>This class represents a syslog message after parsing by an internal syslog parser.
* <p>This class represents a syslog message in the internal syslog parser.
*
* @author Marian Novotny
* @see SyslogParser

View File

@@ -5,9 +5,9 @@ import java.util.function.Function;
/**
* An object for transformation
*
* <p>This functional interface for parsing transformations.
* <p>This functional interface is used for representing parsing transformations.
* It is a functional interface that extends Function interface for
* a function with a map of String to Object argument that returns a map of String to Object.
* a function of a map of String to Object argument that returns a map of String to Object.
*
* @author Marian Novotny
*

View File

@@ -4,7 +4,6 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import uk.co.gresearch.siembol.common.utils.FieldFilter;
import uk.co.gresearch.siembol.common.utils.PatternFilter;
import uk.co.gresearch.siembol.parsers.syslog.SyslogParser;
import java.util.ArrayList;
import java.util.List;