참조 : https://afsdzvcx123.tistory.com/entry/Grafana-Alert-Slack-%EC%97%B0%EB%8F%99%ED%95%98%EA%B8%B0
- Slack API 홈페이지
https://api.slack.com/apps/ -> 로그인 필요.
– “Create New APP” -> “From scratch”

– “App Name” : test, “Select a workspace” -> “workspace name”
이미지 생략
– 생성된 APP 선택된 상태에서 “Oauth & Permissions” -> “Scopes” -> “Bot Token Scopes” -> “Add on Oauth Scope”
chat:write / files:write 권한 선택

– “Oauth & Permissions” -> “OAuth Tokens for Your Workspace” -> “Install to Workspace”
이미지 생략
– Feature-“Incoming Webhooks” -> ON
– Feature-“Incoming Webhooks” -> “Add New Webhook to Workspace”
-> 채널선택 -> 허용
이미지 생략
-> URL 생성
Webhook URL :
-> 해당 앱 채널에 초대해야하나… 자동으로 초대됨.(update)

- Grafana의 Alert -> Contact Point 생성
Home -> Alerting -> Contact Point -> Add contact point

– Recipient : 채널명.
– Token 또는 Webhook URL 사용가능. 테스트시 Webhook URL만 정상작동.
– test 메시지 결과

- Grafana Alert rules 생성
– rule로 지정한 조건 충족시 지정한 contact point를 통해 메시지를 전달.
- Grafana 알람 설정. Alert rules 생성 – Contact Points 수정(1-3과정) – Notification Policies 생성
- Home -> Alerting -> Alert rules -> +Create alert rule
참조 : https://cleaning-toolbox.tistory.com/94
(1) Set an alert rule name : 임의지정
(2) Set a query and alert condition ; alert 발생시킬 컨디션 정의
A는 Query, B/C는 expression 하단에 각각 추가 버튼 있음.
A ; 값이 나오는 쿼리문 -> 주로 Dashboard에서 가져오고 싶은 값 패널에서 explorer로 Query 문을 보고 참조. 직접작성 또는 editor으로 작성가능.
ex> uptime를 숫자(초)로 추출하는 쿼리문
sum(time() – node_boot_time_seconds{origin_prometheus=~””,job=~”node_exporter”})by(instance)
B ; A에서 나온 값을 어떻게 가공할 것인지에 대한 정의
min,max.mean(avr),sum,count 등 제공 “make this the alert condition” 버튼으로 결과 확인 가능.
“A에서 Last 값을 Strict하게 불러옴.”
C ; B에서 가공된 값에 대한 조건
“”threshold” 600이하로 정의.”
Preview 버튼을 통해 테스트 가능.

(3) Alert evaluation behavior
장애를 평가하기 위한 조건 ;
Folder; 같은 평가조건 rule 분류를 위한 폴더.
Evaluation Group ; 같은 체크주기를 정의하는 그룹. 처음에 하나도 없으나 작성해 놓으면 다른 alert rule 작성시 사용가능.
“2분에 1번씩, 6분동안 확인, 데이터가 없을시 Error로 처리.”

-> 즉 alert rule에 해당되는 조건이 될시 6분동안 확인하고 8분째 체크시 경고 발송하게 됨.
(4) Add details for your alert rule ; rule에 대한 설명 및 에러코드 등 세부정보 정의가능.
(5) Notifications
; notification policies에서 alert발생시 누구에게, 어떤 contact point로 알림할지 정하기 위한 labels을 정의.
여기에 정의된 labels을 notification policies에 정의

- Home -> Alerting -> Notification policies
Default policy 아래 “+New nested policy” 클릭하여 생성

Label = Value
Contact Point 정의

**firing 상태로 들어와야 메시지 전송.
이 부분은 Evaluation Group 설정 2분마다 1번씩 6분동안 확인해서 계속 alert rule에 걸리면 firing되어 알람이 전송됨.
