Sending a notification on value change

Hi!

I’m new to InfluxDB and Flux and struggling to get a simple notification task up and running.

In my DB I have a monotonically increasing value and I’d like to set up a task that sends out a Telegram notification whenever that value changes.

As an example I use disk space here. My naive approach/pseudo code looks like:

dspace = from(bucket: "main")
  |> range(start: -5m)
  |> filter(fn: (r) => r["_measurement"] == "disk")
  |> filter(fn: (r) => r["_field"] == "used")
  |> filter(fn: (r) => r["device"] == "sdj1")
  |> last()

max_diff = from(bucket: "main")
  |> range(start: -5m)
  |> filter(fn: (r) => r["_measurement"] == "disk")
  |> filter(fn: (r) => r["_field"] == "used")
  |> filter(fn: (r) => r["device"] == "sdj1")
  |> difference()
  |> max()

if max_diff._value > 0 then
  telegram.message(
    // token etc.
    message: "New value: ${dspace._value}",
  )
else
  0

…and of course doesn’t work. :wink:

I’m still looking for a good Flux tutorial or (cook)book. Did I miss anything?

Sincerely,
Steffen

Hello @selfsimilar,
Does this help?

Have you seen it already?
Thanks