Logstash environment plugin doesn't seem to work

I want to use an environment variable in my logstash config and see there is an "environment" input community plugin which has a function called add_metadata_from_env.

I've installed the plugin (under Logstash 2.1.0) and have this configuration :

environment {
    add_metadata_from_env => { "this_host" => "HOSTNAME" }
    add_field => [ "hostname", "%{[@metadata][this_host]}" ]
  }

But when the event is sent to Elasticsearch, the field value is the literal text and not the value of the env variable.

hostname	  	  %{[@metadata][this_host]}

I've tried various ways of tying to reference the variable but nothing seems to work.

Any ideas?

HOSTNAME isn't a "real" environment variable (see below) so you can't use it here. Logstash normally adds the current hostname as a field so I'm surprised that you feel a need to add it from an environment variable. But if you insist you can inject the hostname via a ruby filter.

The reason for this is that we have a Logstash Shipper sending messages to a load balancer, behind which there is a pool of Logstash Indexers.

We want to tag the hostname of the Indexer in the message so we can trace messages and measure throughput across the pool.

If HOSTNAME is not classed as a real environment variable (which seems odd to me but there we go), I'll look at the Ruby filter option instead.
Thanks

For me this didnt work.

here is example:

My input file :
filter {
environment {
add_metadata_from_env => {"region" => "REGION_ENV"}
add_field => ["my_env", "%{[@metadata][region]}"]
}
}

bash-3.2$ echo $REGION_ENV
amer
bash-3.2$

My output :
{
"message" => "Hello world\r",
"@version" => "1",
"@timestamp" => "2016-02-17T00:04:13.540Z",
"host" => "0:0:0:0:0:0:0:1",
"port" => 61248,
"my_env" => "%{[@metadata][region]}"
}

Anything I am missing here ?

I tried this as well as mentioned on other thread.

Logstash Input :
filter {
environment {
add_metadata_from_env => {"region" => "REGION_ENV"}
add_field => ["my_env", "%{[@metadata][region]}"]
}
}

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

Logstash Output:
{
"message" => "hello world\r",
"@version" => "1",
"@timestamp" => "2016-02-17T00:42:35.846Z",
"host" => "0:0:0:0:0:0:0:1",
"port" => 61853,
"my_env" => "%{[@metadata][region]}",
"@metadata" => {
"region" => nil
}
}

@gaurav1424, please start new threads for questions that don't directly relate to the existing thread.

Ok. Here you go : Environment filter is not working