<?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 How do you use a subsearch with a 'table' command? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-a-subsearch-with-a-table-command/m-p/431320#M123296</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;In order to detect unused workstations in our computer park, we are searching for all assets not connected to Active Directory (AD) AND to Ghost Solution Suite (GSS) since &amp;gt;90 days.&lt;/P&gt;

&lt;P&gt;We can easily perform two searches independently, which are basically the same. First one:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=my_ad_sourcetype
| eval it = strptime(ad_last_inventory,"%Y-%m-%d")
| eval ot = strptime(nowstring,"%Y-%m-%d")
| eval diff = (ot - it)
| eval round = round(diff/86400, 0)
| search round &amp;gt; 90
| table ad_wks_name, ad_last_inventory
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And the second one:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=my_gss_sourcetype
| eval it = strptime(gss_last_inventory,"%Y-%m-%d")
| eval ot = strptime(nowstring,"%Y-%m-%d")
| eval diff = (ot - it)
| eval round = round(diff/86400, 0)
| search round &amp;gt; 90
| table gss_wks_name, gss_last_inventory
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What we can’t do is to combine those two searches. We tried to execute one of two queries as a subsearch and perform a simple comparison at the end like: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| where gss_wks_name=ad_wks_name 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Every time we face an issue, the main search is executed correctly, but the subsearch doesn’t give out the correct result. Instead it repeats the &lt;CODE&gt;_wks_name&lt;/CODE&gt; and the &lt;CODE&gt;_last_inventory&lt;/CODE&gt; date for the last workstation.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;wks_123 | 2018-10-20 23:12:00.0
wks_123 | 2018-10-20 23:12:00.0
wks_123 | 2018-10-20 23:12:00.0
etc.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Do you have an idea what we're doing wrong?&lt;/P&gt;

&lt;P&gt;Thanks for the help!&lt;/P&gt;

&lt;P&gt;Alex.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Jan 2019 12:28:52 GMT</pubDate>
    <dc:creator>AlexeySh</dc:creator>
    <dc:date>2019-01-29T12:28:52Z</dc:date>
    <item>
      <title>How do you use a subsearch with a 'table' command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-a-subsearch-with-a-table-command/m-p/431320#M123296</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;In order to detect unused workstations in our computer park, we are searching for all assets not connected to Active Directory (AD) AND to Ghost Solution Suite (GSS) since &amp;gt;90 days.&lt;/P&gt;

&lt;P&gt;We can easily perform two searches independently, which are basically the same. First one:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=my_ad_sourcetype
| eval it = strptime(ad_last_inventory,"%Y-%m-%d")
| eval ot = strptime(nowstring,"%Y-%m-%d")
| eval diff = (ot - it)
| eval round = round(diff/86400, 0)
| search round &amp;gt; 90
| table ad_wks_name, ad_last_inventory
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And the second one:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=my_gss_sourcetype
| eval it = strptime(gss_last_inventory,"%Y-%m-%d")
| eval ot = strptime(nowstring,"%Y-%m-%d")
| eval diff = (ot - it)
| eval round = round(diff/86400, 0)
| search round &amp;gt; 90
| table gss_wks_name, gss_last_inventory
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What we can’t do is to combine those two searches. We tried to execute one of two queries as a subsearch and perform a simple comparison at the end like: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| where gss_wks_name=ad_wks_name 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Every time we face an issue, the main search is executed correctly, but the subsearch doesn’t give out the correct result. Instead it repeats the &lt;CODE&gt;_wks_name&lt;/CODE&gt; and the &lt;CODE&gt;_last_inventory&lt;/CODE&gt; date for the last workstation.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;wks_123 | 2018-10-20 23:12:00.0
wks_123 | 2018-10-20 23:12:00.0
wks_123 | 2018-10-20 23:12:00.0
etc.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Do you have an idea what we're doing wrong?&lt;/P&gt;

&lt;P&gt;Thanks for the help!&lt;/P&gt;

&lt;P&gt;Alex.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 12:28:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-a-subsearch-with-a-table-command/m-p/431320#M123296</guid>
      <dc:creator>AlexeySh</dc:creator>
      <dc:date>2019-01-29T12:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use a subsearch with a 'table' command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-a-subsearch-with-a-table-command/m-p/431321#M123297</link>
      <description>&lt;P&gt;@AlexeySh ,&lt;/P&gt;

&lt;P&gt;Assuming that you have only one record per workstation, i.e. last_inventory is the latest value of that machine&lt;/P&gt;

&lt;P&gt;Try this and lets know if there are some changes,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  sourcetype=my_ad_sourcetype OR sourcetype=my_gss_sourcetype
  |eval itAd=strptime(ad_last_inventory,"%Y-%m-%d"), itGss=strptime(gss_last_inventory,"%Y-%m-%d")
  |eval ot=strptime(nowstring,"%Y-%m-%d")
  |eval diffAd=round((ot-itAd)/86400,0) , diffGss=round((ot-itGss)/86400,0)
  |eval wks_name=coalesce(ad_wks_name,gss_wks_name)
  |table wks_name,diffAd,diffGss |fillnull value=0
  |stats max(diffAd) as diffAd,max(diffGss) as diffGss by wks_name
  |where diffAd&amp;gt;90 AND diffGss&amp;gt;90
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Jan 2019 14:56:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-a-subsearch-with-a-table-command/m-p/431321#M123297</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2019-01-29T14:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use a subsearch with a 'table' command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-a-subsearch-with-a-table-command/m-p/431322#M123298</link>
      <description>&lt;P&gt;Gorgeous !&lt;/P&gt;

&lt;P&gt;That's exectly what we were searching for.&lt;/P&gt;

&lt;P&gt;Thanks for the help! &lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 15:59:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-use-a-subsearch-with-a-table-command/m-p/431322#M123298</guid>
      <dc:creator>AlexeySh</dc:creator>
      <dc:date>2019-01-29T15:59:03Z</dc:date>
    </item>
  </channel>
</rss>

