<?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: null variables in eval if in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167370#M47655</link>
    <description>&lt;P&gt;As @martin_mueller says, there are many fundamental problems with your search including all that he notes but even if everything that he notes is fixed, any time you compare an event's timestamp to &lt;CODE&gt;now()&lt;/CODE&gt;, it should &lt;EM&gt;always&lt;/EM&gt; be less than; your example is looking for events in the future than have not occurred yet! &lt;CODE&gt;&amp;gt;now()&lt;/CODE&gt;!&lt;/P&gt;</description>
    <pubDate>Fri, 19 Jun 2015 13:08:37 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2015-06-19T13:08:37Z</dc:date>
    <item>
      <title>null variables in eval if</title>
      <link>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167367#M47652</link>
      <description>&lt;P&gt;I'm trying to list the last logged event for each permutation of my two logged fields (columns).  If the last event was too long ago, I want to output "dead" for that combination of the two columns.&lt;/P&gt;

&lt;P&gt;My queries thus far are using eval with if.  However I can't get the if statement to work with my column values.&lt;/P&gt;

&lt;P&gt;If I make a dummy query,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;hello_world_name=* host=* | stats max(timestamp) by hello_world_name, host | eval awol=if(1&amp;gt;0,"dead","live") | fields hello_world_name, host, awol, max(timestamp)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will output "dead", because 1 &amp;gt; 0 evaluates to true.  That seems right !  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;However, this one doesn't work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;hello_world_name=* host=* | stats max(timestamp) by hello_world_name, host | eval awol=if(max(timestamp)&amp;lt;0,"dead","live") | fields hello_world_name, host, awol, max(timestamp)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What happens is, the value in the predicate of the "if" always evaluates to false.  &lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;max(timestamp) compared to anything is always false (or null?)&lt;/LI&gt;
&lt;LI&gt;if I replace the tested value with "timestamp", it still doesn't work - "timestamp" compared to anything is always false (or null?)&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;This one doesn't work either:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;hello_world_name=* host=* | stats max(timestamp) as bob by hello_world_name, host | eval awol=if(bob&amp;gt;now(),"dead","live") | fields hello_world_name, host, awol, bob
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What happens is, even though "bob" is a real value, as evidenced by the column labeled "bob", no matter if the predicate is set "bob&amp;gt;now()" or "bob&amp;lt;now()", the answer is always as if it is false - the value of awol is "live".&lt;/P&gt;

&lt;P&gt;What is the deal?  Am I using eval incorrectly?  How do I test fields from elsewhere in the query?&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2015 04:26:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167367#M47652</guid>
      <dc:creator>brianpreston</dc:creator>
      <dc:date>2015-06-19T04:26:47Z</dc:date>
    </item>
    <item>
      <title>Re: null variables in eval if</title>
      <link>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167368#M47653</link>
      <description>&lt;P&gt;try adding something like this after your stats command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval awol = max(timestamp)
| table awol
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That will show you what awol is calculating to and you can then adjust accordingly.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2015 05:34:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167368#M47653</guid>
      <dc:creator>hogan24</dc:creator>
      <dc:date>2015-06-19T05:34:27Z</dc:date>
    </item>
    <item>
      <title>Re: null variables in eval if</title>
      <link>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167369#M47654</link>
      <description>&lt;P&gt;There's a key misunderstanding in your query.&lt;/P&gt;

&lt;P&gt;If a host is "dead", ie has no events in your time range, there won't be any events in your time range. As a result, it won't even have a row to evaluate the &lt;CODE&gt;awol&lt;/CODE&gt; value for that host.&lt;/P&gt;

&lt;P&gt;Another issue, what format is your &lt;CODE&gt;timestamp&lt;/CODE&gt; field using? Comparing &lt;CODE&gt;now()&lt;/CODE&gt; with a string won't make sense, for example.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2015 12:12:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167369#M47654</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-06-19T12:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: null variables in eval if</title>
      <link>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167370#M47655</link>
      <description>&lt;P&gt;As @martin_mueller says, there are many fundamental problems with your search including all that he notes but even if everything that he notes is fixed, any time you compare an event's timestamp to &lt;CODE&gt;now()&lt;/CODE&gt;, it should &lt;EM&gt;always&lt;/EM&gt; be less than; your example is looking for events in the future than have not occurred yet! &lt;CODE&gt;&amp;gt;now()&lt;/CODE&gt;!&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2015 13:08:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167370#M47655</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-06-19T13:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: null variables in eval if</title>
      <link>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167371#M47656</link>
      <description>&lt;P&gt;Thanks, but the "fields" clause already shows the values -- they are how I know the predicate isn't doing what I want.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2015 15:19:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167371#M47656</guid>
      <dc:creator>brianpreston</dc:creator>
      <dc:date>2015-06-19T15:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: null variables in eval if</title>
      <link>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167372#M47657</link>
      <description>&lt;P&gt;I'm sorry, I think I left out a key element which I thought would be implied by the fields in the query.&lt;/P&gt;

