Setting up an alert that triggers a Python script (Gmail message)


I would like Alerts on InfluxDB to trigger a local Python script (that will send me an email alert via Gmail). How can this be done easily? It looks like Alerts expect an HTTP end-point?


I use Node-RED for this.

InfluxDB Alert → webhook received by Node-RED (running on same machine) → when webhook is received, send email (or run your Python script, turn on a light or siren, etc.). Node-RED can basically do anything (except make breakfast).

1 Like

Thank you @grant1!

I have installed Node-RED indeed, and it’s working fine now without even calling Python (I had never used Node-RED before so there was a learning curve!).

  1. Notification end-point configured on InfluxDB to post to http://localhost:1880/node (my local node-RED server and node created)
  2. in node-RED:
  • http post node (accept http post)
  • function node (to parse JSON and create the email text)
  • email node (works fine with Gmail and authorisation token instead of password)

Here is my code in the “Function” node:

> var newData = JSON.stringify(msg.payload);
> var o = JSON.parse(newData);
> // set email subject
> msg.topic = "Alert from InfluxDB monitoring via Node-RED (" + + ")"; 
> // HTML email body
> msg.payload = "<b>Host:</b> " + 
>     + "<br><b>Check performed:</b> " + o["_check_name"] 
>     + "<br><b>Status:</b> " + o["_level"]
>     + "<br><b>Type of check:</b> " + o["_type"]
>     + "<br><b>Time of alert:</b> " + o["_time"];
> return msg;

Awesome news! Thanks for sharing.

Besides using the webhook routine that I mentioned previously, I use Node-RED for dozens of tasks, such as:

  • Hitting a website every hour, day, or week to get (for example) electricity usage from the power company (comes as an .xml file, but Node-RED can convert to InfluxDB-friendly format)
  • Checking incoming emails (on a dedicated email box) that, based on the sender and subject line, will query InfluxDB or MSSQL and then send back some requested data
  • Grabbing up-to-the-minute pricing on commodity data (e.g. price of natural gas) and use it in a query or formula inside InfluxDB
  • Grabbing and manipulating MQTT data being published by dozens of devices (and often sending to InfluxDB if needed)

I am planning to make an InfluxDB backup node (for v2+) where one can specify the path, token, frequency, etc. and the backup will be done per those settings.

1 Like