summaryrefslogtreecommitdiffstats
path: root/database/rrdfunctions.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-08 16:27:08 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-08 16:27:08 +0000
commit81581f9719bc56f01d5aa08952671d65fda9867a (patch)
tree0f5c6b6138bf169c23c9d24b1fc0a3521385cb18 /database/rrdfunctions.c
parentReleasing debian version 1.38.1-1. (diff)
downloadnetdata-81581f9719bc56f01d5aa08952671d65fda9867a.tar.xz
netdata-81581f9719bc56f01d5aa08952671d65fda9867a.zip
Merging upstream version 1.39.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'database/rrdfunctions.c')
-rw-r--r--database/rrdfunctions.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/database/rrdfunctions.c b/database/rrdfunctions.c
index a8341f87e..cdba221a5 100644
--- a/database/rrdfunctions.c
+++ b/database/rrdfunctions.c
@@ -496,7 +496,7 @@ static void rrd_function_call_wait_free(struct rrd_function_call_wait *tmp) {
struct {
const char *format;
- uint8_t content_type;
+ HTTP_CONTENT_TYPE content_type;
} function_formats[] = {
{ .format = "application/json", CT_APPLICATION_JSON },
{ .format = "text/plain", CT_TEXT_PLAIN },
@@ -523,7 +523,7 @@ uint8_t functions_format_to_content_type(const char *format) {
return CT_TEXT_PLAIN;
}
-const char *functions_content_type_to_format(uint8_t content_type) {
+const char *functions_content_type_to_format(HTTP_CONTENT_TYPE content_type) {
for (int i = 0; function_formats[i].format; i++)
if (function_formats[i].content_type == content_type)
return function_formats[i].format;
@@ -537,7 +537,7 @@ int rrd_call_function_error(BUFFER *wb, const char *msg, int code) {
buffer_flush(wb);
buffer_sprintf(wb, "{\"status\":%d,\"error_message\":\"%s\"}", code, buffer);
- wb->contenttype = CT_APPLICATION_JSON;
+ wb->content_type = CT_APPLICATION_JSON;
buffer_no_cacheable(wb);
return code;
}
@@ -632,7 +632,7 @@ int rrd_call_function_and_wait(RRDHOST *host, BUFFER *wb, int timeout, const cha
bool we_should_free = true;
BUFFER *temp_wb = buffer_create(PLUGINSD_LINE_MAX + 1, &netdata_buffers_statistics.buffers_functions); // we need it because we may give up on it
- temp_wb->contenttype = wb->contenttype;
+ temp_wb->content_type = wb->content_type;
code = rdcf->function(temp_wb, timeout, key, rdcf->collector_data, rrd_call_function_signal_when_ready, tmp);
if (code == HTTP_RESP_OK) {
netdata_mutex_lock(&tmp->mutex);
@@ -647,7 +647,7 @@ int rrd_call_function_and_wait(RRDHOST *host, BUFFER *wb, int timeout, const cha
if (tmp->data_are_ready) {
// we have a response
buffer_fast_strcat(wb, buffer_tostring(temp_wb), buffer_strlen(temp_wb));
- wb->contenttype = temp_wb->contenttype;
+ wb->content_type = temp_wb->content_type;
wb->expires = temp_wb->expires;
if(wb->expires)
@@ -738,14 +738,29 @@ void chart_functions2json(RRDSET *st, BUFFER *wb, int tabs, const char *kq, cons
functions2json(st->functions_view, wb, ident, kq, sq);
}
-void host_functions2json(RRDHOST *host, BUFFER *wb, int tabs, const char *kq, const char *sq) {
+void host_functions2json(RRDHOST *host, BUFFER *wb) {
if(!host || !host->functions) return;
- char ident[tabs + 1];
- ident[tabs] = '\0';
- while(tabs) ident[--tabs] = '\t';
+ buffer_json_member_add_object(wb, "functions");
+
+ struct rrd_collector_function *t;
+ dfe_start_read(host->functions, t) {
+ if(!t->collector->running) continue;
+
+ buffer_json_member_add_object(wb, t_dfe.name);
+ buffer_json_member_add_string(wb, "help", string2str(t->help));
+ buffer_json_member_add_int64(wb, "timeout", t->timeout);
+ buffer_json_member_add_array(wb, "options");
+ if(t->options & RRD_FUNCTION_GLOBAL)
+ buffer_json_add_array_item_string(wb, "GLOBAL");
+ if(t->options & RRD_FUNCTION_LOCAL)
+ buffer_json_add_array_item_string(wb, "LOCAL");
+ buffer_json_array_close(wb);
+ buffer_json_object_close(wb);
+ }
+ dfe_done(t);
- functions2json(host->functions, wb, ident, kq, sq);
+ buffer_json_object_close(wb);
}
void chart_functions_to_dict(DICTIONARY *rrdset_functions_view, DICTIONARY *dst) {