【问题标题】:Prometheus alertmanager - invalid leading UTF-8 octetPrometheus alertmanager - 无效的前导 UTF-8 八位字节
【发布时间】:2021-01-12 04:19:17
【问题描述】:

我正在尝试使用以下 yml 配置来自 Prometheus alertmanagerslack 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


【解决方案1】:

在我的情况下,config/application.yml 有问题 这都是胡言乱语,所以我不得不删除它并重新创建它。 之后问题就解决了。

【讨论】:

  • 很高兴听到,即使在您的 application.yml 文件中使用 也能正常工作。就我而言,它根本不起作用。因此删除并尝试它开始工作。
  • 我的 application.yml 中没有 •。只是一个完全不同的原因,可能会对其他人有所帮助。
【解决方案2】:

通过删除代码中的项目符号 并启动容器来解决。现在可以了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-24
    • 2017-11-02
    相关资源
    最近更新 更多