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-raid...

Excellent article! Delivering

melanie14's picture

Excellent article! Delivering maximum value is something you are an expert at. Thanks!

Geek Guide
The DevOps Toolbox

Tools and Technologies for Scale and Reliability
by Linux Journal Editor Bill Childers

Get your free copy today

Sponsored by IBM

Upcoming Webinar
8 Signs You're Beyond Cron

Scheduling Crontabs With an Enterprise Scheduler
11am CDT, April 29th
Moderated by Linux Journal Contributor Mike Diehl

Sign up now

Sponsored by Skybot