# Is there a way to alter the value of live API data polled using http\_poller input plugin?

**URL:** https://discuss.elastic.co/t/is-there-a-way-to-alter-the-value-of-live-api-data-polled-using-http-poller-input-plugin/142671
**Category:** Logstash
**Created:** [August 2, 2018, 3:21am UTC](https://discuss.elastic.co/t/is-there-a-way-to-alter-the-value-of-live-api-data-polled-using-http-poller-input-plugin/142671 "2018-08-02T03:21:04Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![APJ](https://avatars.discourse-cdn.com/v4/letter/a/b5ac83/32.png) [@APJ](https://discuss.elastic.co/u/APJ)
#### Post date: [August 2, 2018, 3:21am UTC](https://discuss.elastic.co/t/is-there-a-way-to-alter-the-value-of-live-api-data-polled-using-http-poller-input-plugin/142671/1 "2018-08-02T03:21:05Z")

</div>

Hi all,

I have a logstash config file that pulls in live data using the http\_poller plugin. Here is my logstash.conf

```
input {
  http_poller {
    urls => {
        weather => {
            url => "http://api.openweathermap.org/data/2.5/weather?id=5490223&appid="MY_APP_ID"&units=metric"
            headers => {
              Accept => "application/json"
            }
        }
    }
    schedule => { cron => "* * * * * *" }
    codec => json
  }
}
filter {
  mutate {
    remove_field => ["@version" ,"command" ,"host" ,"cod" ,"id" ,"base" ,"coord" ,"sys" ,"dt"]
  }
  split { field => "weather" }
}
output {
  elasticsearch {
    hosts => ["localhost:9200"]
    index => "weather"
  }
  stdout {
    codec => rubydebug
  }
}

```

I want to modify the data retrieved from openweathermap every 30 seconds before sending it into elasticsearch. Is there a way to do it?

I would really appreciate if someone could help me out. Thanks!

---

<div class="post-metadata">

### Author: ![NerdSec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nerdsec/32/22056_2.png) [@NerdSec](https://discuss.elastic.co/u/NerdSec)
#### Post date: [August 2, 2018, 4:13am UTC](https://discuss.elastic.co/t/is-there-a-way-to-alter-the-value-of-live-api-data-polled-using-http-poller-input-plugin/142671/2 "2018-08-02T04:13:54Z")

</div>

> [@APJ](#):
>
> I want to modify the data retrieved from openweathermap every 30 seconds before sending it into elasticsearch. Is there a way to do it?

What do you mean by modify? Could you give an example?

---

<div class="post-metadata">

### Author: ![APJ](https://avatars.discourse-cdn.com/v4/letter/a/b5ac83/32.png) [@APJ](https://discuss.elastic.co/u/APJ)
#### Post date: [August 2, 2018, 4:50am UTC](https://discuss.elastic.co/t/is-there-a-way-to-alter-the-value-of-live-api-data-polled-using-http-poller-input-plugin/142671/3 "2018-08-02T04:50:18Z")

</div>

Hi NerdSec,

The `http://api.openweathermap.org/data/2.5/weather?id=5490223&appid="MY_APP_ID"&units=metric` API gives me a lot of data (fields), like temperature, humdity, pressure, etc.

 ![Capture](https://us1.discourse-cdn.com/elastic/original/3X/e/0/e01d22206b78d5217b23532bd8cd32caffcee6e4.PNG)

For instance, I want to alter the actual temperature value polled in by logstash, and then send that value to elasticsearch.

Let's assume the main.temp is 20ºF. Now, I want logstash to make it 30ºF and send that data to elasticsearch

So, I'd like to know if there is a way to do this. Please help me out here.

---

<div class="post-metadata">

### Author: ![NerdSec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nerdsec/32/22056_2.png) [@NerdSec](https://discuss.elastic.co/u/NerdSec)
#### Post date: [August 2, 2018, 5:27am UTC](https://discuss.elastic.co/t/is-there-a-way-to-alter-the-value-of-live-api-data-polled-using-http-poller-input-plugin/142671/4 "2018-08-02T05:27:59Z")

</div>

Hi,

You can do arithmetic operations using the ruby filter. Here are some links.

> **[Event API | Logstash Reference \[8.11\] | Elastic](https://www.elastic.co/guide/en/logstash/current/event-api.html)**

> [@Doing mathematical ops using logstash filters](https://discuss.elastic.co/t/doing-mathematical-ops-using-logstash-filters/30058/2):
>
> if 'time\_duration' \< '500' { mutate { add\_tag =\> ["FAST"] } Two problems: Fields are referred via the square bracket notation, i.e. [time\_duration] in this case. You need fields to be integers (or doubles) for numerical comparisons to work. See below. I am using haproxy config, which I don't think I need to print here. But for reference, the bytes\_read and the time\_duration are INT types. No, they're strings. That's obvious from the stdout output. The fact that a grok expression use…

> [@Math operations with ruby](https://discuss.elastic.co/t/math-operations-with-ruby/55140):
>
> I want to multiply or divide two fields and create a new field based on that. I've got this ruby code: ruby { code =\> "event['hit\_rate'] = event['MAIN\_client\_req'] \* event['MAIN\_cache\_hit']" } When I try to use it I'm getting: Ruby exception occurred: undefined method `\*' for nil:NilClass {:level=\>:error} Ruby exception occurred: NilClass can't be coerced into Fixnum {:level=\>:error} This is a part of my logstash config: grok { match =\> { "message" =\> "(?\<par…

> <https://stackoverflow.com/questions/38069675/math-functions-in-logstash>

Regards,  
NerdSec

---

<div class="post-metadata">

### Author: ![APJ](https://avatars.discourse-cdn.com/v4/letter/a/b5ac83/32.png) [@APJ](https://discuss.elastic.co/u/APJ)
#### Post date: [August 2, 2018, 7:02am UTC](https://discuss.elastic.co/t/is-there-a-way-to-alter-the-value-of-live-api-data-polled-using-http-poller-input-plugin/142671/5 "2018-08-02T07:02:31Z")

</div>

Thanks a lot NerdSec!

My goal is to perform addition operation on `main.temp` value (main.temp = main.temp + 10) every 30 seconds. Elasticsearch is something new to me. So I would be grateful if you could let me know what exactly needs to be added or changed in the logstash.conf.

Regards,  
APJ

---

<div class="post-metadata">

### Author: ![NerdSec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nerdsec/32/22056_2.png) [@NerdSec](https://discuss.elastic.co/u/NerdSec)
#### Post date: [August 2, 2018, 5:57pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-alter-the-value-of-live-api-data-polled-using-http-poller-input-plugin/142671/6 "2018-08-02T17:57:19Z")

</div>

I am not sure how to do it for every 30 sec. As far as I am aware, the said filter will run for every event, irrespective of time.

---

<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: [August 30, 2018, 5:57pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-alter-the-value-of-live-api-data-polled-using-http-poller-input-plugin/142671/7 "2018-08-30T17:57:20Z")

</div>

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