Spread our blog

How to make the first value of a dropdown as default value

Creating a dropdown is one of the daily use-cases being a developer in Splunk. Today we will try to customize our dropdown at his very best.

So without wasting any time let’s get to the business.

We have the following query,

index=_internal sourcetype=splunkd_ui_access 
| timechart span=1d count by method 
| sort - _time

Explanation:

The above query is basically giving us the information about all the methods count based on time, which is coming from the “_internal” index and “splunkd_ui_access” source type.

Now we will save this above query into a dashboard, by clicking Save as > Dashboard panel.

Put the dashboard name and Save it.

And now go to our dashboard and click on Edit.

Now click on “Add Input” and select “Dropdown

And do as shown below.

We are using the following query to fetch all the dropdown values.

index=_internal sourcetype=splunkd_ui_access  
|timechart span=1d count by method 
|rename _time as time |eval human_time=strftime(time,"%Y-%m-%d") 
|fields time human_time 
|sort - time

Explanation:

we are taking the data from the “_internal” index and “splunkd_ui_access” source type. After that using the time chart command we bring all the counts of the method with respect to time. next, we renamed “_time” as “time” to get the epoch time of the “_time” field. Then using “strftime” we converted the time into human-readable time into “human_time” field. Then using the “fields” command we fetched “time” and “human_time”. Using the sort command we sorted “time” field. Here we have used the time field a couple of times because we will use “time” for the label field in the dropdown and will use “human_time” for the label in the dropdown.

You can also know about :  How To Find The Disk Space Limit Used By The Users In Splunk

Now click on Apply.

Then we have a dropdown which is basically giving us a list of dates. After that, we want to make the first value of the dropdown list always default. so how can we do that, now go to the source code and make the following changes as shown to achieve the above use case.

Here within the dropdown input, add the following tag

<selectFirstChoice>true</selectFirstChoice>

And within the main panel add the dropdown token “date_token”.

Now save it.

Now you will see that in the dropdown always the first value of the dropdown will be the default value, which is dynamic.

Hope you all have enjoyed this blog “How to make the first value of a dropdown as default value“. See you all on to the next one.

Happy Splunking !!

What’s your Reaction?
+1
+1
+1
1
+1
+1
1
+1
+1

Spread our blog

LEAVE A REPLY

Please enter your comment!
Please enter your name here