Pop up notification of software RAID problems in Ubuntu
I finally was able to setup a software RAID in my last install of Ubuntu 8.10 and I wanted to setup monitoring so I would know about any problems immediately. Ubuntu sets up monitoring automatically when you create a MDADM arrary but by default it only sends an email to the local root account. That would be fine for a server but on a desktop system a visual notification would be better. Here are the steps I took to enable a pop up notification whenever something bad happens to my RAID array.
To make the notification bubble I used notify-send. Notify-send is part of the notification-daemon package so install it with this command:
Now we need to configure MDADM to run a program when there's a problem as well as setting the email address of where we want the notifications sent. Edit /etc/mdadm/mdadm.conf and set the MAILADDR and MAILFROM email addresses. MAILADDR is where you want the email sent, MAILFROM is what shows up in the From field in the email. You may have to add the MAILFROM line. To run our program add a PROGRAM line underneath the MAIL line with the following:
Now we are ready to test. Run "sudo /etc/init.d/mdadm restart" to restart MDADM and send the test message. Adjust the int:x and int:y values if the pop up isn't where you want it or the icon isn't showing up and test again. Once you are satisfied with the appearance of the notification go back into /etc/default/mdadm and remove the " --test" from the DAEMON_OPTIONS string so you don't keep getting the test message.
That's it! Now if something happens to the RAID array you'll get a nice visual notification of the problem.
To make the notification bubble I used notify-send. Notify-send is part of the notification-daemon package so install it with this command:
sudo apt-get install notification-daemonIn order to make sure our notification are working we need to be able to send a test notification. MDADM has a testing mode built right in, to activate it edit /etc/default/mdadm and add " --test" to the end of the DAEMON_OPTIONS string. This will tell MDADM to send a test message every time it starts.
Now we need to configure MDADM to run a program when there's a problem as well as setting the email address of where we want the notifications sent. Edit /etc/mdadm/mdadm.conf and set the MAILADDR and MAILFROM email addresses. MAILADDR is where you want the email sent, MAILFROM is what shows up in the From field in the email. You may have to add the MAILFROM line. To run our program add a PROGRAM line underneath the MAIL line with the following:
# display local notificationThis tells MDADM to run our script when there's a problem. Now we just need to create /usr/sbin/mdadm-notify.sh and add the following:
PROGRAM /usr/sbin/mdadm-notify.sh
#!/bin/bashThere are a couple settings you'll want to change on the last line of the script. Most of all you'll have to alter the int:x and int:y values so they work on your system. I have a triple screen setup so my settings will likely put the notification off screen if you don't change them. Also the warning icon I used should be standard for Ubuntu 8.10 but if it's not showing up you'll have to set the path to an icon on your system. Finally be sure to run "sudo set chmod +x /usr/sbin/mdadm-notify.sh" to make the script executable.
#get dbus session
eval `dbus-launch --sh-syntax --exit-with-session`
#show alert
/usr/bin/notify-send -u critical -c device.error -i /usr/share/icons/Human/32x32/status/dialog-warning.png -t 0 "RAID Status" "<b>$2</b>: $1" -h int:x:1250 -h int:y:20
Now we are ready to test. Run "sudo /etc/init.d/mdadm restart" to restart MDADM and send the test message. Adjust the int:x and int:y values if the pop up isn't where you want it or the icon isn't showing up and test again. Once you are satisfied with the appearance of the notification go back into /etc/default/mdadm and remove the " --test" from the DAEMON_OPTIONS string so you don't keep getting the test message.
That's it! Now if something happens to the RAID array you'll get a nice visual notification of the problem.