Dashboards & Visualizations

How can I get the current time in HH:MM:SS as the default value in dropdown?

pradeepkumarg
Influencer

I have a drop down where the user can select the Time as below.

<choice value="00:00:00">00:00:00</choice>
<choice value="01:00:00">01:00:00</choice>
<choice value="02:00:00">02:00:00</choice>
<choice value="03:00:00">03:00:00</choice>
<choice value="04:00:00">04:00:00</choice>
<choice value="05:00:00">05:00:00</choice>
<choice value="06:00:00">06:00:00</choice>
<choice value="07:00:00">07:00:00</choice>
<choice value="08:00:00">08:00:00</choice>
<choice value="09:00:00">09:00:00</choice>
.
.
.
&ltchoice value="24:00:00">24:00:00</choice>

Now, I want to provide a default value which will be current time.

I think I can pass a dummy value like below


<choice value="abc">Current Time</choice>

and then handle it in my search to check for that dummy value and replace it with now() to get the time.

But wanted to check if there is a better way to do this

Tags (3)
1 Solution

strive
Influencer

Add this inside your fieldset

<input type="dropdown" token="varHours" id="field1">       
  <label>Hours :</label>
    <populatingSearch fieldForValue="hours" fieldForLabel="value">
        <![CDATA[search * | head 1 | eval tnow = now() | eval hours = strftime(tnow, "%H:%M:%S") | eval value="Current Time" | table value hours | append [| gentimes start=-1 end=0 increment=1h | eval hours = strftime(starttime, "%H:%M:%S") | eval value=hours | table value hours]]]>
    </populatingSearch>
</input>

alt text

View solution in original post

strive
Influencer

Add this inside your fieldset

<input type="dropdown" token="varHours" id="field1">       
  <label>Hours :</label>
    <populatingSearch fieldForValue="hours" fieldForLabel="value">
        <![CDATA[search * | head 1 | eval tnow = now() | eval hours = strftime(tnow, "%H:%M:%S") | eval value="Current Time" | table value hours | append [| gentimes start=-1 end=0 increment=1h | eval hours = strftime(starttime, "%H:%M:%S") | eval value=hours | table value hours]]]>
    </populatingSearch>
</input>

alt text

pradeepkumarg
Influencer

Awesome.. Thank you..

0 Karma
Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...