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!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...