Created
July 2, 2020 12:27
-
-
Save mjrider/0c086d48dc36f0c2941d00f517b8d10b to your computer and use it in GitHub Desktop.
check diskspace availability of zfs with nrpe
This file contains hidden or 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
#!/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