Before you post: Your responses to these questions will help the community help you. Please complete this template if you’re asking a support question.
Don’t forget to select tags to help index your topic!
1. Describe your incident:
I have set up pipeline to extract nested json and parse message to fields … it seems parsing works fine but we want something like prefixing its object with field name…
for example I have below json:
{"@timestamp": "2022-10-25T17:55:29+00:00", "source": "mr-hub-nginx", "nginx": {"remote_addr": "xx.xx.101.216, xx.xx.146.165", "remote_user": "39942", "body_bytes_sent": 0, "request_length": 786, "request_time": 0.514, "status": 202, "request": "PATCH /test/v1/enablement/19299 HTTP/1.0", "request_method": "PATCH", "http_origin": "-", "http_referrer": "-", "site": "mr-hub-kube.test.com", "port": 443, "http_user_agent": "python-requests/2.28.1" }}
We got logs with filed name “nginx,port,request,…” however, we want to have field name prefix by its object “nginx” like “nginx_port, nginx_request”
In short, whatever object we have should pick dynamically and prefix to field… is that possible ?
2. Describe your environment:
-
OS Information: Ubuntu 20
-
Package Version: 4.3.3+86369d3, codename Noir
-
Service logs, configurations, and environment variables:
I have pipeline set up:
Stage0: extract json
rule "extract json"
when
regex("(\\{.*\\})", to_string($message.message)).matches == true
then
let json = regex("(\\{.*\\})", to_string($message.message), ["json"])["json"];
set_field("json", json);
end
Stage1: parse json
rule "parse json"
when
has_field("json")
then
// the following date format assumes there's no time zone in the string
let json_props = parse_json(to_string($message.json));
set_fields(to_map(json_props));
let nginx_json = select_jsonpath(json_props, {nginx: "$.nginx"});
let nginx_props = parse_json(to_string(nginx_json.nginx));
set_fields(to_map(nginx_props));
end