diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2020-01-17 01:15:04 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2020-01-17 01:15:04 +0100 |
commit | 71a2425ed95120a6de3a41bb233b1066779d4c26 (patch) | |
tree | 007f2756abab644604577352da28b1fd4c20df44 /modules/private/mail | |
parent | 981fa80354fd6f00f49446777c38f77bd8a65f65 (diff) | |
download | Nix-71a2425ed95120a6de3a41bb233b1066779d4c26.tar.gz Nix-71a2425ed95120a6de3a41bb233b1066779d4c26.tar.zst Nix-71a2425ed95120a6de3a41bb233b1066779d4c26.zip |
Add e-mail checks monitoring
Diffstat (limited to 'modules/private/mail')
-rw-r--r-- | modules/private/mail/postfix.nix | 36 | ||||
-rw-r--r-- | modules/private/mail/relay.nix | 6 |
2 files changed, 38 insertions, 4 deletions
diff --git a/modules/private/mail/postfix.nix b/modules/private/mail/postfix.nix index 8fe06da..51f4de7 100644 --- a/modules/private/mail/postfix.nix +++ b/modules/private/mail/postfix.nix | |||
@@ -1,4 +1,4 @@ | |||
1 | { lib, pkgs, config, nodes, name, ... }: | 1 | { lib, pkgs, config, nodes, ... }: |
2 | { | 2 | { |
3 | config = lib.mkIf config.myServices.mail.enable { | 3 | config = lib.mkIf config.myServices.mail.enable { |
4 | services.duplyBackup.profiles.mail.excludeFile = '' | 4 | services.duplyBackup.profiles.mail.excludeFile = '' |
@@ -220,7 +220,13 @@ | |||
220 | ''; | 220 | ''; |
221 | scripts = lib.attrsets.mapAttrs (n: v: | 221 | scripts = lib.attrsets.mapAttrs (n: v: |
222 | toScript n (pkgs.callPackage (builtins.fetchGit { url = v.src.url; ref = "master"; rev = v.src.rev; }) { scriptEnv = v.env; }) | 222 | toScript n (pkgs.callPackage (builtins.fetchGit { url = v.src.url; ref = "master"; rev = v.src.rev; }) { scriptEnv = v.env; }) |
223 | ) config.myEnv.mail.scripts; | 223 | ) config.myEnv.mail.scripts // { |
224 | testmail = pkgs.writeScript "testmail" '' | ||
225 | #! ${pkgs.stdenv.shell} | ||
226 | ${pkgs.coreutils}/bin/touch \ | ||
227 | "/var/lib/naemon/checks/email/$(${pkgs.procmail}/bin/formail -x To: | ${pkgs.coreutils}/bin/tr -d ' <>')" | ||
228 | ''; | ||
229 | }; | ||
224 | in builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList (n: v: ''${n}: "|${v}"'') scripts); | 230 | in builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList (n: v: ''${n}: "|${v}"'') scripts); |
225 | mapFiles = let | 231 | mapFiles = let |
226 | recipient_maps = let | 232 | recipient_maps = let |
@@ -246,8 +252,12 @@ | |||
246 | ) config.myEnv.mail.postfix.backup_domains | 252 | ) config.myEnv.mail.postfix.backup_domains |
247 | ); | 253 | ); |
248 | virtual_map = { | 254 | virtual_map = { |
249 | virtual = pkgs.writeText "postfix-virtual" ( | 255 | virtual = let |
256 | cfg = config.myEnv.monitoring.email_check.eldiron; | ||
257 | address = "${cfg.mail_address}@${cfg.mail_domain}"; | ||
258 | in pkgs.writeText "postfix-virtual" ( | ||
250 | builtins.concatStringsSep "\n" ( | 259 | builtins.concatStringsSep "\n" ( |
260 | ["${address} testmail@localhost"] ++ | ||
251 | lib.attrsets.mapAttrsToList ( | 261 | lib.attrsets.mapAttrsToList ( |
252 | n: v: lib.optionalString v.external '' | 262 | n: v: lib.optionalString v.external '' |
253 | script_${n}@mail.immae.eu ${n}@localhost, scripts@mail.immae.eu | 263 | script_${n}@mail.immae.eu ${n}@localhost, scripts@mail.immae.eu |
@@ -425,5 +435,25 @@ | |||
425 | "smtp.immae.eu" = null; | 435 | "smtp.immae.eu" = null; |
426 | }; | 436 | }; |
427 | }; | 437 | }; |
438 | system.activationScripts.testmail = { | ||
439 | deps = [ "users" ]; | ||
440 | text = let | ||
441 | allCfg = config.myEnv.monitoring.email_check; | ||
442 | cfg = allCfg.eldiron; | ||
443 | reverseTargets = builtins.attrNames (lib.attrsets.filterAttrs (k: v: builtins.elem "eldiron" v.targets) allCfg); | ||
444 | to_email = cfg': host': | ||
445 | let sep = if lib.strings.hasInfix "+" cfg'.mail_address then "_" else "+"; | ||
446 | in "${cfg'.mail_address}${sep}${host'}@${cfg'.mail_domain}"; | ||
447 | mails_to_receive = builtins.concatStringsSep " " (map (to_email cfg) reverseTargets); | ||
448 | in '' | ||
449 | install -m 0555 -o nobody -g nogroup -d /var/lib/naemon/checks/email | ||
450 | for f in ${mails_to_receive}; do | ||
451 | if [ ! -f /var/lib/naemon/checks/email/$f ]; then | ||
452 | install -m 0644 -o nobody -g nogroup /dev/null -T /var/lib/naemon/checks/email/$f | ||
453 | touch -m -d @0 /var/lib/naemon/checks/email/$f | ||
454 | fi | ||
455 | done | ||
456 | ''; | ||
457 | }; | ||
428 | }; | 458 | }; |
429 | } | 459 | } |
diff --git a/modules/private/mail/relay.nix b/modules/private/mail/relay.nix index e0aa387..6ac3df8 100644 --- a/modules/private/mail/relay.nix +++ b/modules/private/mail/relay.nix | |||
@@ -126,8 +126,12 @@ | |||
126 | ) config.myEnv.mail.postfix.backup_domains | 126 | ) config.myEnv.mail.postfix.backup_domains |
127 | ); | 127 | ); |
128 | virtual_map = { | 128 | virtual_map = { |
129 | virtual = pkgs.writeText "postfix-virtual" ( | 129 | virtual = let |
130 | cfg = config.myEnv.monitoring.email_check.eldiron; | ||
131 | address = "${cfg.mail_address}@${cfg.mail_domain}"; | ||
132 | in pkgs.writeText "postfix-virtual" ( | ||
130 | builtins.concatStringsSep "\n" ( | 133 | builtins.concatStringsSep "\n" ( |
134 | ["${address} 1"] ++ | ||
131 | lib.attrsets.mapAttrsToList ( | 135 | lib.attrsets.mapAttrsToList ( |
132 | n: v: lib.optionalString v.external '' | 136 | n: v: lib.optionalString v.external '' |
133 | script_${n}@mail.immae.eu 1 | 137 | script_${n}@mail.immae.eu 1 |