Splunk Search

Convert duration time to number integer

Miguel3393
Path Finder

I have this search, where I get the duration and I need to convert it to integer:
Example:

Min:Sec to Whole

00:02      to   1
00:16      to   1
01:53      to  2
09:20      to  10

...etc

Script:

index="cdr" | search "Call.TermParty.TrunkGroup.TrunkGroupId"="2811" OR
"Call.TermParty.TrunkGroup.TrunkGroupId"="2810"
"Call.ConnectTime"=*
"Call.DisconnectTime"=*
|lookup Pais Call.RoutingInfo.DestAddr OUTPUT Countrie
| eval Disctime=strftime('Call.DisconnectTime'/1000,"%m/%d/%Y %H:%M:%S %Q")
| eval Conntime=strftime('Call.ConnectTime'/1000, "%m/%d/%Y %H:%M:%S%Q")
| eval diffTime=('Call.DisconnectTime'-'Call.ConnectTime')
| eval Duracion=strftime(diffTime/1000, "%M:%S") | table Countrie, Duración

Spain 00:02
Spain 00:16
Argentina 00:53
Spain 09:20
Spain 02:54
Spain 28:30
Spain 01:18
Spain 00:28
Spain 16:40
Spain 00:03
Chile 00:25
Uruguay 01:54
Spain 01:54

Miguel3393_0-1736370753385.png

 Regards.

 

Labels (2)
Tags (2)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

If you want to get duration as whole rounded up minutes, use ceil, as @isoutamo shows, e.g.

| eval WholeMinutes=ceil(diffTime/1000/60)

 

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

If you want to get duration as whole rounded up minutes, use ceil, as @isoutamo shows, e.g.

| eval WholeMinutes=ceil(diffTime/1000/60)

 

gcusello
SplunkTrust
SplunkTrust

Hi @Miguel3393 ,

at first, don't use the search command after the main search because your search is slower!

Then, you already calculated the difference in seconds in the field diffTime, you have only to add this field to the table command.

then, I'm not sure that the solution to extress the duration in minutes and seconds is correct, you shuld use:

| eval Duracion=tostring(diffTime,"duration")

 In other words, please try this:

index="cdr" ("Call.TermParty.TrunkGroup.TrunkGroupId"="2811" OR
"Call.TermParty.TrunkGroup.TrunkGroupId"="2810") "Call.ConnectTime"=* "Call.DisconnectTime"=*
| lookup Pais Call.RoutingInfo.DestAddr OUTPUT Countrie
| eval Disctime=strftime('Call.DisconnectTime'/1000,"%m/%d/%Y %H:%M:%S %Q")
| eval Conntime=strftime('Call.ConnectTime'/1000, "%m/%d/%Y %H:%M:%S%Q")
| eval diffTime=('Call.DisconnectTime'-'Call.ConnectTime')
| eval Duracion=tostring(diffTime,"duration") 
| table Countrie Duracion diffTime

Ciao.

Giuseppe

0 Karma

Miguel3393
Path Finder

Thanks for the response @gcusello 

This is the result I get with what you mention.

Miguel3393_0-1736435619547.png

Regards.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @Miguel3393 ,

good for you, see next time!

let us know if we can help you more, or, please, accept one answer for the other people of Community.

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated by all the contributors 😉

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...