如何通过 Datadog 中的回复代码发出警报?

如何通过 Datadog 中的回复代码发出警报?

需要帮助。我想在网站出现 401 502 等错误时发出警报。服务器上有一个代理,它会在 datadog 中发送不同的部分。有这样的模块 http_check,并且它有这样的功能。

http_response_status_code - A string or Python regular expression for an HTTP status code. This check will report DOWN for any status code that does not match. This defaults to 1xx, 2xx and 3xx HTTP status codes. For example: 401 or 4\d\d

这是我的 http_check.yml

init_config:
instances:
  - name: My first service
    url: https://example.com
    collect_response_time: true
    timeout: 1
    skip_event: true
    http_response_status_code: 502
    check_certificate_expiration: true
    disable_ssl_validation: false
    days_warning: 7
    days_critical: 3
    tags:
      - url:example.com
      - env:production

实际上,我尝试关闭 nginx 并观察它是否发送状态。我什么也没看到。一般来说,任务是监控网站,如果出现问题,则发出警报。

答案1

datadog 的开发人员知道这个问题。为了解决这个问题,我们需要使用这样的自定义检查 -http_检查.py

然后我们需要在主机上重启代理并模拟错误。在事件数据狗中我们将看到http://example.com returned a status of 503 after 30.0 seconds

之后我们可以创建警报。此自定义检查发送除 200 之外的所有代码。

答案2

您可以将 (4|5)\d\d 用于 http_response_status_code。

相关内容