From 798ee6bcd208b5a651ef1fcd179be2502df42cba Mon Sep 17 00:00:00 2001 From: Cyberes Date: Sat, 9 Mar 2024 17:06:13 -0700 Subject: [PATCH] print execd withen error happens --- check_systemd_timer.py | 57 +++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/check_systemd_timer.py b/check_systemd_timer.py index 1b4c5a6..4be25d6 100755 --- a/check_systemd_timer.py +++ b/check_systemd_timer.py @@ -26,36 +26,41 @@ def get_next_elapse(timer_name): lines = output.split('\n') for line in lines: if timer_name in line: - parts = re.search(SYSTEMCTL_TIMERS_RE, line) + try: + parts = re.search(SYSTEMCTL_TIMERS_RE, line) - datetime_object = None - if parts.group(2): - try: - datetime_object = datetime.strptime(parts.group(2), '%a %Y-%m-%d %H:%M:%S %Z') - except ValueError as e: - return None, e + datetime_object = None + if parts.group(2): + try: + datetime_object = datetime.strptime(parts.group(2), '%a %Y-%m-%d %H:%M:%S %Z') + except ValueError as e: + return None, e - time_left = 'n/a' - if parts.group(4): - time_left = parse_systemctl_time_delta(parts.group(4)) - if isinstance(time_left, humanfriendly.InvalidTimespan): - return None, humanfriendly.InvalidTimespan + time_left = 'n/a' + if parts.group(4): + time_left = parse_systemctl_time_delta(parts.group(4)) + if isinstance(time_left, humanfriendly.InvalidTimespan): + return None, humanfriendly.InvalidTimespan - time_passed = 'n/a' - if parts.group(9): - time_passed = parse_systemctl_time_delta(parts.group(9)) - if isinstance(time_passed, humanfriendly.InvalidTimespan): - return None, humanfriendly.InvalidTimespan + time_passed = 'n/a' + if parts.group(9): + time_passed = parse_systemctl_time_delta(parts.group(9)) + if isinstance(time_passed, humanfriendly.InvalidTimespan): + return None, humanfriendly.InvalidTimespan - timer_info = { - 'next': datetime_object, - 'left': time_left, - 'last': parts.group(7), - 'passed': time_passed, - 'unit': parts.group(10), - 'activates': parts.group(12) - } - return timer_info, None + timer_info = { + 'next': datetime_object, + 'left': time_left, + 'last': parts.group(7), + 'passed': time_passed, + 'unit': parts.group(10), + 'activates': parts.group(12) + } + return timer_info, None + except Exception: + print(output) + traceback.print_exc() + sys.exit(nagios.STATE_UNKNOWN) return None, ValueError('Timer not found') except subprocess.CalledProcessError as e: return None, e