Splunk Search

Set earliest and latest time using a variable

zamberetta
New Member

Hi!

I'm trying to set the earliest and latest for a sub-search using a variable from the main search. The code below shows what I am trying to accomplish.

sourcetype=log1 Id=1116061 | stats earliest(_time) AS earliest, latest(_time) AS latest | fieldformat earliest= strftime(earliest, "%m/%d/%Y:%H:%M:%S") | fieldformat latest= strftime(latest, "%m/%d/%Y:%H:%M:%S") | search [index=log2 earliest=earliest latest=latest | stats avg(transcode_ratio) as Ratio]

The main search is giving me the correct value and format (08/30/2016:14:23:31) for the sub search to work. I'm just unable to use a variable as the value. I'm not sure what approach I should take as I have very little experience with splunk and couldn't find an example online that fits.

Many Thanks.

0 Karma

sundareshr
Legend

Try this

index=log2 [search sourcetype=log1 Id=1116061 | stats earliest(_time) AS earliest, latest(_time) AS latest | table earliest latest ] | stats avg(transcode_ratio) as Ratio
0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...