summaryrefslogtreecommitdiffstats
path: root/web/api/health
diff options
context:
space:
mode:
authorthiagoftsm <49162938+thiagoftsm@users.noreply.github.com>2019-06-06 17:01:39 +0000
committerGitHub <noreply@github.com>2019-06-06 17:01:39 +0000
commit58b7d95a7ec9c576f8a06bbab07f755846b5349a (patch)
treef17e30963170e818bbe55ed32843eea71de7ac29 /web/api/health
parent7039044be96ee82058768d98865b992b100a294a (diff)
New URL parser (#6070)
* URL_parser 3 * URL_parser rebase 2! * URL_parameter parsing 3 * URL_parameter parsing 4 * URL_parameter parsing 5 * URL_parser alarms * URL_parser finish the basic structure * URL_parser codacity fixes! * URL_parser scripts! * URL_parser codacy! * URL_parser rebase 3! * URL_parser host fixes! * URL_parser host fixes 2! * URL_parser fix spaces! * URL_parser error message! * URL_parser Christopher requests! * URL_parser alarms fixed! * URL_parser health fixed! * URL_parser rebase 4! * URL_parser C fix write format! * URL_parser fix bugs due cache!
Diffstat (limited to 'web/api/health')
-rw-r--r--web/api/health/health_cmdapi.c145
1 files changed, 77 insertions, 68 deletions
diff --git a/web/api/health/health_cmdapi.c b/web/api/health/health_cmdapi.c
index ec177751b9..eac3daf06b 100644
--- a/web/api/health/health_cmdapi.c
+++ b/web/api/health/health_cmdapi.c
@@ -31,13 +31,10 @@ 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);
@@ -73,75 +70,86 @@ 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 {
- 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();
+ 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);
}
- }
-
- 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);
+ 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);
+ }
}
- }
+ key[lkey] = ksave ;
+ value[lvalue] = vsave ;
+
+ } while( ++i < end );
}
+
if (likely(silencer)) {
// Add the created instance to the linked list in silencers
silencer->next = silencers->silencers;
@@ -160,6 +168,7 @@ 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;