Create a file with this code
I create /etc/emailnotificationraid.py
#!/usr/bin/python
import sys
import smtplib
# Phaerus.com - 2010-11-15
# From somewhere on the Ubuntu forums, 2008
################################
# Edit the following variables #
################################
smtpserver = 'smtp.emailserver.com' # SMTP server
username = 'username' # for SMTP AUTH, set SMTP username here
password = 'password' # for SMTP AUTH, set SMTP password here
sender = 'send_address'
#to = 'youremailaddress@server.com'
to = ['youremailaddress@server.com', 'other_address@server.com']
# above is single address or multiple address
################################
# Setup email
status_file = open("/proc/mdstat")
status = status_file.read()
subject = 'RAID status change!'
event = sys.argv[1] #Provided by mdadm
mddevice = sys.argv[2] #Provided by mdadm
text = "MD Device: " + mddevice + "\nEvent: " + event + "\n\n/proc/mdstat:\n" + status
headers = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (sender, to, subject)
message = headers + text
#Send the email with normal account
session = smtplib.SMTP(smtpserver)
#######################
# send mail with google gmail account for mdadm raid
#mailServer = smtplib.SMTP("smtp.gmail.com", 587)
#mailServer.ehlo()
#mailServer.starttls()
#mailServer.ehlo()
# end google gmail account mdadm #
session.login(username, password)
session.sendmail(sender, to, message)
session.quit()
Add
chmod 744 /etc/emailnotificationraid.py
for test it change into emailnotificaionraid.py
event = sys.argv[1] #Provided by mdadm
mddevice = sys.argv[2] #Provided by mdadm
with
event = test #sys.argv[1] #Provided by mdadm
mddevice = test # sys.argv[2] #Provided by mdadm
Now you can test
/etc/./emailnotificationraid.py
Check your mail.
Now, if all ok, configure raid mdadm to send email notifications.
vim /etc/default/mdadm
check this
# mdadm Debian configuration
# START_DAEMON:
# should mdadm start the MD monitoring daemon during boot?
START_DAEMON=true
# DAEMON_OPTIONS:
# additional options to pass to the daemon.
DAEMON_OPTIONS="--syslog --program /etc/./emailnotificationraid.py"
restart mdadm
/etc/init.d/mdadm restart
bye