Can you use environment variables in configuration file for fluentd

I was wondering how to use env vars in the Fluentd configuration, I tried:

<match **> type elasticsearch logstash_format true logstash_prefix $ENV_VAR host *** port *** include_tag_key true tag_key _key </match> 

but it doesn’t work, any idea?

+5
source share
1 answer

EDIT:

Here is a much better solution:

If you pass the "-use-v1-config" flag to Fluentd, this is possible with "# {ENV ['env_var_name']" something like this:

 <match foobar.**> # ENV["FOO"] is foobar type elasticsearch logstash_prefix "#{ENV['FOO']}" logstash_format true include_tag_key true tag_key _key host **** port **** </match> 

The old, kludgey answer is here.

  • Install fluent-plugin-record-reformer and fluent-plugin-forest
  • Update the configuration as follows.

 <match hello.world> type record_reformer tag ${ENV["FOO"]}.${tag_prefix[-1]} # adding the env variable as a tag prefix </match> <match foobar.**> # ENV["FOO"] is foobar type forest subtype elasticsearch <template> logstash_prefix ${tag_parts[0]} logstash_format true include_tag_key true tag_key _key host **** port **** </template> </match> 

In particular, DO NOT use <match **> there. This will capture all events and lead to behavior that is difficult to debug.

+11
source

Source: https://habr.com/ru/post/1208069/


All Articles