Ruby exception

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.

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

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