X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcurl_xml.c;h=05d75c670b60d4419e0657bd26d9567bc80af528;hb=69b8a9a1af204685dfdfaf1279a0f2928e0bbb32;hp=0f2b92b03ffb4eaec0ceb30731f34b15c738b7e2;hpb=c11a279ed19722816ccc56537a7d928ed06c6bab;p=collectd.git diff --git a/src/curl_xml.c b/src/curl_xml.c index 0f2b92b0..05d75c67 100644 --- a/src/curl_xml.c +++ b/src/curl_xml.c @@ -23,6 +23,7 @@ #include "common.h" #include "plugin.h" #include "configfile.h" +#include "utils_curl_stats.h" #include "utils_llist.h" #include @@ -83,6 +84,7 @@ struct cx_s /* {{{ */ char *post_body; int timeout; struct curl_slist *headers; + curl_stats_t *stats; cx_namespace_t *namespaces; size_t namespaces_num; @@ -114,7 +116,7 @@ static size_t cx_curl_callback (void *buf, /* {{{ */ return (0); } - if (len == 0) + if (len == 0) return (len); if ((db->buffer_fill + len) >= db->buffer_size) @@ -202,6 +204,7 @@ static void cx_free (void *arg) /* {{{ */ sfree (db->cacert); sfree (db->post_body); curl_slist_free_all (db->headers); + curl_stats_destroy (db->stats); for (i = 0; i < db->namespaces_num; i++) { @@ -213,6 +216,13 @@ static void cx_free (void *arg) /* {{{ */ sfree (db); } /* }}} void cx_free */ +static const char *cx_host (cx_t *db) /* {{{ */ +{ + if (db->host == NULL) + return hostname_g; + return db->host; +} /* }}} cx_host */ + static int cx_config_append_string (const char *name, struct curl_slist **dest, /* {{{ */ oconfig_item_t *ci) { @@ -515,7 +525,7 @@ static int cx_handle_base_xpath (char const *plugin_instance, /* {{{ */ 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 != NULL) ? host : hostname_g, sizeof (vl.host)); + sstrncpy (vl.host, host, sizeof (vl.host)); if (plugin_instance != NULL) sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); @@ -558,7 +568,7 @@ static int cx_handle_parsed_xml(xmlDocPtr doc, /* {{{ */ ds = plugin_get_ds (xpath->type); if ( (cx_check_type(ds, xpath) == 0) && - (cx_handle_base_xpath(db->instance, db->host, + (cx_handle_base_xpath(db->instance, cx_host (db), xpath_ctx, ds, le->key, xpath) == 0) ) status = 0; /* we got atleast one success */ @@ -630,6 +640,8 @@ static int cx_curl_perform (cx_t *db, CURL *curl) /* {{{ */ status, db->curl_errbuf, url); return (-1); } + if (db->stats != NULL) + curl_stats_dispatch (db->stats, db->curl, cx_host (db), "curl_xml", db->instance); curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &rc); @@ -981,6 +993,12 @@ static int cx_config_add_url (oconfig_item_t *ci) /* {{{ */ status = cx_config_add_namespace (db, child); else if (strcasecmp ("Timeout", child->key) == 0) status = cf_util_get_int (child, &db->timeout); + else if (strcasecmp ("Statistics", child->key) == 0) + { + db->stats = curl_stats_from_config (child); + if (db->stats == NULL) + status = -1; + } else { WARNING ("curl_xml plugin: Option `%s' not allowed here.", child->key); @@ -1006,7 +1024,7 @@ static int cx_config_add_url (oconfig_item_t *ci) /* {{{ */ /* If all went well, register this database for reading */ if (status == 0) { - user_data_t ud; + user_data_t ud = { 0 }; char *cb_name; if (db->instance == NULL) @@ -1015,7 +1033,6 @@ static int cx_config_add_url (oconfig_item_t *ci) /* {{{ */ DEBUG ("curl_xml plugin: Registering new read callback: %s", db->instance); - memset (&ud, 0, sizeof (ud)); ud.data = (void *) db; ud.free_func = cx_free;