2023-11-07 22:00:00 +01:00
|
|
|
{ config, lib, ... }:
|
2023-03-19 16:14:20 +01:00
|
|
|
let
|
|
|
|
cfg = config.my.hardware.drive-monitor;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.my.hardware.drive-monitor = with lib; {
|
|
|
|
enable = mkEnableOption "drive-monitor configuration";
|
|
|
|
|
|
|
|
OnFailureMail = mkOption {
|
2023-11-07 23:13:51 +01:00
|
|
|
type = types.nullOr types.str;
|
2023-06-22 20:54:16 +02:00
|
|
|
description = lib.mdDoc "Mail address where to send the error report";
|
2023-03-19 16:14:20 +01:00
|
|
|
default = null;
|
|
|
|
example = "alarm@mail.com";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
services = {
|
2024-07-02 22:29:28 +02:00
|
|
|
postfix.enable = cfg.OnFailureMail != null;
|
2023-03-19 16:14:20 +01:00
|
|
|
smartd = {
|
|
|
|
enable = true;
|
|
|
|
notifications.mail = lib.mkIf (cfg.OnFailureMail != null) {
|
|
|
|
enable = true;
|
|
|
|
recipient = cfg.OnFailureMail;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-04-28 22:28:57 +02:00
|
|
|
|
|
|
|
# monitoring
|
|
|
|
services.prometheus.exporters.smartctl.enable = config.services.prometheus.enable;
|
|
|
|
services.prometheus.scrapeConfigs = [
|
|
|
|
{
|
|
|
|
job_name = "smartctl";
|
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets = [ "127.0.0.1:${toString config.services.prometheus.exporters.smartctl.port}" ];
|
|
|
|
labels = {
|
|
|
|
instance = config.networking.hostName;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
];
|
2023-03-19 16:14:20 +01:00
|
|
|
};
|
|
|
|
}
|