Package: mdadm
Version: 2.5.6-9
I wrote a script (see attachement) to automatically send out mails to a
specified user (usually root) about raid/md events. It should be called
from mdadm.conf with the PROGRAM directive.
I hope it's usefull.
--
Ing. A.C.J. van Amersfoort (Arno)
Department Of Electronics (ELD, k1007)
Huygens Laboratory
Leiden University
P.O. Box 9504
Niels Bohrweg 2
2333 CA Leiden
The Netherlands
----------------------------------------------------------------
Phone : +31-(0)71-527.1894 Fax: +31-(0)71-527.5819
E-mail: [EMAIL PROTECTED]
----------------------------------------------------------------
Arno's (Linux firewall) homepage: http://rocky.eld.leidenuniv.nl
#!/bin/sh
# MDADM Event Handler - Generate mails when MD events occur
# Drop a line like "PROGRAM /root/bin/sys/mdadm-event-handler.sh" in your
mdadm.conf to use it
#
# Last update: May 19, 2007
# (C) Copyright 2006-2007 by Arno van Amersfoort
# Homepage : http://rocky.eld.leidenuniv.nl/
# Email : a r n o v a AT r o c k y DOT e l d DOT l e i d e n u
n i v DOT n l
# (note: you must remove all spaces and substitute the
@ and the . at the proper locations!)
#
----------------------------------------------------------------------------------------------------------------------
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
----------------------------------------------------------------------------------------------------------------------
CONFIG="/etc/mdadm/mdadm.conf"
# Overrule mailto address from the mdadm.conf file?:
#MAILADDR="root"
parse_event()
{
echo "Host : $HOSTNAME"
if [ -z "$1" ]; then
echo "Event : Test message"
else
echo "MD Device : $2"
echo "Event : $1"
if [ -n "$3" ]; then
echo "Device Component: $3"
fi
fi
echo ""
echo "/proc/mdstat dump:"
FAIL=0
DEGRADED=0
while read LINE; do
echo -n "$LINE"
if [ -n "$(echo "$LINE" |grep 'active raid')" ]; then
if [ -n "$(echo "$LINE" |grep '\(F\)')" ]; then
FAIL=$(($FAIL + 1))
echo -n " (WARNING: FAILED DISK(S)!)"
fi
if [ -n "$(echo "$LINE" |grep '\(S\)')" ]; then
echo -n " (Hotspare(s) available)"
else
echo -n " (NOTE: No hotspare?!)"
fi
fi
if [ -n "$(echo "$LINE" |grep 'blocks')" ]; then
if [ -n "$(echo "$LINE" |grep '_')" ]; then
DEGRADED=$(($DEGRADED + 1))
echo -n " (DEGRADED!!!)"
fi
fi
echo ""
done < /proc/mdstat
if [ $FAIL -gt 0 ]; then
echo ""
echo "** WARNING: One or more RAID arrays have FAILED disk(s)! **"
fi
if [ $DEGRADED -gt 0 ]; then
echo ""
echo "** WARNING: One or more RAID arrays are running in degraded mode! **"
fi
}
# main line:
# Get MAILADDR from mdadm.conf config file, if not set already
if [ -z "$MAILADDR" ] && [ -f "$CONFIG" ]; then
MAILADDR=`grep MAILADDR "$CONFIG" |cut -d' ' -f2`
if [ -z "$MAILADDR" ]; then
MAILADDR="root"
fi
fi
# Call the parser and send it to the configured address
parse_event $* |mail -s"RAID(MD) event on $HOSTNAME" "$MAILADDR"
exit 0