2016-12-23 6 views
0

ファイルからjsonコンテンツを抽出するために必要なログファイルが1つあり、logstash jsonフィルタを使用して解析する必要があります。私は1つのgrokパターンを書いたが、それは正しく動作していない。以下は私のログファイルです。grok /正規表現を使用してログファイルのjson値を分割する方法

2016-12-18 12:13:52.313 -08:00 [Information] 636176600323139749 1b2c4c40-3da6-46ff-b93f-0eb07a57f2a3 18 - API: GET https://aaa.com/o/v/S?$filter=uid eq '9'&$expand=org($filter=org eq '0') 
{ 
    "Id": "1b", 
    "App": "D", 
    "User": "", 
    "Machine": "DC", 
    "RequestIpAddress": "xx.xxx.xxx", 
    "RequestHeaders": { 
    "Cache-Control": "no-transform", 
    "Connection": "close", 
    "Accept": "application/json" 
}, 
    "RequestTimestamp": "2016-12-18T12:13:52.2609587-08:00", 
    "ResponseContentType": "application/json", 
    "ResponseContentBody": { 
    "@od","value":[ 
    { 
     "uid":"","sId":"10,org":[ 
     { 
      "startDate":"2015-02-27T08:00:00Z","Code":"0","emailId":"[email protected]" 
     } 
     ] 
    } 
    ] 
}, 
    "ResponseStatusCode": 200, 
    "ResponseHeaders": { 
    "Content-Type": "application/json;" 
}, 
    "ResponseTimestamp": "2016-12-18T12:13:52.3119655-08:00" 
} 

マイGROKパターン

grok {    
     match => [ "message","%{TIMESTAMP_ISO8601:exclude}%{GREEDYDATA:exclude1}(?<exclude2>[\s])(?<json_value>[\W\w]+)"]      
    } 
+0

パターンをキャプチャしたくない場合は、「exclude」、「exclude1」などは必要ありません。 –

答えて

0

と仮定すると、これですべて一つのメッセージ(それは複数行ない、あるいは今の前に結合されている)とURIとJSON、このGROKの間にスペースがありますパターンは動作するはずです:

%{TIMESTAMP_ISO8601} %{NOTSPACE:timezone} \[%{WORD:severity}] %{WORD:field1} %{UUID:field2} %{NUMBER:field3} - API: %{WORD:verb} (?<field4>[^\{]*) %{GREEDYDATA:json} 

を(それがエスケープSPACが含まれている%{URI}を使用するように素敵だったでしょうが、あなたは持っている文字列が有効なURIではありませんes)。

+0

正確な出力が得られません。以下は私があなたの提案を使って得た結果です。 – Mangoski

+0

'{" TIMESTAMP_ISO8601 ":[[" 2016-12-18 12:13:52.313 "]]、" YEAR ":[[" 2016 "]]、" MONTHNUM ":[[" 12 "]]、" MONTHDAY "[[]]、[HOUR]:[[" 12 "、null]]、" MINUTE ":[[" 13 "、null]]、" SECOND ":[[" 52.313 "]]、" ISO8601_TIMEZONE " :[[null]]、 "timezone":[["-08:00"]]、 "severity":[["Information"]]、 "field1":[["636176600323139749"]]、 "field2" [["18"]]、[BASE10NUM]:[["18"]]、 "動詞":[["GET"]]、[["184"]、 ]、 "field4":[["https://aaa.com/o/v/S?$filter=uid eq '9&$ expand = org($ filter = org eq"]]、 "json": [["'0')"]]}} ' – Mangoski

関連する問題