diff options
author | Emmanuel Vasilakis <mrzammler@mm.st> | 2023-02-01 19:04:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-01 19:04:30 +0200 |
commit | c5c83a30dd8f0e79dfbf92ba25effd20b018fc99 (patch) | |
tree | a1479763ed0f060d9b7f1a717026e6c7a7820b3e | |
parent | f444be6a847cc255b53483fe1a01d79fe8e6dd6c (diff) |
Don't send alert variables to the cloud (#14325)
filter alert events from variables alert config
-rw-r--r-- | database/sqlite/sqlite_aclk_alert.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/database/sqlite/sqlite_aclk_alert.c b/database/sqlite/sqlite_aclk_alert.c index 653b611fea..ce284ebc3d 100644 --- a/database/sqlite/sqlite_aclk_alert.c +++ b/database/sqlite/sqlite_aclk_alert.c @@ -43,6 +43,34 @@ void update_filtered(ALARM_ENTRY *ae, uint32_t unique_id, char *uuid_str) { ae->flags |= HEALTH_ENTRY_FLAG_ACLK_QUEUED; } +static inline bool is_event_from_alert_variable_config(uint32_t unique_id, char *uuid_str) { + sqlite3_stmt *res = NULL; + int rc = 0; + bool ret = false; + + char sql[ACLK_SYNC_QUERY_SIZE]; + snprintfz(sql,ACLK_SYNC_QUERY_SIZE-1, "select hl.unique_id from health_log_%s hl, alert_hash ah where hl.unique_id = %u " \ + "and hl.config_hash_id = ah.hash_id " \ + "and ah.warn is null and ah.crit is null;", uuid_str, unique_id); + + rc = sqlite3_prepare_v2(db_meta, sql, -1, &res, 0); + if (rc != SQLITE_OK) { + error_report("Failed to prepare statement when trying to check for alert variables."); + return false; + } + + rc = sqlite3_step_monitored(res); + if (likely(rc == SQLITE_ROW)) { + ret = true; + } + + rc = sqlite3_finalize(res); + if (unlikely(rc != SQLITE_OK)) + error_report("Failed to finalize statement when trying to check for alert variables, rc = %d", rc); + + return ret; +} + #define MAX_REMOVED_PERIOD 86400 //decide if some events should be sent or not int should_send_to_cloud(RRDHOST *host, ALARM_ENTRY *ae) @@ -59,6 +87,9 @@ int should_send_to_cloud(RRDHOST *host, ALARM_ENTRY *ae) if (unlikely(uuid_is_null(ae->config_hash_id))) return 0; + if (is_event_from_alert_variable_config(ae->unique_id, uuid_str)) + return 0; + char sql[ACLK_SYNC_QUERY_SIZE]; uuid_t config_hash_id; RRDCALC_STATUS status; |