Other Usage

How to define 2 thresholds based on time?

cbiraris
Path Finder

Hi Team,

I am trying to schedule a alert base on threshold for 2 time window.

If fall to 0 events between 23:00 to 07:00
If fall to less then 20 events between   07:00 to 23:00 
 
is it possible to define 2 threshold like above ? in one alert

index=ABC sourcetype=XYZ login |stats count |where count =0 between23:00 to 07:00

index=ABC sourcetype=XYZ login |stats count |where count <=20 between 07:00 to 23:00 

Please advise.

Thank you

Labels (1)
Tags (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @cbiraris,

yes, you have to define a threshold value using eval:

index=ABC sourcetype=XYZ login 
| stats count 
| eval time_hour=strftime(now(),"%H")
| eval threshold=if(time_hour>22 OR time_hour<8,0,20)
| where count<=threshold

Ciao.

Giuseppe

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
index=ABC sourcetype=XYZ login |stats count |where count=0 OR (count <=20 AND tonumber(strftime(now(),"%H")) >= 7 AND tonumber(strftime(now(),"%H")) < 23)

gcusello
SplunkTrust
SplunkTrust

Hi @cbiraris,

yes, you have to define a threshold value using eval:

index=ABC sourcetype=XYZ login 
| stats count 
| eval time_hour=strftime(now(),"%H")
| eval threshold=if(time_hour>22 OR time_hour<8,0,20)
| where count<=threshold

Ciao.

Giuseppe

cbiraris
Path Finder

Also, can we define 2 different search run interval in this query ? like below---

index=ABC sourcetype=XYZ login |stats count |where count =0 between23:00 to 07:00, search can be run every after 2 hours to check last 2 hours events 

AND 


index=ABC sourcetype=XYZ login |stats count |where count <=20 between 07:00 to 23:00, , search can be run every after 1 hours to check last 1 hours events 
 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

You can do this in one alert but it gets a bit messy - you would probably be better off using two alerts with different schedules, time periods and alert criteria

0 Karma

cbiraris
Path Finder

Thank you @gcusello
Its Working

Tags (1)
0 Karma
Get Updates on the Splunk Community!

Splunk at Cisco Live 2025: Learning, Innovation, and a Little Bit of Mr. Brightside

Pack your bags (and maybe your dancing shoes)—Cisco Live is heading to San Diego, June 8–12, 2025, and Splunk ...

Splunk App Dev Community Updates – What’s New and What’s Next

Welcome to your go-to roundup of everything happening in the Splunk App Dev Community! Whether you're building ...

The Latest Cisco Integrations With Splunk Platform!

Join us for an exciting tech talk where we’ll explore the latest integrations in Cisco &#43; Splunk! We’ve ...