<?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 Using the results of one search to perform another (dynamic search results)? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-the-results-of-one-search-to-perform-another-dynamic/m-p/180287#M51904</link>
    <description>&lt;P&gt;I'm relatively new to Splunk, so I'm pretty sure I'm going about this the wrong way but I have to think it's possible.  Here goes...&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Goal:&lt;/STRONG&gt;&lt;BR /&gt;
I'm working with two log sources: &lt;CODE&gt;dhcpsrvlog&lt;/CODE&gt; and &lt;CODE&gt;web_threat&lt;/CODE&gt;.  &lt;CODE&gt;dhcpsrvlog&lt;/CODE&gt; contains two pieces of data I'm interested in; &lt;CODE&gt;dest_ip&lt;/CODE&gt; and &lt;CODE&gt;dest_host&lt;/CODE&gt;.  The &lt;CODE&gt;web_threat&lt;/CODE&gt; logs however do not contain a hostname, just an IP.  I want to take the &lt;CODE&gt;dest_host&lt;/CODE&gt; information for specific IPs and cross reference it with the &lt;CODE&gt;src_ip&lt;/CODE&gt; field within the &lt;CODE&gt;web_threat&lt;/CODE&gt; logs.  Essentially, I want to leverage the DHCP data to link current IPs for hosts of interest to specific &lt;CODE&gt;web_threat&lt;/CODE&gt; logs.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Part 1:&lt;/STRONG&gt;&lt;BR /&gt;
I have successfully created the search below which displays the most recent DHCP lease for host(s) of interest using a predefined lookup table.  I know it's probably not optimal, but I'm working with what I know:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=dhcpsrvlog description=Assign OR description=Renew [|inputlookup hostwatchlist] | dedup dest_host sortby -_time | table time, dest_host, dest_ip, description | rename time AS "Time of Lease" dest_host AS "Hostname" dest_ip AS "Assigned IP" description AS "Type of Lease"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This properly displays the information I need for situational awareness -- when did the host(s) I'm interested last receive/renew an IP lease and what is the IP?&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Part 2:&lt;/STRONG&gt;&lt;BR /&gt;
Now, what I'd like to do is take the IP from the &lt;CODE&gt;Assigned IP&lt;/CODE&gt; column for each host in the resulting table and use that data to perform a secondary search for specific types of web traffic within my &lt;CODE&gt;web_threat&lt;/CODE&gt; logs.  &lt;/P&gt;

&lt;P&gt;For example, lets say I'm monitoring a host that was involved in a recent malware investigation, it's hostname is &lt;CODE&gt;host.network.local&lt;/CODE&gt; which I manually input into my lookup table.  I have the most recent DHCP log from my search above and it says the host's IP is &lt;CODE&gt;1.2.3.4&lt;/CODE&gt;.  Based on the observed malware let's assume I'm interested in outbound web activity to badsite[d]com from the affected host.  In order to find any such traffic from this host I'd need to perform this search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=web_threat src_ip=1.2.3.4 dst_hostname=badsite.com
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Question:&lt;/STRONG&gt;&lt;BR /&gt;
How can I take the results from my existing &lt;CODE&gt;dhcpsrvlog&lt;/CODE&gt; search providing me with the &lt;CODE&gt;Assigned IP&lt;/CODE&gt; and dynamically search the &lt;CODE&gt;web_threat&lt;/CODE&gt; logs for this traffic as seen in the above search?  I'd like the results to display the &lt;CODE&gt;dest_host&lt;/CODE&gt; field from the DHCP logs if possible, but it's not a requirement.  The primary goal is for the search to dynamically change if/when the host of interest is assigned a new IP (i.e. insert the new &lt;CODE&gt;Assigned IP&lt;/CODE&gt; into the &lt;CODE&gt;src_ip&lt;/CODE&gt; condition of the search).&lt;/P&gt;

&lt;P&gt;I have considered using &lt;CODE&gt;join&lt;/CODE&gt; in an attempt to relate the two logs using internal searches, but I haven't had any success (admittedly, &lt;CODE&gt;join&lt;/CODE&gt; is still a bit confusing).  I'm confident this can be done but I'm either missing something very simple, or what I am attempting requires tokens and/or data models, neither of which I've had time to play with.&lt;/P&gt;

