diff options
Diffstat (limited to 'database/sqlite/sqlite_aclk_alert.c')
-rw-r--r-- | database/sqlite/sqlite_aclk_alert.c | 49 |
1 files changed, 21 insertions, 28 deletions
diff --git a/database/sqlite/sqlite_aclk_alert.c b/database/sqlite/sqlite_aclk_alert.c index 1b58b4231d..079fc16ea0 100644 --- a/database/sqlite/sqlite_aclk_alert.c +++ b/database/sqlite/sqlite_aclk_alert.c @@ -10,7 +10,7 @@ // will replace call to aclk_update_alarm in health/health_log.c // and handle both cases -void sql_queue_alarm_to_aclk(RRDHOST *host, ALARM_ENTRY *ae) +int sql_queue_alarm_to_aclk(RRDHOST *host, ALARM_ENTRY *ae) { //check aclk architecture and handle old json alarm update to cloud //include also the valid statuses for this case @@ -23,54 +23,38 @@ void sql_queue_alarm_to_aclk(RRDHOST *host, ALARM_ENTRY *ae) ((ae->old_status == RRDCALC_STATUS_WARNING || ae->old_status == RRDCALC_STATUS_CRITICAL))) { aclk_update_alarm(host, ae); } - return; + return 0; #endif #ifdef ENABLE_NEW_CLOUD_PROTOCOL } if (ae->flags & HEALTH_ENTRY_FLAG_ACLK_QUEUED) - return; + return 0; if (ae->new_status == RRDCALC_STATUS_REMOVED || ae->new_status == RRDCALC_STATUS_UNINITIALIZED) - return; + return 0; if (unlikely(!host->dbsync_worker)) - return; + return 1; if (unlikely(uuid_is_null(ae->config_hash_id))) - return; - - struct aclk_database_cmd cmd; - memset(&cmd, 0, sizeof(cmd)); - cmd.opcode = ACLK_DATABASE_ADD_ALERT; - cmd.data = ae; - cmd.completion = NULL; - aclk_database_enq_cmd((struct aclk_database_worker_config *) host->dbsync_worker, &cmd); - ae->flags |= HEALTH_ENTRY_FLAG_ACLK_QUEUED; -#else - UNUSED(host); - UNUSED(ae); -#endif - return; -} + return 0; -// stores an alert entry to aclk_alert_ table -int aclk_add_alert_event(struct aclk_database_worker_config *wc, struct aclk_database_cmd cmd) -{ int rc = 0; CHECK_SQLITE_CONNECTION(db_meta); sqlite3_stmt *res_alert = NULL; - ALARM_ENTRY *ae = cmd.data; + char uuid_str[GUID_LEN + 1]; + uuid_unparse_lower_fix(&host->host_uuid, uuid_str); BUFFER *sql = buffer_create(1024); buffer_sprintf( sql, "INSERT INTO aclk_alert_%s (alert_unique_id, date_created) " - "VALUES (@alert_unique_id, strftime('%%s')); ", - wc->uuid_str); + "VALUES (@alert_unique_id, strftime('%%s')) on conflict (alert_unique_id) do nothing; ", + uuid_str); rc = sqlite3_prepare_v2(db_meta, buffer_tostring(sql), -1, &res_alert, 0); if (unlikely(rc != SQLITE_OK)) { @@ -84,15 +68,24 @@ int aclk_add_alert_event(struct aclk_database_worker_config *wc, struct aclk_dat goto bind_fail; rc = execute_insert(res_alert); - if (unlikely(rc != SQLITE_DONE)) + if (unlikely(rc != SQLITE_DONE)) { error_report("Failed to store alert event %u, rc = %d", ae->unique_id, rc); + goto bind_fail; + } + + ae->flags |= HEALTH_ENTRY_FLAG_ACLK_QUEUED; bind_fail: if (unlikely(sqlite3_finalize(res_alert) != SQLITE_OK)) error_report("Failed to reset statement in store alert event, rc = %d", rc); buffer_free(sql); - return (rc != SQLITE_DONE); + return 0; +#else + UNUSED(host); + UNUSED(ae); +#endif + return 0; } int rrdcalc_status_to_proto_enum(RRDCALC_STATUS status) |