Skip to content

Commit b71c2ee

Browse files
sven-ruessNotANormalNerd
authored andcommitted
18171 FIX suseconnect: don't crash when no subscription status is available
When using the suseconnect plugin, a situation could arise where subscription status is not available. This werk implements a more graceful approach and avoids crashes when no subscription status is abailable. Signed-off-by: Sven Rueß <github@sven-ruess.de> Closes: #823 Change-Id: I0a0bc8e6f6de4b0fc95a0ee45d74c900c94e7d0b
1 parent 973a46c commit b71c2ee

File tree

2 files changed

+57
-34
lines changed

2 files changed

+57
-34
lines changed

.werks/18171.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[//]: # (werk v2)
2+
# suseconnect: don't crash when no subscription status is available
3+
4+
key | value
5+
---------- | ---
6+
date | 2025-07-15T15:25:26+00:00
7+
version | 2.3.0p35
8+
class | fix
9+
edition | cre
10+
component | checks
11+
level | 1
12+
compatible | yes
13+
14+
When using the suseconnect plugin, a situation could arise where subscription status is not available.
15+
This werk implements a more graceful approach and avoids crashes when no subscription status is available.

cmk/base/legacy_checks/suseconnect.py

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -68,49 +68,57 @@ def check_suseconnect(_no_item, params, section: Section):
6868
if (specs := get_data(section)) is None:
6969
return
7070

71-
state, infotext = 0, "Status: %(registration_status)s" % specs
72-
if params["status"] != "Ignore" and params["status"] != specs["registration_status"]:
73-
state = 2
74-
yield state, infotext
71+
if "registration_status" in specs:
72+
state, infotext = 0, "Status: %s" % specs["registration_status"]
73+
if params["status"] != "Ignore" and params["status"] != specs["registration_status"]:
74+
state = 2
75+
yield state, infotext
76+
77+
if "subscription_status" in specs:
78+
state, infotext = 0, "Subscription: %s" % specs["subscription_status"]
79+
if (
80+
params["subscription_status"] != "Ignore"
81+
and params["subscription_status"] != specs["subscription_status"]
82+
):
83+
state = 2
84+
yield state, infotext
7585

76-
state, infotext = 0, "Subscription: %(subscription_status)s" % specs
7786
if (
78-
params["subscription_status"] != "Ignore"
79-
and params["subscription_status"] != specs["subscription_status"]
87+
"subscription_type" in specs
88+
and "registration_code" in specs
89+
and "starts_at" in specs
90+
and "expires_at" in specs
8091
):
81-
state = 2
82-
yield state, infotext
83-
84-
yield (
85-
0,
86-
(
87-
"Subscription type: %(subscription_type)s, Registration code: %(registration_code)s, "
88-
"Starts at: %(starts_at)s, Expires at: %(expires_at)s"
92+
yield (
93+
0,
94+
(
95+
"Subscription type: %(subscription_type)s, Registration code: %(registration_code)s, "
96+
"Starts at: %(starts_at)s, Expires at: %(expires_at)s"
97+
)
98+
% specs,
8999
)
90-
% specs,
91-
)
92100

93-
expiration_date = time.strptime(specs["expires_at"], "%Y-%m-%d %H:%M:%S %Z")
94-
expiration_time = time.mktime(expiration_date) - time.time()
101+
expiration_date = time.strptime(specs["expires_at"], "%Y-%m-%d %H:%M:%S %Z")
102+
expiration_time = time.mktime(expiration_date) - time.time()
95103

96-
if expiration_time > 0:
97-
warn, crit = params["days_left"]
98-
days2seconds = 24 * 60 * 60
104+
if expiration_time > 0:
105+
warn, crit = params["days_left"]
106+
days2seconds = 24 * 60 * 60
99107

100-
if expiration_time <= crit * days2seconds:
101-
state = 2
102-
elif expiration_time <= warn * days2seconds:
103-
state = 1
104-
else:
105-
state = 0
108+
if expiration_time <= crit * days2seconds:
109+
state = 2
110+
elif expiration_time <= warn * days2seconds:
111+
state = 1
112+
else:
113+
state = 0
106114

107-
infotext = "Expires in: %s" % render.timespan(expiration_time)
108-
if state:
109-
infotext += " (warn/crit at %d/%d days)" % (warn, crit)
115+
infotext = "Expires in: %s" % render.timespan(expiration_time)
116+
if state:
117+
infotext += " (warn/crit at %d/%d days)" % (warn, crit)
110118

111-
yield state, infotext
112-
else:
113-
yield 2, "Expired since: %s" % render.timespan(-1.0 * expiration_time)
119+
yield state, infotext
120+
else:
121+
yield 2, "Expired since: %s" % render.timespan(-1.0 * expiration_time)
114122

115123

116124
check_info["suseconnect"] = LegacyCheckDefinition(

0 commit comments

Comments
 (0)