summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--custom/unit-status-mail.nix60
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;
5let 5let
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"]);
10in { 10in {
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}