Splunk Search

How to find all the events since the last instance of a specific event?

davemulligan
Engager

I feel like this should be an easy question to find the answer to, but I've spent a good hour or so looking and haven't found it. So, at the risk of looking stupid, here goes:

I'd like to craft a search string to use in a dashboard that returns all the instances of a defined set of events (say, A, B and C) that have occurred since the last occurrence of a different event (say X). I can write the two queries independently no problem:

event_id="X" | head 1 | table _time

gives me the time of the last instance of X, and then I can just change the time range selector to set that to start at that point and run

event_id="A" OR event_id="B" or event_id="C" 

to find the events I'm interested in. But it really seems like this should be possible to do in a single query, passing the result of the first as a parameter into the where clause of the second.

Tags (3)
0 Karma
1 Solution

emechler_splunk
Splunk Employee
Splunk Employee

A subsearch should work nicely here. You can use this to pass KV pairs to the outer search, in your case _time as earliest.

event_id="A" OR event_id="B" or event_id="C" latest=now [ search event_id="X" | head 1 | table _time | rename _time AS earliest ]

So this passes the value of _time for the event found in the first search (named earliest) and then passes it to the outer search which should do what you want.

View solution in original post

emechler_splunk
Splunk Employee
Splunk Employee

A subsearch should work nicely here. You can use this to pass KV pairs to the outer search, in your case _time as earliest.

event_id="A" OR event_id="B" or event_id="C" latest=now [ search event_id="X" | head 1 | table _time | rename _time AS earliest ]

So this passes the value of _time for the event found in the first search (named earliest) and then passes it to the outer search which should do what you want.

davemulligan
Engager

Thank you. I didn't fully understand that the sub search return key - value pairs.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Introducing Splunk 10.0: Smarter, Faster, and More Powerful Than Ever

Now On Demand Whether you're managing complex deployments or looking to future-proof your data ...