# Logstash error: Could not process event: no implicit conversion of NilClass into String

**URL:** https://discuss.elastic.co/t/logstash-error-could-not-process-event-no-implicit-conversion-of-nilclass-into-string/262056
**Category:** Logstash
**Created:** [January 25, 2021, 5:51am UTC](https://discuss.elastic.co/t/logstash-error-could-not-process-event-no-implicit-conversion-of-nilclass-into-string/262056 "2021-01-25T05:51:14Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Subhas\_Patil](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/subhas_patil/32/76864_2.png) [@Subhas\_Patil](https://discuss.elastic.co/u/Subhas_Patil)
#### Post date: [January 25, 2021, 5:51am UTC](https://discuss.elastic.co/t/logstash-error-could-not-process-event-no-implicit-conversion-of-nilclass-into-string/262056/1 "2021-01-25T05:51:14Z")

</div>

Iam getting the error  
`Could not process event: no implicit conversion of NilClass into String` in logstash ruby filter. Here is the ruby file which iam using in the logstash filter:

```
def filter(event)
    require 'json'
    require 'time'
    event_data_full = event.get('message')
    parsed = JSON.parse(event_data_full)
    created_key = parsed["created"]
    created = parsed["created"]
    job = parsed["job"]
    playbook = parsed["playbook"]
    event_keyword = parsed["event"]
    failed = parsed["failed"]
    uuid = parsed["uuid"]

    created = 'NO DATA' if created.nil?
    job = 'NO DATA' if job.nil?
    playbook = 'NO DATA' if playbook.nil?
    event_keyword = 'NO DATA' if event_keyword.nil?
    failed = 'NO DATA' if failed.nil?
    uuid = 'NO DATA' if uuid.nil?

    unreachable_if_exists = parsed["event_data"]["dark"]
    failures_if_exists = parsed["event_data"]["failures"]
    processed_if_exists = parsed["event_data"]["processed"]

    created_field_seconds = Time.parse(created_key).to_f * 1000

    unreachable = 0 if unreachable_if_exists.nil?
    failures = 0 if failures_if_exists.nil?
    processed = 0 if processed_if_exists.nil?
    if unreachable != 0
        unreachable = unreachable_if_exists.count
    end
    if failures !=0
            failures = failures_if_exists.count
    end
    if processed != 0
            processed = processed_if_exists.count
    end

    event.set('unreachable',unreachable.to_i)
    event.set('failures',failures.to_i)
    event.set('processed',processed.to_i)
    event.set('created_field_seconds',created_field_seconds.to_i)
    event.set('created',created.to_s)
    event.set('job',job.to_s)
    event.set('playbook',playbook.to_s)
    event.set('event_keyword',event_keyword.to_s)
    event.set('failed',failed.to_s)
    event.set('uuid',uuid.to_s)

    return [event]

end

```

Any help would be appreciated.

---

<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 22, 2021, 5:51am UTC](https://discuss.elastic.co/t/logstash-error-could-not-process-event-no-implicit-conversion-of-nilclass-into-string/262056/2 "2021-02-22T05:51:46Z")

</div>

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