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!

Introducing the Splunk Community Dashboard Challenge!

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

Get the T-shirt to Prove You Survived Splunk University Bootcamp

As if Splunk University, in Las Vegas, in-person, with three days of bootcamps and labs weren’t enough, now ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...