# Initializing a new grok filter from ruby filter

**URL:** <https://discuss.elastic.co/t/initializing-a-new-grok-filter-from-ruby-filter/311722>\
**Category:** Logstash\
**Created:** [August 9, 2022, 12:16pm UTC](https://discuss.elastic.co/t/initializing-a-new-grok-filter-from-ruby-filter/311722 "2022-08-09T12:16:50Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![who](https://avatars.discourse-cdn.com/v4/letter/w/cdc98d/32.png) [@who](https://discuss.elastic.co/u/who)\
**Post date:** [August 21, 2022, 6:19am UTC](https://discuss.elastic.co/t/initializing-a-new-grok-filter-from-ruby-filter/311722/3 "2022-08-21T06:19:00Z")

</div>

Thanks, I was testing different aspects of this case, so it took time to post the reply here.  
Any way, here's the summarized method from what @Badger mentioned in previous post; to initiate and use grok filter plugin (or any other filter generally):

# init section:

1. initialize

```auto
@grok_filter = LogStash::Filters::Grok.new(
        "match" => { "message" => "PATTERN" },
        "tag_on_failure" => ["_grokparsefailure"]
# .... and literally any other config option you'd pass into grok plugin in filter pipeline
  )

```

1. Register  
`@grok_filter.register`

* * *

# code section:

1. Utilize  
`@grok_filter.filter(event)`

However, I faced a relevant new issue which will post in [another topic](https://discuss.elastic.co/t/determining-which-item-in-patterns-array-of-a-grok-plugin-was-matched/312538). Thank you @Badger

---

_[View the full topic](https://discuss.elastic.co/t/initializing-a-new-grok-filter-from-ruby-filter/311722)._
