summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmmanuel Vasilakis <mrzammler@mm.st>2021-03-26 11:34:23 +0200
committerGitHub <noreply@github.com>2021-03-26 11:34:23 +0200
commit5510b429a642eb2abd8f9831ac98116c4f473325 (patch)
tree3cb94c8737b316cfd2d31bab2ca71844f4f93373
parentf3881e1cd1d2e67275ea4a66760c742b14ac430a (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
-rw-r--r--health/health.h2
-rw-r--r--health/health_json.c12
-rw-r--r--web/api/web_api_v1.c6
3 files changed, 13 insertions, 7 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++;
}
}
diff --git a/web/api/web_api_v1.c b/web/api/web_api_v1.c
index 0d2a33538a..1d8217bbd1 100644
--- a/web/api/web_api_v1.c
+++ b/web/api/web_api_v1.c
@@ -276,6 +276,7 @@ inline int web_client_api_request_v1_alarm_count(RRDHOST *host, struct web_clien
inline int web_client_api_request_v1_alarm_log(RRDHOST *host, struct web_client *w, char *url) {
uint32_t after = 0;
+ char *chart = NULL;
while(url) {
char *value = mystrsep(&url, "&");
@@ -285,12 +286,13 @@ inline int web_client_api_request_v1_alarm_log(RRDHOST *host, struct web_client
if(!name || !*name) continue;
if(!value || !*value) continue;
- if(!strcmp(name, "after")) after = (uint32_t)strtoul(value, NULL, 0);
+ if (!strcmp(name, "after")) after = (uint32_t)strtoul(value, NULL, 0);
+ else if (!strcmp(name, "chart")) chart = value;
}
buffer_flush(w->response.data);
w->response.data->contenttype = CT_APPLICATION_JSON;
- health_alarm_log2json(host, w->response.data, after);
+ health_alarm_log2json(host, w->response.data, after, chart);
return HTTP_RESP_OK;
}