]> arthur.barton.de Git - nagcollect.git/blobdiff - client/lib/tests/RAID.tst
Mac OS X RAID check: handle more than one software RAID system
[nagcollect.git] / client / lib / tests / RAID.tst
index 9c6b59d4759fce045589ddf20550b26b9982efcd..3ce95d992d66991f1c69c1d05e48c892820b5d14 100644 (file)
@@ -1,5 +1,5 @@
 # NagCollect -- Nagios Data Collector for Passive Checks
-# Copyright (c)2009 Alexander Barton, alex@barton.de
+# Copyright (c)2009-2010 Alexander Barton, alex@barton.de
 
 SERVICE="RAID_p"
 
@@ -8,15 +8,31 @@ if [ `uname` = "Darwin" ]; then
        LC_ALL=C diskutil checkRAID >"$tmp"
        if [ $? -eq 0 ]; then
                # Apple Software-RAID detected
-               statusText=`grep "^Status:" "$tmp"`
-               status=`echo "$statusText" | cut -d' ' -f2-`
+               statusString1=`grep "^Status:" "$tmp" | uniq`
+               status=`echo $statusString1 | sed -e 's/Status: //g'`
+               statusString=`grep "^Status:" "$tmp"`
+               statusText=`echo $statusStringAll | sed -e 's/Status: //g' | sed -e 's/ /, /g'`
                if [ "$status" != "Online" ]; then
                        STATUS=2
-                       TEXT="ERROR - RAID is $status"
+                       TEXT="ERROR - RAID is $statusText"
                else
                        STATUS=0
                        TEXT="OK - RAID status is good."
                fi
        fi
        rm -f "$tmp"
+elif [ `uname` = "Linux" ]; then
+       status=$(cat /proc/mdstat | grep -E "(^md|^      [0-9])" | while read info1; do
+               read info2
+               dev=`echo $info1 | cut -d' ' -f1`
+               stat=`echo $info2 | cut -d'[' -f 3 | cut -d']' -f1`
+               echo -n " $dev:$stat"
+       done)
+       if [ "`echo $status | tr -d 'md0123456789: U'`" = "" ]; then
+               STATUS=0
+               TEXT="OK - RAID is good: $status"
+       else
+               STATUS=2
+               TEXT="ERROR - RAID status: $status"
+       fi
 fi