# -*- coding: utf-8 -*- """ Uptime check, at the moment HTTPS only domains Usage of own healthchecks.io instance and config file """ from requests import get, post from config import HC_ROOT, CONFIG def check_domain(domain): try: r = get('https://%s' % domain) except Exception as e: return e return r.status_code def ping_with_info(url, fail=False, data=None): try: if fail: url = '%s/fail' % url post(url, timeout=10, data=data) except Exception as e: print("Ping failed: %s" % e) for check_item in CONFIG: print('Checking %s : %s' % (check_item['host'], ', '.join(check_item['domains']))) fail = False data = [] for domain in check_item['domains']: status = check_domain(domain) if not fail and status != 200: fail = True data.append('%s : %s' % (domain, status)) url = '%s/ping/%s' % (HC_ROOT, check_item['uuid']) ping_with_info(url, fail=fail, data='\n'.join(data))