806186ee1d8d9816ec31fb712ebef282f77abc99
[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         rm -f "$tmp"
50 elif [ `uname` = "Linux" -a -r /proc/mdstat ]; then
51         status=$(cat /proc/mdstat | grep -E "(^md|^      [0-9])" \
52          | while read info1; do
53                 read info2
54                 dev=`echo $info1 | cut -d' ' -f1`
55                 stat=`echo $info2 | cut -d'[' -f 3 | cut -d']' -f1`
56                 echo -n " $dev:$stat"
57         done)
58         if [ -n "$status" ]; then
59                 if [ "`echo $status | tr -d 'md0123456789: U'`" = "" ]; then
60                         [ -z "$STATUS" ] && STATUS=0
61                         TEXT="$TEXT SW-RAID is good: $status."
62                 else
63                         STATUS=2
64                         TEXT="$TEXT SW-RAID status: $status."
65                 fi
66         fi
67 fi
68
69 if [ -n "$TEXT" ]; then
70         case "$STATUS" in
71                 0)      TEXT="OK -${TEXT}"; ;;
72                 1)      TEXT="WARNING -${TEXT}"; ;;
73                 2)      TEXT="ERROR -${TEXT}"; ;;
74                 *)      TEXT="UNKNOWN -${TEXT}"; ;;
75         esac
76 fi