Datadog监视器API / terraform进程监视器检查

时间:2017-03-01 17:53:02

标签: api monitor terraform datadog

我试图在我的terraform代码库中集成一个Datadog监视器检查sshd进程,但我得到了datadog_monitor.host_is_up2: error updating monitor: API error 400 Bad Request: {"errors":["The value provided for parameter 'query' is invalid"]}

我所做的是复制我在Datadog面板上创建的监视器查询并将其粘贴到tf文件中:

resource "datadog_monitor" "host_is_up2" {
  name = "host is up"
  type = "metric alert"
  message = "Monitor triggered"
  escalation_message = "Escalation message"

  query = "process.up.over('process:ssh').last(4).count_by_status()"

  thresholds {
    ok = 0
    warning = 1
    critical = 2
  }

  notify_no_data = false
  renotify_interval = 60

  notify_audit = false
  timeout_h = 60
  include_tags = true
  silenced {
    "*" = 0
  }
}

ofc查询示例"avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo} by {host} > 2"正常工作

如果某个特定服务(如sshd)已启用,通过Datadog API或terraform进行检查的正确方法是什么?

1 个答案:

答案 0 :(得分:2)

您的代码中有两个错误:

  1. 使用的type是错误的。它应该是service check而不是metric alert
  2. 您需要将process.up括在一对''中。
  3. 完成后,您的代码将完美运行。