2 * collectd - src/curl_json.c
3 * Copyright (C) 2009 Doug MacEachern
4 * Copyright (C) 2006-2013 Florian octo Forster
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; only version 2 of the License is applicable.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * Doug MacEachern <dougm at hyperic.com>
21 * Florian octo Forster <octo at collectd.org>
28 #include "utils_avltree.h"
29 #include "utils_complain.h"
30 #include "utils_curl_stats.h"
32 #include <sys/types.h>
35 #include <curl/curl.h>
37 #include <yajl/yajl_parse.h>
38 #if HAVE_YAJL_YAJL_VERSION_H
39 #include <yajl/yajl_version.h>
42 #if defined(YAJL_MAJOR) && (YAJL_MAJOR > 1)
43 #define HAVE_YAJL_V2 1
46 #define CJ_DEFAULT_HOST "localhost"
47 #define CJ_KEY_MAGIC 0x43484b59UL /* CHKY */
48 #define CJ_IS_KEY(key) ((key)->magic == CJ_KEY_MAGIC)
50 #define COUCH_MIN(x, y) ((x) < (y) ? (x) : (y))
53 typedef struct cj_key_s cj_key_t;
54 struct cj_key_s /* {{{ */
78 struct curl_slist *headers;
85 char curl_errbuf[CURL_ERROR_SIZE];
97 char name[DATA_MAX_NAME_LEN];
98 } state[YAJL_MAX_DEPTH];
100 typedef struct cj_s cj_t; /* }}} */
103 typedef size_t yajl_len_t;
105 typedef unsigned int yajl_len_t;
108 static int cj_read(user_data_t *ud);
109 static void cj_submit(cj_t *db, cj_key_t *key, value_t *value);
111 static size_t cj_curl_callback(void *buf, /* {{{ */
112 size_t size, size_t nmemb, void *user_data) {
126 status = yajl_parse(db->yajl, (unsigned char *)buf, len);
127 if (status == yajl_status_ok)
130 else if (status == yajl_status_insufficient_data)
135 yajl_get_error(db->yajl, /* verbose = */ 1,
136 /* jsonText = */ (unsigned char *)buf, (unsigned int)len);
137 ERROR("curl_json plugin: yajl_parse failed: %s", msg);
138 yajl_free_error(db->yajl, msg);
139 return (0); /* abort write callback */
140 } /* }}} size_t cj_curl_callback */
142 static int cj_get_type(cj_key_t *key) {
143 const data_set_t *ds;
145 if ((key == NULL) || !CJ_IS_KEY(key))
148 ds = plugin_get_ds(key->type);
150 static char type[DATA_MAX_NAME_LEN] = "!!!invalid!!!";
152 assert(key->type != NULL);
153 if (strcmp(type, key->type) != 0) {
154 ERROR("curl_json plugin: Unable to look up DS type \"%s\".", key->type);
155 sstrncpy(type, key->type, sizeof(type));
159 } else if (ds->ds_num > 1) {
160 static c_complain_t complaint = C_COMPLAIN_INIT_STATIC;
163 LOG_WARNING, &complaint,
164 "curl_json plugin: The type \"%s\" has more than one data source. "
165 "This is currently not supported. I will return the type of the "
166 "first data source, but this will likely lead to problems later on.",
170 return ds->ds[0].type;
173 static int cj_cb_map_key(void *ctx, const unsigned char *val, yajl_len_t len);
175 static void cj_cb_inc_array_index(void *ctx, _Bool update_key) {
176 cj_t *db = (cj_t *)ctx;
178 if (!db->state[db->depth].in_array)
181 db->state[db->depth].index++;
184 char name[DATA_MAX_NAME_LEN];
186 ssnprintf(name, sizeof(name), "%d", db->state[db->depth].index - 1);
188 cj_cb_map_key(ctx, (unsigned char *)name, (yajl_len_t)strlen(name));
193 #define CJ_CB_ABORT 0
194 #define CJ_CB_CONTINUE 1
196 static int cj_cb_boolean(void *ctx, int boolVal) {
197 cj_cb_inc_array_index(ctx, /* update_key = */ 0);
198 return (CJ_CB_CONTINUE);
201 static int cj_cb_null(void *ctx) {
202 cj_cb_inc_array_index(ctx, /* update_key = */ 0);
203 return (CJ_CB_CONTINUE);
206 static int cj_cb_number(void *ctx, const char *number, yajl_len_t number_len) {
207 char buffer[number_len + 1];
209 cj_t *db = (cj_t *)ctx;
210 cj_key_t *key = db->state[db->depth].key;
215 /* Create a null-terminated version of the string. */
216 memcpy(buffer, number, number_len);
217 buffer[sizeof(buffer) - 1] = 0;
219 if ((key == NULL) || !CJ_IS_KEY(key)) {
221 !db->state[db->depth].in_array /*can be inhomogeneous*/) {
222 NOTICE("curl_json plugin: Found \"%s\", but the configuration expects"
225 return (CJ_CB_CONTINUE);
228 cj_cb_inc_array_index(ctx, /* update_key = */ 1);
229 key = db->state[db->depth].key;
230 if ((key == NULL) || !CJ_IS_KEY(key)) {
231 return (CJ_CB_CONTINUE);
234 cj_cb_inc_array_index(ctx, /* update_key = */ 1);
237 type = cj_get_type(key);
238 status = parse_value(buffer, &vt, type);
240 NOTICE("curl_json plugin: Unable to parse number: \"%s\"", buffer);
241 return (CJ_CB_CONTINUE);
244 cj_submit(db, key, &vt);
245 return (CJ_CB_CONTINUE);
246 } /* int cj_cb_number */
248 /* Queries the key-tree of the parent context for "in_name" and, if found,
249 * updates the "key" field of the current context. Otherwise, "key" is set to
251 static int cj_cb_map_key(void *ctx, unsigned char const *in_name,
252 yajl_len_t in_name_len) {
253 cj_t *db = (cj_t *)ctx;
256 tree = db->state[db->depth - 1].tree;
259 cj_key_t *value = NULL;
263 /* Create a null-terminated version of the name. */
264 name = db->state[db->depth].name;
266 COUCH_MIN((size_t)in_name_len, sizeof(db->state[db->depth].name) - 1);
267 memcpy(name, in_name, name_len);
270 if (c_avl_get(tree, name, (void *)&value) == 0) {
271 if (CJ_IS_KEY((cj_key_t *)value)) {
272 db->state[db->depth].key = value;
274 db->state[db->depth].tree = (c_avl_tree_t *)value;
276 } else if (c_avl_get(tree, CJ_ANY, (void *)&value) == 0)
277 if (CJ_IS_KEY((cj_key_t *)value)) {
278 db->state[db->depth].key = value;
280 db->state[db->depth].tree = (c_avl_tree_t *)value;
283 db->state[db->depth].key = NULL;
286 return (CJ_CB_CONTINUE);
289 static int cj_cb_string(void *ctx, const unsigned char *val, yajl_len_t len) {
290 /* Handle the string as if it was a number. */
291 return (cj_cb_number(ctx, (const char *)val, len));
292 } /* int cj_cb_string */
294 static int cj_cb_start(void *ctx) {
295 cj_t *db = (cj_t *)ctx;
296 if (++db->depth >= YAJL_MAX_DEPTH) {
297 ERROR("curl_json plugin: %s depth exceeds max, aborting.",
298 db->url ? db->url : db->sock);
299 return (CJ_CB_ABORT);
301 return (CJ_CB_CONTINUE);
304 static int cj_cb_end(void *ctx) {
305 cj_t *db = (cj_t *)ctx;
306 db->state[db->depth].tree = NULL;
308 return (CJ_CB_CONTINUE);
311 static int cj_cb_start_map(void *ctx) {
312 cj_cb_inc_array_index(ctx, /* update_key = */ 1);
313 return cj_cb_start(ctx);
316 static int cj_cb_end_map(void *ctx) { return cj_cb_end(ctx); }
318 static int cj_cb_start_array(void *ctx) {
319 cj_t *db = (cj_t *)ctx;
320 cj_cb_inc_array_index(ctx, /* update_key = */ 1);
321 if (db->depth + 1 < YAJL_MAX_DEPTH) {
322 db->state[db->depth + 1].in_array = 1;
323 db->state[db->depth + 1].index = 0;
325 return cj_cb_start(ctx);
328 static int cj_cb_end_array(void *ctx) {
329 cj_t *db = (cj_t *)ctx;
330 db->state[db->depth].in_array = 0;
331 return cj_cb_end(ctx);
334 static yajl_callbacks ycallbacks = {
335 cj_cb_null, /* null */
336 cj_cb_boolean, /* boolean */
339 cj_cb_number, cj_cb_string, cj_cb_start_map, cj_cb_map_key,
340 cj_cb_end_map, cj_cb_start_array, cj_cb_end_array};
342 /* end yajl callbacks */
344 static void cj_key_free(cj_key_t *key) /* {{{ */
351 sfree(key->instance);
354 } /* }}} void cj_key_free */
356 static void cj_tree_free(c_avl_tree_t *tree) /* {{{ */
361 while (c_avl_pick(tree, (void *)&name, (void *)&value) == 0) {
362 cj_key_t *key = (cj_key_t *)value;
367 cj_tree_free((c_avl_tree_t *)value);
373 } /* }}} void cj_tree_free */
375 static void cj_free(void *arg) /* {{{ */
379 DEBUG("curl_json plugin: cj_free (arg = %p);", arg);
386 if (db->curl != NULL)
387 curl_easy_cleanup(db->curl);
390 if (db->tree != NULL)
391 cj_tree_free(db->tree);
402 sfree(db->credentials);
404 sfree(db->post_body);
405 curl_slist_free_all(db->headers);
406 curl_stats_destroy(db->stats);
409 } /* }}} void cj_free */
411 /* Configuration handling functions {{{ */
413 static c_avl_tree_t *cj_avl_create(void) {
414 return c_avl_create((int (*)(const void *, const void *))strcmp);
417 static int cj_config_append_string(const char *name,
418 struct curl_slist **dest, /* {{{ */
419 oconfig_item_t *ci) {
420 struct curl_slist *temp = NULL;
421 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
422 WARNING("curl_json plugin: `%s' needs exactly one string argument.", name);
426 temp = curl_slist_append(*dest, ci->values[0].value.string);
433 } /* }}} int cj_config_append_string */
435 /* cj_append_key adds key to the configuration stored in db.
438 * "httpd/requests/count",
439 * "httpd/requests/current" ->
440 * { "httpd": { "requests": { "count": $key, "current": $key } } }
442 static int cj_append_key(cj_t *db, cj_key_t *key) { /* {{{ */
443 if (db->tree == NULL)
444 db->tree = cj_avl_create();
446 c_avl_tree_t *tree = db->tree;
448 char const *start = key->path;
453 while ((end = strchr(start, '/')) != NULL) {
456 size_t len = end - start;
460 len = COUCH_MIN(len, sizeof(name) - 1);
461 sstrncpy(name, start, len + 1);
464 if (c_avl_get(tree, name, (void *)&value) != 0) {
465 value = cj_avl_create();
466 c_avl_insert(tree, strdup(name), value);
473 if (strlen(start) == 0) {
474 ERROR("curl_json plugin: invalid key: %s", key->path);
478 c_avl_insert(tree, strdup(start), key);
480 } /* }}} int cj_append_key */
482 static int cj_config_add_key(cj_t *db, /* {{{ */
483 oconfig_item_t *ci) {
487 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
488 WARNING("curl_json plugin: The `Key' block "
489 "needs exactly one string argument.");
493 key = calloc(1, sizeof(*key));
495 ERROR("curl_json plugin: calloc failed.");
498 key->magic = CJ_KEY_MAGIC;
500 if (strcasecmp("Key", ci->key) == 0) {
501 status = cf_util_get_string(ci, &key->path);
507 ERROR("curl_json plugin: cj_config: "
515 for (int i = 0; i < ci->children_num; i++) {
516 oconfig_item_t *child = ci->children + i;
518 if (strcasecmp("Type", child->key) == 0)
519 status = cf_util_get_string(child, &key->type);
520 else if (strcasecmp("Instance", child->key) == 0)
521 status = cf_util_get_string(child, &key->instance);
523 WARNING("curl_json plugin: Option `%s' not allowed here.", child->key);
529 } /* for (i = 0; i < ci->children_num; i++) */
536 if (key->type == NULL) {
537 WARNING("curl_json plugin: `Type' missing in `Key' block.");
542 status = cj_append_key(db, key);
549 } /* }}} int cj_config_add_key */
551 static int cj_init_curl(cj_t *db) /* {{{ */
553 db->curl = curl_easy_init();
554 if (db->curl == NULL) {
555 ERROR("curl_json plugin: curl_easy_init failed.");
559 curl_easy_setopt(db->curl, CURLOPT_NOSIGNAL, 1L);
560 curl_easy_setopt(db->curl, CURLOPT_WRITEFUNCTION, cj_curl_callback);
561 curl_easy_setopt(db->curl, CURLOPT_WRITEDATA, db);
562 curl_easy_setopt(db->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
563 curl_easy_setopt(db->curl, CURLOPT_ERRORBUFFER, db->curl_errbuf);
564 curl_easy_setopt(db->curl, CURLOPT_URL, db->url);
565 curl_easy_setopt(db->curl, CURLOPT_FOLLOWLOCATION, 1L);
566 curl_easy_setopt(db->curl, CURLOPT_MAXREDIRS, 50L);
568 if (db->user != NULL) {
569 #ifdef HAVE_CURLOPT_USERNAME
570 curl_easy_setopt(db->curl, CURLOPT_USERNAME, db->user);
571 curl_easy_setopt(db->curl, CURLOPT_PASSWORD,
572 (db->pass == NULL) ? "" : db->pass);
574 size_t credentials_size;
576 credentials_size = strlen(db->user) + 2;
577 if (db->pass != NULL)
578 credentials_size += strlen(db->pass);
580 db->credentials = malloc(credentials_size);
581 if (db->credentials == NULL) {
582 ERROR("curl_json plugin: malloc failed.");
586 ssnprintf(db->credentials, credentials_size, "%s:%s", db->user,
587 (db->pass == NULL) ? "" : db->pass);
588 curl_easy_setopt(db->curl, CURLOPT_USERPWD, db->credentials);
592 curl_easy_setopt(db->curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
595 curl_easy_setopt(db->curl, CURLOPT_SSL_VERIFYPEER, (long)db->verify_peer);
596 curl_easy_setopt(db->curl, CURLOPT_SSL_VERIFYHOST, db->verify_host ? 2L : 0L);
597 if (db->cacert != NULL)
598 curl_easy_setopt(db->curl, CURLOPT_CAINFO, db->cacert);
599 if (db->headers != NULL)
600 curl_easy_setopt(db->curl, CURLOPT_HTTPHEADER, db->headers);
601 if (db->post_body != NULL)
602 curl_easy_setopt(db->curl, CURLOPT_POSTFIELDS, db->post_body);
604 #ifdef HAVE_CURLOPT_TIMEOUT_MS
605 if (db->timeout >= 0)
606 curl_easy_setopt(db->curl, CURLOPT_TIMEOUT_MS, (long)db->timeout);
607 else if (db->interval > 0)
608 curl_easy_setopt(db->curl, CURLOPT_TIMEOUT_MS,
609 (long)CDTIME_T_TO_MS(db->interval));
611 curl_easy_setopt(db->curl, CURLOPT_TIMEOUT_MS,
612 (long)CDTIME_T_TO_MS(plugin_get_interval()));
616 } /* }}} int cj_init_curl */
618 static int cj_config_add_url(oconfig_item_t *ci) /* {{{ */
623 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
624 WARNING("curl_json plugin: The `URL' block "
625 "needs exactly one string argument.");
629 db = calloc(1, sizeof(*db));
631 ERROR("curl_json plugin: calloc failed.");
637 if (strcasecmp("URL", ci->key) == 0)
638 status = cf_util_get_string(ci, &db->url);
639 else if (strcasecmp("Sock", ci->key) == 0)
640 status = cf_util_get_string(ci, &db->sock);
642 ERROR("curl_json plugin: cj_config: "
653 /* Fill the `cj_t' structure.. */
654 for (int i = 0; i < ci->children_num; i++) {
655 oconfig_item_t *child = ci->children + i;
657 if (strcasecmp("Instance", child->key) == 0)
658 status = cf_util_get_string(child, &db->instance);
659 else if (strcasecmp("Host", child->key) == 0)
660 status = cf_util_get_string(child, &db->host);
661 else if (db->url && strcasecmp("User", child->key) == 0)
662 status = cf_util_get_string(child, &db->user);
663 else if (db->url && strcasecmp("Password", child->key) == 0)
664 status = cf_util_get_string(child, &db->pass);
665 else if (strcasecmp("Digest", child->key) == 0)
666 status = cf_util_get_boolean(child, &db->digest);
667 else if (db->url && strcasecmp("VerifyPeer", child->key) == 0)
668 status = cf_util_get_boolean(child, &db->verify_peer);
669 else if (db->url && strcasecmp("VerifyHost", child->key) == 0)
670 status = cf_util_get_boolean(child, &db->verify_host);
671 else if (db->url && strcasecmp("CACert", child->key) == 0)
672 status = cf_util_get_string(child, &db->cacert);
673 else if (db->url && strcasecmp("Header", child->key) == 0)
674 status = cj_config_append_string("Header", &db->headers, child);
675 else if (db->url && strcasecmp("Post", child->key) == 0)
676 status = cf_util_get_string(child, &db->post_body);
677 else if (strcasecmp("Key", child->key) == 0)
678 status = cj_config_add_key(db, child);
679 else if (strcasecmp("Interval", child->key) == 0)
680 status = cf_util_get_cdtime(child, &db->interval);
681 else if (strcasecmp("Timeout", child->key) == 0)
682 status = cf_util_get_int(child, &db->timeout);
683 else if (strcasecmp("Statistics", child->key) == 0) {
684 db->stats = curl_stats_from_config(child);
685 if (db->stats == NULL)
688 WARNING("curl_json plugin: Option `%s' not allowed here.", child->key);
697 if (db->tree == NULL) {
698 WARNING("curl_json plugin: No (valid) `Key' block within `%s' \"`%s'\".",
699 db->url ? "URL" : "Sock", db->url ? db->url : db->sock);
702 if (status == 0 && db->url)
703 status = cj_init_curl(db);
706 /* If all went well, register this database for reading */
710 if (db->instance == NULL)
711 db->instance = strdup("default");
713 DEBUG("curl_json plugin: Registering new read callback: %s", db->instance);
715 cb_name = ssnprintf_alloc("curl_json-%s-%s", db->instance,
716 db->url ? db->url : db->sock);
718 plugin_register_complex_read(/* group = */ NULL, cb_name, cj_read,
719 /* interval = */ db->interval,
721 .data = db, .free_func = cj_free,
731 /* }}} int cj_config_add_database */
733 static int cj_config(oconfig_item_t *ci) /* {{{ */
742 for (int i = 0; i < ci->children_num; i++) {
743 oconfig_item_t *child = ci->children + i;
745 if (strcasecmp("Sock", child->key) == 0 ||
746 strcasecmp("URL", child->key) == 0) {
747 status = cj_config_add_url(child);
753 WARNING("curl_json plugin: Option `%s' not allowed here.", child->key);
758 if ((success == 0) && (errors > 0)) {
759 ERROR("curl_json plugin: All statements failed.");
764 } /* }}} int cj_config */
766 /* }}} End of configuration handling functions */
768 static const char *cj_host(cj_t *db) /* {{{ */
770 if ((db->host == NULL) || (strcmp("", db->host) == 0) ||
771 (strcmp(CJ_DEFAULT_HOST, db->host) == 0))
776 static void cj_submit(cj_t *db, cj_key_t *key, value_t *value) /* {{{ */
778 value_list_t vl = VALUE_LIST_INIT;
783 if (key->instance == NULL) {
785 for (int i = 0; i < db->depth; i++)
786 len += ssnprintf(vl.type_instance + len, sizeof(vl.type_instance) - len,
787 i ? "-%s" : "%s", db->state[i + 1].name);
789 sstrncpy(vl.type_instance, key->instance, sizeof(vl.type_instance));
791 sstrncpy(vl.host, cj_host(db), sizeof(vl.host));
792 sstrncpy(vl.plugin, "curl_json", sizeof(vl.plugin));
793 sstrncpy(vl.plugin_instance, db->instance, sizeof(vl.plugin_instance));
794 sstrncpy(vl.type, key->type, sizeof(vl.type));
796 if (db->interval > 0)
797 vl.interval = db->interval;
799 plugin_dispatch_values(&vl);
800 } /* }}} int cj_submit */
802 static int cj_sock_perform(cj_t *db) /* {{{ */
805 struct sockaddr_un sa_unix = {
806 .sun_family = AF_UNIX,
808 sstrncpy(sa_unix.sun_path, db->sock, sizeof(sa_unix.sun_path));
810 int fd = socket(AF_UNIX, SOCK_STREAM, 0);
813 if (connect(fd, (struct sockaddr *)&sa_unix, sizeof(sa_unix)) < 0) {
814 ERROR("curl_json plugin: connect(%s) failed: %s",
815 (db->sock != NULL) ? db->sock : "<null>",
816 sstrerror(errno, errbuf, sizeof(errbuf)));
823 unsigned char buffer[4096];
824 red = read(fd, buffer, sizeof(buffer));
826 ERROR("curl_json plugin: read(%s) failed: %s",
827 (db->sock != NULL) ? db->sock : "<null>",
828 sstrerror(errno, errbuf, sizeof(errbuf)));
832 if (!cj_curl_callback(buffer, red, 1, db))
837 } /* }}} int cj_sock_perform */
839 static int cj_curl_perform(cj_t *db) /* {{{ */
846 status = curl_easy_perform(db->curl);
847 if (status != CURLE_OK) {
848 ERROR("curl_json plugin: curl_easy_perform failed with status %i: %s (%s)",
849 status, db->curl_errbuf, url);
852 if (db->stats != NULL)
853 curl_stats_dispatch(db->stats, db->curl, cj_host(db), "curl_json",
856 curl_easy_getinfo(db->curl, CURLINFO_EFFECTIVE_URL, &url);
857 curl_easy_getinfo(db->curl, CURLINFO_RESPONSE_CODE, &rc);
859 /* The response code is zero if a non-HTTP transport was used. */
860 if ((rc != 0) && (rc != 200)) {
861 ERROR("curl_json plugin: curl_easy_perform failed with "
862 "response code %ld (%s)",
867 } /* }}} int cj_curl_perform */
869 static int cj_perform(cj_t *db) /* {{{ */
872 yajl_handle yprev = db->yajl;
874 db->yajl = yajl_alloc(&ycallbacks,
876 /* alloc funcs = */ NULL,
878 /* alloc funcs = */ NULL, NULL,
880 /* context = */ (void *)db);
881 if (db->yajl == NULL) {
882 ERROR("curl_json plugin: yajl_alloc failed.");
888 status = cj_curl_perform(db);
890 status = cj_sock_perform(db);
898 status = yajl_complete_parse(db->yajl);
900 status = yajl_parse_complete(db->yajl);
902 if (status != yajl_status_ok) {
903 unsigned char *errmsg;
905 errmsg = yajl_get_error(db->yajl, /* verbose = */ 0,
906 /* jsonText = */ NULL, /* jsonTextLen = */ 0);
907 ERROR("curl_json plugin: yajl_parse_complete failed: %s", (char *)errmsg);
908 yajl_free_error(db->yajl, errmsg);
917 } /* }}} int cj_perform */
919 static int cj_read(user_data_t *ud) /* {{{ */
923 if ((ud == NULL) || (ud->data == NULL)) {
924 ERROR("curl_json plugin: cj_read: Invalid user data.");
928 db = (cj_t *)ud->data;
931 memset(&db->state, 0, sizeof(db->state));
932 db->state[db->depth].tree = db->tree;
934 return cj_perform(db);
935 } /* }}} int cj_read */
937 static int cj_init(void) /* {{{ */
939 /* Call this while collectd is still single-threaded to avoid
940 * initialization issues in libgcrypt. */
941 curl_global_init(CURL_GLOBAL_SSL);
943 } /* }}} int cj_init */
945 void module_register(void) {
946 plugin_register_complex_config("curl_json", cj_config);
947 plugin_register_init("curl_json", cj_init);
948 } /* void module_register */