首页 > 解决方案 > Prometheus alertmanager - 无效的前导 UTF-8 八位字节

问题描述

我正在尝试使用以下 yml配置slack notificationfrom 。Prometheus alertmanager

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 }}

当我启动警报管理器容器时,它会继续重新启动并显示以下错误。

警报管理器 | 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 八位字节"

已验证这里显示为有效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 系统,是不是我的系统有问题?有谁可以帮我离开这里吗。

标签: linuxencodingyamlprometheusprometheus-alertmanager

解决方案


In my occasion there was an issue with the config/application.yml It was all Gibberish so I had to deleted it and recreate it. After that the issue was resolved.


推荐阅读