From e8d50f14185867d490f002aa5c408343ea5ea062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Fri, 19 Apr 2024 23:43:13 +0200 Subject: Factorize smartd monitoring --- flakes/flake.lock | 22 +++++++-------- flakes/private/monitoring/flake.nix | 55 +++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 11 deletions(-) (limited to 'flakes') diff --git a/flakes/flake.lock b/flakes/flake.lock index 85690fa..991a73b 100644 --- a/flakes/flake.lock +++ b/flakes/flake.lock @@ -2815,7 +2815,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-A50vXg0qfzUhyQZKToEseYsLgtaYke41KE/4uuyj+PY=", + "narHash": "sha256-Lpe56lKWhlMQiQoCgvMJuqJtJ8+szDldjqMAGyt2U3U=", "path": "../../flakes/private/monitoring", "type": "path" }, @@ -2833,7 +2833,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-A50vXg0qfzUhyQZKToEseYsLgtaYke41KE/4uuyj+PY=", + "narHash": "sha256-Lpe56lKWhlMQiQoCgvMJuqJtJ8+szDldjqMAGyt2U3U=", "path": "../../flakes/private/monitoring", "type": "path" }, @@ -2851,7 +2851,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-A50vXg0qfzUhyQZKToEseYsLgtaYke41KE/4uuyj+PY=", + "narHash": "sha256-Lpe56lKWhlMQiQoCgvMJuqJtJ8+szDldjqMAGyt2U3U=", "path": "../../flakes/private/monitoring", "type": "path" }, @@ -2869,7 +2869,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-A50vXg0qfzUhyQZKToEseYsLgtaYke41KE/4uuyj+PY=", + "narHash": "sha256-Lpe56lKWhlMQiQoCgvMJuqJtJ8+szDldjqMAGyt2U3U=", "path": "../../flakes/private/monitoring", "type": "path" }, @@ -3753,7 +3753,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-KL5aC6l/mM+ucHadjCtlSY6iBZ9/VKRf2Rgw2tjwfqo=", + "narHash": "sha256-90nIfmXTv1DCJThIjtlNtnkMxefYJMHLp0CHmIekgDc=", "path": "../systems/backup-2", "type": "path" }, @@ -3776,7 +3776,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-VliQ62boc8jNgPCBX6JjVS/pA6YoikZVkvE1xxHAITk=", + "narHash": "sha256-kUhSjG2OtbZMeIEykJGKUC2RovZ1prxXc8aIckE0auI=", "path": "../systems/dilion", "type": "path" }, @@ -3824,7 +3824,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-YVJi4KPT8rsGNzZshYfUyz9l27QGAEsb8Iyu3O0/bMA=", + "narHash": "sha256-20vFVAd2/24Q0Lewy0eNXf94eTY96cFE8mPeKtvT5jY=", "path": "../systems/eldiron", "type": "path" }, @@ -3850,7 +3850,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-HiDwzScPHp084MwtWET+17WbrWf3zs9qJzv/EqNaSqM=", + "narHash": "sha256-BHpsgdt0NuJHTVvfTrsnNlOZdSBtPy/cTidd8sEIhx4=", "path": "../systems/monitoring-1", "type": "path" }, @@ -3875,7 +3875,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-YWEuXALLICHE+WsMtMuiCm6b2IRQyJrFpfMgH6ZLD0A=", + "narHash": "sha256-lT2cXjUGDFOzRtqF4p0oyFCR4gv+VEjthk4FMbOzrL0=", "path": "../systems/quatresaisons", "type": "path" }, @@ -7384,7 +7384,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-A50vXg0qfzUhyQZKToEseYsLgtaYke41KE/4uuyj+PY=", + "narHash": "sha256-Lpe56lKWhlMQiQoCgvMJuqJtJ8+szDldjqMAGyt2U3U=", "path": "../../flakes/private/monitoring", "type": "path" }, @@ -8294,7 +8294,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-A50vXg0qfzUhyQZKToEseYsLgtaYke41KE/4uuyj+PY=", + "narHash": "sha256-Lpe56lKWhlMQiQoCgvMJuqJtJ8+szDldjqMAGyt2U3U=", "path": "./private/monitoring", "type": "path" }, diff --git a/flakes/private/monitoring/flake.nix b/flakes/private/monitoring/flake.nix index b7c3997..5610d67 100644 --- a/flakes/private/monitoring/flake.nix +++ b/flakes/private/monitoring/flake.nix @@ -164,6 +164,13 @@ Whether to enable monitoring. ''; }; + smartdDisks = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = []; + description = '' + List of smartd disks ids (symlinks in /dev/disk/by-id/) to monitor + ''; + }; master = lib.mkOption { type = lib.types.bool; default = false; @@ -261,6 +268,54 @@ objectDefs = self.lib.toObjects cfg.objects; }; + + myServices.monitoring.objects.service = builtins.map (d: { + service_description = "Disk /dev/disk/by-id/${d} is sane"; + use = "local-service"; + check_command = [ "check_smartctl" "/dev/disk/by-id/${d}" ]; + __passive_servicegroups = "webstatus-resources"; + + check_interval = 60; + }) cfg.smartdDisks; + + systemd = let + checkShortTimer = { + timerConfig = { + OnCalendar = "monthly"; + RandomizedDelaySec = "3 weeks"; + FixedRandomDelay = true; + }; + wantedBy = [ "timers.target" ]; + }; + checkLongTimer = { + timerConfig = { + OnCalendar = "monthly"; + RandomizedDelaySec = "3 weeks"; + FixedRandomDelay = true; + }; + wantedBy = [ "timers.target" ]; + }; + toSDTimers = id: { + "check-smartd-long-${id}" = checkLongTimer; + "check-smartd-short-${id}" = checkShortTimer; + }; + toCheckService = id: type: { + description = "Run ${type} smartctl test for /dev/disk/by-id/${id}"; + after = [ "multi-user.target" ]; + serviceConfig = { + Type = "oneshot"; + ExecStart = "${pkgs.smartmontools}/bin/smartctl -t ${type} /dev/disk/by-id/${id}"; + }; + }; + toSDServices = id: { + "check-smartd-long-${id}" = toCheckService id "long"; + "check-smartd-short-${id}" = toCheckService id "short"; + }; + + in { + services = lib.attrsets.mergeAttrsList (builtins.map toSDServices cfg.smartdDisks); + timers = lib.attrsets.mergeAttrsList (builtins.map toSDTimers cfg.smartdDisks); + }; }; }; }; -- cgit v1.2.3