Restructure smart report module
This commit is contained in:
parent
a91efe6818
commit
b991e24a7a
5 changed files with 115 additions and 47 deletions
|
|
@ -15,8 +15,6 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
programs.zsh.shellAliases = {
|
programs.zsh.shellAliases = {
|
||||||
# Disk health monitoring
|
|
||||||
smart-report = "sudo SMART_DRIVES='/dev/disk/by-id/ata-ZHITAI_SC001_XT_1000GB_ZTB401TAB244431J4R:ZFS_Mirror_1;/dev/disk/by-id/ata-ZHITAI_SC001_XT_1000GB_ZTB401TAB244431KEG:ZFS_Mirror_2;/dev/disk/by-id/ata-HGST_HUH721212ALE604_5PK2N4GB:Data_Drive_1_12TB;/dev/disk/by-id/ata-HGST_HUH721212ALE604_5PJ7Z3LE:Data_Drive_2_12TB;/dev/disk/by-id/ata-ST16000NM000J-2TW103_WRS0F8BE:Parity_Drive_16TB' /home/yanlin/.config/nix/scripts/daily-smart-report.sh Ac9qKFH5cA.7Yly";
|
|
||||||
move-inbox = "cp -rl /mnt/storage/Media/downloads/.inbox/* /mnt/storage/Media/downloads/inbox && chown -R yanlin:users /mnt/storage/Media/downloads/inbox";
|
move-inbox = "cp -rl /mnt/storage/Media/downloads/.inbox/* /mnt/storage/Media/downloads/inbox && chown -R yanlin:users /mnt/storage/Media/downloads/inbox";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
../../../modules/borg-client.nix
|
../../../modules/borg-client.nix
|
||||||
../../../modules/webdav.nix
|
../../../modules/webdav.nix
|
||||||
../../../modules/container-updater.nix
|
../../../modules/container-updater.nix
|
||||||
|
../../../modules/smart-report.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
# GRUB bootloader with ZFS support
|
# GRUB bootloader with ZFS support
|
||||||
|
|
@ -252,26 +253,18 @@
|
||||||
hideDotFiles = true;
|
hideDotFiles = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
# Daily SMART report using the shell alias
|
# SMART disk health reporting
|
||||||
systemd.services.daily-smart-report = {
|
services.smart-report = {
|
||||||
description = "Daily SMART Health Report";
|
enable = true;
|
||||||
after = [ "multi-user.target" ];
|
enableSystemdService = true;
|
||||||
serviceConfig = {
|
schedule = "08:00:00";
|
||||||
Type = "oneshot";
|
gotifyToken = "Ac9qKFH5cA.7Yly";
|
||||||
User = "root";
|
drives = {
|
||||||
ExecStart = "${pkgs.zsh}/bin/zsh -c 'source /home/yanlin/.zshrc && smart-report'";
|
"/dev/disk/by-id/ata-ZHITAI_SC001_XT_1000GB_ZTB401TAB244431J4R" = "ZFS_Mirror_1";
|
||||||
StandardOutput = "journal";
|
"/dev/disk/by-id/ata-ZHITAI_SC001_XT_1000GB_ZTB401TAB244431KEG" = "ZFS_Mirror_2";
|
||||||
StandardError = "journal";
|
"/dev/disk/by-id/ata-HGST_HUH721212ALE604_5PK2N4GB" = "Data_Drive_1_12TB";
|
||||||
};
|
"/dev/disk/by-id/ata-HGST_HUH721212ALE604_5PJ7Z3LE" = "Data_Drive_2_12TB";
|
||||||
};
|
"/dev/disk/by-id/ata-ST16000NM000J-2TW103_WRS0F8BE" = "Parity_Drive_16TB";
|
||||||
|
|
||||||
systemd.timers.daily-smart-report = {
|
|
||||||
description = "Daily SMART Report Timer";
|
|
||||||
wantedBy = [ "timers.target" ];
|
|
||||||
timerConfig = {
|
|
||||||
OnCalendar = "08:00:00";
|
|
||||||
Persistent = true;
|
|
||||||
RandomizedDelaySec = "5m";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,6 @@
|
||||||
|
|
||||||
# Any ThinkPad-specific home configurations can be added here
|
# Any ThinkPad-specific home configurations can be added here
|
||||||
# For example, laptop-specific aliases or scripts
|
# For example, laptop-specific aliases or scripts
|
||||||
|
|
||||||
programs.zsh.shellAliases = {
|
|
||||||
# Disk health monitoring
|
|
||||||
smart-report = "sudo SMART_DRIVES='/dev/nvme0n1:System_SSD_ThinkPad' /home/yanlin/.config/nix/scripts/daily-smart-report.sh AieM4SJHFcyl7TC";
|
|
||||||
};
|
|
||||||
|
|
||||||
home.packages = with pkgs; [
|
home.packages = with pkgs; [
|
||||||
texlive.combined.scheme-full
|
texlive.combined.scheme-full
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
./hardware-configuration.nix
|
./hardware-configuration.nix
|
||||||
../../../modules/wireguard.nix
|
../../../modules/wireguard.nix
|
||||||
../../../modules/borg-server.nix
|
../../../modules/borg-server.nix
|
||||||
|
../../../modules/smart-report.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
# Bootloader - standard UEFI setup
|
# Bootloader - standard UEFI setup
|
||||||
|
|
@ -355,26 +356,14 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# Daily SMART report using the shell alias
|
# SMART disk health reporting
|
||||||
systemd.services.daily-smart-report = {
|
services.smart-report = {
|
||||||
description = "Daily SMART Health Report";
|
enable = true;
|
||||||
after = [ "multi-user.target" ];
|
enableSystemdService = true;
|
||||||
serviceConfig = {
|
schedule = "09:00:00";
|
||||||
Type = "oneshot";
|
gotifyToken = "AieM4SJHFcyl7TC";
|
||||||
User = "root";
|
drives = {
|
||||||
ExecStart = "${pkgs.zsh}/bin/zsh -c 'source /home/yanlin/.zshrc && smart-report'";
|
"/dev/nvme0n1" = "System_SSD_ThinkPad";
|
||||||
StandardOutput = "journal";
|
|
||||||
StandardError = "journal";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
systemd.timers.daily-smart-report = {
|
|
||||||
description = "Daily SMART Report Timer";
|
|
||||||
wantedBy = [ "timers.target" ];
|
|
||||||
timerConfig = {
|
|
||||||
OnCalendar = "09:00:00";
|
|
||||||
Persistent = true;
|
|
||||||
RandomizedDelaySec = "10m";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
93
modules/smart-report.nix
Normal file
93
modules/smart-report.nix
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
cfg = config.services.smart-report;
|
||||||
|
|
||||||
|
# Create the smart-report script wrapper
|
||||||
|
smartReportScript = pkgs.writeShellScriptBin "smart-report" ''
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Set environment variable if drives are configured
|
||||||
|
${optionalString (cfg.drives != {}) ''
|
||||||
|
export SMART_DRIVES="${concatStringsSep ";" (mapAttrsToList (device: name: "${device}:${name}") cfg.drives)}"
|
||||||
|
''}
|
||||||
|
|
||||||
|
# Execute the actual script
|
||||||
|
exec ${pkgs.bash}/bin/bash ${cfg.scriptPath} ${cfg.gotifyToken}
|
||||||
|
'';
|
||||||
|
|
||||||
|
in {
|
||||||
|
options.services.smart-report = {
|
||||||
|
enable = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = "Enable SMART disk health reporting";
|
||||||
|
};
|
||||||
|
|
||||||
|
drives = mkOption {
|
||||||
|
type = types.attrsOf types.str;
|
||||||
|
default = {};
|
||||||
|
description = "Drives to monitor (device path -> name mapping)";
|
||||||
|
example = {
|
||||||
|
"/dev/disk/by-id/ata-Samsung_SSD" = "System_SSD";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
scriptPath = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "/home/yanlin/.config/nix/scripts/daily-smart-report.sh";
|
||||||
|
description = "Path to the SMART report script";
|
||||||
|
};
|
||||||
|
|
||||||
|
gotifyToken = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "Gotify notification token";
|
||||||
|
};
|
||||||
|
|
||||||
|
schedule = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "08:00:00";
|
||||||
|
description = "Time to run the daily report (systemd calendar format)";
|
||||||
|
};
|
||||||
|
|
||||||
|
enableSystemdService = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = "Enable systemd timer for automatic daily reports";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
# Install the wrapper script package
|
||||||
|
environment.systemPackages = [ smartReportScript ];
|
||||||
|
|
||||||
|
# Configure systemd service if enabled
|
||||||
|
systemd.services.daily-smart-report = mkIf cfg.enableSystemdService {
|
||||||
|
description = "Daily SMART Health Report";
|
||||||
|
after = [ "multi-user.target" ];
|
||||||
|
path = with pkgs; [ smartmontools bash coreutils gnugrep gawk gnused curl ];
|
||||||
|
environment = {
|
||||||
|
SMART_DRIVES = concatStringsSep ";" (mapAttrsToList (device: name: "${device}:${name}") cfg.drives);
|
||||||
|
};
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
User = "root";
|
||||||
|
ExecStart = "${smartReportScript}/bin/smart-report";
|
||||||
|
StandardOutput = "journal";
|
||||||
|
StandardError = "journal";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.timers.daily-smart-report = mkIf cfg.enableSystemdService {
|
||||||
|
description = "Daily SMART Report Timer";
|
||||||
|
wantedBy = [ "timers.target" ];
|
||||||
|
timerConfig = {
|
||||||
|
OnCalendar = cfg.schedule;
|
||||||
|
Persistent = true;
|
||||||
|
RandomizedDelaySec = "5m";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue