This topic covers the syntax and structure of event handler functions, as well as related scenario examples.
e_output function
The e_output function outputs log data to the target topic with specified alias. The log topic alias refers to the target name specified when you create the transformation task.
Function syntax/format
The parameters are described below:
Function examples
- Scenario: Based on the value of the is_output field in the log, this function determines whether to output the log to the log topic named target-1.
Tip
The first log is output to the log topic with the alias target-1, while the second log is not output.
Dynamically distributes logs to different log topics. For example, if the log field service is set to tos or kafka, you can specify the e_auto_output function to dynamically distribute logs to log topics named tos and kafka based on the value of service. If log topics tos and kafka do not exist, the system will create topics first.
The parameters are described below:
Notice
- If a project or log topic with the same name already exists, the system will not create it again.
- When dynamically creating a project or log topic using a field value, the field value must meet resource naming requirements. Otherwise, an error will occur when using the e_auto_output function. For details, see Resource naming limits.
Function example 1:
- Scenario: This function extracts the value from the service field, then dynamically routes the log to the corresponding topic based on that value, and enables the full-text index for the topic. If the project or log topic does not exist, the system creates them based on the values specified in the function.
- Route log 1 to the tos topic under the myproject project.
- Route log 2 to the kafka topic under the myproject project.
Function example 2:
- Scenario: This function extracts values from the project-name field and topic-name field, and then distributes logs to the corresponding log topic based on these values; adds tags key1:value1 and key2:value2 to the log topic and enables the Full-text index. If the project or log topic does not exist, the system creates them based on the values specified in the function.
- Route log 1 to the myproject01 project under the log topic accesslog01. Then add tags key1:value1 and key2:value2 to this topic and enable the Full-text index.
- Route log 2 to the myproject02 project under the log topic accesslog02. Add tags key1:value1 and key2:value2 to this topic and enable the Full-text index.
Function example 3:
- Scenario: This function provides the project name and topic name from the project-name field and topic-name field; distributes logs to the corresponding log topic based on these values, and disables the full-text index for the log topic. If the project or log topic does not exist, the system creates them based on the values specified in the function.
- Route log 1 to the myproject01 project under the accesslog01 log topic, and disable the Full-text index for this log topic.
- Route log 2 to the myproject02 project under the accesslog02 log topic, and disable the Full-text index for this log topic.
e_split function
Use a separator to split specific fields, resulting in multiple log entries.
Function syntax/format
Splitting rules:
- Rule 1: If the jmes parameter is configured, convert the log field value into a JSON list and extract values using jmes for the next step. At this point, the sep and quote parameters are invalid. If no jmes parameter is set, the splitting will proceed by following Rule 2.
- Rule 2: If the previous value is a list or a JSON-formatted list string, split by this list and end processing. The sep and quote parameters are invalid at this time. If it is not a JSON list or JSON list string, the splitting will proceed by following Rule 2.
- Rule 3: Use sep, quote, and lstrip to parse the previous value with CSV, split by the resulting values, and end processing.
The parameters are described below:
Function examples
- Scenario: Splits into multiple logs based on the value of the city field.
e_drop function
Discards logs that meet the specified criteria.
Function syntax/format
The parameters are described below:
Function examples
- Scenario: Determines whether to discard a log based on the value of the city field.
e_keep function
Keeps logs that meet the criteria; discards logs that do not meet the criteria.
Function syntax/format
The parameters are described below:
Function examples
- Scenario: Determines whether to keep the log based on the value of the city field.