Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I customize the entire email notification in Stackdriver Alerting?

Currently, the message specified in the Document field while creating alerting policy appears in the Document field of the Stackdriver alert email. I would like to overwrite the entire email message body with my custom content. How can I overwrite the message body of Stackdriver Alert email with my custom message? Is there any other workaround to do this?

like image 868
Blessy Avatar asked Mar 13 '18 08:03

Blessy


People also ask

When creating an alerting policy what can be specified?

Each alerting policy specifies the following: Conditions that describe when a resource, or a group of resources, is in a state that requires you to respond. An alerting policy must have at least one condition; however, you can configure a policy to contain multiple conditions.

What is not a recommended best practice for alerts?

What is not a recommended best practice for alerts? []Configure alerting on symptoms and not necessarily causes.


1 Answers

You should be able to send the notification to a webhook, and this could directly be an HTTP-triggered Cloud Function.

This Cloud Function would receive all the information from the alert, and you can follow this tutorial to use SendGrid to send your alerts.

This is a lot more complex than just setting the email notifications, but also provides you with an amazing flexibility regarding alerts, as you'll be able to not just write the message however you want, but you could process the data in any way you want:

  • You have low priority alerts? Then store them and just send a digest once in a while instead of spamming.
  • Want to change who is sent the alert depending on a calendar rotation? Use the function to look up who should be notified.

And those are just some random quick ideas I got while writing this message.

The information provided in the POST body is this one (that's just a sample):

{
  "incident": {
    "incident_id": "f2e08c333dc64cb09f75eaab355393bz",
    "resource_id": "i-4a266a2d",
    "resource_name": "webserver-85",
    "state": "open",
    "started_at": 1385085727,
    "ended_at": null,
    "policy_name": "Webserver Health",
    "condition_name": "CPU usage",
    "url": "https://app.google.stackdriver.com/incidents/f333dc64z",
    "summary": "CPU for webserver-85 is above the threshold of 1% with a value of 28.5%"
  },
  "version": 1.1
}

You can create a single webhook that handles all the alerts, or you can create a webhook on a per-policy basis to handle things separately.

like image 134
Jofre Avatar answered Sep 29 '22 08:09

Jofre