2014-02-26 41 views
2

我想使用logstash解析iis日誌文件並將它們發送到elasticsearch。如何正確設置從iis日誌logstach中的時間戳

我有以下的日誌行

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是實際事件的時間。

我在做什麼錯?

回答

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"] 
    } 
} 
+1

感謝您的建議,不幸的是我無法讓它工作。 @timestamp字段仍然是我運行logstash腳本的時間,而不是事件的時間。 – Jon

+0

意識到它必須處理日誌時間字段,現在正在工作。 – Jon

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"] 
    } 

小疑難雜症是沒有的日期表達,從而導致今年的格式,我猜DATES TAMP從一年中消除了世紀。

+0

其實我的答案接近你的答案,你不需要再發布。 –

+0

啊,我現在看到,沒有引起足夠的重視,把答案設定爲接受:) – Jon