How-to : mdadm (raid) monitoring and alert emails sent through Gmail
Forum » Forum / My Book World Edition (blue rings) » How-to : mdadm (raid) monitoring and alert emails sent through Gmail
Started by: johnnyejohnnye
On: 1199130492|%e %b %Y, %H:%M %Z|agohover
Number of posts: 12
rss icon RSS: New posts
Summary:
Noticed most of the scripts were there, but there were a few steps to get emails sent through Gmail.
How-to : mdadm (raid) monitoring and alert emails sent through Gmail
johnnyejohnnye 1199130492|%e %b %Y, %H:%M %Z|agohover

I do not have a local mail server but wanted any degraded/etc. messages to be sent to my email account.

I used Optware to install msmtp because the default, ssmtp, wasn't playing nicely with TLS/Gmail. I'm assuming this is due to how it was compiled.

ipkg install msmtp

One more package was needed that ipkg didnt solve the dependency for:
ipkg install libiconv

then run:
ldconfig

Now we will set up the smtp server you want to connect to, in this case Gmail.

Create the configuration file and edit:

vi /opt/etc/msmtprc  (optionally you can have user specific config in each home dir)

and add:
defaults
account gmail
host smtp.gmail.com
auth on
user yourgmailuser@gmail.com
password changeme
port 587
auto_from on
tls on
tls_certcheck off
logfile /root/msmtp.log
account default : gmail

Lastly, vi /etc/RAID-message-sender-en.sh and change
/sbin/ssmtp $address <$message

to

/opt/bin/msmtp $address <$message

Now test it by running this on command line:

mdadm --monitor --scan --test --program=/etc/RAID-message-sender-en.sh

/edit
I forgot that you need to set what email address to send the mail to.

echo "destinationemail@isp.com" > /var/oxsemi/email-recipients
last edited on 1199199241|%e %b %Y, %H:%M %Z|agohover by johnnye + show more
Re: How-to : mdadm (raid) monitoring and alert emails sent through Gmail
number3number3 1214255347|%e %b %Y, %H:%M %Z|agohover

Great… so I want to implement this… however I cannot find the RAID-send-message-en.sh script in the /etc
I am running on 2.00.18 firmware…
Got msmtp to work, I was thinking to write a little script with mdadm using —mail, however that needs a sendmail replacement.

If anyone has the scripts available then please share them

Re: How-to : mdadm (raid) monitoring and alert emails sent through Gmail
huotg01huotg01 1217173403|%e %b %Y, %H:%M %Z|agohover

Hello

There is no trace of RAID-message-sender-en.sh on my My Book 2Tb 02.00.18

So your How-to is perfect for msmtp, but is there something missing (or did I missed something) about this point ?

Thanks,

G.

last edited on 1217173564|%e %b %Y, %H:%M %Z|agohover by huotg01 + show more
Re: How-to : mdadm (raid) monitoring and alert emails sent through Gmail
huotg01huotg01 1217217074|%e %b %Y, %H:%M %Z|agohover

Ihe script was present on my other MBWE (an earlier version).
So, here is it:

#!/bin/sh
# Raid message sender, this script should be run by the mdadm RAID program in 
# monitor mode.
#

#############################################################################
# compases a rebuild message
#
# Param 1: Percent complete
# Param 2: Device affected

rebuild_message() {
    cat >>$message <<-EOF
    This is an automatically generated e-mail from the RAID administration
    software running on `hostname` 

    The RAID array $2 has completed $1% of its rebuild.
    EOF
}

##############################################################################
#
# Param 1: Name of event
# Param 2: Device affected
# Param 3: Some other relavent component
#
# It uses /var/oxsemi/email-recipients as the list of people to e-mail
#
recipients=/var/oxsemi/email-recipients
message=/tmp/email-message
WEBUIINFOFILE=/var/oxsemi/failed-drives
cat >$message <<-EOF
Subject:RAID $1 Event

EOF

if [ ! -e $message ]
then
    # cannot create a temporary file to hold an e-mail message
    exit 0;
fi

# on event
case $1 in
DeviceDisappeared)
    cat >>$message <<-EOF
    This is an automatically generated e-mail from the RAID administration
    software running on `hostname` 

    The array $2 was previously configured, but no longer appears to be
    present.    

    EOF
    ;;
RebuildStarted)
    # remove the rebuilding drive from the Web-UI's info file
    devtoremove=`echo $2|sed -e 's:\/:\\\/:g'` 
    sed -i -e "/$devtoremove/d" $WEBUIINFOFILE

    # compose an e-mail
    cat >>$message <<-EOF
    This is an automatically generated e-mail from the RAID administration
    software running on `hostname` 

    The RAID administration program has begun reconstruction of RAID array
    $2. The rebuild process copies data onto the new elements in the
    RAID array to ensure that all components of the array contain the same 
    data. 

    Whilst the rebuild is taking place the system may operate with reduced
    performance.
    EOF
    ;;
Rebuild20)
    rebuild_message 20 $2
    ;;
Rebuild40)
    rebuild_message 40 $2
    ;;
Rebuild60)
    rebuild_message 60 $2
    ;;
Rebuild80)
    rebuild_message 80 $2
    ;;
RebuildFinished)
    cat >>$message <<-EOF
    This is an automatically generated e-mail from the RAID administration
    software running on `hostname`

    The rebuild of    RAID array $2 is complete.
    EOF
    ;;
Fail)
    # write failure info for WebUI
    echo "$2=$3" >> $WEBUIINFOFILE

    # compose e-mail
    cat >>$message <<-EOF
    This is an automatically generated e-mail from the RAID administration
    software running on `hostname`

    The drive containing partition $3 in RAID array $2 has 
    failed.

    EOF
    ;;
