Send alert chart labels config key to cloud (#15283)
* add chart_labels to alert_hash * store chart_labels in alert_hash * transmit to cloud
Emmanuel Vasilakis committed
Jul 3, 2023 at 16:40 UTC
6dd2fc735ad37165de442893109cc5a33bc83522
7 files changed
+34
-6
aclk/aclk-schemas
+1
-1
@@ -1 +1 @@
1
-Subproject commit a9fac9a0e4ebfa021d6f900403626213d28d6852
1
+Subproject commit 2aba113db56ac32deccc1e83784c4b3b6fcfe1cd
aclk/schema-wrappers/alarm_config.cc
+5
@@ -48,6 +48,8 @@ void destroy_aclk_alarm_configuration(struct aclk_alarm_configuration *cfg)
48
freez(cfg->p_db_lookup_dimensions);
49
freez(cfg->p_db_lookup_method);
50
freez(cfg->p_db_lookup_options);
51
+
52
+ freez(cfg->chart_labels);
53
}
54
55
char *generate_provide_alarm_configuration(size_t *len, struct provide_alarm_configuration *data)
@@ -127,6 +129,9 @@ char *generate_provide_alarm_configuration(size_t *len, struct provide_alarm_con
129
cfg->set_p_db_lookup_options(data->cfg.p_db_lookup_options);
130
cfg->set_p_update_every(data->cfg.p_update_every);
131
132
+ if (data->cfg.chart_labels)
133
+ cfg->set_chart_labels(data->cfg.chart_labels);
134
+
135
*len = PROTO_COMPAT_MSG_SIZE(msg);
136
char *bin = (char*)mallocz(*len);
137
if (!msg.SerializeToArray(bin, *len))
aclk/schema-wrappers/alarm_config.h
+2
@@ -50,6 +50,8 @@ struct aclk_alarm_configuration {
50
char *p_db_lookup_method;
51
char *p_db_lookup_options;
52
int32_t p_update_every;
53
+
54
+ char *chart_labels;
55
};
56
57
void destroy_aclk_alarm_configuration(struct aclk_alarm_configuration *cfg);
database/sqlite/sqlite_aclk_alert.c
+3
-1
@@ -519,7 +519,7 @@ void aclk_send_alarm_configuration(char *config_hash)
519
#define SQL_SELECT_ALERT_CONFIG "SELECT alarm, template, on_key, class, type, component, os, hosts, plugin," \
520
"module, charts, families, lookup, every, units, green, red, calc, warn, crit, to_key, exec, delay, repeat, info," \
521
"options, host_labels, p_db_lookup_dimensions, p_db_lookup_method, p_db_lookup_options, p_db_lookup_after," \
522
- "p_db_lookup_before, p_update_every FROM alert_hash WHERE hash_id = @hash_id;"
522
+ "p_db_lookup_before, p_update_every, chart_labels FROM alert_hash WHERE hash_id = @hash_id;"
523
int aclk_push_alert_config_event(char *node_id __maybe_unused, char *config_hash __maybe_unused)
524
{
525
int rc = 0;
@@ -620,6 +620,8 @@ int aclk_push_alert_config_event(char *node_id __maybe_unused, char *config_hash
620
621
alarm_config.p_update_every = sqlite3_column_int(res, 32);
622
623
+ alarm_config.chart_labels = sqlite3_column_bytes(res, 33) > 0 ? strdupz((char *)sqlite3_column_text(res, 33)) : NULL;
624
+
625
p_alarm_config.cfg_hash = strdupz((char *) config_hash);
626
p_alarm_config.cfg = alarm_config;
627
}
database/sqlite/sqlite_db_migration.c
+15
@@ -78,6 +78,10 @@ const char *database_migrate_v5_v6[] = {
78
NULL
79
};
80
81
+const char *database_migrate_v9_v10[] = {
82
+ "ALTER TABLE alert_hash ADD chart_labels TEXT;",
83
+ NULL
84
+};
85
86
static int do_migration_v1_v2(sqlite3 *database, const char *name)
87
{
@@ -287,6 +291,16 @@ static int do_migration_v8_v9(sqlite3 *database, const char *name)
291
return 0;
292
}
293
294
+static int do_migration_v9_v10(sqlite3 *database, const char *name)
295
+{
296
+ UNUSED(name);
297
+ info("Running \"%s\" database migration", name);
298
+
299
+ if (table_exists_in_database("alert_hash") && !column_exists_in_table("alert_hash", "chart_labels"))
300
+ return init_database_batch(database, DB_CHECK_NONE, 0, &database_migrate_v9_v10[0]);
301
+ return 0;
302
+}
303
+
304
static int do_migration_noop(sqlite3 *database, const char *name)
305
{
306
UNUSED(database);
@@ -339,6 +353,7 @@ DATABASE_FUNC_MIGRATION_LIST migration_action[] = {
353
{.name = "v6 to v7", .func = do_migration_v6_v7},
354
{.name = "v7 to v8", .func = do_migration_v7_v8},
355
{.name = "v8 to v9", .func = do_migration_v8_v9},
356
+ {.name = "v9 to v10", .func = do_migration_v9_v10},
357
// the terminator of this array
358
{.name = NULL, .func = NULL}
359
};
database/sqlite/sqlite_functions.c
+2
-2
@@ -3,7 +3,7 @@
3
#include "sqlite_functions.h"
4
#include "sqlite_db_migration.h"
5
6
-#define DB_METADATA_VERSION 9
6
+#define DB_METADATA_VERSION 10
7
8
const char *database_config[] = {
9
"CREATE TABLE IF NOT EXISTS host(host_id BLOB PRIMARY KEY, hostname TEXT NOT NULL, "
@@ -32,7 +32,7 @@ const char *database_config[] = {
32
"every text, units text, calc text, families text, plugin text, module text, charts text, green text, "
33
"red text, warn text, crit text, exec text, to_key text, info text, delay text, options text, "
34
"repeat text, host_labels text, p_db_lookup_dimensions text, p_db_lookup_method text, p_db_lookup_options int, "
35
- "p_db_lookup_after int, p_db_lookup_before int, p_update_every int, source text);",
35
+ "p_db_lookup_after int, p_db_lookup_before int, p_update_every int, source text, chart_labels text);",
36
37
"CREATE INDEX IF NOT EXISTS alert_hash_index ON alert_hash (hash_id);",
38
database/sqlite/sqlite_health.c
+6
-2
@@ -975,8 +975,8 @@ void sql_health_alarm_log_load(RRDHOST *host) {
975
"on_key, class, component, type, os, hosts, lookup, every, units, calc, families, plugin, module, " \
976
"charts, green, red, warn, crit, exec, to_key, info, delay, options, repeat, host_labels, " \
977
"p_db_lookup_dimensions, p_db_lookup_method, p_db_lookup_options, p_db_lookup_after, " \
978
- "p_db_lookup_before, p_update_every, source) values (?1,unixepoch(),?2,?3,?4,?5,?6,?7,?8,?9,?10,?11,?12," \
979
- "?13,?14,?15,?16,?17,?18,?19,?20,?21,?22,?23,?24,?25,?26,?27,?28,?29,?30,?31,?32,?33,?34,?35);"
978
+ "p_db_lookup_before, p_update_every, source, chart_labels) values (?1,unixepoch(),?2,?3,?4,?5,?6,?7,?8,?9,?10,?11,?12," \
979
+ "?13,?14,?15,?16,?17,?18,?19,?20,?21,?22,?23,?24,?25,?26,?27,?28,?29,?30,?31,?32,?33,?34,?35,?36);"
980
981
int sql_store_alert_config_hash(uuid_t *hash_id, struct alert_config *cfg)
982
{
@@ -1160,6 +1160,10 @@ int sql_store_alert_config_hash(uuid_t *hash_id, struct alert_config *cfg)
1160
if (unlikely(rc != SQLITE_OK))
1161
goto bind_fail;
1162
1163
+ rc = sqlite3_bind_string_or_null(res, cfg->chart_labels, ++param);
1164
+ if (unlikely(rc != SQLITE_OK))
1165
+ goto bind_fail;
1166
+
1167
rc = execute_insert(res);
1168
if (unlikely(rc != SQLITE_DONE))
1169
error_report("Failed to store alert config, rc = %d", rc);