# Logstash filter event.get() is hard to debug

**URL:** <https://discuss.elastic.co/t/logstash-filter-event-get-is-hard-to-debug/98662>\
**Category:** Logstash\
**Created:** [August 29, 2017, 10:07am UTC](https://discuss.elastic.co/t/logstash-filter-event-get-is-hard-to-debug/98662 "2017-08-29T10:07:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_ax](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@John\_ax](https://discuss.elastic.co/u/John_ax)\
**Post date:** [August 29, 2017, 10:07am UTC](https://discuss.elastic.co/t/logstash-filter-event-get-is-hard-to-debug/98662/1 "2017-08-29T10:07:35Z")

</div>

Hi, I am using logstash 5.1.1, got lots of ERROR logs, so I try this:

```bash
echo '{"msg":"xxxx", "@timestamp":"2017-08-28T08:16:54.943Z", "service":"x.y.z", "host":"ubuntu","timestamp":1503908214}' |
./logstash -e 'input { stdin { codec => json} } output { stdout { codec => rubydebug } } filter {ruby {
code => "event.set('timestamp', event.get('timestamp') * 1000) if event.get('timestamp') < 10000000000"
	}
	date {
	    match => ["timestamp", "UNIX_MS"]
	    add_field => { "[@metadata][index]" => "%{service}_%{[@metadata][index_day]}"}
	    remove_field => ["@timestamp","@version","source","file","offset","beat","topic","input_type","id"]
	}
}
'

```

but keep failing:

```auto
[2017-08-29T18:02:11,268][ERROR][logstash.filters.ruby] Ruby exception occurred: undefined local variable or method `timestamp' for #<LogStash::Filters::Ruby:0x506d34a3>
{
          "msg" => "xxxx",
      "service" => "x.y.z",
         "host" => "ubuntu",
    "timestamp" => 1503908214,
         "tags" => [
        [0] "_rubyexception"
    ]
}
[2017-08-29T18:02:14,196][WARN][logstash.agent] stopping pipeline {:id=>"main"}

```

the filter is so hard to debug, in Fact the filter config works fine in the realworld

---

<div class="post-metadata">

**Author:** ![John\_ax](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@John\_ax](https://discuss.elastic.co/u/John_ax)\
**Post date:** [August 29, 2017, 10:17am UTC](https://discuss.elastic.co/t/logstash-filter-event-get-is-hard-to-debug/98662/2 "2017-08-29T10:17:57Z")

</div>

sometime I got this:

```auto
[2017-08-29T18:17:23,336][ERROR][logstash.filters.ruby] Ruby exception occurred: undefined method `<' for nil:NilClass
[2017-08-29T18:17:23,587][ERROR][logstash.filters.ruby] Ruby exception occurred: undefined method `<' for nil:NilClass
[2017-08-29T18:17:24,155][ERROR][logstash.filters.ruby] Ruby exception occurred: undefined method `<' for nil:NilClass
[2017-08-29T18:17:24,233][ERROR][logstash.filters.ruby] Ruby exception occurred: undefined method `<' for nil:NilClass
[2017-08-29T18:17:24,326][ERROR][logstash.filters.ruby] Ruby exception occurred: undefined method `<' for nil:NilClass
[2017-08-29T18:17:24,925][ERROR][logstash.filters.ruby] Ruby exception occurred: undefined method `<' for nil:NilClass
[2017-08-29T18:17:25,078][ERROR][logstash.filters.ruby] Ruby exception occurred: undefined method `<' for nil:NilClass
[2017-08-29T18:17:25,706][ERROR][logstash.filters.ruby] Ruby exception occurred: undefined method `<' for nil:NilClass

```

still have no idea what happen.....

---

<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:** [August 29, 2017, 12:07pm UTC](https://discuss.elastic.co/t/logstash-filter-event-get-is-hard-to-debug/98662/3 "2017-08-29T12:07:02Z")

</div>

The first problem is caused by you having a single-quoted string inside your single quoted string:

```
logstash -e '... code => "event.set('timestamp', ...

```

Escaping the inner single quotes should work.

> Ruby exception occurred: undefined method `\<' for nil:NilClass

Given

```
if event.get('timestamp') < 10000000000

```

in your code I'd say the problem is that the event doesn't have a `timestamp` field (so the event.get() call returns nil).

---

<div class="post-metadata">

**Author:** ![John\_ax](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@John\_ax](https://discuss.elastic.co/u/John_ax)\
**Post date:** [August 30, 2017, 2:16am UTC](https://discuss.elastic.co/t/logstash-filter-event-get-is-hard-to-debug/98662/4 "2017-08-30T02:16:49Z")

</div>

thanks for the answer, I use a temp config file and work for me, with many thanks again.

```auto
echo '{"msg":"xxxx", "@timestamp":"2017-08-28T08:16:54.943Z", "service":"x.y.z", "host":"ubuntu","timestamp":1503908214}' | ./logstash -f temp.conf

```

---

<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:** [September 27, 2017, 2:17am UTC](https://discuss.elastic.co/t/logstash-filter-event-get-is-hard-to-debug/98662/5 "2017-09-27T02:17:00Z")

</div>

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