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!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...