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!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...