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!

Strengthen Your Future: A Look Back at Splunk 10 Innovations and .conf25 Highlights!

The Big One: Splunk 10 is Here!  The moment many of you have been waiting for has arrived! We are thrilled to ...

Now Offering the AI Assistant Usage Dashboard in Cloud Monitoring Console

Today, we’re excited to announce the release of a brand new AI assistant usage dashboard in Cloud Monitoring ...

Stay Connected: Your Guide to October Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...