nixos/services.prometheus.alertmanager: remove with lib;
This commit is contained in:
parent
951787fba3
commit
ea4bd53274
@ -1,7 +1,4 @@
|
||||
{ config, pkgs, lib, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.prometheus.alertmanager;
|
||||
mkConfigFile = pkgs.writeText "alertmanager.yml" (builtins.toJSON cfg.configuration);
|
||||
@ -25,16 +22,16 @@ let
|
||||
"--log.level ${cfg.logLevel}"
|
||||
"--storage.path /var/lib/alertmanager"
|
||||
(toString (map (peer: "--cluster.peer ${peer}:9094") cfg.clusterPeers))
|
||||
] ++ (optional (cfg.webExternalUrl != null)
|
||||
] ++ (lib.optional (cfg.webExternalUrl != null)
|
||||
"--web.external-url ${cfg.webExternalUrl}"
|
||||
) ++ (optional (cfg.logFormat != null)
|
||||
) ++ (lib.optional (cfg.logFormat != null)
|
||||
"--log.format ${cfg.logFormat}"
|
||||
);
|
||||
in {
|
||||
imports = [
|
||||
(mkRemovedOptionModule [ "services" "prometheus" "alertmanager" "user" ] "The alertmanager service is now using systemd's DynamicUser mechanism which obviates a user setting.")
|
||||
(mkRemovedOptionModule [ "services" "prometheus" "alertmanager" "group" ] "The alertmanager service is now using systemd's DynamicUser mechanism which obviates a group setting.")
|
||||
(mkRemovedOptionModule [ "services" "prometheus" "alertmanagerURL" ] ''
|
||||
(lib.mkRemovedOptionModule [ "services" "prometheus" "alertmanager" "user" ] "The alertmanager service is now using systemd's DynamicUser mechanism which obviates a user setting.")
|
||||
(lib.mkRemovedOptionModule [ "services" "prometheus" "alertmanager" "group" ] "The alertmanager service is now using systemd's DynamicUser mechanism which obviates a group setting.")
|
||||
(lib.mkRemovedOptionModule [ "services" "prometheus" "alertmanagerURL" ] ''
|
||||
Due to incompatibility, the alertmanagerURL option has been removed,
|
||||
please use 'services.prometheus.alertmanagers' instead.
|
||||
'')
|
||||
@ -42,12 +39,12 @@ in {
|
||||
|
||||
options = {
|
||||
services.prometheus.alertmanager = {
|
||||
enable = mkEnableOption "Prometheus Alertmanager";
|
||||
enable = lib.mkEnableOption "Prometheus Alertmanager";
|
||||
|
||||
package = mkPackageOption pkgs "prometheus-alertmanager" { };
|
||||
package = lib.mkPackageOption pkgs "prometheus-alertmanager" { };
|
||||
|
||||
configuration = mkOption {
|
||||
type = types.nullOr types.attrs;
|
||||
configuration = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.attrs;
|
||||
default = null;
|
||||
description = ''
|
||||
Alertmanager configuration as nix attribute set.
|
||||
@ -57,8 +54,8 @@ in {
|
||||
'';
|
||||
};
|
||||
|
||||
configText = mkOption {
|
||||
type = types.nullOr types.lines;
|
||||
configText = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.lines;
|
||||
default = null;
|
||||
description = ''
|
||||
Alertmanager configuration as YAML text. If non-null, this option
|
||||
@ -71,8 +68,8 @@ in {
|
||||
'';
|
||||
};
|
||||
|
||||
checkConfig = mkOption {
|
||||
type = types.bool;
|
||||
checkConfig = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Check configuration with `amtool check-config`. The call to `amtool` is
|
||||
@ -85,24 +82,24 @@ in {
|
||||
'';
|
||||
};
|
||||
|
||||
logFormat = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
logFormat = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
If set use a syslog logger or JSON logging.
|
||||
'';
|
||||
};
|
||||
|
||||
logLevel = mkOption {
|
||||
type = types.enum ["debug" "info" "warn" "error" "fatal"];
|
||||
logLevel = lib.mkOption {
|
||||
type = lib.types.enum ["debug" "info" "warn" "error" "fatal"];
|
||||
default = "warn";
|
||||
description = ''
|
||||
Only log messages with the given severity or above.
|
||||
'';
|
||||
};
|
||||
|
||||
webExternalUrl = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
webExternalUrl = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
The URL under which Alertmanager is externally reachable (for example, if Alertmanager is served via a reverse proxy).
|
||||
@ -112,8 +109,8 @@ in {
|
||||
'';
|
||||
};
|
||||
|
||||
listenAddress = mkOption {
|
||||
type = types.str;
|
||||
listenAddress = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "";
|
||||
description = ''
|
||||
Address to listen on for the web interface and API. Empty string will listen on all interfaces.
|
||||
@ -121,40 +118,40 @@ in {
|
||||
'';
|
||||
};
|
||||
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
port = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
default = 9093;
|
||||
description = ''
|
||||
Port to listen on for the web interface and API.
|
||||
'';
|
||||
};
|
||||
|
||||
openFirewall = mkOption {
|
||||
type = types.bool;
|
||||
openFirewall = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Open port in firewall for incoming connections.
|
||||
'';
|
||||
};
|
||||
|
||||
clusterPeers = mkOption {
|
||||
type = types.listOf types.str;
|
||||
clusterPeers = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [];
|
||||
description = ''
|
||||
Initial peers for HA cluster.
|
||||
'';
|
||||
};
|
||||
|
||||
extraFlags = mkOption {
|
||||
type = types.listOf types.str;
|
||||
extraFlags = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [];
|
||||
description = ''
|
||||
Extra commandline options when launching the Alertmanager.
|
||||
'';
|
||||
};
|
||||
|
||||
environmentFile = mkOption {
|
||||
type = types.nullOr types.path;
|
||||
environmentFile = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.path;
|
||||
default = null;
|
||||
example = "/root/alertmanager.env";
|
||||
description = ''
|
||||
@ -167,16 +164,16 @@ in {
|
||||
};
|
||||
};
|
||||
|
||||
config = mkMerge [
|
||||
(mkIf cfg.enable {
|
||||
assertions = singleton {
|
||||
config = lib.mkMerge [
|
||||
(lib.mkIf cfg.enable {
|
||||
assertions = lib.singleton {
|
||||
assertion = cfg.configuration != null || cfg.configText != null;
|
||||
message = "Can not enable alertmanager without a configuration. "
|
||||
+ "Set either the `configuration` or `configText` attribute.";
|
||||
};
|
||||
})
|
||||
(mkIf cfg.enable {
|
||||
networking.firewall.allowedTCPPorts = optional cfg.openFirewall cfg.port;
|
||||
(lib.mkIf cfg.enable {
|
||||
networking.firewall.allowedTCPPorts = lib.optional cfg.openFirewall cfg.port;
|
||||
|
||||
systemd.services.alertmanager = {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
@ -188,8 +185,8 @@ in {
|
||||
'';
|
||||
serviceConfig = {
|
||||
ExecStart = "${cfg.package}/bin/alertmanager" +
|
||||
optionalString (length cmdlineArgs != 0) (" \\\n " +
|
||||
concatStringsSep " \\\n " cmdlineArgs);
|
||||
lib.optionalString (lib.length cmdlineArgs != 0) (" \\\n " +
|
||||
lib.concatStringsSep " \\\n " cmdlineArgs);
|
||||
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
||||
|
||||
EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile;
|
||||
|
Loading…
Reference in New Issue
Block a user