summaryrefslogtreecommitdiffstats
path: root/claim
diff options
context:
space:
mode:
authorTimotej S <6674623+underhood@users.noreply.github.com>2020-08-26 14:50:37 +0200
committerGitHub <noreply@github.com>2020-08-26 14:50:37 +0200
commitab7ff3131f3698710e0bd9fa3c66d31a3a194725 (patch)
treea78efc8cc829c2519b69e73e24d74e713c5105bb /claim
parenta11d33bba77043b28cf2b0dac4989cd189c635b2 (diff)
Adds claimed_id streaming (#9804)
* streams claimed_id of child nodes to parents * adds this information into /api/v1/info
Diffstat (limited to 'claim')
-rw-r--r--claim/claim.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/claim/claim.c b/claim/claim.c
index 0e84d6295c..b9186bebcd 100644
--- a/claim/claim.c
+++ b/claim/claim.c
@@ -27,8 +27,6 @@ static char *claiming_errors[] = {
"Service Unavailable", // 17
"Agent Unique Id Not Readable" // 18
};
-static netdata_mutex_t claim_mutex = NETDATA_MUTEX_INITIALIZER;
-static char *claimed_id = NULL;
/* Retrieve the claim id for the agent.
* Caller owns the string.
@@ -36,9 +34,9 @@ static char *claimed_id = NULL;
char *is_agent_claimed()
{
char *result;
- netdata_mutex_lock(&claim_mutex);
- result = (claimed_id == NULL) ? NULL : strdup(claimed_id);
- netdata_mutex_unlock(&claim_mutex);
+ netdata_mutex_lock(&localhost->claimed_id_lock);
+ result = (localhost->claimed_id == NULL) ? NULL : strdupz(localhost->claimed_id);
+ netdata_mutex_unlock(&localhost->claimed_id_lock);
return result;
}
@@ -135,10 +133,11 @@ void load_claiming_state(void)
#if defined( DISABLE_CLOUD ) || !defined( ENABLE_ACLK )
netdata_cloud_setting = 0;
#else
- netdata_mutex_lock(&claim_mutex);
- if (claimed_id != NULL) {
- freez(claimed_id);
- claimed_id = NULL;
+ uuid_t uuid;
+ netdata_mutex_lock(&localhost->claimed_id_lock);
+ if (localhost->claimed_id) {
+ freez(localhost->claimed_id);
+ localhost->claimed_id = NULL;
}
if (aclk_connected)
{
@@ -153,8 +152,14 @@ void load_claiming_state(void)
snprintfz(filename, FILENAME_MAX, "%s/cloud.d/claimed_id", netdata_configured_varlib_dir);
long bytes_read;
- claimed_id = read_by_filename(filename, &bytes_read);
- netdata_mutex_unlock(&claim_mutex); // Only the main thread can call this function, safe to release and then read
+ char *claimed_id = read_by_filename(filename, &bytes_read);
+ if(claimed_id && uuid_parse(claimed_id, uuid)) {
+ error("claimed_id \"%s\" doesn't look like valid UUID", claimed_id);
+ freez(claimed_id);
+ claimed_id = NULL;
+ }
+ localhost->claimed_id = claimed_id;
+ netdata_mutex_unlock(&localhost->claimed_id_lock);
if (!claimed_id) {
info("Unable to load '%s', setting state to AGENT_UNCLAIMED", filename);
return;