infrastructure/modules/dgn-notify/default.nix
catvayor 2329799c87
Some checks failed
Check meta / check_meta (pull_request) Successful in 25s
Check meta / check_dns (pull_request) Successful in 44s
build configuration / build_storage01 (pull_request) Successful in 1m10s
build configuration / build_compute01 (pull_request) Successful in 1m13s
build configuration / build_vault01 (pull_request) Successful in 1m1s
build configuration / build_web02 (pull_request) Successful in 58s
build configuration / build_web01 (pull_request) Successful in 1m31s
build configuration / build_rescue01 (pull_request) Successful in 55s
build configuration / push_to_cache (pull_request) Failing after 2m15s
build configuration / build_vault01 (push) Successful in 1m11s
build configuration / build_rescue01 (push) Successful in 1m12s
build configuration / build_storage01 (push) Successful in 1m14s
build configuration / build_compute01 (push) Successful in 1m17s
build configuration / build_web02 (push) Successful in 1m22s
lint / check (push) Successful in 24s
build configuration / build_web01 (push) Successful in 1m36s
build configuration / push_to_cache (push) Successful in 2m16s
feat(monitoring): Add adminGroup emails
2024-05-22 19:05:03 +02:00

73 lines
1.5 KiB
Nix

{
config,
pkgs,
lib,
meta,
nodeMeta,
...
}:
let
inherit (lib)
concatStringsSep
mkEnableOption
mkForce
mkIf
;
emails = concatStringsSep ", " (
builtins.map (name: meta.organization.members.${name}.email) (
builtins.foldl' (
admins: group: admins ++ meta.organization.groups.${group}
) nodeMeta.admins nodeMeta.adminGroups
)
);
cfg = config.dgn-notify;
in
{
options.dgn-notify = {
enable = mkEnableOption "DGNum email notification cli" // {
default = true;
};
};
config = mkIf cfg.enable {
services.mail.sendmailSetuidWrapper.group = mkForce "mail";
users.groups.mail = { };
programs.msmtp = {
enable = true;
setSendmail = true;
accounts.default = {
tls = true;
tls_starttls = false;
port = 465;
auth = true;
host = "kurisu.lahfa.xyz";
from = "noreply@infra.dgnum.eu";
user = "web-services@infra.dgnum.eu";
passwordeval = "cat ${config.age.secrets.mail.path}";
};
};
services.systemd-notify = {
enable = true;
command = builtins.toString (
pkgs.writeShellScript "sendmail" ''
${pkgs.msmtp}/bin/sendmail -i -t <<ERRMAIL
To: admins+monitoring@dgnum.eu, ${emails}
Subject: [$HOSTNAME] Systemd failure: $1
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=UTF-8
$(systemctl status --full "$1")
ERRMAIL
''
);
};
age-secrets.sources = [ ./. ];
};
}