summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Simons <simons@cryp.to>2011-07-21 19:32:15 +0000
committerPeter Simons <simons@cryp.to>2011-07-21 19:32:15 +0000
commit3a1b6266e4cae111d0c1e72f7dad5a20220be5fa (patch)
treefd6b9f8f0e688f0b9ca1fff4b0819da836098b15
parent7c6c50a3bff8dea7a3382b8c47e4395b193165e9 (diff)
downloadnixlib-3a1b6266e4cae111d0c1e72f7dad5a20220be5fa.tar
nixlib-3a1b6266e4cae111d0c1e72f7dad5a20220be5fa.tar.gz
nixlib-3a1b6266e4cae111d0c1e72f7dad5a20220be5fa.tar.bz2
nixlib-3a1b6266e4cae111d0c1e72f7dad5a20220be5fa.tar.lz
nixlib-3a1b6266e4cae111d0c1e72f7dad5a20220be5fa.tar.xz
nixlib-3a1b6266e4cae111d0c1e72f7dad5a20220be5fa.tar.zst
nixlib-3a1b6266e4cae111d0c1e72f7dad5a20220be5fa.zip
modules/services/monitoring/smartd.nix: added services.smartd.devices option to configure list of devices to monitor
By default -- if this option is unset --, all connected devices will be
monitored. Hard-coding the list of devices is worth-while, though, because this
will also configure smartd to send e-mail messages to 'root' when a test fails.

svn path=/nixos/trunk/; revision=27888
-rw-r--r--modules/services/monitoring/smartd.nix41
1 files changed, 39 insertions, 2 deletions
diff --git a/modules/services/monitoring/smartd.nix b/modules/services/monitoring/smartd.nix
index bf523d4f3f8c..94a01eafc57a 100644
--- a/modules/services/monitoring/smartd.nix
+++ b/modules/services/monitoring/smartd.nix
@@ -6,6 +6,30 @@ let
 
   cfg = config.services.smartd;
 
+  smartdMail = pkgs.writeScript "smartdmail.sh" ''
+    #! /bin/sh
+    TMPNAM=/tmp/smartd-message.$$.tmp
+    if test -n "$SMARTD_ADDRESS"; then
+      echo  >"$TMPNAM" "From: smartd <root>"
+      echo >>"$TMPNAM" 'To: undisclosed-recipients:;'
+      echo >>"$TMPNAM" "Subject: $SMARTD_SUBJECT"
+      echo >>"$TMPNAM"
+      echo >>"$TMPNAM" "Failure on $SMARTD_DEVICESTRING: $SMARTD_FAILTYPE"
+      echo >>"$TMPNAM"
+      cat  >>"$TMPNAM"
+      ${pkgs.smartmontools}/sbin/smartctl >>"$TMPNAM" -a -d "$SMARTD_DEVICETYPE" "$SMARTD_DEVICE"
+      /var/setuid-wrappers/sendmail  <"$TMPNAM" -f "$SENDER" -i "$SMARTD_ADDRESS"
+    fi
+  '';
+
+  smartdConf = pkgs.writeText "smartd.conf" (concatMapStrings (device:
+    ''
+      ${device} -m root -M exec ${smartdMail}
+    ''
+    ) cfg.devices);
+
+  smartdFlags = if (cfg.devices == []) then "" else "--configfile=${smartdConf}";
+
 in
 
 {
@@ -20,10 +44,23 @@ in
         type = types.bool;
         example = "true";
         description = ''
-          Run smartd from the smartmontools package.
+          Run smartd from the smartmontools package. Note that e-mail
+          notifications will not be enabled unless you configure the list of
+          devices with <varname>services.smartd.devices</varname> as well.
         '';
       };
 
+      devices = mkOption {
+        default = [];
+        example = ["/dev/sda" "/dev/sdb"];
+        description = ''
+          List of devices to monitor. By default -- if this list is empty --,
+          smartd will monitor all devices connected to the machine at the time
+          it's being run. Configuring this option has the added benefit of
+          enabling e-mail notifications to "root" every time smartd detects an
+          error.
+        '';
+       };
     };
 
   };
@@ -40,7 +77,7 @@ in
 
         daemonType = "daemon";
 
-        exec = "${pkgs.smartmontools}/sbin/smartd";
+        exec = "${pkgs.smartmontools}/sbin/smartd --pidfile=/var/run/smartd.pid ${smartdFlags}";
       };
 
   };