메시지를 Amazon SNS에 JSON으로 전송하도록 알림 관리자를 구성합니다. - Amazon Managed Service for Prometheus

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

메시지를 Amazon SNS에 JSON으로 전송하도록 알림 관리자를 구성합니다.

기본적으로 Prometheus용 Amazon 관리형 서비스 알림 관리자는 메시지를 일반 텍스트 목록 형식으로 출력합니다. 이 경우 다른 서비스에서 파싱하기가 더 어려울 수 있습니다. 대신 JSON 형식으로 알림을 보내도록 알림 관리자를 구성할 수 있습니다. JSON을 사용하면 Amazon SNS의 다운스트림 메시지를 웹후크 수신 엔드포인트에서 AWS Lambda 또는 웹후크 수신 엔드포인트에서 더 간단하게 처리할 수 있습니다. 기본 템플릿을 사용하는 대신 메시지 내용을 JSON으로 출력하는 사용자 지정 템플릿을 정의하여 다운스트림 함수에서 더 쉽게 구문 분석하도록 할 수 있습니다.

알림 관리자의 메시지를 JSON 형식으로 Amazon SNS로 출력하려면 template_files 루트 섹션 내에 다음 코드를 포함하도록 알림 관리자 구성을 업데이트하세요.

default_template: | {{ define "sns.default.message" }}{{ "{" }}"receiver": "{{ .Receiver }}","status": "{{ .Status }}","alerts": [{{ range $alertIndex, $alerts := .Alerts }}{{ if $alertIndex }}, {{ end }}{{ "{" }}"status": "{{ $alerts.Status }}"{{ if gt (len $alerts.Labels.SortedPairs) 0 -}},"labels": {{ "{" }}{{ range $index, $label := $alerts.Labels.SortedPairs }}{{ if $index }}, {{ end }}"{{ $label.Name }}": "{{ $label.Value }}"{{ end }}{{ "}" }}{{- end }}{{ if gt (len $alerts.Annotations.SortedPairs ) 0 -}},"annotations": {{ "{" }}{{ range $index, $annotations := $alerts.Annotations.SortedPairs }}{{ if $index }}, {{ end }}"{{ $annotations.Name }}": "{{ $annotations.Value }}"{{ end }}{{ "}" }}{{- end }},"startsAt": "{{ $alerts.StartsAt }}","endsAt": "{{ $alerts.EndsAt }}","generatorURL": "{{ $alerts.GeneratorURL }}","fingerprint": "{{ $alerts.Fingerprint }}"{{ "}" }}{{ end }}]{{ if gt (len .GroupLabels) 0 -}},"groupLabels": {{ "{" }}{{ range $index, $groupLabels := .GroupLabels.SortedPairs }}{{ if $index }}, {{ end }}"{{ $groupLabels.Name }}": "{{ $groupLabels.Value }}"{{ end }}{{ "}" }}{{- end }}{{ if gt (len .CommonLabels) 0 -}},"commonLabels": {{ "{" }}{{ range $index, $commonLabels := .CommonLabels.SortedPairs }}{{ if $index }}, {{ end }}"{{ $commonLabels.Name }}": "{{ $commonLabels.Value }}"{{ end }}{{ "}" }}{{- end }}{{ if gt (len .CommonAnnotations) 0 -}},"commonAnnotations": {{ "{" }}{{ range $index, $commonAnnotations := .CommonAnnotations.SortedPairs }}{{ if $index }}, {{ end }}"{{ $commonAnnotations.Name }}": "{{ $commonAnnotations.Value }}"{{ end }}{{ "}" }}{{- end }}{{ "}" }}{{ end }} {{ define "sns.default.subject" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}]{{ end }}
참고

이 템플릿은 영숫자 데이터로 JSON을 생성합니다. 데이터에 특수 문자가 있는 경우 이 템플릿을 사용하기 전에 특수 문자를 인코딩하세요.

이 템플릿이 발신 알림에 사용되도록 하려면 다음과 같이 alertmanager_config 블록에서 템플릿을 참조하세요.

alertmanager_config: | global: templates: - 'default_template'
참고

이 템플릿은 전체 메시지 본문을 JSON으로 작성하기 위한 것입니다. 이 템플릿은 전체 메시지 본문을 덮어씁니다. 이 특정 템플릿을 사용하려는 경우 메시지 본문을 재정의할 수 없습니다. 수동으로 수행한 모든 재정의는 템플릿보다 우선합니다.

해당 내용은 다음을 참조하세요.