繁体   English   中英

在logstash中使用grok过滤器的条件和正则表达式疑问

[英]Conditionals and regex doubts with grok filter in logstash

我正在用一种实用的方法用 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)

如果条件不满足,那么我将应用其他过滤器(希望我能够编写适应此过滤器作为基础)。

如果输入中的密码无效,则输出中不能为false 您只能匹配字符串中的内容。

我想你可以用

%{DATE:date} %{TIME:time} %{LOGLEVEL:loglevel} *\[(?<identifier>qtp[^\]\[:]*):(?<soap>[^\]\[]*)]\s*\[name=(?<account>[^;]+);oip=(?<oip>[0-9.]+);ua=(?<client>[^;]+);soapId=(?<soapId>[^;]+);].*?(?:(?<error>authentication failed).*)?$

以下是添加模式的详细信息:

  • * - 0+ 个空格
  • \\[ - 一个[字符
  • (?<identifier>qtp[^\\]\\[:]*) - 命名组“标识符”: qtp ,然后是除:][之外的 0+ 个字符
  • : - 一个冒号
  • (?<soap>[^\\]\\[]*) - 命名组“soap”:除][以外的 0+ 个字符
  • ]\\s*\\[name= - a ] ,然后是 0+ 个空格和[name= substring
  • (?<account>[^;]+) - 命名组“account”:除; 1+ 个字符
  • ;oip= - 文字子串
  • (?<oip>[0-9.]+) - 命名组“oip”:1+ 位数字和/或点
  • ;ua= - 文字子串
  • (?<client>[^;]+) - 命名组“client”:除; 1+ 个字符
  • ;soapId= - 文字子串
  • (?<soapId>[^;]+) - 命名组“soapId”:除; 1+ 个字符
  • ;] - 文字子串
  • .*? - 除换行符以外的任何 0+ 个字符,尽可能少
  • (?:(?<error>authentication failed).*)? - 匹配 1 或 0 次出现的可选组
    • 命名组“错误”: authentication failed子字符串
    • .* - 该行的所有其余部分
  • $ - 输入结束。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM