Dashboards & Visualizations

User Multiselect Token In Different Searches

tjago11
Communicator

I have a single input on a dashboard that is used in two different searches. The input is a multiselect so I'm using the valuePrefix and valueSuffix properties to format the token for the search. Something like this:

<input type="multiselect" token="hostFilter" searchWhenChanged="true">
  <label>Server</label>
  <search>
    <query>| get my list of servers</query>
    <earliest>-15m</earliest>
    <latest>now</latest>
  </search>
  <valuePrefix>host="</valuePrefix>
  <valueSuffix>)"</valueSuffix>
  <delimiter> OR </delimiter>
  <prefix>(</prefix>
  <suffix>)</suffix>
</input>

This generates a nice OR delimited list of hosts like (host="myHost1" OR host="myHost2") that I can use in a search. Sweet!!

The problem is I want to use that same value in a different area of my dashboard but it needs to be formatted differently. Instead of an OR delimited list with a prefix/suffix, I need to pass it as a comma delimited list for use in a macro like this:
| CallTheMacro("myHost1, myHost2")

In this case the multiselect would have a completely different configuration:

<input type="multiselect" token="hostFilter" searchWhenChanged="true">
  <label>Server</label>
  <search>
    <query>| get my list of servers</query>
    <earliest>-15m</earliest>
    <latest>now</latest>
  </search>
  <delimiter>,</delimiter>
  <prefix>"</prefix>
  <suffix>"</suffix>
</input>

I was able to get something working adding a change condition to the input and doing replaces on the generated token...it is icky and I'm hoping there is a better way:

 <input type="multiselect" token="hostFilter" searchWhenChanged="true">
   <label>Server</label>
   <search>
     <query>| get my list of servers</query>
     <earliest>-15m</earliest>
     <latest>now</latest>
   </search>
   <valuePrefix>host="</valuePrefix>
   <valueSuffix>)"</valueSuffix>
   <delimiter> OR </delimiter>
   <prefix>(</prefix>
   <suffix>)</suffix>
  <change>
    <condition>
      <eval token="macroInput">
        replace('hostFilter', "host=", "")
      </eval>
      <eval token="macroInput">
        replace('macroInput', "\\"", "")
      </eval>
      <eval token="macroInput">
        replace('macroInput', " OR ", ",")
      </eval>
      <eval token="macroInput">
        replace('macroInput', "\\(", "\\"")
      </eval>
      <eval token="macroInput">
        replace('macroInput', "\\)", "\\"")
      </eval>
    </condition>
  </change>
 </input>

What is a bit cool is chaining together the replaces to simplify each step...but it is still very clunky. Any suggestions welcome, thanks.

0 Karma

rvany
Communicator

What I find interesting about this is, that Splunk docs say: <change> and <condition> are "Not available for multiselect inputs" 😉

0 Karma
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!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...