gif gif

The interesting corner

gif gif

Setting up smartd for automatic disk checks with email notifications

Introduction

I have a HP DL360P G8 running proxmox, with 1x1TB and 3x6TB drives. The 6TB drives are running in a RAID5 config resulting in 12TB usable. I got these drives in a pretty good deal, but I figured I want to know if they fail or if something is up with them.

Smartd

The disks all support SMART monitoring, and I can use smartd for that. It's managed through /etc/smartd.conf. There you can specify which disks you want to monitor and which tests you want to perform at what time. I ended up with this:

        
# Monitoring and testing /dev/sda behind CCISS controller, logical drive 0
/dev/sda -d cciss,0 -a -o on -S on -s (S/../.././02|L/../../6/03) -m myemail@example.com

# Monitoring and testing /dev/sda behind CCISS controller, logical drive 1
/dev/sda -d cciss,1 -a -o on -S on -s (S/../.././02|L/../../6/03) -m myemail@example.com

# Monitoring and testing /dev/sda behind CCISS controller, logical drive 2
/dev/sda -d cciss,2 -a -o on -S on -s (S/../.././02|L/../../6/03) -m myemail@example.com

# Monitoring and testing /dev/sda behind CCISS controller, logical drive 3
/dev/sda -d cciss,3 -a -o on -S on -s (S/../.././02|L/../../6/03) -m myemail@example.com          
        
      

As you can see, all my disks are behind a CCISS controller (HP RAID controller), with the 1TB drive on id 0 and the other 6 TB ones on 1,2 and 3. The parameters mean this:

Email

I also want to get an email whenever there is a problem with my drives. To do this, I installed mail-utils and postfix. The config for postfix is located in /etc/postfix/main.cf. I don't have my own SMTP server setup yet (I really want to and should do it sometime tho), so I will use a relay for now. The config I ended up that worked for me was:

      
# See /usr/share/postfix/main.cf.dist for a commented, more complete version

myhostname=my-domain

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no
        
# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
#mydestination = $myhostname, localhost.$mydomain, localhost
mydestination = $myhostname

relayhost = [your.email.provider]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

mynetworks = 127.0.0.0/8

#allow IP v4 only
inet_protocols = ipv4
recipient_delimiter = +

compatibility_level = 2

# specific for my email provider
masquerade_domains = my-domain
masquerade_exceptions = root
sender_canonical_maps = hash:/etc/postfix/sender_canonical        
      
    

The things that took some time to figure out were the inet-protocols = ipv4 and the last 3 lines. The ipv4 line I added to fix an error I would see when checking /var/log/syslog about Network Unreachable when trying to connect to the relay server. The last three lines I added because I was getting this error:

relay=your.email.provider[xx.xx.xxx.xxx]:587, delay=0.43, delays=0.03/0.05/0.32/0.03, dsn=5.7.1, status=bounced (host send.one.com[xx.xx.xxx.xxx] said: 550 5.7.1 [M12] User [notifications@mydomain.com] not authorized to send on behalf of <root@mydomain.com>.

Authentication

For authentication, you need to edit the sasl_passwd file. Some example contents: [smtp.example.com]:587 username@example.com:password. Make sure the proper permissions are set for the file using chmod 600 /etc/postfix/sasl_passwd. After that, you need to run postmap /etc/postfix/sasl_passwd and systemctl restart postfix to create a lookup table and restart postfix.

sender_canonical mapping

To fix the error about User [notifications@mydomain.com] not authorized to send on behalf of <root@mydomain.com>, I added a sender_canonical mapping. This is done trough the /etc/postfix/sender_canonical file. I put this line into the file: root@interesting-corner.nl notifications@interesting-corner.nl. After that, create a lookup table again using postmap /etc/postfix/sender_canonical and restart the service to have the changes take effect. To test if the email notifications are working, append -M test to any of the entries in the smartd config file to have a test message be sent any time the service starts up.

And that's it! Enjoy being worry-free about wether or not your disks are OK, because now you'll get an email about any alerts.