<?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: Compare search to lookup table and return results unique to search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Compare-search-to-lookup-table-and-return-results-unique-to/m-p/204456#M59389</link>
    <description>&lt;P&gt;Until recently, I would have given the same advice but using &lt;CODE&gt;append&lt;/CODE&gt; incurs severe number-of-event limits which can be avoided by using &lt;CODE&gt;appendcols&lt;/CODE&gt; instead.  See this interesting Q&amp;amp;A for details:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/318428/how-can-i-append-and-escape-the-50k-subsearch-limi.html"&gt;https://answers.splunk.com/answers/318428/how-can-i-append-and-escape-the-50k-subsearch-limi.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Given this, I stand by my answer as-is.&lt;/P&gt;</description>
    <pubDate>Fri, 23 Oct 2015 15:24:59 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2015-10-23T15:24:59Z</dc:date>
    <item>
      <title>Compare search to lookup table and return results unique to search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-search-to-lookup-table-and-return-results-unique-to/m-p/204451#M59384</link>
      <description>&lt;P&gt;I have a search that tells me when a system doesn't report into splunk after a threshold of an hour:&lt;/P&gt;

&lt;P&gt;|metadata index=vmware type=hosts  | eval timenow=now() | eval lastseen=timenow-recentTime | where lastseen &amp;gt; 3600 | eval last_seen=tostring(lastseen, "duration") | table host last_seen&lt;/P&gt;

&lt;P&gt;Then I have a lookup csv that is driven by a dashboard that allows users to enter systems that are in maintenance mode or decommissioned.  If a system hits the threshold from the first search but is listed in the csv I don't want it to fire the alert. The lookup table is called decom_maint_systems.csv.&lt;/P&gt;

&lt;P&gt;I can get the correct hostname by using set diff but the problem is I lose the "last_seen" field which I really want to keep.  So how do I compare the two while keeping the fields I want from the initial search?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 07:42:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-search-to-lookup-table-and-return-results-unique-to/m-p/204451#M59384</guid>
      <dc:creator>hlarimer</dc:creator>
      <dc:date>2020-09-29T07:42:20Z</dc:date>
    </item>
    <item>
      <title>Re: Compare search to lookup table and return results unique to search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-search-to-lookup-table-and-return-results-unique-to/m-p/204452#M59385</link>
      <description>&lt;P&gt;As we discussed on the Splunk Usergroups Slack (&lt;A href="http://splunk402.com/chat"&gt;signup request form&lt;/A&gt;) one option would be to use the subsearch retrieving the hosts in maintenance mode and inject that into a where clause... e.g.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| metadata ... | ... | where NOT [inputlookup ... | table host] 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Oct 2015 14:25:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-search-to-lookup-table-and-return-results-unique-to/m-p/204452#M59385</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2015-10-23T14:25:09Z</dc:date>
    </item>
    <item>
      <title>Re: Compare search to lookup table and return results unique to search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-search-to-lookup-table-and-return-results-unique-to/m-p/204453#M59386</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|metadata index=vmware type=hosts | eval timenow=now() | eval lastseen=timenow-recentTime | where lastseen &amp;gt; 3600 | eval last_seen=tostring(lastseen, "duration") | eval type="search" | table host last_seen type| appendpipe [|inputlookup decom_main_systems.csv] | eval type=coalesce(type, "inputlookup") | stats dc(type) AS numTypes* AS * by host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This gives the fully merged set (full join). For each function, tack on the appropriate remaining search string:&lt;/P&gt;

