2

我正在尝试使用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 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 字段是我运行解析的时间,而不是日志事件的时间。这会导致所有日志事件在我查看它们时启动 logstash 时最终堆叠在一起。我希望 @timestamp 成为实际事件的时间。

我究竟做错了什么?

4

2 回答 2

1

首先,您可以在 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"]  
    }
}
于 2014-02-26T15:54:14.953 回答
1

我解决了它,没有意识到我必须将日志条目中的时间存储到某些东西中,在这种情况下为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(至尊是日期过滤器的隐式目标字段)

date {
         match => ["eventtime", "YY-MM-dd HH:mm:ss"]  
  }

一个小问题是日期表达式中没有前导年份的格式,我猜 DATESTAMP 从年份中删除了世纪。

于 2014-02-27T09:46:41.833 回答