<?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: How can I use the results of a search in a second search? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-use-the-results-of-a-search-in-a-second-search/m-p/292029#M88199</link>
    <description>&lt;P&gt;from my understanding, I believe you have to add search inside the bracket something like this:&lt;/P&gt;

&lt;P&gt;index=dnslogs sourcetype=ptr_data &lt;BR /&gt;
     [&lt;STRONG&gt;&lt;EM&gt;search&lt;/EM&gt;&lt;/STRONG&gt; your first query | stats count by dest | fields dest | rename dest as dns_name ]&lt;BR /&gt;
 | stats values(query) by dns_name&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 04:50:57 GMT</pubDate>
    <dc:creator>chicoocholoco</dc:creator>
    <dc:date>2020-09-30T04:50:57Z</dc:date>
    <item>
      <title>How can I use the results of a search in a second search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-use-the-results-of-a-search-in-a-second-search/m-p/292025#M88195</link>
      <description>&lt;P&gt;I'm running a query which returns destination ip address of external traffic of a user in one column something like that:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;----dest-----
1.2.3.4
23.23.23.23
45.45.45.45
67.67.67.67
4.3.2.1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which means the user access the IP addresses listed above (last 15 minutes for example)&lt;/P&gt;

&lt;P&gt;I'm also running a different query to make DNS ptr record check of a given ip address something like that:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=dnslogs sourcetype=ptr_data dns_name="1.2.3.4" | stats values(query)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and it returns something like that:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;----------DNS Value---------
 google.com
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I'm trying to do is: &lt;BR /&gt;
&lt;STRONG&gt;AFTER&lt;/STRONG&gt; my first query &lt;STRONG&gt;return&lt;/STRONG&gt; this one column result, I want to iterate every value of the each raw into my next query to look for  DNS ptr records and then merge the result of queries.&lt;BR /&gt;
What I mean is I need to run every IP address in this query and then merge the results. In my case:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;my ip addresess are 1.2.3.4, 23.23.23.23, 45.45.45.45, 67.67.67.67, 4.3.2.1
x.x.x.x is should be replaced by these ip addresses for each iteration
index=dnslogs sourcetype=ptr_data dns_name="x.x.x.x" | stats values(query)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And my expected results should look something  like that:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;----dest------                ---------DNS Value---------
1.2.3.4                              google.com
23.23.23.23                          NULL
45.45.45.45                          whatsapp.com
                                     web.whatsapp.com
67.67.67.67                          twitter.com
4.3.2.1                              NULL
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The result above shows that some of query result return &lt;STRONG&gt;NULL&lt;/STRONG&gt;, some of them return &lt;STRONG&gt;multiple values&lt;/STRONG&gt; like 45.45.45.45 some of them only return &lt;STRONG&gt;one&lt;/STRONG&gt; value.&lt;BR /&gt;
Is there any way to do that something like that? These two query are completely different query. I looked at sub-search but it didn't work me or I couldn't do this.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 23:40:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-use-the-results-of-a-search-in-a-second-search/m-p/292025#M88195</guid>
      <dc:creator>splunkThreatHun</dc:creator>
      <dc:date>2017-10-09T23:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: How can I use the results of a search in a second search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-use-the-results-of-a-search-in-a-second-search/m-p/292026#M88196</link>
      <description>&lt;P&gt;You can try something like this.&lt;/P&gt;

&lt;P&gt;index=dnslogs sourcetype=ptr_data [search firstquery | stats count by dest | fields dest | rename dest as dns_name | format] | stats count by dns_name,query&lt;/P&gt;

