我正在尝试配置Logstash以将一些JSON字段写入数据库。
JSON源如下:
“延迟”:{“请求”:0,“空”:0,“代理”:-1},“服务”:{“主机”:“ 127.0.0.1”,“ created_at”:1554311520,” connect_timeout“:60000,” id“:” bdc5e673-4631-4460-8932-16633057d19f“,” protocol“:” http“,” name“:” Develop“,” read_timeout“:60000,” port“:9999,” Updated_at“:1554316363,”重试“:5,” write_timeout“:60000},” request“:{” querystring“:{},” size“:” 375“,” uri“:” / some / api / 32165498 /端点“,” url“:” http://127.0.0.1:8000/some/api/32165498/endpoint“,”标头“:{” header1“:” 1“,” header2“:” 352515622568“,” header3 “:” a“,” accept“:” / “,” header4“:” 111“,” header5“:” 39318053“,” cache-control“:” no-cache“,”连接”:“保持活动”,“接受编码”:“ gzip,压缩”,“用户代理”:“ PostmanRuntime / 7.13.0”,“主机”:“ 127.0.0.1:8000”,“邮递员-令牌”:“ e6bdbc21-e39b-4420-9d6f-5666d88d8383”,“ header6”:“ a”,“ header7”:“ 96”},“ method”:“ GET”},“ header7”:“ 127.0.0.1” ,“ tries”:{},“ upstream_uri”:“ / some / api / 32165498 / endpoint”,“ response”:{“ headers”:{“ connection”:“ close”,“ content-type”:“ application / json; charset = utf-8“,” content-length“:” 194“,” s erver“:” kong / 1.0.3“},” status“:400,” size“:” 371“},” route“:{” created_at“:1554311575,” methods“:[” GET“,” POST“ ],“ id”:“ 6a13g329-bf1f-451b-bcaa-14cfcf087925”,“服务”:{“ id”:“ bd51e673-4631-4460-8932-16633057d19f”},“名称”:“开发”,“主机“:[],” updated_at“:1554316427,” preserve_host“:false,” regex_priority“:0,” paths“:[],” protocols“:[” http“],” strip_path“:false},” started_at“ :1559094275277}
当尝试过滤某些字段时,键[]似乎弄乱了输出。
当前管道的logstash.conf如下:
input {
beats {
port => "5044"
host => "0.0.0.0"
}
}
filter {
json {
source => "json-message"
}
if [request][header1] {
mutate {
add_field => { "header" => "%{request[header1]}"}}}
mutate {
remove_field => [ "header" ]
}
}
}
output {
file {
path => "/kong_logs/test.log"
}
}
我也尝试了以下配置,但无济于事:
add_field => { "header" => "%{[request][header1]}"}}}
add_field => { "header" => "%{[request][0][header1]}"}}}
add_field => { "header" => "%{request[0][header1]}"}}}
使用此代码,我希望“ header1”字段被过滤掉,但仍在输出中。
谢谢!
答案 0 :(得分:0)
并非完全是一种解决方案,但作为一种解决方法,我使用了以下代码:
mutate {
remove_field => [ {"[header1][field]" ]
}
像魅力一样工作。