Skip to content

Fix SuSE connect service, if data is missing (Branch 2.3.0) #823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 2.3.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 42 additions & 34 deletions cmk/base/legacy_checks/suseconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,49 +68,57 @@ def check_suseconnect(_no_item, params, section: Section):
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
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

state, infotext = 0, "Subscription: %(subscription_status)s" % specs
if (
params["subscription_status"] != "Ignore"
and params["subscription_status"] != specs["subscription_status"]
"subscription_type" in specs
and "registration_code" in specs
and "starts_at" in specs
and "expires_at" in specs
):
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"
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(
Expand Down