简体   繁体   English

logstash / grok自定义文件

[英]logstash / grok custom fileds

I'm a totally new user of ELK stack. 我是ELK堆栈的全新用户。 I've got a little problem with filtering out specific section from my log. 我从日志中过滤出特定部分时遇到了一些问题。

Sample log: 样本日志:

[2017-05-30 13:58:09,336] INFO  [com.qwerty.test.core.services.impl.order.OrderEntryService] (OrderEntryService.java:5426) [http-/0.0.0.0:1111-111] {{CT,1496145487308}{IP,111.11.111.11}{JTX,1511059/176275501}{OBJT,goodsMovement.reportsUtils.ConsignmentStocksList}{OPT,SQ}{PID,111111}{SS,SSCPLTMPRODPL}{TRT,SAP_LOGISTIC_REPORT}{UID,StudentSaSo-8}}: Saving order: K1010101

and my grok filter: 和我的希腊过滤器:

grok {
    match => { "message" => "(?<timestamp>%{YEAR}-%{MONTHNUM2}-%{MONTHDAY} %{HOUR}:%{MINUTE}:%{SECOND},%{NONNEGINT})\] %{LOGLEVEL:loglevel} * \[(?<logger>[A-Za-z0-9$_.]+)\] \(%{JAVAFILE:class}:%{NONNEGINT:line}\) \[%{NOTSPACE:thread}\] %{GREEDYDATA:message_TEST}"}
    }

so i need filter out "ID", "PID", IP and "UID" and i have no idea how to configure this specific custom pattern. 所以我需要过滤掉“ ID”,“ PID”,IP和“ UID”,而且我不知道如何配置此特定的自定义模式。 I try use patterns from https://github.com/logstash-plugins/logstash-patterns-core/tree/master/patterns but it does not work for me 我尝试使用https://github.com/logstash-plugins/logstash-patterns-core/tree/master/patterns中的模式,但对我不起作用

The beginning of your grok is fine. 骗子的开始很好。 Instead of the last part %{GREEDYDATA:message_TEST} , which will just save the remainder of your message into message_TEST you should actually perform parsing of your object. 而不是最后一部分%{GREEDYDATA:message_TEST}%{GREEDYDATA:message_TEST}会将剩余的消息保存到message_TEST您实际上应该执行对象的解析。 Something like this will save PID , IP and UID fields from your object into respective variables (keep in mind that this pattern relies on the fields order): 这样的事情会将对象中的PIDIPUID字段保存到各自的变量中(请注意,此模式取决于字段顺序):

{{.*}{IP,%{IPV4:IP}}({.*}){3}{PID,%{POSINT:PID}}({.*}){2}{UID,%{DATA:UID}}}

Now a little explanation of what it does. 现在对它的作用进行一些解释。 Outer pair of curly brackets is the limit of your object. 一对大括号是对象的限制。 Then we will take care of each field limited by pair of curly brackets inside of the object. 然后,我们将处理受对象内部一对大括号限制的每个字段。

  • first: opening curly bracket { ; 第一:打开大括号{ ;
  • then, the first inner field is {CT,1496145487308} , we are not interested in saving it - so just tell grok that there's some string limited by curly brackets: {.*} ; 然后,第一个内部字段是{CT,1496145487308} ,我们对保存它不感兴趣-因此,请告诉grok某些字符串受大括号限制: {.*} ;
  • next goes field with IP, that we need to save: {IP,111.11.111.11} . 接下来是IP字段,我们需要保存: {IP,111.11.111.11} It starts with curly bracket and IP, followed by IP address that we have to save (last IP in the match is the name of variable that will store the IP address): {IP,%{IPV4:IP} 它以大括号和IP,开头IP,然后是我们必须保存的IP地址(匹配项中的最后一个IP是将存储IP地址的变量的名称): {IP,%{IPV4:IP}
  • now we have three groups of strings surrounded by curly brackets that we don't need to save: {JTX,1511059/176275501}{OBJT,goodsMovement.reportsUtils.ConsignmentStocksList}{OPT,SQ} . 现在我们有三组不需要大括号的字符串,它们都用大括号括起来: {JTX,1511059/176275501}{OBJT,goodsMovement.reportsUtils.ConsignmentStocksList}{OPT,SQ} For grok it looks like: ({.*}){3} ; 对于grok,它看起来像: ({.*}){3} ;
  • then goes PID field: {PID,111111} . 然后进入PID字段: {PID,111111} For grok PID is just a positive integer similarly to IP surrounded by curly brackets and with PID, in front: {PID,%{POSINT:PID}} ; 对于grok来说,PID只是一个正整数,类似于IP(在大括号中并用PID,包围) PID,位于前面: {PID,%{POSINT:PID}} ;
  • two more groups that we don't want to save. 我们不想保存的另外两个组。 Skip them similarly to the previous ones: ({.*}){2} ; 与先前的类似,跳过它们: ({.*}){2} ;
  • last field is: {UID,StudentSaSo-8} , which is just a string of data for grok. 最后一个字段是: {UID,StudentSaSo-8} ,这只是grok的数据字符串。 Similarly to IP and PID saving it in the respective variable: {UID,%{DATA:UID}} ; 与IP和PID相似,将其保存在相应的变量中: {UID,%{DATA:UID}} ;
  • finally we have closing curly bracket: } . 终于,我们有了大括号: }

In the end your final grok will look as follows: 最后,您的最终傻瓜如下所示:

(?<timestamp>%{YEAR}-%{MONTHNUM}-%{MONTHDAY} %{HOUR}:%{MINUTE}:%{SECOND},%{NONNEGINT})\] %{LOGLEVEL:loglevel} * \[(?<logger>[A-Za-z0-9$_.]+)\] \(%{JAVAFILE:class}:%{NONNEGINT:line}\) \[%{NOTSPACE:thread}\] {%{DATA}{IP,%{IPV4:IP}}({.*}){3}{PID,%{POSINT:PID}}({.*}){2}{UID,%{DATA:UID}}}

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

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