# Use variable in logstash config

**URL:** <https://discuss.elastic.co/t/use-variable-in-logstash-config/330092>\
**Category:** Logstash\
**Created:** [April 17, 2023, 5:11am UTC](https://discuss.elastic.co/t/use-variable-in-logstash-config/330092 "2023-04-17T05:11:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Indeed2000](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@Indeed2000](https://discuss.elastic.co/u/Indeed2000)\
**Post date:** [April 17, 2023, 5:11am UTC](https://discuss.elastic.co/t/use-variable-in-logstash-config/330092/1 "2023-04-17T05:11:56Z")

</div>

Hi  
I have logstash input like below, how can i set variable for "cpu" (it is name of table in database) and it has different values like "mem, disk,i/o,...".  
need to pass name of table as variable instead of define multi input. is it possible in logstash?

```auto
input {
  http_poller {
    urls => {
      test1 => {
        method => get
        url => "http://192.168.1.1:8086/query?pretty=true&q=SELECT+*+FROM+cpu%20WHERE%20time%20%3E%20now()%20-%201m&db=monitoringdb"
        headers => {
          Authorization => "Token "
        }
      }
    }
    schedule => { cron => "* * * * * GMT"}
    request_timeout => 60
    codec => "json"
    metadata_target => "http_poller_metadata"

  }
}

```

---

<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:** [April 17, 2023, 3:00pm UTC](https://discuss.elastic.co/t/use-variable-in-logstash-config/330092/2 "2023-04-17T15:00:08Z")

</div>

> [@Indeed2000](#):
>
> is it possible in logstash?

I believe you can reference an environment variable, but that requires a pipeline restart. You can also edit the configuration using a script and force a pipeline restart that way.

---

<div class="post-metadata">

**Author:** ![Indeed2000](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@Indeed2000](https://discuss.elastic.co/u/Indeed2000)\
**Post date:** [April 18, 2023, 6:20am UTC](https://discuss.elastic.co/t/use-variable-in-logstash-config/330092/3 "2023-04-18T06:20:52Z")

</div>

@Badger would you please tell me example?  
Thanks

---

<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:** [May 16, 2023, 6:21am UTC](https://discuss.elastic.co/t/use-variable-in-logstash-config/330092/4 "2023-05-16T06:21:08Z")

</div>

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