]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - flakes/private/monitoring/myplugins.nix
Add monitoring script with smartctl
[perso/Immae/Config/Nix.git] / flakes / private / monitoring / myplugins.nix
index f76f2c1a4dfe93dbe79a5978d09d2331758a3280..bb3a383c05ff8fd812c8f9e277a68ce0366994ec 100644 (file)
@@ -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$\"";