diff options
author | thiagoftsm <thiagoftsm@gmail.com> | 2020-02-07 20:13:26 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-07 12:13:26 -0800 |
commit | 57055c9ac18e70a812aec4230219e928405cbb26 (patch) | |
tree | d5bc68e600d717199da161aaabf74d2c2591fe20 /health | |
parent | 4dc217a48a0b337e1f0baa13faa93a12c575a500 (diff) |
alarms_values: New endpoint (#7836)
* alarms_values: New endpoint
This commit brings the new endpoint to Netdata
* alarms_values: Documentation
This commit brings the missing documentation for the PR
* alarms_values: New function
This commit brings a new code that removes dupplication
* alarms_values: Fix typo
* alarms_values: Fix missing word
This commit fixes the missing word inside the documentation
* alarms_values: Fix order
This commit fixes the order of the alarm answer
* alarms_values:
Fixes typo and remmove unecessary variable
* alarms_values: Fixes doc
Describe all paramenters present in the endpoint
* alarms_values: Same options
This commit brings the same input pattern for alams and alams_values
* alarms_values: Update swagger
This commit brings the missing information to swagger json
* alarms_values: Update swagger
This commit brings the missing information to swagger yaml
Diffstat (limited to 'health')
-rw-r--r-- | health/health.h | 1 | ||||
-rw-r--r-- | health/health_json.c | 57 |
2 files changed, 45 insertions, 13 deletions
diff --git a/health/health.h b/health/health.h index d77318fd78..78a6ab9eab 100644 --- a/health/health.h +++ b/health/health.h @@ -62,6 +62,7 @@ extern void health_reload(void); extern int health_variable_lookup(const char *variable, uint32_t hash, RRDCALC *rc, calculated_number *result); extern void health_aggregate_alarms(RRDHOST *host, BUFFER *wb, BUFFER* context, RRDCALC_STATUS status); extern void health_alarms2json(RRDHOST *host, BUFFER *wb, int all); +extern void health_alarms_values2json(RRDHOST *host, BUFFER *wb, int all); extern void health_alarm_log2json(RRDHOST *host, BUFFER *wb, uint32_t after); void health_api_v1_chart_variables2json(RRDSET *st, BUFFER *buf); diff --git a/health/health_json.c b/health/health_json.c index 8a088d034a..eae21352f1 100644 --- a/health/health_json.c +++ b/health/health_json.c @@ -113,6 +113,25 @@ void health_alarm_log2json(RRDHOST *host, BUFFER *wb, uint32_t after) { netdata_rwlock_unlock(&host->health_log.alarm_log_rwlock); } +static inline void health_rrdcalc_values2json_nolock(RRDHOST *host, BUFFER *wb, RRDCALC *rc) { + (void)host; + buffer_sprintf(wb, + "\t\t\"%s.%s\": {\n" + "\t\t\t\"id\": %lu,\n" + , rc->chart, rc->name + , (unsigned long)rc->id); + + buffer_strcat(wb, "\t\t\t\"value\":"); + buffer_rrd_value(wb, rc->value); + buffer_strcat(wb, ",\n"); + + buffer_sprintf(wb, + "\t\t\t\"status\": \"%s\"\n" + , rrdcalc_status2string(rc->status)); + + buffer_strcat(wb, "\t\t}"); +} + static inline void health_rrdcalc2json_nolock(RRDHOST *host, BUFFER *wb, RRDCALC *rc) { char value_string[100 + 1]; format_value_and_unit(value_string, 100, rc->value, rc->units, -1); @@ -272,9 +291,23 @@ void health_aggregate_alarms(RRDHOST *host, BUFFER *wb, BUFFER* contexts, RRDCAL rrdhost_unlock(host); } -void health_alarms2json(RRDHOST *host, BUFFER *wb, int all) { +void health_alarms2json_fill_alarms(RRDHOST *host, BUFFER *wb, int all, void (*fp)(RRDHOST *, BUFFER *, RRDCALC *)) { + RRDCALC *rc; int i; + for(i = 0, rc = host->alarms; rc ; rc = rc->next) { + if(unlikely(!rc->rrdset || !rc->rrdset->last_collected_time.tv_sec)) + continue; + + if(likely(!all && !(rc->status == RRDCALC_STATUS_WARNING || rc->status == RRDCALC_STATUS_CRITICAL))) + continue; + + if(likely(i)) buffer_strcat(wb, ",\n"); + fp(host, wb, rc); + i++; + } +} +void health_alarms2json(RRDHOST *host, BUFFER *wb, int all) { rrdhost_rdlock(host); buffer_sprintf(wb, "{\n\t\"hostname\": \"%s\"," "\n\t\"latest_alarm_log_unique_id\": %u," @@ -286,18 +319,7 @@ void health_alarms2json(RRDHOST *host, BUFFER *wb, int all) { host->health_enabled?"true":"false", (unsigned long)now_realtime_sec()); - RRDCALC *rc; - for(i = 0, rc = host->alarms; rc ; rc = rc->next) { - if(unlikely(!rc->rrdset || !rc->rrdset->last_collected_time.tv_sec)) - continue; - - if(likely(!all && !(rc->status == RRDCALC_STATUS_WARNING || rc->status == RRDCALC_STATUS_CRITICAL))) - continue; - - if(likely(i)) buffer_strcat(wb, ",\n"); - health_rrdcalc2json_nolock(host, wb, rc); - i++; - } + health_alarms2json_fill_alarms(host, wb, all, health_rrdcalc2json_nolock); // buffer_strcat(wb, "\n\t},\n\t\"templates\": {"); // RRDCALCTEMPLATE *rt; @@ -308,5 +330,14 @@ void health_alarms2json(RRDHOST *host, BUFFER *wb, int all) { rrdhost_unlock(host); } +void health_alarms_values2json(RRDHOST *host, BUFFER *wb, int all) { + rrdhost_rdlock(host); + buffer_sprintf(wb, "{\n\t\"hostname\": \"%s\"," + "\n\t\"alarms\": {\n", + host->hostname); + health_alarms2json_fill_alarms(host, wb, all, health_rrdcalc_values2json_nolock); + buffer_strcat(wb, "\n\t}\n}\n"); + rrdhost_unlock(host); +} |