Alertmanager
Alertmanager
argocd-notifications 로 Alertmanager에 이벤트를 푸시하는 방법을 알려드릴게요. Prometheus Alertmanager와 연동해서 애플리케이션 상태 이상을 알릴 수 있어요.
출처: 문서
본문
파라미터 (Parameters)
이 알림 서비스는 Alertmanager에 이벤트를 푸시하는 데 사용되며, 다음 설정을 지정해야 합니다:
-
targets- alertmanager 서비스 주소, 배열 타입 -
scheme- 선택 사항, 기본값은 "http", 예: http 또는 https -
apiPath- 선택 사항, 기본값은 "/api/v2/alerts" -
insecureSkipVerify- 선택 사항, 기본값은 "false", scheme 이 https 일 때 ca 검증을 건너뛸지 여부 -
basicAuth- 선택 사항, 서버 인증 -
bearerToken- 선택 사항, 서버 인증 -
timeout- 선택 사항, 알림을 보낼 때 사용하는 타임아웃(초), 기본값은 "3 seconds" -
maxIdleConns- 선택 사항, 모든 호스트를 통틀어 유휴(keep-alive) 연결의 최대 수. -
maxIdleConnsPerHost- 선택 사항, 호스트당 유휴(keep-alive) 연결의 최대 수. -
maxConnsPerHost- 선택 사항, 호스트당 총 연결의 최대 수. -
idleConnTimeout- 선택 사항, 유휴(keep-alive) 연결이 닫히기 전에 유지될 최대 시간.
인증에는 basicAuth 또는 bearerToken 중 하나를 고르면 됩니다. 둘을 동시에 설정하면 basicAuth 가 bearerToken 보다 우선합니다.
예시 (Example)
Prometheus Alertmanager 설정
global:
resolve_timeout: 5m
route:
group_by: ['alertname']
group_wait: 10s
group_interval: 10s
repeat_interval: 1h
receiver: 'default'
receivers:
- name: 'default'
webhook_configs:
- send_resolved: false
url: 'http://10.5.39.39:10080/api/alerts/webhook'
"send_resolved" 를 끄지 않으면 "resolve_timeout" 이후 불필요한 복구(recovery) 알림을 받게 되니 주의하세요.
인증 없이 alertmanager 하나로 보내기
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-notifications-cm
data:
service.alertmanager: |
targets:
- 10.5.39.39:9093
커스텀 api path 로 alertmanager 클러스터에 보내기
alertmanager 가 기본 api 를 바꿨다면 "apiPath" 를 커스터마이즈할 수 있어요.
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-notifications-cm
data:
service.alertmanager: |
targets:
- 10.5.39.39:443
scheme: https
apiPath: /api/events
insecureSkipVerify: true
인증과 함께 고가용성 alertmanager 로 보내기
인증 토큰을 argocd-notifications-secret Secret 에 저장하고, argocd-notifications-cm ConfigMap 에서 설정해 쓰세요.
apiVersion: v1
kind: Secret
metadata:
name: <secret-name>
stringData:
alertmanager-username: <username>
alertmanager-password: <password>
alertmanager-bearer-token: <token>
- basicAuth 사용
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-notifications-cm
data:
service.alertmanager: |
targets:
- 10.5.39.39:19093
- 10.5.39.39:29093
- 10.5.39.39:39093
scheme: https
apiPath: /api/v2/alerts
insecureSkipVerify: true
basicAuth:
username: $alertmanager-username
password: $alertmanager-password
- bearerToken 사용
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-notifications-cm
data:
service.alertmanager: |
targets:
- 10.5.39.39:19093
- 10.5.39.39:29093
- 10.5.39.39:39093
scheme: https
apiPath: /api/v2/alerts
insecureSkipVerify: true
bearerToken: $alertmanager-bearer-token
템플릿 (Templates)
-
labels- 최소 하나의 label 쌍이 필요하며, alertmanager 라우팅에 따라 알림 전략을 다르게 구현합니다 -
annotations- 선택 사항, 정보 라벨 집합을 지정합니다. 더 긴 추가 정보를 저장하는 데 쓸 수 있지만 표시 용도로만 사용됩니다 -
generatorURL- 선택 사항, 기본값은 '{{.app.spec.source.repoURL}}', 클라이언트에서 이 알림을 일으킨 엔티티를 식별하는 데 쓰는 백링크입니다
label, annotations, generatorURL 값은 템플릿화할 수 있어요.
context: |
argocdUrl: https://example.com/argocd
template.app-deployed: |
message: Application {{.app.metadata.name}} has been healthy.
alertmanager:
labels:
fault_priority: "P5"
event_bucket: "deploy"
event_status: "succeed"
recipient: "{{.recipient}}"
annotations:
application: '<a href="{{.context.argocdUrl}}/applications/{{.app.metadata.name}}">{{.app.metadata.name}}</a>'
author: "{{(call .repo.GetCommitMetadata .app.status.sync.revision).Author}}"
message: "{{(call .repo.GetCommitMetadata .app.status.sync.revision).Message}}"
labels 에 따라 Alertmanager에서 목표 지향적(targeted) 푸시를 할 수 있어요.
template.app-deployed: |
message: Application {{.app.metadata.name}} has been healthy.
alertmanager:
labels:
alertname: app-deployed
fault_priority: "P5"
event_bucket: "deploy"
특별한 label alertname 이 있습니다. 값을 설정하지 않으면 기본적으로 템플릿 이름과 같아져요.