如何在 Stackdriver Alerting 中自定义整个电子邮件通知?

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

目前,创建警报策略时在文档字段中指定的消息显示在 Stackdriver 警报电子邮件的文档字段中。 我想用我的自定义内容覆盖整个电子邮件正文。 如何使用我的自定义消息覆盖 Stackdriver 警报电子邮件的消息正文? 有没有其他解决方法可以做到这一点?

您应该可以发送 notification to a webhook, and this could directly be an HTTP-triggered Cloud Function

此 Cloud Function 会收到警报的所有信息,您可以按照 this tutorial to use SendGrid 发送警报。

这比设置电子邮件通知要复杂得多,但也为您提供了有关警报的惊人灵活性,因为您不仅可以随心所欲地编写消息,还可以处理以您想要的任何方式获取数据:

  • 您有低优先级警报?然后存储它们并发送摘要 偶尔而不是垃圾邮件。
  • 想要更改发送对象 根据日历轮换提醒?使用函数查找 谁应该被通知。

这些只是我在撰写此消息时突然想到的一些想法。

POST正文中提供的信息是这个(这只是一个示例):

{
  "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
}

您可以创建一个单独的 webhook 来处理所有警报,或者您可以在 per-policy 基础上创建一个 webhook 来单独处理事情。