mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 12:13:55 +09:00
fix(monitoring): reject a non-text email template before the default
alerta.alerts.email.template went through default "" before its type was checked, so false, 0 or an empty list or map turned into an empty string and the chart rendered without a template instead of failing. The type is now checked on the value as written, and anything other than text or an absent key fails the render. Assisted-by: LLM Signed-off-by: Yan Bondarenko <202671653+yankawai@users.noreply.github.com>
This commit is contained in:
1 parent
2405f0f3fd
commit
fc1fef9291
2 files changed
+12
-4
No files matched your search
@@ -11,7 +11,11 @@
|
||||
{{- $emailSeverities := $email.severities | default (list "critical" "major") }}
|
||||
{{- $emailPasswordSecret := "alertmanager-email-password" }}
|
||||
{{- $emailTemplateConfigMap := "alertmanager-email-template" }}
|
||||
{{- $emailTemplate := $email.template | default "" }}
|
||||
{{- $emailTemplateRaw := index $email "template" }}
|
||||
{{- if not (or (kindIs "string" $emailTemplateRaw) (kindIs "invalid" $emailTemplateRaw)) }}
|
||||
{{- fail (printf "alerta.alerts.email.template must be the text of an Alertmanager template file, got a %s" (kindOf $emailTemplateRaw)) }}
|
||||
{{- end }}
|
||||
{{- $emailTemplate := $emailTemplateRaw | default "" }}
|
||||
{{- $emailSet := list }}
|
||||
{{- range $field := list "to" "from" "smarthost" "authUsername" "repeatInterval" "alertnames" "severities" "template" }}
|
||||
{{- if index $email $field }}{{ $emailSet = append $emailSet $field }}{{ end }}
|
||||
@@ -104,9 +108,6 @@
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if $emailTemplate }}
|
||||
{{- if not (kindIs "string" $emailTemplate) }}
|
||||
{{- fail (printf "alerta.alerts.email.template must be the text of an Alertmanager template file, got a %s" (kindOf $emailTemplate)) }}
|
||||
{{- end }}
|
||||
{{- if not (regexMatch "\\{\\{-?\\s*define\\s" $emailTemplate) }}
|
||||
{{- fail "alerta.alerts.email.template must define named templates, such as email.default.subject and email.default.html, because Alertmanager only uses the file through the names it defines" }}
|
||||
{{- end }}
|
||||
|
||||
@@ -251,3 +251,10 @@ tests:
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: "alerta.alerts.email to, from and smarthost must all be set to enable email alerts. To turn email off, clear every field under alerta.alerts.email. Fields still set are template"
|
||||
|
||||
- it: rejects a template given as a boolean instead of being dropped by the default
|
||||
set:
|
||||
alerta.alerts.email.template: false
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: "alerta.alerts.email.template must be the text of an Alertmanager template file, got a bool"
|
||||
Reference in new issue
Block a user