# Ruby exception

**URL:** https://discuss.elastic.co/t/ruby-exception/176557
**Category:** Logstash
**Created:** [April 12, 2019, 7:29am UTC](https://discuss.elastic.co/t/ruby-exception/176557 "2019-04-12T07:29:03Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Abhilash\_B](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abhilash_b/32/40270_2.png) [@Abhilash\_B](https://discuss.elastic.co/u/Abhilash_B)
#### Post date: [April 12, 2019, 7:29am UTC](https://discuss.elastic.co/t/ruby-exception/176557/1 "2019-04-12T07:29:03Z")

</div>

Is there any issue with the below logstash configuration. I am trying to access the file path using event.get('path') and then split it. I get the following exception

[2019-04-12T07:19:25,192][ERROR][logstash.filters.ruby] Ruby exception occurred: undefined method `split' for nil:NilClass

```
 input{
   beats{
      port => 5046
   }
}

filter{
   if [message] =~ /(.*): (.*) - (.*)/ {
      mutate { strip => ["message"] }
   ruby {
        code => '
            msg = event.get("message")
            path = event.get("path")
            path = path.split("/")
            puts path
            site_id = path[-2]
            source_id = path[-3]
            matches = msg.scan(/(.*): (.*) - (.*)/)
            m = matches[0]
            event.set("test", m[1])
	        event.set("value", m[2])
            event.set("site_id", site_id)
            event.set("source_id", source)      
        '
       }
    }
 else{
  drop {}
 }
}
output {
  elasticsearch {
    hosts => ["localhost:9200"]
    index => "verra-prod-dgn-logs"
  }
  stdout { codec => rubydebug }
}

```

Any help is appreciated.

---

<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: [April 12, 2019, 12:22pm UTC](https://discuss.elastic.co/t/ruby-exception/176557/2 "2019-04-12T12:22:05Z")

</div>

That would occur if the events do not have a [path] field.

---

<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: [May 10, 2019, 12:36pm UTC](https://discuss.elastic.co/t/ruby-exception/176557/3 "2019-05-10T12:36:20Z")

</div>

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