Multiply and adding fields in logstsh

Hello,

I am trying to convert three separate fields for hour minute and second to one in seconds so I have dome some research and found

             if [hour] and [minute] and [second] {
        ruby {
              code => "event['duration_in_seconds'] = event['hour'].to_i * 3600 + event['minute'].to_i   * 60 + event['second']"
           }
      }

but when I run logstash I get the error

[ERROR][logstash.filters.ruby ] Ruby exception occurred: undefined method `[ ]' for #<LogStash::Event:

any help would be appreciated

You need to use event API -- event.get and event.set.

1 Like

That helped a lot thank you!

My solution for anyone who cares.

       if [hour] and [minute] and [second] {
        ruby {
              code => "event.set('duration_in_seconds' , ((event.get('hour').to_f * 3600) + (event.get('minute').to_f * 60) + event.get('second').to_f))"
           }
      }
1 Like

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