Your current configuration appears mostly correct for basic email alert functionality, but let's verify all required components:
# Verify smartd service status
sudo systemctl status smartmontools
# Check if smartd is running with your parameters
ps aux | grep smartd
The following must be properly configured for email alerts to work:
- Functional mail transfer agent (MTA) installed (Postfix/Exim/Sendmail)
- Correct permissions on mail queue directory
- Valid DEVICESCAN line in smartd.conf
Here are three methods to test email alert functionality:
# Method 1: Force immediate check with test email
sudo smartd -q onecheck -m test@example.com
# Method 2: Simulate failing attribute (run as root)
smartctl -d ata -T permissive -v 194,raw48:60 /dev/sda
# Method 3: Trigger scheduled test email
sudo smartctl -t short /dev/sda
sudo smartctl -H /dev/sda
For more granular control, consider these smartd.conf directives:
DEVICESCAN -H -m admin@example.com -M exec /usr/local/bin/smartd-alert.sh \
-s (S/../.././02|L/../../6/03) -d removable -n standby -W 4,40,45
If alerts aren't arriving, check these systems:
# View mail queue
sudo mailq
# Check system mail logs
sudo tail -f /var/log/mail.log
# Test mail delivery manually
echo "Test message" | mail -s "SMART Alert Test" user@domain.com
Here's a sample script to enhance smartd monitoring:
#!/bin/bash
# smartd-alert.sh - Custom alert handler
RECIPIENT="admin@example.com"
SUBJECT="[SMART Alert] $SMARTD_FAILTYPE on $SMARTD_DEVICE"
MESSAGE="$SMARTD_MESSAGE\n\nFull report:\n$(smartctl -a $SMARTD_DEVICE)"
echo -e "$MESSAGE" | mail -s "$SUBJECT" "$RECIPIENT"
logger -t smartd "$SUBJECT"
The configuration you've implemented is technically correct for basic email alert functionality, but let's verify the complete setup and explore testing methods:
# Current configuration check
sudo systemctl status smartd
sudo smartctl -a /dev/sda | grep -i "SMART support"
Your /etc/smartd.conf
line contains all necessary parameters, but these system components must also be functional:
- Mail Transfer Agent (MTA) like Postfix or Exim installed and configured
- Proper DNS resolution for email delivery
- Correct permissions on mail queue directory
Use these methods to simulate failure conditions:
# Method 1: Force attribute change (non-destructive)
sudo smartctl -v 1,raw -s v 1,raw /dev/sda
# Method 2: Trigger self-test failure (non-destructive)
sudo smartctl -t select,10-20 /dev/sda
sudo smartctl -l selftest /dev/sda
For production systems, consider enhancing your configuration:
# /etc/smartd.conf example with multiple recipients and detailed reporting
DEVICESCAN -H -m admin@domain.com,backup@domain.com \
-M exec /usr/local/bin/smartd-alert.sh \
-s (S/../.././02|L/../../7/03) \
-a -o on -S on -W 4,40,45 -n standby,15 -R 5
If alerts aren't arriving, check these logs:
# System logs for SMARTD activity
journalctl -u smartd -f
# Mail server logs
tail -f /var/log/mail.log
grep smartd /var/log/syslog
For more flexible notifications, implement a custom script:
#!/bin/bash
# /usr/local/bin/smartd-alert.sh
SUBJECT="SMART Alert on $(hostname)"
BODY="SMART error detected:
$(cat /dev/stdin)
Device: $SMARTD_DEVICE
Failure: $SMARTD_FAILTYPE
"
echo "$BODY" | mailx -s "$SUBJECT" admin@domain.com
curl -X POST -H "Content-Type: application/json" \
-d '{"text":"SMART Alert: '"$SUBJECT"'","channel":"#alerts"}' \
https://hooks.slack.com/services/YOUR/WEBHOOK/PATH