Splunk Search

How can I reset the "search timeframe" based on data in results?

vbumgarner
Contributor

Is there any way to "reset" the "search timeframe" so that all the "commands that bin" will honor a new "search timeframe" instead of the timeframe used in the original query?

Background:
I have some data where _time doesn't mean anything useful, and I reset _time in the query itself. timechart/bin/sparkline seem to doggedly pay attention to the timeframe from the original query. Is there any way in the query to "reset" what "earliest" and "latest" are, using eventstats or similar, so that downstream commands use the calculated timeframe?

0 Karma

gergelybata
Explorer

Can you identify the "interesting" earliest/latest time and pass them as variable using the | map command?
Or if you only need a custom length sparkline with a special start/end condition (e.g. value larger than 100), you can edit the sparkline field using mv.... commands. E.g. Leaving only 10 tailing zeros at the end of the sparkline (fieldname=spcount and sorry about the regexp):

| nomv spcount | eval spcount =replace(spcount,"(##__SPARKLINE__##,[0-9,]+[1-9]{1},)\S+(0,0,0,0,0,0,0,0,0,0)$|(##__SPARKLINE__##,[0-9,]+)","\1\2\3") |  makemv delim="," setsv=true spcount
0 Karma

vbumgarner
Contributor

Interesting. If I handed it to map, I'm afraid I'd be pinned to the limits of a subsearch, but it's an interesting idea.

I ended up doing something much like your example, but it's a pain, and certainly not easy to explain to anyone else.

What you absolutely can't do is something like this:

search ... | eval _time=fieldX | timechart fixedrange=false bins=100 count by fieldY 

I believe it bins everything at some range relevant to the original query, which in my case ends up being a bin size of a second. So, you end up with thousands of bins.

I think I'd be set if I could do something like...

search ... | eval _time=fieldX | eventstats min(_time) as _search_earliest max(_time) as _search_latest | timechart fixedrange=100 bins=20 count by fieldY
0 Karma

niketnilay
Legend

If your sparkline are not dependent on timeseries data, you can use Pie sparkline instead (or bullet or box-plot).

Refer to my answers for other options available with sparklines: https://answers.splunk.com/answers/474127/pie-chart-sparkline-to-see-filling-ratio-of-splunk.html

PS: As informed, officially supported sparkline visualizations are only line, bar and area, but other sparklines from http://omnipotent.net/jquery.sparkline/#s-about, seem to work as well.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

vbumgarner
Contributor

I am dependent on time data, but the time data isn't in the timeframe of the original query. The timeframe of the original query isn't relevant.

0 Karma
Get Updates on the Splunk Community!

Improve Your Security Posture

Watch NowImprove Your Security PostureCustomers are at the center of everything we do at Splunk and security ...

Maximize the Value from Microsoft Defender with Splunk

 Watch NowJoin Splunk and Sens Consulting for this Security Edition Tech TalkWho should attend:  Security ...

This Week's Community Digest - Splunk Community Happenings [6.27.22]

Get the latest news and updates from the Splunk Community here! News From Splunk Answers ✍️ Splunk Answers is ...