<?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: Why does my search with an eval if condition always return false? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164664#M46761</link>
    <description>&lt;P&gt;Hi,  I removed the |eval span=4 to be safe which made no difference.  The problem that I'm having is that the if-then-else is alway returning false which make qos_unit always have the value of qos_thruput even if qos_metric is Bandwidth.  So to explain:&lt;/P&gt;

&lt;P&gt;If qos_metric = bandwidth then let qos_unit contain qos_bandwidth values else qos_unit contains qos_thruput values.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 20:18:15 GMT</pubDate>
    <dc:creator>cdstealer</dc:creator>
    <dc:date>2020-09-28T20:18:15Z</dc:date>
    <item>
      <title>Why does my search with an eval if condition always return false?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164657#M46754</link>
      <description>&lt;P&gt;Hi,  &lt;/P&gt;

&lt;P&gt;I'm having difficulty in using a field in a dashboard.  I have 3 fields that I'm trying to use some logic with.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;qos_metric&lt;/CODE&gt;, &lt;CODE&gt;qos_bandwidth&lt;/CODE&gt; &amp;amp; &lt;CODE&gt;qos_thruput&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I tried this, but it always returns false:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   | eval qos_unit=if(qos_metric == "Bandwidth", qos_bandwidth, qos_thruput)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The index always contains &lt;CODE&gt;qos_bandwidth&lt;/CODE&gt; &amp;amp; &lt;CODE&gt;qos_thruput&lt;/CODE&gt; together, but I only require one.&lt;/P&gt;

&lt;P&gt;The logic:&lt;BR /&gt;
if &lt;CODE&gt;qos_metric == Bandwidth&lt;/CODE&gt; then &lt;CODE&gt;qos_unit&lt;/CODE&gt; contains the value of &lt;CODE&gt;qos_bandwidth&lt;/CODE&gt;, else &lt;CODE&gt;qos_unit&lt;/CODE&gt; contains the value of &lt;CODE&gt;qos_thruput&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;The search (to add context):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Index=storage_arrays sourcetype=qos dev_name=$device$ qos_class=$class$ | eval qos_unit=if(qos_metric == "Bandwidth", qos_bandwidth, qos_thruput) | chart avg(qos_unit) as "QoS" avg(qos_metric_value) as Limit over _time by qos_class | eval _span=4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I hope I explained OK.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2015 11:22:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164657#M46754</guid>
      <dc:creator>cdstealer</dc:creator>
      <dc:date>2015-06-16T11:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: Why does my search with an eval if condition always return false?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164658#M46755</link>
      <description>&lt;P&gt;if "Bandwidth" is an field, try like :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=storage_arrays sourcetype=qos dev_name=$device$ qos_class=$class$ | eval qos_unit=if(qos_metric == Bandwidth, qos_bandwidth, qos_thruput) | chart avg(qos_unit) as "QoS" avg(qos_metric_value) as Limit over _time by qos_class | eval _span=4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or &lt;BR /&gt;
if "Bandwidth" is an string ,  the you querry is verry OK .&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2015 11:30:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164658#M46755</guid>
      <dc:creator>fdi01</dc:creator>
      <dc:date>2015-06-16T11:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: Why does my search with an eval if condition always return false?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164659#M46756</link>
      <description>&lt;P&gt;Hi fdi01, Thanks for the reply.  The quotes (with/without) make no difference. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2015 11:38:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164659#M46756</guid>
      <dc:creator>cdstealer</dc:creator>
      <dc:date>2015-06-16T11:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: Why does my search with an eval if condition always return false?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164660#M46757</link>
      <description>&lt;P&gt;Hello! I think the error should be your &lt;CODE&gt;avg(qos_unit)&lt;/CODE&gt; and &lt;CODE&gt;avg(qos_metric_value)&lt;/CODE&gt;. Make sure that &lt;STRONG&gt;qos_unit&lt;/STRONG&gt; and &lt;STRONG&gt;qos_metric_value&lt;/STRONG&gt; have numerical values since &lt;CODE&gt;avg&lt;/CODE&gt; will only work with numerical values. If not, try another function&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 20:16:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164660#M46757</guid>
      <dc:creator>stephanefotso</dc:creator>
      <dc:date>2020-09-28T20:16:38Z</dc:date>
    </item>
    <item>
      <title>Re: Why does my search with an eval if condition always return false?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164661#M46758</link>
      <description>&lt;P&gt;Hi,  The two fields only contain integers.  And I've pretty much worked my way through &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.3/SearchReference/CommonEvalFunctions"&gt;doc&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2015 12:42:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164661#M46758</guid>
      <dc:creator>cdstealer</dc:creator>
      <dc:date>2015-06-16T12:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: Why does my search with an eval if condition always return false?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164662#M46759</link>
      <description>&lt;P&gt;You explained everything except for the problem that you are having.  According to your "question" everything is A-OK and working fine.  IMHO there is nothing wrong with your search string with the exception that the final clause ( &lt;CODE&gt;| eval _span=4&lt;/CODE&gt; ) is useless and does nothing (which makes me think that you are trying to have it do something, which maybe is the "unspoken problem" that you are having).  Clarify your problem and maybe we can help you.  In any case, the search you posted should do exactly as you indicated is your desire.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2015 13:33:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164662#M46759</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-06-16T13:33:01Z</dc:date>
    </item>
    <item>
      <title>Re: Why does my search with an eval if condition always return false?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164663#M46760</link>
      <description>&lt;P&gt;Run your search without a token and let know what happen&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Index=storage_arrays sourcetype=qos dev_name=* qos_class=* | eval qos_unit=if(qos_metric == "Bandwidth", qos_bandwidth, qos_thruput) | chart avg(qos_unit) as "QoS" avg(qos_metric_value) as Limit over _time by qos_class
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jun 2015 14:26:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164663#M46760</guid>
      <dc:creator>stephanefotso</dc:creator>
      <dc:date>2015-06-16T14:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: Why does my search with an eval if condition always return false?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164664#M46761</link>
      <description>&lt;P&gt;Hi,  I removed the |eval span=4 to be safe which made no difference.  The problem that I'm having is that the if-then-else is alway returning false which make qos_unit always have the value of qos_thruput even if qos_metric is Bandwidth.  So to explain:&lt;/P&gt;

