check_systemd_timer: detect when timer has triggered

This commit is contained in:
Cyberes 2024-03-04 10:04:16 -07:00
parent caec638872
commit a9c52394e7
1 changed files with 6 additions and 5 deletions

View File

@ -35,11 +35,12 @@ def check_timer(timer_name):
local_timezone_offset = timedelta(seconds=local_timezone_offset_seconds) local_timezone_offset = timedelta(seconds=local_timezone_offset_seconds)
local_datetime = datetime.utcfromtimestamp(int(next_elapse) / 1e6) + local_timezone_offset local_datetime = datetime.utcfromtimestamp(int(next_elapse) / 1e6) + local_timezone_offset
next_elapse_str = local_datetime.strftime("%m-%d-%Y %H:%M") next_elapse_str = local_datetime.strftime("%m-%d-%Y %H:%M")
except Exception as e: except ValueError as e:
print(f'UNKNOWN - exception "{e}"') if 'is out of range' in repr(e):
print('next_elapse:', next_elapse) # This occurs whenever the timer resets.
traceback.print_exc() # "year 586524 is out of range"
sys.exit(nagios.STATE_UNKNOWN) print(f'OK - {timer_name} has triggered.')
sys.exit(nagios.STATE_OK)
current_time = time.time() * 1e6 # convert current time to microseconds current_time = time.time() * 1e6 # convert current time to microseconds
remaining_time_sec = int((next_elapse - current_time) / 1e6) # convert remaining time to seconds remaining_time_sec = int((next_elapse - current_time) / 1e6) # convert remaining time to seconds