@cryptotaxi247 / netdata-1 / commits / 5ead7a756

detect duplicate hosts

Costa Tsaousis (ktsaou) committed Feb 25, 2017 at 01:42 UTC 5ead7a7560b2a8e9afbfaf6300ad86374c5c5589
2 files changed +47 -33
src/rrdhost.c
+35 -26
@@ -187,35 +187,44 @@ RRDHOST *rrdhost_create(const char *hostname,
187 else localhost = host;
188 }
189
190 - if(rrdhost_index_add(host) != host)
191 - fatal("Host '%s': cannot add host to index. It already exists.", hostname);
190 + RRDHOST *t = rrdhost_index_add(host);
191 +
192 + if(t != host) {
193 + 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);
194 + rrdhost_free(host);
195 + host = NULL;
196 + }
197 + else {
198 + info("Host '%s' with guid '%s' initialized"
199 + ", os: %s"
200 + ", update every: %d"
201 + ", memory mode: %s"
202 + ", history entries: %d"
203 + ", streaming: %s"
204 + ", health: %s"
205 + ", cache_dir: '%s'"
206 + ", varlib_dir: '%s'"
207 + ", health_log: '%s'"
208 + ", alarms default handler: '%s'"
209 + ", alarms default recipient: '%s'"
210 + , host->hostname
211 + , host->machine_guid
212 + , host->os
213 + , host->rrd_update_every
214 + , rrd_memory_mode_name(host->rrd_memory_mode)
215 + , host->rrd_history_entries
216 + , host->rrdpush_enabled?"enabled":"disabled"
217 + , host->health_enabled?"enabled":"disabled"
218 + , host->cache_dir
219 + , host->varlib_dir
220 + , host->health_log_filename
221 + , host->health_default_exec
222 + , host->health_default_recipient
223 + );
224 + }
225
226 rrd_unlock();
227
195 - info("Host '%s' with guid '%s' initialized"
196 - ", update every: %d"
197 - ", memory mode: %s"
198 - ", history entries: %d"
199 - ", streaming: %s"
200 - ", health: %s"
201 - ", cache_dir: '%s'"
202 - ", varlib_dir: '%s'"
203 - ", health_log: '%s'"
204 - ", alarms default handler: '%s'"
205 - ", alarms default recipient: '%s'"
206 - , host->hostname
207 - , host->machine_guid
208 - , host->rrd_update_every
209 - , rrd_memory_mode_name(host->rrd_memory_mode)
210 - , host->rrd_history_entries
211 - , host->rrdpush_enabled?"enabled: ":"disabled"
212 - , host->health_enabled?"enabled":"disabled"
213 - , host->cache_dir
214 - , host->varlib_dir
215 - , host->health_log_filename
216 - , host->health_default_exec
217 - , host->health_default_recipient
218 - );
228 return host;
229 }
230
src/rrdpush.c
+12 -7
@@ -449,17 +449,22 @@ int rrdpush_receive(int fd, const char *key, const char *hostname, const char *m
449 if(!strcmp(machine_guid, "localhost"))
450 host = localhost;
451 else
452 - host = rrdhost_find_or_create(hostname, machine_guid, os, update_every, history, mode, health_enabled?1:0);
452 + host = rrdhost_find_or_create(hostname, machine_guid, os, update_every, history, mode, (health_enabled == CONFIG_BOOLEAN_NO)?0:1);
453 +
454 + if(!host) {
455 + error("STREAM %s [receive from [%s]:%s]: failed to find/create host structure.", hostname, client_ip, client_port);
456 + return 1;
457 + }
458
459 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"
455 - , host->hostname
460 + , hostname
461 , client_ip
462 , client_port
458 - , hostname
459 - , machine_guid
460 - , update_every
461 - , history
462 - , rrd_memory_mode_name(mode)
463 + , host->hostname
464 + , host->machine_guid
465 + , host->rrd_update_every
466 + , host->rrd_history_entries
467 + , rrd_memory_mode_name(host->rrd_memory_mode)
468 , (health_enabled == CONFIG_BOOLEAN_NO)?"disabled":((health_enabled == CONFIG_BOOLEAN_YES)?"enabled":"auto")
469 );
470