{ config, pkgs, ... }: let smartd_notifier = pkgs.writeScript "smartd-notify.sh" '' #!${pkgs.bash}/bin/bash # 1. Send Technical Email to Admin ADMIN_EMAIL="${config.email.adminAddress}" SUBJECT="Numbus Server Alert: $SMARTD_FAILTYPE on $SMARTD_DEVICE" TECH_BODY=" SMARTD Alert Details: Device: $SMARTD_DEVICE Type: $SMARTD_DEVICETYPE Failure Type: $SMARTD_FAILTYPE Message: $SMARTD_MESSAGE Full Message: $SMARTD_FULLMESSAGE " printf "Subject: [ADMIN] $SUBJECT\n\n$TECH_BODY" | /run/wrappers/bin/sendmail -t "$ADMIN_EMAIL" # 2. Send Friendly Email to Owner OWNER_NAME=$(cat /etc/numbus-server/owner 2>/dev/null || echo "User") USER_EMAIL="${config.email.toAddress}" FRIENDLY_BODY="Hello $OWNER_NAME, We detected a potential hardware issue on your server ($SMARTD_DEVICE). Don't panic! The administrator has been notified and received the technical details. They will contact you if any action is required on your part. Your Numbus Server" printf "Subject: [Alert] Hardware check on your server\n\n$FRIENDLY_BODY" | /run/wrappers/bin/sendmail -t "$USER_EMAIL" ''; in { ### --> SMART disk heath services.smartd = { enable = true; defaults.autodetected = "-a -o on -S on -s (S/../.././00|L/../../6/01) -n standby,q -M exec ${smartd_notifier}"; notifications = { wall = { enable = true; }; mail = { enable = true; sender = config.email.fromAddress; recipient = "${config.email.toAddress},${config.email.adminAddress}"; }; }; }; ### SMART disk heath <-- }