<?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: If then else compares in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/If-then-else-compares/m-p/68386#M180499</link>
    <description>&lt;P&gt;BTW, nicely explained. Unless I completely misunderstood it, of course!&lt;/P&gt;</description>
    <pubDate>Wed, 20 Mar 2013 18:46:37 GMT</pubDate>
    <dc:creator>lguinn2</dc:creator>
    <dc:date>2013-03-20T18:46:37Z</dc:date>
    <item>
      <title>If then else compares</title>
      <link>https://community.splunk.com/t5/Splunk-Search/If-then-else-compares/m-p/68384#M180497</link>
      <description>&lt;P&gt;All, &lt;/P&gt;

&lt;P&gt;I need to compare the results of two different searches and I am lost. &lt;/P&gt;

&lt;P&gt;Something like this.&lt;BR /&gt;
count( search status=success) &amp;lt; count (search status=error) then alarm. &lt;/P&gt;

&lt;P&gt;How do I get the value of two searches and run a compare? &lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2013 17:24:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/If-then-else-compares/m-p/68384#M180497</guid>
      <dc:creator>daniel333</dc:creator>
      <dc:date>2013-03-20T17:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: If then else compares</title>
      <link>https://community.splunk.com/t5/Splunk-Search/If-then-else-compares/m-p/68385#M180498</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=xyz or whatever
| stats count(eval(status="success")) as successCount count(eval(status="error")) as ErrorCount
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and use a custom condition for your alarm: &lt;CODE&gt;errorCount &amp;gt;= successCount&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;However, the above will only work if the basic search on the first line is the same for both successes and errors. Also, the &lt;CODE&gt;eval&lt;/CODE&gt; function is case-sensitive, so make sure that the values success/error are actually lower-case.&lt;/P&gt;

&lt;P&gt;What if your successes are recorded in one log file but errors come from a different source? Here's a solution when the two base searches are different. It isn't as efficient, though:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=abc status=success
| stats count as successCount
| appendcols [ search sourcetype=xyz status=error
    | addinfo | where _time &amp;gt;= info_min_time AND _time &amp;lt;= info_max_time
    | status count as errorCount ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And you would use exactly the same custom condition: &lt;CODE&gt;errorCount &amp;gt;= successCount&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;What is all that &lt;CODE&gt;addinfo&lt;/CODE&gt; and other stuff? Well, the second solution uses a subsearch. The subsearch will run over &lt;STRONG&gt;all time&lt;/STRONG&gt; unless you provide a time range. The &lt;CODE&gt;addinfo&lt;/CODE&gt; and &lt;CODE&gt;where&lt;/CODE&gt; commands retrieve the time range of the first search and apply it to the subsearch.&lt;/P&gt;

&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2013 18:46:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/If-then-else-compares/m-p/68385#M180498</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2013-03-20T18:46:00Z</dc:date>
    </item>
    <item>
      <title>Re: If then else compares</title>
      <link>https://community.splunk.com/t5/Splunk-Search/If-then-else-compares/m-p/68386#M180499</link>
      <description>&lt;P&gt;BTW, nicely explained. Unless I completely misunderstood it, of course!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2013 18:46:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/If-then-else-compares/m-p/68386#M180499</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2013-03-20T18:46:37Z</dc:date>
    </item>
  </channel>
</rss>

