# Using pre-defined grok patterns

**URL:** <https://discuss.elastic.co/t/using-pre-defined-grok-patterns/271216>\
**Category:** Logstash\
**Created:** [April 26, 2021, 5:31am UTC](https://discuss.elastic.co/t/using-pre-defined-grok-patterns/271216 "2021-04-26T05:31:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ThreatInter](https://avatars.discourse-cdn.com/v4/letter/t/49beb7/32.png) [@ThreatInter](https://discuss.elastic.co/u/ThreatInter)\
**Post date:** [April 26, 2021, 5:31am UTC](https://discuss.elastic.co/t/using-pre-defined-grok-patterns/271216/1 "2021-04-26T05:31:31Z")

</div>

Hi, community. I just discovered that logstash has pre-defined grok patterns, for firewalls, for example (here [logstash-patterns-core/patterns at master · logstash-plugins/logstash-patterns-core · GitHub](https://github.com/logstash-plugins/logstash-patterns-core/tree/master/patterns)). But I can't understand how I should use them. Can you tell me how I can use pre-defined grok-patterns?  
Suppose I want parse ASA-firewall syslog messages. So I should make it like this:

```auto
filter {
    grok {
	patterns_dir => ["/path/to/ASA_patterns"]
        match => { "message" => ["CISCOFW104001","CISCOFW104002",...,]}
        remove_field => ["message","@timestamp"]
    }
}

```

?

---

<div class="post-metadata">

**Author:** ![grumo35](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/grumo35/32/59451_2.png) [@grumo35](https://discuss.elastic.co/u/grumo35)\
**Post date:** [April 26, 2021, 8:59am UTC](https://discuss.elastic.co/t/using-pre-defined-grok-patterns/271216/2 "2021-04-26T08:59:01Z")

</div>

Hi, you should try this :

```auto
filter {
grok {
				patterns_dir => "/path/to/ASA_patterns"
				match => ["message" => "%{CISCOFW104001}"]
			}
}

```

i'm not sure about the array stuff for severals pattern at a time, let me know if you manage tu use more than one.

---

<div class="post-metadata">

**Author:** ![ThreatInter](https://avatars.discourse-cdn.com/v4/letter/t/49beb7/32.png) [@ThreatInter](https://discuss.elastic.co/u/ThreatInter)\
**Post date:** [April 26, 2021, 9:50am UTC](https://discuss.elastic.co/t/using-pre-defined-grok-patterns/271216/3 "2021-04-26T09:50:31Z")

</div>

Thank you for you answer. I'm already made some tries and has understand how it works, maybe I will try few patterns too.

---

<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:** [April 26, 2021, 4:31pm UTC](https://discuss.elastic.co/t/using-pre-defined-grok-patterns/271216/4 "2021-04-26T16:31:43Z")

</div>

> [@ThreatInter](#):
>
> ```auto
> grok {
> patterns_dir => ["/path/to/ASA_patterns"]
> match => { "message" => ["CISCOFW104001","CISCOFW104002",...,]}
> remove_field => ["message","@timestamp"]
> }
> 
> ```

That should work, but you do not need the patterns\_dir option. You are using one of the bundled patterns files that are loaded automatically.

---

<div class="post-metadata">

**Author:** ![ThreatInter](https://avatars.discourse-cdn.com/v4/letter/t/49beb7/32.png) [@ThreatInter](https://discuss.elastic.co/u/ThreatInter)\
**Post date:** [April 27, 2021, 4:48am UTC](https://discuss.elastic.co/t/using-pre-defined-grok-patterns/271216/5 "2021-04-27T04:48:21Z")

</div>

Yea, figured it out. Now have another problem - can't use my custom patterns:

```auto
path: /opt/experimental/logstash_patterns/

```

in this directory I have 2 subdir, same as pre-defined, just changed some of patterns little bit  
 ![изображение](https://us1.discourse-cdn.com/elastic/original/3X/f/2/f2dfe733da94187dae6f536426686f1acee63e00.png)  
my configuration:

```auto
      grok {
        patterns_dir => ["/opt/experimental/logstash_patterns"]
        match => { "message" => ["%{CISCOFW104001}","%{CISCOFW104002}","%{CISCOFW104003}", "%{CISCOFW104004}", "%{CISCOFW105003}",
        "%{CISCOFW105004}", "%{CISCOFW105005}", "%{CISCOFW105008}", "%{CISCOFW105009}", "%{CISCOFW106001}", "%{CISCOFW106006_106007_106010}",
        "%{CISCOFW106014}", "%{CISCOFW106015}", "%{CISCOFW106021}", "%{CISCOFW106023}", "%{CISCOFW106100_2_3}", "%{CISCOFW106100}","%{CISCOFW304001}",
        "%{CISCOFW110002}", "%{CISCOFW302010}", "%{CISCOFW302013_302014_302015_302016}", "%{CISCOFW302020_302021}","%{CISCOFW305011}",
        "%{CISCOFW313001_313004_313008}","%{CISCOFW313001_313004_313008_custom}", "%{CISCOFW313005}", "%{CISCOFW321001}", "%{CISCOFW402117}", "%{CISCOFW402119}","%{CISCOFW419001}",
        "%{CISCOFW419002}", "%{CISCOFW500004}", "%{CISCOFW602303_602304}", "%{CISCOFW710001_710002_710003_710005_710006}","%{CISCOFW713172}", "%{CISCOFW733100}"
        ]}
      }

```

And parsing doesn't working. What could be the problem? Also tried this path:

```auto
/opt/experimental/logstash_patterns/ecs-v1

```

P.S. Solved it.

---

<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:** [May 25, 2021, 4:48am UTC](https://discuss.elastic.co/t/using-pre-defined-grok-patterns/271216/6 "2021-05-25T04:48:32Z")

</div>

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