# Use variables (possibly set by Ruby) in Input

**URL:** <https://discuss.elastic.co/t/use-variables-possibly-set-by-ruby-in-input/202420>\
**Category:** Logstash\
**Created:** [October 5, 2019, 9:13am UTC](https://discuss.elastic.co/t/use-variables-possibly-set-by-ruby-in-input/202420 "2019-10-05T09:13:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohamad\_Rahim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mohamad_rahim/32/55437_2.png) [@Mohamad\_Rahim](https://discuss.elastic.co/u/Mohamad_Rahim)\
**Post date:** [October 5, 2019, 9:13am UTC](https://discuss.elastic.co/t/use-variables-possibly-set-by-ruby-in-input/202420/1 "2019-10-05T09:13:27Z")

</div>

Hello all,

So I'm using the http\_poller plugin to poll events off one of our SaaS subscriptions.  
The problem is that I need to specify the "From Date" and "To Date" statically.  
My question is how can I generate a variable for those dates, for example $fromDate=now()-5Minutes and $toDate=now() , then use them in the request?

I know I can use Ruby code plugin in the filter section, but how to do so in the Input section and how to set the output of the code to a variable?

Currently, my input is something like this:

input {  
http\_poller{  
urls =\> {  
fusion =\> {  
method =\> post  
url =\> "[https://example.somecloud.com/api/audittrail/getaudithistory](https://example.somecloud.com/api/audittrail/getaudithistory)"   
verify\_cert =\> false  
headers =\> {  
"Content-Type" =\> "application/json"  
}  
auth =\> {  
user =\> "user"  
password =\> "password"  
}  
body =\> '{ "fromDate": "2018-09-1 17:06:40","toDate": "2018-09-2 17:06:50"}'  
}  
}  
schedule =\> { every =\> "30s" }  
codec =\> "json"  
}

}

If variables are available, the "body" would look like this:

body =\> '{ "fromDate": $nowMinusFiveMinutes,"toDate": $now}'

Any help would be much appreciated!

---

<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:** [October 5, 2019, 1:00pm UTC](https://discuss.elastic.co/t/use-variables-possibly-set-by-ruby-in-input/202420/2 "2019-10-05T13:00:31Z")

</div>

You cannot do it using a ruby filter. You might be able to do it by setting [environment variables](https://www.elastic.co/guide/en/logstash/current/environment-variables.html) externally to logstash, but those would not change with time whilst logstash runs.

---

<div class="post-metadata">

**Author:** ![Mohamad\_Rahim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mohamad_rahim/32/55437_2.png) [@Mohamad\_Rahim](https://discuss.elastic.co/u/Mohamad_Rahim)\
**Post date:** [October 5, 2019, 2:29pm UTC](https://discuss.elastic.co/t/use-variables-possibly-set-by-ruby-in-input/202420/3 "2019-10-05T14:29:36Z")

</div>

I see.  
So how others are tackling this problem? As most REST calls includes some sort of date filtering parameters.

---

<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:** [October 5, 2019, 3:44pm UTC](https://discuss.elastic.co/t/use-variables-possibly-set-by-ruby-in-input/202420/4 "2019-10-05T15:44:01Z")

</div>

Use a generator input to trigger dummy events, then use an http filter to make the REST call.

---

<div class="post-metadata">

**Author:** ![Mohamad\_Rahim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mohamad_rahim/32/55437_2.png) [@Mohamad\_Rahim](https://discuss.elastic.co/u/Mohamad_Rahim)\
**Post date:** [October 5, 2019, 4:59pm UTC](https://discuss.elastic.co/t/use-variables-possibly-set-by-ruby-in-input/202420/5 "2019-10-05T16:59:02Z")

</div>

Oh, that is a pickle!  
I will try it as a last resort, thanks!

@magnusbaeck Any ideas?

---

<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 2, 2019, 4:59pm UTC](https://discuss.elastic.co/t/use-variables-possibly-set-by-ruby-in-input/202420/6 "2019-11-02T16:59:13Z")

</div>

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