Splunk Enterprise Security

Asset lookup with conditional eval

richardphung
Communicator

Greetings--
I have an asset lookup gen that begins with:

| stats latest(src_ip) as ip latest(os) as os **latest(primary_user) as owner latest(user_name) as user** latest(src_mac) as mac by client_name
| rex field=client_name "^[^\.]+\.(?P<dest_domain>.+)"
| rex field=client_name "^(?<nt_host>[^\.]+)"

However, out asset lookup fields do not contain "user":
https://docs.splunk.com/Documentation/ES/5.3.0/Admin/Formatassetoridentitylist

ip,mac,nt_host,dns,owner,priority,lat,long,city,country,bunit,category,pci_domain,is_expected,should_timesync,should_update,requires_av

When I try:

|makeresults | eval src="1.2.3.4" | get_asset(src)

It automatically puts primary_user as the owner.
However, I would ideally like it to:
Assign latest(user_name) as owner and if latest(user_name)=null, then assign latest(primary_user) as owner, and if both are $null, then to make owner default to "unknown"

I'm not sure how to include the eval latest() inside of |eval owner= case(...), etc.
Any advice would be greatly appreciated.

0 Karma
1 Solution

marycordova
SplunkTrust
SplunkTrust
|eval owner=if(isnotnull('user_name'),'user_name',(if(isnotnull('primary_user'),'primary_user',"unknown")))
| stats latest(src_ip) as ip latest(os) as os latest(owner) as owner latest(src_mac) as mac by client_name
| rex field=client_name "^[^\.]+\.(?P<dest_domain>.+)"
| rex field=client_name "^(?<nt_host>[^\.]+)"
@marycordova

View solution in original post

0 Karma

marycordova
SplunkTrust
SplunkTrust
|eval owner=if(isnotnull('user_name'),'user_name',(if(isnotnull('primary_user'),'primary_user',"unknown")))
| stats latest(src_ip) as ip latest(os) as os latest(owner) as owner latest(src_mac) as mac by client_name
| rex field=client_name "^[^\.]+\.(?P<dest_domain>.+)"
| rex field=client_name "^(?<nt_host>[^\.]+)"
@marycordova
0 Karma

richardphung
Communicator

This worked perfectly.
Thanks!

0 Karma
Get Updates on the Splunk Community!

Infographic provides the TL;DR for the 2024 Splunk Career Impact Report

We’ve been buzzing with excitement about the recent validation of Splunk Education! The 2024 Splunk Career ...

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...