From d317e1a69096acf6b6e13b4e7550c6425477b968 Mon Sep 17 00:00:00 2001 From: Gentleelephant <1132960613@qq.com> Date: Mon, 23 Dec 2024 15:04:06 +0800 Subject: [PATCH] update template Signed-off-by: Gentleelephant <1132960613@qq.com> --- helm/templates/template.yaml | 10 +++++----- helm/templates/zh-cn.yaml | 2 ++ pkg/constants/constants.go | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/helm/templates/template.yaml b/helm/templates/template.yaml index b6eaab2..db6f3ed 100644 --- a/helm/templates/template.yaml +++ b/helm/templates/template.yaml @@ -8,13 +8,13 @@ data: {{ "{{ define \"nm.subject\" -}}{{- $rawStatus := .Status -}}{{- $severity := index .CommonLabels \"severity\" -}}{{- $status := \"\" -}}{{- $numAlerts := len .Alerts -}}{{- if eq $numAlerts 0 -}}Show nothing{{- else if eq $numAlerts 1 -}}{{- range .Alerts -}}{{- $alertType := .Labels.alerttype -}}{{- $alertName := .Labels.alertname -}}{{- $cluster := .Labels.cluster -}}{{- $node := .Labels.node -}}{{- $pod := .Labels.pod -}}{{- $namespace := .Labels.namespace -}}{{- if eq $rawStatus \"firing\" -}}{{- $status = \"[FIRING]\" -}}{{- else if eq $rawStatus \"resolved\" -}}{{- $status = \"[RESOLVED]\" -}}{{- else -}}{{- $status = \"[UNKNOWN]\" -}}{{- end -}}{{- $output := $status -}}{{- if $severity -}}{{- $output = printf \"%s | severity=%s\" $output $severity -}}{{- end -}}{{- if $alertType -}}{{- $output = printf \"%s | alerttype=%s\" $output $alertType -}}{{- end -}}{{- if $alertName -}}{{- $output = printf \"%s | alertname=%s\" $output $alertName -}}{{- end -}}{{- if $cluster -}}{{- $output = printf \"%s | cluster=%s\" $output $cluster -}}{{- end -}}{{- if $node -}}{{- $output = printf \"%s | node=%s\" $output $node -}}{{- end -}}{{- if $namespace -}}{{- $output = printf \"%s | namespace=%s\" $output $namespace -}}{{- end -}}{{- if $pod -}}{{- $output = printf \"%s | pod=%s\" $output $pod -}}{{- end -}}{{- $output -}}{{- end -}}{{- else -}}{{- $hasFiring := false -}}{{- $hasResolved := false -}}{{- range .Alerts -}}{{- if eq .Status \"firing\" -}}{{- $hasFiring = true -}}{{- end -}}{{- if eq .Status \"resolved\" -}}{{- $hasResolved = true -}}{{- end -}}{{- end -}}{{- if and $hasFiring $hasResolved -}}{{- $status = \"[FIRING|RESOLVED]\" -}}{{- else if $hasFiring -}}{{- $status = \"[FIRING]\" -}}{{- else if $hasResolved -}}{{- $status = \"[RESOLVED]\" -}}{{- else -}}{{- $status = \"[UNKNOWN]\" -}}{{- end -}}{{- $alertType := index .GroupLabels \"alerttype\" -}}{{- $alertName := index .GroupLabels \"alertname\" -}}{{- $cluster := index .GroupLabels \"cluster\" -}}{{- $namespace := index .GroupLabels \"namespace\" -}}{{- $node := index .GroupLabels \"node\" -}}{{- $output := $status -}}{{- if $severity -}}{{- $output = printf \"%s | severity=%s\" $output $severity -}}{{- end -}}{{- if $alertType -}}{{- $output = printf \"%s | alerttype=%s\" $output $alertType -}}{{- end -}}{{- if $alertName -}}{{- $output = printf \"%s | alertname=%s\" $output $alertName -}}{{- end -}}{{- if $cluster -}}{{- $output = printf \"%s | cluster=%s\" $output $cluster -}}{{- end -}}{{- if $namespace -}}{{- $output = printf \"%s | namespace=%s\" $output $namespace -}}{{- end -}}{{- if $node -}}{{- $output = printf \"%s | node=%s\" $output $node -}}{{- end -}}{{- $output -}}{{- end -}}{{- end -}}" }} {{ "{{ define \"nm.default.text\" }}{{ range .Alerts }}{{ template \"nm.default.message\" . }}" }} {{ "{{ range .Labels.SortedPairs }} {{ .Name | translate }}: {{ .Value }}" }} - {{ "{{ end }}{{ range .Annotations.SortedPairs.Filter \"runbook_url\" \"message\" \"summary\" \"summary_cn\" }} {{ .Name | translate }}: {{ .Value }}" }} + {{ "{{ end }}{{ range .Annotations.SortedPairs.Filter \"runbook_url\" \"message\" \"summary\" \"summary_cn\" \"summaryCn\" }} {{ .Name | translate }}: {{ .Value }}" }} {{ "{{ end }}" }} {{ "{{ end }}{{- end }}" }} {{ "{{ define \"nm.default.markdown\" }}{{ range .Alerts }}### {{ template \"nm.default.message\" . }}" }} {{ "{{ range .Labels.SortedPairs }}- {{ .Name | translate }}: {{ .Value }}" }} - {{ "{{ end }}{{ range .Annotations.SortedPairs.Filter \"runbook_url\" \"message\" \"summary\" \"summary_cn\" }}- {{ .Name | translate }}: {{ .Value }}" }} + {{ "{{ end }}{{ range .Annotations.SortedPairs.Filter \"runbook_url\" \"message\" \"summary\" \"summary_cn\" \"summaryCn\" }}- {{ .Name | translate }}: {{ .Value }}" }} {{ "{{ end }}" }} {{ "{{ end }}{{- end }}" }} @@ -28,7 +28,7 @@ data: {{ " text: ' {{ .Name | translate }}: {{ .Value }}'" }} {{ " {{- end }}" }} {{ " {{ if ne (len .Annotations.SortedPairs.Filter) 0 }}" }} - {{ " {{ range .Annotations.SortedPairs.Filter \"runbook_url\" \"message\" \"summary\" \"summary_cn\" }}" }} + {{ " {{ range .Annotations.SortedPairs.Filter \"runbook_url\" \"message\" \"summary\" \"summary_cn\" \"summaryCn\" }}" }} {{ " - - tag: text" }} {{ " text: ' {{ .Name | translate }}: {{ .Value }}'" }} {{ " {{- end }}" }} @@ -38,7 +38,7 @@ data: {{ " {{- end }}" }} {{ "{{- end }}" }} - {{ "{{ define \"nm.feishu.text\" }}{{ range .Alerts }}{{ template \"nm.default.message\" . }}{{ \"\\n\" }}{{ range .Labels.SortedPairs }} {{ .Name | translate }}: {{ .Value }}{{ \"\\n\" }}{{ end }}{{ range .Annotations.SortedPairs.Filter \"runbook_url\" \"message\" \"summary\" \"summary_cn\" }} {{ .Name | translate }}: {{ .Value }}{{ \"\\n\" }}{{ end }}{{ \"\\n\" }}{{ end }}{{- end }}" }} + {{ "{{ define \"nm.feishu.text\" }}{{ range .Alerts }}{{ template \"nm.default.message\" . }}{{ \"\\n\" }}{{ range .Labels.SortedPairs }} {{ .Name | translate }}: {{ .Value }}{{ \"\\n\" }}{{ end }}{{ range .Annotations.SortedPairs.Filter \"runbook_url\" \"message\" \"summary\" \"summary_cn\" \"summaryCn\" }} {{ .Name | translate }}: {{ .Value }}{{ \"\\n\" }}{{ end }}{{ \"\\n\" }}{{ end }}{{- end }}" }} {{ "{{ define \"nm.default.html\" }}" }} {{ " " }} @@ -57,7 +57,7 @@ data: {{ " " }} {{ " {{ template \"nm.default.message\" . }}
" }} {{ " {{ range .Labels.SortedPairs }}  {{ .Name | translate }}: {{ .Value }}
{{ end }}" }} - {{ " {{ range .Annotations.SortedPairs.Filter \"runbook_url\" \"message\" \"summary\" \"summary_cn\" }}  {{ .Name | translate }}: {{ .Value }}
{{ end }}" }} + {{ " {{ range .Annotations.SortedPairs.Filter \"runbook_url\" \"message\" \"summary\" \"summary_cn\" \"summaryCn\" }}  {{ .Name | translate }}: {{ .Value }}
{{ end }}" }} {{ " " }} {{ " " }} {{ " {{ end }}" }} diff --git a/helm/templates/zh-cn.yaml b/helm/templates/zh-cn.yaml index 3dffabb..d4cae89 100644 --- a/helm/templates/zh-cn.yaml +++ b/helm/templates/zh-cn.yaml @@ -35,8 +35,10 @@ data: rule_level: "规则级别" name: "名称" receiver: "接收者" + receiver_type: "接收者类型" workload_type: "工作负载类型" rule_type: "规则类型" + reason: "原因" kind: ConfigMap metadata: name: zh-cn diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 96188ed..379c6d1 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -40,7 +40,7 @@ const ( AlertSummaryCN = "summaryCn" ReceiverName = "receiver" - ReceiverType = "receiver-type" + ReceiverType = "receiver_type" Verify = "verify" Notification = "notification"