1

Sending Influxdb alerts to Google Chat

 1 year ago
source link: https://blog.davidvassallo.me/2023/04/13/sending-influxdb-alerts-to-google-chat/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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:

image.png?w=640
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:

image-1.png?w=333

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

image-2.png?w=410

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:

image-3.png?w=663

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:

image-4.png?w=699

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:

image-5.png?w=290

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)}
image-6.png?w=791

And change this to the format which Google Chats expects:

return {
   headers: headers,
   data:
       json["encode"](
                       v: {text: body["_check_name"] + ":\n" + body["_message"]},
       ),
}
image-7.png?w=871

Save, and you good to go


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK