Dashboards & Visualizations

how to format and use time picker values in panel title?

stwong
Communicator

Hi, is it possible to format time picker value, e.g. $earliest$ and $latest$, in panel title? If i do something like this:

 <title>Total access for department $d_name$ between $earliest$ and $latest$</title>

It gives raw time format, or the relative values like -4d@d. We hope to print the values in yyyymmdd HH:MM:SS in title. Please help.

Thanks a lot.

/ST Wong

0 Karma
1 Solution

gokadroid
Motivator

Can you first try to evaluate the string you are interested in as tokens using eval and then use those tokens in the title. Say the token of your timepicker is myTimepicker then try something like this and see if it works out:

<eval token="fromDate">strftime($myTimepicker.earliest$,"%Y%m/%d %H:%M:%S")</eval>
<eval token="toDate">strftime($myTimepicker.latest$, "%Y%m/%d %H:%M:%S")</eval>

And then later use $fromDate$ and $toDate$ in the panel title.

View solution in original post

0 Karma

stwong
Communicator

Hi all,

Thanks for your help. Both ways work with custom time range is selected. However, strftime doesn't understand relative time specifiers like -30m@m, which is used quite frequently by our users.

Thanks again.

0 Karma

aaraneta_splunk
Splunk Employee
Splunk Employee

@stwong - It looks like you found a solution to your question? If one of them provided a working solution, please don't forget to click "Accept" below the best answer to resolve this post so that it can easily be found by other users in the same situation. Don’t forget to upvote anything that was helpful too. Thanks!

0 Karma

stwong
Communicator

Got it. Thanks.

0 Karma

gokadroid
Motivator

You are welcome!

0 Karma

somesoni2
Revered Legend

Try this runanywhere sample

<form>
  <label>TobeDeleted</label>
  <fieldset submitButton="false">
    <input type="time" token="timerange" searchWhenChanged="true">
      <label>Time Range</label>
      <default>
        <earliest>-15m</earliest>
        <latest>now</latest>
      </default>
      </input>
  </fieldset>
  <search>
        <query>| gentimes start=-1 | addinfo </query>
        <earliest>$timerange.earliest$</earliest>
        <latest>$timerange.latest$</latest>
        <done>
          <eval token="Tearliest">strftime($result.info_min_time$,"%F %T")</eval>
          <eval token="Tlatest">strftime($result.info_max_time$,"%F %T")</eval>
        </done>
      </search>
  <row>
    <panel>
      <table>
        <title>Showing data between $Tearliest$ and $Tlatest$</title>
        <search>
          <query>|gentimes start=-1 | eval Message="Dummy Panel" | table Message </query>
          <earliest>$timerange.earliest$</earliest>
        <latest>$timerange.latest$</latest>
        </search>
        <option name="wrap">true</option>
        <option name="rowNumbers">false</option>
        <option name="dataOverlayMode">none</option>
        <option name="drilldown">row</option>
        <option name="count">10</option>
      </table>      
    </panel>
  </row>
</form>

gokadroid
Motivator

Can you first try to evaluate the string you are interested in as tokens using eval and then use those tokens in the title. Say the token of your timepicker is myTimepicker then try something like this and see if it works out:

<eval token="fromDate">strftime($myTimepicker.earliest$,"%Y%m/%d %H:%M:%S")</eval>
<eval token="toDate">strftime($myTimepicker.latest$, "%Y%m/%d %H:%M:%S")</eval>

And then later use $fromDate$ and $toDate$ in the panel title.

0 Karma
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

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