Dashboards & Visualizations

How to offset the token from a time picker

duesser
Path Finder

I basically have the exact same question as https://community.splunk.com/t5/Dashboards-Visualizations/How-to-have-a-panel-use-an-offset-from-a-t....

 

BUT I need to actually change the value in the timerange picker token. E.G. if i select a timerange of "last 4 hour" and my modification is to add an hour, than the $token_time.earliest$ should not be  "-4h" but "-5h".

Labels (4)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try this - although this doesn't work with all options from time pickers - I haven't found an easy way to deal with all options.

<change>
  <eval token="starttime">relative_time(relative_time(now(),$timepicker.earliest$),"-1h")</eval>
  <eval token="finishtime">relative_time(relative_time(now(),$timepicker.latest$),"-1h")</eval>
</change>

View solution in original post

PickleRick
SplunkTrust
SplunkTrust

Also - you can "stack up" time specifiers. Look at this example:

PickleRick_0-1701784270714.png

 

0 Karma

duesser
Path Finder

I am aware of this, which is why I linked the question where this was answered already. I need to change the token within the XML dashboard.

0 Karma

PickleRick
SplunkTrust
SplunkTrust

But why exactly do you want to change the token itself? Isn't it enough to skew the timerange for the resulting search?

0 Karma

duesser
Path Finder

I am loading the search from a datamodel, so I can not do 

| datamodel earliest=$<time_token>$-1h
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Create a new token in the change handler for the timepicker which is based on an hour difference to the timepicker earliest value. If you start changing the timepicker itself, this will be seen as a  change which will then add another hour, which will be seen as a change, and so on.

0 Karma

duesser
Path Finder

I am aware of this, however I was not able to accomplish this. Could you specify HOW EXACTLY you would accomplish this - e.g. shift earliest to earliest-1h within the input part of XML?

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

<change>
  <eval token="starttime">relative_time($timepicker.earliest$","-1h")</eval>
  <eval token="finishtime">relative_time($timepicker.latest$","-1h")</eval>
</change>
0 Karma

duesser
Path Finder

This does not work for me. It evaluates to "NaN". I guess the issue beeing, that $timepicker.xxx$ is filled with "-24h@h" for example, rather than UNIX time.  Maybe it would make sense to post this as a seperate question. "how to convert "-24h@h" or so into UNIX time"?

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try this - although this doesn't work with all options from time pickers - I haven't found an easy way to deal with all options.

<change>
  <eval token="starttime">relative_time(relative_time(now(),$timepicker.earliest$),"-1h")</eval>
  <eval token="finishtime">relative_time(relative_time(now(),$timepicker.latest$),"-1h")</eval>
</change>

duesser
Path Finder

When does it not work? For my intends and purposes it is sufficient! Thank you alot!

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

iirc it is when you use "last hour" (for example) as the latest become the string "now" which confuses relative_time although it might also be when you use advanced as you can get an epoch time.

Get Updates on the Splunk Community!

Enter the Splunk Community Dashboard Challenge for Your Chance to Win!

The Splunk Community Dashboard Challenge is underway! This is your chance to showcase your skills in creating ...

.conf24 | Session Scheduler is Live!!

.conf24 is happening June 11 - 14 in Las Vegas, and we are thrilled to announce that the conference catalog ...

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...