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",
}
}
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!
@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
What's your current query that populates the dropdown?
<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>