日志存储筛选器将文本添加到输出



我正在尝试将json输入包含在其他json中。 我无法掌握过滤器的工作原理,我需要为我的应用程序提供一个示例。

我的 json 输入:

{
"documents": {
"name": "projects",
"fields": {
"done": {
"booleanValue": false
},
"title": {
"stringValue": "testtest"
}
},
"createTime": "2018-10-09T10:16:45.835536Z",
"updateTime": "2018-10-09T10:17:37.550249Z"
}
}

输出应为:

{
"fields": {
"test": {
"stringValue": "{"documents": {"name": "projects","fields": {"done": {"booleanValue": false},"title": {"stringValue": "testtest"}},"createTime": "2018-10-09T10:16:45.835536Z","updateTime": "2018-10-09T10:17:37.550249Z"}}"
}
}
}

假设你有像你展示的那样的输入,最肮脏的解决方案是之前修改 JSON。

#!/bin/bash
echo -e "{"fields":{"test":{"stringValue":"" >> newjson.json
cat yourjson.json >> newjson.json
echo -e ""}}}" >> newjson.json

解决方案:

filter {
mutate {
rename => [""", "\""]
}
mutate {
rename => { "message" => "[stringValue]" }
}
mutate {
rename => { "stringValue" => "[test][stringValue]"}
}
mutate {
rename => { "test" => "[fields][test]"}
}
mutate {
remove_field => ["@timestamp", "@version"]
}
}

最新更新