|
| 1 | +### Alert |
| 2 | +```json |
| 3 | +[ |
| 4 | + { |
| 5 | + "labels": { |
| 6 | + "alertname": "Test Alert Temiydom wgatpelzn eiesvt.", |
| 7 | + "env": "Test", |
| 8 | + "group": "Ops", |
| 9 | + "name": "Teft dwqokj yqka jbroocrw xwz.", |
| 10 | + "severity": "critical" |
| 11 | + }, |
| 12 | + "annotations": { |
| 13 | + "message": "Zxoiyg mnukiqqa imgxyh gwahxoe rixwdzgfn.\"\nLcxdl dpcmu gcrwhvyb qbipfn ifipq omumebq whwmupxag rnbryqneyu gih mszuxf.Tfwbmtj dxuwskbctr ostv kpmxujo tlydykp." |
| 14 | + }, |
| 15 | + "startsAt": "2023-05-04T03:45:54.173Z", |
| 16 | + "endsAt": "2023-05-04T04:45:54.173Z", |
| 17 | + "generatorURL": "https://www.github.com" |
| 18 | + } |
| 19 | +] |
| 20 | +``` |
| 21 | +### Template |
| 22 | +```gotemplate |
| 23 | +{{- define "feishu.title" -}} |
| 24 | + {{- if eq .Status "firing" -}} |
| 25 | + [Firing {{- .Alerts.Firing | len -}}/{{- .Alerts | len -}}] |
| 26 | + {{- else if eq .Status "resolved" -}} |
| 27 | + [Resolved {{- .Alerts.Resolved | len -}}] |
| 28 | + {{- else -}} |
| 29 | + [{{- .Status | toUpper | safeJson -}}] |
| 30 | + {{- end -}} |
| 31 | + {{" "}}{{- range .GroupLabels.SortedPairs -}} {{- if eq .Name "alertname" -}}{{- .Value | safeJson -}}{{- end -}} {{- end -}} |
| 32 | +{{- end -}} |
| 33 | +
|
| 34 | +{{- define "feishu.msg" -}} |
| 35 | + ### {{ template "feishu.title" . -}}\n |
| 36 | + {{- range $idx,$elem := .Alerts.Firing -}} |
| 37 | + {{- range .Labels.SortedPairs -}} |
| 38 | + **{{- .Name | safeJson -}}**:{{" "}}{{- .Value | safeJson -}}\n |
| 39 | + {{- end -}} |
| 40 | + {{- range .Annotations.SortedPairs -}} |
| 41 | + **{{- .Name | safeJson -}}**:{{" "}}{{- .Value | safeJson -}}\n |
| 42 | + {{- end -}} |
| 43 | + **Srart Time**:{{" "}}{{- .StartsAt -}}\n |
| 44 | + {{- if eq .Status "firing" -}} |
| 45 | + [View data]({{.GeneratorURL | safeJson}}) |
| 46 | + {{- end -}} |
| 47 | + {{- end -}} |
| 48 | +{{- end -}} |
| 49 | +{{- define "feishu.json" -}} |
| 50 | + { |
| 51 | + "msg_type": "interactive", |
| 52 | + "card": { |
| 53 | + "elements": [ |
| 54 | + { |
| 55 | + "content": "{{- template "feishu.msg" . -}}", |
| 56 | + "tag": "markdown" |
| 57 | + } |
| 58 | + ], |
| 59 | + "config": { |
| 60 | + "wide_screen_mode": true |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | +{{- end -}} |
| 65 | +
|
| 66 | +``` |
| 67 | +### Alertmanager Config |
| 68 | +```yaml |
| 69 | + |
| 70 | +receivers: |
| 71 | + - name: alert_test |
| 72 | + webhook_configs: |
| 73 | + - url: 'https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxxxxxxxxx' |
| 74 | + json: '{{ template "feishu.json" . }}' |
| 75 | + send_resolved: true |
| 76 | +``` |
| 77 | +
|
| 78 | +### Webhook Content |
| 79 | +``` |
| 80 | +{ |
| 81 | + "msg_type": "interactive", |
| 82 | + "card": { |
| 83 | + "elements": [ |
| 84 | + { |
| 85 | + "content": "### [Firing1/1] Test Alert Temiydom wgatpelzn eiesvt.\n**alertname**: Test Alert Temiydom wgatpelzn eiesvt.\n**env**: Test\n**group**: Ops\n**name**: Teft dwqokj yqka jbroocrw xwz.\n**severity**: critical\n**message**: Zxoiyg mnukiqqa imgxyh gwahxoe rixwdzgfn.\"\nLcxdl dpcmu gcrwhvyb qbipfn ifipq omumebq whwmupxag rnbryqneyu gih mszuxf.Tfwbmtj dxuwskbctr ostv kpmxujo tlydykp.\n**Srart Time**: 2023-05-04 03:45:54.173 +0000 UTC\n[View data](https://www.github.com)", |
| 86 | + "tag": "markdown" |
| 87 | + } |
| 88 | + ], |
| 89 | + "config": { |
| 90 | + "wide_screen_mode": true |
| 91 | + } |
| 92 | + } |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +### Feishu message |
| 97 | + |
0 commit comments