Splunk Search

Avoiding a double-lookup for an efficient search

98123722
Explorer

A user is only allowed to log in from one of their AllowedPlatform:

userAllowedPlatform.csv

| User     | AllowedPlatform |
+----------+-----------------+
| Mike     | PC              |
+----------+-----------------+
| Mike     | iPad            |
+----------+-----------------+
| Andrew   | PC              |
+----------+-----------------+
| Jennifer | iPad            |
+----------+-----------------+
| Jennifer | iPhone          |

The following datasets shows all user activities:

| User     | PlatformUsed |
+----------+--------------+
| Mike     | PC           |
+----------+--------------+
| Mike     | iPad         |
+----------+--------------+
| Mike     | iPhone       |
+----------+--------------+
| Jennifer | iPad         |
+----------+--------------+
| John     | iPhone       |

To find out who uses a platform that's not AllowedPlatform, I run a simple lookup for Users in the dataset against userAllowedPlatform.csv:

index="userLogs" | lookup userAllowedPlatform.csv User AS User, AllowedPlatform as PlatformUsed OUTPUT AllowedPlatform as PlatformUsed_Violation | eval description=if(isnull(PlatformUsed),PlatformUsed_Violation,description) | where NOT len(PlatformUsed_Violation) >1

Which gives me ALL unmatching results:

| User | PlatformUsed_Lookup |
+------+---------------------+
| Mike | iPhone              |
+------+---------------------+
| John | iPhone              |

My goal is perform this but exclude entries that are not part of userAllowedPlatform.csv (John, in this case). I can take the above results and match them again against userAllowedPlatform.csv, this time to remove entries with users that are not in userAllowedPlatform.csv, but this seems to me inefficient and over-complicated.

Looking for a simple and efficient way of solving this.

0 Karma
1 Solution

somesoni2
Revered Legend

Give this a try

index="userLogs" 
| lookup userAllowedPlatform.csv User AS User OUTPUT AllowedPlatform 
| eval description=if(isnull(PlatformUsed),AllowedPlatform,description) 
| where isnotnull(AllowedPlatform) AND AllowedPlatform!=PlaformUsed

View solution in original post

somesoni2
Revered Legend

Give this a try

index="userLogs" 
| lookup userAllowedPlatform.csv User AS User OUTPUT AllowedPlatform 
| eval description=if(isnull(PlatformUsed),AllowedPlatform,description) 
| where isnotnull(AllowedPlatform) AND AllowedPlatform!=PlaformUsed

98123722
Explorer

Thanks! worked perfectly.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

.conf25 Global Broadcast: Don’t Miss a Moment

Hello Splunkers, .conf25 is only a click away.  Not able to make it to .conf25 in person? No worries, you can ...

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...