-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPIServiceMailTrigger.py
34 lines (27 loc) · 985 Bytes
/
APIServiceMailTrigger.py
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
32
33
34
#!/usr/bin/python3.8
import json
from socket import timeout
import requests
from mailFn import mail_notification
# Service Specific Health Check
def dockerComposeServiceHealthCheckFn():
# servicename, container_name, url
servicedata = ''
body = []
with open("./apiservicedata.json") as f:
data = json.load(f)
for service in data:
try:
servicedata = data[service]
urlresponse = requests.get(servicedata['url'], timeout=1)
datanew = urlresponse.json()
servicedata['message'] = datanew['message']
servicedata['statusCode'] = datanew['statusCode']
body.append(servicedata)
except:
servicedata['message'] = 'Container is down'
servicedata['statusCode'] = 500
body.append(servicedata)
mail_notification(body)
if __name__ == '__main__':
dockerComposeServiceHealthCheckFn()