Skip to content

Commit 1d5d9a5

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ß <[email protected]> Closes: #824 Change-Id: I0a0bc8e6f6de4b0fc95a0ee45d74c900c94e7d0b
1 parent 11dd825 commit 1d5d9a5

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.4.0p9
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
@@ -69,49 +69,57 @@ def check_suseconnect(
6969
if (specs := get_data(section)) is None:
7070
return
7171

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

77-
state, infotext = 0, "Subscription: %(subscription_status)s" % specs
7887
if (
79-
params["subscription_status"] != "Ignore"
80-
and params["subscription_status"] != specs["subscription_status"]
88+
"subscription_type" in specs
89+
and "registration_code" in specs
90+
and "starts_at" in specs
91+
and "expires_at" in specs
8192
):
82-
state = 2
83-
yield state, infotext
84-
85-
yield (
86-
0,
87-
(
88-
"Subscription type: %(subscription_type)s, Registration code: %(registration_code)s, "
89-
"Starts at: %(starts_at)s, Expires at: %(expires_at)s"
93+
yield (
94+
0,
95+
(
96+
"Subscription type: %(subscription_type)s, Registration code: %(registration_code)s, "
97+
"Starts at: %(starts_at)s, Expires at: %(expires_at)s"
98+
)
99+
% specs,
90100
)
91-
% specs,
92-
)
93101

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

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

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

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

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

116124

117125
check_info["suseconnect"] = LegacyCheckDefinition(

0 commit comments

Comments
 (0)