Splunk Search

How to append a value to the TimeRangePicker value "now"

vidda42
Explorer

Hi all !

I'm building a view in advanced XML, with a TimeRangePicker, associated with 2 searches.

  • The first search (panel_row1_col1) is showing Table, and all is fine.
  • The second search (panel_row1_col2) is building a "double-bargraph", showing the "Today" graph, and the same graph for 7 days earlier.
    That is to say that, if it's Monday the 7th, you'll get also the graph for Monday 1st on the same graph.

    This view is really usefull and easy-to-read :

My problem is that I can't do the following operation : now-7d , for the drawing on the right.

Is there any way to rewrite the "now" value, or to get a value that allows a substract ?



Final request for drawing the double-bar-graph is :

earliest=@d latest=now action="reject" CF="xxxxx" | multikv | eval ReportKey="today" | append maxtime=120 [ search earliest=@d-604800 latest=now-518400 action="reject" CF="xxxxx" | multikv | eval ReportKey="last week" | eval new_time=time+86400*7 ] | eval _time=if(isnotnull(new_time), new_time, _time) | timechart span=1h count by ReportKey


I get the following : __Invalid value "now-518400" for time term 'latest'
_

David

Tags (1)

aholzer
Motivator

You should be able to use relative values without specifying the "now". By defining latest=-24h it would set the latest alloweable time to 24 hours ago (no need to say "now"). If you define latest=-1000s it will set the latest alloweable time to 1000 seconds from the "now".

You really just need a value, a unit and a direction.

  • Unit = the unit applied to the values for the relative time (seconds = s, minutes = m, hours = h, days = d)
  • Direction = one of two values, negative (-) or positive (+) indicating whether you will be moving into the future or the past. (negative for past, positive for future)
  • Value = the amount of units to move in the direction indicated.
0 Karma

aholzer
Motivator

If you are getting the latest time from somewhere then you should probably use an eval statement with the relative_time function to calculate your latest value.

See this page and search for "relative_time" http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions

... | eval last_time=relative_time(...)

And then use last_time in your subsearch or a where "_time <= last_time"

0 Karma

vidda42
Explorer

Hi there !

Thanks for your answer, but the case is that the "earliest" & "latest" values come from the TimeRangePicker when you select Today.

All the other cases are working fine.

I'm getting the values using :
$search.timeRange.earliest$ & $search.timeRange.latest$

David

0 Karma
Get Updates on the Splunk Community!

Index This | What is broken 80% of the time by February?

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

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...