# If else ruby check for nil

**URL:** <https://discuss.elastic.co/t/if-else-ruby-check-for-nil/222681>\
**Category:** Logstash\
**Created:** [March 9, 2020, 10:18am UTC](https://discuss.elastic.co/t/if-else-ruby-check-for-nil/222681 "2020-03-09T10:18:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![samiujan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/samiujan/32/23605_2.png) [@samiujan](https://discuss.elastic.co/u/samiujan)\
**Post date:** [March 9, 2020, 10:18am UTC](https://discuss.elastic.co/t/if-else-ruby-check-for-nil/222681/1 "2020-03-09T10:18:06Z")

</div>

Hi

I am using a ruby codeblock to add values from redis for specific cases - I am getting some null values and want to log those - but this check for null values and isn't working, I get a complication error - looking at the docs, I am assuming this is valid ruby:

```
 key = event.get('apikey')
 if key == nil
       puts event.to_hash
 else
       endpoint = event.get('uripath')
 end 

```

Here is the concatenated error:

`Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:main, :exception=>"LogStash::ConfigurationError", :message=>"Expected one of [\\t\\r\\n], \"#\", \"{\", \"}\" at line 66, column 19 (byte 2197) after filter {\r\n grok {\r\n match => { \"message\" => '%{SYSLOGTIMESTAMP:syslogtimestamp} %{DATA:Aloha_name} %{DATA:Haproxy_process}: %{DATA:client_ip}:%{INT:client_port} \\[%{HAPROXYDATE:accept_date}\\] %{NOTSPACE:frontend_name} %{NOTSPACE:backend_name}/%{NOTSPACE:server_name} %{INT:Tq}/%{INT:Tw}/%{INT:Tc}/%{INT:Tr}/%{INT:Tt} %{INT:http_status_code} %{NOTSPACE:bytes_read} - - ----`

---

<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:** [March 9, 2020, 12:17pm UTC](https://discuss.elastic.co/t/if-else-ruby-check-for-nil/222681/2 "2020-03-09T12:17:55Z")

</div>

I see no reason to think the ruby filter has anything to do with this. What does your configuration look like?

---

<div class="post-metadata">

**Author:** ![samiujan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/samiujan/32/23605_2.png) [@samiujan](https://discuss.elastic.co/u/samiujan)\
**Post date:** [March 10, 2020, 9:51am UTC](https://discuss.elastic.co/t/if-else-ruby-check-for-nil/222681/3 "2020-03-10T09:51:51Z")

</div>

You are right - I am not sure what it was eventually but I started with a clean file and built up the code... 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:** [April 7, 2020, 9:51am UTC](https://discuss.elastic.co/t/if-else-ruby-check-for-nil/222681/4 "2020-04-07T09:51:57Z")

</div>

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