From 408ce9363bf574796487fedfe59a4a2ff0cbb4cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sat, 13 Apr 2024 12:39:31 +0200 Subject: Add monitoring script with smartctl --- flakes/flake.lock | 22 +++++++++++----------- flakes/private/monitoring/myplugins.nix | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 11 deletions(-) (limited to 'flakes') diff --git a/flakes/flake.lock b/flakes/flake.lock index 17264a4..85690fa 100644 --- a/flakes/flake.lock +++ b/flakes/flake.lock @@ -2815,7 +2815,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-PicwNqwQaCKtN5zPpTfpSDRXbyn9xh8aHqoPnm9cFz8=", + "narHash": "sha256-A50vXg0qfzUhyQZKToEseYsLgtaYke41KE/4uuyj+PY=", "path": "../../flakes/private/monitoring", "type": "path" }, @@ -2833,7 +2833,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-PicwNqwQaCKtN5zPpTfpSDRXbyn9xh8aHqoPnm9cFz8=", + "narHash": "sha256-A50vXg0qfzUhyQZKToEseYsLgtaYke41KE/4uuyj+PY=", "path": "../../flakes/private/monitoring", "type": "path" }, @@ -2851,7 +2851,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-PicwNqwQaCKtN5zPpTfpSDRXbyn9xh8aHqoPnm9cFz8=", + "narHash": "sha256-A50vXg0qfzUhyQZKToEseYsLgtaYke41KE/4uuyj+PY=", "path": "../../flakes/private/monitoring", "type": "path" }, @@ -2869,7 +2869,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-PicwNqwQaCKtN5zPpTfpSDRXbyn9xh8aHqoPnm9cFz8=", + "narHash": "sha256-A50vXg0qfzUhyQZKToEseYsLgtaYke41KE/4uuyj+PY=", "path": "../../flakes/private/monitoring", "type": "path" }, @@ -3753,7 +3753,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-B2JdIp5q/8/LurN4lXB17C1+mpEKeqPzObmNOObO5rQ=", + "narHash": "sha256-KL5aC6l/mM+ucHadjCtlSY6iBZ9/VKRf2Rgw2tjwfqo=", "path": "../systems/backup-2", "type": "path" }, @@ -3776,7 +3776,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-dWAbGxB91utxwTlxsJZdp2OSaIAo8y5LXjdTCFMRn+4=", + "narHash": "sha256-VliQ62boc8jNgPCBX6JjVS/pA6YoikZVkvE1xxHAITk=", "path": "../systems/dilion", "type": "path" }, @@ -3824,7 +3824,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-OvT4dJGxdFBUgwjTu6FzejI/euWYXWsX1vD952B8934=", + "narHash": "sha256-YVJi4KPT8rsGNzZshYfUyz9l27QGAEsb8Iyu3O0/bMA=", "path": "../systems/eldiron", "type": "path" }, @@ -3850,7 +3850,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-6hqQjoy1lyIJziqe0AJ62aq62soi5D14NKOzNEY3SsQ=", + "narHash": "sha256-HiDwzScPHp084MwtWET+17WbrWf3zs9qJzv/EqNaSqM=", "path": "../systems/monitoring-1", "type": "path" }, @@ -3875,7 +3875,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-yBuAfW59X0e840QBFtQrefG3T/IQIQSXiZ4WU2/+gBI=", + "narHash": "sha256-YWEuXALLICHE+WsMtMuiCm6b2IRQyJrFpfMgH6ZLD0A=", "path": "../systems/quatresaisons", "type": "path" }, @@ -7384,7 +7384,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-PicwNqwQaCKtN5zPpTfpSDRXbyn9xh8aHqoPnm9cFz8=", + "narHash": "sha256-A50vXg0qfzUhyQZKToEseYsLgtaYke41KE/4uuyj+PY=", "path": "../../flakes/private/monitoring", "type": "path" }, @@ -8294,7 +8294,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-PicwNqwQaCKtN5zPpTfpSDRXbyn9xh8aHqoPnm9cFz8=", + "narHash": "sha256-A50vXg0qfzUhyQZKToEseYsLgtaYke41KE/4uuyj+PY=", "path": "./private/monitoring", "type": "path" }, diff --git a/flakes/private/monitoring/myplugins.nix b/flakes/private/monitoring/myplugins.nix index f76f2c1..bb3a383 100644 --- a/flakes/private/monitoring/myplugins.nix +++ b/flakes/private/monitoring/myplugins.nix @@ -284,6 +284,30 @@ in ]} ''; }; + smartctl = { + commands = { + check_smartctl = "$USER2$/check_smartctl -i auto -d $ARG1$"; + }; + chunk = let + smartPlugin = pkgs.fetchurl { + url = "https://www.claudiokuenzler.com/monitoring-plugins/check_smart.pl"; + sha256 = "sha256-gxGkzyycUl+I3WziKhOnZSoQjpqbPqjbunfUQxmeb7w="; + }; + in '' + cp ${smartPlugin} $out/check_smartctl + chmod +x $out/check_smartctl + patchShebangs $out + substituteInPlace $out/check_smartctl --replace "/usr/bin /bin /usr/sbin /sbin /usr/local/bin /usr/local/sbin" "${pkgs.smartmontools}/bin" + substituteInPlace $out/check_smartctl --replace "sudo" "${sudo}" + ''; + + sudo = _: { + commands = [ + { command = "${pkgs.smartmontools}/bin/smartctl *"; options = [ "NOPASSWD" ]; } + ]; + runAs = "root"; + }; + }; mysql = { commands = { check_mysql_replication = "${sudo} -u mysql $USER2$/check_mysql_replication \"$ARG1$\" \"$ARG2$\""; -- cgit v1.2.3