# Logstash environment variables missing

**URL:** <https://discuss.elastic.co/t/logstash-environment-variables-missing/59616>\
**Category:** Logstash\
**Created:** [September 2, 2016, 12:30am UTC](https://discuss.elastic.co/t/logstash-environment-variables-missing/59616 "2016-09-02T00:30:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdambly](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jdambly/32/44286_2.png) [@jdambly](https://discuss.elastic.co/u/jdambly)\
**Post date:** [September 2, 2016, 12:30am UTC](https://discuss.elastic.co/t/logstash-environment-variables-missing/59616/1 "2016-09-02T00:30:03Z")

</div>

I have the following environment vars

```auto
ansible@sv5enalysis01:~$ printenv | grep REDIS
REDIS_HOST=172.16.4.35
REDIS_PORT=6381
ansible@sv5enalysis01:~$

```

but when I start logstash it doesn't replace them

```auto
ansible@sv5enalysis01:~$ /opt/logstash/bin/logstash --allow-env -f /etc/logstash/redis.conf
Settings: Default pipeline workers: 32
Could not connect to Redis at %{REDIS_HOST}:0: Name or service not known
Could not connect to Redis at %{REDIS_HOST}:0: Name or service not known
Could not connect to Redis at %{REDIS_HOST}:0: Name or service not known
Could not connect to Redis at %{REDIS_HOST}:0: Name or service not known
Could not connect to Redis at %{REDIS_HOST}:0: Name or service not known

```

this is what my config looks like

```auto
input {
   exec {
      command => 'redis-cli -h 172.16.4.35 -p 6381 info clients'
      interval => 60
      type => "clients"
   }

   exec {
      command => "redis-cli -h %{REDIS_HOST} -p %{REDIS_PORT} info memory"
      interval => 60
      type => "memory"
   }

   exec {
      command => "redis-cli -h %{REDIS_HOST} -p %{REDIS_PORT} info cpu"
      interval => 60
      type => "cpu"
    }

    exec {
      command => "redis-cli -h %{REDIS_HOST} -p %{REDIS_PORT} info stats"
      interval => 60
      type => "stats"
    }

    exec {
      command => "redis-cli -h %{REDIS_HOST} -p %{REDIS_PORT} info replication"
      interval => 60
      type => "replication"
    }

    exec {
      command => "redis-cli -h %{REDIS_HOST} -p %{REDIS_PORT} info keyspace"
      interval => 60
      type => "keyspace"
    }

}
filter {
    environment {
      add_metadata_from_env => {'redis_host' => "REDIS_HOST"}
    }
    split {
    }
    ruby {
       code => "fields = event['message'].split(':')
       if (fields[0] == 'db0')
          fields[1].split(',').each { |t| terms = t.split('='); event[terms[0]] = terms[1].to_i }
       else
          event[fields[0]] = fields[1].to_f
       end
       event['port'] = ENV['REDIS_PORT']
       event['rhost'] = ENV['REDIS_HOST']
       event['hostport'] = ENV['REDIS_HOST']+ENV['REDIS_PORT']
       "
    }
    mutate {
        remove_field => ["command", "host"]
    }

}

output {
    elasticsearch {
       hosts => ["192.168.0.243:9201", "192.168.0.252:9201", "192.168.0.254:9201", "192.168.0.255:9201"]
       index => 'redis_cluster-sv5-%{+YYYY.MM.dd}'
       idle_flush_time => 1
       timeout => 10
       workers => 1
    }
    stdout { codec => rubydebug { metadata => true } }
}

```

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [September 2, 2016, 5:39am UTC](https://discuss.elastic.co/t/logstash-environment-variables-missing/59616/2 "2016-09-02T05:39:19Z")

</div>

Use `${REDIS_HOST}`, not `%{REDIS_HOST}`.

[https://www.elastic.co/guide/en/logstash/current/environment-variables.html](https://www.elastic.co/guide/en/logstash/current/environment-variables.html)

---

<div class="post-metadata">

**Author:** ![jdambly](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jdambly/32/44286_2.png) [@jdambly](https://discuss.elastic.co/u/jdambly)\
**Post date:** [September 2, 2016, 8:37pm UTC](https://discuss.elastic.co/t/logstash-environment-variables-missing/59616/3 "2016-09-02T20:37:03Z")

</div>

awesome that totally fixed it! thanks! I should have seen that.

---

<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:** [July 6, 2017, 4:40am UTC](https://discuss.elastic.co/t/logstash-environment-variables-missing/59616/4 "2017-07-06T04:40:09Z")

</div>


