Sending notifications after 1 hour if the alert check persists

Hello,
I am trying to generate notifications from checks. My checks are being generated every 30 seconds and notification rules run every 2 minutes. I need to send a notification when an alert state changes from ok to warning (this has been figured out) and after every one hour if the warn state persists. I am having difficulty coming up with this query. Any guidance would be appreciated.
Thanks.

Hello @Farhan.ahmed,
Welcome! I apologize for the delay. Thank you for your patience.
I might do something like:

import "array"
import "influxdata/influxdb/monitor"
import "slack"

data =
    array.from(
        rows: [
            {_time: 2021-01-01T00:00:00Z, _level: "ok"},
            {_time: 2021-01-01T00:01:00Z, _level: "ok"},
            {_time: 2021-01-01T00:02:00Z, _level: "ok"},
            {_time: 2021-01-01T00:03:00Z, _level: "ok"},
        ],
    )

stateChangeData = data
    |> monitor.stateChanges()

dummyData = array.from(
        rows: [
            {_time: now(), _level: "noChange"}])
|> yield() 

noChange = union(tables: [dummyData, stateChangeData])
|> count(column: "_level")
|> findRecord(
      fn: (key) => true,
      idx: 0,
  )

if noChange._level == 1 then 
slack.message(url: "https://hooks.slack.com/services/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", channel: "#notifications-testing", text: "name: no Change", color: "warning")
else 0

If you want to use string interpolation for the value then you could also use a filter or conditional mapping and do something like (just the logic here):

data
  |> count()  
  |> filter(fn: (r) => r._value >= 2.0)
  |> map(fn: (r) => ({ r with _value: slack.message(url: "https://hooks.slack.com/services/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", channel: "#notifications-testing", text: "name: Anais, value: ${r._value}, machine: ${r.machineID}", color: "warning")}))
  |> yield()

Also that slack webhook is for the community slack and #notifications-testing channel. You’re welcome to use it. :slight_smile: I hope this helps!