From 88fe4a5c02a457ebbc56af459a21422df30fb29f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sven=20Rue=C3=9F?= Date: Mon, 2 Jun 2025 21:24:01 +0200 Subject: [PATCH 1/2] Fixed SuSE connect check File "/omd/sites/nagios/share/check_mk/checks/suseconnect", line 77, in check_suseconnect state, infotext = 0, "Subscription: %(subscription_status)s" % specs KeyError: subscription_status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sven Rueß --- cmk/base/legacy_checks/suseconnect.py | 77 ++++++++++++++------------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/cmk/base/legacy_checks/suseconnect.py b/cmk/base/legacy_checks/suseconnect.py index 77ee234ee55..890905f5bff 100644 --- a/cmk/base/legacy_checks/suseconnect.py +++ b/cmk/base/legacy_checks/suseconnect.py @@ -69,49 +69,52 @@ def check_suseconnect( if (specs := get_data(section)) is None: return - state, infotext = 0, "Status: %(registration_status)s" % specs - if params["status"] != "Ignore" and params["status"] != specs["registration_status"]: - state = 2 - yield state, infotext - - state, infotext = 0, "Subscription: %(subscription_status)s" % specs - if ( - params["subscription_status"] != "Ignore" - and params["subscription_status"] != specs["subscription_status"] - ): - state = 2 - yield state, infotext - - yield ( - 0, - ( - "Subscription type: %(subscription_type)s, Registration code: %(registration_code)s, " - "Starts at: %(starts_at)s, Expires at: %(expires_at)s" + if "registration_status" in specs: + state, infotext = 0, "Status: %s" % specs["registration_status"] + if params["status"] != "Ignore" and params["status"] != specs["registration_status"]: + state = 2 + yield state, infotext + + if "subscription_status" in specs: + state, infotext = 0, "Subscription: %s" % specs["subscription_status"] + if ( + params["subscription_status"] != "Ignore" + and params["subscription_status"] != specs["subscription_status"] + ): + state = 2 + yield state, infotext + + if "subscription_type" in specs and "registration_code" in specs and "starts_at" in specs and "expires_at" in specs: + yield ( + 0, + ( + "Subscription type: %(subscription_type)s, Registration code: %(registration_code)s, " + "Starts at: %(starts_at)s, Expires at: %(expires_at)s" + ) + % specs, ) - % specs, - ) - expiration_date = time.strptime(specs["expires_at"], "%Y-%m-%d %H:%M:%S %Z") - expiration_time = time.mktime(expiration_date) - time.time() + expiration_date = time.strptime(specs["expires_at"], "%Y-%m-%d %H:%M:%S %Z") + expiration_time = time.mktime(expiration_date) - time.time() - if expiration_time > 0: - warn, crit = params["days_left"] - days2seconds = 24 * 60 * 60 + if expiration_time > 0: + warn, crit = params["days_left"] + days2seconds = 24 * 60 * 60 - if expiration_time <= crit * days2seconds: - state = 2 - elif expiration_time <= warn * days2seconds: - state = 1 - else: - state = 0 + if expiration_time <= crit * days2seconds: + state = 2 + elif expiration_time <= warn * days2seconds: + state = 1 + else: + state = 0 - infotext = "Expires in: %s" % render.timespan(expiration_time) - if state: - infotext += " (warn/crit at %d/%d days)" % (warn, crit) + infotext = "Expires in: %s" % render.timespan(expiration_time) + if state: + infotext += " (warn/crit at %d/%d days)" % (warn, crit) - yield state, infotext - else: - yield 2, "Expired since: %s" % render.timespan(-1.0 * expiration_time) + yield state, infotext + else: + yield 2, "Expired since: %s" % render.timespan(-1.0 * expiration_time) check_info["suseconnect"] = LegacyCheckDefinition( From 727e674ac26c18fe701fe35a212ffb9e5cd4835d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sven=20Rue=C3=9F?= Date: Mon, 2 Jun 2025 21:40:29 +0200 Subject: [PATCH 2/2] Fix Python formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sven Rueß --- cmk/base/legacy_checks/suseconnect.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmk/base/legacy_checks/suseconnect.py b/cmk/base/legacy_checks/suseconnect.py index 890905f5bff..532fd003a90 100644 --- a/cmk/base/legacy_checks/suseconnect.py +++ b/cmk/base/legacy_checks/suseconnect.py @@ -84,7 +84,12 @@ def check_suseconnect( state = 2 yield state, infotext - if "subscription_type" in specs and "registration_code" in specs and "starts_at" in specs and "expires_at" in specs: + if ( + "subscription_type" in specs + and "registration_code" in specs + and "starts_at" in specs + and "expires_at" in specs + ): yield ( 0, (