# Drop some line when match in logstash

**URL:** <https://discuss.elastic.co/t/drop-some-line-when-match-in-logstash/80270>\
**Category:** Logstash\
**Created:** [March 28, 2017, 9:48am UTC](https://discuss.elastic.co/t/drop-some-line-when-match-in-logstash/80270 "2017-03-28T09:48:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DannyM](https://avatars.discourse-cdn.com/v4/letter/d/7feea3/32.png) [@DannyM](https://discuss.elastic.co/u/DannyM)\
**Post date:** [March 28, 2017, 9:48am UTC](https://discuss.elastic.co/t/drop-some-line-when-match-in-logstash/80270/1 "2017-03-28T09:48:00Z")

</div>

At the moment i have this filter working to drop some lines

```
## var_log_messages filter
filter {
        if [type] == "var_log_messages" {
                grok {
                                        patterns_dir => ["/etc/logstash/patterns/"]
                        match => { "message" => "%{SYSLOGTIMESTAMP:var_log_messages_timestamp} %{SYSLOGHOST:var_log_messages_hostname} %{DATA:syslog_program}(?:\[%{POSINT:var_log_secure_pid}\])?: %{GREEDYDATA:message}" }
                        overwrite => ["message"]
                }
                        ##ignore unknown spam line
                        if ([message] =~ "(Got|Sent) message type[=](method\_return|method\_call|signal) (sender)\=(n\/a|\:1\.0|org\.freedesktop\.[a-zA-Z0-9]+|[0-9\:\.]+) destination[=](n\/a|\:1\.0|org\.freedesktop\.[a-zA-Z0-9]+) object\=\/org\/freedesktop\/[a-zA-Z0-9\/\_]+ interface\=org\.freedesktop\.[a-zA-Z0-9]+"){
                            drop{}
                        }
                        else if ([message] =~ "GSSAPI client step ([0-9]{1,2})"){
                            drop{}
                        }
                        else if ([message] =~ "nss\_getpwnam\: name \'root\@test\.cloud\' does not map into domain \'test\.nl"){
                            drop{}
                        }
                }
}

```

But i want to make an universal way to drop unwanted log lines with grok patterns.  
i've made a custom pattern to wich matches a part of an unwanted message.

it would be nice to add some line like:  
else if ([message] =~ "[%{IPA\_TIMESTAMP}] attrlist\_replace - attr\_replace (nsslapd-referral, ldap://%{HOSTNAME:host}"){  
}

but grok isnt useable in a logstash conditional.

How could i check multiple matches with grok and drop the unwanted?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [March 28, 2017, 9:55am UTC](https://discuss.elastic.co/t/drop-some-line-when-match-in-logstash/80270/2 "2017-03-28T09:55:38Z")

</div>

You can use the fact that the grok filter tags events that didn't match any of the expressions with `_grokparsefailure` (or some other tag if you like) and then you can drop events with that tag.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 25, 2017, 9:55am UTC](https://discuss.elastic.co/t/drop-some-line-when-match-in-logstash/80270/3 "2017-04-25T09:55:51Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
