Dashboards & Visualizations

Splunk Search a time range within a specified field

curry59
New Member

Hello,

I have a summary index that I created a custom field of 'latest' which was the last time that the server reported to the cluster index. It shows as "MM/DD/YYYY XX:XX:XX". I would like to create a search that only searches from the today's current time to 2 weeks ago within that 'latest' field.

Currently, I have tried 'latest="-2w@w"', but it only displays the singular day two weeks ago. I would like to it to search over everyday day within that 2 week period from today to 2 weeks ago.

Using 'earliest="2w@w"' does not use the 'latest' field, so that will not work either. Any assistance will be greatly appreciated.

Thanks,

Mike

0 Karma

lguinn2
Legend

You cannot use your latest field interchangeably with the built-in field of the same name. And for that reason, you can't use the relative time syntax. As far as Splunk is concerned, your latest field is simply a string. So you could do this:

yoursearchhere
| eval lasttime=strptime(latest,"%m/%d/%Y %H:%M:%S")
| where _time<= now() and time >= relative_time(lasttime,"-2w@w")

I feel like this isn't the answer, because I really don't understand what you are trying to search. What data do you want as a result of this search? Is that data also in the summary index - if not, then there needs to be a join or an append or something to bring in the second index...

But maybe this will get you started.

0 Karma

curry59
New Member

If i were to change the name of the 'latest' field to say 'lastcheckin', would that make it so I could use the relative time syntax?

0 Karma

curry59
New Member

As for what I am looking to achieve is the last time the server reported to the cluster index. From here we forward the hostname and last time (latest) it reported to the summary index for us to monitor the servers. The search we use to send the information to the summary index:

| tstats latest(_time) as latest where index="$INDEX" NOT host="$MONITORSERVER" by host
| dedup host
| convert ctime(latest)

In the summary index, there is servers that last reported 3 months ago and are now turned off. I do not need to track those servers as they were test servers, but the summary index search still sends the information over to the summary index every minute as stated.

So basically, I am trying to have the latest field in the summary index to show only servers that reported within the last two weeks. This will weed out the servers that have been off for months, as their latest field states that they last reported months ago. Thanks again for the help.

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...