<?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 How to use eval if there is no result from the base search and without the use of any subsearch? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-if-there-is-no-result-from-the-base-search-and/m-p/172603#M49483</link>
    <description>&lt;P&gt;Hello everybody,&lt;/P&gt;

&lt;P&gt;there were two questions lately, related to using &lt;CODE&gt;eval&lt;/CODE&gt; when there were no events from the base search:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://answers.splunk.com/answers/171101/stats-count-eval-error-using-or.html"&gt;http://answers.splunk.com/answers/171101/stats-count-eval-error-using-or.html&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://answers.splunk.com/answers/174458/error-when-using-eval-in-a-range.html"&gt;http://answers.splunk.com/answers/174458/error-when-using-eval-in-a-range.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;So, how to use eval if there is no result from the base search and (&lt;EM&gt;as you already might have figured out&lt;/EM&gt;) without the use of any &lt;CODE&gt;subsearch&lt;/CODE&gt; ?&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
    <pubDate>Fri, 17 Oct 2014 13:09:27 GMT</pubDate>
    <dc:creator>MuS</dc:creator>
    <dc:date>2014-10-17T13:09:27Z</dc:date>
    <item>
      <title>How to use eval if there is no result from the base search and without the use of any subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-if-there-is-no-result-from-the-base-search-and/m-p/172603#M49483</link>
      <description>&lt;P&gt;Hello everybody,&lt;/P&gt;

&lt;P&gt;there were two questions lately, related to using &lt;CODE&gt;eval&lt;/CODE&gt; when there were no events from the base search:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://answers.splunk.com/answers/171101/stats-count-eval-error-using-or.html"&gt;http://answers.splunk.com/answers/171101/stats-count-eval-error-using-or.html&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://answers.splunk.com/answers/174458/error-when-using-eval-in-a-range.html"&gt;http://answers.splunk.com/answers/174458/error-when-using-eval-in-a-range.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;So, how to use eval if there is no result from the base search and (&lt;EM&gt;as you already might have figured out&lt;/EM&gt;) without the use of any &lt;CODE&gt;subsearch&lt;/CODE&gt; ?&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Fri, 17 Oct 2014 13:09:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-if-there-is-no-result-from-the-base-search-and/m-p/172603#M49483</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-10-17T13:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval if there is no result from the base search and without the use of any subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-if-there-is-no-result-from-the-base-search-and/m-p/172604#M49484</link>
      <description>&lt;P&gt;I will show an example using this run everywhere command and explain it line by line:&lt;/P&gt;

&lt;P&gt;First is the base search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=splunkd splunk_server=local earliest=-1h@h latest=-0h@h 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Next we do some &lt;CODE&gt;eval&lt;/CODE&gt; to get some fake &lt;CODE&gt;isFailure&lt;/CODE&gt; field:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval isFailure=if(searchmatch("source"),1,0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now comes the trick, do a simple &lt;CODE&gt;stats count AS ..&lt;/CODE&gt; and provide any further needed values as well:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count as myCount sum(isFailure) AS isFailure
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Next, check if there were no search results, if so set the value of &lt;CODE&gt;isFailure&lt;/CODE&gt; to &lt;CODE&gt;"0"&lt;/CODE&gt; .If there were search results, set &lt;CODE&gt;isFailure&lt;/CODE&gt;to the sum of the &lt;CODE&gt;isFailure&lt;/CODE&gt; field:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval isFailure=if(myCount=="0",0,isFailure)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now set the &lt;CODE&gt;failuresCategory&lt;/CODE&gt; to different levels:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval failuresCategory = case(isFailure=0,"low",isFailure&amp;lt;1000,"elevated",isFailure&amp;gt;=1000,"severe")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and finally display it using &lt;CODE&gt;table&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| table myCount, failuresCategory, isFailure
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now, let do the no results search and see if this works:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=splunkd splunk_server=local earliest=-1h@h latest=-0h@h this will bring back no results from the base search
| eval isFailure=if(searchmatch("source"),1,0)
| stats count as myCount sum(isFailure) AS isFailure
| eval isFailure=if(myCount=="0",0,isFailure)
| eval failuresCategory = case(isFailure=0,"low",isFailure&amp;lt;1000,"elevated",isFailure&amp;gt;=1000,"severe")
| table myCount, failuresCategory, isFailure
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and the result looks like this:&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/111i526172943E3099FF/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Instead of &lt;CODE&gt;table&lt;/CODE&gt; you can use any command like &lt;CODE&gt;chart&lt;/CODE&gt; or &lt;CODE&gt;rangemap&lt;/CODE&gt; as well.&lt;/P&gt;

&lt;P&gt;hope this helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Fri, 17 Oct 2014 13:21:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-if-there-is-no-result-from-the-base-search-and/m-p/172604#M49484</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-10-17T13:21:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval if there is no result from the base search and without the use of any subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-if-there-is-no-result-from-the-base-search-and/m-p/172605#M49485</link>
      <description>&lt;P&gt;Very nice! Sooo, how would I do this with a "stats" command using "by _time". Ths solution is working perfectly on my implementations, but now I have one grouped by time. Maybe I need to run it through a timechart instead...hmmm&lt;/P&gt;

&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2015 21:56:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-if-there-is-no-result-from-the-base-search-and/m-p/172605#M49485</guid>
      <dc:creator>rmarcum</dc:creator>
      <dc:date>2015-08-13T21:56:19Z</dc:date>
    </item>
  </channel>
</rss>

