summaryrefslogtreecommitdiffstats
path: root/health/health_json.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-05-19 12:33:38 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-05-19 12:33:59 +0000
commit1ee0c09c5742557e037df5421ca62abddb90ae22 (patch)
tree71c0fa48bb6d31d036c9badd7e038527f90d1a73 /health/health_json.c
parentReleasing debian version 1.30.1-1. (diff)
downloadnetdata-1ee0c09c5742557e037df5421ca62abddb90ae22.tar.xz
netdata-1ee0c09c5742557e037df5421ca62abddb90ae22.zip
Merging upstream version 1.31.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'health/health_json.c')
-rw-r--r--health/health_json.c50
1 files changed, 48 insertions, 2 deletions
diff --git a/health/health_json.c b/health/health_json.c
index 74a384a3b..4df44611c 100644
--- a/health/health_json.c
+++ b/health/health_json.c
@@ -23,6 +23,9 @@ void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, RRDHOST *host)
"\t\t\"name\": \"%s\",\n"
"\t\t\"chart\": \"%s\",\n"
"\t\t\"family\": \"%s\",\n"
+ "\t\t\"class\": \"%s\",\n"
+ "\t\t\"component\": \"%s\",\n"
+ "\t\t\"type\": \"%s\",\n"
"\t\t\"processed\": %s,\n"
"\t\t\"updated\": %s,\n"
"\t\t\"exec_run\": %lu,\n"
@@ -52,6 +55,9 @@ void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, RRDHOST *host)
, ae->name
, ae->chart
, ae->family
+ , ae->classification?ae->classification:"Unknown"
+ , ae->component?ae->component:"Unknown"
+ , ae->type?ae->type:"Unknown"
, (ae->flags & HEALTH_ENTRY_FLAG_PROCESSED)?"true":"false"
, (ae->flags & HEALTH_ENTRY_FLAG_UPDATED)?"true":"false"
, (unsigned long)ae->exec_run_timestamp
@@ -76,7 +82,22 @@ void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, RRDHOST *host)
, (ae->flags & HEALTH_ENTRY_FLAG_SILENCED)?"true":"false"
);
- health_string2json(wb, "\t\t", "info", ae->info?ae->info:"", ",\n");
+ 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");
if(unlikely(ae->flags & HEALTH_ENTRY_FLAG_NO_CLEAR_NOTIFICATION)) {
buffer_strcat(wb, "\t\t\"no_clear_notification\": true,\n");
@@ -91,6 +112,8 @@ void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, RRDHOST *host)
buffer_strcat(wb, "\n");
buffer_strcat(wb, "\t}");
+
+ freez(replaced_info);
}
void health_alarm_log2json(RRDHOST *host, BUFFER *wb, uint32_t after, char *chart) {
@@ -140,12 +163,30 @@ 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);
+ }
+ }
+
buffer_sprintf(wb,
"\t\t\"%s.%s\": {\n"
"\t\t\t\"id\": %lu,\n"
"\t\t\t\"name\": \"%s\",\n"
"\t\t\t\"chart\": \"%s\",\n"
"\t\t\t\"family\": \"%s\",\n"
+ "\t\t\t\"class\": \"%s\",\n"
+ "\t\t\t\"component\": \"%s\",\n"
+ "\t\t\t\"type\": \"%s\",\n"
"\t\t\t\"active\": %s,\n"
"\t\t\t\"disabled\": %s,\n"
"\t\t\t\"silenced\": %s,\n"
@@ -174,6 +215,9 @@ static inline void health_rrdcalc2json_nolock(RRDHOST *host, BUFFER *wb, RRDCALC
, rc->name
, rc->chart
, (rc->rrdset && rc->rrdset->family)?rc->rrdset->family:""
+ , rc->classification?rc->classification:"Unknown"
+ , rc->component?rc->component:"Unknown"
+ , rc->type?rc->type:"Unknown"
, (rc->rrdset)?"true":"false"
, (rc->rrdcalc_flags & RRDCALC_FLAG_DISABLED)?"true":"false"
, (rc->rrdcalc_flags & RRDCALC_FLAG_SILENCED)?"true":"false"
@@ -181,7 +225,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:""
- , rc->info?rc->info:""
+ , replaced_info?replaced_info:""
, rrdcalc_status2string(rc->status)
, (unsigned long)rc->last_status_change
, (unsigned long)rc->last_updated
@@ -252,6 +296,8 @@ 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) {