我有一台远程机器,它组合多行事件并通过lumberjack协议发送它们。
得到的东西看起来像这样:
{
"message" => "2014-10-20T20:52:56.133+0000 host 2014-10-20 15:52:56,036 [ERROR ][app.logic ] Failed to turn message into JSON\nTraceback (most recent call last):\n File \"somefile.py", line 249, in _get_values\n return r.json()\n File \"/path/to/env/lib/python3.4/site-packages/requests/models.py\", line 793, in json\n return json.loads(self.text, **kwargs)\n File \"/usr/local/lib/python3.4/json/__init__.py\", line 318, in loads\n return _default_decoder.decode(s)\n File \"/usr/local/lib/python3.4/json/decoder.py\", line 343, in decode\n obj, end = self.raw_decode(s, idx=_w(s, 0).end())\n File \"/usr/local/lib/python3.4/json/decoder.py\", line 361, in raw_decode\n raise ValueError(errmsg(\"Expecting value\", s, err.value)) from None\nValueError: Expecting value: line 1 column 1 (char 0), Failed to turn message into JSON"
}
当我尝试将消息与
grok {
match => [ "message", "%{TIMESTAMP_ISO8601:timestamp} \[%LOGLEVEL:loglevel}%{ SPACE}\]\[%{NOTSPACE:module}%{SPACE}\]%{GREEDYDATA:message}" ]
}
GREEDYDATA
并不像我想的那样贪婪。
因此,我尝试使用gsub:
mutate {
gsub => ["message", "\n", "LINE_BREAK"]
}
# Grok goes here
mutate {
gsub => ["message", "LINE_BREAK", "\n"]
}
但是那个没有用,而不是
The Quick brown fox
jumps over the lazy
groks
我得到了
The Quick brown fox\njumps over the lazy\ngroks
所以..。
如何将换行符重新添加到我的数据中,使GREEDYDATA
与我的换行符匹配,或者以其他方式获取消息的相关部分?
发布于 2014-10-20 21:33:42
所有的GREEDYDATA
都是.*
,但是.
不匹配换行符,所以你可以用(?<message>(.|\r|\n)*)
替换%{GREEDYDATA:message}
,让它变得更贪婪。
发布于 2014-10-20 21:45:45
将regex标志添加到开头允许匹配换行符:
match => [ "message", "(?m)%{TIMESTA...
发布于 2020-04-30 10:13:17
我对Vertica log使用(?m)和^\n+的最后理解
match => ["message","(?m)%{TIMESTAMP_ISO8601:ClientTimestamp}%{SPACE}(%{DATA:Action}:)?(%{DATA:ThreadID} )?(\[%{DATA:Module}\] )?(\<%{DATA:Level}\> )?(\[%{DATA:SubAction}\] )?(@%{DATA:Nodename}:)?( (?<Session>(\{.*?\} )?.*?/.*?): )?(?<message>[^\n]+)((\n)?(\t)?(?<StackTrace>[^\n]+))?"]
多亏了asperla
https://stackoverflow.com/questions/26474873
复制