From: Florian Forster Date: Wed, 15 Dec 2010 06:51:40 +0000 (+0100) Subject: curl_json plugin: Fix handling of numbers which are returned as strings. X-Git-Tag: collectd-5.0.0-beta1~5 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2f2744072ab144b8130b2296327fc3382e5f7f80;p=collectd.git curl_json plugin: Fix handling of numbers which are returned as strings. Also, the string handling function has been simplified. The obscure and hardly documented sub-request for incomplete keys feature has been removed. --- diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 5d10b24a..7579664b 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -735,22 +735,6 @@ runtime statistics module of CouchDB -Another CouchDB example: -The following example will collect the status values from each database: - - - Instance "dbs" - - Type "gauge" - - - Type "counter" - - - Type "bytes" - - - In the B block, there may be one or more B blocks, each defining a URL to be fetched via HTTP (using libcurl) and one or more B blocks. The B string argument must be in a path format, which is used to collect a diff --git a/src/curl_json.c b/src/curl_json.c index f6bc512d..442cfcf9 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -190,34 +190,26 @@ static int cj_cb_string (void *ctx, const unsigned char *val, unsigned int len) { cj_t *db = (cj_t *)ctx; - c_avl_tree_t *tree; - char *ptr; - - if (db->depth != 1) /* e.g. _all_dbs */ - return (CJ_CB_CONTINUE); + char str[len + 1]; - cj_cb_map_key (ctx, val, len); /* same logic */ + /* Create a null-terminated version of the string. */ + memcpy (str, val, len); + str[len] = 0; - tree = db->state[db->depth].tree; + /* No configuration for this string -> simply return. */ + if (db->state[db->depth].key == NULL) + return (CJ_CB_CONTINUE); - if ((tree != NULL) && (ptr = rindex (db->url, '/'))) + if (!CJ_IS_KEY (db->state[db->depth].key)) { - char url[PATH_MAX]; - CURL *curl; - - /* url =~ s,[^/]+$,$name, */ - len = (ptr - db->url) + 1; - ptr = url; - sstrncpy (ptr, db->url, sizeof (url)); - sstrncpy (ptr + len, db->state[db->depth].name, sizeof (url) - len); - - curl = curl_easy_duphandle (db->curl); - curl_easy_setopt (curl, CURLOPT_URL, url); - cj_curl_perform (db, curl); - curl_easy_cleanup (curl); + NOTICE ("curl_json plugin: Found string \"%s\", but the configuration " + "expects a map here.", str); + return (CJ_CB_CONTINUE); } - return (CJ_CB_CONTINUE); -} + + /* Handle the string as if it was a number. */ + return (cj_cb_number (ctx, (const char *) val, len)); +} /* int cj_cb_string */ static int cj_cb_start (void *ctx) {