Splunk Search

How to use values in lookup table not as fields but as search strings?

christopheryu
Communicator

Using lookup table to search events but having some issues:

|inputlookup router_lookup | rename Router_Name as DEVICE_NAME Router_Interface as INTERFACE | fields DEVICE_NAME, INTERFACE | format

results to:

( ( DEVICE_NAME="ROUTERA" AND INTERFACE="xe-5/2/0" ) OR ( DEVICE_NAME="ROUTERB" AND INTERFACE="xe-9/3/1" ) OR ( DEVICE_NAME="ROUTERC" AND INTERFACE="xe-6/7/0" ) ... etc

However, I found out that DEVICE_NAME is not a defined field for all routers, so I tried doing this:

|inputlookup router_lookup | rename Router_Name as DEVICE_NAME Router_Interface as INTERFACE | eval Interface_Name=DEVICE_NAME." AND ".INTERFACE | fields Interface_Name | rename Interface_Name as query | format

results to:

( ("ROUTERA AND xe-5/2/0" ) OR ( "ROUTERB AND xe-9/3/1" ) OR ( "ROUTERC AND xe-6/7/0" ) ... etc

this is NOT the result I was looking for since they have quotation marks.

this is what I need:

( (ROUTERA AND xe-5/2/0 ) OR (ROUTERB AND xe-9/3/1 ) OR (ROUTERC AND xe-6/7/0) ... etc

thank you in advance!

0 Karma
1 Solution

woodcock
Esteemed Legend

Like this:

|inputlookup router_lookup | rename Router_Name as DEVICE_NAME Router_Interface as INTERFACE | eval Interface_Name=DEVICE_NAME." AND ".INTERFACE | fields Interface_Name | rename Interface_Name as query | format | rex field=search mode=sed "s/\"//g"

View solution in original post

woodcock
Esteemed Legend

Like this:

|inputlookup router_lookup | rename Router_Name as DEVICE_NAME Router_Interface as INTERFACE | eval Interface_Name=DEVICE_NAME." AND ".INTERFACE | fields Interface_Name | rename Interface_Name as query | format | rex field=search mode=sed "s/\"//g"

christopheryu
Communicator

That worked, thank you!

0 Karma

jkat54
SplunkTrust
SplunkTrust

Try this with your second search:

| return $query | format

But then simplify, you've got renames and such tht are really unnecessary.

|inputlookup router_lookup
| eval query=Router_Name." AND ".Router_Interface
| fields query
| return $query
| format

0 Karma

christopheryu
Communicator

Thank you for the response. Here is what I got using your suggestion:

( ("ROUTERA AND xe-5/2/0" ))

Returned only one item and did not remove the quotation marks. Removing the "| return $query" yields the same result as my second search.

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 ...