aboutsummaryrefslogtreecommitdiff
path: root/flakes/private
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2024-04-19 23:43:13 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2024-06-11 00:17:42 +0200
commite8d50f14185867d490f002aa5c408343ea5ea062 (patch)
treefda35affc1c4a03660d2367a05a5fee343a1bcf7 /flakes/private
parent408ce9363bf574796487fedfe59a4a2ff0cbb4cb (diff)
downloadNix-e8d50f14185867d490f002aa5c408343ea5ea062.tar.gz
Nix-e8d50f14185867d490f002aa5c408343ea5ea062.tar.zst
Nix-e8d50f14185867d490f002aa5c408343ea5ea062.zip
Factorize smartd monitoring
Diffstat (limited to 'flakes/private')
-rw-r--r--flakes/private/monitoring/flake.nix55
1 files changed, 55 insertions, 0 deletions
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 @@
164 Whether to enable monitoring. 164 Whether to enable monitoring.
165 ''; 165 '';
166 }; 166 };
167 smartdDisks = lib.mkOption {
168 type = lib.types.listOf lib.types.str;
169 default = [];
170 description = ''
171 List of smartd disks ids (symlinks in /dev/disk/by-id/) to monitor
172 '';
173 };
167 master = lib.mkOption { 174 master = lib.mkOption {
168 type = lib.types.bool; 175 type = lib.types.bool;
169 default = false; 176 default = false;
@@ -261,6 +268,54 @@
261 objectDefs = 268 objectDefs =
262 self.lib.toObjects cfg.objects; 269 self.lib.toObjects cfg.objects;
263 }; 270 };
271
272 myServices.monitoring.objects.service = builtins.map (d: {
273 service_description = "Disk /dev/disk/by-id/${d} is sane";
274 use = "local-service";
275 check_command = [ "check_smartctl" "/dev/disk/by-id/${d}" ];
276 __passive_servicegroups = "webstatus-resources";
277
278 check_interval = 60;
279 }) cfg.smartdDisks;
280
281 systemd = let
282 checkShortTimer = {
283 timerConfig = {
284 OnCalendar = "monthly";
285 RandomizedDelaySec = "3 weeks";
286 FixedRandomDelay = true;
287 };
288 wantedBy = [ "timers.target" ];
289 };
290 checkLongTimer = {
291 timerConfig = {
292 OnCalendar = "monthly";
293 RandomizedDelaySec = "3 weeks";
294 FixedRandomDelay = true;
295 };
296 wantedBy = [ "timers.target" ];
297 };
298 toSDTimers = id: {
299 "check-smartd-long-${id}" = checkLongTimer;
300 "check-smartd-short-${id}" = checkShortTimer;
301 };
302 toCheckService = id: type: {
303 description = "Run ${type} smartctl test for /dev/disk/by-id/${id}";
304 after = [ "multi-user.target" ];
305 serviceConfig = {
306 Type = "oneshot";
307 ExecStart = "${pkgs.smartmontools}/bin/smartctl -t ${type} /dev/disk/by-id/${id}";
308 };
309 };
310 toSDServices = id: {
311 "check-smartd-long-${id}" = toCheckService id "long";
312 "check-smartd-short-${id}" = toCheckService id "short";
313 };
314
315 in {
316 services = lib.attrsets.mergeAttrsList (builtins.map toSDServices cfg.smartdDisks);
317 timers = lib.attrsets.mergeAttrsList (builtins.map toSDTimers cfg.smartdDisks);
318 };
264 }; 319 };
265 }; 320 };
266 }; 321 };