Commit fd02826b authored by Jonathan Michalon's avatar Jonathan Michalon

Implement retries and be able to run checks only every N * base_tick seconds

parent d3cb5721
......@@ -13,8 +13,8 @@ recursif = Host(ipv4='89.234.141.66', ipv6='2a00:5881:8100:1000::3')
checks = Checks()
checks.add(CheckDNSZone, ["arn-fai.net", "netlib.re"], ip_version=4)
checks.add(CheckPing4, [mail, web])
checks.add(CheckPing6, [mail, web])
checks.add(CheckPing4, [mail, web], retry=2)
checks.add(CheckPing6, [mail, web], retry=2)
checks.add(CheckDNSRec4, [recursif])
checks.add(CheckDNSRec6, [recursif])
# checks.add(CheckSMTP4, [mail, alsace])
......
......@@ -25,15 +25,20 @@ class Checks(list):
class Check(object):
def __init__(self, **options):
self._options = options
self.errmsg = ''
self.ok = True
self._options = options
self.retry = options.get('retry', 0)
self.retry_count = 0
self.every = options.get('every', 1)
self.every_count = 0
self.errmsg = ''
self.ok = True
def __repr__(self):
return '<%s options=%s>' % (self.__class__.__name__, self._options)
def setup(self):
pass
self.every_count += 1
return self.every_count == self.every
def teardown(self):
pass
......@@ -41,10 +46,19 @@ class Check(object):
def check(self, host, addr):
pass
def run(self):
self.setup()
self.ok = self.check()
self.teardown()
def run(self, immediate=False):
run = self.setup()
if run or immediate:
passed = self.check()
self.teardown()
if not passed:
self.retry_count += 1
if self.retry_count > self.retry or immediate:
self.ok = False
else:
self.ok = True
self.retry_count = 0
self.every_count = 0
return self.ok
def exec_with_timeout(self, command, timeout=2, pattern=''):
......
......@@ -38,7 +38,7 @@ if __name__ == '__main__':
# do the actual polling
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
def runner(check):
return check.run(), check
return check.run(immediate=True), check
if args.one:
futures = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment