<?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: Where function not calculating fields as expected in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Where-function-not-calculating-fields-as-expected/m-p/439494#M125018</link>
    <description>&lt;P&gt;This is wrong and cannot (and therefore DOES not) work.  You DO NOT have any field named &lt;CODE&gt;threshold&lt;/CODE&gt;.  That is the whole problem.  See my answer below (which was modified since first posting) for a complete fix.&lt;/P&gt;</description>
    <pubDate>Tue, 13 Aug 2019 17:15:26 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2019-08-13T17:15:26Z</dc:date>
    <item>
      <title>Where function not calculating fields as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Where-function-not-calculating-fields-as-expected/m-p/439488#M125012</link>
      <description>&lt;P&gt;I have a basic search to identify systems that have not checked into a service for X amount of time.  There is nothing fancy about the search but I must be missing something simple because when I use the where function to compare two fields I get no results.  I am searching a list of hostnames, setting a threshold to compare against, and trying to display only events that are older than the set threshold:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main sourcetype="app:agent" hostname IN (host1 host2 host3)
| eval hostname=upper(hostname)
| eval threshold=now()-30
| stats latest(_time) as LastCheckin values(threshold) by computer_name
| where LastCheckin&amp;lt;threshold
| eval LastCheckin=strftime(LastCheckin,"%m-%d-%Y %H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;A couple of things to note:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;App checks in every couple minutes, so for testing the search only checks for events older than 30 seconds ago as I know there are events older than that.&lt;/LI&gt;
&lt;LI&gt;Threshold field is included in stats to verify value is in fact evaled correctly&lt;/LI&gt;
&lt;LI&gt;Taking out the where function will display results as expected&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;I have another search using inputlookup that does work using the same type of format:&lt;/P&gt;

&lt;P&gt;| inputlookup hosts.csv&lt;BR /&gt;
    | eval drop_off=now()-1728000&lt;BR /&gt;
    | where latest &amp;lt; drop_off&lt;BR /&gt;
    | stats values(latest) as latest by hostname&lt;BR /&gt;
    | outputlookup hosts_dropoff.csv&lt;BR /&gt;
Any thoughts as to why I am getting these results?  As I know inputlookup works for another case, I could apply it to this search but would rather not add another step to this process.&lt;/P&gt;&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:41:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Where-function-not-calculating-fields-as-expected/m-p/439488#M125012</guid>
      <dc:creator>cshadduck</dc:creator>
      <dc:date>2020-09-30T01:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: Where function not calculating fields as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Where-function-not-calculating-fields-as-expected/m-p/439489#M125013</link>
      <description>&lt;P&gt;You should &lt;EM&gt;never&lt;/EM&gt; use &lt;CODE&gt;latest(_time)&lt;/CODE&gt; but instead always &lt;CODE&gt;max(_time)&lt;/CODE&gt;; also, use &lt;CODE&gt;fieldformat&lt;/CODE&gt; be sure that you maintain integer aspect of time fields.  The main problem is that you did not name &lt;CODE&gt;threshold&lt;/CODE&gt; so the field created is &lt;CODE&gt;values(threshold)&lt;/CODE&gt;.  This still may not working because &lt;CODE&gt;values()&lt;/CODE&gt; creates a &lt;CODE&gt;multivalue&lt;/CODE&gt; field, perhaps even when there is only 1.  Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main sourcetype="app:agent" hostname IN("host1", "host2", "host3")
| eval hostname=upper(hostname)
| eval threshold=now()-30
| stats latest(_time) as LastCheckin max(threshold) AS threshold BY computer_name
| where LastCheckin&amp;lt;threshold
| fieldformat LastCheckin=strftime(LastCheckin,"%m-%d-%Y %H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Aug 2019 23:19:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Where-function-not-calculating-fields-as-expected/m-p/439489#M125013</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-08-12T23:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Where function not calculating fields as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Where-function-not-calculating-fields-as-expected/m-p/439490#M125014</link>
      <description>&lt;P&gt;Thanks, I like fieldformat as it makes more sense.  Why is max(_time) better than latest(_time)?&lt;/P&gt;

&lt;P&gt;As for the results, it is still not filtering the events.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:45:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Where-function-not-calculating-fields-as-expected/m-p/439490#M125014</guid>
      <dc:creator>cshadduck</dc:creator>
      <dc:date>2020-09-30T01:45:21Z</dc:date>
    </item>
    <item>
      <title>Re: Where function not calculating fields as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Where-function-not-calculating-fields-as-expected/m-p/439491#M125015</link>
      <description>&lt;P&gt;Using &lt;CODE&gt;max&lt;/CODE&gt; has half the work and in the past has actually been more reliable.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2019 14:02:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Where-function-not-calculating-fields-as-expected/m-p/439491#M125015</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-08-13T14:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Where function not calculating fields as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Where-function-not-calculating-fields-as-expected/m-p/439492#M125016</link>
      <description>&lt;P&gt;This is not working because you did not name threshold so it has the name &lt;CODE&gt;values(threshold)&lt;/CODE&gt; and also &lt;CODE&gt;values()&lt;/CODE&gt; creates a &lt;CODE&gt;multivalue&lt;/CODE&gt; field, perhaps even when there is only 1.  Try my updated answer.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2019 14:04:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Where-function-not-calculating-fields-as-expected/m-p/439492#M125016</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-08-13T14:04:40Z</dc:date>
    </item>
    <item>
      <title>Re: Where function not calculating fields as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Where-function-not-calculating-fields-as-expected/m-p/439493#M125017</link>
      <description>&lt;P&gt;So I am at a loss as to why it is working now but it simply needed spaces before and after the &amp;lt; sign.  I had tried all these combinations but for whatever reason it started working this morning.  Maybe it had something to do with the other changes to the search in combination with that.  Whatever the case it is working now:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main sourcetype="app:agent" hostname IN (host1 host2 host3)
 | eval hostname=upper(hostname)
 | eval threshold=now()-30
 | stats max(_time) as LastCheckin values(threshold) by computer_name
 | where LastCheckin &amp;lt; threshold
 | timeformat LastCheckin=strftime(LastCheckin,"%m-%d-%Y %H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks for all the help everyone.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2019 15:46:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Where-function-not-calculating-fields-as-expected/m-p/439493#M125017</guid>
      <dc:creator>cshadduck</dc:creator>
      <dc:date>2019-08-13T15:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: Where function not calculating fields as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Where-function-not-calculating-fields-as-expected/m-p/439494#M125018</link>
      <description>&lt;P&gt;This is wrong and cannot (and therefore DOES not) work.  You DO NOT have any field named &lt;CODE&gt;threshold&lt;/CODE&gt;.  That is the whole problem.  See my answer below (which was modified since first posting) for a complete fix.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2019 17:15:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Where-function-not-calculating-fields-as-expected/m-p/439494#M125018</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-08-13T17:15:26Z</dc:date>
    </item>
  </channel>
</rss>

