# Making Logstash configurations dynamic

**URL:** <https://discuss.elastic.co/t/making-logstash-configurations-dynamic/274095>\
**Category:** Logstash\
**Created:** [May 26, 2021, 4:29pm UTC](https://discuss.elastic.co/t/making-logstash-configurations-dynamic/274095 "2021-05-26T16:29:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![usman1](https://avatars.discourse-cdn.com/v4/letter/u/c67d28/32.png) [@usman1](https://discuss.elastic.co/u/usman1)\
**Post date:** [May 26, 2021, 4:29pm UTC](https://discuss.elastic.co/t/making-logstash-configurations-dynamic/274095/1 "2021-05-26T16:29:01Z")

</div>

Is there a way to make Logstash configuration file dynamic by reading attribute names and types from a different text file (or any other input mechanism).

To explain, if my logstash configuration file looks something like this:

```auto
if[@metadata][f] == "SCALE" {
    csv {
      separator => ","
      columns => ["TIMESTAMP",	"Machine_ID", "FLAG",	"Batch_ID",	"Scale",	"Op_Name",	"Set_Point", "Avg_Wght", "PPM",	"T1PPM"]
    }
    mutate { add_field => { "[@metadata][target_index]" => "dev-mw-1" } }
  }

```

The column names in this configuration are hard coded and each of the field is converted into its respective type using `mutate`.

Can I take these column names and their data type from some other input source (e.g. a text file), save them into a variable and use that variable? So that whenever Logstash is run, it takes fresh attribute from input and changes the configurations accordingly?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [May 26, 2021, 5:31pm UTC](https://discuss.elastic.co/t/making-logstash-configurations-dynamic/274095/2 "2021-05-26T17:31:34Z")

</div>

The logstash configuration can [reference environment variables](https://www.elastic.co/guide/en/logstash/current/environment-variables.html). However, it does not work everywhere. Suppose we have

```
COL1=foo
COL2=bar
COL1TYPE=integer
COL2TYPE=integer

```

Then the configuration

```
input { generator { count => 1 lines => ['123,456'] } }
filter {
    csv { columns => ["${COL1}", "${COL2}"] }
    mutate { convert => { "${COL1}" => "${COL1TYPE}" } }
    mutate { convert => { "bar" => "${COL2TYPE}" } }
}
output { stdout { codec => rubydebug { metadata => false } } }

```

will result in

```
       "bar" => 456,
       "foo" => "123",

```

Note that bar is an integer, but foo is not. The left side of the convert is not substituted. Also a string that looks like an array will be interpreted as a string, not an array. So you cannot do

```
COLUMNS=foo, bar

```

and then use it like this

```
csv { columns => [${COLUMNS}] }
```

---

<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:** [June 23, 2021, 5:32pm UTC](https://discuss.elastic.co/t/making-logstash-configurations-dynamic/274095/3 "2021-06-23T17:32:17Z")

</div>

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