Skip to content

Instantly share code, notes, and snippets.

@fwaggle fwaggle/check_zpool.sh Secret
Created Jan 3, 2019

Embed
What would you like to do?
#! /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
You can’t perform that action at this time.