Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use environment variable in 30-output.conf file #366

Closed
mominmaaz opened this issue Apr 13, 2022 · 2 comments
Closed

How to use environment variable in 30-output.conf file #366

mominmaaz opened this issue Apr 13, 2022 · 2 comments

Comments

@mominmaaz
Copy link

I am running logstash(sebp/elk) in docker. The below mentioned configuration is unable to use environmental variable 'MYVAL'. I am adding environment parameter in docker-compose.yml.

30-output.conf

input {
elasticsearch{
...
}
}

filter {
if ![my_field] {
mutate {
replace => { "my_field" => "${MYVAL:default-value}" }
}
}
}

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

@spujadas
Copy link
Owner

tl;dr - Due to the way Logstash is started in the image, I’m not sure this is feasible in an easy way.

In the image, Logstash is started as a service, and AFAIK env vars are unset by systemd before the service is started, so indeed it can’t see MYVAL even though you’ve set it in your docker-compose.yml file (and if you bash into the container, you’ll see it).

For a number of predefined env vars (see image documentation), the start.sh script "manually" sets the env vars in the service start-up files (see e.g. https://github.com/spujadas/elk-docker/blob/master/start.sh#L187-L191 for the LS_OPTS env var).
But other ad hoc env vars such as your MYVAL would be discarded when the service is launched.

In terms of solutions:

@mominmaaz
Copy link
Author

Thanks this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants