From cc7044a100669c2002999d4eba3f6db648a49e02 Mon Sep 17 00:00:00 2001 From: Cyberes Date: Thu, 18 Jul 2024 19:47:16 -0600 Subject: [PATCH] minor adjustments to check_systemd things --- check_systemd_service.sh | 2 +- check_systemd_timer.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/check_systemd_service.sh b/check_systemd_service.sh index 28a35fc..d5038e7 100755 --- a/check_systemd_service.sh +++ b/check_systemd_service.sh @@ -42,7 +42,7 @@ if [ -z "$UNIT_NAME" ]; then fi # 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" exit 2 fi diff --git a/check_systemd_timer.py b/check_systemd_timer.py index 8422f4a..21eef74 100755 --- a/check_systemd_timer.py +++ b/check_systemd_timer.py @@ -17,7 +17,8 @@ sys.path.insert(0, "/usr/lib/python3/dist-packages") import dbus 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): @@ -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) 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: - 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__':