I have a task that checks if a value exceeds a threshold and reports by slack.
This task has an interval of 10 minutes, the problem is that it notifies every 10 minutes even with the same status.
I am storing in my bucket a _level (tag) column with critical and ok values.
But when I use monitor.stateChangesOnly () it never notify by slack when _level changes from critical to ok or ok to critical. Does monitor.stateChangesOnly () work the same as statechangeonly in kapacitor?
I do not know what I’m doing wrong.
The Slack notification task:
import "influxdata/influxdb/monitor"
import "slack"
option task = {name: "notify slack", every: 10m}
toSlack = slack.endpoint(url: "mySecretWebhook", token: "")
notify = from(bucket: "alerts")
|> range(start: -task.every)
|> filter(fn: (r) => (r._measurement == "alerts" and r._field == "temp"))
|> keep(columns: ["_time", "_value", "_field", "_level", "location", "alertid"])
|> group(columns: ["location", "_level", "alertid"])
|> last()
notify
|> monitor.stateChangesOnly()
|> toSlack(mapFn: (r) =>
({r with channel: "#alertas-influxdb", text: "${r.alertid} ${r.location} ${r._level} Value: " + string(v: r._value) + " Threshold: 18", color: "info"}))()