Debian 8 - Monitoring Disks with SMART

  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.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    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.

    1
    2
    3
    set from="EMAIL_USERNAME"
    set sendmail="/usr/bin/msmtp"
    set message-sendmail-extra-arguments="-a gmail"
  6. Create a new file located at /opt/smartd_mail for sending SMART mail messages.

    • 1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      #!/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.

  7. Edit /etc/default/smartmontools and uncomment start_smartd=yes.

  8. 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
    2. Restart the smartmontools process.
      • systemctl restart smartmontools.service
      • You should receive an email within a few seconds.
  9. 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.

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

    1
    2
    3
    4
    5
    # 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)
  11. Disks in a MegaRAID array can also be monitored and tested.

    1
    2
    3
    4
    5
    # 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)
  12. systemctl restart smartmontools.service