Splunk Search

How to use IN function with VALUE-LIST as a search or lookup

koshyk
Super Champion

hi,
We have a SPL which emits hostname as a single value, but this needs to be checked against a valid list of hostnames on every line. The list is "colon separated"

So ideally, we need to check if

server01
server02

is present in

List1,server101:server102:server103
List2,server04:server02:server05

So in above example, the List2 and server02 should have a match. Please note, the List is a search itself.
Ideally looking for something like

| where IN (servername, [|search myListSearch| fields serverlist|split(serverlist,":")])

Any way to do this using IN operator? ideally i wanted to check if server01 or server02 is present IN the lists in an efficient and short way (rather than splitting the list and comparing). Ideally a "grep -w" should be sufficient

0 Karma
1 Solution

maciep
Champion

You could probably accomplish this with a "normal" subsearch, but I think this works if you want to use the IN function. I'm just reformatting your server list so it looks like "server01","server02", xxx since that's what the function expects.

   | where IN (servername, [
           |search myListSearch
           | fields serverlist
           |eval serverlist = "\"" . replace(serverlist,":","\",\"") . "\""
           | return serverlist 
          ]
      )

View solution in original post

woodcock
Esteemed Legend

Like this:

...  | where [search myListSearch
             | fields serverlist
             | makemv delim=":" serverlist
             | mvexpand serverlist
             | rename serverlist AS servername]

maciep
Champion

You could probably accomplish this with a "normal" subsearch, but I think this works if you want to use the IN function. I'm just reformatting your server list so it looks like "server01","server02", xxx since that's what the function expects.

   | where IN (servername, [
           |search myListSearch
           | fields serverlist
           |eval serverlist = "\"" . replace(serverlist,":","\",\"") . "\""
           | return serverlist 
          ]
      )
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...

Customer success is front and center at .conf25

Hi Splunkers, If you are not able to be at .conf25 in person, you can still learn about all the latest news ...