How can I escape backslash in logstash grok patter

2019-07-20 13:21发布

This is my log:

68.192.186.96 - - [18/May/2015:12:54:42 +0000] GET http://test.com/sectionId/592/apiVersion/2/type/json HTTP/1.1 200 575 \"-\" \"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36\" \"icon_seq=0; PHPSESSID=frmnhfrrc25ullikbv71thc283\"

this is my pattern

%{IPORHOST:remoteip} \- \- \[%{HTTPDATE:timestamp}\] %{WORD:verb} %{NOTSPACE:request} HTTP/%{NUMBER:httpversion} %{NUMBER:status} %{NUMBER:requestNum} \"\-\" %{QUOTEDSTRING:agent}

When I check it's giving me problems with the backslashes in the log. How can I escape them? thanks!

1条回答
手持菜刀,她持情操
2楼-- · 2019-07-20 13:49

You escape a backslash with a backslash. \\ matches \

%{IPORHOST:remoteip} \- \- \[%{HTTPDATE:timestamp}\] %{WORD:verb} %{NOTSPACE:request} HTTP/%{NUMBER:httpversion} %{NUMBER:status} %{NUMBER:requestNum} \\"\-\\" %{QUOTEDSTRING:agent}

Also, when it comes to escaping hyphens, check out this answer.

查看更多
登录 后发表回答