【发布时间】:2021-01-12 04:19:17
【问题描述】:
我正在尝试使用以下 yml 配置来自 Prometheus alertmanager 的 slack notification。
global:
resolve_timeout: 1m
slack_api_url: 'https://hooks.slack.com/services/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'
route:
receiver: 'slack-notifications'
receivers:
- name: 'slack-notifications'
slack_configs:
- channel: '#monitoring-instances'
send_resolved: true
icon_url: https://avatars3.githubusercontent.com/u/3380462
title: |-
[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .CommonLabels.alertname }} for {{ .CommonLabels.job }}
{{- if gt (len .CommonLabels) (len .GroupLabels) -}}
{{" "}}(
{{- with .CommonLabels.Remove .GroupLabels.Names }}
{{- range $index, $label := .SortedPairs -}}
{{ if $index }}, {{ end }}
{{- $label.Name }}="{{ $label.Value -}}"
{{- end }}
{{- end -}}
)
{{- end }}
text: >-
{{ range .Alerts -}}
*Alert:* {{ .Annotations.title }}{{ if .Labels.severity }} - `{{ .Labels.severity }}`{{ end }}
*Description:* {{ .Annotations.description }}
*Details:*
{{ range .Labels.SortedPairs }} • *{{ .Name }}:* `{{ .Value }}`
{{ end }}
{{ end }}
当我启动我的 alert-manager 容器时,它会不断重启并显示以下错误。
警报管理器 | level=error ts=2021-01-12T04:08:19.040Z caller=coordinator.go:124 component=configuration msg="加载配置文件失败" file=/etc/alertmanager/alertmanager.yml err="yaml: 无效前导UTF-8 八位字节”
已验证Here,它显示为有效yaml
还用记事本++检查了encoding已经显示为UTF-8还有其他方法可以解决这个问题吗?
即使这段代码也显示同样的错误。
slack_configs:
- channel: '#monitoring-instances'
send_resolved: false
title: '[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] Monitoring Event Notification'
text: >-
{{ range .Alerts }}
*Alert:* {{ .Annotations.summary }} - `{{ .Labels.severity }}`
*Description:* {{ .Annotations.description }}
*Graph:* <{{ .GeneratorURL }}|:chart_with_upwards_trend:> *Runbook:* <{{ .Annotations.runbook }}|:spiral_note_pad:>
*Details:*
{{ range .Labels.SortedPairs }} • *{{ .Name }}:* `{{ .Value }}`
{{ end }}
{{ end }}
我使用的是 Centos-8.2 系统,是不是我的系统有问题?谁能帮帮我。
【问题讨论】:
-
这一行的问题
{{ range .Labels.SortedPairs }} • *{{ .Name }}:*{{ .Value }}在 linux 中•不接受,它给出了invalid leading UTF-8 octet错误。
标签: linux encoding yaml prometheus prometheus-alertmanager