Flux is a lightweight scripting language for querying databases (like InfluxDB) and working with data. It's part of InfluxDB 1.7 and 2.0, but can be run independently of those.
For a small PoC I am trying to send a notification to slack when a temperature exceeds a certain value.
The connection to slack works but the task itself keeps failing with error: notify: failed to evaluate map function: 57:64-57:77: interpolated expression produced a null value
Tried several combinations - found in other issues - with below code being latest version.
Can anyone please advice?
FYI setup:
Azure IoT MX chip publishing to MQTT BROKER
Raspberry pi running:
docker with: MQTT broker -> Telegraf -> influxdb v2.0 (local on RPI) -> Grafana
influxdb v2. (could not get this running in docker)
For a small PoC I am trying to send a notification to slack when a temperature exceeds a certain value.
The connection to slack works but the task itself keeps failing with error: notify: failed to evaluate map function: 57:64-57:77: interpolated expression produced a null value
Tried several combinations - found in other issues - with below code being latest version.
Can anyone please advice?
FYI setup:
import "strings" import "slack" import "regexp" import "influxdata/influxdb/secrets" import "influxdata/influxdb/schema" import "influxdata/influxdb/monitor" import "experimental"
option task = {name: "Temp high slack test", every: 10s, offset: 0s} option v = {timeRangeStart: -1h, timeRangeStop: now()}
check = { _check_id: "local_OGibsn6FY2HP3HbMM4B_z", _check_name: "Notebook Generated Check", _type: "custom", tags: {}, } notification = { _notification_rule_id: "local_OGibsn6FY2HP3HbMM4B_z", _notification_rule_name: "Notebook Generated Rule", _notification_endpoint_id: "local_OGibsn6FY2HP3HbMM4B_z", _notification_endpoint_name: "Notebook Generated Endpoint", }
task_data = from(bucket: "IoTPoC") |> range(start: -task.every) |> filter(fn: (r) => r["_measurement"] == "smartbyte") |> filter(fn: (r) => r["_field"] == "tempC") |> filter(fn: (r) => exists r._value) |> fill(usePrevious: true) |> fill(value: 0.0)
trigger = (r) => r["tempC"] > 30 messageFn = (r) => "${strings.title(v: r._type)} for ${r._source_measurement} triggered at ${time( v: r._source_timestamp, )}!"
task_data |> schema["fieldsAsCols"]() |> set( key: "_notebook_link", value: "http://0.0.0.0:8086/orgs/xxx/notebooks/xxx", ) |> filter(fn: (r) => r["_measurement"] == "smartbyte") |> monitor["check"](data: check, messageFn: messageFn, crit: trigger) |> filter(fn: trigger) |> keep(columns: ["_value", "_time", "_measurement"]) |> limit(n: 1, offset: 0) |> monitor["notify"]( data: notification, endpoint: slack"endpoint"(mapFn: (r) => ({channel: "iot-stack-poc", text: "${r._message}", color: "#DC4E58"})), )