Merge remote-tracking branch 'origin/master' into staging
[mirror/dsa-puppet.git] / modules / roles / files / mirror_health / mirror-health
index c3606de..bbd4c27 100755 (executable)
@@ -21,7 +21,8 @@ def retrieve_from_host(host, url):
         'http': 'http://{}:80'.format(host),
         'https': 'http://{}:443'.format(host),
     }
-    return requests.get(url, timeout=5, proxies=proxies, allow_redirects=False)
+    headers = {'User-Agent': 'mirror-health'}
+    return requests.get(url, headers=headers, timeout=5, proxies=proxies, allow_redirects=False)
 
 def last_modified(response):
     lm = 0
@@ -48,11 +49,11 @@ def check_uptodate():
             logging.debug("lm for host %s: %s", host, lm)
             if healthy(retrieve_from_host(host, HEALTH_CHECK_URL)):
                 latest_ts = max(latest_ts, lm)
-        except (requests.exceptions.ProxyError, requests.exceptions.ReadTimeout, requests.exceptions.ConnectTimeout):
+        except (requests.exceptions.ProxyError, requests.exceptions.ReadTimeout, requests.exceptions.ConnectTimeout, requests.exceptions.ConnectionError):
             pass
     try:
         local_lm = last_modified(retrieve_from_host('localhost', URL))
-    except (requests.exceptions.ProxyError, requests.exceptions.ReadTimeout, requests.exceptions.ConnectTimeout):
+    except (requests.exceptions.ProxyError, requests.exceptions.ReadTimeout, requests.exceptions.ConnectTimeout, requests.exceptions.ConnectionError):
         return False
     logging.debug("lm for localhost: %s", local_lm)
     if local_lm < latest_ts: