summaryrefslogtreecommitdiffstats
path: root/health
diff options
context:
space:
mode:
authorEmmanuel Vasilakis <mrzammler@mm.st>2022-08-16 10:33:08 +0300
committerGitHub <noreply@github.com>2022-08-16 10:33:08 +0300
commit708efb41bdf952c84b60326d40c07cc69e58d19c (patch)
tree119af9c39fe3dfc6126ef1359ef95d10e86b955b /health
parent62ca74b0a4f5db5ae31d02cb6cbde8d322174249 (diff)
Support chart labels in alerts (#13290)
* chart labels for alerts * proper termination * use strchr * change if statement * change label variable. add docs * change doc * assign buf to temp * use new dictionary functions * reduce variable scope * reduce line length * make sure rrdcalc updates labels after inserted * reduce var scope * add rrdcalc.c for cmocka tests * Revert "add rrdcalc.c for cmocka tests" This reverts commit 5fe122adcf7abcbe6d67fa2ebd7c4ff8620cf9c8. * Fix cmocka unit tests * valgrind errors Co-authored-by: Vladimir Kobal <vlad@prokk.net>
Diffstat (limited to 'health')
-rw-r--r--health/REFERENCE.md38
-rw-r--r--health/health_config.c2
-rw-r--r--health/health_json.c37
-rw-r--r--health/health_log.c19
4 files changed, 43 insertions, 53 deletions
diff --git a/health/REFERENCE.md b/health/REFERENCE.md
index d1af747676..90da4102a9 100644
--- a/health/REFERENCE.md
+++ b/health/REFERENCE.md
@@ -536,12 +536,48 @@ See our [simple patterns docs](/libnetdata/simple_pattern/README.md) for more ex
#### Alarm line `info`
-The info field can contain a small piece of text describing the alarm or template. This will be rendered in notifications and UI elements whenever the specific alarm is in focus. An example for the `ram_available` alarm is:
+The info field can contain a small piece of text describing the alarm or template. This will be rendered in
+notifications and UI elements whenever the specific alarm is in focus. An example for the `ram_available` alarm is:
```yaml
info: percentage of estimated amount of RAM available for userspace processes, without causing swapping
```
+info fields can contain special variables in their text that will be replaced during run-time to provide more specific
+alert information. Current variables supported are:
+
+| variable | description |
+| ---------| ----------- |
+| $family | Will be replaced by the family instance for the alert (e.g. eth0) |
+| $label: | Followed by a chart label name, this will replace the variable with the chart label's value |
+
+For example, an info field like the following:
+
+```yaml
+info: average inbound utilization for the network interface $family over the last minute
+```
+
+Will be rendered on the alert acting on interface `eth0` as:
+
+```yaml
+info: average inbound utilization for the network interface eth0 over the last minute
+```
+
+An alert acting on a chart that has a chart label named e.g. `target`, with a value of `https://netdata.cloud/`,
+can be enriched as follows:
+
+```yaml
+info: average ratio of HTTP responses with unexpected status over the last 5 minutes for the site $label:target
+```
+
+Will become:
+
+```yaml
+info: average ratio of HTTP responses with unexpected status over the last 5 minutes for the site https://netdata.cloud/
+```
+
+> Please note that variable names are case sensitive.
+
## Expressions
Netdata has an internal [infix expression parser](/libnetdata/eval). This parses expressions and creates an internal
diff --git a/health/health_config.c b/health/health_config.c
index 7efa45486a..77b12fc183 100644
--- a/health/health_config.c
+++ b/health/health_config.c
@@ -942,6 +942,8 @@ static int health_readfile(const char *filename, void *data) {
}
rc->info = strdupz(value);
strip_quotes(rc->info);
+ rc->original_info = strdupz(value);
+ strip_quotes(rc->original_info);
}
else if(hash == hash_delay && !strcasecmp(key, HEALTH_DELAY_KEY)) {
alert_cfg->delay = strdupz(value);
diff --git a/health/health_json.c b/health/health_json.c
index 4e8f437613..a0dc55b612 100644
--- a/health/health_json.c
+++ b/health/health_json.c
@@ -96,22 +96,7 @@ void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, RRDHOST *host)
, (ae->flags & HEALTH_ENTRY_FLAG_SILENCED)?"true":"false"
);
- char *replaced_info = NULL;
- if (likely(ae->info)) {
- char *m = NULL;
- replaced_info = strdupz(ae->info);
- size_t pos = 0;
- while ((m = strstr(replaced_info + pos, "$family"))) {
- char *buf = NULL;
- pos = m - replaced_info;
- buf = find_and_replace(replaced_info, "$family", ae->family ? ae->family : "", m);
- freez(replaced_info);
- replaced_info = strdupz(buf);
- freez(buf);
- }
- }
-
- health_string2json(wb, "\t\t", "info", replaced_info?replaced_info:"", ",\n");
+ health_string2json(wb, "\t\t", "info", ae->info ? ae->info : "", ",\n");
if(unlikely(ae->flags & HEALTH_ENTRY_FLAG_NO_CLEAR_NOTIFICATION)) {
buffer_strcat(wb, "\t\t\"no_clear_notification\": true,\n");
@@ -127,7 +112,6 @@ void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, RRDHOST *host)
buffer_strcat(wb, "\t}");
- freez(replaced_info);
freez(edit_command);
}
@@ -182,21 +166,6 @@ static inline void health_rrdcalc2json_nolock(RRDHOST *host, BUFFER *wb, RRDCALC
char value_string[100 + 1];
format_value_and_unit(value_string, 100, rc->value, rc->units, -1);
- char *replaced_info = NULL;
- if (likely(rc->info)) {
- char *m;
- replaced_info = strdupz(rc->info);
- size_t pos = 0;
- while ((m = strstr(replaced_info + pos, "$family"))) {
- char *buf = NULL;
- pos = m - replaced_info;
- buf = find_and_replace(replaced_info, "$family", (rc->rrdset && rc->rrdset->family) ? rc->rrdset->family : "", m);
- freez(replaced_info);
- replaced_info = strdupz(buf);
- freez(buf);
- }
- }
-
char hash_id[GUID_LEN + 1];
uuid_unparse_lower(rc->config_hash_id, hash_id);
@@ -250,7 +219,7 @@ static inline void health_rrdcalc2json_nolock(RRDHOST *host, BUFFER *wb, RRDCALC
, rc->recipient?rc->recipient:host->health_default_recipient
, rc->source
, rc->units?rc->units:""
- , replaced_info?replaced_info:""
+ , rc->info?rc->info:""
, rrdcalc_status2string(rc->status)
, (unsigned long)rc->last_status_change
, (unsigned long)rc->last_updated
@@ -322,8 +291,6 @@ static inline void health_rrdcalc2json_nolock(RRDHOST *host, BUFFER *wb, RRDCALC
buffer_strcat(wb, "\n");
buffer_strcat(wb, "\t\t}");
-
- freez(replaced_info);
}
//void health_rrdcalctemplate2json_nolock(BUFFER *wb, RRDCALCTEMPLATE *rt) {
diff --git a/health/health_log.c b/health/health_log.c
index f0a05531d3..d880625e05 100644
--- a/health/health_log.c
+++ b/health/health_log.c
@@ -512,23 +512,8 @@ inline ALARM_ENTRY* health_create_alarm_entry(
ae->old_value_string = strdupz(format_value_and_unit(value_string, 100, ae->old_value, ae->units, -1));
ae->new_value_string = strdupz(format_value_and_unit(value_string, 100, ae->new_value, ae->units, -1));
- char *replaced_info = NULL;
- if (likely(info)) {
- char *m;
- replaced_info = strdupz(info);
- size_t pos = 0;
- while ((m = strstr(replaced_info + pos, "$family"))) {
- char *buf = NULL;
- pos = m - replaced_info;
- buf = find_and_replace(replaced_info, "$family", (ae->family) ? ae->family : "", m);
- freez(replaced_info);
- replaced_info = strdupz(buf);
- freez(buf);
- }
- }
-
- if(replaced_info) ae->info = strdupz(replaced_info);
- freez(replaced_info);
+ if (info)
+ ae->info = strdupz(info);
ae->old_status = old_status;
ae->new_status = new_status;