#!/bin/bash

mdstat="$1"

[ -f "$mdstat" ] \
	|| { echo "UNKNOWN: no mdstat file given"; exit 3; }

arrays=`grep -c '^md[0-9]' "$mdstat"`
ok=`egrep -c '\[U+\]' "$mdstat"`
failed=`grep -c '\(F\)' "$mdstat"`

if [ $arrays -ne $ok ]; then
	echo "CRITICAL: $ok arrays OK on $arrays active arrays"
	exit 2
fi

if [ $failed -gt 0 ]; then
	echo "CRITICAL: $failed failed arrays on $arrays arrays"
	exit 2
fi

echo "OK: $ok clean arrays on $arrays active arrays"
exit 0
