You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ArgoCD Notification Controller无法向Opsgenie推送同步失败告警

问题分析与修复方案

从错误日志Request validation err: message can not be empty来看,核心原因是Opsgenie告警模板的格式解析失败,导致message字段未被正确识别或渲染为空。结合你的配置,主要存在两个问题:

1. YAML缩进错误

template.app-sync-failed下的opsgenie块缩进不足,导致ArgoCD无法正确解析该配置块,message字段被当作普通字符串的一部分而非有效配置项。

2. Conditions字段的JSON语法错误

在details.Conditions的模板循环中,重复写了{{if $index}},{{end}},会生成多余的逗号,破坏JSON结构,进而影响整个模板的解析。


修复后的配置

template.app-sync-failed: |
    opsgenie:
      message: "ArgoCD Notification - Sync Failure for {{.app.metadata.name}}"
      description: "An ArgoCD application {{.app.metadata.name}} in project {{.app.spec.project}} has experienced a sync failure. Sync status: {{.app.status.sync.status}}"
      priority: "P2"
      tags:
        - "argocd"
        - "notification"
      details:
        "Sync Status": "{{.app.status.sync.status}}"
        "Synced at": "{{.app.status.operationState.finishedAt}}"
        "App Health": "{{.app.status.health.status}}"
        "Revisions": "{{.app.status.sync.revisions}}"
        "Sync Initiator": "{{.app.status.operationState.operation.initiatedBy}}"
        "Conditions": [
          {{range $index, $c := .app.status.conditions}}
            {{if $index}},{{end}}
            {
              "Type": "{{$c.type}}",
              "Message": "{{$c.message}}"
            }
          {{end}}
        ]
    teams:
      facts: |
        [{
          "name": "Sync Status",
          "value": "{{.app.status.sync.status}}"
        },
        {
          "name": "Synced at",
          "value": "{{.app.status.operationState.finishedAt}}"
        },
        {
          "name": "App Health",
          "value": "{{.app.status.health.status}}"
        },
        {
          "name": "Revisions",
          "value": "{{.app.status.sync.revisions}}"
        },
        {
          "name": "Sync Initiator",
          "value": "{{.app.status.operationState.operation.initiatedBy}}"
        }
        {{range $index, $c := .app.status.conditions}}
          {{if $index}},{{end}}
          {
            "name": "{{$c.type}}",
            "value": "{{$c.message}}"
          }
        {{end}}
        ]
      themeColor: '#660000'
      title: Application {{.app.metadata.name}} sync FAILURE
      text: Application {{.app.metadata.name}} has failed sync operation at {{.app.status.operationState.finishedAt}}.

关键修复点

  • 调整opsgenie块的缩进,使其与同级的teams保持一致(使用4个空格缩进,确保YAML结构正确)。
  • 修正Conditions的JSON数组格式:添加[]包裹循环内容,同时只保留一个{{if $index}},{{end}}来处理元素间的逗号,避免多余符号破坏JSON结构。
  • 模板变量本身有效(Teams能正常接收告警可佐证),无需调整变量上下文。

修复后重新部署ArgoCD通知控制器,即可触发Opsgenie告警。

内容的提问来源于stack exchange,提问作者Nitin Chauhan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 19:45:56