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!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...