Splunk Search

Search for event when preceded or followed by another event.

khodges_splunk
Splunk Employee
Splunk Employee

How can I search for an event x, only when preceded or followed by event y? I.e., I only want x when y is immediately adjacent.

Tags (1)
0 Karma

acdevlin
Communicator

I think you'll want to use the transaction command. You can use the "startswith", "endswith", and "maxevents" options to further customize the query. Here's one example for event X followed by event Y.

... | transaction startswith="event x" endswith="event y" maxevents=2

You could then use an append to get the transactions with event Y before event X if you want to keep the whole process as just one search. However, this will cause a dramatic slowdown since the subsearch requires a second pass; I would recommend avoiding the following if high performance is an important goal.

... | transaction startswith="event x" endswith="event y" maxevents=2 | append [search <your search here> | transaction startswith="event y" endswith="event x" maxevents=2]

Does this help answer your question?

Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...