Hardware monitoring
Basically, we're going to use smartmontools
and let it send via gmail smtp (if you don't have gmail… make a free account).
Sources: https://www.cyberciti.biz/tips/monitoring-hard-disk-health-with-smartd-under-linux-or-unix-operating-systems.html and https://gist.github.com/maleadt/02a58eb46118c1d8014c and https://linuxconfig.org/how-to-configure-smartd-and-be-notified-of-hard-disk-problems-via-email and https://forums.raspberrypi.com/viewtopic.php?t=50939
sudo apt-get install smartmontools mailutils msmpt msmtp-mta
Create msmtp config
sudo touch /etc/msmtprc # create global config
sudo chmod 660 /etc/msmtprc # make it accessible. the guide says 664, but this would be a security breach
- Create an app-specific password for your gmail https://myaccount.google.com/apppasswords
and use it in the next step - In
sudo vim /etc/msmtprc
paste (and insertAPP_PASSWORD_WITHOUT_SPACES
)
defaults auth on tls on tls_trust_file /etc/ssl/certs/ca-certificates.crt logfile /var/log/msmtp.log # Gmail configuration account gmail host smtp.gmail.com port 587 from me@example.com user me@example.com password APP_PASSWORD_WITHOUT_SPACES account default: gmail
- Enable logging:
sudo touch /var/log/msmtp.log
sudo chmod 666 /var/log/msmtp.log # there seems to be an issue with msmtp and it won't log unless all users have access. This is relatively harmless.
- Check if SMART support is available
sudo smartctl -i /dev/sda
(or whatever your device identifier is) - Open
sudo vim /etc/default/smartmontools
and modify/uncomment the following line:enable_smart="/dev/sda"
In
sudo vim /etc/smartd.conf
comment out the line withDEVICESCAN
and add the following lines:
(remove the last line after successful test. runsudo systemctl restart smartd
to re-run the test)# MY SETTINGS # check some stuff and track everything (-a), with a Short (-s S) and Long (-s L) test every week and month, respectively. # ignore temperature (194 and 231) and power-on hours (9) attributes (-I) # email (-m) once (-M) if warnings /dev/sda -a -I 194 -I 9 -I 231 -m me@example.com -M once -s (S/../../6/00)|(L/../01/./01) # every saturday midnight | every 1st day of the month 1AM /dev/sda -a -M test -m me@example.com # remove this line after successful test
sudo systemctl reload smartd
to reload the config (which also executes the test line)
Congrats! You're done!