Skip to content

Commit

Permalink
nixos/prometheus: add configText option for alertmanager
Browse files Browse the repository at this point in the history
The reason being less mental overhead when reading upstream
documentation. Examples can be pasted right into the configuration
instead of translating to Nix attrset first.
  • Loading branch information
bjornfor committed Jan 14, 2017
1 parent 7d75dd7 commit d241394
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion nixos/modules/services/monitoring/prometheus/alertmanager.nix
Expand Up @@ -5,6 +5,10 @@ with lib;
let
cfg = config.services.prometheus.alertmanager;
mkConfigFile = pkgs.writeText "alertmanager.yml" (builtins.toJSON cfg.configuration);
alertmanagerYml =
if cfg.configText != null then
pkgs.writeText "alertmanager.yml" cfg.configText
else mkConfigFile;
in {
options = {
services.prometheus.alertmanager = {
Expand Down Expand Up @@ -34,6 +38,17 @@ in {
'';
};

configText = mkOption {
type = types.nullOr types.lines;
default = null;
description = ''
Alertmanager configuration as YAML text. If non-null, this option
defines the text that is written to alertmanager.yml. If null, the
contents of alertmanager.yml is generated from the structured config
options.
'';
};

logFormat = mkOption {
type = types.nullOr types.str;
default = null;
Expand Down Expand Up @@ -96,7 +111,7 @@ in {
after = [ "network.target" ];
script = ''
${pkgs.prometheus-alertmanager.bin}/bin/alertmanager \
-config.file ${mkConfigFile} \
-config.file ${alertmanagerYml} \
-web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
-log.level ${cfg.logLevel} \
${optionalString (cfg.webExternalUrl != null) ''-web.external-url ${cfg.webExternalUrl} \''}
Expand Down

0 comments on commit d241394

Please sign in to comment.