[SOLVED] [logstash 2.3] ruby error using event.get

Hello,

I try to do a substraction on a float number and i'm facing this issue:

# echo '{"ts":"123124.094", "rq":"0.020"}' | \
    /opt/logstash/bin/logstash -e \
    "input { 
        stdin { codec => json }
    } output {
        stdout { codec => rubydebug }
    } filter { 
        ruby { code => \"event.set('total', event.get('ts') - event.get('rq'))\"  }
    }"

Settings: Default pipeline workers: 4
Pipeline main started
Ruby exception occurred: undefined method `get' for #<LogStash::Event:0x60e932d7> {:level=>:error}
{
            "ts" => "123124.094",
            "rq" => "0.020",
      "@version" => "1",
    "@timestamp" => "2017-12-15T17:00:31.650Z",
          "host" => "es-traces.novalocal",
          "tags" => [
        [0] "_rubyexception"
    ]
}
Pipeline main has been shutdown
stopping pipeline {:id=>"main"}

I could not find the event.(get|set) description in the logstash 2.3 documentation, so maybe it is not handled in this version.
Upgrading logstash is not an option for me unfortunately.

Can you share how to achieve that kind of substraction?

Thank you

In Logstash 2.3 you can access the event fields directly (both read and write) like you would access the key in a normal Ruby hash, i.e. event['fieldname'].

Thank you

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