<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How abort a search based on a condition? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360084#M106472</link>
    <description>&lt;P&gt;I'm running many scheduled searches. In SQL, there is the "on error" capability that let's you avoid taking further action if something broke before.&lt;/P&gt;

&lt;P&gt;Many of our searches do something like the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|dbxquery connection=xxx query="select * from tablex"
|massage the data
|outputlookup tablex_fast_lookup
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If the SQL command dies due to a SQL issue, then we end up writing an empty lookup file. Once the lookup file is empty, dozens of other things break. I suppose I could convert it to a kv-store and merge data to the lookup with a last update timestamp. Then we could purge older data based on the timestamp.&lt;/P&gt;

&lt;P&gt;I figured that if I could abort the command, then the lookup file would have stale data, but it would not be empty.&lt;/P&gt;</description>
    <pubDate>Tue, 21 Mar 2017 17:27:36 GMT</pubDate>
    <dc:creator>reed_kelly</dc:creator>
    <dc:date>2017-03-21T17:27:36Z</dc:date>
    <item>
      <title>How abort a search based on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360080#M106468</link>
      <description>&lt;P&gt;I have a search that writes a lookup file at the end. I also have searches that end in a collect command. And there are other things that I would like to do that cause side-effects. What I am looking for is a way to abort a search before getting to the commands with side effects.&lt;/P&gt;

&lt;P&gt;For example,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=abc ...
...
|abort condition=[count &amp;lt; 50]
...
|collect index=summary
|outputlookup abc.csv
|my_custom_command_to_post_to_twitter
|etc...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I could probably do it all by wrapping the latter half in a map command, but I am looking for an easier way.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2017 17:20:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360080#M106468</guid>
      <dc:creator>reed_kelly</dc:creator>
      <dc:date>2017-03-17T17:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: How abort a search based on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360081#M106469</link>
      <description>&lt;P&gt;This explains how to do it with &lt;CODE&gt;map&lt;/CODE&gt; but you can just as easily do it with a &lt;CODE&gt;subsearch&lt;/CODE&gt;:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/172541/is-it-possible-to-purposely-cause-a-scheduled-sear.html"&gt;https://answers.splunk.com/answers/172541/is-it-possible-to-purposely-cause-a-scheduled-sear.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Also, instead of having the search cause an error with bogus time values, you could just as easily replace the entire search with &lt;CODE&gt;|noop&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Mar 2017 03:58:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360081#M106469</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-03-19T03:58:32Z</dc:date>
    </item>
    <item>
      <title>Re: How abort a search based on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360082#M106470</link>
      <description>&lt;P&gt;I'd rather not do it with a map, because some of my finishing commands already leverage map. For the "Accept" how would you do it with a subsearch?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 16:03:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360082#M106470</guid>
      <dc:creator>reed_kelly</dc:creator>
      <dc:date>2017-03-21T16:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: How abort a search based on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360083#M106471</link>
      <description>&lt;P&gt;How are you running the search, scheduled or ad-hoc?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 16:32:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360083#M106471</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-03-21T16:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: How abort a search based on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360084#M106472</link>
      <description>&lt;P&gt;I'm running many scheduled searches. In SQL, there is the "on error" capability that let's you avoid taking further action if something broke before.&lt;/P&gt;

&lt;P&gt;Many of our searches do something like the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|dbxquery connection=xxx query="select * from tablex"
|massage the data
|outputlookup tablex_fast_lookup
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If the SQL command dies due to a SQL issue, then we end up writing an empty lookup file. Once the lookup file is empty, dozens of other things break. I suppose I could convert it to a kv-store and merge data to the lookup with a last update timestamp. Then we could purge older data based on the timestamp.&lt;/P&gt;

&lt;P&gt;I figured that if I could abort the command, then the lookup file would have stale data, but it would not be empty.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 17:27:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360084#M106472</guid>
      <dc:creator>reed_kelly</dc:creator>
      <dc:date>2017-03-21T17:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: How abort a search based on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360085#M106473</link>
      <description>&lt;P&gt;Or you can do it with a &lt;CODE&gt;subsearch&lt;/CODE&gt;, like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YOUR BASE SEARCH HERE [| noop 
| stats count AS blackout 
| addinfo 
| eval blackout=case((SomeLogic="For Blackout Here"), "YES",
    (OtherLogic="For Blackout Here"), "YES",
    true(),"NO") 
| eval earliestMaybe=if((blackout=="NO"), info_min_time, now()) 
| eval latestMaybe=if((blackout=="NO"), info_max_time, 0) 
| eval search="earliest=" . earliestMaybe . " latest=" . info_max_time]
| YOUR POST SEARCH HERE
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Mar 2017 18:31:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360085#M106473</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-03-21T18:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: How abort a search based on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360086#M106474</link>
      <description>&lt;P&gt;For just this particular problem (empty lookup when no data), you could do something like this&lt;BR /&gt;
&lt;STRONG&gt;Updated&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; |dbxquery connection=xxx query="select * from tablex"
 |massage the data
 | eval type="new"  | append [ | inputlookup tablex_fast_lookup | eval type="old"]
 | eventstats count(eval(type="new")) as hasData | eval filter=if(hasData&amp;gt;0,"new","old") 
 | where type=filter | fields - type hasData filter
 |outputlookup tablex_fast_lookup
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Basically, if base search has no data, re-add the existing data from lookup again.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 18:45:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360086#M106474</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-03-21T18:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: How abort a search based on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360087#M106475</link>
      <description>&lt;P&gt;For the append, I think you mean "inputlookup". I know what you mean and this works well for that case.&lt;BR /&gt;
-Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 19:43:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360087#M106475</guid>
      <dc:creator>reed_kelly</dc:creator>
      <dc:date>2017-03-21T19:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: How abort a search based on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360088#M106476</link>
      <description>&lt;P&gt;Taking it one step further, I made a global macro:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[outputlookup_if_data(1)]
args = lookup_file
definition = eval upx_type="new" | append [ |inputlookup $lookup_file$ | eval u
px_type="old"] | eventstats count(eval(upx_type="new")) as upx_hasData | eval u
px_filter=if(upx_hasData&amp;gt;0,"new","old") | where upx_type=upx_filter | fields -
upx_type upx_hasData upx_filter | outputlookup $lookup_file$
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Mar 2017 19:59:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360088#M106476</guid>
      <dc:creator>reed_kelly</dc:creator>
      <dc:date>2017-03-21T19:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: How abort a search based on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360089#M106477</link>
      <description>&lt;P&gt;You could make use of the override_if_empty attribute of outputlookup:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | dbxquery connection=xxx query="select * from tablex"
 |massage the data
 |discard all events when an error condition occurs, maybe using:
 | eventstats count as dbresults
 | where dbresults &amp;gt; 10000 
 | outputlookup tablex_fast_lookup override_if_empty=false
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:10:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-abort-a-search-based-on-a-condition/m-p/360089#M106477</guid>
      <dc:creator>mmol</dc:creator>
      <dc:date>2020-09-30T04:10:30Z</dc:date>
    </item>
  </channel>
</rss>

