我知道这个回复是几年后的事了,但我的方法是利用 .CommonAnnotations 和标签来显示信息,并利用警报名称来查询运行手册 -
警报管理器.yml
slack_configs:
- api_url:
channel: '#XXXXXXXXXXXXXXXX'
color: '{{ template "SLACK_MSG_COLOR" . }}'
send_resolved: true
title: '{{ template "SLACK_MSG_TITLE" . }}'
text: '{{ template "SLACK_MSG_TEXT" . }}'
pagerduty_configs:
- routing_key: '{{ template "Global_PD_Service_Key" . }}'
description: '{{ template "PAGERDUTY_DESCRIPTION" . }}'
severity: '{{ if .CommonLabels.severity }}{{ .CommonLabels.severity | toLower }}{{ else }}critical{{ end }}'
links:
- text: 'Prometheus'
href: '{{ (index .Alerts 0).GeneratorURL }}'
- text: 'Search Runbooks'
href: '{{ template "RUNBOOK_SEARCH" . }}'
和.tmpl
################
# Runbook
################
# Runbook Search
{{ define "RUNBOOK_SEARCH" }}https://dsmith73.github.io/101-docs/search/?q={{ .CommonLabels.alertname }}{{ end }}
################
# Slack
################
# Slack Color
{{ define "SLACK_MSG_COLOR" }}{{ if eq .Status "firing" }}{{ if eq .CommonLabels.severity "critical" }}danger{{ else if eq .CommonLabels.severity "error" }}danger{{ else if eq .CommonLabels.severity "warning" }}warning{{ else }}#439FE0{{ end }}{{ else}}good{{ end }}{{ end }}
# Slack Text
{{define "SLACK_MSG_TEXT" }}
<!here> - {{ .CommonAnnotations.description }}
`View:` :chart_with_upwards_trend:*<{{ (index .Alerts 0).GeneratorURL }}|Prometheus>* or :notebook:*<{{ template "RUNBOOK_SEARCH" . }}|Runbook>*
*Details:*
{{ range .CommonLabels.SortedPairs }}• *{{ .Name }}:* `{{ .Value }}`
{{ end }}
{{ end }}
#Slack Summary
{{ define "SLACK_TITLE_SUMMARY" -}}
{{- if .CommonAnnotations.summary -}}
{{- .CommonAnnotations.summary -}}
{{- else -}}
{{- with index .Alerts 0 -}}
{{- .Annotations.summary -}}
{{- end -}}
{{- end -}}
{{- end -}}
# Slack Title
{{ define "SLACK_MSG_TITLE" }}
{{ if eq .Status "resolved" }}
{{- .Status | toUpper }} : {{ template "SLACK_TITLE_SUMMARY" . }}
{{ else if eq .Status "firing" }}
{{ .CommonLabels.severity | toUpper }} : {{ template "SLACK_TITLE_SUMMARY" . }}
{{ end }}
{{ end }}
对我来说,这是将警报与运行手册联系起来的好方法,而不是在规则或其他位置定义它们......