RedPlug's Tory

Jira에서 발송되는 메일큐가 쌓일 경우에 Slack으로 알람이 오도록 설정하는 코드입니다.

마켓 플레이스에 xml로 볼 수 있게끔 만들어진 앱이 있어서 해당 앱을 설치 후 이용하였습니다.

 

Atlassian Marketplace Mail Queue Monitor REST API (Free)

marketplace.atlassian.com/apps/1214195/mail-queue-monitor-rest-api?hosting=server&tab=overview

 

Mail Queue Monitor REST API

Ever had outgoing mail fail unnoticed? Monitor your error queue to detect issues before your users do

marketplace.atlassian.com

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import requests
import xml.etree.ElementTree as ET
 
# 웹훅 URL 주소
webhookurl = "Webhook URL"
 
# jira URL 주소
jiraurl = 'https://jira.redplug.com/rest/mailqueue/1.0/status'
 
# 알람 체크 갯수
notisize = 100 
 
# 웹훅 발송 함수
def send_message_to_slack(text):
   payload = {"text": text}
   requests.post(webhookurl, json=payload)
 
 
# 메일큐 확인
response = requests.get(jiraurl)
status = response.status_code
text = response.text
root = ET.fromstring(response.text)
size = int(root.find('size').text)
errorsize = int(root.find('errorSize').text)
 
# notisize 넘을경우 웹훅 
if size > notisize or errorsize > notisize:
   send_message_to_slack(f'JIRA Mail Queue Check \n Mail Queue Size : {size}개 \nMail Error Queie Size : {errorsize}개')
else:
   pass
 

slack 발송 테스트(notisize -1로 설정 후 실행)