Splunk Search

Best way to correct tostring(,"duration") bug?

nick405060
Motivator

Hi there,

| eval session_length=tostring(end-start,"duration") is not padding zeros correctly (I believe just for seconds?): 02:08:4.275

What's the most elegant way to fix this?

The best I got so far is rex field=session_length "(?<hm>\d\d:\d\d:)(?<sn>\d\.\d\d\d)" | eval session_length=if(isnull(hm),session_length,hm."0".sn) which I'm pretty sure is breakable

0 Karma
1 Solution

nick405060
Motivator

rex field=session_length mode=sed "s/:(\d)(:|\.)/:0\1\2/g"

Give me karma

View solution in original post

0 Karma

woodcock
Esteemed Legend

Like this:

... | rex field=session_length mode=sed "s/(\d)(\.\d+)$/0\1\2/ s/:(\d)$/:0\1/"
0 Karma

woodcock
Esteemed Legend

The one from @nick405060 is better.

0 Karma

nick405060
Motivator

Maybe, I'm honestly not totally sure if it only effects seconds or not. If it does, then mine could be cleaned up because you don't need (:|.). If it only effects seconds and minutes, mine is good. If it effects hours mine needs to be modded.

0 Karma

woodcock
Esteemed Legend

If yours handles both 02:08:4.275 and 02:08:4, then yours is better, but if it doesn't, then mine is better (because it does both).

0 Karma

nick405060
Motivator

rex field=session_length mode=sed "s/:(\d)(:|\.)/:0\1\2/g"

Give me karma

0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

WATCH NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If exploited, ...

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 ...