Splunk Search

Is it possible to call lookup within case statement?

RSS_STT
Explorer

I want to call lookup within case statement. if possible, please share sample query.

Labels (1)
Tags (1)
0 Karma

RSS_STT
Explorer

I have fields aa, bb, cc, dd, hostname and sometime few filed value may be null in payload.

What i want to do.

if (aa, bb is not null) than lookup abc.csv name output name hostname ip

if (cc, dd is not null)  than lookup abc.csv name output name hostname ip

if hostname=echo than lookup abc.csv name output name hostname ip

Here is the catch, if 1st if condition is executed it should ignore 2nd & 3rd.

if 2nd if statement executed than 3rd should ignored. Like wise i have to go upto 10 if condition.

 

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Since all the lookups appear to be the same, why not do the lookup first, then evaluate (with your conditions) whether the results are worth keeping?

ITWhisperer
SplunkTrust
SplunkTrust

The simple answer is no - what is your usecase? what are you trying to achieve? There may be another way

0 Karma

bowesmana
SplunkTrust
SplunkTrust

Yes you can using the lookup eval command

https://docs.splunk.com/Documentation/SplunkCloud/9.1.2312/SearchReference/ConditionalFunctions#look...

It has to come from a CSV, you cannot use KV store lookups

 

ITWhisperer
SplunkTrust
SplunkTrust

Good point - not easy to use in a case statement though

0 Karma

bowesmana
SplunkTrust
SplunkTrust

True enough - it's fiddly and requires post processing of the JSON output, but it's one of the rare conditional if/execute pieces of powerful logic in SPL

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Observability Simplified: Combining User Experience, Application Performance & ...

Tech Talk Observability Simplified: Combining User Experience, Application Performance & Network ...

Event Series May & June: From Network Visibility to Service Intelligence

Unifying the Network: Moving from Alert Noise to Service Intelligence with Splunk ITSI In today’s hybrid ...

Global Splunk User Group Events: May + June 2026

Your Splunk Community Awaits: Discover Upcoming User Group Events Worldwide    Staying ahead in the fast-paced ...