Skip to main content
Version: 7.7

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)

Description

The dateAndTime function takes a base64-encoded SNMPv2-TC DateAndTime string as input. It performs the following steps:

  1. Checks if the input string is empty. If it is, the function returns an empty time.Time object.
  2. Checks if the input string is too short to be a valid SNMPv2-TC DateAndTime string. If it is, the function returns an error.
  3. Decodes the base64-encoded string.
  4. Parses the decoded string to extract the year, month, day, hour, minutes, seconds, deciseconds, timezone direction, timezone hours, and timezone minutes.
  5. Calculates the total seconds east of UTC based on the timezone direction, hours, and minutes.
  6. Creates a time.Time object using the extracted date and time components and the calculated timezone offset.
  7. Returns the time.Time object in UTC.

Parameters

  • octet (string): The base64-encoded SNMPv2-TC DateAndTime string to be decoded and converted.

Returns

  • any: The decoded and converted time.Time object.
  • error: An error object if the decoding or conversion fails.

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:

  1. Constructs a key by concatenating the OID and the integer value.
  2. Looks up the key in the provided enumerations.
  3. If a matching value is found, it returns the corresponding string.
  4. 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.