# How to read environment variables from logstash?

**URL:** <https://discuss.elastic.co/t/how-to-read-environment-variables-from-logstash/39856>\
**Category:** Logstash\
**Created:** [January 22, 2016, 9:33am UTC](https://discuss.elastic.co/t/how-to-read-environment-variables-from-logstash/39856 "2016-01-22T09:33:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![punit\_naik1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/punit_naik1/32/7239_2.png) [@punit\_naik1](https://discuss.elastic.co/u/punit_naik1)\
**Post date:** [January 22, 2016, 9:33am UTC](https://discuss.elastic.co/t/how-to-read-environment-variables-from-logstash/39856/1 "2016-01-22T09:33:12Z")

</div>

I wanted to read an environment variable so I used the environment filter.  
This was my config:

> input  
> {stdin{}}  
> filter{  
> environment{  
> add\_metadata\_from\_env =\> {"hadoop" =\> "HADOOP\_HOME"}  
> }  
> }  
> output{stdout{codec=\>rubydebug}}

where "HADOOP\_HOME" is my environment variable.  
The output however did not show the extra field "hadoop" and its not giving me any errors too.

So what is wrong? Please help!

---

<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:** [January 22, 2016, 10:37am UTC](https://discuss.elastic.co/t/how-to-read-environment-variables-from-logstash/39856/2 "2016-01-22T10:37:37Z")

</div>

The [rubydebug codec](https://www.elastic.co/guide/en/logstash/current/plugins-codecs-rubydebug.html) needs to be configured to include the contents of the `@metadata` field:

```auto
output {
  stdout {
    codec => rubydebug {
      metadata => true
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![punit\_naik1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/punit_naik1/32/7239_2.png) [@punit\_naik1](https://discuss.elastic.co/u/punit_naik1)\
**Post date:** [January 22, 2016, 10:42am UTC](https://discuss.elastic.co/t/how-to-read-environment-variables-from-logstash/39856/3 "2016-01-22T10:42:41Z")

</div>

Thank you so much Mr. @magnusbaeck! You rock! 🕶 😁

---

<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, 5:14am UTC](https://discuss.elastic.co/t/how-to-read-environment-variables-from-logstash/39856/4 "2017-07-06T05:14:46Z")

</div>


