Splunk Search

How to run a search if another search does not return any results?

drautb
Explorer

Hey all,

I have two searches that both run independently of one another. They both work fine by themselves. Now, I would like the run the second search, if and only if, the first search does NOT return any results. I'm trying to do something like this right now:

<first search> | stats count | where count=0 | <second search>

But that doesn't quite work, the events from are returned, but no others are. What I'd like is for the events from to just be dropped, and the events from to be returned if there were NOT any results for . Has anyone done this before?

Tags (2)

the_wolverine
Champion

If you schedule the first search, you could schedule a second search which looks for result_count=0 in the internal log:

index=_internal startminutesago=5 sourcetype=scheduler savedsearch_name="name_of_first_scheduled_search" status=success result_count=0 | append [ search "second search query" ]

drautb
Explorer

I apologize, thanks for catching that. I've edited my question.

0 Karma

strive
Influencer

What if there are no results from first search? In that case you want your second search to be executed or not executed?

You have contradicting statements in your question.

"Now, I would like the run the second search, if and only if, the first search doesn't return any results."

"What I'd like is for the events from to just be dropped, and the events from to be returned if there were any results for "

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...