如何从iis日志正确设置logstach中的时间戳
我正在尝试使用logstash解析iis日志文件,并将它们发送到elasticsearch 我有下面的日志行如何从iis日志正确设置logstach中的时间戳,iis,
elasticsearch,logstash,kibana,Iis,
elasticsearch,Logstash,Kibana,我正在尝试使用logstash解析iis日志文件,并将它们发送到elasticsearch 我有下面的日志行 2014-02-25 07:49:32 172.17.0.96 GET /config/integration - 80 - 172.17.28.37 Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/33.0.1750.117+Safari/537.36 401 2 5 1
2014-02-25 07:49:32 172.17.0.96 GET /config/integration - 80 - 172.17.28.37 Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/33.0.1750.117+Safari/537.36 401 2 5 15
并使用此过滤器:
filter {
if [message] =~ "^#" {
drop {}
}
grok {
match => ["message", "%{TIMESTAMP_ISO8601} %{IP:host_ip} %{URIPROTO:method} %{URIPATH:path} (?:-|%{NOTSPACE:uri_query}sern) %{NUMBER:port} %{NOTSPACE:username} %{IP:client_ip} %{NOTSPACE:useragent} %{NUMBER:response} %{NUMBER:subresponse} %{NUMBER:scstatus} %{NUMBER:timetaken}"]
}
date {
match => ["logtime", "YYYY-MM-dd HH:mm:ss"]
}
}
所有内容都被正确解析,但结果中@timstamp字段是我运行解析的时间,而不是日志事件的时间。这会导致所有日志事件在我查看它们时开始日志存储时堆叠在一起。我希望@timestamp是实际事件的时间
我做错了什么?首先,您可以在grok中指定一个日志时间字段。然后,使用日期过滤器将日志时间解析为@timestamp。@timestamp将更新为日志时间。比如说,
filter {
if [message] =~ "^#" {
drop {}
}
grok {
match => ["message", "%{TIMESTAMP_ISO8601:logtime} %{IP:host_ip} %{URIPROTO:method} %{URIPATH:path} (?:-|%{NOTSPACE:uri_query}sern) %{NUMBER:port} %{NOTSPACE:username} %{IP:client_ip} %{NOTSPACE:useragent} %{NUMBER:response} %{NUMBER:subresponse} %{NUMBER:scstatus} %{NUMBER:timetaken}"]
}
date {
match => ["logtime", "YYYY-MM-dd HH:mm:ss"]
}
}
我解决了它,但没有意识到我必须将日志条目中的时间存储到某个东西中,在本例中eventtime
grok {
match => ["message", "%{DATESTAMP:eventtime} %{IP:host_ip} %{URIPROTO:method} %{URIPATH:path} (?:-|%{NOTSPACE:uri_query}sern) %{NUMBER:port} %{NOTSPACE:username} %{IP:client_ip} %{NOTSPACE:useragent} %{NUMBER:response} %{NUMBER:subresponse} %{NUMBER:scstatus} %{NUMBER:timetaken}"]
}
然后使用该值设置@timestamp(它是日期过滤器的隐式目标字段)
一个小的gotcha是日期表达式中没有前导年份的格式,我想DATESTAMP会从年份中删除世纪。谢谢你的建议,不幸的是我无法让它工作。@timestamp字段仍然是我运行logstash脚本的时间,而不是事件的时间。实际上我的答案接近您的答案,您无需再次发布。啊,我现在看到了,我没有足够注意,将您的答案设置为已接受:)
date {
match => ["eventtime", "YY-MM-dd HH:mm:ss"]
}