X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fcurl_json.c;h=756f24f3557dc4dbd2e22c730289fca2f44dff04;hb=43ee9ced15521d541dd3fb0698c9c490339dd35f;hp=bf37cf9a49a717ae66d09cea1c31a334896d0060;hpb=be126043c2be20399d7670fe194645292018bde0;p=collectd.git diff --git a/src/curl_json.c b/src/curl_json.c index bf37cf9a..756f24f3 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -82,6 +82,7 @@ typedef struct { struct cj_s /* {{{ */ { char *instance; + char *plugin_name; char *host; char *sock; @@ -396,6 +397,7 @@ static void cj_free(void *arg) /* {{{ */ db->tree = NULL; sfree(db->instance); + sfree(db->plugin_name); sfree(db->host); sfree(db->sock); @@ -578,7 +580,6 @@ static int cj_init_curl(cj_t *db) /* {{{ */ curl_easy_setopt(db->curl, CURLOPT_WRITEDATA, db); curl_easy_setopt(db->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT); curl_easy_setopt(db->curl, CURLOPT_ERRORBUFFER, db->curl_errbuf); - curl_easy_setopt(db->curl, CURLOPT_URL, db->url); curl_easy_setopt(db->curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(db->curl, CURLOPT_MAXREDIRS, 50L); @@ -601,7 +602,7 @@ static int cj_init_curl(cj_t *db) /* {{{ */ } snprintf(db->credentials, credentials_size, "%s:%s", db->user, - (db->pass == NULL) ? "" : db->pass); + (db->pass == NULL) ? "" : db->pass); curl_easy_setopt(db->curl, CURLOPT_USERPWD, db->credentials); #endif @@ -673,6 +674,8 @@ static int cj_config_add_url(oconfig_item_t *ci) /* {{{ */ if (strcasecmp("Instance", child->key) == 0) status = cf_util_get_string(child, &db->instance); + else if (strcasecmp("Plugin", child->key) == 0) + status = cf_util_get_string(child, &db->plugin_name); else if (strcasecmp("Host", child->key) == 0) status = cf_util_get_string(child, &db->host); else if (db->url && strcasecmp("User", child->key) == 0) @@ -801,12 +804,13 @@ static void cj_submit_impl(cj_t *db, cj_key_t *key, value_t *value) /* {{{ */ int len = 0; for (int i = 0; i < db->depth; i++) len += snprintf(vl.type_instance + len, sizeof(vl.type_instance) - len, - i ? "-%s" : "%s", db->state[i + 1].name); + i ? "-%s" : "%s", db->state[i + 1].name); } else sstrncpy(vl.type_instance, key->instance, sizeof(vl.type_instance)); sstrncpy(vl.host, cj_host(db), sizeof(vl.host)); - sstrncpy(vl.plugin, "curl_json", sizeof(vl.plugin)); + sstrncpy(vl.plugin, (db->plugin_name != NULL) ? db->plugin_name : "curl_json", + sizeof(vl.plugin)); sstrncpy(vl.plugin_instance, db->instance, sizeof(vl.plugin_instance)); sstrncpy(vl.type, key->type, sizeof(vl.type)); @@ -858,12 +862,13 @@ static int cj_curl_perform(cj_t *db) /* {{{ */ int status; long rc; char *url; - url = db->url; + + curl_easy_setopt(db->curl, CURLOPT_URL, db->url); status = curl_easy_perform(db->curl); if (status != CURLE_OK) { ERROR("curl_json plugin: curl_easy_perform failed with status %i: %s (%s)", - status, db->curl_errbuf, url); + status, db->curl_errbuf, db->url); return -1; } if (db->stats != NULL)