&lt;P&gt;Any assistance or recommendations are greatly appreciated!&lt;/P&gt;</description>
    <pubDate>Tue, 21 Oct 2014 22:20:44 GMT</pubDate>
    <dc:creator>rdunn</dc:creator>
    <dc:date>2014-10-21T22:20:44Z</dc:date>
    <item>
      <title>Using the results of one search to perform another (dynamic search results)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-results-of-one-search-to-perform-another-dynamic/m-p/180287#M51904</link>
      <description>&lt;P&gt;I'm relatively new to Splunk, so I'm pretty sure I'm going about this the wrong way but I have to think it's possible.  Here goes...&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Goal:&lt;/STRONG&gt;&lt;BR /&gt;
I'm working with two log sources: &lt;CODE&gt;dhcpsrvlog&lt;/CODE&gt; and &lt;CODE&gt;web_threat&lt;/CODE&gt;.  &lt;CODE&gt;dhcpsrvlog&lt;/CODE&gt; contains two pieces of data I'm interested in; &lt;CODE&gt;dest_ip&lt;/CODE&gt; and &lt;CODE&gt;dest_host&lt;/CODE&gt;.  The &lt;CODE&gt;web_threat&lt;/CODE&gt; logs however do not contain a hostname, just an IP.  I want to take the &lt;CODE&gt;dest_host&lt;/CODE&gt; information for specific IPs and cross reference it with the &lt;CODE&gt;src_ip&lt;/CODE&gt; field within the &lt;CODE&gt;web_threat&lt;/CODE&gt; logs.  Essentially, I want to leverage the DHCP data to link current IPs for hosts of interest to specific &lt;CODE&gt;web_threat&lt;/CODE&gt; logs.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Part 1:&lt;/STRONG&gt;&lt;BR /&gt;
I have successfully created the search below which displays the most recent DHCP lease for host(s) of interest using a predefined lookup table.  I know it's probably not optimal, but I'm working with what I know:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=dhcpsrvlog description=Assign OR description=Renew [|inputlookup hostwatchlist] | dedup dest_host sortby -_time | table time, dest_host, dest_ip, description | rename time AS "Time of Lease" dest_host AS "Hostname" dest_ip AS "Assigned IP" description AS "Type of Lease"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This properly displays the information I need for situational awareness -- when did the host(s) I'm interested last receive/renew an IP lease and what is the IP?&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Part 2:&lt;/STRONG&gt;&lt;BR /&gt;
Now, what I'd like to do is take the IP from the &lt;CODE&gt;Assigned IP&lt;/CODE&gt; column for each host in the resulting table and use that data to perform a secondary search for specific types of web traffic within my &lt;CODE&gt;web_threat&lt;/CODE&gt; logs.  &lt;/P&gt;

&lt;P&gt;For example, lets say I'm monitoring a host that was involved in a recent malware investigation, it's hostname is &lt;CODE&gt;host.network.local&lt;/CODE&gt; which I manually input into my lookup table.  I have the most recent DHCP log from my search above and it says the host's IP is &lt;CODE&gt;1.2.3.4&lt;/CODE&gt;.  Based on the observed malware let's assume I'm interested in outbound web activity to badsite[d]com from the affected host.  In order to find any such traffic from this host I'd need to perform this search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=web_threat src_ip=1.2.3.4 dst_hostname=badsite.com
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Question:&lt;/STRONG&gt;&lt;BR /&gt;
How can I take the results from my existing &lt;CODE&gt;dhcpsrvlog&lt;/CODE&gt; search providing me with the &lt;CODE&gt;Assigned IP&lt;/CODE&gt; and dynamically search the &lt;CODE&gt;web_threat&lt;/CODE&gt; logs for this traffic as seen in the above search?  I'd like the results to display the &lt;CODE&gt;dest_host&lt;/CODE&gt; field from the DHCP logs if possible, but it's not a requirement.  The primary goal is for the search to dynamically change if/when the host of interest is assigned a new IP (i.e. insert the new &lt;CODE&gt;Assigned IP&lt;/CODE&gt; into the &lt;CODE&gt;src_ip&lt;/CODE&gt; condition of the search).&lt;/P&gt;

