# Output based on grok message

**URL:** <https://discuss.elastic.co/t/output-based-on-grok-message/350670>\
**Category:** Logstash\
**Created:** [January 9, 2024, 4:13pm UTC](https://discuss.elastic.co/t/output-based-on-grok-message/350670 "2024-01-09T16:13:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brandon\_Kauffman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_kauffman/32/123465_2.png) [@Brandon\_Kauffman](https://discuss.elastic.co/u/Brandon_Kauffman)\
**Post date:** [January 9, 2024, 4:13pm UTC](https://discuss.elastic.co/t/output-based-on-grok-message/350670/1 "2024-01-09T16:13:37Z")

</div>

I am trying to output based on different sysloghosts

```auto
input {
  udp {
    port => 5010
    type => "obs_test_udp"
 }
}
filter {
  grok {
    match => {"message" => "<%{POSINT:syslog_priority}>%{POSINT:syslog_version} %{TIMESTAMP_ISO8601:timestamp} %{SYSLOGHOST:sysloghost}"}
  }
}
output {
  if [sysloghost] in ["10.3.0.20", "10.2.0.12"] {
    file {
        path => "/usr/share/logstash/log/bob.log"
      }
  }
  else if [sysloghost] in ["bk-bot-bot"] {
    file {
        path => "/usr/share/logstash/log/alice.log"
      }
  }
  else {
    file {
        path => "/usr/share/logstash/log/ohno.log"
      }
  }
}

```

I can see the sysloghost file in the ohno log file, but I cannot filter based on it

```auto
{"host":"10.101.192.143","syslog_version":"1","@timestamp":"2024-01-09T16:10:43.649810154Z","message":"<13>1 2024-01-09T11:10:43.755197-05:00 bk-bot-bot bk - - [timeQuality tzKnown=\"1\" isSynced=\"1\" syncAccuracy=\"30500\"] Medford is kewl","sysloghost":"bk-bot-bot","timestamp":"2024-01-09T11:10:43.755197-05:00","@version":"1","type":"obs_test_udp","syslog_priority":"13"}

```

---

<div class="post-metadata">

**Author:** ![Brandon\_Kauffman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_kauffman/32/123465_2.png) [@Brandon\_Kauffman](https://discuss.elastic.co/u/Brandon_Kauffman)\
**Post date:** [January 9, 2024, 4:21pm UTC](https://discuss.elastic.co/t/output-based-on-grok-message/350670/2 "2024-01-09T16:21:57Z")

</div>

```auto
  else if [sysloghost] in ["bk-bot-bot"] {

```

apparently the in condition doesn't work on a single string in an array.

```auto
  else if [sysloghost] in ["bk-bot-bot", "bo dylan"] {

```

worked as expected

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [January 9, 2024, 4:47pm UTC](https://discuss.elastic.co/t/output-based-on-grok-message/350670/3 "2024-01-09T16:47:03Z")

</div>

If I'm not wrong you need to invert when you want to test just one value.

```auto
if "bk-bot-bot" in [sysloghost]

```

Check the examples in the [documentation](https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html#conditionals).

Or you can use just `if [sysloghost] == "bk-bot-bot"`

---

<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:** [January 9, 2024, 5:17pm UTC](https://discuss.elastic.co/t/output-based-on-grok-message/350670/4 "2024-01-09T17:17:40Z")

</div>

See issues [9932](https://github.com/elastic/logstash/issues/9932) and 5591 on github.

---

<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:** [February 6, 2024, 5:18pm UTC](https://discuss.elastic.co/t/output-based-on-grok-message/350670/5 "2024-02-06T17:18:02Z")

</div>

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