Splunk Search

Custom Searches - 'Out of Hours' timeframe

iTUBS
New Member

Hi All,

I am currently trying to perform some monitoring, and am having a bit of trouble with the Splunk search engine.

I want to return results from an entire month, but from specific times during that month

  • Weekdays, after 8pm but before 8am
  • Weekends, 24 hours

Does anyone know how to build this sort of query?

Thanks in advance for any help!

Tags (1)
0 Karma

Ayn
Legend

Extract the week day and the hour from the timestamp, then check events that match your conditions. Something like this:

... | eval date_wday=strftime(_time,"%a") | eval date_hour=strftime(_time, "%H") | search (NOT (date_wday="Sat" OR date_wday="Sun") AND (date_hour>=20 OR date_hour<8)) OR date_wday="Sat" OR date_wday="Sun"

Note: the date_wday and date_hour fields are most often created automatically by Splunk, so if you're seeing that all your events already have these, you don't need to create themselves using eval like what I did above. However there are situations when they will not be created, so make sure first that you're not encountering that problem.

Get Updates on the Splunk Community!

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 ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...