2016-04-19 45 views
0

消息看起來像_grokparsefailure上的漆登錄

1.2.3.4 "-" - - [19/Apr/2016:11:42:18 +0200] "GET http://monsite.vpù/api/opa/status HTTP/1.1" 200 92 "-" "curl - API-Player - PREPROD" hit OPA-PREPROD-API - 0.000144958 

我神交模式

grok { 
     match => { "message" => "%{IP:clientip} \"%{DATA:x_forwarded_for}\" %{USER:ident} %{USER:auth} \[%{HTTPDATE:timestamp}\] \"(?:%{WORD:verb} %{NOTSPACE:request}(?: HTTP/%{NUMBER:httpversion})?|%{DATA:rawrequest})\" %{NUMBER:response} (?:%{NUMBER:bytes}|-) %{QS:referrer} %{QS:agent} (%{NOTSPACE:hitmiss}|-) (%{NOTSPACE:varnish_conf}|-) (%{NOTSPACE:varnish_backend}|-) %{NUMBER:time_firstbyte}"} 
    } 

我有一個grokparsefailure標籤,而我所有的字段除了最後一個正確履行,我得到0而不是的0.000144958

在ES完整消息是

{ 
    "_index": "logstash-2016.04.19", 
    "_type": "syslog", 
    "_id": "AVQt7WSCN-2LsQj9ZIIq", 
    "_score": null, 
    "_source": { 
    "message": "212.95.71.201 \"-\" - - [19/Apr/2016:11:50:12 +0200] \"GET http://monsite.com/api/opa/status HTTP/1.1\" 200 92 \"-\" \"curl - API-Player - PREPROD\" hit OPA-PREPROD-API - 0.000132084", 
    "@version": "1", 
    "@timestamp": "2016-04-19T09:50:12.000Z", 
    "type": "syslog", 
    "host": "212.95.70.80", 
    "tags": [ 
     "_grokparsefailure" 
    ], 
    "application": "varnish-preprod", 
    "clientip": "1.2.3.4", 
    "x_forwarded_for": "-", 
    "ident": "-", 
    "auth": "-", 
    "timestamp": "19/Apr/2016:11:50:12 +0200", 
    "verb": "GET", 
    "request": "http://monsite.com/api/opa/status", 
    "httpversion": "1.1", 
    "response": "200", 
    "bytes": "92", 
    "referrer": "\"-\"", 
    "agent": "\"curl - API-Player - PREPROD\"", 
    "hitmiss": "hit", 
    "varnish_conf": "OPA-PREPROD-API", 
    "varnish_backend": "-", 
    "time_firstbyte": "0.000132084", 
    "geoip": { 
     "ip": "1.2.3.4", 
     "country_code2": "FR", 
     "country_code3": "FRA", 
     "country_name": "France", 
     "continent_code": "EU", 
     "region_name": "C1", 
     "city_name": "Strasbourg", 
     "latitude": 48.60040000000001, 
     "longitude": 7.787399999999991, 
     "timezone": "Europe/Paris", 
     "real_region_name": "Alsace", 
     "location": [ 
     7.787399999999991, 
     48.60040000000001 
     ] 
    }, 
    "agentname": "Other", 
    "agentos": "Other", 
    "agentdevice": "Other" 
    }, 
    "fields": { 
    "@timestamp": [ 
     1461059412000 
    ] 
    }, 
    "highlight": { 
    "agent": [ 
     "\"curl - API-Player - @[email protected]@/[email protected]\"" 
    ], 
    "varnish_conf": [ 
     "[email protected]@[email protected]/[email protected]" 
    ], 
    "application": [ 
     "@[email protected]@/[email protected]@[email protected]@/[email protected]" 
    ], 
    "message": [ 
     "1.2.3.4 \"-\" - - [19/Apr/2016:11:50:12 +0200] \"GET http://monsote.com/api/opa/status HTTP/1.1\" 200 92 \"-\" \"curl - API-Player - @[email protected]@/[email protected]\" hit [email protected]@[email protected]/[email protected] - 0.000132084" 
    ] 
    }, 
    "sort": [ 
    1461059412000 
    ] 
} 

答案是kibana不會顯示非常小的數字

回答

1

如果grok,um失敗,您只會得到一個grokparsefailure。所以,這不是生產標籤的grok。使用groks中的tag_on_failure參數爲每個grok提供一個唯一標記。

至於你的解析問題,我敢打賭你的grok工作得很好。請注意,elasticsearch可以動態地創建字段,並根據所看到的第一個數據猜測字段的類型。如果你的第一個數據是「0」,它會使該字段成爲一個整數,而後面的條目將被轉換爲該類型。您可以拉動映射以查看發生了什麼。

您需要控制創建的映射。您可以指定該字段是Grok本身的一個浮點(%{NUMBER:myField:int}),或者創建自己的模板。

還要注意NOTSPACE匹配「 - 」,那麼你的模式爲varnish_backend等,都不是完全正確的。

+0

感謝Alain,我確實刪除了所有索引以創建新的索引。現在映射對於time_firstbyte是正確的(它是字符串),但仍然是'0'和grokparsefailure。我還申請你的想法(:INT) – glmrenard

+0

網站http://grokconstructor.appspot.com/do/match#result確認我神交模式爲正常(見圖片) – glmrenard

+0

我試試你的想法'神交{ 匹配=> { 「消息」=>「%{IP:clientip} \」%{DATA:x_forwarded_for} \「%{USER:ident}%{USER:auth} \ [%{HTTPDATE:timestamp} \] \」(?:% {WORD:verb}%{NOTSPACE:request}(?: HTTP /%{NUMBER:httpversion})?|%{DATA:rawrequest})\「%{NUMBER:response}(?:%{NUMBER:bytes} - )%{QS:引薦}%{QS:代理}(%{NOTSPACE:hitmiss} | - )%{USERNAME:varnish_conf}%{USERNAME:varnish_backend}%{NUMBER:time_firstbyte:INT}「} tag_on_failure => [「_grokparsefailure_varnish」]'但我的grok消息仍然是_grokparsefailure ' – glmrenard