Nocward
Nocward Monitoring
Nocward Monitoring 参考 阅读约 1 分钟

Webhook 负载

Monitoring 发送到 Webhook 渠道的 JSON 正文和标头,以及如何验证签名。

更新于 2026年9月26日

Webhook 渠道会以 HTTP POST 请求发送每条通知,并带有 Content-Type: application/json:

{
  "version": 1,
  "subject": "[CRITICAL] core-sw",
  "body": "core-sw: cpu_usage_percent is 97.00 (threshold: gt 90.00)",
  "severity": "critical",
  "state": "alert",
  "event_type": "metric_threshold",
  "device": {"id": "0f2c...", "name": "core-sw"},
  "tenant_id": "81083ded-...",
  "event_id": "5b7e...",
  "timestamp": "2026-09-21T13:04:05.123456+00:00"
}
字段 含义
state alert、recovered、info、escalation 或 test
event_type 触发通知的事件,例如 device_down、metric_threshold、snmp_trap
event_id 告警历史记录条目——可用于忽略重复投递

标头

标头 内容
X-Nocward-Event 事件类型
X-Nocward-State 状态
X-Nocward-Delivery 每条排队通知唯一的标识
X-Nocward-Timestamp Unix 时间(秒)
X-Nocward-Signature sha256=<hex>——仅当渠道设置了签名密钥时才有

验证签名

签名为 HMAC-SHA256,以渠道的签名密钥为密钥,对 <timestamp>.<raw body> 进行计算:

import hmac, hashlib

def valid(secret: str, headers: dict, raw_body: bytes) -> bool:
    msg = headers["X-Nocward-Timestamp"].encode() + b"." + raw_body
    expected = "sha256=" + hmac.new(secret.encode(), msg, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, headers["X-Nocward-Signature"])

请拒绝时间戳早于几分钟以前的请求,以防止重放攻击。

投递

投递保证至少一次。投递失败后,会在 30 秒、2 分钟、10 分钟、30 分钟和 2 小时后重试。4xx 应答(408、425 和 429 除外)被视为永久失败,不再重试。请尽快返回 2xx,并以异步方式处理。

这个页面对您有帮助吗?

对产品本身有想法? 提交建议