如何通过 REST api 获取 google 云平台警报状态

How to get google cloud platform alert status via REST apis

我在google 云平台中创建了警报策略。我收到基于警报策略的电子邮件通知。 现在我想为此警报配置一个外部自定义监控系统。我想知道此监控系统每 10-20 秒后可以调用的 REST API 并获取此警报的状态。

请帮忙

如果您只想使用 Cloud MonitoringAlerting Policy,您将无法实现。

无法将警报策略配置为在满足策略条件时(重复)通知。通过 Google Cloud Console 创建的提醒政策仅在满足条件时发送通知。您还可以在条件不再满足时收到通知。

可以在 Notifications per incident 文档中找到更多信息。

Cloud Monitoring API v3 - Alerting policies中可以看到只有事件的创建被发送的信息。

An alerting policy is a configuration resource that describes the criteria for generating incidents and how to notify you when those incidents are created.

一般来说,如果要使用Notification Channels to send notifications outside you can use Webhooks or PubSub

备注

Webhooks only support public endpoints. If you need notifications sent to an endpoint that isn't public, then create a Pub/Sub notification channel and configure a subscription to the Pub/Sub topic. For more information, see Webhook notifications fail when configured for a private endpoint.

由于您没有提供更多信息,因此很难说您是否没有使用第 3 方软件中的某些 built-in 功能来与 GCP 云监控集成。示例之一是 Grafana:

Grafana ships with built-in support for Google Cloud Monitoring. Add it as a data source to build dashboards for your Google Cloud Monitoring metrics.

GCP 也可能使用 Prometheus 功能。也许这可能会给你一些类似于你想要的东西。

Prometheus is a monitoring tool often used with Kubernetes. If you configure Cloud Operations for GKE and include Prometheus support, then the metrics that are generated by services using the Prometheus exposition format can be exported from the cluster and made visible as external metrics in Cloud Monitoring.

有一些解决方法,但它们无法满足您的需求。

  • 可以创建多个条件来识别同一问题。每次满足条件时,都会收到通知。
  • 当条件满足时,可以通知用户,但这可能会导致垃圾邮件。

我最后要提的是,已经有一个Feature Request可以添加多个通知,直到条件消失。 FR: Repeat Notifications until condition is gone.

中有更多详细信息

其他文档:

结论

  • 通过 Google Cloud Console 创建的提醒政策仅在满足条件时发送通知。您还可以启用通知以获取已解决的通知。
  • Feature Request可以重复添加通知 - here
  • 要向其他 apps/resources 发送通知,您可以使用 WebhooksPubSub