Author: simons
Date: Thu Jul 21 19:32:15 2011
New Revision: 27888
URL: https://svn.nixos.org/websvn/nix/?rev=27888&sc=1
Log:
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.
Modified:
nixos/trunk/modules/services/monitoring/smartd.nix
Modified: nixos/trunk/modules/services/monitoring/smartd.nix
==============================================================================
--- nixos/trunk/modules/services/monitoring/smartd.nix Thu Jul 21 19:16:21
2011 (r27887)
+++ nixos/trunk/modules/services/monitoring/smartd.nix Thu Jul 21 19:32:15
2011 (r27888)
@@ -6,6 +6,30 @@
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 @@
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 @@
daemonType = "daemon";
- exec = "${pkgs.smartmontools}/sbin/smartd";
+ exec = "${pkgs.smartmontools}/sbin/smartd
--pidfile=/var/run/smartd.pid ${smartdFlags}";
};
};
_______________________________________________
nix-commits mailing list
[email protected]
http://mail.cs.uu.nl/mailman/listinfo/nix-commits