Drop log line containing hash character
Asked Answered
D

2

8

In my Logstash shipper I want to filter out lines commented with the hash character:

#This log row should be dropped.
But one this should not.

I was able to use grep filter, but as it is discouraged (going to be decommissioned), I'm trying to get a grok filter to do it instead. This filter is not working:

grok {
  match => ["message", "^#.*"]
  drop_if_match => true
}

I also tried placing the regex in a custom pattern file, but didn't help. Any ideas?

Dissension answered 26/11, 2013 at 11:15 Comment(0)
G
21

Even simpler, if you're interested:

filter {
    if ([message] =~ /^#/) {
        drop{}
    }
}

The last few versions of Logstash have been putting more emphasis on branching logic directly in the config files. Takes a little getting used to, but pretty handy once you do.

Gangboard answered 26/11, 2013 at 19:22 Comment(1)
You don't need extra () around the if condition. if [message =~ "^#"] { is now sufficient.Temekatemerity
D
2

The correct answer is that there is a bug in drop_if_match=>true (Logstash v1.2.2). Use this type of workaround:

grok {
  ...
  add_tag => ["some_comment"]
}
if "some_comment" in [tags] {
  drop {}
}
Dissension answered 26/11, 2013 at 12:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.