All Apps and Add-ons

How to edit my XML to populate values in a drop-down upon selecting a token in another drop-down?

lloydknight
Builder

Hello Guys,

So the idea is like this,

Whenever I will select choice value = Pancakes on the 1st dropdown, the 2nd dropdown should be populated with host01, host02, and host03 (not host01 OR host02 OR host03 )
and
Whenever I will select choice value = Cookies on the 1st dropdown, the 2nd dropdown should be populated with host04, host05, and host06 (not host04 OR host05 OR host06 )

Both Pancakes and Cookies share the same token name which is host because I am using the scripted inputs on Splunk Add-on for Unix and Linux

Can you guys guide me or give a clear path on how to execute this?

Thank you in advance!

here's the code:

<form>
  <label>Servers</label>
  <fieldset submitButton="false">
    <input type="dropdown" token="System" searchWhenChanged="true">
      <label>System Name</label>
      <choice value="Pancakes">Pancakes</choice>
       <choice value="Cookies">Cookies</choice>
       <default></default>
      <change>
      <condition label="Pancakes">
        <set token="System">$host$</set>
      <choice value="host01">host01</choice>
      <choice value="host02">host02</choice>
      <choice value="host03">host03</choice>
          </condition>
      <condition label="Cookies">
        <set token="System">$host$</set>
      <choice value="host04">host04</choice>
      <choice value="host05">host04</choice>
      <choice value="host06">host04</choice>
      </condition>
      </change>
    </input>
    <input type="dropdown" token="host" searchWhenChanged="false">
      <label>Hostname</label>

*//choice value should be displayed here base on the selected token @ 1st dropdown*


      <default>$System$</default>     
         </input>
  </fieldset>
  <row>
    <panel>
      <chart>
        <search>
          <query>index=os host=$host$ tag=performance tag=storage MountedOn=* earliest="10/1/2016:00:01:00" latest="10/31/2016:23:59:59"
            | rex field=UsePct "(?<Usage>(\d+%))"
            | eval Usage=replace (Usage,"%","")
            | eval Usage=tonumber(trim(Usage))
            | bucket _time span=1d
            | timechart max(Usage) by MountedOn limit=0</query>
          <earliest>0</earliest>
          <latest></latest>
        </search>
        <option name="charting.axisLabelsX.majorLabelStyle.overflowMode">ellipsisNone</option>
        <option name="charting.axisLabelsX.majorLabelStyle.rotation">0</option>
        <option name="charting.axisTitleX.visibility">visible</option>
        <option name="charting.axisTitleY.visibility">visible</option>
        <option name="charting.axisTitleY2.visibility">visible</option>
        <option name="charting.axisX.scale">linear</option>
        <option name="charting.axisY.scale">linear</option>
        <option name="charting.axisY2.enabled">0</option>
        <option name="charting.axisY2.scale">inherit</option>
        <option name="charting.chart">line</option>
        <option name="charting.chart.bubbleMaximumSize">50</option>
        <option name="charting.chart.bubbleMinimumSize">10</option>
        <option name="charting.chart.bubbleSizeBy">area</option>
        <option name="charting.chart.nullValueMode">gaps</option>
        <option name="charting.chart.showDataLabels">none</option>
        <option name="charting.chart.sliceCollapsingThreshold">0.01</option>
        <option name="charting.chart.stackMode">default</option>
        <option name="charting.chart.style">shiny</option>
        <option name="charting.drilldown">all</option>
        <option name="charting.layout.splitSeries">0</option>
        <option name="charting.layout.splitSeries.allowIndependentYRanges">0</option>
        <option name="charting.legend.labelStyle.overflowMode">ellipsisMiddle</option>
        <option name="charting.legend.placement">right</option>
        <option name="wrap">true</option>
        <option name="rowNumbers">false</option>
        <option name="dataOverlayMode">none</option>
        <option name="count">10</option>
      </chart>
    </panel>
  </row>
</form>
0 Karma

niketn
Legend

You should define a lookup table for mapping values of System and Host. For example system_to_host.csv

System, host
Pancakes, host1
Pancakes, host2
Pancakes, host3
Cookies, host4
Cookies, host5
Cookies, host6

Your first input dropdown System Name, should have the following code

<input type="dropdown" token="System" searchWhenChanged="true">
  <label>System Name</label>
  <choice value="*">All</choice>
  <choice value="Pancakes">Pancakes</choice>
  <choice value="Cookies">Cookies</choice>
  <default>*</default>
</input>

PS: I have added default value All to map to * and match all results for both inputs.

Your second input Host Name should be built from Dynamic Search query based on value selected in System Name. Provided you have created Lookup Definition system_to_host from the above csv file, following is your second dropdown code :

<input type="dropdown" token="host">
  <label>Host Name</label>
  <choice value="*">All</choice>
  <fieldForLabel>host</fieldForLabel>
  <fieldForValue>host</fieldForValue>
  <search>
    <query>| inputlookup system_to_host | search System=$System$ | table host</query>
  </search>
</input>
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

gokadroid
Motivator

What I am not able to understand, and I apologize for my miss is, what exactly does this statement mean:
2nd dropdown should be populated with host01, host02, and host03 (not host01 OR host02 OR host03 )
2nd dropdown should be populated with host04, host05, and host06 (not host04 OR host05 OR host06 )

What purpose does this second drop down serve?

0 Karma

lloydknight
Builder

on the 1st drowdown which are the Systems (Pancakes, Cookies), upon selecting Pancakes, only the 3 hosts will appear in the 2nd dropdown. I mentioned (not host01 OR host02 OR host03 ) because some answers that I found here uses this value which selects the 3 hosts simultaneously which is not my requirement.

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...