summaryrefslogtreecommitdiffstats
path: root/nixos
diff options
context:
space:
mode:
authorRyan Lahfa <masterancpp@gmail.com>2023-06-16 11:30:30 +0200
committerGitHub <noreply@github.com>2023-06-16 11:30:30 +0200
commitafc6f0d93babfd795bd25f828e3ef3cdb145953d (patch)
tree03d237be80ecaa1881a7133db31b9a480c488575 /nixos
parentb5a987d6805c595b054d1baefa96f19a1144ae0f (diff)
parentdb8b28dc5dcd75009953f97762d6d196b9e519c2 (diff)
Merge pull request #228479 from zimbatm/netdata-auto-claim
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/monitoring/netdata.nix29
1 files changed, 28 insertions, 1 deletions
diff --git a/nixos/modules/services/monitoring/netdata.nix b/nixos/modules/services/monitoring/netdata.nix
index bd0dea83e1a8..d2b2b2f1747c 100644
--- a/nixos/modules/services/monitoring/netdata.nix
+++ b/nixos/modules/services/monitoring/netdata.nix
@@ -159,6 +159,15 @@ in {
'';
};
+ claimTokenFile = mkOption {
+ type = types.nullOr types.path;
+ default = null;
+ description = lib.mdDoc ''
+ If set, automatically registers the agent using the given claim token
+ file.
+ '';
+ };
+
enableAnalyticsReporting = mkOption {
type = types.bool;
default = false;
@@ -260,7 +269,25 @@ in {
PrivateTmp = true;
ProtectControlGroups = true;
PrivateMounts = true;
- };
+ } // (lib.optionalAttrs (cfg.claim_token_file != null) {
+ LoadCredential = [
+ "netdata_claim_token:${cfg.claimTokenFile}"
+ ];
+
+ ExecStartPre = pkgs.writeShellScript "netdata-claim" ''
+ set -euo pipefail
+
+ if [[ -f /var/lib/netdata/cloud.d/claimed_id ]]; then
+ # Already registered
+ exit
+ fi
+
+ exec ${cfg.package}/bin/netdata-claim.sh \
+ -token="$(< "$CREDENTIALS_DIRECTORY/netdata_claim_token")" \
+ -url=https://app.netdata.cloud \
+ -daemon-not-running
+ '';
+ });
};
systemd.enableCgroupAccounting = true;