Hello I need help on creating multiple dependent dropdown.
Criteria :
1.one drop down has three environments ( stage, test and prod) - each environment has three applications (s1,s2 and s3)
2. second drop down has three applications ( s1,s2 and s3) - this is dependent on environment.
3. Each application has three different indexes which should be passed based on above 2 dropdowns.
If I select stage as first drop down then 2nd drop down should show all application and then the search should run the application with then environment selected.
eg: I selected stage and second drop down as s1 so search query is index = s1_stage
Based on the example given, I think the OP wants to adapt dropdowns to actual deployed application and environment combination dynamically. So, I'd take a different route. The key is the composition of index names. I think what you want is like
| tstats count by index
| rex field=index "[^_]+_(?<environment>.+)"
| stats count by environment
| fields - count| tstats count by index
| rex field=index "(?<application>[^_]+)_"
| stats count by application
| fields - countHere is a complete mockup dashboard:
<form version="1.1" theme="light">
<label>multiple dependent dropdown Dashboard</label>
<description>https://community.splunk.com/t5/Dashboards-Visualizations/Create-multiple-dependent-dropdown-Dashboard/m-p/758134#M59378</description>
<fieldset submitButton="false">
<input type="dropdown" token="environment_tok">
<label>Environment</label>
<fieldForLabel>environment</fieldForLabel>
<fieldForValue>environment</fieldForValue>
<search>
<query>| makeresults
| eval environment = split("stage,test,prod", ","), application = mvappend("s1", "s2", "s3")
| mvexpand environment
| mvexpand application
| eval index = application . "_" . environment
| stats count by index
``` the above emulates
| tstats count by index ```
| rex field=index "\S+_(?<environment>.+)"
| stats count by environment
| fields - count</query>
<earliest>-24h@h</earliest>
<latest>now</latest>
</search>
</input>
<input type="dropdown" token="application_tok">
<label>Application</label>
<fieldForLabel>application</fieldForLabel>
<fieldForValue>application</fieldForValue>
<search>
<query>| makeresults
| eval environment = split("stage,test,prod", ","), application = mvappend("s1", "s2", "s3")
| mvexpand environment
| mvexpand application
| eval index = application . "_" . environment
| stats count by index
``` the above emulates
| tstats count by index ```
| rex field=index "(?<application>[^_]+)_"
| stats count by application
| fields - count
</query>
<earliest>-24h@h</earliest>
<latest>now</latest>
</search>
</input>
</fieldset>
<row>
<panel>
<title>This is what you put in your search</title>
<html>
<pre>
index="$application_tok$_$environment_tok$"
blah, blah
</pre>
</html>
</panel>
<panel>
<title>This is what your search renders into</title>
<html>
<pre>
index="$application_tok$_$environment_tok$"
blah, blah
</pre>
</html>
</panel>
</row>
<row>
<panel>
<title>Use this search for environment</title>
<html>
<pre>
| tstats count by index
| rex field=index "[^_]+_(?<environment>.+)"
| stats count by environment
| fields - count
</pre>
</html>
</panel>
<panel>
<title>Use this search for application</title>
<html>
<pre>
| tstats count by index
| rex field=index "(?<application>[^_]+)_"
| stats count by application
| fields - count
</pre>
</html>
</panel>
</row>
</form>This way, no matter what combination of deployment is, the dropdowns always have the correct elements.
Hi @akumarsripathi ,
the easiest way is to crete a lookup containing the associtions between environments, applications and indexes, es:
env app index
stage s1 index1
stage s1 index2
stage s1 index3
stage s2 index1
stage s2 index2
stage s2 index3
stage s3 index1
stage s3 index2
stage s3 index3
test s1 index1
test s1 index2
test s1 index3
test s2 index1
test s2 index2
test s2 index3
test s3 index1
test s3 index2
test s3 index3
prod s1 index1
prod s1 index2
prod s1 index3
prod s2 index1
prod s2 index2
prod s2 index3
prod s3 index1
prod s3 index2
prod s3 index3then you can create the three dropdowns using the token of the previous dorpdown:
<input type="dropdown" token="env" searchWhenChanged="true">
<label>Select an environment:</label>
<prefix>env="</prefix>
<suffix>"</suffix>
<default>*</default>
<choice value="*">All</choice>
<fieldForLabel>env</fieldForLabel>
<fieldForValue>env</fieldForValue>
<search>
<query>| inputlookup my_lookup.csv | dedup env | table env</query>
<earliest>-24h</earliest>
<latest>now</latest>
</search>
</input>
<input type="dropdown" token="app" searchWhenChanged="true">
<label>Select an app:</label>
<prefix>app="</prefix>
<suffix>"</suffix>
<default>*</default>
<choice value="*">All</choice>
<fieldForLabel>app</fieldForLabel>
<fieldForValue>app</fieldForValue>
<search>
<query>| inputlookup my_lookup.csv WHERE $env$ | dedup app | table app</query>
<earliest>-24h</earliest>
<latest>now</latest>
</search>
</input>
<input type="dropdown" token="index" searchWhenChanged="true">
<label>Select an index:</label>
<prefix>index="</prefix>
<suffix>"</suffix>
<default>*</default>
<choice value="*">All</choice>
<fieldForLabel>index</fieldForLabel>
<fieldForValue>index</fieldForValue>
<search>
<query>| inputlookup my_lookup.csv | WHERE $env$ AND $app$ | dedup index | table index</query>
<earliest>-24h</earliest>
<latest>now</latest>
</search>
</input>Ciao.
Giuseppe
Where are these dependencies defined?
Assuming that they are in some sort of lookup, you can use the change handler of the first dropdown to set a token which is used in the search to setup the second dropdown. You can then use the change handler of the second dropdown to select the appropriate index.