&lt;P&gt;I have considered using &lt;CODE&gt;join&lt;/CODE&gt; in an attempt to relate the two logs using internal searches, but I haven't had any success (admittedly, &lt;CODE&gt;join&lt;/CODE&gt; is still a bit confusing).  I'm confident this can be done but I'm either missing something very simple, or what I am attempting requires tokens and/or data models, neither of which I've had time to play with.&lt;/P&gt;

&lt;P&gt;Any assistance or recommendations are greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 21 Oct 2014 22:20:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-results-of-one-search-to-perform-another-dynamic/m-p/180287#M51904</guid>
      <dc:creator>rdunn</dc:creator>
      <dc:date>2014-10-21T22:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using the results of one search to perform another (dynamic search results)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-results-of-one-search-to-perform-another-dynamic/m-p/180288#M51905</link>
      <description>&lt;P&gt;Hi Rdunn,&lt;/P&gt;

&lt;P&gt;I believe you're in the right way... join would be the command here. Let's see if I can build a search command using the information you provide in your question. First let's see if I'm taking the right assumptions:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;The search below will list the DHCP events, containing the&lt;/STRONG&gt;&lt;CODE&gt;dest_ip(s)&lt;/CODE&gt;** used by the Host(s) you're investigating:**&lt;BR /&gt;
&lt;PRE&gt;sourcetype=dhcpsrvlog description=Assign OR description=Renew [|inputlookup hostwatchlist] | dedup dest_host sortby -_time&lt;/PRE&gt;&lt;/P&gt;

&lt;P&gt;Now to join it with the &lt;CODE&gt;web_threat&lt;/CODE&gt; events you need first to have the a field name in common. Apparently the &lt;STRONG&gt;joining key&lt;/STRONG&gt; here is the Host's IP, in this case &lt;CODE&gt;dest_ip&lt;/CODE&gt; from DHCP log and &lt;CODE&gt;src_ip&lt;/CODE&gt; from Webthreat logs.&lt;/P&gt;

&lt;P&gt;Here how you could join both:&lt;BR /&gt;
&lt;PRE&gt;sourcetype=dhcpsrvlog description=Assign OR description=Renew [|inputlookup hostwatchlist] | dedup dest_host sortby -_time&lt;BR /&gt;
 | join type=inner max=0 dest_ip&lt;BR /&gt;
  [&lt;BR /&gt;
   search sourcetype=web_threat dst_hostname=badsite.com | rename src_ip AS dest_ip&lt;BR /&gt;
  ]&lt;BR /&gt;
| table _time, dest_host, dest_ip, dst_hostname&lt;BR /&gt;
&lt;/PRE&gt;&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;*Note that I renamed the field src_ip.&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;Just to give you a bit of explanation, the &lt;CODE&gt;join&lt;/CODE&gt; command needs two things to match events between the searches: same field name and same field content - both are CASE-SENSITIVE! The &lt;CODE&gt;type=right&lt;/CODE&gt; tells to list only values that have matches... you could use &lt;CODE&gt;type=left&lt;/CODE&gt; if you wish to list events from DHCP logs independent if they have or don't have matching events from the join operation. The &lt;CODE&gt;max=0&lt;/CODE&gt; tells to match all events, the default is 1. Also the &lt;CODE&gt;join&lt;/CODE&gt; command by default overwrite the fields, in other word, the search inside the join will return, for example &lt;CODE&gt;_time&lt;/CODE&gt; field and this will be used at the output, overwriting the &lt;CODE&gt;_time&lt;/CODE&gt; from the first search.&lt;/P&gt;

&lt;P&gt;As a suggestion you might want have the &lt;CODE&gt;dst_hostname&lt;/CODE&gt; as another lookup to make you like easier instead to add it directly to the search.&lt;/P&gt;

