Best way to drop an event #23045
-
Hi, I've create a pipeline that takes various logs from different embedded devices. The logs are either in kernel format or process format. Anything that are not those formats are to be dropped. The way I've done it is to have one transform per type of logs; I raise an error with transforms:
parse_kernel_log:
type: "remap"
inputs: ["*_extract_log"]
drop_on_error: true
source: |
. |= parse_regex!(.message, r'^\[(?P<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\] \[(?P<severity>\w+)\] \[\s*(?P<uptime>[0-9]+[.][0-9]{6})\] (?P<message>.+)$')
# Coerce parsed fields
.timestamp = parse_timestamp!(.timestamp, "%Y-%m-%d %H:%M:%S")
.pid = 0
.process = "kernel"
.message = strip_whitespace(.message)
.uptime = to_float!(.uptime)
parse_process_log:
type: "remap"
inputs: ["*_extract_log"]
drop_on_error: true
source: |
. |= parse_regex!(.message, r'^\[(?P<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\] \[(?P<severity>\w+)\] (?P<process>\w+)\[(?P<pid>\d+)\]: (?P<message>.+)$')
# Coerce parsed fields
.timestamp = parse_timestamp!(.timestamp, "%Y-%m-%d %H:%M:%S")
.pid = to_int!(.pid)
.message = strip_whitespace(.message) This works as intended but there is two drawbacks:
If we had custom function in VRL, I could do something like that Is there a better way to do what I'm currently doing? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You have a couple of options here, before you transform the data I would use an exclusive route to split the streams, then you have one stream far process and another far kernel and you can process the data as expected. example type: exclusive_route
inputs:
- '*'
routes:
- name: "kernel"
condition: match(to_string!(.message), r'parse_kernel_log')
- name: "process"
condition: match(to_string!(.message), r'parse_process_log') Alternatively, you could convert to one remap and try to process the data on error. example transforms:
parse_kernel_log:
type: "remap"
inputs: ["*_extract_log"]
drop_on_error: true
source: |
., err |= parse_regex(.message, r'^\[(?P<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\] \[(?P<severity>\w+)\] \[\s*(?P<uptime>[0-9]+[.][0-9]{6})\] (?P<message>.+)$')
if err != null {
. |= parse_regex!(.message, r'^\[(?P<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\] \[(?P<severity>\w+)\] (?P<process>\w+)\[(?P<pid>\d+)\]: (?P<message>.+)$')
}
# Coerce parsed fields
.timestamp = parse_timestamp!(.timestamp, "%Y-%m-%d %H:%M:%S")
.message = strip_whitespace(.message)
.uptime = to_float!(.uptime) |
Beta Was this translation helpful? Give feedback.
You have a couple of options here, before you transform the data I would use an exclusive route to split the streams, then you have one stream far process and another far kernel and you can process the data as expected.
example
Alternatively, you could convert to one remap and try to process the data on error.
example