Sending Influxdb alerts to Google Chat

We recently moved away from Slack as a company and started using Google Chat. The main stumbling block from a tech point of view was that most monitoring services (such as InfluxDB which we use) have easy integration with Slack, but not Google Chat:

Easy slack integration… but limited HTTP(S) options

Luckily, we can bend the rules in InfluxDB to send our notifications to Google Chat. Once you know how, it’s a 10 minute job

Create a Google Chat “Space” webhook

This will be where your notifications are going to start appearing. Once you create a space, click on the arrow button and the “Apps & integrations” option:

Create a webhook, noting the resulting URL for the next steps:

Create an InfluxDB Notification Endpoint

In InfluxDB, under Alerts > Notification Endpoints create a new notification endpoint, using HTTP and the webhook URL you obtained from the previous step:

ASIDE: as with any other notification, you must use the above endpoint in some sort of InfluxDB notification rule for it to ever be used

Bending the rules

At this stage, if you try out your new notification endpont… nothing happens. That’s because Google Chat webhooks expect an HTTP POST request that contains a JSON object that has a “text” attribute:

By default, influx doesnt send the HTTP POST JSON body in the correct format. So, go to a notification rule which uses the notification endpoint you defined in the previous step, and EDIT (not click on) the notification rule:

You’ll see lots of code, which is where this blog post comes in handy, cause instead of trying to figure out that blob of code, you now know that all you need to do is find the line towards the end which determines what data to send to the HTTP endpoint_

return {headers: headers, data: json["encode"](v: body)}

And change this to the format which Google Chats expects:

return {
   headers: headers,
                       v: {text: body["_check_name"] + ":\n" + body["_message"]},

Save, and you good to go

3 thoughts on “Sending Influxdb alerts to Google Chat

Comments are closed.