@@ -161,11 +161,13 @@ def health_check():
161
161
last_seen_local = last_seen .astimezone (tz )
162
162
expires = None
163
163
key_healthy = True if device .get ("keyExpiryDisabled" , False ) else True
164
+ key_days_to_expire = None
164
165
if not device .get ("keyExpiryDisabled" , False ) and device .get ("expires" ):
165
166
expires = datetime .strptime (device ["expires" ], "%Y-%m-%dT%H:%M:%SZ" ).replace (tzinfo = pytz .UTC )
166
167
expires = expires .astimezone (tz )
167
168
time_until_expiry = expires - datetime .now (tz )
168
169
key_healthy = time_until_expiry .total_seconds () / 60 > KEY_THRESHOLD_MINUTES
170
+ key_days_to_expire = time_until_expiry .days
169
171
170
172
online_is_healthy = last_seen_local >= threshold_time
171
173
is_healthy = online_is_healthy and key_healthy
@@ -196,6 +198,7 @@ def health_check():
196
198
"online_healthy" : online_is_healthy ,
197
199
"keyExpiryDisabled" : device .get ("keyExpiryDisabled" , False ),
198
200
"key_healthy" : key_healthy ,
201
+ "key_days_to_expire" : key_days_to_expire ,
199
202
"healthy" : is_healthy
200
203
}
201
204
@@ -277,11 +280,13 @@ def health_check_by_identifier(identifier):
277
280
last_seen_local = last_seen .astimezone (tz ) # Convert lastSeen to the specified timezone
278
281
expires = None
279
282
key_healthy = True if device .get ("keyExpiryDisabled" , False ) else True
283
+ key_days_to_expire = None
280
284
if not device .get ("keyExpiryDisabled" , False ) and device .get ("expires" ):
281
285
expires = datetime .strptime (device ["expires" ], "%Y-%m-%dT%H:%M:%SZ" ).replace (tzinfo = pytz .UTC )
282
286
expires = expires .astimezone (tz )
283
287
time_until_expiry = expires - datetime .now (tz )
284
288
key_healthy = time_until_expiry .total_seconds () / 60 > KEY_THRESHOLD_MINUTES
289
+ key_days_to_expire = time_until_expiry .days
285
290
286
291
logging .debug (f"Device { device ['name' ]} last seen (local): { last_seen_local .isoformat ()} " )
287
292
online_is_healthy = last_seen_local >= threshold_time
@@ -304,6 +309,7 @@ def health_check_by_identifier(identifier):
304
309
"online_healthy" : online_is_healthy ,
305
310
"keyExpiryDisabled" : device .get ("keyExpiryDisabled" , False ),
306
311
"key_healthy" : key_healthy ,
312
+ "key_days_to_expire" : key_days_to_expire ,
307
313
"healthy" : online_is_healthy and key_healthy
308
314
}
309
315
@@ -373,11 +379,13 @@ def health_check_unhealthy():
373
379
last_seen_local = last_seen .astimezone (tz ) # Convert lastSeen to the specified timezone
374
380
expires = None
375
381
key_healthy = True if device .get ("keyExpiryDisabled" , False ) else True
382
+ key_days_to_expire = None
376
383
if not device .get ("keyExpiryDisabled" , False ) and device .get ("expires" ):
377
384
expires = datetime .strptime (device ["expires" ], "%Y-%m-%dT%H:%M:%SZ" ).replace (tzinfo = pytz .UTC )
378
385
expires = expires .astimezone (tz )
379
386
time_until_expiry = expires - datetime .now (tz )
380
387
key_healthy = time_until_expiry .total_seconds () / 60 > KEY_THRESHOLD_MINUTES
388
+ key_days_to_expire = time_until_expiry .days
381
389
382
390
logging .debug (f"Device { device ['name' ]} last seen (local): { last_seen_local .isoformat ()} " )
383
391
online_is_healthy = last_seen_local >= threshold_time
@@ -405,6 +413,7 @@ def health_check_unhealthy():
405
413
"online_healthy" : online_is_healthy ,
406
414
"keyExpiryDisabled" : device .get ("keyExpiryDisabled" , False ),
407
415
"key_healthy" : key_healthy ,
416
+ "key_days_to_expire" : key_days_to_expire ,
408
417
"healthy" : online_is_healthy and key_healthy
409
418
}
410
419
@@ -472,11 +481,13 @@ def health_check_healthy():
472
481
last_seen_local = last_seen .astimezone (tz ) # Convert lastSeen to the specified timezone
473
482
expires = None
474
483
key_healthy = True if device .get ("keyExpiryDisabled" , False ) else True
484
+ key_days_to_expire = None
475
485
if not device .get ("keyExpiryDisabled" , False ) and device .get ("expires" ):
476
486
expires = datetime .strptime (device ["expires" ], "%Y-%m-%dT%H:%M:%SZ" ).replace (tzinfo = pytz .UTC )
477
487
expires = expires .astimezone (tz )
478
488
time_until_expiry = expires - datetime .now (tz )
479
489
key_healthy = time_until_expiry .total_seconds () / 60 > KEY_THRESHOLD_MINUTES
490
+ key_days_to_expire = time_until_expiry .days
480
491
481
492
logging .debug (f"Device { device ['name' ]} last seen (local): { last_seen_local .isoformat ()} " )
482
493
online_is_healthy = last_seen_local >= threshold_time
@@ -498,6 +509,7 @@ def health_check_healthy():
498
509
"online_healthy" : online_is_healthy ,
499
510
"keyExpiryDisabled" : device .get ("keyExpiryDisabled" , False ),
500
511
"key_healthy" : key_healthy ,
512
+ "key_days_to_expire" : key_days_to_expire ,
501
513
"healthy" : online_is_healthy and key_healthy
502
514
}
503
515
0 commit comments