2023-08-19 15:44:50 +00:00
|
|
|
inputs: {
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
system,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
cfg = config.outage-detector;
|
|
|
|
package = inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.default;
|
|
|
|
inherit (lib) mkIf mkEnableOption mkOption types;
|
|
|
|
in {
|
|
|
|
options.outage-detector = {
|
|
|
|
enable = mkEnableOption "outage-detector";
|
|
|
|
|
|
|
|
timer = lib.mkOption {
|
|
|
|
type = types.nullOr types.int;
|
2023-10-04 17:12:35 +00:00
|
|
|
|
2023-08-19 15:44:50 +00:00
|
|
|
default = null;
|
2023-10-04 17:12:35 +00:00
|
|
|
|
2023-08-19 15:44:50 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
The time intervall in seconds the script should be repeated.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
2023-10-04 17:03:31 +00:00
|
|
|
type = with types; attrsOf (either str int);
|
|
|
|
|
2023-10-04 17:11:32 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
The settings for the outage-detector script.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
{
|
2023-10-04 17:11:55 +00:00
|
|
|
logFile = "/home/user/outage-detector.log";
|
2023-10-04 17:11:32 +00:00
|
|
|
host = "1.1.1.1";
|
|
|
|
timeout = 2;
|
|
|
|
};
|
|
|
|
'';
|
2023-08-19 15:44:50 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment.systemPackages = [package];
|
|
|
|
|
|
|
|
systemd.services.outage-detector = mkIf (cfg.timer
|
|
|
|
!= null) {
|
2023-10-13 11:56:55 +00:00
|
|
|
script = "${package}/bin/outage-detector log ${cfg.settings.logFile} --host ${cfg.settings.host} --timeout ${toString cfg.settings.timeout}";
|
2023-08-19 15:44:50 +00:00
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.timers.outage-detector = mkIf (cfg.timer
|
|
|
|
!= null) {
|
|
|
|
wantedBy = ["timers.target"];
|
|
|
|
timerConfig = {
|
|
|
|
OnBootSec = "0s";
|
|
|
|
OnUnitActiveSec = "${toString cfg.timer}s";
|
|
|
|
Unit = "outage-detector.service";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|