沙师弟,师父的充电器掉了

filebeat如何让处理json格式日志的时候支持exclude_lines

Beats | 作者 a505100745 | 发布于2018年06月04日 | 阅读数:10224

目前有个问题,就是nginx的日志是json格式的,但是偶尔会出现
127.0.0.1 - - [04/Jun/2018:00:08:56 +0800] "GET / HTTP/1.1" 200 1167 "-" "curl/7.59.0"
这样的日志,不知道是怎么进到日志里的,现在想到的办法就是在filebeat中配置exclude_lines,但是同时配置了json跟exclude_lines后会报错
  json.message_key: log
json.keys_under_root: true
json.overwrite_keys: true
exclude_lines: ['^DBG',"^$","^127.0.0.1"]

When using the JSON decoder and line filtering together, you need to specify a message_key value accessing 'filebeat.prospector
说这两个想要一起使用需要设置一个特定的message_key,这个我就不知道该设置成什了么。我设置的log就报错。有没有大神帮忙解答下这个问题,谢谢了。
 
 
 
已邀请:

medcl - 今晚打老虎。

赞同来自:

因为 filter 工作顺序是在 decode 的后面。
你可以使用来先普通的方式加载进来,再使用 processors 依次进行过滤和 decode。
 
测试数据
{"a":1}
123,1231
测试配置
filebeat.prospectors:
- type: log
paths:
- /tmp/a.log

processors:
- drop_event:
when:
regexp:
message: "^123"
- decode_json_fields:
fields: ["message"]

output.console:
pretty: true
输出
{
"@timestamp": "2018-06-04T12:45:58.967Z",
"@metadata": {
"beat": "filebeat",
"type": "doc",
"version": "6.2.3"
},
"source": "/tmp/a.log",
"offset": 2849395,
"message": {
"a": 1
},
"prospector": {
"type": "log"
},
"beat": {
"name": "MacBook-Pro.local",
"hostname": "MacBook-Pro.local",
"version": "6.2.3"
}
}

要回复问题请先登录注册