Splunk Search

How to convert epoch time to HH:MM:SS AFTER using stats AVG?

mjd555
Path Finder

So I have the following search:

Index="Cyber" sourcetype=Response queue = "Incident" status ="resolved"  | dedup ticket

     | table Date_Created, Acknowledge_Date 
     | eval epoch1=strptime(Date_Created,"%Y-%m-%d %H:%M:%S") 
     | convert timeformat="%Y-%m-%d %H:%M:%S" mktime(Date_Created) as epochDateCreated
     | eval epoch2=strptime(Acknowledge_Date,"%Y-%m-%d %H:%M:%S")
     | convert timeformat="%Y-%m-%d %H:%M:%S" mktime(Acknowledge_Date) as epochAck
     | eval Diff=(epochAck-epochDateCreated)

     |stats avg(Diff)

I now have an average time it takes to acknowledge an incident in epoch format. However, I cannot use Strftime once the figure has already been averaged. Is there a way around this?

1 Solution

richgalloway
SplunkTrust
SplunkTrust

Try this

... | stats avg(Diff) AS avgDiff | fieldformat avgDiff=tostring(avgDiff, "duration") | ...
---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

Try this

... | stats avg(Diff) AS avgDiff | fieldformat avgDiff=tostring(avgDiff, "duration") | ...
---
If this reply helps you, Karma would be appreciated.

ppablo
Retired

confetti @richgalloway 🙂 I just noticed my upvote put you over the 10,000 karma milestone. Congrats and well deserved!

richgalloway
SplunkTrust
SplunkTrust

Thanks, ppablo!

---
If this reply helps you, Karma would be appreciated.

MuS
Legend

Added more :confetti: to the party !!!!! 🙂

mjd555
Path Finder

Afraid this didn't work as it just returned a blank value

0 Karma

richgalloway
SplunkTrust
SplunkTrust

I just noticed a typo in the fieldformat command. Try the new answer. If it still doesn't work, please post your new search.

---
If this reply helps you, Karma would be appreciated.

mjd555
Path Finder

Perfect, that has given me an answer of: 03:25:04.487179

Is there a way to round this?

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Try substr. Adjust the second number to get the length you want.

... | eval avgDiff=substr(avgDiff, 1, 😎 | ...
---
If this reply helps you, Karma would be appreciated.

mjd555
Path Finder

Amazing, thanks for your help!!

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Please accept the answer.

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...