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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...