Andrew22
(Andrew)
September 9, 2019, 6:35pm
1
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
Badger
September 9, 2019, 7:00pm
2
You need to use event API -- event.get and event.set.
1 Like
Andrew22
(Andrew)
September 9, 2019, 7:12pm
3
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
system
(system)
Closed
October 7, 2019, 7:12pm
4
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.