Commit 0735e600 authored by Jonathan Michalon's avatar Jonathan Michalon

Only report checks that have failed before last report (act as a reminder)

parent 478e2627
...@@ -2,6 +2,7 @@ from .subprocess_compat import TimeoutExpired, Popen, PIPE ...@@ -2,6 +2,7 @@ from .subprocess_compat import TimeoutExpired, Popen, PIPE
import re import re
from . import mails from . import mails
from collections import Iterable from collections import Iterable
from datetime import datetime
class Host(object): class Host(object):
...@@ -61,6 +62,7 @@ class Check(object): ...@@ -61,6 +62,7 @@ class Check(object):
self.retry_count = min(self.retry_count + 1, self.retry) self.retry_count = min(self.retry_count + 1, self.retry)
if self.retry_count == self.retry or immediate: if self.retry_count == self.retry or immediate:
if self.ok: if self.ok:
self.failure_date = datetime.now()
self.ok = False self.ok = False
mails.send_email_for_check(self) mails.send_email_for_check(self)
else: else:
......
...@@ -5,19 +5,23 @@ from time import sleep ...@@ -5,19 +5,23 @@ from time import sleep
import config as user_config import config as user_config
from lib import config from lib import config
from lib import mails from lib import mails
from datetime import datetime, timedelta
def create_report(): def create_report(only_old=False):
has_error = False has_error = False
report = '' report = ''
report += "\n Checks in error:\n" report += "\n Checks in error:\n"
now = datetime.now()
delta = timedelta(seconds=config.emails.report.every)
for check in config.checks: for check in config.checks:
if not check.ok: if not check.ok and (not only_old or now - check.failure_date > delta):
has_error = True has_error = True
report += '-+' * 40 + '\n' report += '-+' * 40 + '\n'
report += "%s: %s\n\t%s\n" % (check.target_name, check, report += "%s: %s\nSince %s\n\t%s\n" % (check.target_name, check,
check.errmsg.strip()) check.failure_date, check.errmsg.strip())
report += '-+' * 40 + "\n\n Other checks (usually OK but may be in retry mode):\n" report += '-+' * 40 + "\n\n"
report += " Other checks (usually OK but may be in retry mode):\n"
for check in config.checks: for check in config.checks:
if check.ok: if check.ok:
report += "Check %s is %s\n" % (check, report += "Check %s is %s\n" % (check,
...@@ -33,8 +37,10 @@ def usr1_handler(signum, frame): ...@@ -33,8 +37,10 @@ def usr1_handler(signum, frame):
def alarm_handler(signum, frame): def alarm_handler(signum, frame):
(report, err) = create_report() (report, err) = create_report(only_old=True)
if err: if err:
report = "Following entries have failed for more than %ss:\n" % \
config.emails.report.every + report
mails.send_email_report(report) mails.send_email_report(report)
......
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