Splunk Search

How to pass values to a eval if subsearch?

pierre_weg
Path Finder

Hi guys!

I have a sourcetype "A" with some info about infrastructure. Host IP is one of this info.

I have another sourcetype "B" (same index) that have a list of critical IPs.

What I'm trying to do is to use eval and IF to set a field value if the IP from sourcetype "A" are present on sourcetype "B".

Fixing the IP value on the subsearch, the result is correct.

index=lab | eval XPTO=if([ search index=lab sourcetype=B IP="192.168.1.2"],1,0)

but I need to pass the IP dynamically from the main search. Something like... 

index=lab | eval XPTO=if([ search index=lab sourcetype=B IP=$IP$],1,0)

it's a simple question, like an Excel VLOOKUP function.

Did you have a suggestion?

Labels (1)
0 Karma

pierre_weg
Path Finder

Thanks @PickleRick 
I found a solution that seem to retrieve what I need just doing this

index=lab sourcetype=A
| eval XPTO=if([ search index=lab sourcetype=B | fields IP],"yes","no")

0 Karma

PickleRick
SplunkTrust
SplunkTrust

In such a limited case it might indeed work. Be wary however that it will most probably produce an overly complicated eval if condition (and - as usual - subsearch is limited by the usual number of returned rows and subsearch duration)

PickleRick
SplunkTrust
SplunkTrust

1. You don't do it this way. You simply can't. The subsearch is run before your main search and its result is rendered - simplifying a bit - as a string which is pasted into the main search.

2. Even if it worked that way, this kind of search would mean that there would have to be a subsearch spawned for each row of the main search. It would be highly ineffective.

3. You can simulate something similar with the map command, but its use is highly discouraged if you can avoid it.

4. Typically those kinds of searches are done using search or two appended ones with some clever statsing to match data from two datasets.

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...