serverCheck.py 863 B

123456789101112131415161718192021222324252627
  1. import urllib.request
  2. import json
  3. import requests
  4. def notify_group(msg):
  5. #'WekCRfnAirSiSxALiD6gcm0B56EejsoK89zFbIaiZQD' is ChoozmoTeam
  6. glist=['WekCRfnAirSiSxALiD6gcm0B56EejsoK89zFbIaiZQD']
  7. for gid in glist:
  8. headers = {"Authorization": "Bearer " + gid,"Content-Type": "application/x-www-form-urlencoded"}
  9. r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params={"message": msg})
  10. try:
  11. contents = urllib.request.urlopen("https://www.choozmo.com:8887/checkStatus").read()
  12. status_dict = json.loads(contents.decode('utf-8'))
  13. if len(status_dict['errors'])==0:
  14. print('Everything works fine')
  15. else:
  16. for msg in status_dict['errors']:
  17. notify_group('ERROR : '+msg+' down')
  18. except:
  19. err_msg = 'ERROR : 8887 status api down'
  20. print(err_msg)
  21. notify_group(err_msg)