<?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: Using lookups, determine if search is null. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-lookups-determine-if-search-is-null/m-p/449560#M127292</link>
    <description>&lt;P&gt;I didn't realize that my question was so difficult.  I will add some additional input here to try and clarify my issue.  Lets say I have my lookup table and it looks something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Location, Vendor, dns_name, host-ip, host-short-name
Location-A, Vendor-Bob, hostA.networkA.com, 1.1.1.1, hostA
Location-B, Vendor-Bob, hostB.networkB.com, 2.2.2.2, hostB
Location-C, Vendor-Bob, hostC.networkC.com, 3.3.3.3, hostC
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now, in the code above, I use the host-ip from the lookup table to search an index for records based on the dvc field.  As long as there is a match, I get output in a table.  In the example below I match on 1.1.1.1 and 3.3.3.3, but not 2.2.2.2.  My output table looks like this;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Line added to the code above:

| table Vendor Location short-name dvc clean_since

OUTPUT:
Vendor-Bob    Location-A    hostA    1.1.1.1     4567
Vendor-Bob    Location-C    hostC    3.3.3.3       789    
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I need is the output table to include all the host-ips in the lookup table even is there is no match.  The "clean_since" field will default to some default value.  It should look something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; OUTPUT:
 Vendor-Bob    Location-A    hostA    1.1.1.1     4567
Vendor-Bob     Location-B    hostB    2.2.2.2     10000
 Vendor-Bob    Location-C    hostC    3.3.3.3      789
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I hope this clears up some things.  I really need some kind of solution soon.&lt;/P&gt;</description>
    <pubDate>Thu, 09 May 2019 18:50:23 GMT</pubDate>
    <dc:creator>OldManEd</dc:creator>
    <dc:date>2019-05-09T18:50:23Z</dc:date>
    <item>
      <title>Using lookups, determine if search is null.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-lookups-determine-if-search-is-null/m-p/449557#M127289</link>
      <description>&lt;P&gt;I have a lookup table where the columns are formatted as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Location, Vendor, dns_name, host-ip, host-short-name
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My search is here:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=&amp;lt;undex name&amp;gt;

| search [| inputlookup device-list 
          | search Vendor=&amp;lt;Some Vendor Name&amp;gt; 
          | fields host-ip
          | rename host-ip AS dvc
          | format] 

| lookup device-list host-ip AS dvc 

