Accessing environment variable in config file in a custom made beats


#1

I have built a custom made beats based on libbeat and I want to use environment variable as a value in the config file. However, if I type ${VAR} in the config file and I run config test, I got:
./countbeat -c countbeat.yml --configtest
Exiting: error unpacking config data: missing field accessing 'name' (source:'countbeat.yml')

I tried in line of configuring the name of the shipper:
name: "${HOSTNAME}"

And it works if I change it into a static string:
name: "a_name"

I have tried to use the filebeat (v1.2.3) and the syntax works. Have I made any mistake in building the beats? Thank you.

Thank you.


Beats (Metricbeat) config not accepting environment variables
(Steffen Siering) #2

is the environment variable really set?

With beats 5.0, variable expansion will check if environment variable is available and fail if no default is set. In beats 1.x a missing environment variable will just be ignored.

this might work for you:

name: '${HOSTNAME:localhost}'

if HOSTNAME is not set it will expand into "localhost".

In 5.0 you can try to print a custom error if HOSTNAME is missing via:

name: ${HOSTNAME:?Please set HOSTNAME environment variable}

in beats 5.0 one can also overwrite any setting from command line via -E flag. For example:

./countbeat -c countbeat.yml --configtest -E name=otherhost


#3

Thank you. You are right, $HOSTNAME is set in the shell only but not exported, so it is not available to countbeat.


(system) #4

This topic was automatically closed after 21 days. New replies are no longer allowed.