Email Alert Function in Flux?

I was just playing around with the TICK stack when 2.0 dropped. I had just done some testing on pushing windows system data via telegraf on version 1.X sending some simple Email alerts when 2.0 dropped.

Is there a function in FLUX which allows me to send emails? I haven’t seen anything in the docs. Maybe I need more coffee this morning?

@acorreia Not yet. Flux “event” functions are coming. One major feature these rely on is conditional logic which is also still in the works.

Thanks Scott. I actually found a slideshare that was very helpful:

Looks like the way the way that its going to work is to filter from one bucket into an ‘Alert’ bucket and from there you filter down from there and action of items in that bucket. Hopefully there will be some alert templates to take advantage of.

Checking on the status of the email feature

@scott hello, as far as i can see conditional logic is implemented and i am using it.

Is it possible to set up email alert with flux ?

btw flux is really helping me create very complex “queries”, for me this is game changer in db.


Sending emails directly from Flux/InfluxDB isn’t available yet, but if you’re using a 3rd party transactional SMTP provider with a public API (like SendGrid or Mandrill), you can use the function to make an API call and trigger an email.

Got it, will try…thanks

Any visibility when approx smtp may be available ?

option task = {
name: "email alert digest",
cron: "0 5 * * 0"

import "smtp"
body = ""
from(bucket: "alerts")
|> range(start: -24h)
|> filter(fn: (r) => (r.level == "warn" or r.level == "critical") and r._field == "message")
|> group(columns: ["alert"])
|> count()
|> group()
|> map(fn: (r) => body = body + "Alert {r.alert} triggered {r._value} times\n")
config: loadSecret(name: "smtp_digest"),
to: "",
title: "Alert digest for {now()}",
body: message)

@scott I tried HTTP post, I followed the example but failing on initialize dependencies, is there other settings missing on my side ?

root@189d6517cfa3:/# influx -type=flux
Connected to http://localhost:8086 version 1.7.9
InfluxDB shell version: 1.7.9
> import "http"
  url: "",
  headers: {k: "XXXXYYYYYZZZZ"},
  data: bytes(v: "3")
Error: error calling function "post": url validator uninitialized in dependencies


@salvq, this may be an issue that’s isolated to the the Flux REPL. Have you tried using the Data Explorer or a raw API query call?

@scott I tried API call from the bash shell and working just fine…the issue here might be how to translate below HTTP POST format to Flux HTTP POST syntax

I tried so many different combination in flux but no success yet

Linux curl syntax

root@189d6517cfa3:/# curl -s \
> --form-string "t=title" \
> --form-string "m=Test" \
> --form-string "k=XXXXYYYYYZZZZ" \

{"status":1,"success":"message transmitted","available":207,"message_ids":"7470582:20625"}

This is how it looks in JavaScript syntax

var xhttp;
if (window.XMLHttpRequest) {
    xhttp = new XMLHttpRequest();
    } else {
    // code for IE6, IE5
    xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}"POST", "", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

@salvq There isn’t a specific date for SMTP support in Flux yet. The focus of the Flux team over the next few months is performance and optimization.

The url validator uninitialized in dependencies error is unique to the REPL. The REPL currently doesn’t load the url validator that’s part of InfluxDB. If you run these scripts from the Data Explorer in the UI, you won’t get this error.

With your attempts to use the function, do you need to send the key-value pairs as query parameters or just as the request body? What about these?:

data = {title: "The Title", message: "The message", private_key: "PrIvAtEkEy"}

// As query parameters
  url: "${data.title}&m=${data.message}&k=${data.private_key}",
  headers: {"Content-type": "application/x-www-form-urlencoded"},
  data: bytes(v: "")

// As the body
  url: "",
  headers: {"Content-type": "application/x-www-form-urlencoded"},
  data: bytes(v: "t=\"${data.title}\", m=\"${data.message}\", k=\"${data.private_key}\"")

Fully understand the focus, performance is really key. For some of the heavy scripts, transformation and math calculation I am running in the graphs it takes some time to transform and calculate the final number but it gets jobs done eventually. This was the key for me because for some of the routines I was not able to make it via InfluxQL.

Anyway, neither of these worked. Key-value pairs have to be part of request body. Actually can not use Data explorer due to hosted virtual machines so only bash shell or Grafana and neither worked :frowning:

  url: "",
  headers: {Content-type: "application/x-www-form-urlencoded"},
  data: bytes(v: "t=\"${data.title}\", m=\"${data.message}\", k=\"${data.private_key}\"")
  url: "",
  headers: {Content-type: "application/x-www-form-urlencoded"},
  data: bytes(v: "t=\"${data.title}\", m=\"${data.message}\", k=\"${data.private_key}\"")
Error: loc 3:20-3:62: unexpected token for property key: SUB ("-")
  url: "",
  data: bytes(v: "t=\"${data.title}\", m=\"${data.message}\", k=\"${data.private_key}\"")
  url: "",
  data: bytes(v: "t=\"${data.title}\", m=\"${data.message}\", k=\"${data.private_key}\"")
Error: error calling function "post": url validator uninitialized in dependencies

Whoops, I forgot to wrap Content-type in quotes. That should solve that problem. Are you getting the url validator... error in Grafana too?

hmmm, still the same error, url validator

> import "http"
> data = {title: "The Title", message: "The message", private_key: "KEY"}
> "",headers: {"Content-type": "application/x-www-form-urlencoded"},data: bytes(v: "t=\"${data.title}\", m=\"${data.message}\", k=\"${data.private_key}\""))
Error: error calling function "post": url validator uninitialized in dependencies

In grafana I just got an error InfluxDB Error: Internal Server Error, similar one to wrong query and no other detail log available what is failing on influxdb side.

message:"InfluxDB Error: Internal Server Error"

Hi Guys,

I have also started 1 week back and on the same point where, I want to send Alert Notifications.

I am using http method to call my backend currently localhost. but get following error when Influx tries to send post method,

influxdb | ts=2020-02-18T15:58:50.461315Z lvl=info msg="Error exhausting result iterator" log_id=0L2G8u3G000 service=task-executor error="failed to evaluate map function: Post http://localhost:8080/api/email: dial tcp connect: connection refused" name=experimental-to13

Any pointer will be help full.


We now have documentation on how to send email alerts for Sendgrid, AWS SES, Mailjet, and Mailgun:

Does this give you what you’re looking for?

1 Like

Really surprised that this (normal email) still isn’t a feature.
Just pass the email to postfix / exim installed on the server, so much simpler than using a third party (especially when third parties are not options for some people!).


Indeed, sending confidental emails to third party services is no option for me. Any plans to support postfix?

@asargent - while the Sendgrid, AWS SES, Mailjet and Mailgun support is great, for OSS users, being able to send an email via an smtp relay would be a great feature and the current alerting mechanism in 2.0.8 doesn’t yet seem to support it. Is this support planned? Is there an issue for this?

UPDATE: here is the issue: InfluxDB v2 - E-Mail - Notification Endpoint · Issue #17938 · influxdata/influxdb · GitHub