summaryrefslogtreecommitdiffstats
path: root/web/api/badges
diff options
context:
space:
mode:
Diffstat (limited to 'web/api/badges')
-rw-r--r--web/api/badges/web_buffer_svg.c23
-rw-r--r--web/api/badges/web_buffer_svg.h6
2 files changed, 18 insertions, 11 deletions
diff --git a/web/api/badges/web_buffer_svg.c b/web/api/badges/web_buffer_svg.c
index 00b4ad650..080f2240f 100644
--- a/web/api/badges/web_buffer_svg.c
+++ b/web/api/badges/web_buffer_svg.c
@@ -893,6 +893,10 @@ int web_client_api_request_v1_badge(RRDHOST *host, struct web_client *w, char *u
int group = RRDR_GROUPING_AVERAGE;
uint32_t options = 0x00000000;
+ const RRDCALC_ACQUIRED *rca = NULL;
+ RRDCALC *rc = NULL;
+ RRDSET *st = NULL;
+
while(url) {
char *value = mystrsep(&url, "&");
if(!value || !*value) continue;
@@ -957,7 +961,7 @@ int web_client_api_request_v1_badge(RRDHOST *host, struct web_client *w, char *u
int scale = (scale_str && *scale_str)?str2i(scale_str):100;
- RRDSET *st = rrdset_find(host, chart);
+ st = rrdset_find(host, chart);
if(!st) st = rrdset_find_byname(host, chart);
if(!st) {
buffer_no_cacheable(w->response.data);
@@ -967,9 +971,10 @@ int web_client_api_request_v1_badge(RRDHOST *host, struct web_client *w, char *u
}
st->last_accessed_time = now_realtime_sec();
- RRDCALC *rc = NULL;
if(alarm) {
- rc = rrdcalc_find(st, alarm);
+ rca = rrdcalc_from_rrdset_get(st, alarm);
+ rc = rrdcalc_acquired_to_rrdcalc(rca);
+
if (!rc) {
buffer_no_cacheable(w->response.data);
buffer_svg(w->response.data, "alarm not found", NAN, "", NULL, NULL, -1, scale, 0, -1, -1, NULL, NULL);
@@ -1020,19 +1025,19 @@ int web_client_api_request_v1_badge(RRDHOST *host, struct web_client *w, char *u
label = dim;
}
else
- label = st->name;
+ label = rrdset_name(st);
}
if(!units) {
if(alarm) {
if(rc->units)
- units = rc->units;
+ units = rrdcalc_units(rc);
else
units = "";
}
else if(options & RRDR_OPTION_PERCENTAGE)
units = "%";
else
- units = st->units;
+ units = rrdset_units(st);
}
debug(D_WEB_CLIENT, "%llu: API command 'badge.svg' for chart '%s', alarm '%s', dimensions '%s', after '%lld', before '%lld', points '%d', group '%d', options '0x%08x'"
@@ -1111,7 +1116,8 @@ int web_client_api_request_v1_badge(RRDHOST *host, struct web_client *w, char *u
points, after, before, group, group_options, 0, options,
NULL, &latest_timestamp,
NULL, NULL, NULL,
- &value_is_null, NULL, 0, 0);
+ &value_is_null, NULL, 0, 0,
+ QUERY_SOURCE_API_BADGE);
// if the value cannot be calculated, show empty badge
if (ret != HTTP_RESP_OK) {
@@ -1143,7 +1149,8 @@ int web_client_api_request_v1_badge(RRDHOST *host, struct web_client *w, char *u
);
}
- cleanup:
+cleanup:
+ rrdcalc_from_rrdset_release(st, rca);
buffer_free(dimensions);
return ret;
}
diff --git a/web/api/badges/web_buffer_svg.h b/web/api/badges/web_buffer_svg.h
index 4853a8864..71857811f 100644
--- a/web/api/badges/web_buffer_svg.h
+++ b/web/api/badges/web_buffer_svg.h
@@ -6,12 +6,12 @@
#include "libnetdata/libnetdata.h"
#include "web/server/web_client.h"
-extern void buffer_svg(BUFFER *wb, const char *label,
+void buffer_svg(BUFFER *wb, const char *label,
NETDATA_DOUBLE value, const char *units, const char *label_color, const char *value_color, int precision, int scale, uint32_t options, int fixed_width_lbl, int fixed_width_val, const char* text_color_lbl, const char* text_color_val);
-extern char *format_value_and_unit(char *value_string, size_t value_string_len,
+char *format_value_and_unit(char *value_string, size_t value_string_len,
NETDATA_DOUBLE value, const char *units, int precision);
-extern int web_client_api_request_v1_badge(struct rrdhost *host, struct web_client *w, char *url);
+int web_client_api_request_v1_badge(struct rrdhost *host, struct web_client *w, char *url);
#include "web/api/web_api_v1.h"