Configure WeCom Notification Message Template
Time updated:2025-12-22 09:26:17
-
Log in to a cluster node and create a markdown template.
vi <template-name>The content is as follows:
apiVersion: v1 data: template: | {{- define "nm.default.markdown.test" }} {{- range .Alerts }} {{- $rawStatus := .Status }} {{- if eq $rawStatus "firing" }} ### <font color="yellow">{{ template "nm.default.message" . }}</font> {{- else }} ### <font color="green">{{ template "nm.default.message" . }}</font> {{- end }} {{- range .Labels.SortedPairs }} {{- if eq .Name "severity" }} {{- $color := "" }} {{- if eq .Value "critical" }} {{- $color = "red" }} {{- else if eq .Value "error" }} {{- $color = "orange" }} {{- else if eq .Value "warning" }} {{- $color = "yellow" }} {{- else if eq .Value "info" }} {{- $color = "blue" }} {{- end }} > <font color="{{$color}}">**{{ .Name | translate }}: {{ .Value }}**</font> {{- else }} > **{{ .Name | translate }}**: {{ .Value }} {{- end }} {{- end }} {{ range .Annotations.SortedPairs.Filter "runbook_url" "message" "summary" "summary_cn" }} > **{{ .Name | translate }}**: {{ .Value }} {{- end }} {{ end }} {{- end }} kind: ConfigMap metadata: name: notification-manager-template-test namespace: kubesphere-monitoring-system -
Execute the following command to create a ConfigMap named
notification-manager-template-test.kubectl apply -f <template-name> -
Configure WeCom in the Notification Channels or User Notification Settings to receive notification messages in WeCom sessions or WeCom group chats.
-
View the wechat receiver.
kubectl -n kubesphere-monitoring-system get receiver-
Receivers starting with
global-, such asglobal-wechat-receiver, are globally configured wechat receivers. -
Receivers starting with a user name, such as
admin-wechat-receiver, are tenant-level configured wechat receivers.
-
-
Edit the corresponding wechat receiver to use the markdown template in notification messages.
kubectl -n kubesphere-monitoring-system edit receiver <wechat-receiver-name>spec: wechat: enabled: true template: nm.default.markdown.test tmplText: name: notification-manager-template-test namespace: kubesphere-monitoring-system tmplType: markdownWeCom notification messages will be displayed using this markdown template.