From 6d1d3be3b3791d11864dacc0f63d94f0ca1b0f6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Numbus?= Date: Sun, 11 Jan 2026 18:36:13 +0100 Subject: [PATCH] SMART custom notifications (to test) --- deploy.sh | 6 ++++- templates/nix-config/misc/smart.nix | 38 ++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/deploy.sh b/deploy.sh index af65fdd..7bd191e 100644 --- a/deploy.sh +++ b/deploy.sh @@ -10,7 +10,7 @@ export GUM_SPIN_TITLE_BOLD=true NECESSARY_VARIABLES_LIST=("TARGET_HOST" "REMOTE_PASS" "SSH_PUBLIC_KEY" "DOMAIN_NAME" \ "EMAIL_ADDRESS" "CF_DNS_API_TOKEN" "SENDER_EMAIL_ADDRESS" "SENDER_EMAIL_ADDRESS_PASSWORD" \ "SENDER_EMAIL_DOMAIN" "SENDER_EMAIL_PORT" "HOME_ROUTER_SUBNET" "HOME_ROUTER_IP" \ -"HOME_SERVER_IP" "SELECTED_SERVICES") +"HOME_SERVER_IP" "SELECTED_SERVICES" "SERVER_OWNER_NAME") ### Default settings <-- user_input() { @@ -67,6 +67,7 @@ necessary_information() { user_input "DOMAIN_NAME" " Please provide the domain name (FQDN) your home server will use :" "For example : yourdomain.com" "${DOMAIN_REGEX}" "Invalid domain name format." user_input "EMAIL_ADDRESS" " Please provide a valid email address (will be used for ACME, and your services) :" "For example : myemail@gmail.com" "${EMAIL_REGEX}" "Invalid email address format." user_input "CF_DNS_API_TOKEN" " Please provide a cloudflare API token with DNS zone permission :" "For example : bA7hdvCOuXGytlNKohi3ZGtlVpf5CHpLuCMiJrE" "" "" "true" + user_input "SERVER_OWNER_NAME" " Please provide the name of the server owner :" "For example : Steve" "" "" echo -e "\n\n➡️ Some services will be able to send you emails. For that you need an email that supports sending emails (like Gmail for example)\n" # SMTP SETTINGS @@ -626,6 +627,7 @@ nix_generation() { cp -avu templates/nix-config/flake.nix final-nix-config/etc/nixos/ cp -avu templates/nix-config/misc/* final-nix-config/etc/nixos/misc/ + echo "${SERVER_OWNER_NAME:-User}" > final-nix-config/etc/numbus-server/owner echo -e "\n✅ Writing correct ips to configuration.nix..." sed -i "s|HOME_SERVER_IP|${HOME_SERVER_IP}|g" final-nix-config/etc/nixos/misc/networking.nix sed -i "s|HOME_ROUTER_IP|${HOME_ROUTER_IP}|g" final-nix-config/etc/nixos/misc/networking.nix @@ -712,6 +714,8 @@ export_configuration() { cp -avu templates/post-install/numbus-server.sh "$CONFIG_EXPORT_DIR" echo "export TARGET_INTERFACE=\"${TARGET_INTERFACE}\"" >> $CONFIG_EXPORT_FILE + echo -e "\n# SERVER SETTINGS" >> $CONFIG_EXPORT_FILE + echo "export SERVER_OWNER_NAME=\"${SERVER_OWNER_NAME:-User}\"" >> $CONFIG_EXPORT_FILE echo -e "\n# DISK SETTINGS" >> $CONFIG_EXPORT_FILE echo "export BOOT_DISKS_ID=\"(${BOOT_DISKS_ID[@]})\"" >> $CONFIG_EXPORT_FILE echo "export DATA_DISKS_ID=\"(${DATA_DISKS_ID[@]})\"" >> $CONFIG_EXPORT_FILE diff --git a/templates/nix-config/misc/smart.nix b/templates/nix-config/misc/smart.nix index f6b6803..019f7e6 100644 --- a/templates/nix-config/misc/smart.nix +++ b/templates/nix-config/misc/smart.nix @@ -1,9 +1,45 @@ { 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"; + defaults.autodetected = "-a -o on -S on -s (S/../.././00|L/../../6/01) -n standby,q -M exec ${smartd_notifier}"; notifications = { wall = { enable = true;