Getting Data In

Subtracts two time field showing null result

Manasi25
Explorer

Hi,

 

i have my query below, i used query from "Solved" questions on community, however its showing NULL result for me.

Query --

index=victorops sourcetype="splunk:victorops:incidents:json" "PTS"
| dedup incidentNumber
| eval startTimeFormatted=strptime(startTime,"%Y-%m-%dT%H:%M:%SZ") -18000
| eval SplunkStartTime=strftime(startTimeFormatted,"%m/%d/%y %H:%M:%S")


| eval endTimeFormatted=strptime(lastAlertTime,"%Y-%m-%dT%H:%M:%SZ") -18000
| eval SplunkEndTime=strftime(endTimeFormatted,"%m/%d/%y %H:%M:%S")


| eval MTTR = round((SplunkEndTime-SplunkStartTime)/86400)
| table incidentNumber, SplunkStartTime, routingKey, entityDisplayName, SplunkEndTime, currentPhase, MTTR


Above query  showing "NULL" output to "MTTR" field.

 

Please advise !

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| eval MTTR = tostring(endTimeFormatted-startTimeFormatted,"duration")

View solution in original post

0 Karma

scelikok
SplunkTrust
SplunkTrust

Hi @Manasi25,

Since the time fields are string formatted, MTTR calculation is not possible. Please try below options;

in days;
| eval MTTR =round((lastAlertTime-startTime)/86400)

OR formatted as duration; 
| eval MTTR = tostring(lastAlertTime-startTime, "duration")

 

If this reply helps you an upvote and "Accept as Solution" is appreciated.
0 Karma

Manasi25
Explorer

Hello

Thank you ! 
I used this and this shows "00:00:00" result to all time spam. PFA

Please advise further!

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| eval MTTR = tostring(round((endTimeFormatted-startTimeFormatted)/86400),"duration")
0 Karma

Manasi25
Explorer

Hello @ITWhisperer ,

I searched with your query and still getting "00:00:00" result to all rows.

 

PFA. please help !

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| eval MTTR = tostring(endTimeFormatted-startTimeFormatted,"duration")
0 Karma

Manasi25
Explorer

Hi @ITWhisperer 

This helps and result is good. Thank you !

0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

you cannot calculate with string fields. You must use those with numeric values. In your case those are startTimeFormatted and endTimeFormatted.

If you would like to see MTTR as human readable convert it with 

eval MTTR = tostring(MTTR, "duration")

after calculation.

r. Ismo 

0 Karma
Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Shape the Future of Splunk: Join the Product Research Lab!

Join the Splunk Product Research Lab and connect with us in the Slack channel #product-research-lab to get ...

Auto-Injector for Everything Else: Making OpenTelemetry Truly Universal

You might have seen Splunk’s recent announcement about donating the OpenTelemetry Injector to the ...