]> arthur.barton.de Git - nagcollect.git/blob - client/lib/tests/RAID.tst
RAID.tst: Add support for Apple hardware RAID cards
[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"
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="ERROR - RAID is $statusText"
18                 else
19                         STATUS=0
20                         TEXT="OK - RAID status is good."
21                 fi
22         fi
23         LC_ALL=C raidutil list status | 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 -b78-`
32                         [ -n "$status" ] \
33                                 && status="$status $v:$s" \
34                                 || status="$v:$s"
35                         [ "$s" = "Good" ] && good=$good+1 || bad=bad+1
36                 done <"$tmp"
37                 if [ $bad -eq 0 -a $good -gt 1 ]; then
38                         STATUS=0
39                         TEXT="OK - HW-RAID is good: $status"
40                 elif [ $bad -gt 0 ]; then
41                         STATUS=2
42                         TEXT="ERROR - HW-RAID status: $status"
43                 else
44                         STATUS=1
45                         TEXT="ERROR - HW-RAID status is unknown!? ($status)"
46                 fi
47         fi
48         rm -f "$tmp"
49 elif [ `uname` = "Linux" -a -r /proc/mdstat ]; then
50         status=$(cat /proc/mdstat | grep -E "(^md|^      [0-9])" | while read info1; do
51                 read info2
52                 dev=`echo $info1 | cut -d' ' -f1`
53                 stat=`echo $info2 | cut -d'[' -f 3 | cut -d']' -f1`
54                 echo -n " $dev:$stat"
55         done)
56         if [ "`echo $status | tr -d 'md0123456789: U'`" = "" ]; then
57                 STATUS=0
58                 TEXT="OK - RAID is good: $status"
59         else
60                 STATUS=2
61                 TEXT="ERROR - RAID status: $status"
62         fi
63 fi