Dashboards & Visualizations

How to add timerange values to panel content?

aaronkorn
Splunk Employee
Splunk Employee

Has anyone successfully taken the time range values from a timerange picker and passed the human readable format into the title or contents? For example I have a TRP and a single value panel that shows a simple count and then the after label is: "between $time.earliest$ and $time.latest$". This effectively just passes the range i.e. for last 7 days it would read "between -7d@h and now but" would like to see the actual dates. Any ideas on how to do this in simple xml?

0 Karma

wpreston
Motivator

I use a single value panel to do this, and have the search results display the earliest and latest search times. Try adding this to your dashboard, it should run anywhere:

...
   <row>
      <panel>
         <single>
            <searchstring>|stats count | addinfo | eval startDate=strftime(info_min_time,"%m/%d/%y @ %l:%M%p") | eval endDate=strftime(info_max_time,"%m/%d/%y @ %l:%M%p") | eval searchTime=startDate+" to "+endDate | stats values(searchTime)</searchstring>
            <earliestTime>$earliest$</earliestTime>
            <latestTime>$latest$</latestTime>
            <option name="underLabel">Is the time period of events in this search</option>
         </single>
      </panel>
   </row>
0 Karma

somesoni2
Revered Legend

See if this works for you. (run anywhere example)

<form>
  <label>ErrorWarningDistribution</label>
  <fieldset submitButton="False">
    <input type="time">
        <default>Yesterday</default>
    </input>
    <input type="dropdown" token="title" id="field2">
      <selectFirstChoice>true</selectFirstChoice>
      <populatingSearch fieldForValue="title" fieldForLabel="title">
        <![CDATA[
| gentimes start=-1 | addinfo | eval title="between '".strftime(info_min_time,"%F %T")."' and '".strftime(info_max_time,"%F %T")."'"]]>
      </populatingSearch>
    </input>
    <html id="field3">
<style>
.input#field2
{
display:none;
}
</style>      
    </html>
  </fieldset>
  <row>
    <panel>
      <chart>
        <title>Showing report to period $title$</title>
        <searchString>index=_internal log_level=*
          | chart count(eval(log_level="ERROR")) as ERROR 
          count(eval(log_level="WARN")) as WARNING over date_mday by sourcetype</searchString> 
        <option name="charting.chart">column</option>        
      </chart>
    </panel>
  </row>
</form>
0 Karma

MattZerfas
Communicator

Somesoni2 were you ever able to get the issue fixed with it not always updating when the time is changed? What you have here is exactly what I need but I need to have it fully working. Also another note is that this seems to have broken in 6.2.

0 Karma

somesoni2
Revered Legend

I guess this approach has a issue that the title is not getting updated after changing the time. I will see if I can get that part working.

0 Karma

aaronkorn
Splunk Employee
Splunk Employee

I am on 6.1.2

0 Karma

somesoni2
Revered Legend

What version of Splunk are you using?

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...