Hello, I have json of this type at the input:
{
"folders": [{
"template": "template_name1",
"attrs": [{
"attrStr": {
"key": "key1",
"value": "value1"
}
}, {
"attrStr": {
"key": "key2",
"value": "value2"
}
}
]
}, {
"template": "template_name2",
"attrs": [{
"attrStr": {
"key": "key3",
"value": "value3"
}
}, {
"attrStr": {
"key": "key4",
"value": "value4"
}
}
]
}
...............
, {
"template": "template_nameN",
"attrs": [{
"attrStr": {
"key": "keyN",
"value": "valueN"
}
}, {
"attrStr": {
"key": "keyN",
"value": "valueN"
}
}
]
}
I need to save the original event and add the "template_nameN" values to it in a new field.
But I can't use ruby script in my work. Is there a way to do this using standard logstash filter tools?
I tried this type of filter, but then the original event is not saved or nothing is displayed at all:
filter {
if [message] == "doHttpRqLog" {
if [service] == "service1" and ([requestURI] == "/method1" or [requestURI] == "/method2" or [requestURI] == "/method3" or [requestURI] == "/method4") {
json {
source => "requestBody"
target => "parsed_requestBody"
}
if ([requestURI] == "/method2" or [requestURI] == "/method3") and [parsed_requestBody][folders] {
uuid { target => "uid" }
split {
field => "[parsed_requestBody][folders]"
}
mutate {
add_field => { "template_arr" => "%{[parsed_requestBody][folders][template]}" }
}
clone {
clones => ["original_event"]
}
aggregate {
task_id => "%{uid}"
code => "
map['templates'] ||= []
map['templates'] << event.get('template_arr')
map['original_event'] ||= event.to_hash()
event.cancel()
"
push_previous_map_as_event => true
timeout => 5
}
if [original_event] {
mutate {
merge => { "original_event" => "event" }
remove_field => ["original_event"]
}
}
mutate {
add_field => { "template" => "%{templates.join(',')}" }
remove_field => ["template_arr", "templates"]
}
}
}
}
}
Please help me fix the filter
Thnx!