ZFS: Difference between revisions
imported>Cyounkins ZED needs ZFS to be be built with mail features, added test pool for email testing |
imported>Cyounkins Under ZED, moved msmtp doc into separate page |
||
Line 514: | Line 514: | ||
== Mail notification for ZFS Event Daemon == | == Mail notification for ZFS Event Daemon == | ||
ZFS Event Daemon (zed) monitors events generated by the ZFS kernel module and runs configured tasks. It can be configured to send an email when a pool scrub is finished or a disk has failed. | ZFS Event Daemon (zed) monitors events generated by the ZFS kernel module and runs configured tasks. It can be configured to send an email when a pool scrub is finished or a disk has failed. [https://search.nixos.org/options?query=services.zfs.zed zed options] | ||
The <code>zfs</code> package must be built with mail features. The following override is needed as <code>zfs</code> is implicitly used in partition mounting: | The <code>zfs</code> package must be built with mail features. The following override is needed as <code>zfs</code> is implicitly used in partition mounting: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
nixpkgs.config.packageOverrides = pkgs: { | |||
zfsStable = pkgs.zfsStable.override { enableMail = true; }; | |||
}; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
A mail sender like [[msmtp]] or [[postfix]] is required. | |||
A minimal, testable ZED configuration example: | |||
<syntaxhighlight lang=" | <syntaxhighlight lang="nix"> | ||
services.zfs.zed.enableMail = true; | |||
root | services.zfs.zed.settings = { | ||
ZED_EMAIL_ADDR = [ "root" ]; | |||
ZED_NOTIFY_VERBOSE = true; | |||
}; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Above, <code>ZED_EMAIL_ADDR</code> is set to <code>root</code>, which most people will have an alias for in their mailer. You can change it to directly mail you: <code>ZED_EMAIL_ADDR = [ "you@example.com" ];</code> | |||
< | |||
ZED pulls in <code>mailutils</code> and runs <code>mail</code> by default, but you can override it with <code>ZED_EMAIL_PROG</code>. If using msmtp, you may need <code>ZED_EMAIL_PROG = "${pkgs.msmtp}/bin/msmtp";</code>. | |||
You can customize the mail command with <code>ZED_EMAIL_OPTS</code>. For example, if your upstream mail server requires a certain FROM address: <code>ZED_EMAIL_OPTS = "-r 'noreply@example.com' -s '@SUBJECT@' @ADDRESS@";</code> | |||
</ | |||
After a <code>sudo nixos-rebuild switch</code>, you can test ZED notifications by performing a scrub on an existing pool, or on a small test pool: | |||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
$ cd /tmp | $ cd /tmp | ||
Line 584: | Line 548: | ||
$ sudo zpool create test /tmp/sparse_file | $ sudo zpool create test /tmp/sparse_file | ||
$ sudo zpool scrub test | $ sudo zpool scrub test | ||
// Check for email | // Check for email when scrub is complete | ||
// Cleanup | |||
$ sudo zpool export test | $ sudo zpool export test | ||
$ rm sparse_file | $ rm sparse_file |