【发布时间】:2019-02-05 18:46:53
【问题描述】:
我正在用一种实用的方法开始使用 elastic-stack 的第一步,试图让它在我的环境中与应用程序一起工作。我很难从头开始理解如何编写 grok 过滤器。我希望有一个这样的工作,所以我可以从那个工作,其余的工作。
我参加了一些 udemy 课程,我正在阅读这个“Elastic Stack 6.0”,我正在阅读文档,但我找不到一种方法来使这项工作按预期工作。
到目前为止,我使用的唯一真正有效的 grok 过滤器就像 (/etc/logstash/config.d/beats.conf) 一样简单
input {
beats {
port => 5044
}
}
filter {
grok {
match => { 'message' => "%{DATE:date} %{TIME:time} %
{LOGLEVEL:loglevel}"
}
}
}
output {
elasticsearch {
hosts => ["localhost:9200"]
}
}
这是我需要处理的日志条目之一,但有许多不同的形式。我只需要把这个整理好,这样我就可以让过滤器适应其他的了。
2019-02-05 19:13:04,394 信息 [qtp1286783232-574:http://localhost:8080/service/soap/AuthRequest] [name=admin@example.com;oip=172.16.1.69;ua=zclient/8.8.9_GA_3019;soapId=3bde7ed0;] SoapEngine - 处理程序异常:[admin] 身份验证失败,密码无效
我想要这个信息,只有当有“soapId”并且“INFO”旁边的字段以“qtq”开头时:
date: 2019-02-05
time: 19:13:04,394
loglevel: INFO
identifier: qtp1286783232-574
soap: http://localhost:8080/service/soap/AuthRequest
Which could also end in things like "GetInfoRequest" or "NoOpRequest"
account: admin@example.com
oip: 172.16.1.69
client: zclient/8.8.9_GA_3019
soapid: 3bde7ed0
error: true (if either "invalid password" or "authentication failed" are found in the line)
如果条件不满足,那么我将应用其他过滤器(希望我能够编写适应这个作为基础的过滤器)。
【问题讨论】:
-
如果输入中有
invalid password,则不能有false。您只能匹配字符串中的内容。 -
试试
%{DATE:date} %{TIME:time} %{LOGLEVEL:loglevel} *\[(?<identifier>qtp[^\]\[:]*):(?<soap>[^\]\[]*)]\s*\[name=(?<accout>[^;]+);oip=(?<oip>[0-9.]+);ua=(?<client>[^;]+);soapId=(?<soapId>[^;]+);].*?(?:(?<error>authentication failed).*)?$。您可能需要双转义反斜杠。 -
非常感谢维克托!这在第一次尝试时奏效了。我现在正在按照本指南github.com/kkos/oniguruma/blob/master/doc/RE 尝试完全理解它,我没有看到将您的 cmets 标记为“答案”的选项,所以我只对它们投了赞成票。再次,非常感谢!
-
在下面查看我的解释。
标签: regex elastic-stack logstash-grok