Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
check_cron_file: Don't crash on missing cron file.
Alex Vandiver41b7ae4e4465
diff --git a/puppet/zulip/files/nagios_plugins/zulip_app_frontend/check_cron_file b/puppet/zulip/files/nagios_plugins/zulip_app_frontend/check_cron_fileindex 920f2054dba..1d8120e8e4f 100755--- a/puppet/zulip/files/nagios_plugins/zulip_app_frontend/check_cron_file+++ b/puppet/zulip/files/nagios_plugins/zulip_app_frontend/check_cron_file@@ -16,26 +16,32 @@ def nagios_from_file(results_file: str, max_time_diff: int = 60 * 2) -> "Tuple[iThis file is created by various nagios checking cron jobs such ascheck-rabbitmq-queues and check-rabbitmq-consumers"""- with open(results_file) as f:- data = f.read().strip()- pieces = data.split("|")-- if not len(pieces) == 4:+ try:+ with open(results_file) as f:+ data = f.read().strip()+ except FileNotFoundError:state = "UNKNOWN"ret = 3- data = "Results file malformed"+ data = "Results file is missing"else:- timestamp = int(pieces[0])+ pieces = data.split("|")- time_diff = int(time.time() - timestamp)- if time_diff > max_time_diff:- ret = 3+ if not len(pieces) == 4:state = "UNKNOWN"- data = "Results file is stale"+ ret = 3+ data = "Results file malformed"else:- ret = int(pieces[1])- state = pieces[2]- data = pieces[3]+ timestamp = int(pieces[0])++ time_diff = int(time.time() - timestamp)+ if time_diff > max_time_diff:+ ret = 3+ state = "UNKNOWN"+ data = "Results file is stale"+ else:+ ret = int(pieces[1])+ state = pieces[2]+ data = pieces[3]return (ret, f"{state}: {data}")