[英]logstash filter add text to output
我正在尝试将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"]
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.