struct cx_s /* {{{ */
{
char *instance;
+ char *plugin_name;
char *host;
char *url;
sfree(db->buffer);
sfree(db->instance);
+ sfree(db->plugin_name);
sfree(db->host);
sfree(db->url);
sfree(db);
} /* }}} void cx_free */
-static const char *cx_host(cx_t *db) /* {{{ */
+static const char *cx_host(const cx_t *db) /* {{{ */
{
if (db->host == NULL)
return hostname_g;
status = cx_handle_single_value_xpath(xpath_ctx, xpath, ds, vl, i);
if (status != 0)
return -1; /* An error has been printed. */
- } /* for (i = 0; i < xpath->values_len; i++) */
+ } /* for (i = 0; i < xpath->values_len; i++) */
plugin_dispatch_values(vl);
vl->values = NULL;
if (xpath->instance_prefix != NULL) {
if (instance_node != NULL) {
char *node_value = (char *)xmlNodeGetContent(instance_node->nodeTab[0]);
- ssnprintf(vl->type_instance, sizeof(vl->type_instance), "%s%s",
- xpath->instance_prefix, node_value);
+ snprintf(vl->type_instance, sizeof(vl->type_instance), "%s%s",
+ xpath->instance_prefix, node_value);
sfree(node_value);
} else
sstrncpy(vl->type_instance, xpath->instance_prefix,
return 0;
} /* }}} int cx_handle_instance_xpath */
-static int cx_handle_base_xpath(char const *plugin_instance, /* {{{ */
- char const *host, xmlXPathContextPtr xpath_ctx,
+static int cx_handle_base_xpath(const cx_t *db, /* {{{ */
+ xmlXPathContextPtr xpath_ctx,
const data_set_t *ds, char *base_xpath,
cx_xpath_t *xpath) {
int total_nodes;
/* set the values for the value_list */
vl.values_len = ds->ds_num;
sstrncpy(vl.type, xpath->type, sizeof(vl.type));
- sstrncpy(vl.plugin, "curl_xml", sizeof(vl.plugin));
- sstrncpy(vl.host, host, sizeof(vl.host));
- if (plugin_instance != NULL)
- sstrncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance));
+ sstrncpy(vl.plugin, (db->plugin_name != NULL) ? db->plugin_name : "curl_xml",
+ sizeof(vl.plugin));
+ sstrncpy(vl.host, cx_host(db), sizeof(vl.host));
+ if (db->instance != NULL)
+ sstrncpy(vl.plugin_instance, db->instance, sizeof(vl.plugin_instance));
for (int i = 0; i < total_nodes; i++) {
int status;
ds = plugin_get_ds(xpath->type);
if ((cx_check_type(ds, xpath) == 0) &&
- (cx_handle_base_xpath(db->instance, cx_host(db), xpath_ctx, ds, le->key,
- xpath) == 0))
+ (cx_handle_base_xpath(db, xpath_ctx, ds, le->key, xpath) == 0))
status = 0; /* we got atleast one success */
le = le->next;
long rc;
char *ptr;
char *url;
- url = db->url;
db->buffer_fill = 0;
+
+ curl_easy_setopt(db->curl, CURLOPT_URL, db->url);
+
status = curl_easy_perform(curl);
if (status != CURLE_OK) {
ERROR("curl_xml 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)
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);
return -1;
}
- ssnprintf(db->credentials, credentials_size, "%s:%s", db->user,
- (db->pass == NULL) ? "" : db->pass);
+ snprintf(db->credentials, credentials_size, "%s:%s", db->user,
+ (db->pass == NULL) ? "" : db->pass);
curl_easy_setopt(db->curl, CURLOPT_USERPWD, db->credentials);
#endif
if (strcasecmp("Instance", child->key) == 0)
status = cf_util_get_string(child, &db->instance);
+ else if (strcasecmp("PluginName", 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 (strcasecmp("User", child->key) == 0)