yahoo
November 28, 2017, 5:39pm
1
I am trying to convert a time duration into float.
The error message:
Ruby exception occurred: undefined method `/' for 2017-01-01T05:00:00.000Z:LogStash::Timestamp
{
"voice_duration" => "00:00:00",
"voice_durationd" => 2017-01-01T05:00:00.000Z,
}
The Logstash config:
date {
match => ["[voice_duration]", "HH:mm:ss"]
target => "[voice_durationd]"
timezone => "%{mytimezone}"
}
ruby { code => "event.set('duration', (event.get('voice_durationd') / 60 ))" }
Durations can be converted to different units by division or multiplication but a timestamp can't. voice_durationd
is clearly a timestamp.
What are you trying to do here?
yahoo
November 28, 2017, 9:01pm
3
I am trying to convert a time duration into float.
The input data is in the form HH:mm:ss.
yahoo
November 29, 2017, 3:35am
4
My solution:
# convert duration from hour:min:second 00:00:00 into a float of minutes
csv {
# hour:min:second
columns => [ "hours", "minutes", "seconds"]
source => "voice_duration"
separator => ":"
}
ruby {
code => "event.set('duration', ( (event.get('hours').to_f * 60) + event.get('minutes').to_f + (event.get('seconds').to_f / 60 )))"
}
mutate {
remove_field => [ "voice_duration", "hours", "minutes", "seconds"]
}
1 Like
system
(system)
Closed
December 27, 2017, 3:35am
5
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.