DSL Processor
Introduction
The DSL Processor is a powerful tool designed to streamline and enhance your data processing workflows. It allows you to define and execute complex data transformations using a simple and intuitive domain-specific language (DSL). Trapcoll is built ontop of Benthos and includes additional functions to enrich and transform stream Trap data.
Features
- Intuitive Syntax: Write clear and concise transformation rules.
- High Performance: Optimized for speed and efficiency.
- Flexibility: Easily adaptable to various data processing needs.
Configuration
To configure the DSL Processor, please refer to the Configuration Reference.
Custom Functions
Trapcoll DSL Processor supports the following custom functions:
displayString
The displayString
function is a custom Benthos stream processing function that decodes a base64-encoded string and translates it to NVT ASCII format.
Syntax
displayString(octet string) (any, error)
Description
The displayString function takes a base64-encoded string as input. It first checks if the input string is empty. If it is, the function returns the input string as is. Otherwise, it decodes the string using base64 decoding. If the decoding is successful, it translates the decoded string to NVT ASCII format and returns it. If any error occurs during the decoding process, the function returns an error.
Parameters
octet (string): The base64-encoded string to be decoded and translated.
Returns
any: The decoded and translated string. error: An error object if the decoding or translation fails.
dateAndTime
The dateAndTime
function is a custom Benthos stream processing function that decodes a base64-encoded SNMPv2-TC DateAndTime string and converts it to a time.Time
object.
Syntax
dateAndTime(octet string) (any, error)
Parameters
octet
(string): The base64-encoded SNMPv2-TC DateAndTime string to be decoded and converted.
Returns
any
: The decoded and convertedtime.Time
object.error
: An error object if the decoding or conversion fails.
Description
The dateAndTime
function takes a base64-encoded SNMPv2-TC DateAndTime string as input. It performs the following steps:
- Checks if the input string is empty. If it is, the function returns an empty
time.Time
object. - Checks if the input string is too short to be a valid SNMPv2-TC DateAndTime string. If it is, the function returns an error.
- Decodes the base64-encoded string.
- Parses the decoded string to extract the year, month, day, hour, minutes, seconds, deciseconds, timezone direction, timezone hours, and timezone minutes.
- Calculates the total seconds east of UTC based on the timezone direction, hours, and minutes.
- Creates a
time.Time
object using the extracted date and time components and the calculated timezone offset. - Returns the
time.Time
object in UTC.
enumEnrich
The enumEnrich
function is a custom Benthos stream processing function that enriches an integer value with a corresponding string from a predefined set of enumerations.
Syntax
enumEnrich(oid string, enums dsl.Enums) func(int64) (any, error)
Description
The enumEnrich
function takes an OID (Object Identifier) and a set of enumerations as input. It returns a function that can be used to enrich an integer value based on the provided enumerations. The returned function performs the following steps:
- Constructs a key by concatenating the OID and the integer value.
- Looks up the key in the provided enumerations.
- If a matching value is found, it returns the corresponding string.
- If no matching value is found, it returns the integer value as a string.
Parameters
oid
(string): The Object Identifier used as a prefix for the enumeration keys.enums
(dsl.Enums): A map of enumeration keys to their corresponding string values.
Returns
- The enriched string or the integer value as a string if no match is found.