# Filter conditions, config

**URL:** <https://discuss.elastic.co/t/filter-conditions-config/222221>\
**Category:** Logstash\
**Created:** [March 5, 2020, 7:49am UTC](https://discuss.elastic.co/t/filter-conditions-config/222221 "2020-03-05T07:49:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![111291](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/111291/32/62724_2.png) [@111291](https://discuss.elastic.co/u/111291)\
**Post date:** [March 5, 2020, 7:49am UTC](https://discuss.elastic.co/t/filter-conditions-config/222221/1 "2020-03-05T07:49:57Z")

</div>

We have three servers. Each sends logs of one format. I am trying to make conditions for filtering logs from these servers using tags. But that does not work.

```auto
input {
  beats {
    port => 5044
    type => beats
  }
  udp {
    port => 6514
    type => syslog
  }
}

filter {
  if ["server1", "server2", "server3"] in [tags] {
    grok {
      match => { "message" => "%{INT:Min}:%{BASE10NUM:Sec}-%{INT:Duration},(%{WORD:Event}|%{SPACE:Event}),%{INT:Level}" }
      match => { "[log][file][path]" => "%{INT:TempYYMMDDHH}.log" }
    }
  } else {
    grok {
      match => { "message" => "%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: %{GREEDYDATA:syslog_message}" }
      add_field => ["received_at", "%{@timestamp}"]
      add_field => ["received_from", "%{host}"]
    }
    date {
      match => ["syslog_timestamp", "MMM d HH:mm:ss", "MMM dd HH:mm:ss"]
    }
  }
}

output {
  if "server1" in [tags] {
    elasticsearch {
      index => "server1-%{+YYYY.MM.dd}"
      hosts => ["localhost:9200"]
    }
  } else if "server2" in [tags] {
    elasticsearch {
      index => "server2-%{+YYYY.MM.dd}"
      hosts => ["localhost:9200"]
    }
  } else if "server3" in [tags] {
    elasticsearch {
      index => "server3-%{+YYYY.MM.dd}"
      hosts => ["localhost:9200"]
    }
  } else {
    elasticsearch {
    	hosts => ["localhost:9200"]
    }
    stdout {
	codec => rubydebug
    }
  }
}
```

Also tried this option

```auto
if "server1" in [tags] or "server2" in [tags] or "server3" in [tags] {
.............
.............
} else ......

```

Please help solve this problem!

Best regards!

---

<div class="post-metadata">

**Author:** ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)\
**Post date:** [March 5, 2020, 9:30am UTC](https://discuss.elastic.co/t/filter-conditions-config/222221/2 "2020-03-05T09:30:01Z")

</div>

Hi there,

what do you mean by `that does not work`? It is a bit too generic. Do all events fall in the `else` condition? Do all events fall in the `if` condition? Does the laptop blow up?

Also, can you share the output you get in the stdout so we can see what really is in that `tags` field?

Thanks

---

<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 2, 2020, 9:30am UTC](https://discuss.elastic.co/t/filter-conditions-config/222221/3 "2020-04-02T09:30:02Z")

</div>

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