Dashboards & Visualizations

How to generate search from dashboard input with variable number of values?

sptz16
New Member

This seems to be a very simple requirement, but I'm unable to find a solution: I built a dashboard where the user enters an ip address which will then be used in a search like:

dest=$ip$

Now what I need is a way to search for 1 or more ip addresses. So, if the user enters "10.1.1.1 10.2.2.8 10.3.3.3" then the following search must be generated:

(dest=10.1.1.1 OR dest=10.2.2.8  OR dest=10.3.3.3)

Is there a way to do this?

Tags (1)
0 Karma
1 Solution

HiroshiSatoh
Champion

You can edit the value of the text field with a subquery.

index=XXX [search noop|stats count | eval dest="$ip$"|eval dest=split(dest," ") |table dest]|・・・・
↓Correct.
index=XXX [| noop|stats count | eval dest="$ip$"|eval dest=split(dest," ") |mvexpand dest|fields dest] |・・・・
(It still worked)
index=XXX [| noop|stats count | eval dest="$ip$"|eval dest=split(dest," ") |fields dest] |・・・・

View solution in original post

0 Karma

DalJeanis
Legend

For an explanation of how HiroshiSatoh's answer works, see the "format" command.

https://docs.splunk.com/Documentation/Splunk/6.5.2/Search/Changetheformatofsubsearchresults

0 Karma

HiroshiSatoh
Champion

You can edit the value of the text field with a subquery.

index=XXX [search noop|stats count | eval dest="$ip$"|eval dest=split(dest," ") |table dest]|・・・・
↓Correct.
index=XXX [| noop|stats count | eval dest="$ip$"|eval dest=split(dest," ") |mvexpand dest|fields dest] |・・・・
(It still worked)
index=XXX [| noop|stats count | eval dest="$ip$"|eval dest=split(dest," ") |fields dest] |・・・・

0 Karma

sptz16
New Member

Ah, but now it's getting more complicated. I need to search for the address list in src AND dest fields, so I tried:

[search noop | stats count | eval src="$cidr" | eval src=split(src, " "), dest=split(src, " ") |
 table src, dest ]

But it only returns events where src matches. And this:

[search noop | stats count | eval src="$cidr",dest="$cidr"
 | eval src=split(src, " "), dest=split(dest, " ")
 | table src, dest ]

yields no results at all 😞

0 Karma

HiroshiSatoh
Champion

Please perform sub search separately.

index=XXX [| noop|stats count | eval src="$cidr$"|eval src=split(src," ") |mvexpand src|fields src] [| noop|stats count | eval dest="$cidr$"|eval dest=split(dest," ") |mvexpand dest|fields dest] |・・・・

( (src=XXX) OR (src=XXX) OR (src=XXX) OR (src=XXX) ) AND ( (dest=XXX) OR (dest=XXX) OR (dest=XXX) OR (dest=XXX) )
※Please be careful because it is AND condition.

0 Karma

sptz16
New Member

Holy cow, works like a charm! Thanks a lot, HiroshiSatoh!

0 Karma

somesoni2
Revered Legend

I think you need an mvexpand command as well (after split).

0 Karma

HiroshiSatoh
Champion

I also thought so.
But just by splitting it worked fine.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...