@cryptotaxi247 / netdata-1 / commits / a982c5c05

move machine_guid from registry to rrdhost

Costa Tsaousis (ktsaou) committed Feb 17, 2017 at 22:42 UTC a982c5c058188316363ac2830b2583d5644207db
4 files changed +14 -15
src/registry.c
+1 -1
@@ -45,7 +45,7 @@ static inline void registry_json_header(struct web_client *w, const char *action
45 buffer_flush(w->response.data);
46 w->response.data->contenttype = CT_APPLICATION_JSON;
47 buffer_sprintf(w->response.data, "{\n\t\"action\": \"%s\",\n\t\"status\": \"%s\",\n\t\"hostname\": \"%s\",\n\t\"machine_guid\": \"%s\"",
48 - action, status, registry.hostname, registry.machine_guid);
48 + action, status, registry.hostname, localhost.machine_guid);
49 }
50
51 static inline void registry_json_footer(struct web_client *w) {
src/registry_internals.c
+12 -12
@@ -275,8 +275,8 @@ static inline int is_machine_guid_blacklisted(const char *guid) {
275 }
276
277 char *registry_get_this_machine_guid(void) {
278 - if(likely(registry.machine_guid[0]))
279 - return registry.machine_guid;
278 + if(likely(localhost.machine_guid[0]))
279 + return localhost.machine_guid;
280
281 // read it from disk
282 int fd = open(registry.machine_guid_filename, O_RDONLY);
@@ -286,38 +286,38 @@ char *registry_get_this_machine_guid(void) {
286 error("Failed to read machine GUID from '%s'", registry.machine_guid_filename);
287 else {
288 buf[GUID_LEN] = '\0';
289 - if(registry_regenerate_guid(buf, registry.machine_guid) == -1) {
289 + if(registry_regenerate_guid(buf, localhost.machine_guid) == -1) {
290 error("Failed to validate machine GUID '%s' from '%s'. Ignoring it - this might mean this netdata will appear as duplicate in the registry.",
291 buf, registry.machine_guid_filename);
292
293 - registry.machine_guid[0] = '\0';
293 + localhost.machine_guid[0] = '\0';
294 }
295 - else if(is_machine_guid_blacklisted(registry.machine_guid))
296 - registry.machine_guid[0] = '\0';
295 + else if(is_machine_guid_blacklisted(localhost.machine_guid))
296 + localhost.machine_guid[0] = '\0';
297 }
298 close(fd);
299 }
300
301 // generate a new one?
302 - if(!registry.machine_guid[0]) {
302 + if(!localhost.machine_guid[0]) {
303 uuid_t uuid;
304
305 uuid_generate_time(uuid);
306 - uuid_unparse_lower(uuid, registry.machine_guid);
307 - registry.machine_guid[GUID_LEN] = '\0';
306 + uuid_unparse_lower(uuid, localhost.machine_guid);
307 + localhost.machine_guid[GUID_LEN] = '\0';
308
309 // save it
310 fd = open(registry.machine_guid_filename, O_WRONLY|O_CREAT|O_TRUNC, 444);
311 if(fd == -1)
312 fatal("Cannot create unique machine id file '%s'. Please fix this.", registry.machine_guid_filename);
313
314 - if(write(fd, registry.machine_guid, GUID_LEN) != GUID_LEN)
314 + if(write(fd, localhost.machine_guid, GUID_LEN) != GUID_LEN)
315 fatal("Cannot write the unique machine id file '%s'. Please fix this.", registry.machine_guid_filename);
316
317 close(fd);
318 }
319
320 - setenv("NETDATA_REGISTRY_UNIQUE_ID", registry.machine_guid, 1);
320 + setenv("NETDATA_REGISTRY_UNIQUE_ID", localhost.machine_guid, 1);
321
322 - return registry.machine_guid;
322 + return localhost.machine_guid;
323 }
src/registry_internals.h
-2
@@ -14,8 +14,6 @@
14 struct registry {
15 int enabled;
16
17 - char machine_guid[GUID_LEN + 1];
18 -
17 // entries counters / statistics
18 unsigned long long persons_count;
19 unsigned long long machines_count;
src/rrd.h
+1
@@ -297,6 +297,7 @@ struct rrdhost {
297 avl avl;
298
299 char *hostname;
300 + char machine_guid[GUID_LEN + 1];
301
302 RRDSET *rrdset_root;
303 pthread_rwlock_t rrdset_root_rwlock;