&lt;P&gt;Anyway, hope I was able to help.&lt;/P&gt;

&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:59:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-results-of-one-search-to-perform-another-dynamic/m-p/180288#M51905</guid>
      <dc:creator>musskopf</dc:creator>
      <dc:date>2020-09-28T17:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using the results of one search to perform another (dynamic search results)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-results-of-one-search-to-perform-another-dynamic/m-p/180289#M51906</link>
      <description>&lt;P&gt;&lt;CODE&gt;join&lt;/CODE&gt; kind of works, but is much less efficient than using a subsearch with a &lt;CODE&gt;return&lt;/CODE&gt; in most cases. You are already using a subsearch in one of your searches. It's okay to have a subsearch within a subsearch. Something that should work for you would be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=web_threat dst_hostname="badsite.com" [ sourcetype=dhcpsrvlog description=Assign OR description=Renew [ inputlookup hostwatchlist] | dedup dest_host | return 10000 src_ip=dest_ip ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;return 10000&lt;/CODE&gt; says to query for up to 10000 results from the subsearch (this is the max), and &lt;CODE&gt;src_ip=dest_ip&lt;/CODE&gt; says to use the value of &lt;CODE&gt;dest_ip&lt;/CODE&gt; as &lt;CODE&gt;src_ip&lt;/CODE&gt; in the outer search.&lt;/P&gt;

&lt;P&gt;This does lose you the &lt;CODE&gt;dest_host&lt;/CODE&gt;, but you could recover that by adding a &lt;CODE&gt;| lookup hostwatchlist dest_ip AS src_ip OUTPUT dest_host AS src_host&lt;/CODE&gt; (which also renames &lt;CODE&gt;dest_host&lt;/CODE&gt; to &lt;CODE&gt;src_host&lt;/CODE&gt;, which makes more sense in this context. So:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=web_threat 
dst_hostname="badsite.com"
[ sourcetype=dhcpsrvlog
  description=Assign OR description=Renew 
  [ inputlookup hostwatchlist]
  | dedup dest_host
  | return 10000 src_ip=dest_ip ]
| lookup hostwatchlist dest_ip AS src_ip OUTPUT dest_host AS src_host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, this will lose you the "type of lease", and you can't get that back as easily. If you need it, then a &lt;CODE&gt;join&lt;/CODE&gt; will do it, or you should do it in two steps by writing the first results to a lookup.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Oct 2014 03:56:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-results-of-one-search-to-perform-another-dynamic/m-p/180289#M51906</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2014-10-22T03:56:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using the results of one search to perform another (dynamic search results)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-results-of-one-search-to-perform-another-dynamic/m-p/180290#M51907</link>
      <description>&lt;P&gt;Couldn't comment on the accepted answer (apparently I need more points) so I'm commenting here.  &lt;/P&gt;

&lt;P&gt;Thanks for the assistance, musskopf!  With a small amount of tweaking I was able to get exactly what I wanted.  Here is the search I ended up with:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; sourcetype=dhcpsrvlog description=Assign OR description=Renew [|inputlookup HostWatchList] | dedup dest_host sortby -_time | join type=inner max=0 dest_ip [search sourcetype=pan_threat dst_hostname=badsite.com | rename src_ip AS dest_ip] | dedup dst_hostname sortby -_time | table _time, dest_host, dest_ip, dst_hostname
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I added the &lt;CODE&gt;dedup dst_hostname sortby -_time&lt;/CODE&gt;  portion to the search you provided.  This simply provides the most recent hit per destination as opposed to the entire list.  I may decide it is necessary to see them all later, but for now I just want to see unique domains contacted.  &lt;CODE&gt;join&lt;/CODE&gt; worked like a champ for what I needed.  Thanks again! &lt;/P&gt;</description>
      <pubDate>Wed, 22 Oct 2014 19:22:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-results-of-one-search-to-perform-another-dynamic/m-p/180290#M51907</guid>
      <dc:creator>rdunn</dc:creator>
      <dc:date>2014-10-22T19:22:51Z</dc:date>
    </item>
  </channel>
</rss>