&lt;P&gt;There will be events - they will just be old.  My intention is for the final version of the query to test "timestamp" for its difference from now().  For example something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if (max(timestamp - now()) &amp;gt; 600, ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jun 2015 15:21:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167372#M47657</guid>
      <dc:creator>brianpreston</dc:creator>
      <dc:date>2015-06-19T15:21:57Z</dc:date>
    </item>
    <item>
      <title>Re: null variables in eval if</title>
      <link>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167373#M47658</link>
      <description>&lt;P&gt;Some how my answer got clipped; it is repaired now.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2015 15:26:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167373#M47658</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-06-19T15:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: null variables in eval if</title>
      <link>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167374#M47659</link>
      <description>&lt;P&gt;Thanks woodcock, but that is not the problem.  As I mentioned in the text of my question,&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;What happens is, even though "bob" is&lt;BR /&gt;
a real value, as evidenced by the&lt;BR /&gt;
column labeled "bob", no matter if the&lt;BR /&gt;
predicate is set "bob&amp;gt;now()" or&lt;BR /&gt;
"bob if it is false - the value of awol is&lt;BR /&gt;
"live".&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Fri, 19 Jun 2015 16:57:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167374#M47659</guid>
      <dc:creator>brianpreston</dc:creator>
      <dc:date>2015-06-19T16:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: null variables in eval if</title>
      <link>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167375#M47660</link>
      <description>&lt;P&gt;query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;hello_world_name=* host=* | stats max(timestamp) by hello_world_name, host | eval awol=if(max(timestamp)&amp;gt;0,"dead","live") | fields hello_world_name, host, awol, max(timestamp)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;result:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;hello_world_name    host    awol    max(timestamp)
1   inabanoirousagi live    2015-02-04 03:32:32,910
bloobloo    inabanoirousagi live    2015-06-18 21:16:43,910
fnord   inabanoirousagi live    2015-06-17 20:43:20,860
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;query: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;hello_world_name=* host=* | stats max(timestamp) as bob by hello_world_name, host | eval awol=if(bob&amp;gt;now(),"dead","live") | fields hello_world_name, host, awol, bob
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;result:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;hello_world_name    host    awol    bob
1   inabanoirousagi live    2015-02-04 03:32:32,910
bloobloo    inabanoirousagi live    2015-06-18 21:16:43,910
fnord   inabanoirousagi live    2015-06-17 20:43:20,860
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jun 2015 17:00:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167375#M47660</guid>
      <dc:creator>brianpreston</dc:creator>
      <dc:date>2015-06-19T17:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: null variables in eval if</title>
      <link>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167376#M47661</link>
      <description>&lt;P&gt;&lt;STRONG&gt;timestamp&lt;/STRONG&gt; is still a string, and even &lt;STRONG&gt;max(timestamp)&lt;/STRONG&gt; is still a string.  It looks like when comparing against integers the answer will always be &lt;STRONG&gt;false&lt;/STRONG&gt;.&lt;/P&gt;

&lt;P&gt;Ways around this:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;use &lt;STRONG&gt;_time&lt;/STRONG&gt; instead of the original parsed timestamp.  This will be Splunk's guess at the timestamp.  I think it might be derived from the field it recognizes as a timestamp.&lt;/LI&gt;
&lt;LI&gt;parse the timestamp field into an integer with &lt;STRONG&gt;strptime&lt;/STRONG&gt; .  This can be a little dicey, so it's more reliable to use &lt;STRONG&gt;_time&lt;/STRONG&gt;&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Fri, 19 Jun 2015 17:39:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/null-variables-in-eval-if/m-p/167376#M47661</guid>
      <dc:creator>brianpreston</dc:creator>
      <dc:date>2015-06-19T17:39:20Z</dc:date>
    </item>
  </channel>
</rss>

