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

拈花ヽ惹草 提交于 2020-12-03 16:27:18

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/49251738/how-can-i-customize-the-entire-email-notification-in-stackdriver-alerting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!