Trouble getting Logstash to pick up an environment variable

I am consistently getting an error with trying to pick up the environment variable within my input config file.

Here is what I have:

input {
    redis {
        data_type => "list"
        key => "syslog"
        host => "${REDIS_HOST}"
        add_field => { "logstash_host" => '${HOSTNAME}'
                       "log_source" => "redis"
                       "msg_src" => "%{[type]}" }
        tags =>  [ "syslog", "redis" ]
    }
}

It isn't picking up the REDIST_HOST or the HOSTNAME variables. I have added them to the /etc/default/logstash file (this is Ubuntu 16.04). I have even tried doing it via a shell script inside of /etc/profile.d

I have tried with both export REDIS="10.2.2.2" and just REDIS="10.2.2.2" and neither is working.

The error I get is the following:

[2018-02-07T15:19:49,562][ERROR][logstash.agent ] Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:main, :exception=>"LogStash::ConfigurationError", :message=>"Cannot evaluate ${REDIS_HOST}. Environment variable REDIS_HOST is not set and there is no default value given.", :backtrace...

I start via a service (sudo service logstash start). What am I doing wrong?

Does it work correctly if you run it from the command line with the "--allow-env" switch?

I just tried this both, putting both the export and leaving the export out of the /etc/default/logstash file, and the error didn't show up.

I think I have figured out what I was doing wrong.

I was trying to set something inside the /etc/default/logstash file using another, global environment variable. Apparently, it wasn't picking that up.

I'm guessing this was the issue. Apologize for not checking this part more thoroughly.

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