diff options
author | Emmanuel Vasilakis <mrzammler@mm.st> | 2021-04-20 16:24:41 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-20 16:24:41 +0300 |
commit | f5bd20e60ae8a65b9c709fcd28d08c1bea268f2d (patch) | |
tree | 8897d68a69f82d8fd0732aca8c344778a5e62340 /health/health_json.c | |
parent | 0a6a14e323ee3b7a2dc17b2ca5b0cce4a8b2eb5e (diff) |
Provide new attributes in health conf files (#10961)
* read and store new attributes (class, component, type) from health conf files. Replace family variable in info strings
* provide the attributes to jsons
* remove extra semicolon
* populate conf files with new attributes
* added newline
* remove extra defines from health.h
* remove empty line
* remove realloc
* use helper variables for find_and_replace. Adjust position for next strstr
* remove comments
* Add type to mysql.conf and vcsa.conf
* fix formatting
* add parenthesis
* remove extra assignment
* changes to mysql_galera_cluster_state from master
* add type Errors to unbound_request_list_overwritten
* fix identation for info strings spawning more than one line
* check for null, replace with empty string if true
* add class, component, type to systemdunits.conf
Diffstat (limited to 'health/health_json.c')
-rw-r--r-- | health/health_json.c | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/health/health_json.c b/health/health_json.c index 74a384a3b2..8363ad04da 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->class?ae->class:"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->class?rc->class:"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) { |