Environment variables in if..then logic

I am using a number of environment variables in my logstash config which all work well, except for one. In my output section I am trying to use a variable in an if.. then statement and it does not appear to be working. Perhaps it is my syntax. The user, password and proxy variables substitute correctly, but the code always takes the first branch regardless of the value of ${LS_USE_PROXY}. What am I doing wrong?

if "${LS_USE_PROXY}" == "true" {
    elasticsearch {
        hosts => ["https://xxx.eu-central-1.aws.cloud.es.io:443"]
        index => "%{[@metadata][index_alias]}"
        user => "${LS_ELASTIC_USER}"
        password => "${LS_ELASTIC_PASSWD}"
        proxy => "${LS_PROXY}"
    }
} else {
    elasticsearch {
        hosts => ["https://xxx.eu-central-1.aws.cloud.es.io:443"]
        index => "%{[@metadata][index_alias]}"
        user => "${LS_ELASTIC_USER}"
        password => "${LS_ELASTIC_PASSWD}"
    }
}

This is not supported. The workaround is to use mutate+add_field to add a field to [@metadata] then test that.

Sorry @Badger, what specifically is not supported? Using an environment variable in a condition?

Exactly.

Ok. Thanks.

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