X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=nagcollect.git;a=blobdiff_plain;f=client%2Flib%2Ftests%2FRAID.tst;h=859062b1280a914b7b7f3f6f3e05756b26178c07;hp=53c57b2557f508ce2b57562279306793b4da5215;hb=HEAD;hpb=2cc4c245f51339cfaf3c5497b15550b6288b4b19 diff --git a/client/lib/tests/RAID.tst b/client/lib/tests/RAID.tst index 53c57b2..859062b 100644 --- a/client/lib/tests/RAID.tst +++ b/client/lib/tests/RAID.tst @@ -5,7 +5,8 @@ SERVICE="RAID_p" if [ `uname` = "Darwin" ]; then tmp=`mktemp "/tmp/$$.XXXX"` - LC_ALL=C diskutil checkRAID >"$tmp" + tmp2=`mktemp "/tmp/$$-2.XXXX"` + LC_ALL=C diskutil checkRAID >"$tmp" 2>/dev/null if [ $? -eq 0 ]; then # Apple Software-RAID detected statusString1=`grep "^Status:" "$tmp" | uniq` @@ -14,13 +15,13 @@ 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 | grep "RAID " >"$tmp" + LC_ALL=C raidutil list status 2>/dev/null | grep "RAID " >"$tmp" if [ $? -eq 0 ]; then # Apple Hardware-RAID detected declare -i good=0 @@ -28,36 +29,76 @@ if [ `uname` = "Darwin" ]; then status="" while read x; do v=`echo "$x" | cut -d' ' -f1` - s=`echo "$x" | cut -b78-` + s=`echo "$x" | cut -b67- | sed -e 's/://g'` + s2=`echo "$x" | cut -b78-` [ -n "$status" ] \ - && status="$status $v:$s" \ + && status="$status, $v:$s" \ || status="$v:$s" - [ "$s" = "Good" ] && good=$good+1 || bad=bad+1 + [ "$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" + LC_ALL=C screen -D -m sh -c "promiseutil -C array -a list -v >$tmp2" + grep -A8 '^LdId' "$tmp2" | grep '^[0-9]' >"$tmp" + if [ $? -eq 0 ]; then + # Promise Hardware-RAID detected + declare -i good=0 + declare -i bad=0 + status="" + while read x; do + v=`echo "$x" | awk "{ print \\$2 }"` + z=`echo "$x" | awk "{ print \\$3 }"` + s=`echo "$x" | awk "{ print \\$4 }"` + [ -n "$status" ] \ + && status="$status, $v($z):$s" \ + || status="$v($z):$s" + [ "$s" = "OK" ] && good=$good+1 || bad=bad+1 + done <"$tmp" + if [ $bad -eq 0 -a $good -ge 1 ]; then + [ -z "$STATUS" ] && STATUS=0 + TEXT="$TEXT Promise HW-RAID is good: $status." + elif [ $bad -gt 0 ]; then + STATUS=2 + TEXT="$TEXT Promise HW-RAID status: $status." + else + [ -z "$STATUS" -o "$STATUS" = "1" ] && STATUS=1 + TEXT="$TEXT Promise HW-RAID status is unknown ($status)!?" + fi + fi + rm -f "$tmp" "$tmp2" elif [ `uname` = "Linux" -a -r /proc/mdstat ]; then - status=$(cat /proc/mdstat | grep -E "(^md|^ [0-9])" | while read info1; do + 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" + if [ -n "$status" ]; then + if [ "`echo $status | tr -d 'md0123456789: U'`" = "" ]; then + [ -z "$STATUS" ] && STATUS=0 + TEXT="$TEXT SW-RAID is good: $status." + else + STATUS=2 + 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