# How to filter logs coming from filebeat and apply a filter on message

**URL:** <https://discuss.elastic.co/t/how-to-filter-logs-coming-from-filebeat-and-apply-a-filter-on-message/267694>\
**Category:** Logstash\
**Created:** [March 18, 2021, 3:46pm UTC](https://discuss.elastic.co/t/how-to-filter-logs-coming-from-filebeat-and-apply-a-filter-on-message/267694 "2021-03-18T15:46:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![muralikrishna](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@muralikrishna](https://discuss.elastic.co/u/muralikrishna)\
**Post date:** [March 18, 2021, 3:46pm UTC](https://discuss.elastic.co/t/how-to-filter-logs-coming-from-filebeat-and-apply-a-filter-on-message/267694/1 "2021-03-18T15:46:27Z")

</div>

Hi Folks,

I am using Logstash 7.8 version and i will be getting logs from multiple data sources as part of my requirement.

I wanted to apply a filter on my log message coming from filebeat and containing the string "pam\_sm\_open\_session" so that i can add a tag to the message and send it to my desired destination.

I have tried using the below to get the desired output, how ever it is not working for me.

my log message: "Mar 18 23:20:01 PAM-unixteam[14\*\*\*]: pam\_sm\_open\_session(service=crond, terminal=cron, user=root, ruser=UNDEF, rhost=UNDEF)"

I am using the below filter, to add a tag

* * *

## if [agent\_type] == "filebeat" { if [message] =~ "pam\_sm\_open\_session" { mutate { add\_tag =\> ["UNIX"] } } }

also tried like below.

* * *

## if [agent\_type] == "filebeat" { if "pam\_sm\_open\_session" in [message] { mutate { add\_tag =\> ["Unix] } } }

but both of them are not working and not giving the expected results.

Appreciate if anyone can help me in resolving this.. Thanks alot.

---

<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 18, 2021, 5:47pm UTC](https://discuss.elastic.co/t/how-to-filter-logs-coming-from-filebeat-and-apply-a-filter-on-message/267694/2 "2021-03-18T17:47:07Z")

</div>

I would expect both the tests against [message] to work. Perhaps the test for [agent\_type] is not working. What does the event look like if you use

```
output { stdout { codec => rubydebug } }
```

---

<div class="post-metadata">

**Author:** ![muralikrishna](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@muralikrishna](https://discuss.elastic.co/u/muralikrishna)\
**Post date:** [March 18, 2021, 7:12pm UTC](https://discuss.elastic.co/t/how-to-filter-logs-coming-from-filebeat-and-apply-a-filter-on-message/267694/3 "2021-03-18T19:12:04Z")

</div>

Thanks for the reply badger.

Yes I think the check for [agent\_type] is the issue..

Also tried this way, still no luck.

* * *

## If [agent] [type] == "filebeat"

And for rubydebug, will check and let u know.

---

<div class="post-metadata">

**Author:** ![muralikrishna](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@muralikrishna](https://discuss.elastic.co/u/muralikrishna)\
**Post date:** [April 1, 2021, 2:32pm UTC](https://discuss.elastic.co/t/how-to-filter-logs-coming-from-filebeat-and-apply-a-filter-on-message/267694/4 "2021-04-01T14:32:49Z")

</div>

Hi,

This is working now for me..

* * *

## If [agent] [type] == "filebeat"

---

<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 29, 2021, 2:33pm UTC](https://discuss.elastic.co/t/how-to-filter-logs-coming-from-filebeat-and-apply-a-filter-on-message/267694/5 "2021-04-29T14:33:20Z")

</div>

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