<?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 the results from one search as a field to use in another search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306308#M91967</link>
    <description>&lt;P&gt;Dean,&lt;BR /&gt;
we might need to debug this a little.  What happens when you do just the first (subquery) part?&lt;/P&gt;

&lt;P&gt;search EventCode=4738 Account_Expires!="-" | eval  Account_Name=mvindex(Account_Name, -1) |eval New_DN="\"CN=".Account_Name.",OU=Users - Disabled,DC=testdomain,DC=ca\"" | table New_DN&lt;/P&gt;

&lt;P&gt;And if it looks like a fqdn, what happens if you manually stick that values into the outer query?&lt;BR /&gt;
 EventCode=5139 New_DN=...&lt;BR /&gt;
 | table _time, Account_Name, New_DN, Old_DN&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 16:59:01 GMT</pubDate>
    <dc:creator>MonkeyK</dc:creator>
    <dc:date>2020-09-29T16:59:01Z</dc:date>
    <item>
      <title>Using the results from one search as a field to use in another search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306303#M91962</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;

&lt;P&gt;I am trying to combine two different searches to correlate with one another.&lt;/P&gt;

&lt;P&gt;The first search is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EventCode=4738 Account_Expires!="-" | table _time, Account_Name, Account_Expires| eval  Account_Name=mvindex(Account_Name, -1) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will provide me any AD account that had made changes to the account expiry.  I use the &lt;STRONG&gt;| eval  Account_Name=mvindex(Account_Name, -1)&lt;/STRONG&gt; to show me the 2nd name as the first one is the person who made the change.  The second one is the account was changed.&lt;/P&gt;

&lt;P&gt;Next we have an OU in AD that we move the user to called Users - Disabled.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EventCode=5139  New_DN="CN=*,OU=Users - Disabled,DC=testdomain,DC=ca" | table _time, Account_Name, New_DN, Old_DN
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is so I can see if a user was moved to this "Users - Disabled" OU&lt;/P&gt;

&lt;P&gt;How do I combine these by obtaining the "Account_Name" from the first search to use as an insert to search for this user that was moved(as per below)?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EventCode=5139  New_DN="CN=&amp;lt;Insert "Account_Name" here&amp;gt;,OU=Users - Disabled,DC=testdomain,DC=ca" | table _time, Account_Name, New_DN, Old_DN
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The problem I have is that EventCode=5139 does not show the second user as EventCode=4738 does.  The goal is here is to see how much time has transpired from when an "Account_Expires" was set and when the account is moved to this "Users - Disabled" OU.  Is this something that is possible?  &lt;/P&gt;

&lt;P&gt;After that I would want to set an alert to notify me when the "Account_Expires" field was changed and if the AD account was not moved to the "Users - Disabled" OU  within about 10 days.  Any suggestions would be appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:58:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306303#M91962</guid>
      <dc:creator>DeanDeleon0</dc:creator>
      <dc:date>2020-09-29T16:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Using the results from one search as a field to use in another search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306304#M91963</link>
      <description>&lt;P&gt;Dean, should be something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EventCode=5139  [|search EventCode=4738 Account_Expires!="-" | eval  Account_Name=mvindex(Account_Name, -1) |eval New_DN="\"CN=".Account_Name.",OU=Users - Disabled,DC=testdomain,DC=ca\"" | table New_DN] 
| table _time, Account_Name, New_DN, Old_DN
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Basically, that just uses you first search to create the New_DN field for the second search&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2017 22:08:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306304#M91963</guid>
      <dc:creator>MonkeyK</dc:creator>
      <dc:date>2017-11-28T22:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using the results from one search as a field to use in another search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306305#M91964</link>
      <description>&lt;P&gt;I would add &lt;CODE&gt;| table New_DN&lt;/CODE&gt;  at the end of subsearch. Else it would return all available fields from subsearch and will not work.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EventCode=5139  [|search EventCode=4738 Account_Expires!="-" | eval  Account_Name=mvindex(Account_Name, -1) |eval New_DN="\"CN=".Account_Name.",OU=Users - Disabled,DC=testdomain,DC=ca\"" | table New_DN ] 
 | table _time, Account_Name, New_DN, Old_DN
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Nov 2017 22:41:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306305#M91964</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-11-28T22:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using the results from one search as a field to use in another search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306306#M91965</link>
      <description>&lt;P&gt;good point. somesoni2!.  I will correct it&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 01:00:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306306#M91965</guid>
      <dc:creator>MonkeyK</dc:creator>
      <dc:date>2017-11-29T01:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using the results from one search as a field to use in another search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306307#M91966</link>
      <description>&lt;P&gt;Thanks for helping out!  I am having some issues with this.  Individually the searches work fine.  But not when put together like that.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 17:02:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306307#M91966</guid>
      <dc:creator>DeanDeleon0</dc:creator>
      <dc:date>2017-11-29T17:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using the results from one search as a field to use in another search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306308#M91967</link>
      <description>&lt;P&gt;Dean,&lt;BR /&gt;
we might need to debug this a little.  What happens when you do just the first (subquery) part?&lt;/P&gt;

&lt;P&gt;search EventCode=4738 Account_Expires!="-" | eval  Account_Name=mvindex(Account_Name, -1) |eval New_DN="\"CN=".Account_Name.",OU=Users - Disabled,DC=testdomain,DC=ca\"" | table New_DN&lt;/P&gt;

