diff options
| author | Tobias Wiese <tobias@tobiaswiese.com> | 2021-02-25 21:45:19 +0100 |
|---|---|---|
| committer | Tobias Wiese <tobias@tobiaswiese.com> | 2021-02-25 21:45:19 +0100 |
| commit | ff5d647e7a398dd09513347628d7a2909639b2f3 (patch) | |
| tree | f1da522e1378f58c3e323188b5d39213eb9ffa20 /check_systemd | |
Initial commit.1.0.0
Provide the basic functionality and an example for integration with
icinga2.
Diffstat (limited to 'check_systemd')
| -rwxr-xr-x | check_systemd | 26 |
1 files changed, 26 insertions, 0 deletions
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 |
