Title
Create new category
Edit page index title
Edit category
Edit link
Script Execution Processor
Description
This Processor enables you to use a subset of JavaScript to transform your data, which can significantly simplify your Pipeline map.You can combine multiple actions like filtering, dropping, mapping, and casting inside of a single script.
This processor has specific limitations on command execution, as described in the section on Known Limitations.
Configuration
Option | Description |
|---|---|
| The JavaScript code to transform your data |
Main Function
With the JavaScript processor you can define a single function to encapsulate the logic for processing an event. This function can be named whatever you want, but by default is called processEvent. This function has up to three arguments that you can declare positionally, by any name.
Parameter | Description |
|---|---|
| This is a reference to the actual message that flows through this processor |
| The metadata associated with the event |
| The timestamp associated with this event. In some automated parsing sources we will try and extract the timestamp from the incoming event, but for the most part this timestamp will be set to the time we received the event. |
| The annotations object for the event. In scenarios where you have created a Data Profile, classification information such as event type, message type, and total bytes will be present. |
The function must return a value on all paths. The returned object (modified, replaced, or otherwise) becomes the message downstream. Returning null causes the message to be dropped (no event is propagated). Modified metadata is propagated with the message.
Global Functions
These functions are available to use on any respective value. At this time, these are the only supported global operations. There is no support for global objects like Math, Array, Map, or Set, except for Object, JSON and Date objects.
Function | Description |
|---|---|
| Returns the number of milliseconds elapsed since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC. |
| Parses a string representation of a date, and returns and returns the number of milliseconds elapsed since the epoch. It defaults to Unit indicates the scale of units to return ( |
| Returns a timestamp representing the time of processing of this script. |
| Parses
|
| Parses a JSON string into a JS type. It defaults to |
| Converts a JavaScript value to a JSON string. You should use this for converting any JSON object, instead of the |
| Returns an array of property key-value pairs of the spedified object. It returns an empty array when the provided value is not an object, or |
| Returns an array of property keys of the provided object. It returns an empty array when the provided value is not an object or |
| Attempts to parse the data as an integer and returns the integer. It defaults to |
| Attempts to parse the data as a float and returns the float. It defaults to |
| Parses the |
| Casts an object to a string. Returns an empty string for null values. |
Comparison Operators
This processor supports all basic comparison operators that are defined in JavaScript.
Operator | Description |
|---|---|
> | Greater Than |
>= | Greater Than or Equal To |
< | Less Than |
<= | Less Than or Equal To |
== or === | Equal. Note: This has strict type checking whether it's defined as |
!= or !== | Not Equal. Note: This has strict type checking whether it's defined as |
Arithmetic Operators
An arithmetic operator takes numerical values as their operands and returns a single numerical value.
Operator | Description |
|---|---|
Addition | |
Subtraction | |
Multiplication | |
/ | Division |
String Operations
String operations supported follow the standard Javascript conventions.
Operator | Description |
|---|---|
Concatenates two strings together | |
.endsWith(substring) | Checks whether a string ends with |
.startsWith(substring) | Checks whether a string starts with |
.at() | Retrieve an character at the specific index from a string (more readable) |
.charAt() | Retrieve an character at the specific index from a string |
.indexOf() | Return the first index of a value in a string |
.lastIndexOf() | Return the last index of a value in a string |
.length | Returns the number of characters in a string Note that to avoid collisions with a field name of |
.padEnd() | Adds additional specified characters to the end of a string |
.padStart() | Adds additional specified characters to the beginning of a string |
.repeat() | Returns a new string with a number of copies of the original string |
.slice() | Extracts the specified portion of the string by index, defaulting to the end of the string if only one index is specified |
.substring() | Extracts a specified portion of the string between the indexes given |
.toLowerCase() | Changes all string characters to lower case letters |
.toUpperCase() | Changes all string characters to upper case letters |
.trim() | Removes whitespaces from both sides of the string |
.trimEnd() | Removes whitespaces from the end of the string |
.trimStart() | Removes whitespaces from the beginning of the string |
Function-Scoped Variables
Variables can be defined and used inside of the main processEvent function. To use one, define a variable with the let keyword.
Deleting Attributes
Attributes can be deleted from an object by assigning undefined .
Examples
Filter Events
Adding Properties to an Event
Removing Properties from an Event
Parsing Numbers
Convert To String
Counting the Number of Bytes in a Message
This example shows how you can compute the size of the event payload using combined functions. This returns the amount of the size in bytes by assuming that each character is 1 byte (8 bit ASCII characters).
Working with Strings
Working with Arrays
Known Limitations
This processor was not intended to implement the full JavaScript language, but was developed with event manipulation in mind only. For this reason, it has some limitations:
Only one function can be used to encapsulate all of the logic (helper functions aren't supported)
Accessing Array items is only supported with literal values (numbers)
Only JavaScript ES5 syntax is supported
Error handling is not supported via try/catch
Mixing data types with binary expressions results in a no-op