How can I escape backslash in logstash grok pattern?

ε祈祈猫儿з 提交于 2019-12-11 02:49:57

问题


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:


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.



来源:https://stackoverflow.com/questions/30304397/how-can-i-escape-backslash-in-logstash-grok-pattern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!