diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2017-07-30 19:38:50 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2017-07-30 19:38:50 +0200 |
commit | 0293edb691c5369b0cc772ec6690cf53164c91d8 (patch) | |
tree | d1ca1bd8ddcecec176db67d6c837bb823939cc83 /custom | |
parent | eaf585b8d3082c69a3659743ca0b685063321d98 (diff) | |
download | nixos-0293edb691c5369b0cc772ec6690cf53164c91d8.tar nixos-0293edb691c5369b0cc772ec6690cf53164c91d8.tar.gz nixos-0293edb691c5369b0cc772ec6690cf53164c91d8.tar.bz2 nixos-0293edb691c5369b0cc772ec6690cf53164c91d8.tar.xz nixos-0293edb691c5369b0cc772ec6690cf53164c91d8.zip |
…
Diffstat (limited to 'custom')
-rw-r--r-- | custom/unit-status-mail.nix | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/custom/unit-status-mail.nix b/custom/unit-status-mail.nix index 58136724..1b87a0b0 100644 --- a/custom/unit-status-mail.nix +++ b/custom/unit-status-mail.nix | |||
@@ -5,7 +5,7 @@ with lib; | |||
5 | let | 5 | let |
6 | cfg = config.systemd.status-mail; | 6 | cfg = config.systemd.status-mail; |
7 | 7 | ||
8 | serviceCfg = traceValSeq (foldl singleServiceCfg {} cfg.onFailure); | 8 | serviceCfg = foldl singleServiceCfg {} cfg.onFailure; |
9 | singleServiceCfg = attrs: unitName: attrs // (setAttrByPath [unitName "onFailure"] ["unit-status-mail@%n.service"]); | 9 | singleServiceCfg = attrs: unitName: attrs // (setAttrByPath [unitName "onFailure"] ["unit-status-mail@%n.service"]); |
10 | in { | 10 | in { |
11 | options = { | 11 | options = { |
@@ -29,37 +29,37 @@ in { | |||
29 | }; | 29 | }; |
30 | 30 | ||
31 | config = mkIf (cfg.onFailure != []) { | 31 | config = mkIf (cfg.onFailure != []) { |
32 | systemd.services = config.systemd.services // serviceCfg; | 32 | systemd.services = { |
33 | "unit-status-mail@" = { | ||
34 | serviceConfig = { | ||
35 | Type = "oneshot"; | ||
36 | }; | ||
37 | scriptArgs = "%I \"Hostname: %H\" \"Machine-ID: %m\" \"Boot-ID: %b\""; | ||
38 | script = '' | ||
39 | #!${pkgs.stdenv.shell} | ||
40 | MAILTO="${cfg.recipient}" | ||
41 | MAILFROM="unit-status-mailer" | ||
42 | UNIT=$1 | ||
33 | 43 | ||
34 | systemd.services."unit-status-mail@" = { | 44 | EXTRA="" |
35 | serviceConfig = { | 45 | for e in "''${@:2}"; do |
36 | Type = "oneshot"; | 46 | EXTRA+="$e"$'\n' |
37 | }; | 47 | done |
38 | scriptArgs = "%I \"Hostname: %H\" \"Machine-ID: %m\" \"Boot-ID: %b\""; | 48 | |
39 | script = '' | 49 | UNITSTATUS=$(systemctl status $UNIT) |
40 | #!${pkgs.stdenv.shell} | 50 | |
41 | MAILTO="${cfg.recipient}" | 51 | ${config.security.wrapperDir}/sendmail $MAILTO <<EOF |
42 | MAILFROM="unit-status-mailer" | 52 | From:$MAILFROM |
43 | UNIT=$1 | 53 | To:$MAILTO |
44 | 54 | Subject:Status of $UNIT | |
45 | EXTRA="" | ||
46 | for e in "''${@:2}"; do | ||
47 | EXTRA+="$e"$'\n' | ||
48 | done | ||
49 | |||
50 | UNITSTATUS=$(systemctl status $UNIT) | ||
51 | |||
52 | ${config.security.wrapperDir}/sendmail $MAILTO <<EOF | ||
53 | From:$MAILFROM | ||
54 | To:$MAILTO | ||
55 | Subject:Status of $UNIT | ||
56 | 55 | ||
57 | Status report for unit: $UNIT | 56 | Status report for unit: $UNIT |
58 | $EXTRA | 57 | $EXTRA |
59 | 58 | ||
60 | $UNITSTATUS | 59 | $UNITSTATUS |
61 | EOF | 60 | EOF |
62 | ''; | 61 | ''; |
63 | }; | 62 | }; |
63 | } // serviceCfg; | ||
64 | }; | 64 | }; |
65 | } | 65 | } |