# Add environment variables on filebeat start

**URL:** https://discuss.elastic.co/t/add-environment-variables-on-filebeat-start/152855
**Category:** Beats
**Tags:** filebeat
**Created:** [October 17, 2018, 1:58pm UTC](https://discuss.elastic.co/t/add-environment-variables-on-filebeat-start/152855 "2018-10-17T13:58:00Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![leslie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leslie/32/77605_2.png) [@leslie](https://discuss.elastic.co/u/leslie)
#### Post date: [October 17, 2018, 1:58pm UTC](https://discuss.elastic.co/t/add-environment-variables-on-filebeat-start/152855/1 "2018-10-17T13:58:00Z")

</div>

i am using filebeat 6.0.0 which without **add\_host\_metadata** processor; and my os is Windows.

now i hope to add an IP field to the filebeat result of all modules, but i `don't` want to set an Environment Variable globally. Do I have any other way to do that?

i am trying start filebeat with `filebeat.exe -E "IP=192.0.0.100"`, and modules config files like

```
type: log
paths:
{{ range $i, $path := .paths }}
 - {{$path}}
{{ end }}
fields:
  ip: "${IP}"

```

Then the filebeat starts failed. Can I set new environment variables with `-E` argument ?  
PS. I have many servers to run filebeat, so i prefer to set the same configuration files on different servers.

---

<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: [October 18, 2018, 8:53pm UTC](https://discuss.elastic.co/t/add-environment-variables-on-filebeat-start/152855/2 "2018-10-18T20:53:34Z")

</div>

Can you update filebeat to 6.4.2 with add\_host\_metadata?

What is the error message you get?

Do you want the IP for some special modules/inputs only? Or do you want it with every event?

---

<div class="post-metadata">

### Author: ![leslie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leslie/32/77605_2.png) [@leslie](https://discuss.elastic.co/u/leslie)
#### Post date: [October 19, 2018, 5:32am UTC](https://discuss.elastic.co/t/add-environment-variables-on-filebeat-start/152855/3 "2018-10-19T05:32:15Z")

</div>

I met the same problem as [Filebeat Windows | Time sync](https://discuss.elastic.co/t/filebeat-windows-time-sync/121513/5) using filebeat 6.4.2, so i downgrade to 6.0.0 .

the error is

```
2018-10-19T13:28:54+08:00 CRIT Exiting: missing field accessing 'fields.ip'

```

I want IP for some modules,however adding IP for every event is ok.

---

<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: [October 19, 2018, 12:40pm UTC](https://discuss.elastic.co/t/add-environment-variables-on-filebeat-start/152855/4 "2018-10-19T12:40:28Z")

</div>

This looks like modules do not pick up env variables up correctly. Can you try to add the setting globally in your `filebeat.yml`?

---

<div class="post-metadata">

### Author: ![leslie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leslie/32/77605_2.png) [@leslie](https://discuss.elastic.co/u/leslie)
#### Post date: [October 22, 2018, 6:30am UTC](https://discuss.elastic.co/t/add-environment-variables-on-filebeat-start/152855/5 "2018-10-22T06:30:55Z")

</div>

Yes, When the below config is setted in `filebeat.yml`, it works to every event. but when it is in module config file, it failed.

```
fields.ip: "${IP}"

```

I have tried using `-M "*.*.prospector.fields.ip=$ip"` to start filebeat. this way is worked only if I set modules in `filebeat.yml`, just like:

```
filebeat.modules:
 - module: customize
   adv-iis-access:
     enabled: true

```

When I use external config file, like:

```
filebeat.config.modules:
 path: ${path.config}/modules.d/*.yml

```

`-M` setting dose not add a new field to the event.

---

<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: [October 22, 2018, 2:53pm UTC](https://discuss.elastic.co/t/add-environment-variables-on-filebeat-start/152855/6 "2018-10-22T14:53:11Z")

</div>

This clearly looks like a bug. No idea if this is resolved in 6.4. Can you check with 6.4.2 and open an [bug report](https://github.com/elastic/beats/issues) if you can reproduce your findings with 6.4?

---

<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: [November 19, 2018, 2:53pm UTC](https://discuss.elastic.co/t/add-environment-variables-on-filebeat-start/152855/7 "2018-11-19T14:53:13Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
