Yu Watanabe Yu Watanabe - 1 year ago 276
Ruby Question

Ruby code in logstash failing with _rubyexception

I would like to get help with the code in ruby filter.

logstash version is 5.0.0 alpha4.

I am testing the code in ruby filter as below but I am getting _rubyexception.

ruby {
code => "
event['newfield'] = 'test'

ruby filter is defined inside filter { }.
The logstash.log shows as below,

:timestamp=>"2016-08-03T15:26:47.291000+0900", :message=>"Ruby exception occurred: undefined method[]=' for 2016-08-03T06:26:46.829Z test %{message}:LogStash::Event", :level=>:error}

I cant find the reason why ruby filter is unable to use event object.
I appreciate if I could get some help to cope this issue.


Val Val
Answer Source

There is a new event API in Logstash 5.0.0 and now you need to set fields on the event as follows:

  ruby {
    code => "
      event.set('newfield', 'test')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download