<?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: Need help getting grandparent/parent/child relationships to table in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Need-help-getting-grandparent-parent-child-relationships-to/m-p/470781#M132445</link>
    <description>&lt;P&gt;I figured it out, it was simpler than I realised.&lt;/P&gt;

&lt;P&gt;Aggregate parent &amp;amp; child together, output aggregated results to CSV and then use the parent's ParentProcessID as the ProcessID to query to get the grandparent. Finally, aggregate everything again to join the grandparent into the previous parent/child aggregation. &lt;/P&gt;

&lt;P&gt;For each query, you can preserve the original process IDs with a simple &lt;CODE&gt;eval ThisProcessID=ProcessID&lt;/CODE&gt; and then use them in the final aggregation/table view. You also need to rename the fields for the parent and grandparent queries so they don't get merged into the same field during aggregation, i.e. 'FileName' becomes 'ParentFileName'.&lt;/P&gt;

&lt;P&gt;In my use-case I had a lot more fields than below and I needed to zip some values and expand them later to prevent multi-value aggregation, so I've included that too.&lt;/P&gt;

&lt;P&gt;See example query below.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputcsv dispatch=t child_with_parent_processes_aggregated.csv
| append [
    search event=ProcessExecution earliest=-1y latest=now [
        | inputcsv dispatch=t child_processes.csv
        | append [
            search event=ProcessExecution earliest=-1y latest=now [
                search event=ProcessExecution FileName="cmd.exe"
                | eval ChildProcessID=ProcessID
                | rename ParentProcessID AS ProcessID
                | outputcsv dispatch=t child_processes.csv
                | fields ProcessID
            ]
            | rename FileName AS ParentFileName
        ]
        | eval zipped=mvzip(FileName,ChildProcessID,"!!!!!cpid=")
        | stats values(*) as * by ProcessID
        | mvexpand zipped
        | rex field=zipped "^(?&amp;lt;FileName&amp;gt;.*)!!!!!cpid=(?&amp;lt;ChildProcessID&amp;gt;.*)$"
        | eval ParentProcessID=ProcessID
        | rename ParentProcessID as ProcessID
        | table ParentFileName ParentProcessID FileName ChildProcessID ProcessID
        | outputcsv dispatch=t child_with_parent_processes_aggregated.csv
        | fields TargetProcessId_decimal
    ]
    | rename FileName AS GrandParentFileName
    | eval GrandParentProcessID=ProcessID
]
| eval zipped=mvzip(mvzip(mvzip(FileName,ChildProcessID,"!!!!!cpid="),ParentFileName,"!!!!!pname="),ParentProcessID,"!!!!!ppid=")
| stats values(*) as * by ProcessID
| mvexpand zipped
| rex field=zipped "^(?&amp;lt;FileName&amp;gt;.*)!!!!!cpid=(?&amp;lt;ChildProcessID&amp;gt;.*)!!!!!pname=(?&amp;lt;ParentFileName&amp;gt;.*)!!!!!ppid=(?&amp;lt;ParentProcessID&amp;gt;.*)$"
| rename ChildProcessID as ProcessID
| table GrandParentFileName GrandParentProcessID ParentFileName ParentProcessID FileName ProcessID
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 30 Oct 2019 09:53:51 GMT</pubDate>
    <dc:creator>ngperf</dc:creator>
    <dc:date>2019-10-30T09:53:51Z</dc:date>
    <item>
      <title>Need help getting grandparent/parent/child relationships to table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-getting-grandparent-parent-child-relationships-to/m-p/470776#M132440</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have data in the following format from Microsoft Windows OS process executions:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;FileName,ProcessID,ParentProcessID
child1.exe,126,108
parent1.exe,108,93
grandparent1.exe,93,24
child2.exe,276,92
parent2.exe,92,24
...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As you can see, for example, the process hierarchies here would be as follows:&lt;/P&gt;

