Skip to content

Instantly share code, notes, and snippets.

@jazzl0ver
Last active September 18, 2024 14:59
Show Gist options
  • Save jazzl0ver/0d69d487d6c3deab5cebcb1595acb02c to your computer and use it in GitHub Desktop.
Save jazzl0ver/0d69d487d6c3deab5cebcb1595acb02c to your computer and use it in GitHub Desktop.
Nagios check for systemd failed units
#!/bin/bash
# Source http://lzone.de/blog/Nagios+Check+for+Systemd+Failed+Units
# Nagios return codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
if [ -f /bin/systemctl ]; then
failed=$(/bin/systemctl --failed --no-legend | grep -v masked)
failed=${failed/ */} # Strip everything after first space
failed=${failed/.service/} # Strip .service suffix
if [ "$failed" != "" ]; then
echo "CRITICAL: Failed units - $failed"
exit $STATE_CRITICAL
else
echo "OK: No failed units"
exit $STATE_OK
fi
else
echo "UNKNOWN: No systemd. Nothing was checked"
exit $STATE_UNKNOWN
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment