# Parse cloud flare logs in json format with ELK

**URL:** <https://discuss.elastic.co/t/parse-cloud-flare-logs-in-json-format-with-elk/144694>\
**Category:** Logstash\
**Created:** [August 16, 2018, 10:53am UTC](https://discuss.elastic.co/t/parse-cloud-flare-logs-in-json-format-with-elk/144694 "2018-08-16T10:53:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roberto\_Giordani](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@Roberto\_Giordani](https://discuss.elastic.co/u/Roberto_Giordani)\
**Post date:** [August 16, 2018, 10:53am UTC](https://discuss.elastic.co/t/parse-cloud-flare-logs-in-json-format-with-elk/144694/1 "2018-08-16T10:53:01Z")

</div>

Hi,  
I'm trying to create a logstash filter to parse the cloud flare json logs like this

{"ClientIP":"x.x.x.x","ClientRequestHost":"[www.test.org](http://www.test.org)","ClientRequestMethod":"POST","ClientRequestProtocol":"HTTP/2","ClientRequestReferer":"","ClientRequestURI":"/index.html","ClientRequestUserAgent":"Go-http-client/2.0","ClientSrcPort":59876,"EdgeEndTimestamp":1533254858064000000,"EdgeServerIP":"","EdgeStartTimestamp":1533254857428999936,"OriginIP":"y.y.y.y","OriginResponseStatus":204,"WAFAction":"unknown","WAFFlags":"0","WAFMatchedVar":"","WAFProfile":"unknown","WAFRuleID":"","WAFRuleMessage":""}

using filebeat as input  
input\_type: log  
json.keys\_under\_root: true  
json.overwrite\_keys: false  
json.add\_error\_key: true

and logstash filter like this  
filter {  
date {  
match =\> ["timestamp", "yyyy-MM-dd HH:mm:ss,SSS", "yyyy-MM-dd HH:mm:ss", "ISO8601"]  
target =\> "@timestamp"  
remove\_field =\> "timestamp"  
}  
mutate {  
gsub =\> [  
"message", '"{', "'{",  
"message", '}"', "}'"  
]  
}  
kv {  
source =\> "message"  
remove\_field =\> ["message"]  
field\_split =\> ","  
value\_split =\> ":"  
trim\_key =\> " "  
trim\_value =\> " "  
}  
}

But Kibana doesn't show the fields splitted correctly  
In particular the first and the last.  
Could you help me ?  
Thanks

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [August 16, 2018, 11:10am UTC](https://discuss.elastic.co/t/parse-cloud-flare-logs-in-json-format-with-elk/144694/2 "2018-08-16T11:10:28Z")

</div>

Don't parse JSON with mutate and kv filters. Use a json filter or json codec in Logstash or enable Filebeat's JSON parser (which it seems like you've done).

---

<div class="post-metadata">

**Author:** ![Roberto\_Giordani](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@Roberto\_Giordani](https://discuss.elastic.co/u/Roberto_Giordani)\
**Post date:** [August 16, 2018, 11:32am UTC](https://discuss.elastic.co/t/parse-cloud-flare-logs-in-json-format-with-elk/144694/3 "2018-08-16T11:32:21Z")

</div>

So you suggest me to remove completely the logstash filter above and all works fine?

---

<div class="post-metadata">

**Author:** ![Roberto\_Giordani](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@Roberto\_Giordani](https://discuss.elastic.co/u/Roberto_Giordani)\
**Post date:** [August 16, 2018, 12:08pm UTC](https://discuss.elastic.co/t/parse-cloud-flare-logs-in-json-format-with-elk/144694/4 "2018-08-16T12:08:09Z")

</div>

great!  
I've only added on 02-beats.conf the codec json  
codec =\> "json"

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 13, 2018, 12:08pm UTC](https://discuss.elastic.co/t/parse-cloud-flare-logs-in-json-format-with-elk/144694/5 "2018-09-13T12:08:14Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