&lt;P&gt;grandparent1.exe -&amp;gt; parent1.exe -&amp;gt; child1.exe&lt;BR /&gt;
grandparent1.exe -&amp;gt; parent2.exe -&amp;gt; child2.exe&lt;BR /&gt;
And there could be many more relationships with various parents and grandparents, as you would expect.&lt;/P&gt;

&lt;P&gt;I would like to output these relationships in the following manner:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;FileName,ParentFileName,GrandparentFileName
child1.exe,parent1.exe,grandparent1.exe
child2.exe,parent2.exe,grandparent1.exe
...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The limitations here are that, frustratingly, I have no permissions to use lookup tables on the hosted Splunk environment I'm using.&lt;/P&gt;

&lt;P&gt;Currently, I can quite easily get the parent information using the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputcsv dispatch=t procs.csv
| append [
    search event=ProcessExecution earliest=-1y latest=now [
        search event=ProcessExecution FileName="cmd.exe"
        | rename ParentProcessID AS ProcessID
        | outputcsv dispatch=t procs.csv
        | fields ProcessID
    ]
    | rename FileName AS ParentFileName
    | fields ParentFileName
]
| stats values(FileName) as FileName
    values(ParentFileName) as ParentFileName
    by ProcessID
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But I'm totally lost on how I would get the grandparent information into this. &lt;/P&gt;

&lt;P&gt;I'd like to stay away from using 'join' because I'll sometimes be processing a lot more than 50,000 records. As you can see above, I'm limiting my first subsearch to 'FileName' matching 'cmd.exe" and only querying for the parent processes of those records. This way, the search is efficient and will never hit 50,000.&lt;/P&gt;

&lt;P&gt;Any help is much appreciated, thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 18:19:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-getting-grandparent-parent-child-relationships-to/m-p/470776#M132440</guid>
      <dc:creator>ngperf</dc:creator>
      <dc:date>2019-10-28T18:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: Need help getting grandparent/parent/child relationships to table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-getting-grandparent-parent-child-relationships-to/m-p/470777#M132441</link>
      <description>&lt;P&gt;The way to do it is to dump the information to a temporary &lt;CODE&gt;lookup file&lt;/CODE&gt; using the &lt;CODE&gt;outputlookup&lt;/CODE&gt; command and then use it multiple times in a row with &lt;CODE&gt;| lookup&lt;/CODE&gt; like I demonstrate in this Q&amp;amp;A:&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/778755/multiple-joinouter-within-same-search.html#answer-778767"&gt;https://answers.splunk.com/answers/778755/multiple-joinouter-within-same-search.html#answer-778767&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 23:51:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-getting-grandparent-parent-child-relationships-to/m-p/470777#M132441</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-10-28T23:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: Need help getting grandparent/parent/child relationships to table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-getting-grandparent-parent-child-relationships-to/m-p/470778#M132442</link>
      <description>&lt;P&gt;Unfortunately as I mentioned, I don’t have permission on the hosted instance I’m using to utilise lookup tables. Is there another way to do this?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2019 00:10:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-getting-grandparent-parent-child-relationships-to/m-p/470778#M132442</guid>
      <dc:creator>ngperf</dc:creator>
      <dc:date>2019-10-29T00:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: Need help getting grandparent/parent/child relationships to table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-getting-grandparent-parent-child-relationships-to/m-p/470779#M132443</link>
      <description>&lt;P&gt;Are you sure?  You are unable to use &lt;CODE&gt;|outputlookup SomeFileNameHere.csv&lt;/CODE&gt;?  It is possible to block this but it requires sophisticated extra admin to do so and I've never see an environment locked down that much.  Have you tried it?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2019 01:35:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-getting-grandparent-parent-child-relationships-to/m-p/470779#M132443</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-10-29T01:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: Need help getting grandparent/parent/child relationships to table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-getting-grandparent-parent-child-relationships-to/m-p/470780#M132444</link>
      <description>&lt;P&gt;I get the following error below when using either &lt;CODE&gt;outputlookup&lt;/CODE&gt; or &lt;CODE&gt;outputcsv&lt;/CODE&gt; (without &lt;CODE&gt;dispatch=t&lt;/CODE&gt;). I believe this is due to the "output_file" permission being disabled in &lt;CODE&gt;authorize.conf&lt;/CODE&gt;.&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;Error in 'outputlookup' command: You have insufficient privileges to perform this operation.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 29 Oct 2019 09:29:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-getting-grandparent-parent-child-relationships-to/m-p/470780#M132444</guid>
      <dc:creator>ngperf</dc:creator>
      <dc:date>2019-10-29T09:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: Need help getting grandparent/parent/child relationships to table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-getting-grandparent-parent-child-relationships-to/m-p/470781#M132445</link>
      <description>&lt;P&gt;I figured it out, it was simpler than I realised.&lt;/P&gt;