FailSpare)
    cat >>$message <<-EOF
    This is an automatically generated e-mail from the RAID administration
    software running on `hostname`

    The spare drive containing partition $3 in RAID array $2
    has failed. This drive was the target of a RAID rebuild, the system will
    continue running on the remaining drives in the array. 

    EOF
    ;;
SpareActive)
    cat >>$message <<-EOF
    This is an automatically generated e-mail from the RAID administration
    software running on `hostname`

    The spare drive containing partition $3 in RAID array $2
    has completed its rebuild process. 

    EOF
    ;;
NewArray)
    cat >>$message <<-EOF
    This is an automatically generated e-mail from the RAID administration
    software running on `hostname`

    A new RAID array $2 has been detected. 

    EOF
    ;;
DegradedArray)
    cat >>$message <<-EOF
    This is an automatically generated e-mail from the RAID administration
    software running on `hostname` 

    The RAID administration program has noticed RAID array $2 
    appears to be running in a degraded state. 
    EOF
    ;;
MoveSpare)
    cat >>$message <<-EOF
    This is an automatically generated e-mail from the RAID administration
    software running on `hostname`

    A drive has been moved from RAID array $3 to $2. This is to
    allow the faulty device in $2 to be replaced.
    EOF
    ;;
TestMessage)
    cat >>$message <<-EOF
    This is an automatically generated test e-mail from software running 
    on `hostname`
    EOF
    ;;
#These are events for which we shouldn't generate an e-mail
SparesMissing) # no space for spare drives
    if [ -e $message ]
    then
        rm $message
    fi
    exit 0
    ;;
*)
    cat >>$message <<-EOF
    This is an automatically generated e-mail from the RAID administration
    software running on `hostname`

    A $1 event has occured on RAID array $2.

    EOF
    ;;
esac

# e-mail all the people in the e-mail list file.
for address in `cat $recipients`
do
#    /sbin/ssmtp $address <$message
    /sbin/msmtp $address <$message
done

if [ -e $message ]
then
    rm $message
fi
Re: How-to : mdadm (raid) monitoring and alert emails sent through Gmail
huotg01huotg01 1217220614|%e %b %Y, %H:%M %Z|agohover

When running

mdadm --monitor --scan --test --program=/etc/RAID-message-sender-en.sh

I have the following message:

/opt/bin/msmtp: can't load library 'libgcrypt.so.11'

Any idea ?

Thanks,

G.

Re: How-to : mdadm (raid) monitoring and alert emails sent through Gmail
huotg01huotg01 1217253355|%e %b %Y, %H:%M %Z|agohover

The answer is :

ipkg install libgcrypt

and then

ldconfig

and that's it.

G.

last edited on 1217258233|%e %b %Y, %H:%M %Z|agohover by huotg01 + show more
Re: How-to : mdadm (raid) monitoring and alert emails sent through Gmail
huotg01huotg01 1217255477|%e %b %Y, %H:%M %Z|agohover

It is not going to be an easy one …

When running :

mdadm --monitor --scan --test --program=/etc/RAID-message-sender-en.sh

I know have the following message:

msmtp: the server does not support TLS via the STARTTLS command

Trying to find out what it is.

Re: How-to : mdadm (raid) monitoring and alert emails sent through Gmail
huotg01huotg01 1217262187|%e %b %Y, %H:%M %Z|agohover

Aleluya !!!

My problem is that I just adapted John's script without understand it :

defaults
account videotron
host relais.videotron.ca
auth on
user Vlxxxxxxxx
password myPW
port 25
auto_from on
tls on
tls_certcheck off
logfile /root/msmtp.log
account default : videotron

Almost everything was OK except that my ISP provider doesn't support authentification…
Therefore auth and tls have to be set to off

…and then it works.

ETJ (End of this journey).

Re: How-to : mdadm (raid) monitoring and alert emails sent through Gmail
BobbiasBobbias 1199130972|%e %b %Y, %H:%M %Z|agohover

Kinda cool, I'm a bit of a linux newb though, so I don't exactly get what it's doing.. I know it is meant to detect degraded messages and such, but what is it supposed to do after. I don't know much about mdadm's monitor mode.

Re: How-to : mdadm (raid) monitoring and alert emails sent through Gmail
johnnyejohnnye 1199198935|%e %b %Y, %H:%M %Z|agohover

The purpose of this thread was for people who want those mdadm messages mailed to them when they occur.

There is a script in init.d that is run on start, raid_monitoring.sh. It will send emails with the RAID-message-sender-en.sh, for example:
(the $2 would be replaced with which drived failed)

This is an automatically generated e-mail from the RAID administration
        software running on `hostname`

        The RAID administration program has noticed RAID array $2
        appears to be running in a degraded state.
last edited on 1199199030|%e %b %Y, %H:%M %Z|agohover by johnnye + show more
Re: How-to : mdadm (raid) monitoring and alert emails sent through Gmail
BobbiasBobbias 1199199474|%e %b %Y, %H:%M %Z|agohover

Alright, that's pretty cool, I might even look into doing this, just because I know how much losing a lot of information can hurt, since I've had to format my 320 GB harddrive before (with 200+GB of anime, music, and a couple movies.)

Re: How-to : mdadm (raid) monitoring and alert emails sent through Gmail
number3number3 1214515150|%e %b %Y, %H:%M %Z|agohover

Just a questions… do you need to add the script init.d to anything. Or will it functiono when you add the msmtp configuration?

New post
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License