about summary refs log tree commit diff
path: root/nixos/modules/services/monitoring
diff options
context:
space:
mode:
authorAlberto Berti <alberto@metapensiero.it>2019-02-21 16:32:46 +0100
committerJean-Baptiste Giraudeau <jean-baptiste.giraudeau@iohk.io>2019-03-25 14:36:44 +0100
commit1b6ce80c2bc3e16397b688ce217e049cebaa460a (patch)
treebd0e1a1f199051b4b5bf9d3fc4adfa09f0bf8ee1 /nixos/modules/services/monitoring
parent11b89720b7920d4b2cf1a5d2bc54ced5797ea477 (diff)
downloadnixlib-1b6ce80c2bc3e16397b688ce217e049cebaa460a.tar
nixlib-1b6ce80c2bc3e16397b688ce217e049cebaa460a.tar.gz
nixlib-1b6ce80c2bc3e16397b688ce217e049cebaa460a.tar.bz2
nixlib-1b6ce80c2bc3e16397b688ce217e049cebaa460a.tar.lz
nixlib-1b6ce80c2bc3e16397b688ce217e049cebaa460a.tar.xz
nixlib-1b6ce80c2bc3e16397b688ce217e049cebaa460a.tar.zst
nixlib-1b6ce80c2bc3e16397b688ce217e049cebaa460a.zip
Make it pass a minimal test
Diffstat (limited to 'nixos/modules/services/monitoring')
-rw-r--r--nixos/modules/services/monitoring/prometheus/alertmanager.nix62
-rw-r--r--nixos/modules/services/monitoring/prometheus/default.nix12
2 files changed, 36 insertions, 38 deletions
diff --git a/nixos/modules/services/monitoring/prometheus/alertmanager.nix b/nixos/modules/services/monitoring/prometheus/alertmanager.nix
index 88fd312e87c5..187b78de899f 100644
--- a/nixos/modules/services/monitoring/prometheus/alertmanager.nix
+++ b/nixos/modules/services/monitoring/prometheus/alertmanager.nix
@@ -137,44 +137,40 @@ let
         '';
       };
     };
-    mkAMConfig = amCfg: amVersion:
-      config = mkMerge [
-        (mkIf amCfg.enable {
-          assertions = singleton {
-            assertion = amCfg.configuration != null || amCfg.configText != null;
-            message = "Can not enable alertmanager without a configuration. "
-             + "Set either the `configuration` or `configText` attribute.";
+    mkAMConfig = amCfg: amVersion: [
+      (mkIf amCfg.enable {
+        assertions = singleton {
+          assertion = amCfg.configuration != null || amCfg.configText != null;
+          message = "Can not enable alertmanager without a configuration. "
+           + "Set either the `configuration` or `configText` attribute.";
+        };
+      })
+      (mkIf amCfg.enable {
+        networking.firewall.allowedTCPPorts = optional amCfg.openFirewall amCfg.port;
+
+        systemd.services."alertmanager${amVersion}" = {
+          wantedBy = [ "multi-user.target" ];
+          after    = [ "network.target" ];
+          script = ''
+            ${amCfg.package}/bin/alertmanager \
+              ${concatStringsSep " \\\n  " cmdlineArgs}
+          '';
+          serviceConfig = {
+            User = amCfg.user;
+            Group = amCfg.group;
+            Restart  = "always";
+            PrivateTmp = true;
+            WorkingDirectory = "/tmp";
+            ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
           };
-        })
-        (mkIf amCfg.enable {
-          networking.firewall.allowedTCPPorts = optional amCfg.openFirewall amCfg.port;
-
-          systemd.services."alertmanager${amVersion}" = {
-            wantedBy = [ "multi-user.target" ];
-            after    = [ "network.target" ];
-            script = ''
-              ${amCfg.package}/bin/alertmanager \
-                ${concatStringsSep " \\\n  " cmdlineArgs}
-            '';
-            serviceConfig = {
-              User = amCfg.user;
-              Group = amCfg.group;
-              Restart  = "always";
-              PrivateTmp = true;
-              WorkingDirectory = "/tmp";
-              ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
-            };
-          };
-        })
-      ];
+        };
+      })
+    ];
 in {
   options = {
     services.prometheus.alertmanager = amOptions;
     services.prometheus2.alertmanager = amOptions;
   };
 
-  config = mkMerge [
-    (mkAMConfig cfg "")
-    (mkAMConfig cfg2 "2")
-  ];
+  config = mkMerge ((mkAMConfig cfg "") ++ (mkAMConfig cfg2 "2"));
 }
diff --git a/nixos/modules/services/monitoring/prometheus/default.nix b/nixos/modules/services/monitoring/prometheus/default.nix
index 0aa3268b3416..18391b2f00c3 100644
--- a/nixos/modules/services/monitoring/prometheus/default.nix
+++ b/nixos/modules/services/monitoring/prometheus/default.nix
@@ -22,8 +22,10 @@ let
 
   # a wrapper that verifies that the configuration is valid for
   # prometheus 2
-  prom2toolCheck = what: name: file: pkgs.runCommand "${name}-${what}-checked"
-    { buildInputs = [ cfg2.package ]; } ''
+  prom2toolCheck = what: name: file:
+    pkgs.runCommand
+      "${name}-${replaceStrings [" "] [""] what}-checked"
+      { buildInputs = [ cfg2.package ]; } ''
     ln -s ${file} $out
     promtool ${what} $out
   '';
@@ -64,7 +66,7 @@ let
   # This becomes the main config file for Prometheus 2
   promConfig2 = {
     global = cfg2.globalConfig;
-    rule_files = map (prom2toolCheck "check-rules" "rules") (cfg2.ruleFiles ++ [
+    rule_files = map (prom2toolCheck "check rules" "rules") (cfg2.ruleFiles ++ [
       (pkgs.writeText "prometheus.rules" (concatStringsSep "\n" cfg2.rules))
     ]);
     scrape_configs = cfg2.scrapeConfigs;
@@ -83,7 +85,7 @@ let
     yml = if cfg2.configText != null then
       pkgs.writeText "prometheus.yml" cfg2.configText
       else generatedPrometheus2Yml;
-    in promtoo2lCheck "check-config" "prometheus.yml" yml;
+    in prom2toolCheck "check config" "prometheus.yml" yml;
 
   cmdlineArgs2 = cfg2.extraFlags ++ [
     "--storage.tsdb.path=${cfg2.dataDir}/data/"
@@ -704,7 +706,7 @@ in {
         after    = [ "network.target" ];
         script = ''
           #!/bin/sh
-          exec ${cfg.package}/bin/prometheus \
+          exec ${cfg2.package}/bin/prometheus \
             ${concatStringsSep " \\\n  " cmdlineArgs2}
         '';
         serviceConfig = {