]> arthur.barton.de Git - netdata.git/commitdiff
detect duplicate hosts
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Fri, 24 Feb 2017 23:42:05 +0000 (01:42 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Fri, 24 Feb 2017 23:42:05 +0000 (01:42 +0200)
src/rrdhost.c
src/rrdpush.c

index f43d472bd30c8ef325446a3f75c21456c26fe0d9..6e9d7baade02d0c3e9244e58bf49f9eb08bb0806 100644 (file)
@@ -187,35 +187,44 @@ RRDHOST *rrdhost_create(const char *hostname,
         else localhost = host;
     }
 
-    if(rrdhost_index_add(host) != host)
-        fatal("Host '%s': cannot add host to index. It already exists.", hostname);
+    RRDHOST *t = rrdhost_index_add(host);
+
+    if(t != host) {
+        error("Host '%s': cannot add host with machine guid '%s' to index. It already exists as host '%s' with machine guid '%s'.", host->hostname, host->machine_guid, t->hostname, t->machine_guid);
+        rrdhost_free(host);
+        host = NULL;
+    }
+    else {
+        info("Host '%s' with guid '%s' initialized"
+                     ", os: %s"
+                     ", update every: %d"
+                     ", memory mode: %s"
+                     ", history entries: %d"
+                     ", streaming: %s"
+                     ", health: %s"
+                     ", cache_dir: '%s'"
+                     ", varlib_dir: '%s'"
+                     ", health_log: '%s'"
+                     ", alarms default handler: '%s'"
+                     ", alarms default recipient: '%s'"
+             , host->hostname
+             , host->machine_guid
+             , host->os
+             , host->rrd_update_every
+             , rrd_memory_mode_name(host->rrd_memory_mode)
+             , host->rrd_history_entries
+             , host->rrdpush_enabled?"enabled":"disabled"
+             , host->health_enabled?"enabled":"disabled"
+             , host->cache_dir
+             , host->varlib_dir
+             , host->health_log_filename
+             , host->health_default_exec
+             , host->health_default_recipient
+        );
+    }
 
     rrd_unlock();
 
-    info("Host '%s' with guid '%s' initialized"
-                 ", update every: %d"
-                 ", memory mode: %s"
-                 ", history entries: %d"
-                 ", streaming: %s"
-                 ", health: %s"
-                 ", cache_dir: '%s'"
-                 ", varlib_dir: '%s'"
-                 ", health_log: '%s'"
-                 ", alarms default handler: '%s'"
-                 ", alarms default recipient: '%s'"
-         , host->hostname
-         , host->machine_guid
-         , host->rrd_update_every
-         , rrd_memory_mode_name(host->rrd_memory_mode)
-         , host->rrd_history_entries
-         , host->rrdpush_enabled?"enabled: ":"disabled"
-         , host->health_enabled?"enabled":"disabled"
-         , host->cache_dir
-         , host->varlib_dir
-         , host->health_log_filename
-         , host->health_default_exec
-         , host->health_default_recipient
-    );
     return host;
 }
 
index fe6b477639012b0b4347a00073d2e9d825032229..5d3e17a06d0fd163753188803c03f0bbe1082afe 100644 (file)
@@ -449,17 +449,22 @@ int rrdpush_receive(int fd, const char *key, const char *hostname, const char *m
     if(!strcmp(machine_guid, "localhost"))
         host = localhost;
     else
-        host = rrdhost_find_or_create(hostname, machine_guid, os, update_every, history, mode, health_enabled?1:0);
+        host = rrdhost_find_or_create(hostname, machine_guid, os, update_every, history, mode, (health_enabled == CONFIG_BOOLEAN_NO)?0:1);
+
+    if(!host) {
+        error("STREAM %s [receive from [%s]:%s]: failed to find/create host structure.", hostname, client_ip, client_port);
+        return 1;
+    }
 
     info("STREAM %s [receive from [%s]:%s]: metrics for host '%s' with machine_guid '%s': update every = %d, history = %d, memory mode = %s, health %s"
-         , host->hostname
+         , hostname
          , client_ip
          , client_port
-         , hostname
-         , machine_guid
-         , update_every
-         , history
-         , rrd_memory_mode_name(mode)
+         , host->hostname
+         , host->machine_guid
+         , host->rrd_update_every
+         , host->rrd_history_entries
+         , rrd_memory_mode_name(host->rrd_memory_mode)
          , (health_enabled == CONFIG_BOOLEAN_NO)?"disabled":((health_enabled == CONFIG_BOOLEAN_YES)?"enabled":"auto")
     );