我试图在ELK堆栈中使用GROK过滤器解析和构造原始代理数据,我可以得到正确格式的时间戳和用户代理字符串。请参考示例日志,如下所示:
"1488852784.440 1 10.11.62.19 TCP_DENIED/403 0 GET http://xxx.xxx.com/xxx - NONE/- - BLOCK_WEBCAT_12-XXX-XXX-NONE-NONE-NONE-NONE <IW_aud,0.0,-,""-"",-,-,-,-,""-"",-,-,-,""-"",-,-,""-"",""-"",-,-,IW_aud,-,""-"",""-"",""Unknown"",""Unknown"",""-"",""-"",0.00,0,-,""-"",""-"",-,""-"",-,-,""-"",""-""> - L ""http://xxx.xxx.xxx"" 10.11.11.2 - 403 TCP_DENIED ""Streaming Audio"" - - - GET ""Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"" http://xxx.xxx.xxx"
我使用以下过滤器:
%{NUMBER:timestamp}%{SPACE}%{NUMBER:request_msec:float} %{IPORHOST:src_ip} %{WORD}/%{NUMBER:response_status:int} %{NUMBER:response_size} %{WORD:http_method} (%{URIPROTO:http_proto}://)?%{IPORHOST:dst_host}(?::%{POSINT:port})?(?:%{NOTSPACE:uri_param})? %{USERNAME:user} %{WORD}/(%{IPORHOST:dst_ip}|-)%{GREEDYDATA:content_type}
基于http://grokconstructor.appspot.com,我能够解析除时间戳(1488852784.440)和用户代理字符串之外的一些字段。我在时间戳上尝试了不同的Drok默认过滤器,但它仍显示为数字。
答案 0 :(得分:0)
这是因为Grok无法转换为date
数据类型。为此,您需要使用date
过滤器为您执行此精确转换。
filter {
date {
match => [ "timestamp", UNIX_MS ]
}
}
这会将事件的@timestamp
字段设置为timestamp
字段中已解析的时间戳。