-
-
Save fwaggle/ed275525496e83a86818ce80216d7020 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
# Check zpool status - tested on ZFS-on-Linux | |
# James Fraser <fwaggle@fwaggle.org> | |
ZPOOL=$1 | |
ZSTATUS=$(zpool status $ZPOOL) | |
if [ "$?" != "0" ] | |
then | |
echo "CRITICAL" | |
exit 2 | |
fi | |
STATUS='UNKNOWN' | |
ERRORS=$(echo "$ZSTATUS" | grep 'sd[a-z]' | awk 'BEGIN {}; { rd+=$3; wr+=$4; ck+=$5; } END { printf "%s %s %s\n", rd, wr, ck }') | |
STATE=$(echo "$ZSTATUS" | grep 'state:' | awk '{ print $2; }') | |
# Everything is normal. | |
if [ "$STATUS" == "UNKNOWN" -a "$STATE" == 'ONLINE' -a "$ERRORS" == "0 0 0" ] | |
then | |
STATUS='OK' | |
fi | |
if [ "$ERRORS" != "0 0 0" ] | |
then | |
STATUS='WARNING' | |
fi | |
if [ "$STATE" == 'FAULTED' -o "$STATE" == 'DEGRADED' -o "$STATE" == 'UNAVAIL' ] | |
then | |
STATUS='CRITICAL' | |
fi | |
echo "${STATUS} - Zpool is ${STATE}|${ERRORS}" | |
echo "$ZSTATUS" | |
# Set return codes for Nagios/Icinga. | |
if [ "$STATUS" == 'CRITICAL' ]; then exit 2; fi | |
if [ "$STATUS" == 'WARNING' ]; then exit 1; fi | |
if [ "$STATUS" == 'OK' ]; then exit 0; fi | |
exit 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment