-
Notifications
You must be signed in to change notification settings - Fork 118
/
check_osx_raid.sh
executable file
·89 lines (75 loc) · 1.33 KB
/
check_osx_raid.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
# Nagios Exit Codes
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
usage()
{
cat <<EOF
Check the RAID status for disks on OSX.
Options:
-l List full RAID information
-c Check RAID status
Usage: $0 -c
EOF
}
argcheck() {
# if less than n argument
if [ $ARGC -lt $1 ]; then
echo "Missing arguments! Use \`\`-h'' for help."
exit 1
fi
}
RAID_CHECK=0
ARGC=$#
argcheck 1
while getopts "hlc" OPTION
do
case $OPTION in
h)
usage
;;
c)
RAID_CHECK=1
;;
l)
diskutil appleRAID list
exit $OK
;;
\?)
exit $UNKNOWN
;;
esac
done
if [ $RAID_CHECK -eq 1 ]; then
STATUS_ROW=$(diskutil appleRAID list | awk '/^Status:/ { print $2 }')
DISK=$(diskutil appleRAID list | awk '/disk.*(Fail|ebuild)/ { print $2 }')
STATUS=$(diskutil appleRAID list | grep ^[0-9])
case $STATUS in
*[fF]ailed*)
echo "$DISK Failure: $STATUS_ROW array!"
exit $CRITICAL
;;
*[oO]ffline*)
echo "$DISK Failure: $STATUS_ROW array!"
exit $CRITICAL
;;
*[dD]egraded*)
echo "$DISK Failure: $STATUS_ROW array!"
exit $CRITICAL
;;
*[Rr]ebuilding*)
echo "$DISK Rebuilding: $STATUS_ROW array!"
exit $WARNING
;;
*[oO]nline*)
echo "RAID array is online."
exit $OK
;;
*)
echo "Unknown status for: $STATUS"
exit $UNKNOWN
;;
esac
fi