2024-12-12 14:41:43 +01:00
|
|
|
# SPDX-FileCopyrightText: 2024 Maurice Debray <maurice.debray@dgnum.eu>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: EUPL-1.2
|
|
|
|
|
2024-03-29 23:15:10 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
2024-05-13 23:31:34 +02:00
|
|
|
meta,
|
|
|
|
nodeMeta,
|
2024-03-29 23:15:10 +01:00
|
|
|
...
|
|
|
|
}:
|
2024-05-13 23:31:34 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
inherit (lib)
|
|
|
|
concatStringsSep
|
|
|
|
mkEnableOption
|
|
|
|
mkForce
|
|
|
|
mkIf
|
|
|
|
;
|
|
|
|
|
|
|
|
emails = concatStringsSep ", " (
|
2024-05-22 19:03:07 +02:00
|
|
|
builtins.map (name: meta.organization.members.${name}.email) (
|
|
|
|
builtins.foldl' (
|
|
|
|
admins: group: admins ++ meta.organization.groups.${group}
|
|
|
|
) nodeMeta.admins nodeMeta.adminGroups
|
|
|
|
)
|
2024-05-13 23:31:34 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
cfg = config.dgn-notify;
|
|
|
|
in
|
|
|
|
|
2024-03-29 23:15:10 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
options.dgn-notify = {
|
2024-05-13 23:31:34 +02:00
|
|
|
enable = mkEnableOption "DGNum email notification cli" // {
|
2024-03-29 23:15:10 +01:00
|
|
|
default = true;
|
|
|
|
};
|
|
|
|
};
|
2024-05-13 23:31:34 +02:00
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
services.mail.sendmailSetuidWrapper.group = mkForce "mail";
|
2024-04-20 20:40:26 +02:00
|
|
|
users.groups.mail = { };
|
|
|
|
|
2024-03-29 23:15:10 +01:00
|
|
|
programs.msmtp = {
|
|
|
|
enable = true;
|
2024-04-20 20:40:26 +02:00
|
|
|
setSendmail = true;
|
2024-03-29 23:15:10 +01:00
|
|
|
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}";
|
|
|
|
};
|
|
|
|
};
|
2024-05-13 23:31:34 +02:00
|
|
|
|
2024-03-29 23:15:10 +01:00
|
|
|
services.systemd-notify = {
|
|
|
|
enable = true;
|
|
|
|
command = builtins.toString (
|
|
|
|
pkgs.writeShellScript "sendmail" ''
|
|
|
|
${pkgs.msmtp}/bin/sendmail -i -t <<ERRMAIL
|
2024-05-13 23:31:34 +02:00
|
|
|
To: admins+monitoring@dgnum.eu, ${emails}
|
2024-03-29 23:15:10 +01:00
|
|
|
Subject: [$HOSTNAME] Systemd failure: $1
|
|
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
Content-Type: text/plain; charset=UTF-8
|
|
|
|
|
|
|
|
$(systemctl status --full "$1")
|
|
|
|
ERRMAIL
|
|
|
|
''
|
|
|
|
);
|
|
|
|
};
|
|
|
|
age-secrets.sources = [ ./. ];
|
|
|
|
};
|
|
|
|
}
|