Skip to content

Instantly share code, notes, and snippets.

@DaffyDuke
Created March 7, 2017 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaffyDuke/ae3e9bd90c05cd49c6f5bacde2ed2839 to your computer and use it in GitHub Desktop.
Save DaffyDuke/ae3e9bd90c05cd49c6f5bacde2ed2839 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
if [ -f /bin/systemctl ]; then
failed=$(/bin/systemctl --failed --no-legend)
failed=${failed/ */} # Strip everything after first space
failed=${failed/.service/} # Strip .service suffix if [ "$failed" != "" ]; then
echo "Failed units: $failed"
exit 1
else
echo "No failed units."
exit 0
fi
else
echo "No systemd. Nothing was checked!"
exit 0
fi
@jazzl0ver
Copy link

jazzl0ver commented Feb 7, 2023

there's an error in line 6. a little bit improved version: https://gist.github.com/jazzl0ver/0d69d487d6c3deab5cebcb1595acb02c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment