Dashboards & Visualizations

How to only include an input token in search if it has a value

frbuser
Path Finder

I have a form dashboard that has several input fields. How do I only use a token if it has a value? Mean I may want to leave the input blank and not pass anything to the search. So the input is optional.

The reason is my results don't always include some fields in every log. So if pass * as the default and it ends up being field=* this will exclude logs which don't have the field present. How do I get around this?

I only want my search to become field=$input$ if the user actually filled out the input. Otherwise I want the entire line removed.

0 Karma

manjunathmeti
Champion

Use prefix element like below. Here token $input$ is set to field = value when user provides an input else it will be empty.

<form>
  <label>Test</label>
  <fieldset submitButton="true">
    </input>
    <input type="text" token="input">
      <label>Input text</label>
      <prefix>field = </prefix>
    </input>
  </fieldset>
  <row>
    <panel>
      <table>
        <title>Test</title>
        <search>
          <query>index=INDEX $input$</query>
        </search>
        <option name="list.drilldown">none</option>
      </table>
    </panel>
  </row>
 </form>
0 Karma

frbuser
Path Finder

@manjunathmeti That's AWESOME! It works for the "text" input type. How would you do the same for muli-select inputs?

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