Splunk Search

Conditional searches

efo
Engager

Hi,
We have gotten quite a complex search request, which we are not sure if is possible at all.

If the application log says "SITE X DOWN", and then within an five minute interval logs "SITE BACKUP X DOWN" it must raise an alert. If the applications logs SITE BAKCUP X DOWN outside the five minute interval everything is OK.

How, if at all possible, could this be accomplished?

--
Espen

Tags (1)
0 Karma
1 Solution

Ayn
Legend

You can use the transaction command. This will join separate events together to a new combined event (a transaction) based on rules that you specify. You can then search for transactions that match multiple conditions.

In your case, you want to find cases where "SITE X DOWN" and "SITE BACKUP X DOWN" occur within a 5 minute interval. This can be accomplished using transaction like this:

"SITE X DOWN" OR "SITE BACKUP X DOWN" 
| transaction source startswith="SITE X DOWN" endswith="SITE BACKUP X DOWN" maxspan=5m

Any events returned by this search will match your condition. I used "source" as an argument to transaction but any field identifier can be used. This specifies what field(s) Splunk should look for and use when grouping together events, so in this case Splunk will be looking to grouping events into transactions if they have the same value for the "source" field. The more unique the field value, the better.

More information on the transaction command is available in the docs: http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Transaction

View solution in original post

efo
Engager

This is perfect, thank you.
But is it best run with time range "rt-5 to rt" or just a normal search that ranges the last ten minutes or so?

0 Karma

Ayn
Legend

You can use the transaction command. This will join separate events together to a new combined event (a transaction) based on rules that you specify. You can then search for transactions that match multiple conditions.

In your case, you want to find cases where "SITE X DOWN" and "SITE BACKUP X DOWN" occur within a 5 minute interval. This can be accomplished using transaction like this:

"SITE X DOWN" OR "SITE BACKUP X DOWN" 
| transaction source startswith="SITE X DOWN" endswith="SITE BACKUP X DOWN" maxspan=5m

Any events returned by this search will match your condition. I used "source" as an argument to transaction but any field identifier can be used. This specifies what field(s) Splunk should look for and use when grouping together events, so in this case Splunk will be looking to grouping events into transactions if they have the same value for the "source" field. The more unique the field value, the better.

More information on the transaction command is available in the docs: http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Transaction

Ayn
Legend

Just don't use source as a field to run transaction on.

0 Karma

lpolo
Motivator

How would you do it if you have two different source logs?

0 Karma

efo
Engager

This solves the problem.
Thank you very much, Ayn

0 Karma

Drainy
Champion

Excellent answer, clearly explained

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Introducing the 2026 - 2027 SplunkTrust cohort!

The goal of the SplunkTrust™ membership has historically been to acknowledge and recognize those who go above ...

(re)Introducing the Splunk Community Champions + 2026 – 2027 Splunk MVPs ...

This program exists as a channel to empower and recognize Splunk advocates and help supercharge initiatives to ...

Pro Tips for .conf26: How to Prep Like a Splunk Veteran

There’s no shortage of incredible content lined up for .conf26 in Denver, from deep-dive technical sessions ...