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!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...