Splunk Search

Can a variable value which depends on a dropdown token be included in search?

efranke
New Member

Hello everyone,

I am trying to assign a value to "myVar", which depends on a dropdown token on my dashboard. The value of "myVar" is used to search for a specific sourcetype. This is my current solution which does not work:

index="dev_analytics" OR index="live_analytics" | 
eval myVar=case($instance$==servertoserver-test,"flink_dev2",$instance$==servertoserver-prod,"s2sdatacollector") | 
where sourcetype==myVar

It works, if I just assign the specific value to "myVar" (eval myVar=="mySourcetype"). For specifc reasons, I can not do something like sourcetype=$instance$.

Is there anything I can do to make my solution work?

Thanks in advance and regards,
Eric

0 Karma
1 Solution

renjith_nair
SplunkTrust
SplunkTrust

@efranke ,

Set the value at the dropdown on change event.

Here is an example

<form>
  <label>efranke</label>
  <fieldset submitButton="false">
    <input type="dropdown" token="instance">
      <label>Instance</label>
      <choice value="servertoserver-test">servertoserver-test</choice>
      <choice value="servertoserver-prod">servertoserver-prod</choice>
      <default>servertoserver-test</default>
      <initialValue>servertoserver-test</initialValue>
      <change>
        <condition value="servertoserver-test">
          <set token="sourcetype">flink_dev2</set>
        </condition>
        <condition value="servertoserver-prod">
          <set token="sourcetype">s2sdatacollector</set>
        </condition>
      </change>
    </input>
  </fieldset>
  <row>
    <panel>
      <title>Result for $sourcetype$</title>
      <table>
        <search>
          <query>index="dev_analytics" OR index="live_analytics" sourcetype="$sourcetype$"</query>
          <earliest>-15m</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
      </table>
    </panel>
  </row>
</form>
Happy Splunking!

View solution in original post

0 Karma

efranke
New Member

@renjith.nair

Thank you, the solution works perfectly for me.

Regards,
Eric

0 Karma

renjith_nair
SplunkTrust
SplunkTrust

@efranke ,

Set the value at the dropdown on change event.

Here is an example

<form>
  <label>efranke</label>
  <fieldset submitButton="false">
    <input type="dropdown" token="instance">
      <label>Instance</label>
      <choice value="servertoserver-test">servertoserver-test</choice>
      <choice value="servertoserver-prod">servertoserver-prod</choice>
      <default>servertoserver-test</default>
      <initialValue>servertoserver-test</initialValue>
      <change>
        <condition value="servertoserver-test">
          <set token="sourcetype">flink_dev2</set>
        </condition>
        <condition value="servertoserver-prod">
          <set token="sourcetype">s2sdatacollector</set>
        </condition>
      </change>
    </input>
  </fieldset>
  <row>
    <panel>
      <title>Result for $sourcetype$</title>
      <table>
        <search>
          <query>index="dev_analytics" OR index="live_analytics" sourcetype="$sourcetype$"</query>
          <earliest>-15m</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
      </table>
    </panel>
  </row>
</form>
Happy Splunking!
0 Karma
Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...