print execd withen error happens

This commit is contained in:
Cyberes 2024-03-09 17:06:13 -07:00
parent b528868249
commit 798ee6bcd2
1 changed files with 31 additions and 26 deletions

View File

@ -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