&lt;P&gt;If qos_metric = bandwidth then let qos_unit contain qos_bandwidth values else qos_unit contains qos_thruput values.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 20:18:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164664#M46761</guid>
      <dc:creator>cdstealer</dc:creator>
      <dc:date>2020-09-28T20:18:15Z</dc:date>
    </item>
    <item>
      <title>Re: Why does my search with an eval if condition always return false?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164665#M46762</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Index=storage_arrays sourcetype=qos dev_name=$device$ qos_class=$class$ | eval qos_unit=if(like(qos_metric,"%Bandwidth%"), qos_bandwidth, qos_thruput) | chart avg(qos_unit) as "QoS" avg(qos_metric_value) as Limit over _time by qos_class
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The only reason that this makes sense ("if" is always true) is if your test is not what you think it is; this test is a little more flexible to accommodate bounding whitespace.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2015 15:06:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164665#M46762</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-06-16T15:06:14Z</dc:date>
    </item>
    <item>
      <title>Re: Why does my search with an eval if condition always return false?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164666#M46763</link>
      <description>&lt;P&gt;Hi,  Thanks again.  Still no joy &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;  Though I have sorted it another way &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  Answer to follow.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2015 07:00:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164666#M46763</guid>
      <dc:creator>cdstealer</dc:creator>
      <dc:date>2015-06-17T07:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: Why does my search with an eval if condition always return false?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164667#M46764</link>
      <description>&lt;P&gt;Instead of trying to go through an eval condition, I've created an input with the static values Name=Bandwidth Value=qos_bandwidth, Name=Throughput,Value=qos_thruput.  I then removed the entire eval statement.  This seems to work as expected &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  It just means a manual step rather than automated.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="storage_arrays" sourcetype="qos" dev_name="$device$" qos_class="$class$" | chart avg($qosVol$) as "QoS" avg(qos_metric_value) as "Limit" over _time by qos_class
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thank you for all your time.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;EDIT&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Managed to automate it and thought I'd add it just in case.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="storage_arrays" sourcetype="qos" dev_name="$device$" qos_class="$class$" | fields qos_class dev_name qos_metric qos_bandwidth qos_thruput qos_metric_value | transaction qos_metric qos_bandwidth qos_thruput qos_class dev_name | eval qos_unit=if(qos_metric == "Bandwidth", qos_bandwidth, qos_thruput)| chart avg(qos_unit) as "QoS" avg(qos_metric_value) as "Limit" over _time by qos_class
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Breakdown:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;main search populated by form options&amp;gt; | &amp;lt;only return the fields I'm interested in&amp;gt; | &amp;lt;merge the fields&amp;gt; The "qos_metric" field is from a second source, so creates a separate event to the other fields. | &amp;lt;If statement so if qos_metric is Bandwidth only return qos_bandwidth value, else qos_thruput values.&amp;gt; | &amp;lt;stick it in a chart so we can do pretty graphs&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 20:18:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-my-search-with-an-eval-if-condition-always-return-false/m-p/164667#M46764</guid>
      <dc:creator>cdstealer</dc:creator>
      <dc:date>2020-09-28T20:18:38Z</dc:date>
    </item>
  </channel>
</rss>

