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
Get Updates on the Splunk Community!

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...

Integrating Splunk Search API and Quarto to Create Reproducible Investigation ...

 Splunk is More Than Just the Web Console For Digital Forensics and Incident Response (DFIR) practitioners, ...

Congratulations to the 2025-2026 SplunkTrust!

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