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!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...