-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_zpool.sh
executable file
·63 lines (60 loc) · 1.77 KB
/
check_zpool.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh
# NRPE check for zpool
# Written by: Søren Klintrup <github at klintrup.dk>
# Get your copy from https://github.com/Klintrup/check_zpool
PATH="/sbin:/bin:/usr/sbin:/usr/bin"
unset ERRORSTRING
unset OKSTRING
unset ERR
if [ -x "/sbin/zpool" ]; then
DEVICES="$(zpool list -H -o name)"
else
ERRORSTRING="zpool binary does not exist on system"
ERR=3
fi
for DEVICE in ${DEVICES}; do
DEVICESTRING="$(zpool list -H -o health "${DEVICE}")"
if [ "$(echo "${DEVICESTRING}" | tr '[:upper:]' '[:lower:]' | sed -Ee 's/.*(degraded|faulted|offline|online|removed|unavail).*/\1/')" = "" ]; then
ERRORSTRING="${ERRORSTRING} / ${DEVICE}: unknown state"
if ! [ "${ERR}" = 2 ]; then ERR=3; fi
else
case $(echo "${DEVICESTRING}" | tr '[:upper:]' '[:lower:]' | sed -Ee 's/.*(degraded|faulted|offline|online|removed|unavail).*/\1/') in
degraded)
ERR=2
ERRORSTRING="${ERRORSTRING} / ${DEVICE}: DEGRADED"
;;
faulted)
ERR=2
ERRORSTRING="${ERRORSTRING} / ${DEVICE}: FAULTED"
;;
offline)
ERR=2
ERRORSTRING="${ERRORSTRING} / ${DEVICE}: OFFLINE"
;;
removed)
ERR=2
ERRORSTRING="${ERRORSTRING} / ${DEVICE}: REMOVED"
;;
unavail)
ERR=2
ERRORSTRING="${ERRORSTRING} / ${DEVICE}: UNAVAIL"
;;
online)
OKSTRING="${OKSTRING} / ${DEVICE}: online"
;;
esac
fi
done
if [ "${1}" ]; then
if [ "${ERRORSTRING}" ]; then
echo "${ERRORSTRING} ${OKSTRING}" | sed s/"^\/ "// | mail -s "$(hostname -s): ${0} reports errors" -E "${*}"
fi
else
if [ "${ERRORSTRING}" ] || [ "${OKSTRING}" ]; then
echo "${ERRORSTRING} ${OKSTRING}" | sed -E s/"^[[:blank:]]{1,}\/ "//
exit ${ERR}
else
echo no zpool volumes found
exit 3
fi
fi