# Http\_poller run ruby script and use some vars in the header

**URL:** https://discuss.elastic.co/t/http-poller-run-ruby-script-and-use-some-vars-in-the-header/164818
**Category:** Logstash
**Created:** [January 18, 2019, 3:22pm UTC](https://discuss.elastic.co/t/http-poller-run-ruby-script-and-use-some-vars-in-the-header/164818 "2019-01-18T15:22:43Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jehogo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jehogo/32/39946_2.png) [@jehogo](https://discuss.elastic.co/u/jehogo)
#### Post date: [January 18, 2019, 3:22pm UTC](https://discuss.elastic.co/t/http-poller-run-ruby-script-and-use-some-vars-in-the-header/164818/1 "2019-01-18T15:22:43Z")

</div>

I want to retrieve logs from a server using http\_poller plugin but I need to set some vars in the header request. Then, I need to execute the ruby code and use the vars in the input of conf file

```
**api_key** = '27c59....beb28'
api_secret = '15db2.....b682ec'
**data** = 'thedata'
**timestamp** = DateTime.now.strftime('%s')
text_to_hash = api_key << data << String(timestamp)
digest = OpenSSL::Digest.new('SHA256')
**hash** = OpenSSL::HMAC.hexdigest(digest, api_secret, text_to_hash)

```

conf File

```
input {
    http_poller {
        urls => {
          api2 => {
            url => "the_endpoint"
            method => post
            headers => {
              "Content-Type" => "application/json"
              "x-ltd-apikey" => < **api_key** >
              "x-ltd-sign" => < **hash** >
              "x-ltd-timestamp" => < **timestamp** >
            }
            body => < **data** >
          }
        }
        schedule => {
          "in" => "1s"
        }
      }
}

```

Do you have some idea?

---

<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: [January 18, 2019, 3:34pm UTC](https://discuss.elastic.co/t/http-poller-run-ruby-script-and-use-some-vars-in-the-header/164818/2 "2019-01-18T15:34:22Z")

</div>

I am not aware of any way to run ruby (essentially a filter) before running an input.

If you need to do something in ruby to build the apikey and signed data then you would have to implement the POST in the ruby filter too. You could probably still use the http\_poller just for the scheduling, or perhaps replace it with a heartbeat input.

---

<div class="post-metadata">

### Author: ![jehogo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jehogo/32/39946_2.png) [@jehogo](https://discuss.elastic.co/u/jehogo)
#### Post date: [January 18, 2019, 3:55pm UTC](https://discuss.elastic.co/t/http-poller-run-ruby-script-and-use-some-vars-in-the-header/164818/3 "2019-01-18T15:55:34Z")

</div>

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: [February 15, 2019, 3:55pm UTC](https://discuss.elastic.co/t/http-poller-run-ruby-script-and-use-some-vars-in-the-header/164818/4 "2019-02-15T15:55:45Z")

</div>

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