Grok-logstash管道未过滤文本



我是Elasticstack的新手。我正在尝试实现一个logstash管道,在这个管道中,一个文件将被处理,如果文件行包含以下关键字,它将过滤并输出

  1. java.lang.Exception-任何包含Exception的文件行都应该被过滤,并在Kibana 上可用

  2. XYZ过程已完成。

我尝试了以下操作,但似乎也输出了与异常不匹配的所有内容-

input {
beats {
port => 5044
tags => "exception"
}
}
filter{
if "exception" in [tags]{


grok {
match => { message => "Exception"
}
}
}
output {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "%{[@metadata][beat]}-%{[@metadata][version]}" 
}
}

请帮助并告知

如果这是您在管道中应用的唯一过滤器,那么与GROK过滤器不匹配的所有过滤器都将添加一个_grokparsefailure标记。您可以使用它来删除事件。在完成过滤器中的所有选项后,使用下面的。

if "_grokparsefailure" in [tags] {
drop{}
}

所以样本过滤器可以是

filter {
grok {
match => { message => "Exception" }
}
if "_grokparsefailure" in [tags] {
drop{}
}
}

另一种方法是,在匹配发生时添加一个标记,然后只接收具有该标记的事件。示例

input {
beats {
port => 5044
tags => "exception"
}
}
filter{
if "exception" in [tags]{
grok {
match => { message => "Exception"}
add_tag => [ "exception_match" ]
}
}
output {
if"exception_match" in [tags]
{
elasticsearch {
hosts => ["http://localhost:9200"]
index => "%{[@metadata][beat]}-%{[@metadata][version]}" 
}
}
}

最新更新