Skip to content

Instantly share code, notes, and snippets.

@mjrider
Created July 2, 2020 12:27
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 mjrider/0c086d48dc36f0c2941d00f517b8d10b to your computer and use it in GitHub Desktop.
Save mjrider/0c086d48dc36f0c2941d00f517b8d10b to your computer and use it in GitHub Desktop.
check diskspace availability of zfs with nrpe
#!/bin/sh
# Nagios plugin return values
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
# do we have what we need
if [ ${#} -lt 1 ] ; then
exit ${STATE_UNKNOWN}
fi
DATASET="${1}"
WARNING="${2:-20}"
CRITICAL="${3:-10}"
# is warning bigger then critical?
if [ ${WARNING} -le ${CRITICAL} ] ; then
echo "Warning[${WARNING}%] must be bigger than Critical[${CRITICAL}%]"
exit ${STATE_UNKNOWN}
fi
#
LINE=$(/sbin/zfs list -oavail,used -t filesystem -pH "${DATASET}")
AVAIL="$(echo "${LINE}" | awk '{print $1}')"
USED="$(echo "${LINE}" | awk '{print $2}')"
TOTAL=$((AVAIL+USED))
FREEPERC=$(bc -l <<EOC
scale=0
${AVAIL}*100/${TOTAL}
EOC
)
if [ "${FREEPERC}" -gt "${WARNING}" ]; then
exit ${STATE_OK}
else
if [ "${FREEPERC}" -gt "${CRITICAL}" ]; then
exit ${STATE_WARNING}
else
exit ${STATE_CRITICAL}
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment