summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'check.py')
-rw-r--r--check.py44
1 files changed, 25 insertions, 19 deletions
diff --git a/check.py b/check.py
index bf76a90..30a548c 100644
--- a/check.py
+++ b/check.py
@@ -1,13 +1,26 @@
#!/usr/bin/python
+import logging
import urllib2
import time
import rfc822
class GardCheck:
# Base class which provides some helper functions
- def __init__(self, url):
+ def __init__(self, url, log=True):
self.url = url
+ if log:
+ self.logger = logging.getLogger('')
+ else:
+ self.logger = None
+
+ def log_info(self, msg):
+ if self.logger is not None:
+ self.logger.info(msg)
+
+ def log_error(self, msg):
+ if self.logger is not None:
+ self.logger.error(msg)
def check_file_exists(self, url):
ret = True
@@ -40,7 +53,7 @@ class GardCheck:
return ts
- def get_lag(self, path, verbose=False):
+ def get_lag(self, path):
ts = self._get_timestamp_from_url(self.url + path)
now = time.mktime(time.gmtime())
if ts is None or now < ts:
@@ -51,7 +64,7 @@ class GardCheck:
mins, secs = divmod(secs, 60)
hours, mins = divmod(mins, 60)
days, hours = divmod(hours, 24)
- return '%02d d %02dh %02d m %02d s' % (days, hours, mins, secs)
+ return '%02dd %02dh %02dm %02ds' % (days, hours, mins, secs)
def timestamp_to_secs(self, ts):
return rfc822.mktime_tz(rfc822.parsedate_tz(ts))
@@ -70,18 +83,15 @@ class DistfilesCheck(GardCheck):
path = '/distfiles/timestamp.chk'
return self.get_lag(path)
- def check(self, maxlag, verbose=False):
- # XXX: Replace 'verbose' with a logger object
-
+ def check(self, maxlag):
lag = self.lag()
if lag is None:
- print 'ERROR: Could not get distfiles timestamp for ' + self.url
+ self.log_error('Could not get distfiles timestamp for ' + self.url)
ret = False
elif lag > maxlag:
- if verbose is True:
- print 'ERROR: distfiles at %s is lagging\n\tdelta is %s' \
- % (self.url, self.humanize_time(lag))
+ self.log_error('Distfiles at %s is lagging (delta is %s)' \
+ % (self.url, self.humanize_time(lag)))
ret = False
else:
ret = True
@@ -94,18 +104,15 @@ class ReleasesCheck(GardCheck):
path = '/releases/.test/timestamp.x'
return self.get_lag(path)
- def check(self, maxlag, verbose=False):
- # Verify that releases aren't lagging
-
+ def check(self, maxlag):
lag = self.lag()
if lag is None:
- print 'ERROR: Could not get releases timestamp for ' + self.url
+ self.log_error('Could not get releases timestamp for ' + self.url)
ret = False
elif lag > maxlag:
- if verbose is True:
- print 'ERROR: releases at %s is lagging\n\tdelta is %s' \
- % (self.url, self.humanize_time(lag))
+ self.log_error('Releases at %s is lagging (delta is %s)' \
+ % (self.url, self.humanize_time(lag)))
ret = False
else:
ret = True
@@ -113,8 +120,7 @@ class ReleasesCheck(GardCheck):
# Verify that releases/.test/THIS-FILE-SHOULD-NOT-BE-PUBLIC.txt
# is not world readable
if self.check_file_exists(self.url+'releases/.test/THIS-FILE-SHOULD-NOT-BE-PUBLIC.txt'):
- if verbose is True:
- print 'ERROR: THIS-FILE-SHOULD-NOT-BE-PUBLIC.txt is visible on %s' % self.url
+ self.log_error('ERROR: releases permission check failed on %s' % self.url)
ret = False
return ret