&lt;P&gt;For your case:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| where numTypes=1 AND type="search"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For XOR (outer join):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| where numTypes= 1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For left join:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| where type="search"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For right join:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| where type="inputlookup"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For inner join:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| where numTypes&amp;gt;1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Oct 2015 14:28:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-search-to-lookup-table-and-return-results-unique-to/m-p/204453#M59386</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-10-23T14:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: Compare search to lookup table and return results unique to search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-search-to-lookup-table-and-return-results-unique-to/m-p/204454#M59387</link>
      <description>&lt;P&gt;That works perfectly!  Thanks for your quick response!&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 14:29:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-search-to-lookup-table-and-return-results-unique-to/m-p/204454#M59387</guid>
      <dc:creator>hlarimer</dc:creator>
      <dc:date>2015-10-23T14:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: Compare search to lookup table and return results unique to search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-search-to-lookup-table-and-return-results-unique-to/m-p/204455#M59388</link>
      <description>&lt;P&gt;Be careful... I think you want &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.3.0/SearchReference/append"&gt;append&lt;/A&gt; instead of &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.3.0/SearchReference/appendcols"&gt;appendcols&lt;/A&gt; as the former adds new events to the result set the latter just tacks on fields to existing events (without regard to fields matching, it's just first results are combined, second results, etc) For example, check out: &lt;CODE&gt;|noop | stats count | fields | eval foo=mvrange(1,10,1) | mvexpand foo | appendcols [noop | stats count | fields | eval bar=mvrange(1,10,1) | mvexpand bar |reverse]&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Your setting of type for the inputlookup should then be a simple eval inside the subsearch of append, and you need to use a statistical function for all other fields... (e.g. &lt;CODE&gt;stats values(*) as * by host&lt;/CODE&gt; ) But then you can pipe to a where command as you mention.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 15:12:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-search-to-lookup-table-and-return-results-unique-to/m-p/204455#M59388</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2015-10-23T15:12:31Z</dc:date>
    </item>
    <item>
      <title>Re: Compare search to lookup table and return results unique to search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-search-to-lookup-table-and-return-results-unique-to/m-p/204456#M59389</link>
      <description>&lt;P&gt;Until recently, I would have given the same advice but using &lt;CODE&gt;append&lt;/CODE&gt; incurs severe number-of-event limits which can be avoided by using &lt;CODE&gt;appendcols&lt;/CODE&gt; instead.  See this interesting Q&amp;amp;A for details:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/318428/how-can-i-append-and-escape-the-50k-subsearch-limi.html"&gt;https://answers.splunk.com/answers/318428/how-can-i-append-and-escape-the-50k-subsearch-limi.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Given this, I stand by my answer as-is.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 15:24:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-search-to-lookup-table-and-return-results-unique-to/m-p/204456#M59389</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-10-23T15:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: Compare search to lookup table and return results unique to search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-search-to-lookup-table-and-return-results-unique-to/m-p/204457#M59390</link>
      <description>&lt;P&gt;Did you know that in your link you're using &lt;CODE&gt;appendpipe&lt;/CODE&gt; in all your searches, but drawing a conclusion about &lt;CODE&gt;appendcols&lt;/CODE&gt;? It's an interesting abuse of &lt;CODE&gt;appendpipe&lt;/CODE&gt; However one should note that in the general case &lt;CODE&gt;appendpipe [search ...]&lt;/CODE&gt; will give you very different results than &lt;CODE&gt;append [search ...]&lt;/CODE&gt; and &lt;CODE&gt;appendcols [search ...]&lt;/CODE&gt; as the latter two go back to indexes from disk to add results, but the former will only add rows and filter results from before the command. &lt;/P&gt;

&lt;P&gt;Actually as I was writing this, I was trying to figure out how appendpipe allowed you to use &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.3.0/SearchReference/inputlookup"&gt;inputlookup&lt;/A&gt; and it seems like not only does appendpipe allow generation commands, but also there's a very useful &lt;CODE&gt;append=true&lt;/CODE&gt; parameter in inputlookup so &lt;CODE&gt;| append [inputlookup ]&lt;/CODE&gt; or &lt;CODE&gt;| appendpipe [inputlookup ]&lt;/CODE&gt; is more simply written as &lt;CODE&gt;| inputlookup append=true&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;For completeness I'll note that &lt;CODE&gt;appendcols&lt;/CODE&gt; has the same subsearch limitations as &lt;CODE&gt;append&lt;/CODE&gt; (note the same sections in the docs about subsearch options). And I'll note that &lt;CODE&gt;appendcols&lt;/CODE&gt; will throw an error if not used after a reporting command like stats ("Error in 'appendcols' command: You can only use appendcols after a reporting command (such as stats, chart, or timechart)."). But ignoring all that &lt;CODE&gt;appendcols&lt;/CODE&gt; is still the wrong command because it'll only add results if the set being appended is longer than the original set and it does not care about any matching of fields. In this specific case, let's have an example, where your search prior to appendcols returns 3 rows (in order) host A, B, and C. Let's say that your lookup contains only 2 rows, (in order) host D and B. From these two sets of data, we would want the resulting set to be 2 rows A and C however after the appendcols command your result set will be exactly the same as before the appendcols command (since host is in both sets of data, the host field is taken from the source set by default, and since your lookup has fewer rows than your source set, no additional results are added). Your eval with coalesce will do nothing since all of your results already have the field type set on them (from before the appendcols ) and thus nothing will be excluded with your where afterwards.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 19:00:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-search-to-lookup-table-and-return-results-unique-to/m-p/204457#M59390</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2015-10-23T19:00:23Z</dc:date>
    </item>
    <item>
      <title>Re: Compare search to lookup table and return results unique to search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-search-to-lookup-table-and-return-results-unique-to/m-p/204458#M59391</link>
      <description>&lt;P&gt;All good points, especially about &lt;CODE&gt;appendcols&lt;/CODE&gt; which I never should have mentioned, as you noted.  The mistake in my answer has been corrected (re-edited); it is now &lt;CODE&gt;appendpipe&lt;/CODE&gt;.  I am not at all convinced that your commands equivalency is entirely correct but I will retry and see and update the other Q&amp;amp;A.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 21:08:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-search-to-lookup-table-and-return-results-unique-to/m-p/204458#M59391</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-10-23T21:08:09Z</dc:date>
    </item>
  </channel>
</rss>

