Skip to content

Commit

Permalink
Merge pull request #280 from Gentleelephant/fix-1223
Browse files Browse the repository at this point in the history
update template
  • Loading branch information
benjaminhuo authored Dec 23, 2024
2 parents 0c9b1fe + d317e1a commit ed99293
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
10 changes: 5 additions & 5 deletions helm/templates/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}" }}
Expand All @@ -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 }}" }}
Expand All @@ -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\" }}" }}
{{ " <html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns=\"http://www.w3.org/1999/xhtml\" style=\"font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;\">" }}
Expand All @@ -57,7 +57,7 @@ data:
{{ " <td style=\"font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;\" valign=\"top\">" }}
{{ " <strong style=\"font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;\">{{ template \"nm.default.message\" . }}</strong><br style=\"font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;\" />" }}
{{ " {{ range .Labels.SortedPairs }}&nbsp;&nbsp;{{ .Name | translate }}: {{ .Value }}<br style=\"font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;\" />{{ end }}" }}
{{ " {{ range .Annotations.SortedPairs.Filter \"runbook_url\" \"message\" \"summary\" \"summary_cn\" }}&nbsp;&nbsp;{{ .Name | translate }}: {{ .Value }}<br style=\"font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;\" />{{ end }}" }}
{{ " {{ range .Annotations.SortedPairs.Filter \"runbook_url\" \"message\" \"summary\" \"summary_cn\" \"summaryCn\" }}&nbsp;&nbsp;{{ .Name | translate }}: {{ .Value }}<br style=\"font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;\" />{{ end }}" }}
{{ " </td>" }}
{{ " </tr>" }}
{{ " {{ end }}" }}
Expand Down
2 changes: 2 additions & 0 deletions helm/templates/zh-cn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ data:
rule_level: "规则级别"
name: "名称"
receiver: "接收者"
receiver_type: "接收者类型"
workload_type: "工作负载类型"
rule_type: "规则类型"
reason: "原因"
kind: ConfigMap
metadata:
name: zh-cn
Expand Down
2 changes: 1 addition & 1 deletion pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
AlertSummaryCN = "summaryCn"

ReceiverName = "receiver"
ReceiverType = "receiver-type"
ReceiverType = "receiver_type"

Verify = "verify"
Notification = "notification"
Expand Down

0 comments on commit ed99293

Please sign in to comment.