Store and transmit chart_name to cloud in alert events (#15441)
Emmanuel Vasilakis committed
Jul 20, 2023 at 23:23 UTC
5607d21c025bf79aa80fccb5ad07842a31066aef
13 files changed
+158
-56
aclk/aclk-schemas
+1
-1
@@ -1 +1 @@
1
-Subproject commit 2aba113db56ac32deccc1e83784c4b3b6fcfe1cd
1
+Subproject commit 40703f5e0258b3f4a97d3767e0f4e6833801b7d1
aclk/schema-wrappers/alarm_stream.cc
+2
-4
@@ -87,6 +87,7 @@ void destroy_alarm_log_entry(struct alarm_log_entry *entry)
87
freez(entry->rendered_info);
88
freez(entry->chart_context);
89
freez(entry->transition_id);
90
+ freez(entry->chart_name);
91
}
92
93
static void fill_alarm_log_entry(struct alarm_log_entry *data, AlarmLogEntry *proto)
@@ -129,15 +130,12 @@ static void fill_alarm_log_entry(struct alarm_log_entry *data, AlarmLogEntry *pr
130
131
proto->set_value(data->value);
132
proto->set_old_value(data->old_value);
132
-
133
proto->set_updated(data->updated);
134
-
134
proto->set_rendered_info(data->rendered_info);
136
-
135
proto->set_chart_context(data->chart_context);
138
-
136
proto->set_event_id(data->event_id);
137
proto->set_transition_id(data->transition_id);
138
+ proto->set_chart_name(data->chart_name);
139
}
140
141
char *generate_alarm_log_entry(size_t *len, struct alarm_log_entry *data)
aclk/schema-wrappers/alarm_stream.h
+1
@@ -73,6 +73,7 @@ struct alarm_log_entry {
73
char *rendered_info;
74
75
char *chart_context;
76
+ char *chart_name;
77
78
uint64_t event_id;
79
char *transition_id;
database/rrd.h
+3
-1
@@ -1045,6 +1045,7 @@ struct alarm_entry {
1045
STRING *name;
1046
STRING *chart;
1047
STRING *chart_context;
1048
+ STRING *chart_name;
1049
STRING *family;
1050
1051
STRING *classification;
@@ -1086,7 +1087,8 @@ struct alarm_entry {
1087
};
1088
1089
#define ae_name(ae) string2str((ae)->name)
1089
-#define ae_chart_name(ae) string2str((ae)->chart)
1090
+#define ae_chart_id(ae) string2str((ae)->chart)
1091
+#define ae_chart_name(ae) string2str((ae)->chart_name)
1092
#define ae_chart_context(ae) string2str((ae)->chart_context)
1093
#define ae_family(ae) string2str((ae)->family)
1094
#define ae_classification(ae) string2str((ae)->classification)
database/rrdcalc.c
+2
@@ -292,6 +292,7 @@ static void rrdcalc_link_to_rrdset(RRDSET *st, RRDCALC *rc) {
292
rc->name,
293
rc->rrdset->id,
294
rc->rrdset->context,
295
+ rc->rrdset->name,
296
rc->rrdset->family,
297
rc->classification,
298
rc->component,
@@ -336,6 +337,7 @@ static void rrdcalc_unlink_from_rrdset(RRDCALC *rc, bool having_ll_wrlock) {
337
rc->name,
338
rc->rrdset->id,
339
rc->rrdset->context,
340
+ rc->rrdset->name,
341
rc->rrdset->family,
342
rc->classification,
343
rc->component,
database/sqlite/sqlite_aclk_alert.c
+4
-5
@@ -268,7 +268,7 @@ void aclk_push_alert_event(struct aclk_sync_host_config *wc)
268
buffer_sprintf(sql, "select aa.sequence_id, hld.unique_id, hld.alarm_id, hl.config_hash_id, hld.updated_by_id, hld.when_key, " \
269
" hld.duration, hld.non_clear_duration, hld.flags, hld.exec_run_timestamp, hld.delay_up_to_timestamp, hl.name, " \
270
" hl.chart, hl.family, hl.exec, hl.recipient, ha.source, hl.units, hld.info, hld.exec_code, hld.new_status, " \
271
- " hld.old_status, hld.delay, hld.new_value, hld.old_value, hld.last_repeat, hl.chart_context, hld.transition_id, hld.alarm_event_id " \
271
+ " hld.old_status, hld.delay, hld.new_value, hld.old_value, hld.last_repeat, hl.chart_context, hld.transition_id, hld.alarm_event_id, hl.chart_name " \
272
" from health_log hl, aclk_alert_%s aa, alert_hash ha, health_log_detail hld " \
273
" where hld.unique_id = aa.alert_unique_id and hl.config_hash_id = ha.hash_id and aa.date_submitted is null " \
274
" and hl.host_id = @host_id and hl.health_log_id = hld.health_log_id " \
@@ -371,14 +371,12 @@ void aclk_push_alert_event(struct aclk_sync_host_config *wc)
371
372
alarm_log.value = (NETDATA_DOUBLE) sqlite3_column_double(res, 23);
373
alarm_log.old_value = (NETDATA_DOUBLE) sqlite3_column_double(res, 24);
374
-
374
alarm_log.updated = (sqlite3_column_int64(res, 8) & HEALTH_ENTRY_FLAG_UPDATED) ? 1 : 0;
375
alarm_log.rendered_info = sqlite3_text_strdupz_empty(res, 18);
377
-
376
alarm_log.chart_context = sqlite3_text_strdupz_empty(res, 26);
377
alarm_log.transition_id = sqlite3_uuid_unparse_strdupz(res, 27);
380
-
378
alarm_log.event_id = (time_t) sqlite3_column_int64(res, 28);
379
+ alarm_log.chart_name = sqlite3_text_strdupz_empty(res, 29);
380
381
aclk_send_alarm_log_entry(&alarm_log);
382
@@ -788,7 +786,7 @@ void health_alarm_entry2proto_nolock(struct alarm_log_entry *alarm_log, ALARM_EN
786
char transition_id[UUID_STR_LEN];
787
uuid_unparse_lower(ae->transition_id, transition_id);
788
791
- alarm_log->chart = strdupz(ae_chart_name(ae));
789
+ alarm_log->chart = strdupz(ae_chart_id(ae));
790
alarm_log->name = strdupz(ae_name(ae));
791
alarm_log->family = strdupz(ae_family(ae));
792
@@ -827,6 +825,7 @@ void health_alarm_entry2proto_nolock(struct alarm_log_entry *alarm_log, ALARM_EN
825
alarm_log->updated = (ae->flags & HEALTH_ENTRY_FLAG_UPDATED) ? 1 : 0;
826
alarm_log->rendered_info = strdupz(ae_info(ae));
827
alarm_log->chart_context = strdupz(ae_chart_context(ae));
828
+ alarm_log->chart_name = strdupz(ae_chart_name(ae));
829
830
alarm_log->transition_id = strdupz((char *)transition_id);
831
alarm_log->event_id = (uint64_t) ae->alarm_event_id;
database/sqlite/sqlite_db_migration.c
+16
-1
@@ -83,6 +83,11 @@ const char *database_migrate_v9_v10[] = {
83
NULL
84
};
85
86
+const char *database_migrate_v10_v11[] = {
87
+ "ALTER TABLE health_log ADD chart_name TEXT;",
88
+ NULL
89
+};
90
+
91
static int do_migration_v1_v2(sqlite3 *database, const char *name)
92
{
93
UNUSED(name);
@@ -293,7 +298,6 @@ static int do_migration_v8_v9(sqlite3 *database, const char *name)
298
299
static int do_migration_v9_v10(sqlite3 *database, const char *name)
300
{
296
- UNUSED(name);
301
netdata_log_info("Running \"%s\" database migration", name);
302
303
if (table_exists_in_database("alert_hash") && !column_exists_in_table("alert_hash", "chart_labels"))
@@ -301,6 +305,16 @@ static int do_migration_v9_v10(sqlite3 *database, const char *name)
305
return 0;
306
}
307
308
+static int do_migration_v10_v11(sqlite3 *database, const char *name)
309
+{
310
+ netdata_log_info("Running \"%s\" database migration", name);
311
+
312
+ if (table_exists_in_database("health_log") && !column_exists_in_table("health_log", "chart_name"))
313
+ return init_database_batch(database, DB_CHECK_NONE, 0, &database_migrate_v10_v11[0]);
314
+
315
+ return 0;
316
+}
317
+
318
static int do_migration_noop(sqlite3 *database, const char *name)
319
{
320
UNUSED(database);
@@ -354,6 +368,7 @@ DATABASE_FUNC_MIGRATION_LIST migration_action[] = {
368
{.name = "v7 to v8", .func = do_migration_v7_v8},
369
{.name = "v8 to v9", .func = do_migration_v8_v9},
370
{.name = "v9 to v10", .func = do_migration_v9_v10},
371
+ {.name = "v10 to v11", .func = do_migration_v10_v11},
372
// the terminator of this array
373
{.name = NULL, .func = NULL}
374
};
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 10
6
+#define DB_METADATA_VERSION 11
7
8
const char *database_config[] = {
9
"CREATE TABLE IF NOT EXISTS host(host_id BLOB PRIMARY KEY, hostname TEXT NOT NULL, "
@@ -47,7 +47,7 @@ const char *database_config[] = {
47
48
"CREATE TABLE IF NOT EXISTS health_log (health_log_id INTEGER PRIMARY KEY, host_id blob, alarm_id int, "
49
"config_hash_id blob, name text, chart text, family text, recipient text, units text, exec text, "
50
- "chart_context text, last_transition_id blob, UNIQUE (host_id, alarm_id)) ;",
50
+ "chart_context text, last_transition_id blob, chart_name text, UNIQUE (host_id, alarm_id)) ;",
51
52
"CREATE INDEX IF NOT EXISTS health_log_ind_1 ON health_log (host_id);",
53
database/sqlite/sqlite_health.c
+105
-29
@@ -83,8 +83,8 @@ failed:
83
Inserts an entry in the table
84
*/
85
#define SQL_INSERT_HEALTH_LOG "INSERT INTO health_log (host_id, alarm_id, " \
86
- "config_hash_id, name, chart, family, exec, recipient, units, chart_context, last_transition_id) " \
87
- "VALUES (?,?,?,?,?,?,?,?,?,?,?) " \
86
+ "config_hash_id, name, chart, family, exec, recipient, units, chart_context, last_transition_id, chart_name) " \
87
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?) " \
88
"ON CONFLICT (host_id, alarm_id) DO UPDATE SET last_transition_id = excluded.last_transition_id RETURNING health_log_id; "
89
90
#define SQL_INSERT_HEALTH_LOG_DETAIL "INSERT INTO health_log_detail (health_log_id, unique_id, alarm_id, alarm_event_id, " \
@@ -174,6 +174,12 @@ void sql_health_alarm_log_insert(RRDHOST *host, ALARM_ENTRY *ae) {
174
goto failed;
175
}
176
177
+ rc = sqlite3_bind_string_or_null(res, ae->chart_name, 12);
178
+ if (unlikely(rc != SQLITE_OK)) {
179
+ error_report("Failed to bind chart_name parameter for SQL_INSERT_HEALTH_LOG");
180
+ goto failed;
181
+ }
182
+
183
rc = sqlite3_step_monitored(res);
184
if (likely(rc == SQLITE_ROW))
185
health_log_id = (size_t) sqlite3_column_int64(res, 0);
@@ -766,7 +772,7 @@ void sql_check_removed_alerts_state(RRDHOST *host)
772
"hld.updates_id, hld.when_key, hld.duration, hld.non_clear_duration, hld.flags, hld.exec_run_timestamp, " \
773
"hld.delay_up_to_timestamp, hl.name, hl.chart, hl.family, hl.exec, hl.recipient, ah.source, hl.units, " \
774
"hld.info, hld.exec_code, hld.new_status, hld.old_status, hld.delay, hld.new_value, hld.old_value, " \
769
- "hld.last_repeat, ah.class, ah.component, ah.type, hl.chart_context, hld.transition_id, hld.global_id " \
775
+ "hld.last_repeat, ah.class, ah.component, ah.type, hl.chart_context, hld.transition_id, hld.global_id, hl.chart_name " \
776
"FROM health_log hl, alert_hash ah, health_log_detail hld " \
777
"WHERE hl.config_hash_id = ah.hash_id and hl.host_id = @host_id and hl.last_transition_id = hld.transition_id;"
778
void sql_health_alarm_log_load(RRDHOST *host) {
@@ -945,6 +951,11 @@ void sql_health_alarm_log_load(RRDHOST *host) {
951
if (sqlite3_column_type(res, 32) != SQLITE_NULL)
952
ae->global_id = sqlite3_column_int64(res, 32);
953
954
+ if (sqlite3_column_type(res, 33) != SQLITE_NULL)
955
+ ae->chart_name = string_strdupz((char *) sqlite3_column_text(res, 33));
956
+ else
957
+ ae->chart_name = NULL;
958
+
959
char value_string[100 + 1];
960
string_freez(ae->old_value_string);
961
string_freez(ae->new_value_string);
@@ -1767,7 +1778,7 @@ fail:
1778
#define SQL_POPULATE_TEMP_ALERT_TRANSITION_TABLE "INSERT INTO v_%p (host_id) VALUES (@host_id)"
1779
1780
#define SQL_SEARCH_ALERT_TRANSITION_SELECT "SELECT " \
1770
- "h.host_id, h.alarm_id, h.config_hash_id, h.name, h.chart, h.family, h.recipient, h.units, h.exec, " \
1781
+ "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, " \
1782
"h.chart_context, d.when_key, d.duration, d.non_clear_duration, d.flags, d.delay_up_to_timestamp, " \
1783
"d.info, d.exec_code, d.new_status, d.old_status, d.delay, d.new_value, d.old_value, d.last_repeat, " \
1784
"d.transition_id, d.global_id, ah.class, ah.type, ah.component, d.exec_run_timestamp"
@@ -1913,31 +1924,31 @@ run_query:;
1924
atd.config_hash_id = (uuid_t *)sqlite3_column_blob(res, 2);
1925
atd.alert_name = (const char *) sqlite3_column_text(res, 3);
1926
atd.chart = (const char *) sqlite3_column_text(res, 4);
1916
- atd.chart_name = (const char *) sqlite3_column_text(res, 4); // FIXME don't copy the id, find the name
1917
- atd.family = (const char *) sqlite3_column_text(res, 5);
1918
- atd.recipient = (const char *) sqlite3_column_text(res, 6);
1919
- atd.units = (const char *) sqlite3_column_text(res, 7);
1920
- atd.exec = (const char *) sqlite3_column_text(res, 8);
1921
- atd.chart_context = (const char *) sqlite3_column_text(res, 9);
1922
- atd.when_key = sqlite3_column_int64(res, 10);
1923
- atd.duration = sqlite3_column_int64(res, 11);
1924
- atd.non_clear_duration = sqlite3_column_int64(res, 12);
1925
- atd.flags = sqlite3_column_int64(res, 13);
1926
- atd.delay_up_to_timestamp = sqlite3_column_int64(res, 14);
1927
- atd.info = (const char *) sqlite3_column_text(res, 15);
1928
- atd.exec_code = sqlite3_column_int(res, 16);
1929
- atd.new_status = sqlite3_column_int(res, 17);
1930
- atd.old_status = sqlite3_column_int(res, 18);
1931
- atd.delay = (int) sqlite3_column_int(res, 19);
1932
- atd.new_value = (NETDATA_DOUBLE) sqlite3_column_double(res, 20);
1933
- atd.old_value = (NETDATA_DOUBLE) sqlite3_column_double(res, 21);
1934
- atd.last_repeat = sqlite3_column_int64(res, 22);
1935
- atd.transition_id = (uuid_t *) sqlite3_column_blob(res, 23);
1936
- atd.global_id = sqlite3_column_int64(res, 24);
1937
- atd.classification = (const char *) sqlite3_column_text(res, 25);
1938
- atd.type = (const char *) sqlite3_column_text(res, 26);
1939
- atd.component = (const char *) sqlite3_column_text(res, 27);
1940
- atd.exec_run_timestamp = sqlite3_column_int64(res, 28);
1927
+ atd.chart_name = (const char *) sqlite3_column_text(res, 5);
1928
+ atd.family = (const char *) sqlite3_column_text(res, 6);
1929
+ atd.recipient = (const char *) sqlite3_column_text(res, 7);
1930
+ atd.units = (const char *) sqlite3_column_text(res, 8);
1931
+ atd.exec = (const char *) sqlite3_column_text(res, 9);
1932
+ atd.chart_context = (const char *) sqlite3_column_text(res, 10);
1933
+ atd.when_key = sqlite3_column_int64(res, 11);
1934
+ atd.duration = sqlite3_column_int64(res, 12);
1935
+ atd.non_clear_duration = sqlite3_column_int64(res, 13);
1936
+ atd.flags = sqlite3_column_int64(res, 14);
1937
+ atd.delay_up_to_timestamp = sqlite3_column_int64(res, 15);
1938
+ atd.info = (const char *) sqlite3_column_text(res, 16);
1939
+ atd.exec_code = sqlite3_column_int(res, 17);
1940
+ atd.new_status = sqlite3_column_int(res, 18);
1941
+ atd.old_status = sqlite3_column_int(res, 19);
1942
+ atd.delay = (int) sqlite3_column_int(res, 20);
1943
+ atd.new_value = (NETDATA_DOUBLE) sqlite3_column_double(res, 21);
1944
+ atd.old_value = (NETDATA_DOUBLE) sqlite3_column_double(res, 22);
1945
+ atd.last_repeat = sqlite3_column_int64(res, 23);
1946
+ atd.transition_id = (uuid_t *) sqlite3_column_blob(res, 24);
1947
+ atd.global_id = sqlite3_column_int64(res, 25);
1948
+ atd.classification = (const char *) sqlite3_column_text(res, 26);
1949
+ atd.type = (const char *) sqlite3_column_text(res, 27);
1950
+ atd.component = (const char *) sqlite3_column_text(res, 28);
1951
+ atd.exec_run_timestamp = sqlite3_column_int64(res, 29);
1952
1953
cb(&atd, data);
1954
}
@@ -2087,3 +2098,68 @@ fail_only_drop:
2098
return added;
2099
}
2100
2101
+#define SQL_FETCH_CHART_NAME "SELECT chart_name FROM health_log where host_id = @host_id LIMIT 1;"
2102
+bool is_chart_name_populated(uuid_t *host_uuid)
2103
+{
2104
+ sqlite3_stmt *res = NULL;
2105
+ int rc;
2106
+
2107
+ bool status = true;
2108
+
2109
+ rc = sqlite3_prepare_v2(db_meta, SQL_FETCH_CHART_NAME, -1, &res, 0);
2110
+ if (unlikely(rc != SQLITE_OK)) {
2111
+ error_report("Failed to prepare statement to check health_log chart_name");
2112
+ return true;
2113
+ }
2114
+
2115
+ rc = sqlite3_bind_blob(res, 1, host_uuid, sizeof(*host_uuid), SQLITE_STATIC);
2116
+ if (unlikely(rc != SQLITE_OK)) {
2117
+ error_report("Failed to bind host_id for health_log chart_name check");
2118
+ goto fail;
2119
+ }
2120
+
2121
+ rc = sqlite3_step_monitored(res);
2122
+ if (likely(rc == SQLITE_ROW))
2123
+ status = sqlite3_column_type(res, 0) != SQLITE_NULL;
2124
+fail:
2125
+
2126
+ rc = sqlite3_finalize(res);
2127
+ if (unlikely(rc != SQLITE_OK))
2128
+ error_report("Failed to finalize the prepared statement for health_log chart_name check");
2129
+
2130
+ return status;
2131
+}
2132
+
2133
+#define SQL_POPULATE_CHART_NAME " UPDATE health_log SET chart_name = upd.chart_name FROM " \
2134
+ "(SELECT c.type || '.' || IFNULL(c.name, c.id) AS chart_name, hl.host_id, hl.health_log_id FROM " \
2135
+ "chart c, health_log hl WHERE (c.type || '.' || c.id) = hl.chart AND c.host_id = hl.host_id " \
2136
+ "AND hl.host_id = @host_id) AS upd WHERE health_log.host_id = upd.host_id " \
2137
+ "AND health_log.health_log_id = upd.health_log_id"
2138
+
2139
+void chart_name_populate(uuid_t *host_uuid)
2140
+{
2141
+ sqlite3_stmt *res = NULL;
2142
+ int rc;
2143
+
2144
+ rc = sqlite3_prepare_v2(db_meta, SQL_POPULATE_CHART_NAME, -1, &res, 0);
2145
+ if (unlikely(rc != SQLITE_OK)) {
2146
+ error_report("Failed to prepare statement to update health_log chart_name");
2147
+ return;
2148
+ }
2149
+
2150
+ rc = sqlite3_bind_blob(res, 1, host_uuid, sizeof(*host_uuid), SQLITE_STATIC);
2151
+ if (unlikely(rc != SQLITE_OK)) {
2152
+ error_report("Failed to bind host_id for health_log chart_name update");
2153
+ goto fail;
2154
+ }
2155
+
2156
+ rc = execute_insert(res);
2157
+ if (unlikely(rc != SQLITE_DONE))
2158
+ error_report("Failed to update chart name in health_log, rc = %d", rc);
2159
+
2160
+fail:
2161
+
2162
+ rc = sqlite3_finalize(res);
2163
+ if (unlikely(rc != SQLITE_OK))
2164
+ error_report("Failed to finalize the prepared statement for health_log chart_name update");
2165
+}
database/sqlite/sqlite_health.h
+2
@@ -37,4 +37,6 @@ int sql_get_alert_configuration(
37
bool debug __maybe_unused);
38
39
bool sql_find_alert_transition(const char *transition, void (*cb)(const char *machine_guid, const char *context, time_t alert_id, void *data), void *data);
40
+bool is_chart_name_populated(uuid_t *host_uuid);
41
+void chart_name_populate(uuid_t *host_uuid);
42
#endif //NETDATA_SQLITE_HEALTH_H
health/health.c
+17
-13
@@ -433,14 +433,14 @@ static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) {
433
434
if(unlikely(ae->new_status < RRDCALC_STATUS_CLEAR)) {
435
// do not send notifications for internal statuses
436
- netdata_log_debug(D_HEALTH, "Health not sending notification for alarm '%s.%s' status %s (internal statuses)", ae_chart_name(ae), ae_name(ae), rrdcalc_status2string(ae->new_status));
436
+ netdata_log_debug(D_HEALTH, "Health not sending notification for alarm '%s.%s' status %s (internal statuses)", ae_chart_id(ae), ae_name(ae), rrdcalc_status2string(ae->new_status));
437
goto done;
438
}
439
440
if(unlikely(ae->new_status <= RRDCALC_STATUS_CLEAR && (ae->flags & HEALTH_ENTRY_FLAG_NO_CLEAR_NOTIFICATION))) {
441
// do not send notifications for disabled statuses
442
- netdata_log_debug(D_HEALTH, "Health not sending notification for alarm '%s.%s' status %s (it has no-clear-notification enabled)", ae_chart_name(ae), ae_name(ae), rrdcalc_status2string(ae->new_status));
443
- netdata_log_health("[%s]: Health not sending notification for alarm '%s.%s' status %s (it has no-clear-notification enabled)", rrdhost_hostname(host), ae_chart_name(ae), ae_name(ae), rrdcalc_status2string(ae->new_status));
442
+ netdata_log_debug(D_HEALTH, "Health not sending notification for alarm '%s.%s' status %s (it has no-clear-notification enabled)", ae_chart_id(ae), ae_name(ae), rrdcalc_status2string(ae->new_status));
443
+ netdata_log_health("[%s]: Health not sending notification for alarm '%s.%s' status %s (it has no-clear-notification enabled)", rrdhost_hostname(host), ae_chart_id(ae), ae_name(ae), rrdcalc_status2string(ae->new_status));
444
445
// mark it as run, so that we will send the same alarm if it happens again
446
goto done;
@@ -457,9 +457,9 @@ static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) {
457
// we have executed this alarm notification in the past
458
if(last_executed_status == ae->new_status && !(ae->flags & HEALTH_ENTRY_FLAG_IS_REPEATING)) {
459
// don't send the notification for the same status again
460
- netdata_log_debug(D_HEALTH, "Health not sending again notification for alarm '%s.%s' status %s", ae_chart_name(ae), ae_name(ae)
460
+ netdata_log_debug(D_HEALTH, "Health not sending again notification for alarm '%s.%s' status %s", ae_chart_id(ae), ae_name(ae)
461
, rrdcalc_status2string(ae->new_status));
462
- netdata_log_health("[%s]: Health not sending again notification for alarm '%s.%s' status %s", rrdhost_hostname(host), ae_chart_name(ae), ae_name(ae)
462
+ netdata_log_health("[%s]: Health not sending again notification for alarm '%s.%s' status %s", rrdhost_hostname(host), ae_chart_id(ae), ae_name(ae)
463
, rrdcalc_status2string(ae->new_status));
464
goto done;
465
}
@@ -470,7 +470,7 @@ static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) {
470
if(unlikely(ae->new_status == RRDCALC_STATUS_CLEAR)) {
471
if((!(ae->flags & HEALTH_ENTRY_RUN_ONCE)) || (ae->flags & HEALTH_ENTRY_RUN_ONCE && ae->old_status < RRDCALC_STATUS_RAISED) ) {
472
netdata_log_debug(D_HEALTH, "Health not sending notification for first initialization of alarm '%s.%s' status %s"
473
- , ae_chart_name(ae), ae_name(ae), rrdcalc_status2string(ae->new_status));
473
+ , ae_chart_id(ae), ae_name(ae), rrdcalc_status2string(ae->new_status));
474
goto done;
475
}
476
}
@@ -479,11 +479,11 @@ static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) {
479
480
// Check if alarm notifications are silenced
481
if (ae->flags & HEALTH_ENTRY_FLAG_SILENCED) {
482
- netdata_log_health("[%s]: Health not sending notification for alarm '%s.%s' status %s (command API has disabled notifications)", rrdhost_hostname(host), ae_chart_name(ae), ae_name(ae), rrdcalc_status2string(ae->new_status));
482
+ netdata_log_health("[%s]: Health not sending notification for alarm '%s.%s' status %s (command API has disabled notifications)", rrdhost_hostname(host), ae_chart_id(ae), ae_name(ae), rrdcalc_status2string(ae->new_status));
483
goto done;
484
}
485
486
- netdata_log_health("[%s]: Sending notification for alarm '%s.%s' status %s.", rrdhost_hostname(host), ae_chart_name(ae), ae_name(ae), rrdcalc_status2string(ae->new_status));
486
+ netdata_log_health("[%s]: Sending notification for alarm '%s.%s' status %s.", rrdhost_hostname(host), ae_chart_id(ae), ae_name(ae), rrdcalc_status2string(ae->new_status));
487
488
const char *exec = (ae->exec) ? ae_exec(ae) : string2str(host->health.health_default_exec);
489
const char *recipient = (ae->recipient) ? ae_recipient(ae) : string2str(host->health.health_default_recipient);
@@ -562,7 +562,7 @@ static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) {
562
ae->alarm_event_id,
563
(unsigned long)ae->when,
564
ae_name(ae),
565
- ae->chart?ae_chart_name(ae):"NOCHART",
565
+ ae->chart?ae_chart_id(ae):"NOCHART",
566
ae->family?ae_family(ae):"NOFAMILY",
567
rrdcalc_status2string(ae->new_status),
568
rrdcalc_status2string(ae->old_status),
@@ -627,7 +627,7 @@ static inline void health_alarm_wait_for_execution(ALARM_ENTRY *ae) {
627
628
static inline void health_process_notifications(RRDHOST *host, ALARM_ENTRY *ae) {
629
netdata_log_debug(D_HEALTH, "Health alarm '%s.%s' = " NETDATA_DOUBLE_FORMAT_AUTO " - changed status from %s to %s",
630
- ae->chart?ae_chart_name(ae):"NOCHART", ae_name(ae),
630
+ ae->chart?ae_chart_id(ae):"NOCHART", ae_name(ae),
631
ae->new_value,
632
rrdcalc_status2string(ae->old_status),
633
rrdcalc_status2string(ae->new_status)
@@ -844,8 +844,9 @@ static void initialize_health(RRDHOST *host)
844
host->health.health_default_exec = string_strdupz(config_get(CONFIG_SECTION_HEALTH, "script to execute on alarm", filename));
845
host->health.health_default_recipient = string_strdupz("root");
846
847
- // TODO: This needs to go to the metadata thread
848
- // Health should wait before accessing the table (needs to be created by the metadata thread)
847
+ if (!is_chart_name_populated(&host->host_uuid))
848
+ chart_name_populate(&host->host_uuid);
849
+
850
sql_health_alarm_log_load(host);
851
852
// ------------------------------------------------------------------------
@@ -1156,6 +1157,7 @@ void *health_main(void *ptr) {
1157
rc->name,
1158
rc->rrdset->id,
1159
rc->rrdset->context,
1160
+ rc->rrdset->name,
1161
rc->rrdset->family,
1162
rc->classification,
1163
rc->component,
@@ -1422,6 +1424,7 @@ void *health_main(void *ptr) {
1424
rc->name,
1425
rc->rrdset->id,
1426
rc->rrdset->context,
1427
+ rc->rrdset->name,
1428
rc->rrdset->family,
1429
rc->classification,
1430
rc->component,
@@ -1446,7 +1449,7 @@ void *health_main(void *ptr) {
1449
1450
health_alarm_log_add_entry(host, ae);
1451
1449
- netdata_log_health("[%s]: Alert event for [%s.%s], value [%s], status [%s].", rrdhost_hostname(host), ae_chart_name(ae), ae_name(ae), ae_new_value_string(ae), rrdcalc_status2string(ae->new_status));
1452
+ netdata_log_health("[%s]: Alert event for [%s.%s], value [%s], status [%s].", rrdhost_hostname(host), ae_chart_id(ae), ae_name(ae), ae_new_value_string(ae), rrdcalc_status2string(ae->new_status));
1453
1454
rc->last_status_change_value = rc->value;
1455
rc->last_status_change = now;
@@ -1508,6 +1511,7 @@ void *health_main(void *ptr) {
1511
rc->name,
1512
rc->rrdset->id,
1513
rc->rrdset->context,
1514
+ rc->rrdset->name,
1515
rc->rrdset->family,
1516
rc->classification,
1517
rc->component,
health/health.h
+1
@@ -70,6 +70,7 @@ ALARM_ENTRY* health_create_alarm_entry(
70
STRING *name,
71
STRING *chart,
72
STRING *chart_context,
73
+ STRING *chart_id,
74
STRING *family,
75
STRING *classification,
76
STRING *component,
health/health_log.c
+2
@@ -20,6 +20,7 @@ inline ALARM_ENTRY* health_create_alarm_entry(
20
STRING *name,
21
STRING *chart,
22
STRING *chart_context,
23
+ STRING *chart_name,
24
STRING *family,
25
STRING *class,
26
STRING *component,
@@ -43,6 +44,7 @@ inline ALARM_ENTRY* health_create_alarm_entry(
44
ae->name = string_dup(name);
45
ae->chart = string_dup(chart);
46
ae->chart_context = string_dup(chart_context);
47
+ ae->chart_name = string_dup(chart_name);
48
49
uuid_copy(ae->config_hash_id, *((uuid_t *) config_hash_id));
50