nixpkgs/nixos/modules/services/monitoring/kthxbye.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

162 lines
4.4 KiB
Nix

{
config,
pkgs,
lib,
...
}:
let
cfg = config.services.kthxbye;
in
{
options.services.kthxbye = {
enable = lib.mkEnableOption "kthxbye alert acknowledgement management daemon";
package = lib.mkPackageOption pkgs "kthxbye" { };
openFirewall = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Whether to open ports in the firewall needed for the daemon to function.
'';
};
extraOptions = lib.mkOption {
type = with lib.types; listOf str;
default = [ ];
description = ''
Extra command line options.
Documentation can be found [here](https://github.com/prymitive/kthxbye/blob/main/README.md).
'';
example = lib.literalExpression ''
[
"-extend-with-prefix 'ACK!'"
];
'';
};
alertmanager = {
timeout = lib.mkOption {
type = lib.types.str;
default = "1m0s";
description = ''
Alertmanager request timeout duration in the [time.Duration](https://pkg.go.dev/time#ParseDuration) format.
'';
example = "30s";
};
uri = lib.mkOption {
type = lib.types.str;
default = "http://localhost:9093";
description = ''
Alertmanager URI to use.
'';
example = "https://alertmanager.example.com";
};
};
extendBy = lib.mkOption {
type = lib.types.str;
default = "15m0s";
description = ''
Extend silences by adding DURATION seconds.
DURATION should be provided in the [time.Duration](https://pkg.go.dev/time#ParseDuration) format.
'';
example = "6h0m0s";
};
extendIfExpiringIn = lib.mkOption {
type = lib.types.str;
default = "5m0s";
description = ''
Extend silences that are about to expire in the next DURATION seconds.
DURATION should be provided in the [time.Duration](https://pkg.go.dev/time#ParseDuration) format.
'';
example = "1m0s";
};
extendWithPrefix = lib.mkOption {
type = lib.types.str;
default = "ACK!";
description = ''
Extend silences with comment starting with PREFIX string.
'';
example = "!perma-silence";
};
interval = lib.mkOption {
type = lib.types.str;
default = "45s";
description = ''
Silence check interval duration in the [time.Duration](https://pkg.go.dev/time#ParseDuration) format.
'';
example = "30s";
};
listenAddress = lib.mkOption {
type = lib.types.str;
default = "0.0.0.0";
description = ''
The address to listen on for HTTP requests.
'';
example = "127.0.0.1";
};
port = lib.mkOption {
type = lib.types.port;
default = 8080;
description = ''
The port to listen on for HTTP requests.
'';
};
logJSON = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Format logged messages as JSON.
'';
};
maxDuration = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
description = ''
Maximum duration of a silence, it won't be extended anymore after reaching it.
Duration should be provided in the [time.Duration](https://pkg.go.dev/time#ParseDuration) format.
'';
example = "30d";
};
};
config = lib.mkIf cfg.enable {
systemd.services.kthxbye = {
description = "kthxbye Alertmanager ack management daemon";
wantedBy = [ "multi-user.target" ];
script = ''
${cfg.package}/bin/kthxbye \
-alertmanager.timeout ${cfg.alertmanager.timeout} \
-alertmanager.uri ${cfg.alertmanager.uri} \
-extend-by ${cfg.extendBy} \
-extend-if-expiring-in ${cfg.extendIfExpiringIn} \
-extend-with-prefix ${cfg.extendWithPrefix} \
-interval ${cfg.interval} \
-listen ${cfg.listenAddress}:${toString cfg.port} \
${lib.optionalString cfg.logJSON "-log-json"} \
${lib.optionalString (cfg.maxDuration != null) "-max-duration ${cfg.maxDuration}"} \
${lib.concatStringsSep " " cfg.extraOptions}
'';
serviceConfig = {
Type = "simple";
DynamicUser = true;
Restart = "on-failure";
};
};
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.port ];
};
}