# Accessing environment variables in filebeat

**URL:** https://discuss.elastic.co/t/accessing-environment-variables-in-filebeat/55714
**Category:** Beats
**Tags:** filebeat
**Created:** [July 18, 2016, 2:16am UTC](https://discuss.elastic.co/t/accessing-environment-variables-in-filebeat/55714 "2016-07-18T02:16:51Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![snandam](https://avatars.discourse-cdn.com/v4/letter/s/96bed5/32.png) [@snandam](https://discuss.elastic.co/u/snandam)
#### Post date: [July 18, 2016, 2:16am UTC](https://discuss.elastic.co/t/accessing-environment-variables-in-filebeat/55714/1 "2016-07-18T02:16:51Z")

</div>

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.

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

```

service filebeat start

```auto
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 ''

```

```auto
$ env | grep ENVIRONMENT_NAME

ENVIRONMENT_NAME=dev

```

Any help is appreciated

---

<div class="post-metadata">

### Author: ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)
#### Post date: [July 18, 2016, 6:28am UTC](https://discuss.elastic.co/t/accessing-environment-variables-in-filebeat/55714/2 "2016-07-18T06:28:49Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![snandam](https://avatars.discourse-cdn.com/v4/letter/s/96bed5/32.png) [@snandam](https://discuss.elastic.co/u/snandam)
#### Post date: [July 18, 2016, 12:15pm UTC](https://discuss.elastic.co/t/accessing-environment-variables-in-filebeat/55714/3 "2016-07-18T12:15:45Z")

</div>

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

```auto
[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

```

---

<div class="post-metadata">

### Author: ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)
#### Post date: [July 20, 2016, 8:54am UTC](https://discuss.elastic.co/t/accessing-environment-variables-in-filebeat/55714/4 "2016-07-20T08:54:27Z")

</div>

@steffens Could you have a look at this?

---

<div class="post-metadata">

### Author: ![steffens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steffens/32/79630_2.png) [@steffens](https://discuss.elastic.co/u/steffens)
#### Post date: [July 20, 2016, 1:54pm UTC](https://discuss.elastic.co/t/accessing-environment-variables-in-filebeat/55714/5 "2016-07-20T13:54:31Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [August 8, 2016, 2:17am UTC](https://discuss.elastic.co/t/accessing-environment-variables-in-filebeat/55714/6 "2016-08-08T02:17:16Z")

</div>

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