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!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...