51c785ce032b60225763faaaf9d80e2f767b265e
[nagcollect.git] / client / lib / tests / RAID.tst
1 # NagCollect -- Nagios Data Collector for Passive Checks
2 # Copyright (c)2009-2011 Alexander Barton, alex@barton.de
3
4 SERVICE="RAID_p"
5
6 if [ `uname` = "Darwin" ]; then
7         tmp=`mktemp "/tmp/$$.XXXX"`
8         LC_ALL=C diskutil checkRAID >"$tmp" 2>/dev/null
9         if [ $? -eq 0 ]; then
10                 # Apple Software-RAID detected
11                 statusString1=`grep "^Status:" "$tmp" | uniq`
12                 status=`echo $statusString1 | sed -e 's/Status: //g'`
13                 statusString=`grep "^Status:" "$tmp"`
14                 statusText=`echo $statusString | sed -e 's/Status: //g' | sed -e 's/ /, /g'`
15                 if [ "$status" != "Online" ]; then
16                         STATUS=2
17                         TEXT="$TEXT SW-RAID is $statusText."
18                 else
19                         [ -z "$STATUS" ] && STATUS=0
20                         TEXT="$TEXT SW-RAID status is good."
21                 fi
22         fi
23         LC_ALL=C raidutil list status 2>/dev/null | grep "RAID " >"$tmp"
24         if [ $? -eq 0 ]; then
25                 # Apple Hardware-RAID detected
26                 declare -i good=0
27                 declare -i bad=0
28                 status=""
29                 while read x; do
30                         v=`echo "$x" | cut -d' ' -f1`
31                         s=`echo "$x" | cut -b67- | sed -e 's/://g'`
32                         s2=`echo "$x" | cut -b78-`
33                         [ -n "$status" ] \
34                                 && status="$status, $v:$s" \
35                                 || status="$v:$s"
36                         [ "$s2" = "Good" ] && good=$good+1 || bad=bad+1
37                 done <"$tmp"
38                 if [ $bad -eq 0 -a $good -ge 1 ]; then
39                         [ -z "$STATUS" ] && STATUS=0
40                         TEXT="$TEXT Apple HW-RAID is good: $status."
41                 elif [ $bad -gt 0 ]; then
42                         STATUS=2
43                         TEXT="$TEXT Apple HW-RAID status: $status."
44                 else
45                         [ -z "$STATUS" -o "$STATUS" = "1" ] && STATUS=1
46                         TEXT="$TEXT  Apple HW-RAID status is unknown ($status)!?"
47                 fi
48         fi
49         LC_ALL=C promiseutil -C array -a list -v 2>/dev/null </dev/tty \
50          | grep -A8 '^LdId' | grep '^[0-9]' >"$tmp"
51         if [ $? -eq 0 ]; then
52                 # Promise Hardware-RAID detected
53                 declare -i good=0
54                 declare -i bad=0
55                 status=""
56                 while read x; do
57                         v=`echo "$x" | awk "{ print \\$2 }"`
58                         z=`echo "$x" | awk "{ print \\$3 }"`
59                         s=`echo "$x" | awk "{ print \\$4 }"`
60                         [ -n "$status" ] \
61                                 && status="$status, $v($z):$s" \
62                                 || status="$v($z):$s"
63                         [ "$s" = "OK" ] && good=$good+1 || bad=bad+1
64                 done <"$tmp"
65                 if [ $bad -eq 0 -a $good -ge 1 ]; then
66                         [ -z "$STATUS" ] && STATUS=0
67                         TEXT="$TEXT Promise HW-RAID is good: $status."
68                 elif [ $bad -gt 0 ]; then
69                         STATUS=2
70                         TEXT="$TEXT Promise HW-RAID status: $status."
71                 else
72                         [ -z "$STATUS" -o "$STATUS" = "1" ] && STATUS=1
73                         TEXT="$TEXT  Promise HW-RAID status is unknown ($status)!?"
74                 fi
75         fi
76         rm -f "$tmp"
77 elif [ `uname` = "Linux" -a -r /proc/mdstat ]; then
78         status=$(cat /proc/mdstat | grep -E "(^md|^      [0-9])" \
79          | while read info1; do
80                 read info2
81                 dev=`echo $info1 | cut -d' ' -f1`
82                 stat=`echo $info2 | cut -d'[' -f 3 | cut -d']' -f1`
83                 echo -n " $dev:$stat"
84         done)
85         if [ -n "$status" ]; then
86                 if [ "`echo $status | tr -d 'md0123456789: U'`" = "" ]; then
87                         [ -z "$STATUS" ] && STATUS=0
88                         TEXT="$TEXT SW-RAID is good: $status."
89                 else
90                         STATUS=2
91                         TEXT="$TEXT SW-RAID status: $status."
92                 fi
93         fi
94 fi
95
96 if [ -n "$TEXT" ]; then
97         case "$STATUS" in
98                 0)      TEXT="OK -${TEXT}"; ;;
99                 1)      TEXT="WARNING -${TEXT}"; ;;
100                 2)      TEXT="ERROR -${TEXT}"; ;;
101                 *)      TEXT="UNKNOWN -${TEXT}"; ;;
102         esac
103 fi