How to write NRQL query that is only executed at specific times

###Alerts Question Template

  • Please describe what are you seeing:
    We have an NRQL query that selects transactions for an application and raises an alert if the query result returned is less than 1 in 30mins. However, we would like the alert to not be raised even if the criteria is met when it’s outside of the time window of 9am-9pm Monday to Friday.

How to write such a query?

Helpful Resources
Relic Solution: The key to consistent alert notifications

Troubleshooting downtime document

Hi, @cindy.tran: It is not possible to create an alert condition (NRQL or otherwise) that is only evaluated at certain times. You may, however, use the REST API to create a script that enables the condition at specific times and disables it at other times.

You might also consider creating a baseline alert condition, which will create an incident when the result of your query deviates from the historical value of the query for that time of day.

1 Like

Since you are using NRQL Alerts @cindy.tran, you may be able to filter out certain timeframes in your query. Perhaps adding the below to your WHERE clause will help:

hourOf(timestamp) not in ('21:00', '22:00', '23:00', '0:00','1:00', '2:00', '3:00', '4:00', '5:00', '6:00', '7:00', '8:00') AND weekdayOf(timestamp) not in ('Saturday', 'Sunday')
4 Likes

HI @RyanVeitch, As per your suggestion I’m using the below nrql query so that I want to disable alerts between 9 PM to 3 AM but I’m receiving alerts around 9.30 PM daily. Please suggest did I miss anything in below query

Hi @Anish_Uppalapati,

While this query will filter out any Transaction events recorded during the timeframe that you have defined, that also means it will effectively return a count of 0 between 9pm and 3am PT. If your alert condition’s thresholds are configured to open a violation “when query returns a value less than 1 for at least 30 minutes,” you can expect to see a violation open at 9:30pm PT every night.

For your case, I would look into the prior suggestions of scripting alert condition disablement via the Alerts API or setting up a baseline alert condition that opens a violation when data deviates from the norm. I’d love to know if either of those seem applicable for your case!

2 Likes

Hi @jeffrey_s, Good to hear from your end. Talking about baseline alert condition, I really have no idea about how We can make new relic to not sending alerts for specific timeline window. If you can help me out on this That will be great. Now coming to alerts api, We need to create seperate project for this enable/disable alerts. All this leads to extra workaround for us. I still wonder How new relic lacking the disablement of alerts till now.

Hi @Anish_Uppalapati - I understand that it’s troublesome to have to use the API as a workaround. There is an existing feature idea to allow alerts to report only during certain hours. I encourage you to add your use case there:

Thank you!