Lua Script

The Lau Script Function Processor allows you to write a custom transform for your pipeline using Lua script.

Purpose

The Lua Script Processor is a versatile data transformation component designed to execute custom Lua scripts on incoming data within a pipeline. This processor is particularly useful for applying bespoke data transformations, enriching data, or filtering events based on custom logic defined in Lua. The Lua scripts are executed in a sandboxed environment to ensure restricted access to system resources, maintaining a secure processing environment.

Usage

Select Lua Script transform. Add Name (required) and Description (optional).

General Configuration:

  • Bypass Transform: Defaults to disabled. When enabled, this transform will be bypassed entirely, allowing the event to pass through without any modifications.

  • Add Filter Conditions: Defaults to disabled. When enabled, it allows events to filter through conditions. Only events that meet the true condition will be processed; all others will bypass this transform. Based on AND/OR conditions, "+Rule" or "+Group" buttons.

Lua:

Enabled: Defaults to enabled, meaning it does evaluate all events. Toggle Enabled off to prevent event processing to feed data to the downstream Transforms.

Lua Script: This field specifies the Lua script to be executed for each incoming event. The script must define the processEvent(event) function, which is invoked for every event received. This function should return the event (potentially modified) to allow it to proceed to the next stage of processing. If the function returns nil, the event will be discarded. Additional helper functions can also be defined and called from within processEvent(event).

Metric Event: Indicates whether the script should process log data or metric data. Set this to true if the script should handle metric data; otherwise, it will process log data by default.

Script Function Details:

  • processEvent(event): This is the main entry point for processing an event. The event parameter contains the data to be processed. The function name and parameter names must remain unchanged. The function should return the event object to continue processing or null to discard it.

  • Fields in the JSON data are accessed using event.field. For nested fields, use event.field.nested.

Examples

Examples require that Enabled is toggled on.

Clean Fields

Scenario: Remove fields where field value is empty.

Results: All fields with empty field values are removed.

Pass Through Without Modification

Modify a Field

Discard Event

Multiple Functions

  • Filter Event: Apply conditions to filter data before or after removing fields.

  • Aggregate Metrics: Aggregate multiple metrics into a single metric based on a set of conditions.

Additional Resources

Last updated

Was this helpful?