Rule and notificaion check for specific condition

Hi,

I am trying to write a check where i want to fire slack endpoint when ever the result will be in CRIT state.

Check will be like -

Measurement - myMeasurement
Fielid - testField
Tag - host

So want to check
if testField is more than 100(CRIT state) above 3 times then trigger an endpoint notification(Slack)

I am super existed and try to integrate in our system. Im new to this influx rule engine.
If possible then can you arrange a call on your rule engine.

Any help will be appreciated.

Hi, can anyone help me with this problem. Please take a look and write me back.

What have you got so far? Are you following a blog - if so can you paste the link here?

Hello @debnath,
You’ll have to write a custom notification rule for this. Something like:

package main
//CPU Notification Rule 
import "influxdata/influxdb/monitor"
import "slack"
import "influxdata/influxdb/secrets"
import "experimental"
option task = {name: "CPU Notification Rule ", 
               every: 10m, 
               offset: 0s}
slack_endpoint = slack["endpoint"](url: "https:hooks.slack.com/services/xxx/xxx/xxx")
notification = {_notification_rule_id: "0758afea09061000",
                _notification_rule_name: "CPU Notification Rule ",
                _notification_endpoint_id: "0754bad181a5b000",
                _notification_endpoint_name: "My slack",}
statuses = monitor["from"](start: -10s, fn: (r) = r["_check_name"] == "CPU Check")
crit = statuses 
       |> filter(fn: (r) => r["_level"] == "crit")
all_statuses = crit 
               |> filter(fn: (r) => (r["_time"] >= experimental["subDuration"](from: now(), d: 10m)))

count_statuses =  all_statuses |> count() |> findRecord(fn: (key) => true), idx: 0)


notify = (tables<-) => { 
final_status = tables 
|> monitor["notify"](data: notification, 
                     endpoint: slack_endpoint(mapFn: (r) = (
{channel: "", 
 text: "Notification Rule: ${ r._notification_rule_name } triggered by     check: ${ r._check_name }: ${ r._message }", 
 color: if r["_level"] == "crit" then "danger" else if r["_level"] == "warn" then "warning" else "good"})))

condition_met = if count_statuses._value > 3 then final_status else 0 

return condition_met
}

all_statuses
|> notify()

I’m using the following resources:

@Anaisdg Thank you helped a lot.