diff options
Diffstat (limited to 'src/database')
-rw-r--r-- | src/database/sqlite/sqlite_aclk_node.c | 6 | ||||
-rw-r--r-- | src/database/sqlite/sqlite_health.c | 18 |
2 files changed, 18 insertions, 6 deletions
diff --git a/src/database/sqlite/sqlite_aclk_node.c b/src/database/sqlite/sqlite_aclk_node.c index 70d1ebda1..411b8bd70 100644 --- a/src/database/sqlite/sqlite_aclk_node.c +++ b/src/database/sqlite/sqlite_aclk_node.c @@ -167,6 +167,12 @@ void aclk_check_node_info_and_collectors(void) if (pp_queue_empty && wc->node_info_send_time && wc->node_info_send_time + 30 < now) { wc->node_info_send_time = 0; build_node_info(host); + if (netdata_cloud_enabled) { + netdata_mutex_lock(&host->receiver_lock); + int live = (host == localhost || host->receiver || !(rrdhost_flag_check(host, RRDHOST_FLAG_ORPHAN))) ? 1 : 0; + netdata_mutex_unlock(&host->receiver_lock); + aclk_host_state_update(host, live, 1); + } internal_error(true, "ACLK SYNC: Sending node info for %s", rrdhost_hostname(host)); } diff --git a/src/database/sqlite/sqlite_health.c b/src/database/sqlite/sqlite_health.c index 9304c8c73..b3ad12857 100644 --- a/src/database/sqlite/sqlite_health.c +++ b/src/database/sqlite/sqlite_health.c @@ -755,20 +755,20 @@ done: * Store an alert config hash in the database */ #define SQL_STORE_ALERT_CONFIG_HASH \ - "insert or replace into alert_hash (hash_id, date_updated, alarm, template, " \ + "INSERT OR REPLACE INTO alert_hash (hash_id, date_updated, alarm, template, " \ "on_key, class, component, type, lookup, every, units, calc, " \ "green, red, warn, crit, exec, to_key, info, delay, options, repeat, host_labels, " \ "p_db_lookup_dimensions, p_db_lookup_method, p_db_lookup_options, p_db_lookup_after, " \ "p_db_lookup_before, p_update_every, source, chart_labels, summary, time_group_condition, " \ "time_group_value, dims_group, data_source) " \ - "values (@hash_id,UNIXEPOCH(),@alarm,@template," \ + "VALUES (@hash_id,UNIXEPOCH(),@alarm,@template," \ "@on_key,@class,@component,@type,@lookup,@every,@units,@calc," \ "@green,@red,@warn,@crit,@exec,@to_key,@info,@delay,@options,@repeat,@host_labels," \ "@p_db_lookup_dimensions,@p_db_lookup_method,@p_db_lookup_options,@p_db_lookup_after," \ "@p_db_lookup_before,@p_update_every,@source,@chart_labels,@summary, @time_group_condition, " \ "@time_group_value, @dims_group, @data_source)" -void sql_alert_store_config(RRD_ALERT_PROTOTYPE *ap __maybe_unused) +void sql_alert_store_config(RRD_ALERT_PROTOTYPE *ap) { static __thread sqlite3_stmt *res = NULL; int param = 0; @@ -776,7 +776,7 @@ void sql_alert_store_config(RRD_ALERT_PROTOTYPE *ap __maybe_unused) if (!PREPARE_COMPILED_STATEMENT(db_meta, SQL_STORE_ALERT_CONFIG_HASH, &res)) return; - BUFFER *buf = buffer_create(128, NULL); + CLEAN_BUFFER *buf = buffer_create(128, NULL); SQLITE_BIND_FAIL( done, sqlite3_bind_blob(res, ++param, &ap->config.hash_id, sizeof(ap->config.hash_id), SQLITE_STATIC)); @@ -842,7 +842,14 @@ void sql_alert_store_config(RRD_ALERT_PROTOTYPE *ap __maybe_unused) else SQLITE_BIND_FAIL(done, sqlite3_bind_null(res, ++param)); - SQLITE_BIND_FAIL(done, sqlite3_bind_int(res, ++param, ap->config.update_every)); + char repeat[255]; + if (!ap->config.has_custom_repeat_config) + SQLITE_BIND_FAIL(done, sqlite3_bind_null(res, ++param)); + else { + snprintfz(repeat, sizeof(repeat) - 1, "warning %us critical %us", ap->config.warn_repeat_every, ap->config.crit_repeat_every); + SQLITE_BIND_FAIL(done, sqlite3_bind_text(res, ++param, repeat, -1, SQLITE_STATIC)); + } + SQLITE_BIND_FAIL(done, SQLITE3_BIND_STRING_OR_NULL(res, ++param, ap->match.host_labels)); if (ap->config.after) { @@ -875,7 +882,6 @@ void sql_alert_store_config(RRD_ALERT_PROTOTYPE *ap __maybe_unused) error_report("Failed to store alert config, rc = %d", rc); done: - buffer_free(buf); REPORT_BIND_FAIL(res, param); SQLITE_RESET(res); } |