@@ -235,12 +235,15 @@ def thread_machine_content(machine, machine_content, idx):
235235 # machine = passed in machine information
236236 # content = place to write the content
237237
238+ app .logger .debug ("Machine Information" )
239+ app .logger .debug (str (machine ))
240+
238241 url = headscale .get_url ()
239242 api_key = headscale .get_api_key ()
240243
241244 # 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 ())
244247
245248 # Get the machines routes
246249 pulled_routes = headscale .get_machine_routes (url , api_key , machine ["id" ])
@@ -335,20 +338,27 @@ def thread_machine_content(machine, machine_content, idx):
335338 created_print = helper .pretty_print_duration (created_delta )
336339 created_time = str (created_local .strftime ('%A %m/%d/%Y, %H:%M:%S' ))+ " " + str (timezone )+ " (" + str (created_print )+ ")"
337340
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 :
344357 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+
350361
351- expiring_soon = True if int (expiry_delta .days ) < 14 and int (expiry_delta .days ) > 0 else False
352362 # Get the first 10 characters of the PreAuth Key:
353363 if machine ["preAuthKey" ]:
354364 preauth_key = str (machine ["preAuthKey" ]["key" ])[0 :10 ]
0 commit comments