Logstash on kubernetes. Multiple output conditions

Hi, guys!

I want to manipulate output indexes in my output section. The config example below don't work. I need insert data into one index when host_name index is present or another if not.
Field kubernetes.labels.devops_destination field in both condition should be == "logs"

output {
  if [vs-service] == "nameofservice" {
    elasticsearch {
      hosts => ["${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}"]
      manage_template => false
      ssl_certificate_verification => false
      user => "user"
      password => "${PASSWORD}"
      index => "%{[vs_service]}_%{[accountcode]}"
    }
  }
  else if [kubernetes][labels][devops_destination] == "logs" and "" in [host_name] {
    elasticsearch {
      hosts => ["${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}"]
      manage_template => false
      ssl_certificate_verification => false
      user => "user"
      password => "${PASSWORD}"
      index => "%{[kubernetes][labels][devops_destination]}-%{[host_name]}-%{+YYYY.MM.dd}"
    }
  }
  else if [kubernetes][labels][devops_destination] == "logs"  {
    elasticsearch {
      hosts => ["${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}"]
      manage_template => false
      ssl_certificate_verification => false
      user => "user"
      password => "${PASSWORD}"
      index => "%{[kubernetes][labels][devops_destination]}-%{[kubernetes][namespace]}-%{+YYYY.MM.dd}"
    }
  }
  else {
    elasticsearch {
      hosts => ["${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}"]
      manage_template => false
      ssl_certificate_verification => false
      user => "user"
      password => "${PASSWORD}"
      index => "recyclebin-%{+YYYY.MM.dd}"
    }
  }
}

What do you think that means?

I think, this field is exist.
I looking for condition checking existence field and not null

I think you want

else if [kubernetes][labels][devops_destination] == "logs" and [host_name] {

But working just this condition:
else if [host_name] {
If I start using your example - stop working.

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