Splunk Search

Select the right index based on value in Dropdown

sandmountain
Explorer

I have a dropdown with two values PROD and TEST. Based on my selection in my panels in the dashboard I have to choose a different index for my search. How can I do this?

Example of two searches: (which also includes other tokens. These can be ignored. Both searches work if I directly put in the right index

1/ 
index=<IF PROD then AAA_prod_index else AAA_test_index> sourcetype IN (abc:edge:api, abc:edge:api)  proxy!="ow*" $client_token$ $target_token$ |
rex mode=sed field=proxy "s#^(.*?)_(.*)$#*_\2#" | stats count by proxy

2/
index=<IF PROD then BBB_prod_index else BBB_test_index> sourcetype=accesslog  tenant=$tenant_token$ | stats count by HTTPStatusCode

Labels (4)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

Your dropdown token, for example

<input type="dropdown" token="environment">
  <label>Environment</label>
  <choice value="prod">PROD</choice>
  <choice value="test">TEST</choice>
</input>
...

and then the searches just use that token

index=AAA_$environment$_index sourcetype IN (abc:edge:api, abc:edge:api)  proxy!="ow*" $client_token$ $target_token$ |
rex mode=sed field=proxy "s#^(.*?)_(.*)$#*_\2#" | stats count by proxy
----
index=BBB_$environment$_index sourcetype=accesslog  tenant=$tenant_token$ | stats count by HTTPStatusCode

View solution in original post

sandmountain
Explorer

Thx that worked fine

0 Karma

bowesmana
SplunkTrust
SplunkTrust

Please mark the answer as a solution for others to benefit from - thanks

0 Karma

bowesmana
SplunkTrust
SplunkTrust

Your dropdown token, for example

<input type="dropdown" token="environment">
  <label>Environment</label>
  <choice value="prod">PROD</choice>
  <choice value="test">TEST</choice>
</input>
...

and then the searches just use that token

index=AAA_$environment$_index sourcetype IN (abc:edge:api, abc:edge:api)  proxy!="ow*" $client_token$ $target_token$ |
rex mode=sed field=proxy "s#^(.*?)_(.*)$#*_\2#" | stats count by proxy
----
index=BBB_$environment$_index sourcetype=accesslog  tenant=$tenant_token$ | stats count by HTTPStatusCode
Get Updates on the Splunk Community!

Stay Connected: Your Guide to July and August Tech Talks, Office Hours, and Webinars!

Dive into our sizzling summer lineup for July and August Community Office Hours and Tech Talks. Scroll down to ...

Edge Processor Scaling, Energy & Manufacturing Use Cases, and More New Articles on ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Get More Out of Your Security Practice With a SIEM

Get More Out of Your Security Practice With a SIEMWednesday, July 31, 2024  |  11AM PT / 2PM ETREGISTER ...