View in #flux on Slack
@Sander_Wapperom: Hi all,
I’m trying to set up email alerts and using the code of the docs: https://docs.influxdata.com/influxdb/cloud/monitor-alert/send-email/?t=Mailjet . The task last run status is “Task ran succesfully” however no emails are sent
The only change I made is in the authorization part, because ${MYKEYHERE}:${MYSECRETHERE} returns an error I tried both {MYKEYHERE}:{MYSECRETHERE} and MYKEYHERE:MYSECRETHERE without success.
I noticed that when I ran the flux snippet below in the explore interface (using influxDBcloud v2) it returns no value. When I alter the filter to |> filter(fn: (r) => r["_measurement"] == "statuses" and r["_level"] == "ok")
It does run in the explorer, but when I copy this syntax to the task, the task last run status changes to completed(failed)
numberOfCrits = from(bucket: "_monitoring")
|> range(start: -task.every)
|> filter(fn: (r) => r.measurement == "statuses" and "r.level" == "ok")
|> count()
Am I doing something wrong, misinterpreting the docs or is there an error in the docs themselves? All input is very much appreciated!
complete code altered to my use case according to the docs
import "http"
import "influxdata/influxdb/secrets"
option task = {
name: "Email Alerts",
every: 2m,
}
numberOfCrits = from(bucket: "_monitoring")
|> range(start: -task.every)
|> filter(fn: (r) => r.measurement == "statuses" and "r.level" == "ok")
|> count()
numberOfCrits
|> map(
fn: (r) => if r._value > 0 then
{r with
_value: <http://http.post|http.post>(
url: "<https://api.mailjet.com/v3.1/send>",
headers: {
"Content-type": "application/json",
"Authorization": "Basic MYKEYHERE:MYSECRETHERE",
},
data: bytes(
v: "{
\"Messages\": [{
\"From\": {
\"Email\": \"<mailto:xxx.xxx@xxx.nl|xxx.xxx@xxx.nl>\"
},
\"To\": [{
\"Email\": \"<mailto:xxx@xxx.nl|xxx@xxx.nl>\"
}],
\"Subject\": \"InfluxDB critical alert test\",
\"TextPart\": \"There have been ${string(v: r._value)} critical statuses.\",
\"HTMLPart\": \"<h3>${string(v: r._value)} critical statuses</h3><p>There have been ${string(v: r._value)} critical statuses.\"
}]
}",
),
),
}
else
{r with _value: 0},
)
Send alert email | InfluxDB Cloud Documentation
Logs hint towards a problem with the post url… any suggestions?
2021-07-05 19:16:00
Completed(failed)
2021-07-05 19:16:01
Error exhausting result iterator; Err: runtime error @14:8_42:6: map: failed to evaluate map function: Post “https://api.mailjet.com/v3.1/send”: EOF: runtime error @14:8_42:6: map: failed to evaluate map function: Post “https://api.mailjet.com/v3.1/send”: EOF