使用Kibana的Grok调试器:
1。访问GROK调试器,您可以使用“导航菜单”或“全局搜索”字段[1]通过导航到开发人员工具页面来找到GROK调试器。对于旧版本,例如7.17,打开主菜单,单击开发工具,然后单击Grok Debugger ** [3]。请注意,如果您使用弹性堆栈安全功能,则必须具有`anage_pipeline`权限来使用Grok调试器[1] [3]。
2。在“示例数据”部分中输入示例数据,输入代表您要解析的数据的消息[1] [3]。例如:`55.3.244.1 get /index.html 15824 0.043` [1]。
3。在Grok模式部分中输入Grok模式,输入要应用于数据的Grok模式[1] [3]。要在给定示例中解析日志行,请使用:`'%{ip:client}%{word}%{uripathparam:unprect}%{number:bytes}%{number}%{number:duration}`[1]。
4。仿真单击模拟,您将看到应用Grok模式[1] [3]导致的模拟事件。
您还可以测试自定义模式[3]:
1。示例数据输入您的示例消息[3]。例如:```1月1日06:25:43 MailServer14 Postfix/Clearup [21403]:BEF25A72965:Message-ID =`[3]。
2。grok模式输入您的grok模式[1] [3]。例如:`'%{syslogbase}%{postfix_queueid:queue_id}:%{msg:syslog_message}`。此GROK模式引用自定义模式,称为“ Postfix_queueid”和“ msg” [3]。
3.自定义模式扩展“自定义模式”部分,并为要在Grok表达式中使用的自定义模式输入模式定义。在其自己的行[1] [3]上指定每个模式定义。在给定的示例中,指定“ Postfix_queueid”和“ msg”的模式定义:`postfix_queueid [0-9a-f] {10,11} msg message-id =`[1] [3]。
4。模拟单击模拟** [1] [3]。您会看到通过应用包含自定义模式[1]的Grok模式而产生的模拟输出事件。如果发生错误,您可以继续在自定义模式上迭代,直到输出与您期望的事件匹配[1] [3]。
Grok调试器简化了日志分析,使您可以在部署之前测试和完善Grok模式[5]。 Grok是一种模式匹配的语法,您可以用来解析任意文本并构造它[1] [3]。它非常适合解析系统列表,Apache和其他WebServer日志,MySQL日志,并且通常是为人类消费编写的任何日志格式[1] [3]。
引用:[1] https://www.elastic.co/guide/en/kibana/current/xpack-grokdebugger.html
[2] https://www.elastic.co/guide/en/elasticsearch/reference/current/grok.html
[3] https://www.elastic.co/guide/en/kibana/7.17/xpack-grokdebugger.html
[4] https://stackoverflow.com/questions/26679465/debugging-new-new-logstash-grok-filters-before-full-use
[5] https://latenode.com/blog/a-complete-guide-to-using-the-the-grok-debugger
[6] https://discuss.elastic.co/t/grok-filter-pattern-not-working/211780
[7] https://edgedelta.com/company/blog/what-are-rok-patterns
[8] https://www.elastic.co/guide/en/elasticsearch/reference/current/esqurrent/esql-process-data-with-data-with-dissect-and-grok.html
[9] https://www.elastic.co/blog/debugging-broking-broken-grok-expressions-in-elasticsearch-processors
[10] https://stackoverflow.com/questions/38096827/querying-kibana-using-grok-pattern