Splunk Search

How do I combine start time from one event and end time in another and display the stats table in one row?

x213217
Explorer

alt textHello,

I have the following search that generates the below table. How do i get the starting timestamp and the Success or Failure timestamp in the same row as the starting timestamp when these values are all in separate events (one event has start time of job X, next has success/failure time of job X). They will also need to be associated in the right order.

index=XXX source=XXX jobName=XXX

| where statusText="SUCCESS" or statusText="STARTING" or statusText="FAILURE"
| eval startTime=if(statusText=="STARTING",timestamp,null)
| eval failureTime=if(statusText=="FAILURE",timestamp,null)
| eval successTime=if(statusText=="SUCCESS",timestamp,null)
| table jobName startTime successTime failureTime
| rename startTime as "Start Time" successTime as "Success Time" failureTime as "Failure Time"

alt text

Tags (1)
0 Karma
1 Solution

renjith_nair
Legend

@x213217,

Try adding this to your search before the last line in your search (rename)

|streamstats last(successTime) as prev_successTime,last(failureTime) as prev_failuretime current=f window=1|where startTime!=""
|eval successTime=coalesce(prev_successtime,successTime),failureTime=coalesce(prev_failuretime,failureTime)|fields - prev*

Final search

index=XXX source=XXX jobName=XXX
| where statusText="SUCCESS" or statusText="STARTING" or statusText="FAILURE"
| eval startTime=if(statusText=="STARTING",timestamp,null)
| eval failureTime=if(statusText=="FAILURE",timestamp,null)
| eval successTime=if(statusText=="SUCCESS",timestamp,null)
| table jobName startTime successTime failureTime
| streamstats last(startTime) as prev_successTime,last(failureTime) as prev_failuretime current=f window=1|where startTime!=""
| eval successTime=coalesce(prev_successtime,successTime),failureTime=coalesce(prev_failuretime,failureTime)|fields - prev*
| rename startTime as "Start Time" successTime as "Success Time" failureTime as "Failure Time"
---
What goes around comes around. If it helps, hit it with Karma 🙂

View solution in original post

0 Karma

renjith_nair
Legend

@x213217,

Try adding this to your search before the last line in your search (rename)

|streamstats last(successTime) as prev_successTime,last(failureTime) as prev_failuretime current=f window=1|where startTime!=""
|eval successTime=coalesce(prev_successtime,successTime),failureTime=coalesce(prev_failuretime,failureTime)|fields - prev*

Final search

index=XXX source=XXX jobName=XXX
| where statusText="SUCCESS" or statusText="STARTING" or statusText="FAILURE"
| eval startTime=if(statusText=="STARTING",timestamp,null)
| eval failureTime=if(statusText=="FAILURE",timestamp,null)
| eval successTime=if(statusText=="SUCCESS",timestamp,null)
| table jobName startTime successTime failureTime
| streamstats last(startTime) as prev_successTime,last(failureTime) as prev_failuretime current=f window=1|where startTime!=""
| eval successTime=coalesce(prev_successtime,successTime),failureTime=coalesce(prev_failuretime,failureTime)|fields - prev*
| rename startTime as "Start Time" successTime as "Success Time" failureTime as "Failure Time"
---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma

x213217
Explorer

Nevermind got it to work! thanks

| where statusText="SUCCESS" OR statusText="STARTING" OR statusText="FAILURE"
| eval startTime=if(statusText=="STARTING",timestamp,null)
| eval failureTime=if(statusText=="FAILURE",timestamp,null)
| eval successTime=if(statusText=="SUCCESS",timestamp,null)
| streamstats last(successTime) as prev_successtime,last(failureTime) as prev_failuretime current=f window=1|where startTime!=""
| eval successTime=coalesce(prev_successtime,successTime),failureTime=coalesce(prev_failuretime,failureTime)|fields - prev*
| table jobName startTime successTime failureTime
| rename startTime as "Start Time" successTime as "Success Time" failureTime as "Failure Time"
0 Karma

x213217
Explorer

Hello and thank you for your response - I believe this is very close - However it seems to be leaving out the successTime as you can see in the new screenshot i posted above

the startTime seems to match up with the failure time but for events with the SUCCESS timestamp it does not appear in the table? any suggestions on how to fix this ?

thanks.

0 Karma
Get Updates on the Splunk Community!

New in Observability - Improvements to Custom Metrics SLOs, Log Observer Connect & ...

The latest enhancements to the Splunk observability portfolio deliver improved SLO management accuracy, better ...

Improve Data Pipelines Using Splunk Data Management

  Register Now   This Tech Talk will explore the pipeline management offerings Edge Processor and Ingest ...

3-2-1 Go! How Fast Can You Debug Microservices with Observability Cloud?

Register Join this Tech Talk to learn how unique features like Service Centric Views, Tag Spotlight, and ...