# Can you apply another grok filter in case of \_grokparsefailure?

**URL:** <https://discuss.elastic.co/t/can-you-apply-another-grok-filter-in-case-of-grokparsefailure/196557>\
**Category:** Logstash\
**Created:** [August 23, 2019, 3:41pm UTC](https://discuss.elastic.co/t/can-you-apply-another-grok-filter-in-case-of-grokparsefailure/196557 "2019-08-23T15:41:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Siri\_sour](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/siri_sour/32/47746_2.png) [@Siri\_sour](https://discuss.elastic.co/u/Siri_sour)\
**Post date:** [August 23, 2019, 3:41pm UTC](https://discuss.elastic.co/t/can-you-apply-another-grok-filter-in-case-of-grokparsefailure/196557/1 "2019-08-23T15:41:37Z")

</div>

Hey,  
I'm working with different log structure and l Tried to adapt my grok filter for most of logs, but there still some that cause a grokparsefailure.

I wonder what is the best way to handle a grokparsefailure?

In my case I have something like this:

filter {

```
grok {
      match => { message => "(%{TIMESTAMP_ISO8601:timestamp_tmp}\s+\[%{DATA:task}\]\s+%{LOGLEVEL:loglevel}\s+\[%{DATA:package}\]((\s{2}(?m)(?<msgdetail>.*))|(.*\"\s+(?m)(?<msgdtail>.*))|(\+(?m)(?<msgdetail>.*)|.*]\s+(?m)(?<msgdetail>.*))))|(\A%{TIMESTAMP_ISO8601:timestamp_tmp}\s+(.*)%{LOGLEVEL:loglevel}\s+\[%{DATA:package}\]\s+(?m)(?<msgdetail>.*)) | (%{TIMESTAMP_ISO8601:timestamp_tmp}\s+%{LOGLEVEL:loglevel} (?m)(?<msgdetail>.*))" }

    }

  if "_grokparsefailure" in [tags] {
        grok {
            match => {message => "%{TIMESTAMP_ISO8601:timestamp_tmp} (?<task>\[.*\]) %{LOGLEVEL:loglevel} (?m)(?<masgdetail>.*)"}
        }
    }

  mutate{

      rename => { "message" => "raw_message" }
      rename => { "msgdetail" => "message" }
      remove_field => "task"
      lowercase => ["loglevel"]
}

```

}

I have huge amounts of logs and I couldn't manage to test the if statement part.  
Is this gonna work? or is there a better approach to do this?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [August 23, 2019, 6:12pm UTC](https://discuss.elastic.co/t/can-you-apply-another-grok-filter-in-case-of-grokparsefailure/196557/2 "2019-08-23T18:12:51Z")

</div>

A more compact way to do that would be

```
grok {
    match => {
        message => [
            "(%{TIMESTAMP_ISO8601:timestamp_tmp}\s+\[%{DATA:task}\]\s+%{LOGLEVEL:loglevel}\s+\[%{DATA:package}\]((\s{2}(?m)(?<msgdetail>.*))|(.*\"\s+(?m)(?<msgdtail>.*))|(\+(?m)(?<msgdetail>.*)|.*]\s+(?m)(?<msgdetail>.*))))|(\A%{TIMESTAMP_ISO8601:timestamp_tmp}\s+(.*)%{LOGLEVEL:loglevel}\s+\[%{DATA:package}\]\s+(?m)(?<msgdetail>.*)) | (%{TIMESTAMP_ISO8601:timestamp_tmp}\s+%{LOGLEVEL:loglevel} (?m)(?<msgdetail>.*))",
            "%{TIMESTAMP_ISO8601:timestamp_tmp} (?<task>\[.*\]) %{LOGLEVEL:loglevel} (?m)(?<masgdetail>.*)"
    }
}

```

You should probably anchor those patterns to start of line using ^ at the beginning.

---

<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:** [September 20, 2019, 6:20pm UTC](https://discuss.elastic.co/t/can-you-apply-another-grok-filter-in-case-of-grokparsefailure/196557/3 "2019-09-20T18:20:27Z")

</div>

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