diff options
author | Emmanuel Vasilakis <mrzammler@mm.st> | 2021-03-26 11:34:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-26 11:34:23 +0200 |
commit | 5510b429a642eb2abd8f9831ac98116c4f473325 (patch) | |
tree | 3cb94c8737b316cfd2d31bab2ca71844f4f93373 /health | |
parent | f3881e1cd1d2e67275ea4a66760c742b14ac430a (diff) |
Add a new parameter 'chart' to the /api/v1/alarm_log. (#10788)
* add a chart parameter to api alarm_log
* Use hash_chart instead
* also do the strcmp
* cleaner?
* save an if
* move simple_hash out of the loop
* Changed if
* formatting changes
* fix formating
Diffstat (limited to 'health')
-rw-r--r-- | health/health.h | 2 | ||||
-rw-r--r-- | health/health_json.c | 12 |
2 files changed, 9 insertions, 5 deletions
diff --git a/health/health.h b/health/health.h index 5281e16e3c..07ce1311e2 100644 --- a/health/health.h +++ b/health/health.h @@ -64,7 +64,7 @@ extern int health_variable_lookup(const char *variable, uint32_t hash, RRDCALC * 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); +extern void health_alarm_log2json(RRDHOST *host, BUFFER *wb, uint32_t after, char *chart); void health_api_v1_chart_variables2json(RRDSET *st, BUFFER *buf); void health_api_v1_chart_custom_variables2json(RRDSET *st, BUFFER *buf); diff --git a/health/health_json.c b/health/health_json.c index a958abcb66..2a81d1c024 100644 --- a/health/health_json.c +++ b/health/health_json.c @@ -93,18 +93,22 @@ void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, RRDHOST *host) buffer_strcat(wb, "\t}"); } -void health_alarm_log2json(RRDHOST *host, BUFFER *wb, uint32_t after) { +void health_alarm_log2json(RRDHOST *host, BUFFER *wb, uint32_t after, char *chart) { netdata_rwlock_rdlock(&host->health_log.alarm_log_rwlock); buffer_strcat(wb, "["); unsigned int max = host->health_log.max; unsigned int count = 0; + uint32_t hash_chart = 0; + if (chart) hash_chart = simple_hash(chart); ALARM_ENTRY *ae; - for(ae = host->health_log.alarms; ae && count < max ; count++, ae = ae->next) { - if(ae->unique_id > after) { - if(likely(count)) buffer_strcat(wb, ","); + for (ae = host->health_log.alarms; ae && count < max; ae = ae->next) { + if ((ae->unique_id > after) && (!chart || (ae->hash_chart == hash_chart && !strcmp(ae->chart, chart)))) { + if (likely(count)) + buffer_strcat(wb, ","); health_alarm_entry2json_nolock(wb, ae, host); + count++; } } |