Error Script Task (MailGUN)

Hello friends, I have the following problem, my query works normally until the value of the variable becomes critical, as I am new to FLUX programming, I would like to know if the standard code contains any errors, below it and I have not changed anything.

Note: when I test send a test email through the Note, everything is correct (email, MailGun token), it arrives normally, but not through the script.

If you can shed some light, thanks in advance!

import "strings"
import "regexp"
import "influxdata/influxdb/secrets"
import "influxdata/influxdb/schema"
import "influxdata/influxdb/monitor"
import "http"
import "experimental"

option task = {name: "Notebook Task for ogc71l9675e6", every: 10m, offset: 1s}
option v = {timeRangeStart: -1h, timeRangeStop: now()}

check = {
    _check_id: "ogc71l9675e6",
    _check_name: "Notebook Generated Check",
    _type: "custom",
    tags: {},
notification = {
    _notification_rule_id: "ogc71l9675e6",
    _notification_rule_name: "Notebook Generated Rule",
    _notification_endpoint_id: "ogc71l9675e6",
    _notification_endpoint_name: "Notebook Generated Endpoint",

task_data =
    from(bucket: "teste2")
        |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
        |> filter(fn: (r) => r["_measurement"] == "xxxxx")
        |> filter(fn: (r) => r["L1"] == "xxxx")
        |> filter(fn: (r) => r["_field"] == "xxxxx" or r["_field"] == "xxxxx")
        |> filter(
                (r) =>

trigger = (r) => r["xxxxxxx_xxxx"] > 100
messageFn = (r) =>
    "${strings.title(v: r._type)} for ${r._source_measurement} triggered at ${time(
            v: r._source_timestamp,

apiKey = secrets.get(key: "MailGun")
auth = http.basicAuth(u: "api", p: "${apiKey}")

    |> schema["fieldsAsCols"]()
    |> set(
        key: "_notebook_link",
        value: "http://xxxx.xxxx.xxxx:8086/orgs/xxxxxx/notebooks/xxxxxxx",
    |> filter(fn: (r) => r["_measurement"] == "xxxxxxx")
    |> 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,
                mapFn: (r) => {
                    data =
                            arr: [
                            v: "&",

                    return {
                        headers: {
                            "Content-Type": "application/x-www-form-urlencoded",
                            "Authorization": "${auth}",
                        data: bytes(v: data),

Hello @Alan_Manzato,
If you’re writing your own custom alerts I actually recommend not using the monitor.check functions as that kinda puts some of your data in that bucket and feels black boxy. It’s mostly set up that way to provide structure for users who are only building tasks through the UI.

I recommend following this structure instead:

Because you can run it in the data explorer (minus the task options)
And verify that you’re getting alerts as expected and put a bunch of yeilds everywhere like print statements to debug.

And you don’t have to wait for the task to execute.