int entries,
RRD_MEMORY_MODE memory_mode,
int health_enabled,
+ int rrdpush_enabled,
+ char *rrdpush_destination,
+ char *rrdpush_api_key,
int is_localhost
) {
host->rrd_history_entries = entries;
host->rrd_memory_mode = memory_mode;
host->health_enabled = (memory_mode == RRD_MEMORY_MODE_NONE)? 0 : health_enabled;
- host->rrdpush_enabled = default_rrdpush_enabled;
+ host->rrdpush_enabled = (rrdpush_enabled && rrdpush_destination && *rrdpush_destination && rrdpush_api_key && *rrdpush_api_key);
+ host->rrdpush_destination = (host->rrdpush_enabled)?strdupz(rrdpush_destination):NULL;
+ host->rrdpush_api_key = (host->rrdpush_enabled)?strdupz(rrdpush_api_key):NULL;
host->rrdpush_pipe[0] = -1;
host->rrdpush_pipe[1] = -1;
- host->rrdpush_socket = -1;
+ host->rrdpush_socket = -1;
pthread_mutex_init(&host->rrdpush_mutex, NULL);
pthread_rwlock_init(&host->rrdhost_rwlock, NULL);
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"
+ " to: '%s' (api key: '%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->rrdpush_destination
+ , host->rrdpush_api_key
+ , 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;
}
-RRDHOST *rrdhost_find_or_create(const char *hostname, const char *guid, const char *os, int update_every, int history, RRD_MEMORY_MODE mode, int health_enabled) {
+RRDHOST *rrdhost_find_or_create(
+ const char *hostname
+ , const char *guid
+ , const char *os
+ , int update_every
+ , int history
+ , RRD_MEMORY_MODE mode
+ , int health_enabled
+ , int rrdpush_enabled
+ , char *rrdpush_destination
+ , char *rrdpush_api_key
+) {
debug(D_RRDHOST, "Searching for host '%s' with guid '%s'", hostname, guid);
RRDHOST *host = rrdhost_find(guid, 0);
if(!host) {
- host = rrdhost_create(hostname, guid, os, update_every, history, mode, health_enabled, 0);
+ host = rrdhost_create(
+ hostname
+ , guid
+ , os
+ , update_every
+ , history
+ , mode
+ , health_enabled
+ , rrdpush_enabled
+ , rrdpush_destination
+ , rrdpush_api_key
+ , 0
+ );
}
else {
host->health_enabled = health_enabled;
rrdpush_init();
debug(D_RRDHOST, "Initializing localhost with hostname '%s'", hostname);
- localhost = rrdhost_create(hostname,
- registry_get_this_machine_guid(),
- os_type,
- default_rrd_update_every,
- default_rrd_history_entries,
- default_rrd_memory_mode,
- default_health_enabled,
- 1
+ localhost = rrdhost_create(
+ hostname
+ , registry_get_this_machine_guid()
+ , os_type
+ , default_rrd_update_every
+ , default_rrd_history_entries
+ , default_rrd_memory_mode
+ , default_health_enabled
+ , default_rrdpush_enabled
+ , default_rrdpush_destination
+ , default_rrdpush_api_key
+ , 1
);
}
freez(host->os);
freez(host->cache_dir);
freez(host->varlib_dir);
+ freez(host->rrdpush_api_key);
+ freez(host->rrdpush_destination);
freez(host->health_default_exec);
freez(host->health_default_recipient);
freez(host->health_log_filename);