From a9c52394e7d42cc5a696bd79b3fd7e0f3649d520 Mon Sep 17 00:00:00 2001 From: Cyberes Date: Mon, 4 Mar 2024 10:04:16 -0700 Subject: [PATCH] check_systemd_timer: detect when timer has triggered --- check_systemd_timer.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/check_systemd_timer.py b/check_systemd_timer.py index 149b947..e475a59 100755 --- a/check_systemd_timer.py +++ b/check_systemd_timer.py @@ -35,11 +35,12 @@ def check_timer(timer_name): local_timezone_offset = timedelta(seconds=local_timezone_offset_seconds) local_datetime = datetime.utcfromtimestamp(int(next_elapse) / 1e6) + local_timezone_offset next_elapse_str = local_datetime.strftime("%m-%d-%Y %H:%M") - except Exception as e: - print(f'UNKNOWN - exception "{e}"') - print('next_elapse:', next_elapse) - traceback.print_exc() - sys.exit(nagios.STATE_UNKNOWN) + except ValueError as e: + if 'is out of range' in repr(e): + # This occurs whenever the timer resets. + # "year 586524 is out of range" + print(f'OK - {timer_name} has triggered.') + sys.exit(nagios.STATE_OK) current_time = time.time() * 1e6 # convert current time to microseconds remaining_time_sec = int((next_elapse - current_time) / 1e6) # convert remaining time to seconds