Skip to content

Instantly share code, notes, and snippets.

@jimeh
Last active January 17, 2022 23:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jimeh/7f4f1da81df100a00425 to your computer and use it in GitHub Desktop.
Save jimeh/7f4f1da81df100a00425 to your computer and use it in GitHub Desktop.

This is a mirror of an article from a seemingly dead site: http://www.pcmediacenter.com.au/forum/topic/44471-mdadm-raid-email-notifications-w-ssmtp/


mdadm RAID: eMail notifications w/ sSMTP

Posted 15 June 2011 - 04:09 AM

Hi Guys,

I banged around with postfix for weeks trying to get it the way i wanted it, in terms of correctly spoofing the senders address, and SMTP authentication etc, when i came across this guide here . Uber simple setup, providing SMTP

I'll provide a generic outline below, but all credit goes to the OP.

Install ssmtp

$ sudo apt-get install ssmtp

Configure ssmtp via its config file /etc/ssmtp/ssmtp.conf

#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=postmaster

# The place where the mail goes. The actual machine name is required no
# MX records are consulted.
# Commonly mailhosts are named mail.domain.com
mailhub=smtp.gmail.com:587

# Where will the mail seem to come from?
#rewriteDomain=

# The full hostname - domain.com
hostname=smtpserverdomain.com.au

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
# FromLineOverride=YES

UseSTARTTLS=YES
UseTLS=YES
AuthUser=username@gmail.com
AuthPass=passwordhere

Now for a test of ssmtp, create a test file with some text in it. My test file was called ‘test’:

$ ssmtp username@youremail.com.au < test

Test mdadm

$ sudo mdadm --monitor --scan --test

And it's as simple as that!

For the security conscious, modify the permissions of the ssmtp.conf file, as your password is stored in plain-text

$ sudo chmod 660 /etc/ssmtp/ssmtp.conf

Now you simply need to add an email receiver in /etc/mdadm/mdadm.conf, as well as an optional sender address (this may or may not work when set different to your authentication email address, depending on your provider)

# instruct the monitoring daemon where to send mail alerts
MAILADDR receivermail@youremailaddress.com.au
MAILFROM RAID.Error@youremailaddress.com.au

It was previously required to setup a cron job for mdadm to monitor the array every x amount of seconds, but mdadm now notifies the kernel as soon as the array state changes, invoking the email sending automatically!

Let's hope you never have to receive on of these alerts! But be satisfied in knowing, that if something does go wrong, your sure to be alerted!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment