summaryrefslogtreecommitdiffstats
path: root/database
diff options
context:
space:
mode:
authorCosta Tsaousis <costa@netdata.cloud>2023-07-18 15:37:07 +0300
committerGitHub <noreply@github.com>2023-07-18 15:37:07 +0300
commit3cdedeed4030f10bb98d0893878b19d23443aed5 (patch)
treedd4bd1d9e31ddfe4472f3f940813d06b8a48f5d3 /database
parent2d4e91ab505dadf08ed2e31cbf9fa9398f1c3fb8 (diff)
add chart id and name to alert instances and transitions (#15430)
Diffstat (limited to 'database')
-rw-r--r--database/contexts/api_v2.c51
-rw-r--r--database/contexts/rrdcontext.h4
-rw-r--r--database/sqlite/sqlite_health.c22
3 files changed, 56 insertions, 21 deletions
diff --git a/database/contexts/api_v2.c b/database/contexts/api_v2.c
index 474b085047..4469e11614 100644
--- a/database/contexts/api_v2.c
+++ b/database/contexts/api_v2.c
@@ -9,41 +9,59 @@
struct alert_transitions_facets alert_transition_facets[] = {
[ATF_STATUS] = {
- .id = "status",
+ .id = "f_status",
.name = "Alert Status",
- .query_param = "status",
+ .query_param = "f_status",
.order = 1,
},
[ATF_TYPE] = {
- .id = "type",
+ .id = "f_type",
.name = "Alert Type",
- .query_param = "type",
+ .query_param = "f_type",
.order = 2,
},
[ATF_ROLE] = {
- .id = "role",
+ .id = "f_role",
.name = "Recipient Role",
- .query_param = "role",
+ .query_param = "f_role",
.order = 3,
},
[ATF_CLASS] = {
- .id = "class",
+ .id = "f_class",
.name = "Alert Class",
- .query_param = "class",
+ .query_param = "f_class",
.order = 4,
},
[ATF_COMPONENT] = {
- .id = "component",
+ .id = "f_component",
.name = "Alert Component",
- .query_param = "component",
+ .query_param = "f_component",
.order = 5,
},
[ATF_NODE] = {
- .id = "node",
+ .id = "f_node",
.name = "Alert Node",
- .query_param = "node",
+ .query_param = "f_node",
.order = 6,
},
+ [ATF_ALERT_NAME] = {
+ .id = "f_alert",
+ .name = "Alert Name",
+ .query_param = "f_alert",
+ .order = 7,
+ },
+ [ATF_CHART_NAME] = {
+ .id = "f_instance",
+ .name = "Instance Name",
+ .query_param = "f_instance",
+ .order = 8,
+ },
+ [ATF_CONTEXT] = {
+ .id = "f_context",
+ .name = "Context",
+ .query_param = "f_context",
+ .order = 9,
+ },
// terminator
[ATF_TOTAL_ENTRIES] = {
@@ -1300,7 +1318,8 @@ static int contexts_v2_alert_instance_to_json_callback(const DICTIONARY_ITEM *it
buffer_json_member_add_uint64(wb, "ni", t->ni);
buffer_json_member_add_string(wb, "nm", string2str(t->name));
- buffer_json_member_add_string(wb, "ch", string2str(t->chart_name));
+ buffer_json_member_add_string(wb, "ch", string2str(t->chart_id));
+ buffer_json_member_add_string(wb, "ch_n", string2str(t->chart_name));
if(ctl->request->options & CONTEXT_V2_OPTION_ALERTS_WITH_SUMMARY)
buffer_json_member_add_uint64(wb, "ati", t->ati);
@@ -1392,6 +1411,7 @@ struct sql_alert_transition_fixed_size {
uint32_t alarm_id;
char alert_name[SQL_TRANSITION_DATA_SMALL_STRING];
char chart[RRD_ID_LENGTH_MAX];
+ char chart_name[RRD_ID_LENGTH_MAX];
char chart_context[SQL_TRANSITION_DATA_MEDIUM_STRING];
char family[SQL_TRANSITION_DATA_SMALL_STRING];
char recipient[SQL_TRANSITION_DATA_MEDIUM_STRING];
@@ -1430,6 +1450,7 @@ static struct sql_alert_transition_fixed_size *contexts_v2_alert_transition_dup(
n->alarm_id = t->alarm_id;
strncpyz(n->alert_name, t->alert_name ? t->alert_name : "", sizeof(n->alert_name) - 1);
strncpyz(n->chart, t->chart ? t->chart : "", sizeof(n->chart) - 1);
+ strncpyz(n->chart_name, t->chart_name ? t->chart_name : n->chart, sizeof(n->chart_name) - 1);
strncpyz(n->chart_context, t->chart_context ? t->chart_context : "", sizeof(n->chart_context) - 1);
strncpyz(n->family, t->family ? t->family : "", sizeof(n->family) - 1);
strncpyz(n->recipient, t->recipient ? t->recipient : "", sizeof(n->recipient) - 1);
@@ -1547,6 +1568,9 @@ static void contexts_v2_alert_transition_callback(struct sql_alert_transition_da
[ATF_COMPONENT] = t->component,
[ATF_ROLE] = t->recipient && *t->recipient ? t->recipient : string2str(localhost->health.health_default_recipient),
[ATF_NODE] = machine_guid,
+ [ATF_ALERT_NAME] = t->alert_name,
+ [ATF_CHART_NAME] = t->chart_name,
+ [ATF_CONTEXT] = t->chart_context,
};
for(size_t i = 0; i < ATF_TOTAL_ENTRIES ;i++) {
@@ -1681,6 +1705,7 @@ static void contexts_v2_alert_transitions_to_json(BUFFER *wb, struct rrdcontext_
buffer_json_member_add_string(wb, "alert", *t->alert_name ? t->alert_name : NULL);
buffer_json_member_add_string(wb, "instance", *t->chart ? t->chart : NULL);
+ buffer_json_member_add_string(wb, "instance_n", *t->chart_name ? t->chart_name : NULL);
buffer_json_member_add_string(wb, "context", *t->chart_context ? t->chart_context : NULL);
// buffer_json_member_add_string(wb, "family", *t->family ? t->family : NULL);
buffer_json_member_add_string(wb, "component", *t->component ? t->component : NULL);
diff --git a/database/contexts/rrdcontext.h b/database/contexts/rrdcontext.h
index 585226df09..68ab3c35ca 100644
--- a/database/contexts/rrdcontext.h
+++ b/database/contexts/rrdcontext.h
@@ -424,6 +424,7 @@ struct sql_alert_transition_data {
uint32_t alarm_id;
const char *alert_name;
const char *chart;
+ const char *chart_name;
const char *chart_context;
const char *family;
const char *recipient;
@@ -589,6 +590,9 @@ typedef enum __attribute__((packed)) {
ATF_COMPONENT,
ATF_ROLE,
ATF_NODE,
+ ATF_ALERT_NAME,
+ ATF_CHART_NAME,
+ ATF_CONTEXT,
// total
ATF_TOTAL_ENTRIES,
diff --git a/database/sqlite/sqlite_health.c b/database/sqlite/sqlite_health.c
index 8790da7f18..c5651be221 100644
--- a/database/sqlite/sqlite_health.c
+++ b/database/sqlite/sqlite_health.c
@@ -1766,16 +1766,21 @@ fail:
#define SQL_POPULATE_TEMP_ALERT_TRANSITION_TABLE "INSERT INTO v_%p (host_id) VALUES (@host_id)"
-#define SQL_SEARCH_ALERT_TRANSITION "SELECT h.host_id, h.alarm_id, h.config_hash_id, h.name, h.chart, h.family, h.recipient, h.units, h.exec, h.chart_context, d.when_key, " \
- "d.duration, d.non_clear_duration, d.flags, d.delay_up_to_timestamp, d.info, d.exec_code, d.new_status, d.old_status, d.delay, " \
- " d.new_value, d.old_value, d.last_repeat, d.transition_id, d.global_id, ah.class, ah.type, ah.component FROM health_log h, health_log_detail d, v_%p t, alert_hash ah " \
- " WHERE h.host_id = t.host_id AND h.config_hash_id = ah.hash_id AND h.health_log_id = d.health_log_id AND d.global_id BETWEEN @after AND @before "
+#define SQL_SEARCH_ALERT_TRANSITION_SELECT "SELECT " \
+ "h.host_id, h.alarm_id, h.config_hash_id, h.name, h.chart, h.family, h.recipient, h.units, h.exec, " \
+ "h.chart_context, d.when_key, d.duration, d.non_clear_duration, d.flags, d.delay_up_to_timestamp, " \
+ "d.info, d.exec_code, d.new_status, d.old_status, d.delay, d.new_value, d.old_value, d.last_repeat, " \
+ "d.transition_id, d.global_id, ah.class, ah.type, ah.component, d.exec_run_timestamp"
+#define SQL_SEARCH_ALERT_TRANSITION_COMMON_WHERE \
+ "h.config_hash_id = ah.hash_id AND h.health_log_id = d.health_log_id" \
+ " AND ( d.new_status > 2 OR d.old_status > 2 )"
-#define SQL_SEARCH_ALERT_TRANSITION_DIRECT "SELECT h.host_id, h.alarm_id, h.config_hash_id, h.name, h.chart, h.family, h.recipient, h.units, h.exec, h.chart_context, d.when_key, " \
- "d.duration, d.non_clear_duration, d.flags, d.delay_up_to_timestamp, d.info, d.exec_code, d.new_status, d.old_status, d.delay, " \
- " d.new_value, d.old_value, d.last_repeat, d.transition_id, d.global_id, ah.class, ah.type, ah.component, d.exec_run_timestamp FROM health_log h, health_log_detail d, alert_hash ah " \
- " WHERE h.config_hash_id = ah.hash_id AND h.health_log_id = d.health_log_id AND transition_id = @transition "
+#define SQL_SEARCH_ALERT_TRANSITION SQL_SEARCH_ALERT_TRANSITION_SELECT " FROM health_log h, health_log_detail d, v_%p t, alert_hash ah " \
+ " WHERE h.host_id = t.host_id AND " SQL_SEARCH_ALERT_TRANSITION_COMMON_WHERE " AND d.global_id BETWEEN @after AND @before "
+
+#define SQL_SEARCH_ALERT_TRANSITION_DIRECT SQL_SEARCH_ALERT_TRANSITION_SELECT " FROM health_log h, health_log_detail d, alert_hash ah " \
+ " WHERE " SQL_SEARCH_ALERT_TRANSITION_COMMON_WHERE " AND transition_id = @transition "
void sql_alert_transitions(
DICTIONARY *nodes,
@@ -1909,6 +1914,7 @@ run_query:;
atd.config_hash_id = (uuid_t *)sqlite3_column_blob(res, 2);
atd.alert_name = (const char *) sqlite3_column_text(res, 3);
atd.chart = (const char *) sqlite3_column_text(res, 4);
+ atd.chart_name = (const char *) sqlite3_column_text(res, 4); // FIXME don't copy the id, find the name
atd.family = (const char *) sqlite3_column_text(res, 5);
atd.recipient = (const char *) sqlite3_column_text(res, 6);
atd.units = (const char *) sqlite3_column_text(res, 7);