Add disk monitoring to blowhole

Signed-off-by: magic_rb <magic_rb@redalder.org>
This commit is contained in:
magic_rb 2023-12-03 20:00:10 +01:00
parent e8100d690e
commit ad6a5f6784
No known key found for this signature in database
GPG key ID: 08D5287CC5DDCA0E
3 changed files with 85 additions and 0 deletions

View file

@ -44,6 +44,7 @@ in
./watchdog.nix
./nixpkgs.nix
./users.nix
./disk_monitoring.nix
./sol.nix
../../common/remote_access.nix
./microvms.nix

View file

@ -0,0 +1,76 @@
{
lib,
pkgs,
config,
...
}: let
inherit (lib) concatMapStringsSep;
cfg = config.services.smartd;
smartdNotify = pkgs.writeShellScript "smartd-notify-matrix" ''
while [[ $# > 0 ]] ; do
case "$1" in
-i)
shift 2
;;
*)
;;
esac
done
{
${pkgs.coreutils}/bin/cat <<EOF
smartd on \`<blowhole>\`
$SMARTD_SUBJECT
\`\`\`
$SMARTD_FULLMESSAGE
\`\`\`
\`\`\`
$(${pkgs.smartmontools}/sbin/smartctl -a -d "$SMARTD_DEVICETYPE" "$SMARTD_DEVICE")
\`\`\`
EOF
} | ${pkgs.matrix-commander-rs}/bin/matrix-commander-rs -c /var/secrets/matrix-smartd.json -s /var/lib/matrix-commander --markdown -m -
'';
smartdConfig = pkgs.writeText "smartd.conf" ''
DEFAULT -m <nomailer> -M exec ${smartdNotify} -M test -a
${concatMapStringsSep "\n" (d: "${d.device} ${d.options}") cfg.devices}
'';
in {
services.smartd = {
# The module needs fixing
enable = false;
devices = map (x: {device = "/dev/disk/by-id/" + x;}) [
# Old Skyhawks
"ata-ST1000VX005-2EZ102_Z9CBQKCQ"
"ata-ST1000VX005-2EZ102_Z9CBQLDS"
# NAS WD Reds
"ata-WDC_WD40EFZX-68AWUN0_WD-WX82DA1C79SK"
"ata-WDC_WD40EFZX-68AWUN0_WD-WXA2DA1C9JKA"
# Boot SSD
"ata-Apacer_AS350_128GB_2021020103001990"
# Database SSDs
"nvme-KINGSTON_SA2000M8250G_50026B76844F4629"
"nvme-KINGSTON_SA2000M8250G_50026B76851B664C"
];
extraOptions = ["-M" "exec ${smartdNotify}" "-M" "test"];
};
systemd.services.smartd = {
description = "S.M.A.R.T. Daemon";
wantedBy = ["multi-user.target"];
serviceConfig.ExecStart = "${pkgs.smartmontools}/sbin/smartd --no-fork --configfile=${smartdConfig} -s /var/lib/smartd/";
};
}

View file

@ -82,6 +82,14 @@ in
device = "blowhole-zpool/persist/vault";
fsType = "zfs";
};
"/var/lib/matrix-commander" = {
device = "blowhole-zpool/persist/matrix-commander";
fsType = "zfs";
};
"/var/lib/smartd" = {
device = "blowhole-zpool/persist/smartd";
fsType = "zfs";
};
}
// secret.mounts.blowhole or {};
}