diff options
author | Pavlos Emm. Katsoulakis <paul@netdata.rocks> | 2019-06-07 18:14:44 +0300 |
---|---|---|
committer | Pavlos Emm. Katsoulakis <paul@netdata.rocks> | 2019-06-07 18:14:44 +0300 |
commit | 0fca36fd596e49395141561bc42c168a240f51b8 (patch) | |
tree | 7c47ac793a7937015e4fb3c557ecbb3de5940456 /web/api/health | |
parent | d6f3937b4d4bffedb8a8cc61f80affde7f17b180 (diff) |
Revert "New URL parser (#6070)"
This reverts commit 58b7d95a7ec9c576f8a06bbab07f755846b5349a.
---
As agreed with @thiago and @cakrit we revert URL parser changes,
to buy the time on a more detailed investigation
---
Diffstat (limited to 'web/api/health')
-rw-r--r-- | web/api/health/health_cmdapi.c | 145 |
1 files changed, 68 insertions, 77 deletions
diff --git a/web/api/health/health_cmdapi.c b/web/api/health/health_cmdapi.c index eac3daf06b..ec177751b9 100644 --- a/web/api/health/health_cmdapi.c +++ b/web/api/health/health_cmdapi.c @@ -31,10 +31,13 @@ void free_silencers(SILENCER *t) { return; } + + int web_client_api_request_v1_mgmt_health(RRDHOST *host, struct web_client *w, char *url) { int ret = 400; (void) host; - (void)url; + + BUFFER *wb = w->response.data; buffer_flush(wb); @@ -70,86 +73,75 @@ int web_client_api_request_v1_mgmt_health(RRDHOST *host, struct web_client *w, c buffer_strcat(wb, HEALTH_CMDAPI_MSG_AUTHERROR); ret = 403; } else { - uint32_t end = w->total_params; - if (end) { - uint32_t i = 0; - do { - char *key = w->param_name[i].body; - size_t lkey = w->param_name[i].length; - char ksave = key[lkey]; - key[lkey] = 0x00; - - char *value = w->param_values[i].body; - size_t lvalue = w->param_values[i].length; - char vsave = value[lvalue]; - value[lvalue] = 0x00; - - debug(D_WEB_CLIENT, "%llu: API v1 health query param '%s' with value '%s'", w->id, key, value); - - // name and value are now the parameters - if (!strncmp(key, "cmd",lkey)) { - if (!strcmp(value, HEALTH_CMDAPI_CMD_SILENCEALL)) { - silencers->all_alarms = 1; - silencers->stype = STYPE_SILENCE_NOTIFICATIONS; - buffer_strcat(wb, HEALTH_CMDAPI_MSG_SILENCEALL); - } else if (!strcmp(value, HEALTH_CMDAPI_CMD_DISABLEALL)) { - silencers->all_alarms = 1; - silencers->stype = STYPE_DISABLE_ALARMS; - buffer_strcat(wb, HEALTH_CMDAPI_MSG_DISABLEALL); - } else if (!strcmp(value, HEALTH_CMDAPI_CMD_SILENCE)) { - silencers->stype = STYPE_SILENCE_NOTIFICATIONS; - buffer_strcat(wb, HEALTH_CMDAPI_MSG_SILENCE); - } else if (!strcmp(value, HEALTH_CMDAPI_CMD_DISABLE)) { - silencers->stype = STYPE_DISABLE_ALARMS; - buffer_strcat(wb, HEALTH_CMDAPI_MSG_DISABLE); - } else if (!strcmp(value, HEALTH_CMDAPI_CMD_RESET)) { - silencers->all_alarms = 0; - silencers->stype = STYPE_NONE; - free_silencers(silencers->silencers); - silencers->silencers = NULL; - buffer_strcat(wb, HEALTH_CMDAPI_MSG_RESET); - } - } else { - uint32_t hash = simple_uhash(key); - if (unlikely(silencer == NULL)) { - if ( - (hash == hash_alarm && !strcasecmp(key, HEALTH_ALARM_KEY)) || - (hash == hash_template && !strcasecmp(key, HEALTH_TEMPLATE_KEY)) || - (hash == hash_chart && !strcasecmp(key, HEALTH_CHART_KEY)) || - (hash == hash_context && !strcasecmp(key, HEALTH_CONTEXT_KEY)) || - (hash == hash_host && !strcasecmp(key, HEALTH_HOST_KEY)) || - (hash == hash_families && !strcasecmp(key, HEALTH_FAMILIES_KEY)) - ) { - silencer = create_silencer(); - } - } - - if (hash == hash_alarm && !strncasecmp(key, HEALTH_ALARM_KEY,lkey)) { - silencer->alarms = strdupz(value); - silencer->alarms_pattern = simple_pattern_create(silencer->alarms, NULL, SIMPLE_PATTERN_EXACT); - } else if (hash == hash_chart && !strncasecmp(key, HEALTH_CHART_KEY,lkey)) { - silencer->charts = strdupz(value); - silencer->charts_pattern = simple_pattern_create(silencer->charts, NULL, SIMPLE_PATTERN_EXACT); - } else if (hash == hash_context && !strncasecmp(key, HEALTH_CONTEXT_KEY,lkey)) { - silencer->contexts = strdupz(value); - silencer->contexts_pattern = simple_pattern_create(silencer->contexts, NULL, SIMPLE_PATTERN_EXACT); - } else if (hash == hash_host && !strncasecmp(key, HEALTH_HOST_KEY,lkey)) { - silencer->hosts = strdupz(value); - silencer->hosts_pattern = simple_pattern_create(silencer->hosts, NULL, SIMPLE_PATTERN_EXACT); - } else if (hash == hash_families && !strncasecmp(key, HEALTH_FAMILIES_KEY,lkey)) { - silencer->families = strdupz(value); - silencer->families_pattern = simple_pattern_create(silencer->families, NULL, SIMPLE_PATTERN_EXACT); - } else { - buffer_strcat(wb, HEALTH_CMDAPI_MSG_INVALID_KEY); + while (url) { + char *value = mystrsep(&url, "&"); + if (!value || !*value) continue; + + char *key = mystrsep(&value, "="); + if (!key || !*key) continue; + if (!value || !*value) continue; + + debug(D_WEB_CLIENT, "%llu: API v1 health query param '%s' with value '%s'", w->id, key, value); + + // name and value are now the parameters + if (!strcmp(key, "cmd")) { + if (!strcmp(value, HEALTH_CMDAPI_CMD_SILENCEALL)) { + silencers->all_alarms = 1; + silencers->stype = STYPE_SILENCE_NOTIFICATIONS; + buffer_strcat(wb, HEALTH_CMDAPI_MSG_SILENCEALL); + } else if (!strcmp(value, HEALTH_CMDAPI_CMD_DISABLEALL)) { + silencers->all_alarms = 1; + silencers->stype = STYPE_DISABLE_ALARMS; + buffer_strcat(wb, HEALTH_CMDAPI_MSG_DISABLEALL); + } else if (!strcmp(value, HEALTH_CMDAPI_CMD_SILENCE)) { + silencers->stype = STYPE_SILENCE_NOTIFICATIONS; + buffer_strcat(wb, HEALTH_CMDAPI_MSG_SILENCE); + } else if (!strcmp(value, HEALTH_CMDAPI_CMD_DISABLE)) { + silencers->stype = STYPE_DISABLE_ALARMS; + buffer_strcat(wb, HEALTH_CMDAPI_MSG_DISABLE); + } else if (!strcmp(value, HEALTH_CMDAPI_CMD_RESET)) { + silencers->all_alarms = 0; + silencers->stype = STYPE_NONE; + free_silencers(silencers->silencers); + silencers->silencers = NULL; + buffer_strcat(wb, HEALTH_CMDAPI_MSG_RESET); + } + } else { + uint32_t hash = simple_uhash(key); + if (unlikely(silencer == NULL)) { + if ( + (hash == hash_alarm && !strcasecmp(key, HEALTH_ALARM_KEY)) || + (hash == hash_template && !strcasecmp(key, HEALTH_TEMPLATE_KEY)) || + (hash == hash_chart && !strcasecmp(key, HEALTH_CHART_KEY)) || + (hash == hash_context && !strcasecmp(key, HEALTH_CONTEXT_KEY)) || + (hash == hash_host && !strcasecmp(key, HEALTH_HOST_KEY)) || + (hash == hash_families && !strcasecmp(key, HEALTH_FAMILIES_KEY)) + ) { + silencer = create_silencer(); } } - key[lkey] = ksave ; - value[lvalue] = vsave ; - } while( ++i < end ); + if (hash == hash_alarm && !strcasecmp(key, HEALTH_ALARM_KEY)) { + silencer->alarms = strdupz(value); + silencer->alarms_pattern = simple_pattern_create(silencer->alarms, NULL, SIMPLE_PATTERN_EXACT); + } else if (hash == hash_chart && !strcasecmp(key, HEALTH_CHART_KEY)) { + silencer->charts = strdupz(value); + silencer->charts_pattern = simple_pattern_create(silencer->charts, NULL, SIMPLE_PATTERN_EXACT); + } else if (hash == hash_context && !strcasecmp(key, HEALTH_CONTEXT_KEY)) { + silencer->contexts = strdupz(value); + silencer->contexts_pattern = simple_pattern_create(silencer->contexts, NULL, SIMPLE_PATTERN_EXACT); + } else if (hash == hash_host && !strcasecmp(key, HEALTH_HOST_KEY)) { + silencer->hosts = strdupz(value); + silencer->hosts_pattern = simple_pattern_create(silencer->hosts, NULL, SIMPLE_PATTERN_EXACT); + } else if (hash == hash_families && !strcasecmp(key, HEALTH_FAMILIES_KEY)) { + silencer->families = strdupz(value); + silencer->families_pattern = simple_pattern_create(silencer->families, NULL, SIMPLE_PATTERN_EXACT); + } else { + buffer_strcat(wb, HEALTH_CMDAPI_MSG_INVALID_KEY); + } + } } - if (likely(silencer)) { // Add the created instance to the linked list in silencers silencer->next = silencers->silencers; @@ -168,7 +160,6 @@ int web_client_api_request_v1_mgmt_health(RRDHOST *host, struct web_client *w, c ret = 200; } } - w->response.data = wb; buffer_no_cacheable(w->response.data); return ret; |