Splunk Search

How to disable splunk alert for a specific time frame?

rzv424
Engager

We want an alert to run every day (Monday-Sunday) on a 30 minutes interval with one exception. The exception is it should not run specifically on Wednesday and Friday from 5AM to 8AM. However it should run on other hours on Wednesday and Friday as well  (apart from 5AM to 8AM)

One cron is not able to achieve that. Hence want to change in the alert logic.

0 Karma
1 Solution

subham29
Engager

@rzv424 
Solution1:

You can create two alerts with the same logic with different CRONs.

  1. 1st alert CRON will run every day except on Wed and Fri. Cron is: */30 * * * 0,1,2,4,6
  2. Second alert CRON will run every 30 minutes on Wednesday and Friday and will stop from 5AM to 8AM. Cron is: */30 0-5,8-23 * * 3,5

Solution2:

You can create one alert with a CRON to run every day of the week at 30 minutes interval, Cron is */30 * * * *

And you can add the filtering at the logic of query itself:
Use an EVAL command to output the current day and hour after your logic ends. and then filter or don't show your outputs as per your exception requirement

......| eval now_day=strftime(now(), "%a"), now_hour=strftime(now(), "%H")
| search NOT ((now_day="Wed" AND (now_hour="5" OR now_hour="6" OR now_hour="7" OR now_hour="8")) OR (now_day="Fri" AND (now_hour="5" OR now_hour="6" OR now_hour="7" OR now_hour="8")))

View solution in original post

0 Karma

subham29
Engager

@rzv424 
Solution1:

You can create two alerts with the same logic with different CRONs.

  1. 1st alert CRON will run every day except on Wed and Fri. Cron is: */30 * * * 0,1,2,4,6
  2. Second alert CRON will run every 30 minutes on Wednesday and Friday and will stop from 5AM to 8AM. Cron is: */30 0-5,8-23 * * 3,5

Solution2:

You can create one alert with a CRON to run every day of the week at 30 minutes interval, Cron is */30 * * * *

And you can add the filtering at the logic of query itself:
Use an EVAL command to output the current day and hour after your logic ends. and then filter or don't show your outputs as per your exception requirement

......| eval now_day=strftime(now(), "%a"), now_hour=strftime(now(), "%H")
| search NOT ((now_day="Wed" AND (now_hour="5" OR now_hour="6" OR now_hour="7" OR now_hour="8")) OR (now_day="Fri" AND (now_hour="5" OR now_hour="6" OR now_hour="7" OR now_hour="8")))

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

You have two options:

  1. Duplicate the alert and use a different cron expression for the different days/time periods
  2. Use now() function to determine when the search is running and modify the results so that the alert isn't triggered.
0 Karma
Get Updates on the Splunk Community!

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

Splunk Decoded: Business Transactions vs Business IQ

It’s the morning of Black Friday, and your e-commerce site is handling 10x normal traffic. Orders are flowing, ...

Fastest way to demo Observability

I’ve been having a lot of fun learning about Kubernetes and Observability. I set myself an interesting ...