Dashboards & Visualizations

exatracing seconds from the string "2h:30m:20s:

Pavankt
Loves-to-Learn

i have a splunk array 

per_stage_data[ [-]
     { [-]
       Stage: S1
        TimeTaken0h:30m:23s
     }
     { [-]
       Stage: S2
        TimeTaken0h:52m:36s
     }
 
   ]

i am implementing a splunk dashboard , in that i want to convert the per_stage_data{}.TimeTaken into seconds. i had tried multiple ways but it didn't worked.

tried using the below solution  but it's not giving any output.

rex field="_raw" "CallDuration: (?<hours>\d+)h:(?<minutes>\d+)m:(?<seconds>\d+)s" | eval CallDurationInSeconds = ((hours*60*60)+(minutes*60)+(seconds))

 

appreciate any inputs.

 

Thanks in advance. 

Labels (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Firstly, why are you using "CallDuration" as you text anchor in the regex when your sample show "TimeTaken"?

Secondly, your JSON array has multiple entries, so, if you know how many entries (Stages) will be present, you can include that in your regex and extract each one separately, or you can use max_match=0 to extract them all into a multi-value field.

Thirdly, for it to be valid JSON, there would be double quotes in the string which would need to be escaped in the regex.

| rex field="_raw" max_match=0 "\"TimeTaken\": \"(?<hours>\d+)h:(?<minutes>\d+)m:(?<seconds>\d+)s\""

Fourthly, if it is JSON, why aren't you using spath to extract the fields (assuming you haven't extracted them as part of the sourcetype definition)?

 

0 Karma

Pavankt
Loves-to-Learn

Thanks for the reply Actually my json file contains total 2 stages as below.

per_stage_info_vendor_data[ [-]
     { [-]
       Stage: stage1
       WallClockTime0h:30m:23s
     }
     { [-]
       Stage: stage2
        WallClockTime0h:52m:36s
     }
   
   ]

 

with following regular expression we are able to get the hours mins and seconds.

rex field=per_stage_info_vendor_data{}.WallClockTime max_match=0 "((?<hours>\d+)h:(?<minutes>\d+)m:(?<seconds>\d+)s)"

But when i tried |eval  stagetime=hours*3600+minutes*60+seconds  it's not working, when i checked further any of the arithmetic  operation on these three fields(hours,minutes and seconds).

 

do i need to convert these fields to any other format.

 

 

 

 

 

Tags (1)
0 Karma
Get Updates on the Splunk Community!

.conf25 technical session recap of Observability for Gen AI: Monitoring LLM ...

If you’re unfamiliar, .conf is Splunk’s premier event where the Splunk community, customers, partners, and ...

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...

Announcing the Migration of the Splunk Add-on for Microsoft Azure Inputs to ...

Announcing the Migration of the Splunk Add-on for Microsoft Azure Inputs to Officially Supported Splunk ...