&lt;P&gt;Aggregate parent &amp;amp; child together, output aggregated results to CSV and then use the parent's ParentProcessID as the ProcessID to query to get the grandparent. Finally, aggregate everything again to join the grandparent into the previous parent/child aggregation. &lt;/P&gt;

&lt;P&gt;For each query, you can preserve the original process IDs with a simple &lt;CODE&gt;eval ThisProcessID=ProcessID&lt;/CODE&gt; and then use them in the final aggregation/table view. You also need to rename the fields for the parent and grandparent queries so they don't get merged into the same field during aggregation, i.e. 'FileName' becomes 'ParentFileName'.&lt;/P&gt;

&lt;P&gt;In my use-case I had a lot more fields than below and I needed to zip some values and expand them later to prevent multi-value aggregation, so I've included that too.&lt;/P&gt;

&lt;P&gt;See example query below.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputcsv dispatch=t child_with_parent_processes_aggregated.csv
| append [
    search event=ProcessExecution earliest=-1y latest=now [
        | inputcsv dispatch=t child_processes.csv
        | append [
            search event=ProcessExecution earliest=-1y latest=now [
                search event=ProcessExecution FileName="cmd.exe"
                | eval ChildProcessID=ProcessID
                | rename ParentProcessID AS ProcessID
                | outputcsv dispatch=t child_processes.csv
                | fields ProcessID
            ]
            | rename FileName AS ParentFileName
        ]
        | eval zipped=mvzip(FileName,ChildProcessID,"!!!!!cpid=")
        | stats values(*) as * by ProcessID
        | mvexpand zipped
        | rex field=zipped "^(?&amp;lt;FileName&amp;gt;.*)!!!!!cpid=(?&amp;lt;ChildProcessID&amp;gt;.*)$"
        | eval ParentProcessID=ProcessID
        | rename ParentProcessID as ProcessID
        | table ParentFileName ParentProcessID FileName ChildProcessID ProcessID
        | outputcsv dispatch=t child_with_parent_processes_aggregated.csv
        | fields TargetProcessId_decimal
    ]
    | rename FileName AS GrandParentFileName
    | eval GrandParentProcessID=ProcessID
]
| eval zipped=mvzip(mvzip(mvzip(FileName,ChildProcessID,"!!!!!cpid="),ParentFileName,"!!!!!pname="),ParentProcessID,"!!!!!ppid=")
| stats values(*) as * by ProcessID
| mvexpand zipped
| rex field=zipped "^(?&amp;lt;FileName&amp;gt;.*)!!!!!cpid=(?&amp;lt;ChildProcessID&amp;gt;.*)!!!!!pname=(?&amp;lt;ParentFileName&amp;gt;.*)!!!!!ppid=(?&amp;lt;ParentProcessID&amp;gt;.*)$"
| rename ChildProcessID as ProcessID
| table GrandParentFileName GrandParentProcessID ParentFileName ParentProcessID FileName ProcessID
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Oct 2019 09:53:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-getting-grandparent-parent-child-relationships-to/m-p/470781#M132445</guid>
      <dc:creator>ngperf</dc:creator>
      <dc:date>2019-10-30T09:53:51Z</dc:date>
    </item>
  </channel>
</rss>

