diff options
Diffstat (limited to '')
-rw-r--r-- | src/database/sqlite/sqlite_health.c (renamed from database/sqlite/sqlite_health.c) | 365 |
1 files changed, 113 insertions, 252 deletions
diff --git a/database/sqlite/sqlite_health.c b/src/database/sqlite/sqlite_health.c index 7d79ff70b..ea883c51b 100644 --- a/database/sqlite/sqlite_health.c +++ b/src/database/sqlite/sqlite_health.c @@ -3,6 +3,7 @@ #include "sqlite_health.h" #include "sqlite_functions.h" #include "sqlite_db_migration.h" +#include "health/health_internals.h" #define MAX_HEALTH_SQL_SIZE 2048 #define SQLITE3_BIND_STRING_OR_NULL(res, key, param) \ @@ -101,7 +102,8 @@ failed: "config_hash_id, name, chart, exec, recipient, units, chart_context, last_transition_id, chart_name) " \ "VALUES (@host_id,@alarm_id, @config_hash_id,@name,@chart,@exec,@recipient,@units,@chart_context," \ "@last_transition_id,@chart_name) ON CONFLICT (host_id, alarm_id) DO UPDATE " \ - "SET last_transition_id = excluded.last_transition_id, chart_name = excluded.chart_name RETURNING health_log_id" + "SET last_transition_id = excluded.last_transition_id, chart_name = excluded.chart_name, " \ + "config_hash_id=excluded.config_hash_id RETURNING health_log_id" #define SQL_INSERT_HEALTH_LOG_DETAIL \ "INSERT INTO health_log_detail (health_log_id, unique_id, alarm_id, alarm_event_id, " \ @@ -893,18 +895,21 @@ void sql_health_alarm_log_load(RRDHOST *host) /* * 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, " \ - "on_key, class, component, type, os, hosts, lookup, every, units, calc, plugin, module, " \ - "charts, 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) values (@hash_id,UNIXEPOCH(),@alarm,@template," \ - "@on_key,@class,@component,@type,@os,@hosts,@lookup,@every,@units,@calc,@plugin,@module," \ - "@charts,@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)" - -int sql_store_alert_config_hash(uuid_t *hash_id, struct alert_config *cfg) +#define SQL_STORE_ALERT_CONFIG_HASH \ + "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," \ + "@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)" + +int sql_alert_store_config(RRD_ALERT_PROTOTYPE *ap __maybe_unused) { static __thread sqlite3_stmt *res = NULL; int rc, param = 0; @@ -923,133 +928,153 @@ int sql_store_alert_config_hash(uuid_t *hash_id, struct alert_config *cfg) return 1; } } + BUFFER *buf = buffer_create(128, NULL); - rc = sqlite3_bind_blob(res, ++param, hash_id, sizeof(*hash_id), SQLITE_STATIC); + rc = sqlite3_bind_blob(res, ++param, &ap->config.hash_id, sizeof(ap->config.hash_id), SQLITE_STATIC); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->alarm, ++param); - if (unlikely(rc != SQLITE_OK)) - goto bind_fail; + if (ap->match.is_template) + rc = SQLITE3_BIND_STRING_OR_NULL(res, NULL, ++param); + else + rc = SQLITE3_BIND_STRING_OR_NULL(res, ap->config.name, ++param); - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->template_key, ++param); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->on, ++param); - if (unlikely(rc != SQLITE_OK)) - goto bind_fail; + if (ap->match.is_template) + rc = SQLITE3_BIND_STRING_OR_NULL(res, ap->config.name, ++param); + else + rc = SQLITE3_BIND_STRING_OR_NULL(res, NULL, ++param); - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->classification, ++param); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->component, ++param); + if (ap->match.is_template) + rc = SQLITE3_BIND_STRING_OR_NULL(res, ap->match.on.context, ++param); + else + rc = SQLITE3_BIND_STRING_OR_NULL(res, ap->match.on.chart, ++param); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->type, ++param); + rc = SQLITE3_BIND_STRING_OR_NULL(res, ap->config.classification, ++param); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->os, ++param); + rc = SQLITE3_BIND_STRING_OR_NULL(res, ap->config.component, ++param); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->host, ++param); + rc = SQLITE3_BIND_STRING_OR_NULL(res, ap->config.type, ++param); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->lookup, ++param); + // Rebuild lookup + rc = SQLITE3_BIND_STRING_OR_NULL(res, NULL, ++param); // lookup line if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->every, ++param); + rc = sqlite3_bind_int(res, ++param, ap->config.update_every); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->units, ++param); + rc = SQLITE3_BIND_STRING_OR_NULL(res, ap->config.units, ++param); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->calc, ++param); + if (ap->config.calculation) + rc = sqlite3_bind_text(res, ++param, expression_source(ap->config.calculation), -1, SQLITE_STATIC); + else + rc = sqlite3_bind_null(res, ++param); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->plugin, ++param); + NETDATA_DOUBLE green = NAN; + rc = sqlite3_bind_double(res, ++param, green); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->module, ++param); + NETDATA_DOUBLE red = NAN; + rc = sqlite3_bind_double(res, ++param, red); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->charts, ++param); + if (ap->config.warning) + rc = sqlite3_bind_text(res, ++param, expression_source(ap->config.warning), -1, SQLITE_STATIC); + else + rc = sqlite3_bind_null(res, ++param); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->green, ++param); + if (ap->config.critical) + rc = sqlite3_bind_text(res, ++param, expression_source(ap->config.critical), -1, SQLITE_STATIC); + else + rc = sqlite3_bind_null(res, ++param); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->red, ++param); + rc = SQLITE3_BIND_STRING_OR_NULL(res, ap->config.exec, ++param); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->warn, ++param); + rc = SQLITE3_BIND_STRING_OR_NULL(res, ap->config.recipient, ++param); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->crit, ++param); + rc = SQLITE3_BIND_STRING_OR_NULL(res, ap->config.info, ++param); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->exec, ++param); - if (unlikely(rc != SQLITE_OK)) - goto bind_fail; + if (ap->config.delay_up_duration) + buffer_sprintf(buf, "up %ds ", ap->config.delay_up_duration); - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->to, ++param); - if (unlikely(rc != SQLITE_OK)) - goto bind_fail; + if (ap->config.delay_down_duration) + buffer_sprintf(buf, "down %ds ", ap->config.delay_down_duration); - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->info, ++param); - if (unlikely(rc != SQLITE_OK)) - goto bind_fail; + if (ap->config.delay_multiplier) + buffer_sprintf(buf, "multiplier %.1f ", ap->config.delay_multiplier); + + if (ap->config.delay_max_duration) + buffer_sprintf(buf, "max %ds", ap->config.delay_max_duration); - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->delay, ++param); + // delay + rc = sqlite3_bind_text(res, ++param, buffer_tostring(buf), -1, SQLITE_STATIC); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->options, ++param); + if (ap->config.alert_action_options & ALERT_ACTION_OPTION_NO_CLEAR_NOTIFICATION) + rc = sqlite3_bind_text(res, ++param, "no-clear-notification", -1, SQLITE_STATIC); + else + rc = sqlite3_bind_null(res, ++param); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->repeat, ++param); + rc = sqlite3_bind_int(res, ++param, ap->config.update_every); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->host_labels, ++param); + rc = SQLITE3_BIND_STRING_OR_NULL(res, ap->match.host_labels, ++param); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - if (cfg->p_db_lookup_after) { - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->p_db_lookup_dimensions, ++param); + if (ap->config.after) { + rc = SQLITE3_BIND_STRING_OR_NULL(res, ap->config.dimensions, ++param); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->p_db_lookup_method, ++param); + rc = sqlite3_bind_text(res, ++param, time_grouping_id2txt(ap->config.time_group), -1, SQLITE_STATIC); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = sqlite3_bind_int(res, ++param, (int) cfg->p_db_lookup_options); + rc = sqlite3_bind_int(res, ++param, (int) RRDR_OPTIONS_REMOVE_OVERLAPPING(ap->config.options)); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = sqlite3_bind_int(res, ++param, (int) cfg->p_db_lookup_after); + rc = sqlite3_bind_int64(res, ++param, (int) ap->config.after); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = sqlite3_bind_int(res, ++param, (int) cfg->p_db_lookup_before); + rc = sqlite3_bind_int64(res, ++param, (int) ap->config.before); if (unlikely(rc != SQLITE_OK)) goto bind_fail; } else { @@ -1074,19 +1099,35 @@ int sql_store_alert_config_hash(uuid_t *hash_id, struct alert_config *cfg) goto bind_fail; } - rc = sqlite3_bind_int(res, ++param, cfg->p_update_every); + rc = sqlite3_bind_int(res, ++param, ap->config.update_every); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->source, ++param); + rc = SQLITE3_BIND_STRING_OR_NULL(res, ap->config.source, ++param); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->chart_labels, ++param); + rc = SQLITE3_BIND_STRING_OR_NULL(res, ap->match.chart_labels, ++param); if (unlikely(rc != SQLITE_OK)) goto bind_fail; - rc = SQLITE3_BIND_STRING_OR_NULL(res, cfg->summary, ++param); + rc = SQLITE3_BIND_STRING_OR_NULL(res, ap->config.summary, ++param); + if (unlikely(rc != SQLITE_OK)) + goto bind_fail; + + rc = sqlite3_bind_int(res, ++param, ap->config.time_group_condition); + if (unlikely(rc != SQLITE_OK)) + goto bind_fail; + + rc = sqlite3_bind_double(res, ++param, ap->config.time_group_value); + if (unlikely(rc != SQLITE_OK)) + goto bind_fail; + + rc = sqlite3_bind_int(res, ++param, ap->config.dims_group); + if (unlikely(rc != SQLITE_OK)) + goto bind_fail; + + rc = sqlite3_bind_int(res, ++param, ap->config.data_source); if (unlikely(rc != SQLITE_OK)) goto bind_fail; @@ -1098,9 +1139,11 @@ int sql_store_alert_config_hash(uuid_t *hash_id, struct alert_config *cfg) if (unlikely(rc != SQLITE_OK)) error_report("Failed to reset statement in alert hash_id store function, rc = %d", rc); + buffer_free(buf); return 0; bind_fail: + buffer_free(buf); error_report("Failed to bind parameter %d to store alert hash_id, rc = %d", param, rc); rc = sqlite3_reset(res); if (unlikely(rc != SQLITE_OK)) @@ -1108,75 +1151,6 @@ bind_fail: return 1; } -/* - alert hashes are used for cloud communication. - if cloud is disabled or openssl is not available (which will prevent cloud connectivity) - skip hash calculations -*/ -#if defined ENABLE_HTTPS -#define DIGEST_ALERT_CONFIG_VAL(v) ((v) ? EVP_DigestUpdate(evpctx, (string2str(v)), string_strlen((v))) : EVP_DigestUpdate(evpctx, "", 1)) -#endif -int alert_hash_and_store_config( - uuid_t hash_id, - struct alert_config *cfg, - int store_hash) -{ -#if defined ENABLE_HTTPS - EVP_MD_CTX *evpctx; - unsigned char hash_value[EVP_MAX_MD_SIZE]; - unsigned int hash_len; - evpctx = EVP_MD_CTX_create(); - EVP_DigestInit_ex(evpctx, EVP_sha256(), NULL); - - DIGEST_ALERT_CONFIG_VAL(cfg->alarm); - DIGEST_ALERT_CONFIG_VAL(cfg->template_key); - DIGEST_ALERT_CONFIG_VAL(cfg->os); - DIGEST_ALERT_CONFIG_VAL(cfg->host); - DIGEST_ALERT_CONFIG_VAL(cfg->on); - DIGEST_ALERT_CONFIG_VAL(cfg->plugin); - DIGEST_ALERT_CONFIG_VAL(cfg->module); - DIGEST_ALERT_CONFIG_VAL(cfg->charts); - DIGEST_ALERT_CONFIG_VAL(cfg->lookup); - DIGEST_ALERT_CONFIG_VAL(cfg->calc); - DIGEST_ALERT_CONFIG_VAL(cfg->every); - DIGEST_ALERT_CONFIG_VAL(cfg->green); - DIGEST_ALERT_CONFIG_VAL(cfg->red); - DIGEST_ALERT_CONFIG_VAL(cfg->warn); - DIGEST_ALERT_CONFIG_VAL(cfg->crit); - DIGEST_ALERT_CONFIG_VAL(cfg->exec); - DIGEST_ALERT_CONFIG_VAL(cfg->to); - DIGEST_ALERT_CONFIG_VAL(cfg->units); - DIGEST_ALERT_CONFIG_VAL(cfg->info); - DIGEST_ALERT_CONFIG_VAL(cfg->classification); - DIGEST_ALERT_CONFIG_VAL(cfg->component); - DIGEST_ALERT_CONFIG_VAL(cfg->type); - DIGEST_ALERT_CONFIG_VAL(cfg->delay); - DIGEST_ALERT_CONFIG_VAL(cfg->options); - DIGEST_ALERT_CONFIG_VAL(cfg->repeat); - DIGEST_ALERT_CONFIG_VAL(cfg->host_labels); - DIGEST_ALERT_CONFIG_VAL(cfg->chart_labels); - DIGEST_ALERT_CONFIG_VAL(cfg->summary); - - EVP_DigestFinal_ex(evpctx, hash_value, &hash_len); - EVP_MD_CTX_destroy(evpctx); - fatal_assert(hash_len > sizeof(uuid_t)); - - char uuid_str[UUID_STR_LEN]; - uuid_unparse_lower(*((uuid_t *)&hash_value), uuid_str); - uuid_copy(hash_id, *((uuid_t *)&hash_value)); - - /* store everything, so it can be recreated when not in memory or just a subset ? */ - if (store_hash) - (void)sql_store_alert_config_hash( (uuid_t *)&hash_value, cfg); -#else - UNUSED(hash_id); - UNUSED(cfg); - UNUSED(store_hash); -#endif - - return 1; -} - #define SQL_SELECT_HEALTH_LAST_EXECUTED_EVENT \ "SELECT hld.new_status FROM health_log hl, health_log_detail hld " \ "WHERE hl.host_id = @host_id AND hl.alarm_id = @alarm_id AND hld.unique_id != @unique_id AND hld.flags & @flags " \ @@ -1580,10 +1554,9 @@ static uint32_t get_next_alarm_event_id(uint64_t health_log_id, uint32_t alarm_i } #define SQL_GET_ALARM_ID \ - "SELECT alarm_id, health_log_id FROM health_log WHERE host_id = @host_id AND chart = @chart " \ - "AND name = @name AND config_hash_id = @config_hash_id" + "SELECT alarm_id, health_log_id FROM health_log WHERE host_id = @host_id AND chart = @chart AND name = @name" -uint32_t sql_get_alarm_id(RRDHOST *host, STRING *chart, STRING *name, uint32_t *next_event_id, uuid_t *config_hash_id) +uint32_t sql_get_alarm_id(RRDHOST *host, STRING *chart, STRING *name, uint32_t *next_event_id) { int rc = 0; sqlite3_stmt *res = NULL; @@ -1617,13 +1590,6 @@ uint32_t sql_get_alarm_id(RRDHOST *host, STRING *chart, STRING *name, uint32_t * return alarm_id; } - rc = sqlite3_bind_blob(res, 4, config_hash_id, sizeof(*config_hash_id), SQLITE_STATIC); - if (unlikely(rc != SQLITE_OK)) { - error_report("Failed to bind config_hash_id parameter for SQL_GET_ALARM_ID."); - sqlite3_finalize(res); - return alarm_id; - } - while (sqlite3_step_monitored(res) == SQLITE_ROW) { alarm_id = (uint32_t) sqlite3_column_int64(res, 0); health_log_id = (uint64_t) sqlite3_column_int64(res, 1); @@ -1639,111 +1605,6 @@ uint32_t sql_get_alarm_id(RRDHOST *host, STRING *chart, STRING *name, uint32_t * return alarm_id; } -#define SQL_UPDATE_ALARM_ID_WITH_CONFIG_HASH \ - "UPDATE health_log SET config_hash_id = @config_hash_id WHERE host_id = @host_id AND alarm_id = @alarm_id " \ - "AND health_log_id = @health_log_id" - -void sql_update_alarm_with_config_hash(RRDHOST *host, uint32_t alarm_id, uint64_t health_log_id, uuid_t *config_hash_id) -{ - int rc = 0; - sqlite3_stmt *res = NULL; - - rc = sqlite3_prepare_v2(db_meta, SQL_UPDATE_ALARM_ID_WITH_CONFIG_HASH, -1, &res, 0); - if (rc != SQLITE_OK) { - error_report("Failed to prepare statement when trying to update an alarm id with a config hash."); - return; - } - - rc = sqlite3_bind_blob(res, 1, config_hash_id, sizeof(*config_hash_id), SQLITE_STATIC); - if (unlikely(rc != SQLITE_OK)) { - error_report("Failed to bind config_hash_id parameter for SQL_UPDATE_ALARM_ID_WITH_CONFIG_HASH."); - goto done; - } - - rc = sqlite3_bind_blob(res, 2, &host->host_uuid, sizeof(host->host_uuid), SQLITE_STATIC); - if (unlikely(rc != SQLITE_OK)) { - error_report("Failed to bind host_id parameter for SQL_UPDATE_ALARM_ID_WITH_CONFIG_HASH."); - goto done; - } - - rc = sqlite3_bind_int64(res, 3, (sqlite3_int64) alarm_id); - if (unlikely(rc != SQLITE_OK)) { - error_report("Failed to bind alarm_id parameter for SQL_GET_ALARM_ID."); - goto done; - } - - rc = sqlite3_bind_int64(res, 4, (sqlite3_int64) health_log_id); - if (unlikely(rc != SQLITE_OK)) { - error_report("Failed to bind alarm_id parameter for SQL_GET_ALARM_ID."); - goto done; - } - - rc = execute_insert(res); - if (unlikely(rc != SQLITE_DONE)) - error_report("Failed to execute SQL_UPDATE_ALARM_ID_WITH_CONFIG_HASH, rc = %d", rc); - -done: - rc = sqlite3_finalize(res); - if (unlikely(rc != SQLITE_OK)) - error_report("Failed to reset statement to update health log detail table with config hash ids, rc = %d", rc); - -} - -#define SQL_GET_ALARM_ID_CHECK_ZERO_HASH \ - "SELECT alarm_id, health_log_id FROM health_log WHERE host_id = @host_id AND chart = @chart " \ - "AND name = @name AND (config_hash_id IS NULL OR config_hash_id = ZEROBLOB(16))" - -uint32_t sql_get_alarm_id_check_zero_hash(RRDHOST *host, STRING *chart, STRING *name, uint32_t *next_event_id, uuid_t *config_hash_id) -{ - int rc = 0; - sqlite3_stmt *res = NULL; - uint32_t alarm_id = 0; - uint64_t health_log_id = 0; - - rc = sqlite3_prepare_v2(db_meta, SQL_GET_ALARM_ID_CHECK_ZERO_HASH, -1, &res, 0); - if (rc != SQLITE_OK) { - error_report("Failed to prepare statement when trying to get an alarm id with zero hash"); - return alarm_id; - } - - rc = sqlite3_bind_blob(res, 1, &host->host_uuid, sizeof(host->host_uuid), SQLITE_STATIC); - if (unlikely(rc != SQLITE_OK)) { - error_report("Failed to bind host_id parameter for SQL_GET_ALARM_ID_CHECK_ZERO_HASH."); - sqlite3_finalize(res); - return alarm_id; - } - - rc = SQLITE3_BIND_STRING_OR_NULL(res, chart, 2); - if (unlikely(rc != SQLITE_OK)) { - error_report("Failed to bind char parameter for SQL_GET_ALARM_ID_CHECK_ZERO_HASH."); - sqlite3_finalize(res); - return alarm_id; - } - - rc = SQLITE3_BIND_STRING_OR_NULL(res, name, 3); - if (unlikely(rc != SQLITE_OK)) { - error_report("Failed to bind name parameter for SQL_GET_ALARM_ID_CHECK_ZERO_HASH."); - sqlite3_finalize(res); - return alarm_id; - } - - while (sqlite3_step_monitored(res) == SQLITE_ROW) { - alarm_id = (uint32_t) sqlite3_column_int64(res, 0); - health_log_id = (uint64_t) sqlite3_column_int64(res, 1); - } - - rc = sqlite3_finalize(res); - if (unlikely(rc != SQLITE_OK)) - error_report("Failed to finalize the statement while getting an alarm id."); - - if (alarm_id) { - sql_update_alarm_with_config_hash(host, alarm_id, health_log_id, config_hash_id); - *next_event_id = get_next_alarm_event_id(health_log_id, alarm_id); - } - - return alarm_id; -} - #define SQL_GET_ALARM_ID_FROM_TRANSITION_ID \ "SELECT hld.alarm_id, hl.host_id, hl.chart_context FROM health_log_detail hld, health_log hl " \ "WHERE hld.transition_id = @transition_id " \ @@ -1996,10 +1857,11 @@ done_only_drop: #define SQL_POPULATE_TEMP_CONFIG_TARGET_TABLE "INSERT INTO c_%p (hash_id) VALUES (@hash_id)" #define SQL_SEARCH_CONFIG_LIST \ - "SELECT ah.hash_id, alarm, template, on_key, class, component, type, os, hosts, lookup, every, " \ - " units, calc, families, plugin, module, charts, green, red, warn, crit, " \ + "SELECT ah.hash_id, alarm, template, on_key, class, component, type, lookup, every, " \ + " units, calc, families, 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 " \ + " 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 " \ " FROM alert_hash ah, c_%p t where ah.hash_id = t.hash_id" int sql_get_alert_configuration( @@ -2079,16 +1941,11 @@ int sql_get_alert_configuration( acd.classification = (const char *) sqlite3_column_text(res, param++); acd.component = (const char *) sqlite3_column_text(res, param++); acd.type = (const char *) sqlite3_column_text(res, param++); - acd.selectors.os = (const char *) sqlite3_column_text(res, param++); - acd.selectors.hosts = (const char *) sqlite3_column_text(res, param++); acd.value.db.lookup = (const char *) sqlite3_column_text(res, param++); acd.value.every = (const char *) sqlite3_column_text(res, param++); acd.value.units = (const char *) sqlite3_column_text(res, param++); acd.value.calc = (const char *) sqlite3_column_text(res, param++); acd.selectors.families = (const char *) sqlite3_column_text(res, param++); - acd.selectors.plugin = (const char *) sqlite3_column_text(res, param++); - acd.selectors.module = (const char *) sqlite3_column_text(res, param++); - acd.selectors.charts = (const char *) sqlite3_column_text(res, param++); acd.status.green = (const char *) sqlite3_column_text(res, param++); acd.status.red = (const char *) sqlite3_column_text(res, param++); acd.status.warn = (const char *) sqlite3_column_text(res, param++); @@ -2109,6 +1966,10 @@ int sql_get_alert_configuration( acd.source = (const char *) sqlite3_column_text(res, param++); acd.selectors.chart_labels = (const char *) sqlite3_column_text(res, param++); acd.summary = (const char *) sqlite3_column_text(res, param++); + acd.value.db.time_group_condition =(int32_t) sqlite3_column_int(res, param++); + acd.value.db.time_group_value = sqlite3_column_double(res, param++); + acd.value.db.dims_group = (int32_t) sqlite3_column_int(res, param++); + acd.value.db.data_source = (int32_t) sqlite3_column_int(res, param++); cb(&acd, data); added++; |