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!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...