Debian 8 - Monitoring Disks with SMART
Apr 28, 2016
  1. Install the smart monitoring tools and the msmtp SMTP client.
    • apt-get install smartmontools msmtp
  2. Reconfigure exim4 to be an internet site. This will allow msmtp to send email.
    • dpkg-reconfigure exim4-config
  3. Download the Mozilla CA certificate bundle.
    • wget https://curl.haxx.se/ca/cacert.pem -O /etc/ssl/cacert.pem
  4. Create a file in the root users home directory named .msmtprc.
    account gmail
    auth on
    host smtp.gmail.com
    port 587
    tls_trust_file /etc/ssl/cacert.pem
    tls on
    user EMAIL_USERNAME
    password EMAIL_PASSWORD
    from EMAIL_USERNAME
    account default: gmail
    
  5. Create a file in the root users home directory named .mailrc.
    set from="EMAIL_USERNAME"
    set sendmail="/usr/bin/msmtp -t"
    set message-sendmail-extra-arguments="-a gmail"
    
  6. Create a new file located at /opt/smartd_mail for sending SMART mail messages.
    • ``` #!/bin/bash TMP_FILE=”/tmp/.smarterror”

Body

echo “Device: $SMARTD_DEVICE” > $TMP_FILE echo “Failure type: $SMARTD_FAILTYPE” » $TMP_FILE echo “” » $TMP_FILE echo “smartctl -a -d $SMARTD_DEVICETYPE $SMARTD_DEVICE” » $TMP_FILE

Send

cat $TMP_FILE | mailx -s “$SMARTD_SUBJECT” $SMARTD_ADDRESS &> /dev/null

Delete temp file

rm -f $TMP_FILE

   - Make it executable `chmod +x /opt/smartd_mail`.

1. Edit `/etc/default/smartmontools` and uncomment `start_smartd=yes`.

1. Open and erase **everything** in `/etc/smartd.conf`.
   1. First we are going to setup a test command to make sure email is working.
      - `/dev/sda -H -a -d ata -m YOUR_EMAIL_ADDRESS -M test -M exec /opt/smartd_mail`
   1. Restart the smartmontools process.
      - `systemctl restart smartmontools.service`
      - You should receive an email within a few seconds.

1. If you have configured everything correctly and still do not receive any mail, you can install the `msmtp-mta` package which will replace/remove exim4.

1. Next, edit the same file except this time monitoring will be configured as well as self tests.

Monitoring

/dev/disk/by-id/YOUR_DISK_ID -H -a -d ata -m YOUR_EMAIL_ADDRESS -M exec /opt/smartd_mail

Self-Test (Daily short test at 1-2AM, Weekly long test at 4-5AM)

/dev/disk/by-id/YOUR_DISK_ID -a -d ata -s (S/../.././01|L/../../06/04)


1. Disks in a MegaRAID array can also be monitored and tested.

Monitoring

/dev/disk/by-id/scsi-SCSI_ID -H -a -d megaraid,DISK_ID -m YOUR_EMAIL_ADDRESS -M exec /opt/smartd_mail

Self-Test

/dev/disk/by-id/scsi-SCSI_ID -a -d megaraid,DISK_ID -s (S/../.././01|L/../../06/04) ```

  1. systemctl restart smartmontools.service
Comments