Splunk Search

Can I use a search again in an eval if condition?

kranthi851
New Member

Hi,

From a search, I will get two fields HOST and SRC. I have to join this with other two searches (query-1, query-2) to get the USER field. I have to join query-1 with HOST as a common field, but if I don't have user details in there, then I have to use SRC as common field in query-2 to get the USER.

Search I'm using:

index=abc| join type=left HOST [search index=XYZ earliest=-30d latest=now] | rename Login as user|eval user=if(isnull(user) OR user="","unknown",user)|eval user=if(user=unknown,(search index=abc|join SRC[index=123], USER)|tableHOST SRC USER

If user is not available in query-1, how to search in query-2?

Tags (4)
0 Karma
1 Solution

somesoni2
Revered Legend

Try like this

index=abc| join type=left HOST [search index=XYZ earliest=-30d latest=now] |join type=left SRC [search index=123 ] | eval USER=coalesce(Login,USER) |tableHOST SRC USER

The join 1 gives you field Login and join2 will give you field USER. In the end, the coalesce function will take the first not null values from both the column and assign to USER field.

View solution in original post

0 Karma

somesoni2
Revered Legend

Try like this

index=abc| join type=left HOST [search index=XYZ earliest=-30d latest=now] |join type=left SRC [search index=123 ] | eval USER=coalesce(Login,USER) |tableHOST SRC USER

The join 1 gives you field Login and join2 will give you field USER. In the end, the coalesce function will take the first not null values from both the column and assign to USER field.

0 Karma

kranthi851
New Member

Thanks for the reply! suppose for a same event if i got Login=uname and USER=lname, In the final result of USER will it show both or Just the Login result.?

0 Karma

somesoni2
Revered Legend

Just Login (first non-null value). You can replace that coalesce command with a case statement to handle mulitple scenarios as per your requirement.

0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

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