Convert time duration to float

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?

I am trying to convert a time duration into float.
The input data is in the form HH:mm:ss.

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

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