How To Configure Software RAID To Send An Email When Something's Wrong With RAID

Version 1.0
Author: Falko Timme

This short guide explains how you can configure software RAID to send you an email when something's wrong with RAID, for example if a hard drive fails. I've tested this on Debian Etch, but it should apply to all other distributions with minor adjustments to paths, etc.

I do not issue any guarantee that this will work for you!

Open your mdadm.conf file (on Debian it's /etc/mdadm/mdadm.conf)...

vi /etc/mdadm/mdadm.conf

... and add a MAILADDR line (with your email address) to the file, e.g. like this:

DEVICES /dev/sda* /dev/sdb*
ARRAY /dev/md0 level=raid1 num-devices=2 UUID=c8a78e3a:e335c0f0:997be224:f02c088a
ARRAY /dev/md1 level=raid1 num-devices=2 UUID=fd9f3b6b:4fc9cf4f:09db592d:480d34fe
MAILADDR [email protected]

Then restart mdadm:

/etc/init.d/mdadm restart

That's it. Now whenever there's something wrong with your RAID setup, you will receive an email, for example as follows:

From: mdadm monitoring <[email protected]>
To: [email protected]
Subject: DegradedArray event on /dev/md1:server1.example.com


This is an automatically generated mail message from mdadm
running on server1.example.com

A DegradedArray event had been detected on md device /dev/md1.

Faithfully yours, etc.

P.S. The /proc/mdstat file currently contains the following:

Personalities : [raid0] [raid1]
md1 : active raid1 sda2[2] sdb2[1]
      487853760 blocks [2/1] [_U]
      [>....................]  recovery =  4.3% (21448384/487853760) finish=114.3min speed=67983K/sec

md0 : active raid1 sda1[0] sdb1[1]
      530048 blocks [2/2] [UU]

unused devices: <none>

or like this:

From: mdadm monitoring <[email protected]>
To: [email protected]
Subject: FailSpare event on /dev/md1:server1.example.com


This is an automatically generated mail message from mdadm
running on server1.example.com

A FailSpare event had been detected on md device /dev/md1.

It could be related to component device /dev/sda2.

Faithfully yours, etc.

P.S. The /proc/mdstat file currently contains the following:

Personalities : [raid0] [raid1]
md1 : active raid1 sda2[2](F) sdb2[1]
      487853760 blocks [2/1] [_U]
      [===================>.]  recovery = 99.9% (487851840/487853760) finish=0.0min speed=61037K/sec

md0 : active raid1 sda1[0] sdb1[1]
      530048 blocks [2/2] [UU]

unused devices: <none>

Falko Timme

About Falko Timme

Falko Timme is an experienced Linux administrator and founder of Timme Hosting, a leading nginx business hosting company in Germany. He is one of the most active authors on HowtoForge since 2005 and one of the core developers of ISPConfig since 2000. He has also contributed to the O'Reilly book "Linux System Administration".

Share this page:

Suggested articles

3 Comment(s)

Add comment

Comments

By: RogerK

A Linux server sends email to "root" by default. Rather than hardcoding an email address into every config file, it's cleaner to simply place a file named "forward" (that's dot-forward) in the root directory of the root account. The contents of that file should be a single line which is the admin's real, outside email address.

Now, whenever any process sends a message to "root", it will be automatically forwarded to the address specified in the ".forward" file.

The file should be a plain text file, with permissions 0644.

Lastly... put "root" back into the "mdadm.conf"  file if it's been changed.

By: fred

What I do is send all root messages to an email address.  So then you not only get mdadm failure messages but a lot of other things just by that one setup.

 

nano /etc/aliases

root: [email protected] //

newaliases

 

Then test it:

 

echo testing | mail -s "test mail" [email protected]

By: Debian

echo test | mail -s "test message" root