@@ -235,12 +235,15 @@ def thread_machine_content(machine, machine_content, idx):
235
235
# machine = passed in machine information
236
236
# content = place to write the content
237
237
238
+ app .logger .debug ("Machine Information" )
239
+ app .logger .debug (str (machine ))
240
+
238
241
url = headscale .get_url ()
239
242
api_key = headscale .get_api_key ()
240
243
241
244
# Set the current timezone and local time
242
- timezone = pytz .timezone (os .environ ["TZ" ] if os .environ ["TZ" ] else "UTC" )
243
- local_time = timezone .localize (datetime .now ())
245
+ timezone = pytz .timezone (os .environ ["TZ" ] if os .environ ["TZ" ] else "UTC" )
246
+ local_time = timezone .localize (datetime .now ())
244
247
245
248
# Get the machines routes
246
249
pulled_routes = headscale .get_machine_routes (url , api_key , machine ["id" ])
@@ -335,20 +338,27 @@ def thread_machine_content(machine, machine_content, idx):
335
338
created_print = helper .pretty_print_duration (created_delta )
336
339
created_time = str (created_local .strftime ('%A %m/%d/%Y, %H:%M:%S' ))+ " " + str (timezone )+ " (" + str (created_print )+ ")"
337
340
338
- expiry_parse = parser .parse (machine ["expiry" ])
339
- expiry_local = expiry_parse .astimezone (timezone )
340
- expiry_delta = expiry_local - local_time
341
- expiry_print = helper .pretty_print_duration (expiry_delta , "expiry" )
342
-
343
- if str (expiry_local .strftime ('%Y' )) in ("0001" , "9999" , "0000" ):
341
+ # If there is no expiration date, we don't need to do any calculations:
342
+ if machine ["expiry" ] != "0001-01-01T00:00:00Z" :
343
+ expiry_parse = parser .parse (machine ["expiry" ])
344
+ expiry_local = expiry_parse .astimezone (timezone )
345
+ expiry_delta = expiry_local - local_time
346
+ expiry_print = helper .pretty_print_duration (expiry_delta , "expiry" )
347
+ if str (expiry_local .strftime ('%Y' )) in ("0001" , "9999" , "0000" ):
348
+ expiry_time = "No expiration date."
349
+ elif int (expiry_local .strftime ('%Y' )) > int (expiry_local .strftime ('%Y' ))+ 2 :
350
+ expiry_time = str (expiry_local .strftime ('%m/%Y' ))+ " " + str (timezone )+ " (" + str (expiry_print )+ ")"
351
+ else :
352
+ expiry_time = str (expiry_local .strftime ('%A %m/%d/%Y, %H:%M:%S' ))+ " " + str (timezone )+ " (" + str (expiry_print )+ ")"
353
+
354
+ expiring_soon = True if int (expiry_delta .days ) < 14 and int (expiry_delta .days ) > 0 else False
355
+ app .logger .debug ("Machine: " + machine ["name" ]+ " expires: " + str (expiry_local .strftime ('%Y' ))+ " / " + str (expiry_delta .days ))
356
+ else :
344
357
expiry_time = "No expiration date."
345
- elif int (expiry_local .strftime ('%Y' )) > int (expiry_local .strftime ('%Y' ))+ 2 :
346
- expiry_time = str (expiry_local .strftime ('%m/%Y' ))+ " " + str (timezone )+ " (" + str (expiry_print )+ ")"
347
- else :
348
- expiry_time = str (expiry_local .strftime ('%A %m/%d/%Y, %H:%M:%S' ))+ " " + str (timezone )+ " (" + str (expiry_print )+ ")"
349
- app .logger .debug ("Machine: " + machine ["name" ]+ " expires: " + str (expiry_local .strftime ('%Y' ))+ " / " + str (expiry_delta .days ))
358
+ expiring_soon = False
359
+ app .logger .debug ("Machine: " + machine ["name" ]+ " has no expiration date" )
360
+
350
361
351
- expiring_soon = True if int (expiry_delta .days ) < 14 and int (expiry_delta .days ) > 0 else False
352
362
# Get the first 10 characters of the PreAuth Key:
353
363
if machine ["preAuthKey" ]:
354
364
preauth_key = str (machine ["preAuthKey" ]["key" ])[0 :10 ]
0 commit comments