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

时间:2020-07-08 05:08:21

标签: terraform monitor threshold 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...
}

1 个答案:

答案 0 :(得分:2)

所有操作都在conditional logic variablesmessage属性中进行。

例如,如果您将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. 带有有趣链接的“您应该参考”部分将始终显示。