From ff5d647e7a398dd09513347628d7a2909639b2f3 Mon Sep 17 00:00:00 2001 From: Tobias Wiese Date: Thu, 25 Feb 2021 21:45:19 +0100 Subject: Initial commit. Provide the basic functionality and an example for integration with icinga2. --- check_systemd | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 check_systemd (limited to 'check_systemd') diff --git a/check_systemd b/check_systemd new file mode 100755 index 0000000..c71682b --- /dev/null +++ b/check_systemd @@ -0,0 +1,26 @@ +#!/bin/sh -e +for line in $(systemctl show -p SystemState,NFailedUnits); do + split_idx="$(printf "%s" "$line" | awk '{print index($0, "=")}')" + property="$(printf "%s" "$line" | awk '{print substr($0, 1, '"$split_idx"' - 1)}')" + value="$(printf "%s" "$line" | awk '{print substr($0, '"$split_idx"' + 1)}')" + + case "$property" in + "SystemState") + SYSTEM_STATE="$value" + ;; + "NFailedUnits") + FAILED_UNITS="$value" + ;; + *) + ;; + esac +done + +if [ -z "$SYSTEM_STATE" ] || [ -z "$FAILED_UNITS" ]; then + echo "$0: failed to get expected data from system." >&2 + exit 3 +fi + +printf "SYSTEM %s: %d units failed.\n" "$SYSTEM_STATE" "$FAILED_UNITS" + +[ "0" = "$FAILED_UNITS" ] || exit 2 -- cgit v1.2.3