about summary refs log tree commit diff
path: root/nixos/modules/services/monitoring
diff options
context:
space:
mode:
authorArnout Engelen <arnout@bzzt.net>2023-09-20 22:33:10 +0200
committerGitHub <noreply@github.com>2023-09-20 22:33:10 +0200
commit69ecad6acbef29514ddeed18a6f8316d8b0c2021 (patch)
tree3a44b26dd4984cf511b9753b3b82c8c87837d842 /nixos/modules/services/monitoring
parentd1b8e9a099e5cb82d12410a85ec164b50209647c (diff)
parent1bf360af285fc9fd6407c2bead296e3d0d5b6549 (diff)
downloadnixlib-69ecad6acbef29514ddeed18a6f8316d8b0c2021.tar
nixlib-69ecad6acbef29514ddeed18a6f8316d8b0c2021.tar.gz
nixlib-69ecad6acbef29514ddeed18a6f8316d8b0c2021.tar.bz2
nixlib-69ecad6acbef29514ddeed18a6f8316d8b0c2021.tar.lz
nixlib-69ecad6acbef29514ddeed18a6f8316d8b0c2021.tar.xz
nixlib-69ecad6acbef29514ddeed18a6f8316d8b0c2021.tar.zst
nixlib-69ecad6acbef29514ddeed18a6f8316d8b0c2021.zip
Merge pull request #254563 from raboof/prometheus-exporter-nextcloud-fixup
prometheus-exporter-nextcloud: require either tokenFile or passwordFile
Diffstat (limited to 'nixos/modules/services/monitoring')
-rw-r--r--nixos/modules/services/monitoring/prometheus/exporters.nix8
-rw-r--r--nixos/modules/services/monitoring/prometheus/exporters/nextcloud.nix15
2 files changed, 17 insertions, 6 deletions
diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix
index 8bb017894ee2..66aff30b5ed1 100644
--- a/nixos/modules/services/monitoring/prometheus/exporters.nix
+++ b/nixos/modules/services/monitoring/prometheus/exporters.nix
@@ -304,6 +304,14 @@ in
           'services.mysql.enable' is set to false.
       '';
     } {
+      assertion = cfg.nextcloud.enable -> (
+        (cfg.nextcloud.passwordFile == null) != (cfg.nextcloud.tokenFile == null)
+      );
+      message = ''
+        Please specify either 'services.prometheus.exporters.nextcloud.passwordFile' or
+          'services.prometheus.exporters.nextcloud.tokenFile'
+      '';
+    } {
       assertion = cfg.sql.enable -> (
         (cfg.sql.configFile == null) != (cfg.sql.configuration == null)
       );
diff --git a/nixos/modules/services/monitoring/prometheus/exporters/nextcloud.nix b/nixos/modules/services/monitoring/prometheus/exporters/nextcloud.nix
index 28add020f5cc..28a3eb6a134c 100644
--- a/nixos/modules/services/monitoring/prometheus/exporters/nextcloud.nix
+++ b/nixos/modules/services/monitoring/prometheus/exporters/nextcloud.nix
@@ -23,10 +23,12 @@ in
       description = lib.mdDoc ''
         Username for connecting to Nextcloud.
         Note that this account needs to have admin privileges in Nextcloud.
+        Unused when using token authentication.
       '';
     };
     passwordFile = mkOption {
-      type = types.path;
+      type = types.nullOr types.path;
+      default = null;
       example = "/path/to/password-file";
       description = lib.mdDoc ''
         File containing the password for connecting to Nextcloud.
@@ -34,9 +36,9 @@ in
       '';
     };
     tokenFile = mkOption {
-      type = types.path;
+      type = types.nullOr types.path;
+      default = null;
       example = "/path/to/token-file";
-      default = "";
       description = lib.mdDoc ''
         File containing the token for connecting to Nextcloud.
         Make sure that this file is readable by the exporter user.
@@ -58,12 +60,13 @@ in
           --addr ${cfg.listenAddress}:${toString cfg.port} \
           --timeout ${cfg.timeout} \
           --server ${cfg.url} \
-          ${if cfg.tokenFile == "" then ''
+          ${if cfg.passwordFile != null then ''
             --username ${cfg.username} \
             --password ${escapeShellArg "@${cfg.passwordFile}"} \
-         '' else ''
+          '' else ''
             --auth-token ${escapeShellArg "@${cfg.tokenFile}"} \
-         ''} ${concatStringsSep " \\\n  " cfg.extraFlags}'';
+          ''} \
+          ${concatStringsSep " \\\n  " cfg.extraFlags}'';
     };
   };
 }