RAID.tst: Support more than one RAID system per host
authorAlexander Barton <alex@barton.de>
Fri, 10 Aug 2012 10:15:25 +0000 (12:15 +0200)
committerAlexander Barton <alex@barton.de>
Fri, 10 Aug 2012 10:15:25 +0000 (12:15 +0200)
Now the status message and result code are aggregated.

client/lib/tests/RAID.tst

index 048d45b..806186e 100644 (file)
@@ -14,10 +14,10 @@ if [ `uname` = "Darwin" ]; then
                statusText=`echo $statusString | sed -e 's/Status: //g' | sed -e 's/ /, /g'`
                if [ "$status" != "Online" ]; then
                        STATUS=2
-                       TEXT="ERROR - RAID is $statusText"
+                       TEXT="$TEXT SW-RAID is $statusText."
                else
-                       STATUS=0
-                       TEXT="OK - RAID status is good."
+                       [ -z "$STATUS" ] && STATUS=0
+                       TEXT="$TEXT SW-RAID status is good."
                fi
        fi
        LC_ALL=C raidutil list status 2>/dev/null | grep "RAID " >"$tmp"
@@ -36,14 +36,14 @@ if [ `uname` = "Darwin" ]; then
                        [ "$s2" = "Good" ] && good=$good+1 || bad=bad+1
                done <"$tmp"
                if [ $bad -eq 0 -a $good -ge 1 ]; then
-                       STATUS=0
-                       TEXT="OK - HW-RAID is good: $status"
+                       [ -z "$STATUS" ] && STATUS=0
+                       TEXT="$TEXT Apple HW-RAID is good: $status."
                elif [ $bad -gt 0 ]; then
                        STATUS=2
-                       TEXT="ERROR - HW-RAID status: $status"
+                       TEXT="$TEXT Apple HW-RAID status: $status."
                else
-                       STATUS=1
-                       TEXT="ERROR - HW-RAID status is unknown!? ($status)"
+                       [ -z "$STATUS" -o "$STATUS" = "1" ] && STATUS=1
+                       TEXT="$TEXT  Apple HW-RAID status is unknown ($status)!?"
                fi
        fi
        rm -f "$tmp"
@@ -57,11 +57,20 @@ elif [ `uname` = "Linux" -a -r /proc/mdstat ]; then
        done)
        if [ -n "$status" ]; then
                if [ "`echo $status | tr -d 'md0123456789: U'`" = "" ]; then
-                       STATUS=0
-                       TEXT="OK - RAID is good: $status"
+                       [ -z "$STATUS" ] && STATUS=0
+                       TEXT="$TEXT SW-RAID is good: $status."
                else
                        STATUS=2
-                       TEXT="ERROR - RAID status: $status"
+                       TEXT="$TEXT SW-RAID status: $status."
                fi
        fi
 fi
+
+if [ -n "$TEXT" ]; then
+       case "$STATUS" in
+               0)      TEXT="OK -${TEXT}"; ;;
+               1)      TEXT="WARNING -${TEXT}"; ;;
+               2)      TEXT="ERROR -${TEXT}"; ;;
+               *)      TEXT="UNKNOWN -${TEXT}"; ;;
+       esac
+fi