Dashboards & Visualizations

How to achieve a token value change based on dropdown?

mjon395
Explorer

Hi All,

I have a dashboard with a dropdown of about 40 choices that come from a search query (not static).

Each choice should "unhide" the respective panel on the dashboard. 

I do not think I am grasping the <done>, <change>, <finalized>, <condition match>, etc elements I need to figure this out.  I have created a dummy version of my actual dashboard below:

 

 

 

<form>
  <fieldset submitButton="true" autoRun="false">
    <input type="dropdown" token="dashboard">
      <label>Dashboard Selection</label>
      <fieldForLabel>Picker</fieldForLabel>
      <fieldForValue>Picker</fieldForValue>
      <search>
        <query>| makeresults
| eval Picker = "Apple,Orange"
| eval Picker = split(Picker,",")
| stats count by Picker</query>
      </search>
    </input>
  </fieldset>
  <row>
    <panel>
      <html>DEBUG TOKENS : : : showapple - $showapple$ || dashboard - $dashboard$</html>
    </panel>
  </row>
  <row>
    <panel depends="$showapple$">
      <title>Apple Dashboard</title>
      <table>
        <search>
          <query>| makeresults
| eval Events = "10.10.10.10"
| table Events</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
        <option name="refresh.display">progressbar</option>
      </table>
    </panel>
  </row>
  <row>
    <panel depends="$showorange$">
      <title>Orange Dashboard</title>
      <table>
        <search>
          <query>| makeresults
| eval Events = "192.168.1.1"
| table Events</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
      </table>
    </panel>
  </row>
</form>

 

 

 

 You will notice I do not have any code to decipher when showapple or showorange is true.  I basically tried iterations of this code to make it work:

 

 

 

          <done>
            <condition>
              <eval token="showapple">if($dashboard$="Apple","TRUE",null())</eval>
<eval token="showorange">if($dashboard$="Orange","TRUE",null())</eval>
            </condition>
          </done>

 

 

 

I have tried using the above in different areas, and I always get null().  I also tried doing <change> instead of <done> so the dashboards would change depending on the dropdown value instantly, but I did not have success there either.

Labels (3)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
<form>
  <fieldset submitButton="true" autoRun="false">
    <input type="dropdown" token="dashboard">
      <label>Dashboard Selection</label>
      <fieldForLabel>Picker</fieldForLabel>
      <fieldForValue>Picker</fieldForValue>
      <search>
        <query>| makeresults
| eval Picker = "Apple,Orange"
| eval Picker = split(Picker,",")
| stats count by Picker</query>
      </search>
      <change>
        <eval token="showapple">if("Apple"==$value$, "TRUE", null())</eval>
        <eval token="showorange">if("Orange"==$value$, "TRUE", null())</eval>
      </change>
    </input>
  </fieldset>
  <row>
    <panel>
      <html>DEBUG TOKENS : : : showapple - $showapple$ || dashboard - $dashboard$</html>
    </panel>
  </row>
  <row>
    <panel depends="$showapple$">
      <title>Apple Dashboard</title>
      <table>
        <search>
          <query>| makeresults
| eval Events = "10.10.10.10"
| table Events</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
        <option name="refresh.display">progressbar</option>
      </table>
    </panel>
  </row>
  <row>
    <panel depends="$showorange$">
      <title>Orange Dashboard</title>
      <table>
        <search>
          <query>| makeresults
| eval Events = "192.168.1.1"
| table Events</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
      </table>
    </panel>
  </row>
</form>

View solution in original post

0 Karma

ccorte
Loves-to-Learn

what is the json syntax? documentation is not clear

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
<form>
  <fieldset submitButton="true" autoRun="false">
    <input type="dropdown" token="dashboard">
      <label>Dashboard Selection</label>
      <fieldForLabel>Picker</fieldForLabel>
      <fieldForValue>Picker</fieldForValue>
      <search>
        <query>| makeresults
| eval Picker = "Apple,Orange"
| eval Picker = split(Picker,",")
| stats count by Picker</query>
      </search>
      <change>
        <eval token="showapple">if("Apple"==$value$, "TRUE", null())</eval>
        <eval token="showorange">if("Orange"==$value$, "TRUE", null())</eval>
      </change>
    </input>
  </fieldset>
  <row>
    <panel>
      <html>DEBUG TOKENS : : : showapple - $showapple$ || dashboard - $dashboard$</html>
    </panel>
  </row>
  <row>
    <panel depends="$showapple$">
      <title>Apple Dashboard</title>
      <table>
        <search>
          <query>| makeresults
| eval Events = "10.10.10.10"
| table Events</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
        <option name="refresh.display">progressbar</option>
      </table>
    </panel>
  </row>
  <row>
    <panel depends="$showorange$">
      <title>Orange Dashboard</title>
      <table>
        <search>
          <query>| makeresults
| eval Events = "192.168.1.1"
| table Events</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
      </table>
    </panel>
  </row>
</form>
0 Karma

mjon395
Explorer

Perfect, as desired.  I don't think I was close to the change and == eval tokens as you set, so you saved me a lot (more) headache.

I have additionally added extra tokens so only the specific dashboards load the query (I think?).  So instead of all 40 dashboards loading in the background, the queries fail to load unless the respective token is true.

<form>
  <fieldset submitButton="true" autoRun="false">
    <input type="dropdown" token="dashboard">
      <label>Dashboard Selection</label>
      <fieldForLabel>Picker</fieldForLabel>
      <fieldForValue>Picker</fieldForValue>
      <search>
        <query>| makeresults
| eval Picker = "Apple,Orange"
| eval Picker = split(Picker,",")
| stats count by Picker</query>
      </search>
      <change>
        <eval token="showapple">if("Apple"==$value$, "TRUE", null())</eval>
        <eval token="searchapple">if($showapple$=="TRUE","| makeresults", null())</eval>
        <eval token="showorange">if("Orange"==$value$, "TRUE", null())</eval>
        <eval token="searchorange">if($showorange$=="TRUE","| makeresults", null())</eval>
      </change>
    </input>
  </fieldset>
  <row>
    <panel>
      <html>DEBUG TOKENS : : : showapple - $showapple$ ($searchapple$) || showorange - $showorange$ ($searchorange$) || dashboard - $dashboard$</html>
    </panel>
  </row>
  <row>
    <panel depends="$showapple$">
      <title>Apple Dashboard</title>
      <table>
        <search>
          <query>$searchapple$
| eval Events = "10.10.10.10"
| table Events</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
        <option name="refresh.display">progressbar</option>
      </table>
    </panel>
  </row>
  <row>
    <panel depends="$showorange$">
      <title>Orange Dashboard</title>
      <table>
        <search>
          <query>$searchorange$
| eval Events = "192.168.1.1"
| table Events</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
      </table>
    </panel>
  </row>
</form>

Is there an issue with this method to prevent the "inactive" panels from queueing up queries? (searchapple, searchorange)

0 Karma

jdunlea
Contributor

If your dropdown is a non-static list of choices that come from a search query, how do you have a "respective panel" for each dropdown choice? If you have a respective panel for each dropdown choice, that implies that you know upfront how many dropdown options there can be. 

0 Karma

mjon395
Explorer

In the actual dashboard, the dropdown search is looking for all values within a lookup.  These values never change; it's just simpler to use the lookup to spit the values out rather than typing in the values one by one.

The only reason I mentioned that the dropdown panel uses a search for the values was because I was not sure if this would change the solution needed compared to using static options.

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!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...