Desktop notification of RAID status failure

Despite there are some attempts (raid-notify, raidmonitor) to provide a GUI-enabled mechanism that warns users about software-RAID failures, I think there is an alternative for some of us that want a simpler solution, just because it's simple or because our distribution of choice doesn't offer an apropriate package.

Once properly installed, the following script will show a pop-up message in the event of RAID status changes:

#!/bin/bash
#
# PREREQUISITE: aptitude install libnotify-bin

# is somebody running an X server?
USER=($(/usr/bin/w | awk '($3==":0"){print $1" "$3}'))

export XAUTHORITY=/home/$USER/.Xauthority
export DISPLAY=${USER[1]}

if [ ! -f $XAUTHORITY ] ; then
exit 1
fi

LEVEL=critical
ICON=gtk-stop
TIMEOUT=0
SUBJECT="Warning!"

for arg in "$@"
do
MESSAGE="$MESSAGE ${arg}"
done

sudo -u $USER /usr/bin/notify-send -u $LEVEL -i $ICON -t $TIMEOUT "$SUBJECT" "$MESSAGE"

Save it to ~/bin/desktop-notify.sh. To install it, follow this steps as root user:

$ chmod +x /home/user/bin/desktop-notify.sh
$ echo "PROGRAM /home/user/bin/desktop-notify.sh" >> /etc/mdadm/mdadm.conf
$ /etc/init.d/mdadm reload

To test if it works correctly:

$ mdadm --monitor /dev/md2 -t

That's all. My original article (in Spanish) is located at

http://minglanillosesferoides.blogspot.com/2010/09/notificar-estado-rai…