Commit 7f38484d authored by Jonathan Michalon's avatar Jonathan Michalon

Move usr1_handler's print code outside, in a new create_report helper

parent d8598c06
...@@ -7,22 +7,29 @@ from lib import config ...@@ -7,22 +7,29 @@ from lib import config
from lib import mails from lib import mails
def usr1_handler(signum, frame): def create_report():
print ("""Signal SIGUSR1 caught, printing state of checks. has_error = False
report = ''
Checks in error:""") report += "\n Checks in error:\n"
for check in config.checks: for check in config.checks:
if not check.ok: if not check.ok:
print ('-+' * 40) has_error = True
print ("Check %s is in error state:\n\t%s" % (check, report += '-+' * 40 + '\n'
check.errmsg.strip())) report += "%s: %s\n\t%s\n" % (check.target_name, check,
print ('-+' * 40, """ check.errmsg.strip())
report += '-+' * 40 + "\n\n Other checks (usually OK but may be in retry mode):\n"
Other checks (usually OK but may be in retry mode):""")
for check in config.checks: for check in config.checks:
if check.ok: if check.ok:
print ("Check %s is %s" % (check, report += "Check %s is %s\n" % (check,
"OK" if check.retry_count == 0 else "retrying")) "OK" if check.retry_count == 0 else "retrying")
return (report, has_error)
def usr1_handler(signum, frame):
(report, err) = create_report()
print ("Signal SIGUSR1 caught, printing state of checks.")
print (report)
if __name__ == '__main__': if __name__ == '__main__':
......
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