&lt;P&gt;And if it looks like a fqdn, what happens if you manually stick that values into the outer query?&lt;BR /&gt;
 EventCode=5139 New_DN=...&lt;BR /&gt;
 | table _time, Account_Name, New_DN, Old_DN&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:59:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306308#M91967</guid>
      <dc:creator>MonkeyK</dc:creator>
      <dc:date>2020-09-29T16:59:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using the results from one search as a field to use in another search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306309#M91968</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;EventCode=4738 Account_Expires!="-" | eval Account_Name=mvindex(Account_Name, -1) |eval New_DN="\"CN=".Account_Name.",OU=Users - Disabled,DC=testdomain,DC=ca\"" | table New_DN
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Will result in:&lt;/P&gt;

&lt;P&gt;"CN=bruce.wayne,OU=Users - Disabled,DC=testdomain,DC=ca"&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EventCode=5139 New_DN="CN=bruce.wayne,OU=Users - Disabled,DC=testdomain,DC=ca" | table _time, Account_Name, New_DN
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Yields no results.  However,  I see where the problem is.  EventCode 5139 displays the New_DN account name with a space:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;CN=**Bruce Wayne**,OU=Users - Disabled,DC=testdomain,DC=ca
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This copies the account name with the period between the first and last name.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"CN=**bruce.wayne**,OU=Users - Disabled,DC=testdomain,DC=ca"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is there a simple way to create the space and remove the period?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 21:51:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306309#M91968</guid>
      <dc:creator>DeanDeleon0</dc:creator>
      <dc:date>2017-11-29T21:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using the results from one search as a field to use in another search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306310#M91969</link>
      <description>&lt;P&gt;Good catch on the space!&lt;BR /&gt;&lt;BR /&gt;
to replace the period with a space, use this eval statement:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;replace(Account_Name,"\."," ")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;so now the whole thing would be&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EventCode=5139  [|search EventCode=4738 Account_Expires!="-" | eval  Account_Name=mvindex(Account_Name, -1) |eval New_DN="\"CN=".replace(Account_Name,"\."," ").",OU=Users - Disabled,DC=testdomain,DC=ca\"" | table New_DN] 
 | table _time, Account_Name, New_DN, Old_DN
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Nov 2017 01:26:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306310#M91969</guid>
      <dc:creator>MonkeyK</dc:creator>
      <dc:date>2017-11-30T01:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using the results from one search as a field to use in another search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306311#M91970</link>
      <description>&lt;P&gt;I believe we are just one step away now.  I think it is here from when you asked me to test them individually:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   EventCode=5139 New_DN=...
    | table _time, Account_Name, New_DN, Old_DN
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I think it ends up looking like this instead, where the "New_DN=" is not inserted so it does not yield any results:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EventCode=5139 "CN=bruce wayne,OU=Users - Disabled,DC=testdomain,DC=ca"  | table _time, Account_Name, New_DN, Old_DN 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How do we insert "New_DN=" in front of that?&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 16:24:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306311#M91970</guid>
      <dc:creator>DeanDeleon0</dc:creator>
      <dc:date>2017-11-30T16:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using the results from one search as a field to use in another search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306312#M91971</link>
      <description>&lt;P&gt;When you use the subsearch's table command should assign the field name, so &lt;/P&gt;

&lt;P&gt;[|search EventCode=4738 Account_Expires!="-" | eval  Account_Name=mvindex(Account_Name, -1) |eval New_DN="\"CN=".replace(Account_Name,"."," ").",OU=Users - Disabled,DC=testdomain,DC=ca\"" | table New_DN] &lt;/P&gt;

&lt;P&gt;should result resolve to&lt;BR /&gt;
New_DN="CN=bruce wayne,OU=Users - Disabled,DC=testdomain,DC=ca"&lt;/P&gt;

&lt;P&gt;You can see this has taken place after the run if you click on "Job|inspect Job"&lt;BR /&gt;
and then "search log" in the dialog that appears.&lt;BR /&gt;
You will be able to search for "expanded index search" (it may be a few results down)  or "New_DN=" &lt;BR /&gt;
and you will see  EventCode=5139  (New_DN="CN=bruce wayne,OU=Users - Disabled,DC=testdomain,DC=ca")&lt;/P&gt;

&lt;P&gt;if there are multiple New_DNs, you will see them OR'd:&lt;BR /&gt;
EventCode=5139  (New_DN="CN=bruce wayne,OU=Users - Disabled,DC=testdomain,DC=ca" OR New_DN="CN=clark kent,OU=Users - Disabled,DC=testdomain,DC=ca" )&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:59:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306312#M91971</guid>
      <dc:creator>MonkeyK</dc:creator>
      <dc:date>2020-09-29T16:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using the results from one search as a field to use in another search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306313#M91972</link>
      <description>&lt;P&gt;Thanks! This is working! Much appreciated!  The issue was there was a subfolder in the OU=Users - Disabled.  example: OU=December,OU=Users - Disabled,...etc&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 16:26:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306313#M91972</guid>
      <dc:creator>DeanDeleon0</dc:creator>
      <dc:date>2017-12-04T16:26:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using the results from one search as a field to use in another search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306314#M91973</link>
      <description>&lt;P&gt;ah!  Glad it works for you.&lt;BR /&gt;
FQDNs always mess me up.&lt;BR /&gt;&lt;BR /&gt;
As long as you are building the DN anyway, you can  use a wildcard.  I probably should have considered that.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 12:24:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-results-from-one-search-as-a-field-to-use-in-another/m-p/306314#M91973</guid>
      <dc:creator>MonkeyK</dc:creator>
      <dc:date>2017-12-05T12:24:18Z</dc:date>
    </item>
  </channel>
</rss>

