@@ -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
116124check_info ["suseconnect" ] = LegacyCheckDefinition (
0 commit comments