# Help with filtering message based on regex

**URL:** <https://discuss.elastic.co/t/help-with-filtering-message-based-on-regex/266582>\
**Category:** Logstash\
**Created:** [March 8, 2021, 3:42pm UTC](https://discuss.elastic.co/t/help-with-filtering-message-based-on-regex/266582 "2021-03-08T15:42:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![judge](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@judge](https://discuss.elastic.co/u/judge)\
**Post date:** [March 8, 2021, 3:42pm UTC](https://discuss.elastic.co/t/help-with-filtering-message-based-on-regex/266582/1 "2021-03-08T15:42:25Z")

</div>

Hi, I really need some help with logstash.

I a trying to filter messages based on content and send them to an alternative server for example:

{"type":"syslog","host":"1.1.1.1","@timestamp":"2021-03-08T13:18:55.722Z","message":"\<14\>Mar 8 14:04:21 myrouter1 RT\_FLOW: RT\_FLOW\_SESSION\_CREATE: session created 1.1.1.2/500-\>1.1.1.3/500 0x0 junos-ike 0x0 N/A N/

I want to pick out RT\_FLOW\_SESSION\* with regex and tag the entry but I cannot seem to work out how to structure this.

my inputs and outputs are working fine, i have tested this using:

```auto
input {
	syslog {
		port => 514
			}
filter {if [host] == "1.1.1.1"{
mutate { add_tag => [router]}}

```

I have a number of IPs to match, but I think filtering based on a regex will be more efficient.

Thanks in advance.

---

<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:** [March 8, 2021, 5:33pm UTC](https://discuss.elastic.co/t/help-with-filtering-message-based-on-regex/266582/2 "2021-03-08T17:33:35Z")

</div>

You could use grok

```
grok { match => { "message" => "RT_FLOW_SESSION_%{WORD:sessionOp}:" } }
```

---

<div class="post-metadata">

**Author:** ![judge](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@judge](https://discuss.elastic.co/u/judge)\
**Post date:** [March 11, 2021, 7:46pm UTC](https://discuss.elastic.co/t/help-with-filtering-message-based-on-regex/266582/3 "2021-03-11T19:46:12Z")

</div>

Thank you Badger

---

<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 8, 2021, 7:47pm UTC](https://discuss.elastic.co/t/help-with-filtering-message-based-on-regex/266582/4 "2021-04-08T19:47:00Z")

</div>

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