Mac OS X RAID check: handle more than one software RAID system
[nagcollect.git] / client / lib / tests / RAID.tst
1 # NagCollect -- Nagios Data Collector for Passive Checks
2 # Copyright (c)2009-2010 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 $statusStringAll | 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         rm -f "$tmp"
24 elif [ `uname` = "Linux" ]; then
25         status=$(cat /proc/mdstat | grep -E "(^md|^      [0-9])" | while read info1; do
26                 read info2
27                 dev=`echo $info1 | cut -d' ' -f1`
28                 stat=`echo $info2 | cut -d'[' -f 3 | cut -d']' -f1`
29                 echo -n " $dev:$stat"
30         done)
31         if [ "`echo $status | tr -d 'md0123456789: U'`" = "" ]; then
32                 STATUS=0
33                 TEXT="OK - RAID is good: $status"
34         else
35                 STATUS=2
36                 TEXT="ERROR - RAID status: $status"
37         fi
38 fi