Splunk Search

Besides a series of regex's, is there an automated way to change duration format into plain english?

Phil219
Path Finder

To make a "plain english" dashboard panel, I currently use the following search to change a duration value (SecondsSinceUpdate) to "ActualTimeSinceUpdate":

|metadata type=hosts 
|eval SecondsSinceUpdate = now()-recentTime
|eval ActualTimeSinceUpdate=tostring(SecondsSinceUpdate,"duration")
|rex mode=sed field=ActualTimeSinceUpdate "s/\+/ days, /"
|rex mode=sed field=ActualTimeSinceUpdate "s/\:/ hours, /"
|rex mode=sed field=ActualTimeSinceUpdate "s/\:/ minutes and /"
|rex mode=sed field=ActualTimeSinceUpdate "s/$/ seconds/"
|rex mode=sed field=ActualTimeSinceUpdate "s/\Q00 hours, \E//"
|rex mode=sed field=ActualTimeSinceUpdate "s/\Q00 minutes \E//"
|rex mode=sed field=ActualTimeSinceUpdate "s/\Q 0\E/ /g"
|rex mode=sed field=ActualTimeSinceUpdate "s/^\Q0\E//"
|rex mode=sed field=ActualTimeSinceUpdate "s/^\Qand \E//"

Which results in the attachedalt text

How can this be accomplished more simply?

0 Karma

somesoni2
Revered Legend

Try like this

| gentimes start=-10 | append [search index=_internal | head 1 | table _time | bucket span=1s _time | rename _time as endtime]
 | eval SecondsSinceUpdate = now()-endtime 
 | eval ActualTimeSinceUpdate=tostring(SecondsSinceUpdate,"duration") 
| eval humanTimeSinceUpdate=replace(replace(replace(ActualTimeSinceUpdate,"(\d+):(\d+):(\d+)$","\1 hours,\2 minutes, \3 seconds"),"(\d+)\+","\1 days,"),"00 \w+,","")
0 Karma
Get Updates on the Splunk Community!

Enter the Splunk Community Dashboard Challenge for Your Chance to Win!

The Splunk Community Dashboard Challenge is underway! This is your chance to showcase your skills in creating ...

.conf24 | Session Scheduler is Live!!

.conf24 is happening June 11 - 14 in Las Vegas, and we are thrilled to announce that the conference catalog ...

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...