简体   繁体   English

Logstash-Grok-多行异常

[英]Logstash - Grok - Exception on multiple lines

I'm trying to parse through a grok filter some very various exception, so I wrote a grok filter, with the help of rubular.com, to parse every single type of exception. 我试图通过grok过滤器解析各种异常,因此我在rubular.com的帮助下编写了grok过滤器来解析每种类型的异常。 The filter is: 过滤器为:

grok {
match => { message => "^(?<year>\d{4})-(?<month>\d{1,2})-(?<day>\d{1,2})\W(?<hours>\d{2}):(?<minutes>\d{2}):(?<seconds>\d{2})(,)[0-9]*(.*)(?<log_level>(ERROR|INFO)) (?<exception>(.*\n^Axis.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*)|(com.*trying.*\ncom.*is:.*\n.*java.*)|(com.*\n^org.*\n###.*non valido\n\n.*^###.*\n^###.*\n^###.*)|(.*trying.*\n^com.*ServiceException.*\n### Error querying.*\n\n.*\n^###.*\n.*)|(.*trying.*\n^com.*ServiceException.*\n^###.*\n^###.*)|(.*trying.*\n^com.*)|(.*\n^org.*\n###.*Exception.*\n### Cause:.*)|(com.*\n^org.*\n###.*)|(.*\n^java.*CORBA.*\n.*)|(.*\n^java*.*)|(com.*\n^com.*)|(.*null\n^Axis.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*)|(.*\n))"}
}

which as you can see as a lot of OR conditions in the exception field and a lot of \\n to take the carriage returns. 如您所见,在例外字段中有很多OR条件,并且有许多\\ n可以使用回车符。 The problem is that, from what I understood, Logstash can read only one line at a time and can't match multiple lines (so, even if on rubular this pattern was working perfectly, it doesn't in logstash). 问题是,据我了解,Logstash一次只能读取一行,并且不能匹配多行(因此,即使在rubular上,此模式运行良好,也无法在logstash中使用)。 How can I filter the exceptions correctly? 如何正确过滤异常?

You can multiline before grok, for example java exceptions: 您可以在grok之前多行,例如java例外:

multiline {
    type => %sometype
    pattern => "(^\s)"
    what => previous 
          }

So this will append all lines that starts with whitespace to previous. 因此,这会将所有以空格开头的行添加到上一行。 And after that you can use grok filter. 然后,您可以使用grok过滤器。

Oh, and you can mutate to avoid '\\n' symbols after multiline: 哦,您可以进行变异以避免多行后出现'\\ n'符号:

mutate {
    gsub => ["message", "\n", " "]
       }

After that you are ready to filter multiline message. 之后,您就可以过滤多行消息了。

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

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