如何在 terraform 中为 Datadog 设置单独的警告消息和警报消息?

How do I set a separate message for warning vs alert in terraform for Datadog?

我正在设置一个如下所示的监视器:

resource "datadog_monitor" "queue_size_critical" {
  message = "High Priority"
  name    = "too many messages in queue"
  query   = "max(last_10m):max:aws.sqs.approximate_number_of_messages_visible{aws_account:<account>,queuename:<queuename>} > 10"
  type    = "metric alert"
  tags    = my_tags
  thresholds = {
    ok = 0
    warning = 1
    critical = 10
  }
  renotify_interval = 1440
}

我还有一个如下所示的小部件:

widget {
  alert_value_definition {
    alert_id = datadog_monitor.queue_size_critical.id
    title    = datadog_monitor.queue_size_critical.name
  }
}

我想定义两种不同的消息,一种是在超过“警告”阈值时发送,另一种是在超过“临界”阈值时发送。

我该怎么做?

这是正确的吗?

resource "datadog_monitor" "queue_size_critical" {
      message = "{{#is_alert}}High Priority{{/is_alert}}
                 {{#is_warning}}Low priority{{/is_warning}}
                 This gets sent every time, in every message."
      name    = "too many messages in queue"
      query   = bla bla bla
      ...etc...
}

这些都在 message 属性中用 conditional logic variables 处理了。

例如,如果您将 message 值定义为...

{{#is_alert}}
High Priority @pagerduty
{{/is_alert}}

{{#is_warning}}
Medium Priority @slack-mychannel
{{/is_warning}}

You should reference [this dashboard](mydashboardlink) to see how bad this is and follow [these steps](myrunbook) to resolve the situation.

...然后...

  1. 当您的监视器超过警报阈值时,它会在消息中包含“高优先级”,并且会向您的 pagerduty 集成发送通知,
  2. 当它超过警告阈值时,它将包括“中优先级”并向您的松弛频道“mychannel”发送通知,并且
  3. 带有有趣链接的“您应该参考”部分总是会出现。