Splunk Search

How to get the full directory path to a file? (e.g. dirname)

bwlm
Path Finder

Similar to the Regex to find a directory in a path question, how does one find the full directory path to an file (e.g. like the "dirname" command in Linux)?

For example in Windows Security Event logs, Event ID 4688 for New Process Creation has the field "New_Process_Name" which is the full path to the executable... how does one get the full directory of the executable?

Labels (1)
0 Karma
1 Solution

bwlm
Path Finder

In simply using the Splunk Multivalue eval functions "split", "mvcount", "mvindex" and "mvjoin"... here is one possible solution:

| makeresults
| eval New_Process_Name="C:\Windows\System32\notepad.exe"
| eval DirNameExeValues=split(New_Process_Name,"\\")
| eval DirNameExeValueCount=mvcount(DirNameExeValues)
| eval DirName=mvindex(DirNameExeValues,0,DirNameExeValueCount-2)
| eval DirName=mvjoin(DirName, "\\")
| eval ExeName=mvindex(split(New_Process_Name,"\\"),-1)
| table New_Process_Name, DirNameExeValues, DirNameExeValueCount, DirName, ExeName

 Or to compress the DirName evaluation from multiple lines to one...

| makeresults
| eval New_Process_Name="C:\Windows\System32\notepad.exe"
| eval DirName=mvjoin( mvindex( split(New_Process_Name,"\\"),0, mvcount(split(New_Process_Name,"\\"))-2 ), "\\")
| eval ExeName=mvindex(split(New_Process_Name,"\\"),-1)
| table New_Process_Name, DirName, ExeName

 

View solution in original post

0 Karma

bwlm
Path Finder

In simply using the Splunk Multivalue eval functions "split", "mvcount", "mvindex" and "mvjoin"... here is one possible solution:

| makeresults
| eval New_Process_Name="C:\Windows\System32\notepad.exe"
| eval DirNameExeValues=split(New_Process_Name,"\\")
| eval DirNameExeValueCount=mvcount(DirNameExeValues)
| eval DirName=mvindex(DirNameExeValues,0,DirNameExeValueCount-2)
| eval DirName=mvjoin(DirName, "\\")
| eval ExeName=mvindex(split(New_Process_Name,"\\"),-1)
| table New_Process_Name, DirNameExeValues, DirNameExeValueCount, DirName, ExeName

 Or to compress the DirName evaluation from multiple lines to one...

| makeresults
| eval New_Process_Name="C:\Windows\System32\notepad.exe"
| eval DirName=mvjoin( mvindex( split(New_Process_Name,"\\"),0, mvcount(split(New_Process_Name,"\\"))-2 ), "\\")
| eval ExeName=mvindex(split(New_Process_Name,"\\"),-1)
| table New_Process_Name, DirName, ExeName

 

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...