Dashboards & Visualizations

How to dynamically fill in a dropdown?

wti
Engager

Hello all,

We have some custom JSON data getting in to Splunk. We are also creating some dashboards with this data.
Everything is working great, except for drop down boxes.

In our data, (below), we have JSON coming from two different devices, one has a plugcount of 8 and another has a plugcount of 4.

In our dropdown we are reading the JSON values, the listbox shows values of 8, and 4 as the only selections (as expected).

What I would like to do is show all selections for the numbers in between, from 1 to the maximum read also (i.e. 1,2,3,4,5,6,7,8).
Could anyone point me in the right direction ?
Thanks.

JSON CODE sent to Splunk
{
    "sourcetype": "powerdata",
    "event": {
        "timestamp": "2019-05-22T17:14:53+00:00", 
        "siteid": "OFFICE158RACK", 
        "assettag": "DEVICECPM16", 
        "branchcount": "4", 
        "plugcount": "8", 
    }
}

{
    "sourcetype": "powerdata",
    "event": {
        "timestamp": "2019-05-22T17:14:55+00:00", 
        "siteid": "OFFICE158RACK", 
        "assettag": "DEVICEVMR8", 
        "branchcount": "2", 
        "plugcount": "4", 
    }
}

evania
Splunk Employee
Splunk Employee

Hi @wti ,

Did you have a chance to check out @niketnilay 's answer? If it worked, please resolve this post by approving it! If your problem is still not solved, keep us updated so that someone else can help you.

Thanks for posting!

0 Karma

niketn
Legend

@wti you can try adding the following to your existing search instead of | stats count by plugcount:

  <yourCurrentSearch  to fetch plugcount>
 | stats max(plugcount) as plugcount
 | eval "plugcount"='plugcount'+1
 | eval "plugcount"=mvrange(1,'plugcount')
 | stats count by plugcount
 | fields - count

PS: As per Post Processing Best Practices, you should not pass on raw data through post-processing (which may actually silently drop data as well and also cause high memory consumption in your dashboard). If you really need to reuse the data from a search result across the dashboard, you should ensure the data is sent through a transforming command via the base search like stats or timechart so that results are reduced to what you are interested in.

Try the following run anywhere example based on the sample data provided

| makeresults 
| eval _raw=
    "{
     \"sourcetype\": \"powerdata\",
     \"event\": {
         \"timestamp\": \"2019-05-22T17:14:53+00:00\", 
         \"siteid\": \"OFFICE158RACK\", 
         \"assettag\": \"DEVICECPM16\", 
         \"branchcount\": \"4\", 
         \"plugcount\": \"8\"
         }
 }" 
| append 
    [| makeresults 
    | eval _raw=
        "{
        \"sourcetype\": \"powerdata\",
        \"event\": {
        \"timestamp\": \"2019-05-22T17:14:55+00:00\", 
        \"siteid\": \"OFFICE158RACK\", 
        \"assettag\": \"DEVICEVMR8\", 
        \"branchcount\": \"2\", 
        \"plugcount\": \"4\"
        }
        }"]
 | spath
 | stats max(event.plugcount) as event.plugcount
 | eval "event.plugcount"='event.plugcount'+1
 | eval "event.plugcount"=mvrange(1,'event.plugcount')
 | stats count by event.plugcount
 | fields - count
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

somesoni2
Revered Legend

What's your current query that populates the dropdown?

0 Karma

wti
Engager
 <query>index="main" | table sourcetype, siteid, assettag,  branchcount, plugcount,  timestamp  |  eval timestamp_epoc = strptime (timestamp, "%Y-%m-%d") | eval release_year = strftime(timestamp_epoc, "%Y") | eval release_month = strftime(timestamp_epoc, "%m") | fillnull value="No Defined" release_year,  plugcount | search sourcetype=powerdata  </query>

 <input type="dropdown" token="branchcount" searchWhenChanged="true">
   <label>branchcount</label>
   <search base="base_search">
     <query>| stats count by branchcount</query>
   </search>
   <choice value="*">All</choice>
   <default>*</default>
   <initialValue>*</initialValue>
   <fieldForLabel>branchcount</fieldForLabel>
   <fieldForValue>branchcount</fieldForValue>
 </input>   
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!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...