From 39070dc595132ef9e1172b1857b90fb1899c4779 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Fri, 10 Feb 2023 13:46:01 +0100 Subject: [PATCH] copr-fe: catch exceptions while checking uptime robot --- .../frontend/templates/copr-cdn-check.py.j2 | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/roles/copr/frontend/templates/copr-cdn-check.py.j2 b/roles/copr/frontend/templates/copr-cdn-check.py.j2 index 55ee1dc4e5..2ff1a7d749 100644 --- a/roles/copr/frontend/templates/copr-cdn-check.py.j2 +++ b/roles/copr/frontend/templates/copr-cdn-check.py.j2 @@ -1,8 +1,40 @@ #! /usr/bin/python3 +""" +Ask UptimeRobot service how the CDN works. + +The API output looks like: + +{ + "stat": "ok", + "pagination": { + "offset": 0, + "limit": 50, + "total": 1 + }, + "monitors": [ + { + "id": 788475080, + "friendly_name": "Copr's CDN", + "url": "https://download.copr.fedorainfracloud.org/", + "type": 1, + "sub_type": "", + "keyword_type": null, + "keyword_case_type": 0, + "keyword_value": "", + "port": "", + "interval": 600, + "timeout": 30, + "status": 2, + "create_datetime": 1624272619 + } + ] +} +""" + +import logging import sys import requests -import logging # NAGIOS exit codes NAG_UNKNOWN = 3 @@ -93,5 +125,9 @@ def main(): if __name__ == "__main__": - main() + try: + main() + except Exception as exc: + LOG.exception("some exception occured: %s", exc) + sys.exit(NAG_UNKNOWN)