&lt;P&gt;OR&lt;BR /&gt;
(using dnslookup lookup)&lt;BR /&gt;
firstquery | stats count by dest | lookup dnslookup clientip as dest&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:12:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-use-the-results-of-a-search-in-a-second-search/m-p/292026#M88196</guid>
      <dc:creator>kyaparla</dc:creator>
      <dc:date>2020-09-29T16:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: How can I use the results of a search in a second search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-use-the-results-of-a-search-in-a-second-search/m-p/292027#M88197</link>
      <description>&lt;P&gt;First, run this so you understand what is going on...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; your first query | stats count by dest | fields dest | rename dest as dns_name | format
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That will return a single field called "search", with a value that looks like this....&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;( ( dns_name="1.2.3.4" ) OR ( dns_name="23.23.23.23" ) OR ... ) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When you put that search inside brackets, it will be run first as a subsearch, and the output of the field &lt;CODE&gt;search&lt;/CODE&gt; will be dropped into the main search just the way you read it above.  The &lt;CODE&gt;format&lt;/CODE&gt; at the end is implicit, so you don't actually need to have it there unless you are using some of its options. &lt;/P&gt;

&lt;P&gt;So this... &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=dnslogs sourcetype=ptr_data [your first query | stats count by dest | fields dest | rename dest as dns_name ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;...is the same as this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=dnslogs sourcetype=ptr_data   ( ( dns_name="1.2.3.4" ) OR ( dns_name="23.23.23.23" ) OR ... ) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;... and then you run it into this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats values(query) by dns_name
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;...so the whole thing is like this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=dnslogs sourcetype=ptr_data 
    [your first query | stats count by dest | fields dest | rename dest as dns_name ]
| stats values(query) by dns_name
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Oct 2017 04:33:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-use-the-results-of-a-search-in-a-second-search/m-p/292027#M88197</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-10-10T04:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: How can I use the results of a search in a second search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-use-the-results-of-a-search-in-a-second-search/m-p/292028#M88198</link>
      <description>&lt;P&gt;i believe you have to add the word search itself inside the bracket so it should look like this&lt;/P&gt;

&lt;P&gt;index=dnslogs sourcetype=ptr_data &lt;BR /&gt;
     [&lt;STRONG&gt;&lt;EM&gt;search&lt;/EM&gt;&lt;/STRONG&gt; your first query | stats count by dest | fields dest | rename dest as dns_name ]&lt;BR /&gt;
 | stats values(query) by dns_name&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:50:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-use-the-results-of-a-search-in-a-second-search/m-p/292028#M88198</guid>
      <dc:creator>chicoocholoco</dc:creator>
      <dc:date>2020-09-30T04:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: How can I use the results of a search in a second search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-use-the-results-of-a-search-in-a-second-search/m-p/292029#M88199</link>
      <description>&lt;P&gt;from my understanding, I believe you have to add search inside the bracket something like this:&lt;/P&gt;

&lt;P&gt;index=dnslogs sourcetype=ptr_data &lt;BR /&gt;
     [&lt;STRONG&gt;&lt;EM&gt;search&lt;/EM&gt;&lt;/STRONG&gt; your first query | stats count by dest | fields dest | rename dest as dns_name ]&lt;BR /&gt;
 | stats values(query) by dns_name&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:50:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-use-the-results-of-a-search-in-a-second-search/m-p/292029#M88199</guid>
      <dc:creator>chicoocholoco</dc:creator>
      <dc:date>2020-09-30T04:50:57Z</dc:date>
    </item>
    <item>
      <title>Re: How can I use the results of a search in a second search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-use-the-results-of-a-search-in-a-second-search/m-p/292030#M88200</link>
      <description>&lt;P&gt;This is not working for me. It was working fine until yesterday, but suddenly stopped working Please find my query below&lt;/P&gt;

&lt;P&gt;sourcetype="ms:o365:reporting:messagetrace" SenderAddress=&lt;EM&gt;@company.com Status=&lt;/EM&gt;  [search index=notable source="Threat - Detect Spam Email - Rule" | stats count by Subject | fields Subject] | stats dc(RecipientAddress) as recipientcount  count by Subject SenderAddress&lt;/P&gt;

&lt;P&gt;Any idea?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 07:56:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-use-the-results-of-a-search-in-a-second-search/m-p/292030#M88200</guid>
      <dc:creator>anubhp</dc:creator>
      <dc:date>2020-04-02T07:56:02Z</dc:date>
    </item>
  </channel>
</rss>

