Grok 解析消息中的特殊字符
Grok parsing with special characters in message
在 Logstash/grok 中,我如何解析带有丹麦字母表中特殊字符(例如 æøå)的邮件?
我正在尝试解析以下消息(IIS 日志文件):
2016-06-12 18:15:10 server01 192.168.10.1 GET /test/charæfoobar pagenumber=2 443 - 192.168.100.31 HTTP/1.1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64;+rv:47.0)+Gecko/20100101+Firefox/47.0 https://domain.com/test/char%C3%A6foobar domain.com 200 0 0 5493 559 515
采用这种模式:
%{TIMESTAMP_ISO8601:logTimestamp} %{NOTSPACE:server} %{IP:serverIp} %{WORD:method} %{URIPATHPARAM:page} %{NOTSPACE:querystring} %{NUMBER:port} %{NOTSPACE:username} %{IP:clientIp} %{NOTSPACE:httpVersion} %{NOTSPACE:useragent} %{NOTSPACE:referer} %{NOTSPACE:siteDomain} %{NUMBER:status} %{NUMBER:substatus} %{NUMBER:win32Status} %{NUMBER:bytesSent:int} %{NUMBER:bytesReceived:int} %{NUMBER:timetaken:int}
我一直在使用这个工具进行调试:http://grokconstructor.appspot.com/ 它似乎被消息中的 æ 字符卡住了。
我正在使用编码设置为 UTF-8 的 Filebeat 日志发送器,IIS 也以 UTF-8 格式输出日志。它直接运送到 Logstash。
有什么想法吗?
根据统一资源定位符 (URL) 上的 RFC 1738:
URLs are written only with the graphic printable characters of the US-ASCII coded character set. The octets 80-FF hexadecimal are not used in US-ASCII, and the octets 00-1F and 7F hexadecimal represent control characters; these must be encoded.
由于字符 æ
,即 unicode E6,在 80-FF 范围内,因此需要将其编码为 %C3%A6
等价的十六进制。如果您的 URL 被正确编码为 /test/char%C3%A6foobar
,就像引用 URL 中的情况一样,那么 grok 将正确解析它。
更新
如果你想处理那些非 ASCII 字符,而不是使用 URIPATHPARAM
预定义模式,你可以从那个模式构建 your own pattern 并包含你想要的非 ASCII 字符考虑。
在 Logstash/grok 中,我如何解析带有丹麦字母表中特殊字符(例如 æøå)的邮件?
我正在尝试解析以下消息(IIS 日志文件):
2016-06-12 18:15:10 server01 192.168.10.1 GET /test/charæfoobar pagenumber=2 443 - 192.168.100.31 HTTP/1.1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64;+rv:47.0)+Gecko/20100101+Firefox/47.0 https://domain.com/test/char%C3%A6foobar domain.com 200 0 0 5493 559 515
采用这种模式:
%{TIMESTAMP_ISO8601:logTimestamp} %{NOTSPACE:server} %{IP:serverIp} %{WORD:method} %{URIPATHPARAM:page} %{NOTSPACE:querystring} %{NUMBER:port} %{NOTSPACE:username} %{IP:clientIp} %{NOTSPACE:httpVersion} %{NOTSPACE:useragent} %{NOTSPACE:referer} %{NOTSPACE:siteDomain} %{NUMBER:status} %{NUMBER:substatus} %{NUMBER:win32Status} %{NUMBER:bytesSent:int} %{NUMBER:bytesReceived:int} %{NUMBER:timetaken:int}
我一直在使用这个工具进行调试:http://grokconstructor.appspot.com/ 它似乎被消息中的 æ 字符卡住了。
我正在使用编码设置为 UTF-8 的 Filebeat 日志发送器,IIS 也以 UTF-8 格式输出日志。它直接运送到 Logstash。
有什么想法吗?
根据统一资源定位符 (URL) 上的 RFC 1738:
URLs are written only with the graphic printable characters of the US-ASCII coded character set. The octets 80-FF hexadecimal are not used in US-ASCII, and the octets 00-1F and 7F hexadecimal represent control characters; these must be encoded.
由于字符 æ
,即 unicode E6,在 80-FF 范围内,因此需要将其编码为 %C3%A6
等价的十六进制。如果您的 URL 被正确编码为 /test/char%C3%A6foobar
,就像引用 URL 中的情况一样,那么 grok 将正确解析它。
更新
如果你想处理那些非 ASCII 字符,而不是使用 URIPATHPARAM
预定义模式,你可以从那个模式构建 your own pattern 并包含你想要的非 ASCII 字符考虑。