minor adjustments to check_systemd things

This commit is contained in:
Cyberes 2024-07-18 19:47:16 -06:00
parent 76b1ef24b7
commit cc7044a100
2 changed files with 5 additions and 4 deletions

View File

@ -42,7 +42,7 @@ if [ -z "$UNIT_NAME" ]; then
fi fi
# Check if the unit exists # Check if the unit exists
if ! systemctl list-units --full -all | grep -Fq "\b$UNIT_NAME.service\b"; then if ! systemctl list-units --full -all 2>/dev/null | grep -Pq "\b$UNIT_NAME\b"; then
echo "CRITICAL - $UNIT_NAME does not exist" echo "CRITICAL - $UNIT_NAME does not exist"
exit 2 exit 2
fi fi

View File

@ -17,7 +17,8 @@ sys.path.insert(0, "/usr/lib/python3/dist-packages")
import dbus import dbus
SYSTEMCTL_TIMERS_RE = re.compile( SYSTEMCTL_TIMERS_RE = re.compile(
r'^(([A-Za-z]*\s[0-9]{4}-[0-9]{2}-[0-9]{2}\s*[0-9]{2}:[0-9]{2}:[0-9]{2}\s[A-Z]*)|n\/a|-)\s*((([0-9]*[a-z]*\s)*left)|n\/a|-)\s*(([A-Za-z]*\s[0-9]{4}-[0-9]{2}-[0-9]{2}\s[0-9]{2}:[0-9]{2}:[0-9]{2}\s[A-Z]*)|n\/a|-)\s*(([0-9A-Za-z\s]*\sago)|n\/a|-)\s*([A-Za-z\-_]*.timer)\s*(([A-Za-z\-_]*.service)|\s*)') r'^(([A-Za-z]*\s[0-9]{4}-[0-9]{2}-[0-9]{2}\s*[0-9]{2}:[0-9]{2}:[0-9]{2}\s[A-Z]*)|n\/a|-)\s*((([0-9]*[a-z]*\s)*left)|n\/a|-)\s*(([A-Za-z]*\s[0-9]{4}-[0-9]{2}-[0-9]{2}\s[0-9]{2}:[0-9]{2}:[0-9]{2}\s[A-Z]*)|n\/a|-)\s*(([0-9A-Za-z\s]*\sago)|n\/a|-)\s*([A-Za-z\-_]*.timer)\s*(([A-Za-z\-_]*.service)|\s*)'
)
def get_next_elapse(timer_name): def get_next_elapse(timer_name):
@ -115,9 +116,9 @@ def check_timer(timer_name):
} }
quit_check(f'{timer_name} is active. Trigger time: {next_elapse_str}. Remaining time: {remaining_time_human}. Time since last trigger: {passed_time_human}.', nagios.STATE_OK, perfdata_dict) quit_check(f'{timer_name} is active. Trigger time: {next_elapse_str}. Remaining time: {remaining_time_human}. Time since last trigger: {passed_time_human}.', nagios.STATE_OK, perfdata_dict)
else: else:
quit_check(f'{timer_name} is not active.', nagios.STATE_CRIT) quit_check(f'{timer_name} is not active', nagios.STATE_CRIT)
except dbus.exceptions.DBusException: except dbus.exceptions.DBusException:
quit_check(f'{timer_name} could not be found.', nagios.STATE_CRIT) quit_check(f'{timer_name} does not exist', nagios.STATE_CRIT)
if __name__ == '__main__': if __name__ == '__main__':