Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Thanks, Yu

like image 911
Yu Watanabe Avatar asked Feb 17 '26 14:02

Yu Watanabe


2 Answers

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')
    "
  }
like image 70
Val Avatar answered Feb 19 '26 04:02

Val


For get the value from field name:

ruby {
 code => "
 value = (event.get('field_name'))
    "
}
like image 41
Vignesh Ammasi Avatar answered Feb 19 '26 02:02

Vignesh Ammasi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!