X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fcurl.c;h=4bfd1e4d0b4f0241ce93b50efb0dd47acf74c1a6;hp=cde383d38a277283e9a59a735957d61285edb5db;hb=06a86a60a7dabc685bdbd81ce3d36ea5f7e2c2d4;hpb=267bbc64779f9c7b32e063aac0df22be61bda6ae diff --git a/src/curl.c b/src/curl.c index cde383d3..4bfd1e4d 100644 --- a/src/curl.c +++ b/src/curl.c @@ -53,20 +53,21 @@ struct web_page_s; typedef struct web_page_s web_page_t; struct web_page_s /* {{{ */ { + char *plugin_name; char *instance; char *url; char *user; char *pass; char *credentials; - _Bool digest; - _Bool verify_peer; - _Bool verify_host; + bool digest; + bool verify_peer; + bool verify_host; char *cacert; struct curl_slist *headers; char *post_body; - _Bool response_time; - _Bool response_code; + bool response_time; + bool response_code; int timeout; curl_stats_t *stats; @@ -84,8 +85,7 @@ struct web_page_s /* {{{ */ /* * Global variables; */ -/* static CURLM *curl = NULL; */ -static web_page_t *pages_g = NULL; +static web_page_t *pages_g; /* * Private functions @@ -146,6 +146,7 @@ static void cc_web_page_free(web_page_t *wp) /* {{{ */ curl_easy_cleanup(wp->curl); wp->curl = NULL; + sfree(wp->plugin_name); sfree(wp->instance); sfree(wp->url); @@ -368,8 +369,8 @@ static int cc_page_init_curl(web_page_t *wp) /* {{{ */ return -1; } - ssnprintf(wp->credentials, credentials_size, "%s:%s", wp->user, - (wp->pass == NULL) ? "" : wp->pass); + snprintf(wp->credentials, credentials_size, "%s:%s", wp->user, + (wp->pass == NULL) ? "" : wp->pass); curl_easy_setopt(wp->curl, CURLOPT_USERPWD, wp->credentials); #endif @@ -412,14 +413,15 @@ static int cc_config_add_page(oconfig_item_t *ci) /* {{{ */ ERROR("curl plugin: calloc failed."); return -1; } + page->plugin_name = NULL; page->url = NULL; page->user = NULL; page->pass = NULL; - page->digest = 0; - page->verify_peer = 1; - page->verify_host = 1; - page->response_time = 0; - page->response_code = 0; + page->digest = false; + page->verify_peer = true; + page->verify_host = true; + page->response_time = false; + page->response_code = false; page->timeout = -1; page->stats = NULL; @@ -435,7 +437,9 @@ static int cc_config_add_page(oconfig_item_t *ci) /* {{{ */ for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; - if (strcasecmp("URL", child->key) == 0) + if (strcasecmp("Plugin", child->key) == 0) + status = cf_util_get_string(child, &page->plugin_name); + else if (strcasecmp("URL", child->key) == 0) status = cf_util_get_string(child, &page->url); else if (strcasecmp("User", child->key) == 0) status = cf_util_get_string(child, &page->user); @@ -566,7 +570,8 @@ static void cc_submit(const web_page_t *wp, const web_match_t *wm, /* {{{ */ vl.values = &value; vl.values_len = 1; - sstrncpy(vl.plugin, "curl", sizeof(vl.plugin)); + sstrncpy(vl.plugin, (wp->plugin_name != NULL) ? wp->plugin_name : "curl", + sizeof(vl.plugin)); sstrncpy(vl.plugin_instance, wp->instance, sizeof(vl.plugin_instance)); sstrncpy(vl.type, wm->type, sizeof(vl.type)); if (wm->instance != NULL) @@ -581,7 +586,8 @@ static void cc_submit_response_code(const web_page_t *wp, long code) /* {{{ */ vl.values = &(value_t){.gauge = (gauge_t)code}; vl.values_len = 1; - sstrncpy(vl.plugin, "curl", sizeof(vl.plugin)); + sstrncpy(vl.plugin, (wp->plugin_name != NULL) ? wp->plugin_name : "curl", + sizeof(vl.plugin)); sstrncpy(vl.plugin_instance, wp->instance, sizeof(vl.plugin_instance)); sstrncpy(vl.type, "response_code", sizeof(vl.type)); @@ -594,7 +600,8 @@ static void cc_submit_response_time(const web_page_t *wp, /* {{{ */ vl.values = &(value_t){.gauge = response_time}; vl.values_len = 1; - sstrncpy(vl.plugin, "curl", sizeof(vl.plugin)); + sstrncpy(vl.plugin, (wp->plugin_name != NULL) ? wp->plugin_name : "curl", + sizeof(vl.plugin)); sstrncpy(vl.plugin_instance, wp->instance, sizeof(vl.plugin_instance)); sstrncpy(vl.type, "response_time", sizeof(vl.type)); @@ -623,7 +630,7 @@ static int cc_read_page(web_page_t *wp) /* {{{ */ if (wp->response_time) cc_submit_response_time(wp, CDTIME_T_TO_DOUBLE(cdtime() - start)); if (wp->stats != NULL) - curl_stats_dispatch(wp->stats, wp->curl, hostname_g, "curl", wp->instance); + curl_stats_dispatch(wp->stats, wp->curl, NULL, "curl", wp->instance); if (wp->response_code) { long response_code = 0;