diff options
Diffstat (limited to 'web/api/exporters/allmetrics.c')
-rw-r--r-- | web/api/exporters/allmetrics.c | 79 |
1 files changed, 38 insertions, 41 deletions
diff --git a/web/api/exporters/allmetrics.c b/web/api/exporters/allmetrics.c index 17e5e077eb..88ff78e7e4 100644 --- a/web/api/exporters/allmetrics.c +++ b/web/api/exporters/allmetrics.c @@ -18,57 +18,54 @@ struct prometheus_output_options { }; inline int web_client_api_request_v1_allmetrics(RRDHOST *host, struct web_client *w, char *url) { - (void)url; int format = ALLMETRICS_SHELL; const char *prometheus_server = w->client_ip; uint32_t prometheus_backend_options = global_backend_options; PROMETHEUS_OUTPUT_OPTIONS prometheus_output_options = PROMETHEUS_OUTPUT_TIMESTAMPS | ((global_backend_options & BACKEND_OPTION_SEND_NAMES)?PROMETHEUS_OUTPUT_NAMES:0); const char *prometheus_prefix = global_backend_prefix; - uint32_t end = w->total_params; - if (end) { - uint32_t i = 0; - do { - char *name = w->param_name[i].body; - size_t lname = w->param_name[i].length; - char *value = w->param_values[i].body; - size_t lvalue = w->param_values[i].length; + while(url) { + char *value = mystrsep(&url, "&"); + if (!value || !*value) continue; - if(!strncmp(name, "format",lname)) { - if(!strncmp(value, ALLMETRICS_FORMAT_SHELL,lvalue)) - format = ALLMETRICS_SHELL; - else if(!strncmp(value, ALLMETRICS_FORMAT_PROMETHEUS,lvalue)) - format = ALLMETRICS_PROMETHEUS; - else if(!strncmp(value, ALLMETRICS_FORMAT_PROMETHEUS_ALL_HOSTS,lvalue)) - format = ALLMETRICS_PROMETHEUS_ALL_HOSTS; - else if(!strncmp(value, ALLMETRICS_FORMAT_JSON,lvalue)) - format = ALLMETRICS_JSON; - else - format = 0; - } - else if(!strncmp(name, "server",lname)) { - prometheus_server = value; - } - else if(!strncmp(name, "prefix",lname)) { - prometheus_prefix = value; - } - else if(!strncmp(name, "data",lname) || !strncmp(name, "source",lname) || !strncmp(name, "data source",lname) || !strncmp(name, "data-source",lname) || !strncmp(name, "data_source",lname) || !strncmp(name, "datasource",lname)) { - prometheus_backend_options = backend_parse_data_source(value, prometheus_backend_options); - } - else { - int i; - for(i = 0; prometheus_output_flags_root[i].name ; i++) { - if(!strncmp(name, prometheus_output_flags_root[i].name,lname)) { - if(!strncmp(value, "yes",lvalue) || !strncmp(value, "1",lvalue) || !strncmp(value, "true",lvalue)) - prometheus_output_options |= prometheus_output_flags_root[i].flag; - else - prometheus_output_options &= ~prometheus_output_flags_root[i].flag; + char *name = mystrsep(&value, "="); + if(!name || !*name) continue; + if(!value || !*value) continue; + + if(!strcmp(name, "format")) { + if(!strcmp(value, ALLMETRICS_FORMAT_SHELL)) + format = ALLMETRICS_SHELL; + else if(!strcmp(value, ALLMETRICS_FORMAT_PROMETHEUS)) + format = ALLMETRICS_PROMETHEUS; + else if(!strcmp(value, ALLMETRICS_FORMAT_PROMETHEUS_ALL_HOSTS)) + format = ALLMETRICS_PROMETHEUS_ALL_HOSTS; + else if(!strcmp(value, ALLMETRICS_FORMAT_JSON)) + format = ALLMETRICS_JSON; + else + format = 0; + } + else if(!strcmp(name, "server")) { + prometheus_server = value; + } + else if(!strcmp(name, "prefix")) { + prometheus_prefix = value; + } + else if(!strcmp(name, "data") || !strcmp(name, "source") || !strcmp(name, "data source") || !strcmp(name, "data-source") || !strcmp(name, "data_source") || !strcmp(name, "datasource")) { + prometheus_backend_options = backend_parse_data_source(value, prometheus_backend_options); + } + else { + int i; + for(i = 0; prometheus_output_flags_root[i].name ; i++) { + if(!strcmp(name, prometheus_output_flags_root[i].name)) { + if(!strcmp(value, "yes") || !strcmp(value, "1") || !strcmp(value, "true")) + prometheus_output_options |= prometheus_output_flags_root[i].flag; + else + prometheus_output_options &= ~prometheus_output_flags_root[i].flag; - break; - } + break; } } - } while( ++i < end); + } } buffer_flush(w->response.data); |