| stats latest(_time) AS last_seen by Vendor Location short-name dvc
| eval time_since = ((now() - last_seen) / 60)
| eval clean_since = round(time_since, 0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Everything works fine when there are records returned from the "| lookup device-list host-ip AS dvc"  section.  What I need is a way to determine if no events were returned.  If no records were returned, I would like to create a table entry with the data from the lookup table and add some default variable values.  I have not been able to figure out a way to accomplish that.  My biggest problem is how to determine if no records were returned from the search and keep the lookuptable data. &lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 18:15:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-lookups-determine-if-search-is-null/m-p/449557#M127289</guid>
      <dc:creator>OldManEd</dc:creator>
      <dc:date>2019-05-08T18:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using lookups, determine if search is null.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-lookups-determine-if-search-is-null/m-p/449558#M127290</link>
      <description>&lt;P&gt;Try &lt;CODE&gt;coalesce&lt;/CODE&gt;.  It checks if the first argument is null and, if so, applies the second argument.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=&amp;lt;undex name&amp;gt;
| search [| inputlookup device-list 
           | search Vendor=&amp;lt;Some Vendor Name&amp;gt; 
           | fields host-ip
           | rename host-ip AS dvc
           | format] 
| lookup device-list host-ip AS dvc 
| eval Location=coalesce(Location, "default Location"), Vendor=coalesce(Vendor, "default Vendor"), dns_name=coalesce(dns_name, "default DNS name"), host-short-name=coalesce(host-short-name, "Default short name")
| stats latest(_time) AS last_seen by Vendor Location short-name dvc
| eval time_since = ((now() - last_seen) / 60)
| eval clean_since = round(time_since, 0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 May 2019 20:14:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-lookups-determine-if-search-is-null/m-p/449558#M127290</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2019-05-08T20:14:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using lookups, determine if search is null.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-lookups-determine-if-search-is-null/m-p/449559#M127291</link>
      <description>&lt;P&gt;I tried it but it didn't work.  The results only display for those records that are returned from the "| lookup device-list host-ip AS dvc" search.  If there is no match for host-ip/dvc, nothing is displayed.  I need to display some data for ALL host-ip entries.&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 13:13:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-lookups-determine-if-search-is-null/m-p/449559#M127291</guid>
      <dc:creator>OldManEd</dc:creator>
      <dc:date>2019-05-09T13:13:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using lookups, determine if search is null.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-lookups-determine-if-search-is-null/m-p/449560#M127292</link>
      <description>&lt;P&gt;I didn't realize that my question was so difficult.  I will add some additional input here to try and clarify my issue.  Lets say I have my lookup table and it looks something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Location, Vendor, dns_name, host-ip, host-short-name
Location-A, Vendor-Bob, hostA.networkA.com, 1.1.1.1, hostA
Location-B, Vendor-Bob, hostB.networkB.com, 2.2.2.2, hostB
Location-C, Vendor-Bob, hostC.networkC.com, 3.3.3.3, hostC
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now, in the code above, I use the host-ip from the lookup table to search an index for records based on the dvc field.  As long as there is a match, I get output in a table.  In the example below I match on 1.1.1.1 and 3.3.3.3, but not 2.2.2.2.  My output table looks like this;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Line added to the code above:

| table Vendor Location short-name dvc clean_since

OUTPUT:
Vendor-Bob    Location-A    hostA    1.1.1.1     4567
Vendor-Bob    Location-C    hostC    3.3.3.3       789    
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I need is the output table to include all the host-ips in the lookup table even is there is no match.  The "clean_since" field will default to some default value.  It should look something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; OUTPUT:
 Vendor-Bob    Location-A    hostA    1.1.1.1     4567
Vendor-Bob     Location-B    hostB    2.2.2.2     10000
 Vendor-Bob    Location-C    hostC    3.3.3.3      789
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I hope this clears up some things.  I really need some kind of solution soon.&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 18:50:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-lookups-determine-if-search-is-null/m-p/449560#M127292</guid>
      <dc:creator>OldManEd</dc:creator>
      <dc:date>2019-05-09T18:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using lookups, determine if search is null.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-lookups-determine-if-search-is-null/m-p/449561#M127293</link>
      <description>&lt;P&gt;OK, no answer yet.  Perhaps another way of asking this question is, can I print out the lookup table data, even if the search returns no events?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2019 16:39:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-lookups-determine-if-search-is-null/m-p/449561#M127293</guid>
      <dc:creator>OldManEd</dc:creator>
      <dc:date>2019-06-13T16:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: Using lookups, determine if search is null.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-lookups-determine-if-search-is-null/m-p/449562#M127294</link>
      <description>&lt;P&gt;Well, I got it.  For those of you that are interested, I rewrote the search using a join.  This one was interesting to say the least.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup &amp;lt;lookup name&amp;gt;
| search Vendor="&amp;lt;Specific name of Vendor"
| fields dns-name, Location, Vendor, short-name
| rename dns-name AS host
| sort host
| eval lastTime=0

| join type=left host [  | metadata type=hosts
                                        | lookup &amp;lt;lookup name&amp;gt; dns-name AS host ]

| eval secondsAgo = now() - lastTime
| eval durationStr=if(secondsAgo&amp;gt;1560807101,"No Events Ever Seen", tostring(secondsAgo, "duration"))

| rename short-name AS "Server Name",
                  durationStr AS "Time Since Last Event",
                               host AS "DNS Name"

| table "Vendor" "Location" "Server Name" "DNS Name" "Time Since Last Event"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now, when I run the search I get the following output:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Vendor      Location    Server Name    DNS Name    Time Since Last Event Seen
VendorA    Denver      &amp;lt;hostname&amp;gt;    &amp;lt;dnsname&amp;gt;    01:56:29
VendorA    Chicago     &amp;lt;hostname&amp;gt;    &amp;lt;dnsname&amp;gt;    No Events Ever Seen
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note:  The 1560807101 value for the durationStr calculation was just something I pulled out of the air that was large enough to not cause issues.  I think I used the difference between when I wrote this and "12/31/1969 at 17:00:00".  &lt;/P&gt;

&lt;P&gt;Life is good.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 19:44:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-lookups-determine-if-search-is-null/m-p/449562#M127294</guid>
      <dc:creator>OldManEd</dc:creator>
      <dc:date>2019-06-20T19:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using lookups, determine if search is null.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-lookups-determine-if-search-is-null/m-p/449563#M127295</link>
      <description>&lt;P&gt;Hi - if you're still looking, this may be what you're after. I had a similar question a few years ago. &lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/331715/how-do-i-get-an-automatic-lookup-to-populate-a-tab.html#answer-331720"&gt;https://answers.splunk.com/answers/331715/how-do-i-get-an-automatic-lookup-to-populate-a-tab.html#answer-331720&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 17:09:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-lookups-determine-if-search-is-null/m-p/449563#M127295</guid>
      <dc:creator>cchimento</dc:creator>
      <dc:date>2020-05-05T17:09:09Z</dc:date>
    </item>
  </channel>
</rss>

