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
SplunkTrust
SplunkTrust

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
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...