Splunk Search

Conditionaly Change form input variable value in the form search query

hartfoml
Motivator

I have a form that is doing SQL seach and Splunk Search using one veriable input text. When I want to use a wild card in the form I put in a "%" for SQL but this does not work for Splunk. For splunk I need to use a "*".

I tried using the eval with the if commend to change the wild card but this did not work

useing:
<input type="text" token="ip">


Then puting in the wild card "%" in the form

Then | dbquery MVM "SELECT * from TABLE WHERE IP LIKE '%$ip$%'

the SQL search runes like this | dbquery MVM "SELECT * from TABLE WHERE IP LIKE '%%%'

Then index=foo | eval ip=if(ip="%","*",ip) | search IP="*$ip$*"

the splunk search runes like this index=foo | eval ip=if(ip="%","*",ip) | search IP="*%*"

How can I convert the % to a * for the splunk search?

0 Karma

sundareshr
Legend

For your splunk search, have you tried .. | where like(ip, $ip$). With this approach, you will not have to change the % to *. Give it a try!

0 Karma
Get Updates on the Splunk Community!

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

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

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...