Accessing environment variables in filebeat

I'm trying to access an environment variable in filebeat.yml to use as value for a field that I would like to include in the output but don;t seem to work as expected.

filebeat:
  prospectors:
    -
       paths:
        - /var/log/tomcat8/catalina.out
      input_type: log
      fields:
        environment: ${ENVIRONMENT_NAME}

service filebeat start

2016/07/18 02:14:33.430679 beat.go:147: INFO Init Beat: filebeat; Version: 1.2.3

2016/07/18 02:14:33.430833 cfgfile.go:89: INFO Replacing config environment variable '${ENVIRONMENT_NAME}' with ''
$ env | grep ENVIRONMENT_NAME

ENVIRONMENT_NAME=dev

Any help is appreciated

How do you start Filebeat? How do you set the environment variable? It seems like the user with which filebeat is started does not have the environment variable.

Thanks. Filebeat is running as root. If it matters, this is an aws ebs environment.

[root@ip-172-44-44-0 filebeat]# export ENVIRONMENT_NAME=dev
[root@ip-172-44-44-0 filebeat]# service filebeat stop
Stopping filebeat:                                         [  OK  ]
[root@ip-172-44-44-0 filebeat]# service filebeat start
Starting filebeat: 2016/07/18 12:13:18.333971 geolite.go:24: INFO GeoIP disabled: No paths were set under output.geoip.paths
2016/07/18 12:13:18.334116 file.go:39: INFO File output base filename set to: filebeat
2016/07/18 12:13:18.334246 file.go:50: INFO Rotate every bytes set to: 1024000
2016/07/18 12:13:18.334367 file.go:57: INFO Number of files set to: 7
2016/07/18 12:13:18.334494 outputs.go:126: INFO Activated file as output plugin.
2016/07/18 12:13:18.334657 publish.go:288: INFO Publisher name: ip-172-44-44-0
2016/07/18 12:13:18.335017 async.go:78: INFO Flush Interval set to: -1ms
2016/07/18 12:13:18.335137 async.go:84: INFO Max Bulk Size set to: -1
2016/07/18 12:13:18.335257 beat.go:147: INFO Init Beat: filebeat; Version: 1.2.3
2016/07/18 12:13:18.335406 cfgfile.go:89: INFO Replacing config environment variable '${ENVIRONMENT_NAME}' with ''
                                                           [  OK  ]
[root@ip-172-44-44-0 filebeat]# ps auxf | grep filebeat
root      2567  0.0  0.3 110456  2096 pts/0    S+   12:13   0:00                          \_ grep --color=auto filebeat
root      2555  0.0  0.1   9400   644 pts/0    S    12:13   0:00 filebeat-god -r / -n -p /var/run/filebeat.pid -- /usr/bin/filebeat -c /etc/filebeat/filebeat.yml
root      2556  0.1  1.5 125804  9524 pts/0    Sl   12:13   0:00  \_ /usr/bin/filebeat -c /etc/filebeat/filebeat.yml

[root@ip-172-44-44-0 filebeat]# env | grep ENVIRONMENT_NAME
ENVIRONMENT_NAME=dev

@steffens Could you have a look at this?

filebeat tries to read environment variables via os.GetEnv. I suspect filebeat-god or init script to push an empty environment to filebeat. Can you try to add env to the filebeat init script?

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