Dashboards & Visualizations

How do i set a token based on the dropdown options in splunk dashboard

splunk9879
Loves-to-Learn

i am trying to create a Splunk dashboard, where I want to set a value to a token based on the two dropdown values(service dropdown and environment dropdown)

<input type="dropdown" token="service" searchWhenChanged="true">
<label>service</label>
<choice value="capi">capi</choice>
<choice value="crapi">crapi</choice>
<choice value="oapi">oapi</choice>
<default>capi</default>
<initialValue>capi</initialValue>
</input>

<input type="dropdown" token="environment" searchWhenChanged="true">
<label>Environment</label>
<choice value="prod">prod</choice>
<choice value="ppe">ppe</choice>
<choice value="pte">pte</choice>
<choice value="dev">dev</choice>
<default>prod</default>
<initialValue>prod</initialValue>
</input>

above are the 2 dropdowns, now i want to set a value to token "endpoint" based on value selected in service and environment dropdown values.

i tried using condition match, but i am not getting it right

<condition match="$service$==capi AND $environment$==ppe">
<set token = endpoint>"/capi/ppe"</set>
</condition>

 

Labels (1)
0 Karma

bowesmana
SplunkTrust
SplunkTrust

You need to put the right hand side of the test in escaped quotes and also all should be inside a <change> element, e.g.

<change>
  <condition match="$service$=&quot;capi&quot; AND $environment$=&quot;ppe&quot;">
    <set token="endpoint">/capi/ppe</set>
  </condition>
</change>

and the quotes in the set need to be round the token name, not the value, unless you want the quotes in the value.

Hope this helps 

0 Karma

splunk9879
Loves-to-Learn

Hi bowesmana,

firstly thanks for such a quick reply.

i tried to put the below code in my xml, but i still don't see $endpoint$ in search query being populated with the value set in condition.

probably i am using condition in wrong place.

below is my xml, please let me know where i am getting wrong.

 

 

 

<form>
  <label>Apigee logs</label>
  <description>Stats based on the logs of selected services </description>
  <fieldset submitButton="false">
      <input type="dropdown" token="service" searchWhenChanged="true">
          <label>Service</label>
          <choice value="capi">capi</choice>
          <choice value="crapi">crapi</choice>
          <default>capi</default>
          <initialValue>capi</initialValue>
      </input>
    <input type="dropdown" token="environment" searchWhenChanged="true">
      <label>Environment</label>
      <choice value="ppe">ppe</choice>
      <choice value="pte">pte</choice>
      <default>ppe</default>
      <initialValue>ppe</initialValue>
    </input>
<change>
    <condition match="$service$=&quot;capi&quot; AND $environment$=&quot;ppe&quot;">
    <set token="endpoint">/capi/ppe</set>
  </condition>
</change>
    </input>
<row>
    <panel>
      <title>Response status codes over time</title>
      <chart>
        <title>only real traffic, excludes _status/_interface/(...) endpoints</title>
        <search>
          <query>index=api_$environment$
            endpoint=$endpoint$
            | timechart span="$time_span$" count by responseStatus</query>
      </chart>
    </panel>
  </row>
</form>

 

 

0 Karma

bowesmana
SplunkTrust
SplunkTrust

Change elements are part of the <input> - you will need to have it in both inputs

Do you really want to always set the endpoint to /capi/ppe or do you want to set it to some part of the selected dropdowns. 

If so, you should be using the dropdown tokens in the <set> statement for endpoint, e.g. 

<set token="endpoint">/$service$/$environment$</set>

 and in that case you would not need the condition either

0 Karma

splunk9879
Loves-to-Learn

Hi bowesmana, Thank you so much for replying back.

Below is my actual requirement 

when $service$=capi AND $environment$=ppe

set $endpoint$ = /colleague/job

when $service=capi AND $environment$=dev

set $endpoint$=/merchant/profile

0 Karma

bowesmana
SplunkTrust
SplunkTrust

You just need to then add a <condition> and <set> pair for each condition you want inside those change blocks.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...