# HTTP\_POLLER Plugin for Logstash

**URL:** <https://discuss.elastic.co/t/http-poller-plugin-for-logstash/110498>\
**Category:** Logstash\
**Created:** [December 6, 2017, 10:43am UTC](https://discuss.elastic.co/t/http-poller-plugin-for-logstash/110498 "2017-12-06T10:43:39Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![Rym\_Guerbi\_Michaut](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rym_guerbi_michaut/32/25496_2.png) [@Rym\_Guerbi\_Michaut](https://discuss.elastic.co/u/Rym_Guerbi_Michaut)\
**Post date:** [January 2, 2018, 12:54pm UTC](https://discuss.elastic.co/t/http-poller-plugin-for-logstash/110498/21 "2018-01-02T12:54:31Z")

</div>

Hi magnusbaeck,

I've tried to put the code you gave me, but still don't work.

```auto
input {
 http_poller {
    urls => {
        jira => {
        method => get
        user => " "
        password => " "
        url => "my_url"
        headers => {
        Accept => "application/json"
        }
     }
    }
	request_timeout => 60
	schedule => { cron => "*/01 * * * * UTC"}
	metadata_target => "http_poller_metadata"
  }
}

filter {
	  ruby{
	    code => 
		userlist = []
		event.get('users').each { |k, v|
  		userlist << {"name" => k, "weeks" => v}
		}
		event.set('users', userlist)
	  }
	}
}
output {
   	elasticsearch {
	hosts => ["localhost:9200"] 
	index => "json_10meilleurs_logs_2"
	user => "elastic"
	password => "changeme"	
	}
}

```

I've tried with the following code and I get a one single document but can't read it in kibana.

```auto
input {
 http_poller {
    urls => {
        jira => {
        method => get
        user => " "
        password => " "
        url => "my_url"
        headers => {
        Accept => "application/json"
        }
     }
    }
	request_timeout => 60
	schedule => { cron => "*/01 * * * * UTC"}
	metadata_target => "http_poller_metadata"
  }
}

filter {

	json{
		source => "message"
		}
}
output {
   	elasticsearch {
	hosts => ["localhost:9200"] 
	index => "json_10meilleurs_logs"
	user => "elastic"
	password => "changeme"	
	}
}

```

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [January 3, 2018, 9:36am UTC](https://discuss.elastic.co/t/http-poller-plugin-for-logstash/110498/22 "2018-01-03T09:36:08Z")

</div>

The Ruby code needs to be surrounded by quotes (in this case double quotes). Compare what you have against examples in e.g. the documentation and it should be obvious what to do.

---

<div class="post-metadata">

**Author:** ![Rym\_Guerbi\_Michaut](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rym_guerbi_michaut/32/25496_2.png) [@Rym\_Guerbi\_Michaut](https://discuss.elastic.co/u/Rym_Guerbi_Michaut)\
**Post date:** [January 3, 2018, 9:38am UTC](https://discuss.elastic.co/t/http-poller-plugin-for-logstash/110498/23 "2018-01-03T09:38:05Z")

</div>

Hi, have done it too, have done some changes on it since yesterday according to the errors got and finished with this code:

```auto
filter {
	  ruby{
	   	code => " 
			userlist = [],
			event.get('users').each { |k, v|, 
			userlist.concat(["name" => k, "weeks" => v])
			}
			event.set('users', userlist) "
	  }
}

```

But still doesn't work ☹

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [January 3, 2018, 9:41am UTC](https://discuss.elastic.co/t/http-poller-plugin-for-logstash/110498/24 "2018-01-03T09:41:41Z")

</div>

Oh. You can't have double quotes _in_ the Ruby code if you surround the whole code block with double quotes. Just use single quotes throughout the code.

---

<div class="post-metadata">

**Author:** ![Rym\_Guerbi\_Michaut](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rym_guerbi_michaut/32/25496_2.png) [@Rym\_Guerbi\_Michaut](https://discuss.elastic.co/u/Rym_Guerbi_Michaut)\
**Post date:** [January 3, 2018, 9:46am UTC](https://discuss.elastic.co/t/http-poller-plugin-for-logstash/110498/25 "2018-01-03T09:46:53Z")

</div>

ok

corrected with:

```auto
filter {
	  ruby{
	   	code => " 
			userlist = [],
			event.get('users').each { |k, v|, 
			userlist.concat(['name' => k, 'weeks' => v])
			}
			event.set('users', userlist) "
	  }
}

```

and got a syntax error:

```auto
SyntaxError: (ruby filter code):3: syntax error, unexpected ','
			event.get('users').each { |k, v|, 
                       ^

```

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [January 3, 2018, 7:08pm UTC](https://discuss.elastic.co/t/http-poller-plugin-for-logstash/110498/26 "2018-01-03T19:08:36Z")

</div>

Don't end the lines with commas.

---

<div class="post-metadata">

**Author:** ![Rym\_Guerbi\_Michaut](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rym_guerbi_michaut/32/25496_2.png) [@Rym\_Guerbi\_Michaut](https://discuss.elastic.co/u/Rym_Guerbi_Michaut)\
**Post date:** [January 24, 2018, 10:50am UTC](https://discuss.elastic.co/t/http-poller-plugin-for-logstash/110498/27 "2018-01-24T10:50:21Z")

</div>

Hello,  
Here I am again, still cannot solve the problem.  
Have taken off the commas at the end of the lines. So get this filter code:

```auto
filter {
	  ruby{
	   	code => " 
			userlist = []
			event.get('users').each { |k, v| 
			userlist.concat(['name' => k, 'weeks' => v])
			}
			event.set('users', userlist) "
	  }
}

```

And I get thir error:

 ![ruby_code](https://us1.discourse-cdn.com/elastic/original/3X/a/1/a13e6be5ed5d98b3d88f037a1e018789ce970c17.png)

By the way, by reading back our exchanges, I'd like to change a small thing. There's no "users" field. It starts directly by the name of the users.  
So the structure of the document is more like:

```auto
{
    "user1": {
      "6": { ... },
      "5": { ... },
      ...
      "1": { ... },
    },
    "user2": {
      "6": { ... },
      "5": { ... },
      ...
      "1": { ... },
    },
    ...
    "user2": {
      "6": { ... },
      "5": { ... },
      ...
      "1": { ... },
    },
}

```

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [January 26, 2018, 2:52pm UTC](https://discuss.elastic.co/t/http-poller-plugin-for-logstash/110498/28 "2018-01-26T14:52:02Z")

</div>

Please don't post screenshots if you can copy/paste plain text.

The error message means that `event.get('users')` returned nil, which in turn means that the event had no `users` field.

---

<div class="post-metadata">

**Author:** ![Rym\_Guerbi\_Michaut](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rym_guerbi_michaut/32/25496_2.png) [@Rym\_Guerbi\_Michaut](https://discuss.elastic.co/u/Rym_Guerbi_Michaut)\
**Post date:** [January 26, 2018, 3:09pm UTC](https://discuss.elastic.co/t/http-poller-plugin-for-logstash/110498/29 "2018-01-26T15:09:57Z")

</div>

> [@magnusbaeck](#):
>
> Please don't post screenshots if you can copy/paste plain text.

Ok, got it 🙂

> [@magnusbaeck](#):
>
> The error message means that `event.get('users')` returned nil, which in turn means that the event had no `users` field.

Ok  
So, could you please tell me where can I find the documentation about the pattern of an event ?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [January 28, 2018, 9:38pm UTC](https://discuss.elastic.co/t/http-poller-plugin-for-logstash/110498/30 "2018-01-28T21:38:36Z")

</div>

> So, could you please tell me where can I find the documentation about the pattern of an event ?

I don't think I understand the question, but the event API is documented here: [Event API | Logstash Reference [8.11] | Elastic](https://www.elastic.co/guide/en/logstash/current/event-api.html)

---

<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 25, 2018, 9:39pm UTC](https://discuss.elastic.co/t/http-poller-plugin-for-logstash/110498/31 "2018-02-25T21:39:48Z")

</div>

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

[Previous page](https://discuss.elastic.co/t/http-poller-plugin-for-logstash/110498.md?page=1)
