aboutsummaryrefslogtreecommitdiffstats
path: root/roles/nagios_client/files/usr/lib64/nagios/plugins/check_systemd
blob: c7d83de232ffbae012d0791043f1ad303b54f2ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash

set -Eeu -o pipefail

trap 'exit 3' ERR

failed_units=$(systemctl --state failed --no-legend --plain | cut -d' ' -f1)

if [ -n "$failed_units" ]; then
  echo "CRIT - failed units: ${failed_units// /, }"

  for unit in $failed_units; do
    sudo systemctl status -- "$unit" ||:
  done

  exit 2
else
  echo 'OK - all units healthy'
  exit 0
fi