Send alerts summary field to cloud (#16056)
* new aclk schema * transmit summary to cloud and expose in v2/alerts * missing assign
Emmanuel Vasilakis committed
Oct 2, 2023 at 09:56 UTC
8c9492a4767001459d99e232b58f63baf1e95f91
9 files changed
+29
-12
aclk/aclk-schemas
+1
-1
@@ -1 +1 @@
1
-Subproject commit 40703f5e0258b3f4a97d3767e0f4e6833801b7d1
1
+Subproject commit 83c661c0dcddb9526814ebbd0668fbc3e281f03f
aclk/schema-wrappers/alarm_config.cc
+4
@@ -50,6 +50,7 @@ void destroy_aclk_alarm_configuration(struct aclk_alarm_configuration *cfg)
50
freez(cfg->p_db_lookup_options);
51
52
freez(cfg->chart_labels);
53
+ freez(cfg->summary);
54
}
55
56
char *generate_provide_alarm_configuration(size_t *len, struct provide_alarm_configuration *data)
@@ -132,6 +133,9 @@ char *generate_provide_alarm_configuration(size_t *len, struct provide_alarm_con
133
if (data->cfg.chart_labels)
134
cfg->set_chart_labels(data->cfg.chart_labels);
135
136
+ if (data->cfg.summary)
137
+ cfg->set_summary(data->cfg.summary);
138
+
139
*len = PROTO_COMPAT_MSG_SIZE(msg);
140
char *bin = (char*)mallocz(*len);
141
if (!msg.SerializeToArray(bin, *len))
aclk/schema-wrappers/alarm_config.h
+1
@@ -52,6 +52,7 @@ struct aclk_alarm_configuration {
52
int32_t p_update_every;
53
54
char *chart_labels;
55
+ char *summary;
56
};
57
58
void destroy_aclk_alarm_configuration(struct aclk_alarm_configuration *cfg);
aclk/schema-wrappers/alarm_stream.cc
+2
-6
@@ -68,26 +68,21 @@ void destroy_alarm_log_entry(struct alarm_log_entry *entry)
68
{
69
//freez(entry->node_id);
70
//freez(entry->claim_id);
71
-
71
freez(entry->chart);
72
freez(entry->name);
73
freez(entry->family);
75
-
74
freez(entry->config_hash);
77
-
75
freez(entry->timezone);
79
-
76
freez(entry->exec_path);
77
freez(entry->conf_source);
78
freez(entry->command);
83
-
79
freez(entry->value_string);
80
freez(entry->old_value_string);
86
-
81
freez(entry->rendered_info);
82
freez(entry->chart_context);
83
freez(entry->transition_id);
84
freez(entry->chart_name);
85
+ freez(entry->summary);
86
}
87
88
static void fill_alarm_log_entry(struct alarm_log_entry *data, AlarmLogEntry *proto)
@@ -136,6 +131,7 @@ static void fill_alarm_log_entry(struct alarm_log_entry *data, AlarmLogEntry *pr
131
proto->set_event_id(data->event_id);
132
proto->set_transition_id(data->transition_id);
133
proto->set_chart_name(data->chart_name);
134
+ proto->set_summary(data->summary);
135
}
136
137
char *generate_alarm_log_entry(size_t *len, struct alarm_log_entry *data)
aclk/schema-wrappers/alarm_stream.h
+2
-1
@@ -76,7 +76,8 @@ struct alarm_log_entry {
76
char *chart_name;
77
78
uint64_t event_id;
79
- char *transition_id;
79
+ char *transition_id;
80
+ char *summary;
81
};
82
83
struct send_alarm_checkpoint {
database/contexts/api_v2.c
+6
@@ -355,6 +355,7 @@ static void alert_instances_v2_insert_callback(const DICTIONARY_ITEM *item __may
355
t->status = rc->status;
356
t->flags = rc->run_flags;
357
t->info = rc->info;
358
+ t->summary = rc->summary;
359
t->value = rc->value;
360
t->last_updated = rc->last_updated;
361
t->last_status_change = rc->last_status_change;
@@ -1280,6 +1281,7 @@ static void contexts_v2_alert_config_to_json_from_sql_alert_config_data(struct s
1281
buffer_json_member_add_string(wb, "component", t->component);
1282
buffer_json_member_add_string(wb, "type", t->type);
1283
buffer_json_member_add_string(wb, "info", t->info);
1284
+ buffer_json_member_add_string(wb, "summary", t->summary);
1285
// buffer_json_member_add_string(wb, "source", t->source); // moved to alert instance
1286
}
1287
@@ -1343,6 +1345,7 @@ static int contexts_v2_alert_instance_to_json_callback(const DICTIONARY_ITEM *it
1345
buffer_json_member_add_string(wb, "units", string2str(t->units));
1346
buffer_json_member_add_string(wb, "fami", string2str(t->family));
1347
buffer_json_member_add_string(wb, "info", string2str(t->info));
1348
+ buffer_json_member_add_string(wb, "sum", string2str(t->summary));
1349
buffer_json_member_add_string(wb, "ctx", string2str(t->context));
1350
buffer_json_member_add_string(wb, "st", rrdcalc_status2string(t->status));
1351
buffer_json_member_add_uuid(wb, "tr_i", &t->last_transition_id);
@@ -1438,6 +1441,7 @@ struct sql_alert_transition_fixed_size {
1441
char units[SQL_TRANSITION_DATA_SMALL_STRING];
1442
char exec[SQL_TRANSITION_DATA_BIG_STRING];
1443
char info[SQL_TRANSITION_DATA_BIG_STRING];
1444
+ char summary[SQL_TRANSITION_DATA_BIG_STRING];
1445
char classification[SQL_TRANSITION_DATA_SMALL_STRING];
1446
char type[SQL_TRANSITION_DATA_SMALL_STRING];
1447
char component[SQL_TRANSITION_DATA_SMALL_STRING];
@@ -1477,6 +1481,7 @@ static struct sql_alert_transition_fixed_size *contexts_v2_alert_transition_dup(
1481
strncpyz(n->units, t->units ? t->units : "", sizeof(n->units) - 1);
1482
strncpyz(n->exec, t->exec ? t->exec : "", sizeof(n->exec) - 1);
1483
strncpyz(n->info, t->info ? t->info : "", sizeof(n->info) - 1);
1484
+ strncpyz(n->summary, t->summary ? t->summary : "", sizeof(n->summary) - 1);
1485
strncpyz(n->classification, t->classification ? t->classification : "", sizeof(n->classification) - 1);
1486
strncpyz(n->type, t->type ? t->type : "", sizeof(n->type) - 1);
1487
strncpyz(n->component, t->component ? t->component : "", sizeof(n->component) - 1);
@@ -1734,6 +1739,7 @@ static void contexts_v2_alert_transitions_to_json(BUFFER *wb, struct rrdcontext_
1739
1740
buffer_json_member_add_time_t(wb, "when", t->when_key);
1741
buffer_json_member_add_string(wb, "info", *t->info ? t->info : "");
1742
+ buffer_json_member_add_string(wb, "summary", *t->summary ? t->summary : "");
1743
buffer_json_member_add_string(wb, "units", *t->units ? t->units : NULL);
1744
buffer_json_member_add_object(wb, "new");
1745
{
database/contexts/rrdcontext.h
+3
@@ -432,6 +432,7 @@ struct sql_alert_transition_data {
432
const char *units;
433
const char *exec;
434
const char *info;
435
+ const char *summary;
436
const char *classification;
437
const char *type;
438
const char *component;
@@ -472,6 +473,7 @@ struct sql_alert_config_data {
473
const char *classification;
474
const char *component;
475
const char *type;
476
+ const char *summary;
477
478
struct {
479
struct {
@@ -531,6 +533,7 @@ struct sql_alert_instance_v2_entry {
533
RRDCALC_STATUS status;
534
RRDCALC_FLAGS flags;
535
STRING *info;
536
+ STRING *summary;
537
NETDATA_DOUBLE value;
538
time_t last_updated;
539
time_t last_status_change;
database/sqlite/sqlite_aclk_alert.c
+6
-2
@@ -275,7 +275,7 @@ void aclk_push_alert_event(struct aclk_sync_host_config *wc)
275
" hld.duration, hld.non_clear_duration, hld.flags, hld.exec_run_timestamp, hld.delay_up_to_timestamp, hl.name, "
276
" hl.chart, hl.family, hl.exec, hl.recipient, ha.source, hl.units, hld.info, hld.exec_code, hld.new_status, "
277
" hld.old_status, hld.delay, hld.new_value, hld.old_value, hld.last_repeat, hl.chart_context, hld.transition_id, "
278
- "hld.alarm_event_id, hl.chart_name "
278
+ " hld.alarm_event_id, hl.chart_name, hld.summary "
279
" from health_log hl, aclk_alert_%s aa, alert_hash ha, health_log_detail hld "
280
" where hld.unique_id = aa.alert_unique_id and hl.config_hash_id = ha.hash_id and aa.date_submitted is null "
281
" and hl.host_id = @host_id and hl.health_log_id = hld.health_log_id "
@@ -388,6 +388,7 @@ void aclk_push_alert_event(struct aclk_sync_host_config *wc)
388
alarm_log.transition_id = sqlite3_uuid_unparse_strdupz(res, 27);
389
alarm_log.event_id = (time_t) sqlite3_column_int64(res, 28);
390
alarm_log.chart_name = sqlite3_text_strdupz_empty(res, 29);
391
+ alarm_log.summary = sqlite3_text_strdupz_empty(res, 30);
392
393
aclk_send_alarm_log_entry(&alarm_log);
394
@@ -535,7 +536,7 @@ void aclk_send_alarm_configuration(char *config_hash)
536
"SELECT alarm, template, on_key, class, type, component, os, hosts, plugin," \
537
"module, charts, families, lookup, every, units, green, red, calc, warn, crit, to_key, exec, delay, repeat, info," \
538
"options, host_labels, p_db_lookup_dimensions, p_db_lookup_method, p_db_lookup_options, p_db_lookup_after," \
538
- "p_db_lookup_before, p_update_every, chart_labels FROM alert_hash WHERE hash_id = @hash_id;"
539
+ "p_db_lookup_before, p_update_every, chart_labels, summary FROM alert_hash WHERE hash_id = @hash_id;"
540
541
int aclk_push_alert_config_event(char *node_id __maybe_unused, char *config_hash __maybe_unused)
542
{
@@ -637,6 +638,7 @@ int aclk_push_alert_config_event(char *node_id __maybe_unused, char *config_hash
638
alarm_config.p_update_every = sqlite3_column_int(res, 32);
639
640
alarm_config.chart_labels = SQLITE3_COLUMN_STRDUPZ_OR_NULL(res, 33);
641
+ alarm_config.summary = SQLITE3_COLUMN_STRDUPZ_OR_NULL(res, 34);
642
643
p_alarm_config.cfg_hash = strdupz((char *) config_hash);
644
p_alarm_config.cfg = alarm_config;
@@ -846,6 +848,8 @@ void health_alarm_entry2proto_nolock(struct alarm_log_entry *alarm_log, ALARM_EN
848
alarm_log->transition_id = strdupz((char *)transition_id);
849
alarm_log->event_id = (uint64_t) ae->alarm_event_id;
850
851
+ alarm_log->summary = strdupz(ae_summary(ae));
852
+
853
freez(edit_command);
854
}
855
#endif
database/sqlite/sqlite_health.c
+4
-2
@@ -1882,7 +1882,7 @@ done:
1882
"SELECT h.host_id, h.alarm_id, h.config_hash_id, h.name, h.chart, h.chart_name, h.family, h.recipient, h.units, h.exec, " \
1883
"h.chart_context, d.when_key, d.duration, d.non_clear_duration, d.flags, d.delay_up_to_timestamp, " \
1884
"d.info, d.exec_code, d.new_status, d.old_status, d.delay, d.new_value, d.old_value, d.last_repeat, " \
1885
- "d.transition_id, d.global_id, ah.class, ah.type, ah.component, d.exec_run_timestamp"
1885
+ "d.transition_id, d.global_id, ah.class, ah.type, ah.component, d.exec_run_timestamp, d.summary"
1886
1887
#define SQL_SEARCH_ALERT_TRANSITION_COMMON_WHERE "h.config_hash_id = ah.hash_id AND h.health_log_id = d.health_log_id"
1888
@@ -2054,6 +2054,7 @@ run_query:;
2054
atd.type = (const char *) sqlite3_column_text(res, 27);
2055
atd.component = (const char *) sqlite3_column_text(res, 28);
2056
atd.exec_run_timestamp = sqlite3_column_int64(res, 29);
2057
+ atd.summary = (const char *) sqlite3_column_text(res, 30);
2058
2059
cb(&atd, data);
2060
}
@@ -2079,7 +2080,7 @@ done_only_drop:
2080
"SELECT ah.hash_id, alarm, template, on_key, class, component, type, os, hosts, lookup, every, " \
2081
" units, calc, families, plugin, module, charts, green, red, warn, crit, " \
2082
" exec, to_key, info, delay, options, repeat, host_labels, p_db_lookup_dimensions, p_db_lookup_method, " \
2082
- " p_db_lookup_options, p_db_lookup_after, p_db_lookup_before, p_update_every, source, chart_labels " \
2083
+ " p_db_lookup_options, p_db_lookup_after, p_db_lookup_before, p_update_every, source, chart_labels, summary " \
2084
" FROM alert_hash ah, c_%p t where ah.hash_id = t.hash_id"
2085
2086
int sql_get_alert_configuration(
@@ -2188,6 +2189,7 @@ int sql_get_alert_configuration(
2189
acd.value.update_every = (int32_t) sqlite3_column_int(res, param++);
2190
acd.source = (const char *) sqlite3_column_text(res, param++);
2191
acd.selectors.chart_labels = (const char *) sqlite3_column_text(res, param++);
2192
+ acd.summary = (const char *) sqlite3_column_text(res, param++);
2193
2194
cb(&acd, data);
2195
added++;