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_impl(cj_t *db, cj_key_t *key, value_t *value);
111 /* cj_submit is a function pointer to cj_submit_impl, allowing the unit-test to
112 * overwrite which function is called. */
113 static void (*cj_submit)(cj_t *, cj_key_t *, value_t *) = cj_submit_impl;
115 static size_t cj_curl_callback(void *buf, /* {{{ */
116 size_t size, size_t nmemb, void *user_data) {
130 status = yajl_parse(db->yajl, (unsigned char *)buf, len);
131 if (status == yajl_status_ok)
134 else if (status == yajl_status_insufficient_data)
139 yajl_get_error(db->yajl, /* verbose = */ 1,
140 /* jsonText = */ (unsigned char *)buf, (unsigned int)len);
141 ERROR("curl_json plugin: yajl_parse failed: %s", msg);
142 yajl_free_error(db->yajl, msg);
143 return 0; /* abort write callback */
144 } /* }}} size_t cj_curl_callback */
146 static int cj_get_type(cj_key_t *key) {
147 const data_set_t *ds;
149 if ((key == NULL) || !CJ_IS_KEY(key))
152 ds = plugin_get_ds(key->type);
154 static char type[DATA_MAX_NAME_LEN] = "!!!invalid!!!";
156 assert(key->type != NULL);
157 if (strcmp(type, key->type) != 0) {
158 ERROR("curl_json plugin: Unable to look up DS type \"%s\".", key->type);
159 sstrncpy(type, key->type, sizeof(type));
163 } else if (ds->ds_num > 1) {
164 static c_complain_t complaint = C_COMPLAIN_INIT_STATIC;
167 LOG_WARNING, &complaint,
168 "curl_json plugin: The type \"%s\" has more than one data source. "
169 "This is currently not supported. I will return the type of the "
170 "first data source, but this will likely lead to problems later on.",
174 return ds->ds[0].type;
177 /* cj_load_key loads the configuration for "key" from the parent context and
178 * sets either .key or .tree in the current context. */
179 static int cj_load_key(cj_t *db, char const *key) {
180 if (db == NULL || key == NULL || db->depth <= 0)
183 sstrncpy(db->state[db->depth].name, key, sizeof(db->state[db->depth].name));
185 c_avl_tree_t *tree = db->state[db->depth - 1].tree;
190 /* the parent has a key, so the tree pointer is invalid. */
191 if (CJ_IS_KEY(db->state[db->depth - 1].key)) {
196 if (c_avl_get(tree, key, (void *)&value) == 0) {
197 if (CJ_IS_KEY((cj_key_t *)value)) {
198 db->state[db->depth].key = value;
200 db->state[db->depth].tree = value;
202 } else if (c_avl_get(tree, CJ_ANY, (void *)&value) == 0) {
203 if (CJ_IS_KEY((cj_key_t *)value)) {
204 db->state[db->depth].key = value;
206 db->state[db->depth].tree = value;
209 db->state[db->depth].key = NULL;
215 static void cj_advance_array(cj_t *db) {
216 if (!db->state[db->depth].in_array)
219 db->state[db->depth].index++;
221 char name[DATA_MAX_NAME_LEN];
222 ssnprintf(name, sizeof(name), "%d", db->state[db->depth].index);
223 cj_load_key(db, name);
227 #define CJ_CB_ABORT 0
228 #define CJ_CB_CONTINUE 1
230 static int cj_cb_boolean(void *ctx, int boolVal) {
231 cj_advance_array(ctx);
232 return CJ_CB_CONTINUE;
235 static int cj_cb_null(void *ctx) {
236 cj_advance_array(ctx);
237 return CJ_CB_CONTINUE;
240 static int cj_cb_number(void *ctx, const char *number, yajl_len_t number_len) {
241 char buffer[number_len + 1];
243 cj_t *db = (cj_t *)ctx;
244 cj_key_t *key = db->state[db->depth].key;
246 /* Create a null-terminated version of the string. */
247 memcpy(buffer, number, number_len);
248 buffer[sizeof(buffer) - 1] = 0;
251 /* no config for this element. */
252 cj_advance_array(ctx);
253 return CJ_CB_CONTINUE;
254 } else if (!CJ_IS_KEY(key)) {
255 /* the config expects a map or an array. */
257 "curl_json plugin: Found \"%s\", but the configuration expects a map.",
259 cj_advance_array(ctx);
260 return CJ_CB_CONTINUE;
263 int type = cj_get_type(key);
265 int status = parse_value(buffer, &vt, type);
267 NOTICE("curl_json plugin: Unable to parse number: \"%s\"", buffer);
268 cj_advance_array(ctx);
269 return CJ_CB_CONTINUE;
272 cj_submit(db, key, &vt);
273 cj_advance_array(ctx);
274 return CJ_CB_CONTINUE;
275 } /* int cj_cb_number */
277 /* Queries the key-tree of the parent context for "in_name" and, if found,
278 * updates the "key" field of the current context. Otherwise, "key" is set to
280 static int cj_cb_map_key(void *ctx, unsigned char const *in_name,
281 yajl_len_t in_name_len) {
282 char name[in_name_len + 1];
284 memmove(name, in_name, in_name_len);
285 name[sizeof(name) - 1] = 0;
287 if (cj_load_key(ctx, name) != 0)
290 return CJ_CB_CONTINUE;
293 static int cj_cb_string(void *ctx, const unsigned char *val, yajl_len_t len) {
294 /* Handle the string as if it was a number. */
295 return cj_cb_number(ctx, (const char *)val, len);
296 } /* int cj_cb_string */
298 static int cj_cb_end(void *ctx) {
299 cj_t *db = (cj_t *)ctx;
300 db->state[db->depth].tree = NULL;
302 cj_advance_array(ctx);
303 return CJ_CB_CONTINUE;
306 static int cj_cb_start_map(void *ctx) {
307 cj_t *db = (cj_t *)ctx;
309 if ((db->depth + 1) >= YAJL_MAX_DEPTH) {
310 ERROR("curl_json plugin: %s depth exceeds max, aborting.",
311 db->url ? db->url : db->sock);
315 return CJ_CB_CONTINUE;
318 static int cj_cb_end_map(void *ctx) { return cj_cb_end(ctx); }
320 static int cj_cb_start_array(void *ctx) {
321 cj_t *db = (cj_t *)ctx;
323 if ((db->depth + 1) >= YAJL_MAX_DEPTH) {
324 ERROR("curl_json plugin: %s depth exceeds max, aborting.",
325 db->url ? db->url : db->sock);
329 db->state[db->depth].in_array = 1;
330 db->state[db->depth].index = 0;
332 cj_load_key(db, "0");
334 return CJ_CB_CONTINUE;
337 static int cj_cb_end_array(void *ctx) {
338 cj_t *db = (cj_t *)ctx;
339 db->state[db->depth].in_array = 0;
340 return cj_cb_end(ctx);
343 static yajl_callbacks ycallbacks = {
344 cj_cb_null, /* null */
345 cj_cb_boolean, /* boolean */
348 cj_cb_number, cj_cb_string, cj_cb_start_map, cj_cb_map_key,
349 cj_cb_end_map, cj_cb_start_array, cj_cb_end_array};
351 /* end yajl callbacks */
353 static void cj_key_free(cj_key_t *key) /* {{{ */
360 sfree(key->instance);
363 } /* }}} void cj_key_free */
365 static void cj_tree_free(c_avl_tree_t *tree) /* {{{ */
370 while (c_avl_pick(tree, (void *)&name, (void *)&value) == 0) {
371 cj_key_t *key = (cj_key_t *)value;
376 cj_tree_free((c_avl_tree_t *)value);
382 } /* }}} void cj_tree_free */
384 static void cj_free(void *arg) /* {{{ */
388 DEBUG("curl_json plugin: cj_free (arg = %p);", arg);
395 if (db->curl != NULL)
396 curl_easy_cleanup(db->curl);
399 if (db->tree != NULL)
400 cj_tree_free(db->tree);
411 sfree(db->credentials);
413 sfree(db->post_body);
414 curl_slist_free_all(db->headers);
415 curl_stats_destroy(db->stats);
418 } /* }}} void cj_free */
420 /* Configuration handling functions {{{ */
422 static c_avl_tree_t *cj_avl_create(void) {
423 return c_avl_create((int (*)(const void *, const void *))strcmp);
426 static int cj_config_append_string(const char *name,
427 struct curl_slist **dest, /* {{{ */
428 oconfig_item_t *ci) {
429 struct curl_slist *temp = NULL;
430 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
431 WARNING("curl_json plugin: `%s' needs exactly one string argument.", name);
435 temp = curl_slist_append(*dest, ci->values[0].value.string);
442 } /* }}} int cj_config_append_string */
444 /* cj_append_key adds key to the configuration stored in db.
447 * "httpd/requests/count",
448 * "httpd/requests/current" ->
449 * { "httpd": { "requests": { "count": $key, "current": $key } } }
451 static int cj_append_key(cj_t *db, cj_key_t *key) { /* {{{ */
452 if (db->tree == NULL)
453 db->tree = cj_avl_create();
455 c_avl_tree_t *tree = db->tree;
457 char const *start = key->path;
462 while ((end = strchr(start, '/')) != NULL) {
465 size_t len = end - start;
469 len = COUCH_MIN(len, sizeof(name) - 1);
470 sstrncpy(name, start, len + 1);
473 if (c_avl_get(tree, name, (void *)&value) != 0) {
474 value = cj_avl_create();
475 c_avl_insert(tree, strdup(name), value);
482 if (strlen(start) == 0) {
483 ERROR("curl_json plugin: invalid key: %s", key->path);
487 c_avl_insert(tree, strdup(start), key);
489 } /* }}} int cj_append_key */
491 static int cj_config_add_key(cj_t *db, /* {{{ */
492 oconfig_item_t *ci) {
496 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
497 WARNING("curl_json plugin: The `Key' block "
498 "needs exactly one string argument.");
502 key = calloc(1, sizeof(*key));
504 ERROR("curl_json plugin: calloc failed.");
507 key->magic = CJ_KEY_MAGIC;
509 if (strcasecmp("Key", ci->key) == 0) {
510 status = cf_util_get_string(ci, &key->path);
516 ERROR("curl_json plugin: cj_config: "
524 for (int i = 0; i < ci->children_num; i++) {
525 oconfig_item_t *child = ci->children + i;
527 if (strcasecmp("Type", child->key) == 0)
528 status = cf_util_get_string(child, &key->type);
529 else if (strcasecmp("Instance", child->key) == 0)
530 status = cf_util_get_string(child, &key->instance);
532 WARNING("curl_json plugin: Option `%s' not allowed here.", child->key);
538 } /* for (i = 0; i < ci->children_num; i++) */
545 if (key->type == NULL) {
546 WARNING("curl_json plugin: `Type' missing in `Key' block.");
551 status = cj_append_key(db, key);
558 } /* }}} int cj_config_add_key */
560 static int cj_init_curl(cj_t *db) /* {{{ */
562 db->curl = curl_easy_init();
563 if (db->curl == NULL) {
564 ERROR("curl_json plugin: curl_easy_init failed.");
568 curl_easy_setopt(db->curl, CURLOPT_NOSIGNAL, 1L);
569 curl_easy_setopt(db->curl, CURLOPT_WRITEFUNCTION, cj_curl_callback);
570 curl_easy_setopt(db->curl, CURLOPT_WRITEDATA, db);
571 curl_easy_setopt(db->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
572 curl_easy_setopt(db->curl, CURLOPT_ERRORBUFFER, db->curl_errbuf);
573 curl_easy_setopt(db->curl, CURLOPT_URL, db->url);
574 curl_easy_setopt(db->curl, CURLOPT_FOLLOWLOCATION, 1L);
575 curl_easy_setopt(db->curl, CURLOPT_MAXREDIRS, 50L);
577 if (db->user != NULL) {
578 #ifdef HAVE_CURLOPT_USERNAME
579 curl_easy_setopt(db->curl, CURLOPT_USERNAME, db->user);
580 curl_easy_setopt(db->curl, CURLOPT_PASSWORD,
581 (db->pass == NULL) ? "" : db->pass);
583 size_t credentials_size;
585 credentials_size = strlen(db->user) + 2;
586 if (db->pass != NULL)
587 credentials_size += strlen(db->pass);
589 db->credentials = malloc(credentials_size);
590 if (db->credentials == NULL) {
591 ERROR("curl_json plugin: malloc failed.");
595 ssnprintf(db->credentials, credentials_size, "%s:%s", db->user,
596 (db->pass == NULL) ? "" : db->pass);
597 curl_easy_setopt(db->curl, CURLOPT_USERPWD, db->credentials);
601 curl_easy_setopt(db->curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
604 curl_easy_setopt(db->curl, CURLOPT_SSL_VERIFYPEER, (long)db->verify_peer);
605 curl_easy_setopt(db->curl, CURLOPT_SSL_VERIFYHOST, db->verify_host ? 2L : 0L);
606 if (db->cacert != NULL)
607 curl_easy_setopt(db->curl, CURLOPT_CAINFO, db->cacert);
608 if (db->headers != NULL)
609 curl_easy_setopt(db->curl, CURLOPT_HTTPHEADER, db->headers);
610 if (db->post_body != NULL)
611 curl_easy_setopt(db->curl, CURLOPT_POSTFIELDS, db->post_body);
613 #ifdef HAVE_CURLOPT_TIMEOUT_MS
614 if (db->timeout >= 0)
615 curl_easy_setopt(db->curl, CURLOPT_TIMEOUT_MS, (long)db->timeout);
616 else if (db->interval > 0)
617 curl_easy_setopt(db->curl, CURLOPT_TIMEOUT_MS,
618 (long)CDTIME_T_TO_MS(db->interval));
620 curl_easy_setopt(db->curl, CURLOPT_TIMEOUT_MS,
621 (long)CDTIME_T_TO_MS(plugin_get_interval()));
625 } /* }}} int cj_init_curl */
627 static int cj_config_add_url(oconfig_item_t *ci) /* {{{ */
632 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
633 WARNING("curl_json plugin: The `URL' block "
634 "needs exactly one string argument.");
638 db = calloc(1, sizeof(*db));
640 ERROR("curl_json plugin: calloc failed.");
646 if (strcasecmp("URL", ci->key) == 0)
647 status = cf_util_get_string(ci, &db->url);
648 else if (strcasecmp("Sock", ci->key) == 0)
649 status = cf_util_get_string(ci, &db->sock);
651 ERROR("curl_json plugin: cj_config: "
662 /* Fill the `cj_t' structure.. */
663 for (int i = 0; i < ci->children_num; i++) {
664 oconfig_item_t *child = ci->children + i;
666 if (strcasecmp("Instance", child->key) == 0)
667 status = cf_util_get_string(child, &db->instance);
668 else if (strcasecmp("Host", child->key) == 0)
669 status = cf_util_get_string(child, &db->host);
670 else if (db->url && strcasecmp("User", child->key) == 0)
671 status = cf_util_get_string(child, &db->user);
672 else if (db->url && strcasecmp("Password", child->key) == 0)
673 status = cf_util_get_string(child, &db->pass);
674 else if (strcasecmp("Digest", child->key) == 0)
675 status = cf_util_get_boolean(child, &db->digest);
676 else if (db->url && strcasecmp("VerifyPeer", child->key) == 0)
677 status = cf_util_get_boolean(child, &db->verify_peer);
678 else if (db->url && strcasecmp("VerifyHost", child->key) == 0)
679 status = cf_util_get_boolean(child, &db->verify_host);
680 else if (db->url && strcasecmp("CACert", child->key) == 0)
681 status = cf_util_get_string(child, &db->cacert);
682 else if (db->url && strcasecmp("Header", child->key) == 0)
683 status = cj_config_append_string("Header", &db->headers, child);
684 else if (db->url && strcasecmp("Post", child->key) == 0)
685 status = cf_util_get_string(child, &db->post_body);
686 else if (strcasecmp("Key", child->key) == 0)
687 status = cj_config_add_key(db, child);
688 else if (strcasecmp("Interval", child->key) == 0)
689 status = cf_util_get_cdtime(child, &db->interval);
690 else if (strcasecmp("Timeout", child->key) == 0)
691 status = cf_util_get_int(child, &db->timeout);
692 else if (strcasecmp("Statistics", child->key) == 0) {
693 db->stats = curl_stats_from_config(child);
694 if (db->stats == NULL)
697 WARNING("curl_json plugin: Option `%s' not allowed here.", child->key);
706 if (db->tree == NULL) {
707 WARNING("curl_json plugin: No (valid) `Key' block within `%s' \"`%s'\".",
708 db->url ? "URL" : "Sock", db->url ? db->url : db->sock);
711 if (status == 0 && db->url)
712 status = cj_init_curl(db);
715 /* If all went well, register this database for reading */
719 if (db->instance == NULL)
720 db->instance = strdup("default");
722 DEBUG("curl_json plugin: Registering new read callback: %s", db->instance);
724 cb_name = ssnprintf_alloc("curl_json-%s-%s", db->instance,
725 db->url ? db->url : db->sock);
727 plugin_register_complex_read(/* group = */ NULL, cb_name, cj_read,
728 /* interval = */ db->interval,
730 .data = db, .free_func = cj_free,
740 /* }}} int cj_config_add_database */
742 static int cj_config(oconfig_item_t *ci) /* {{{ */
751 for (int i = 0; i < ci->children_num; i++) {
752 oconfig_item_t *child = ci->children + i;
754 if (strcasecmp("Sock", child->key) == 0 ||
755 strcasecmp("URL", child->key) == 0) {
756 status = cj_config_add_url(child);
762 WARNING("curl_json plugin: Option `%s' not allowed here.", child->key);
767 if ((success == 0) && (errors > 0)) {
768 ERROR("curl_json plugin: All statements failed.");
773 } /* }}} int cj_config */
775 /* }}} End of configuration handling functions */
777 static const char *cj_host(cj_t *db) /* {{{ */
779 if ((db->host == NULL) || (strcmp("", db->host) == 0) ||
780 (strcmp(CJ_DEFAULT_HOST, db->host) == 0))
785 static void cj_submit_impl(cj_t *db, cj_key_t *key, value_t *value) /* {{{ */
787 value_list_t vl = VALUE_LIST_INIT;
792 if (key->instance == NULL) {
794 for (int i = 0; i < db->depth; i++)
795 len += ssnprintf(vl.type_instance + len, sizeof(vl.type_instance) - len,
796 i ? "-%s" : "%s", db->state[i + 1].name);
798 sstrncpy(vl.type_instance, key->instance, sizeof(vl.type_instance));
800 sstrncpy(vl.host, cj_host(db), sizeof(vl.host));
801 sstrncpy(vl.plugin, "curl_json", sizeof(vl.plugin));
802 sstrncpy(vl.plugin_instance, db->instance, sizeof(vl.plugin_instance));
803 sstrncpy(vl.type, key->type, sizeof(vl.type));
805 if (db->interval > 0)
806 vl.interval = db->interval;
808 plugin_dispatch_values(&vl);
809 } /* }}} int cj_submit_impl */
811 static int cj_sock_perform(cj_t *db) /* {{{ */
814 struct sockaddr_un sa_unix = {
815 .sun_family = AF_UNIX,
817 sstrncpy(sa_unix.sun_path, db->sock, sizeof(sa_unix.sun_path));
819 int fd = socket(AF_UNIX, SOCK_STREAM, 0);
822 if (connect(fd, (struct sockaddr *)&sa_unix, sizeof(sa_unix)) < 0) {
823 ERROR("curl_json plugin: connect(%s) failed: %s",
824 (db->sock != NULL) ? db->sock : "<null>",
825 sstrerror(errno, errbuf, sizeof(errbuf)));
832 unsigned char buffer[4096];
833 red = read(fd, buffer, sizeof(buffer));
835 ERROR("curl_json plugin: read(%s) failed: %s",
836 (db->sock != NULL) ? db->sock : "<null>",
837 sstrerror(errno, errbuf, sizeof(errbuf)));
841 if (!cj_curl_callback(buffer, red, 1, db))
846 } /* }}} int cj_sock_perform */
848 static int cj_curl_perform(cj_t *db) /* {{{ */
855 status = curl_easy_perform(db->curl);
856 if (status != CURLE_OK) {
857 ERROR("curl_json plugin: curl_easy_perform failed with status %i: %s (%s)",
858 status, db->curl_errbuf, url);
861 if (db->stats != NULL)
862 curl_stats_dispatch(db->stats, db->curl, cj_host(db), "curl_json",
865 curl_easy_getinfo(db->curl, CURLINFO_EFFECTIVE_URL, &url);
866 curl_easy_getinfo(db->curl, CURLINFO_RESPONSE_CODE, &rc);
868 /* The response code is zero if a non-HTTP transport was used. */
869 if ((rc != 0) && (rc != 200)) {
870 ERROR("curl_json plugin: curl_easy_perform failed with "
871 "response code %ld (%s)",
876 } /* }}} int cj_curl_perform */
878 static int cj_perform(cj_t *db) /* {{{ */
881 yajl_handle yprev = db->yajl;
883 db->yajl = yajl_alloc(&ycallbacks,
885 /* alloc funcs = */ NULL,
887 /* alloc funcs = */ NULL, NULL,
889 /* context = */ (void *)db);
890 if (db->yajl == NULL) {
891 ERROR("curl_json plugin: yajl_alloc failed.");
897 status = cj_curl_perform(db);
899 status = cj_sock_perform(db);
907 status = yajl_complete_parse(db->yajl);
909 status = yajl_parse_complete(db->yajl);
911 if (status != yajl_status_ok) {
912 unsigned char *errmsg;
914 errmsg = yajl_get_error(db->yajl, /* verbose = */ 0,
915 /* jsonText = */ NULL, /* jsonTextLen = */ 0);
916 ERROR("curl_json plugin: yajl_parse_complete failed: %s", (char *)errmsg);
917 yajl_free_error(db->yajl, errmsg);
926 } /* }}} int cj_perform */
928 static int cj_read(user_data_t *ud) /* {{{ */
932 if ((ud == NULL) || (ud->data == NULL)) {
933 ERROR("curl_json plugin: cj_read: Invalid user data.");
937 db = (cj_t *)ud->data;
940 memset(&db->state, 0, sizeof(db->state));
941 db->state[db->depth].tree = db->tree;
943 return cj_perform(db);
944 } /* }}} int cj_read */
946 static int cj_init(void) /* {{{ */
948 /* Call this while collectd is still single-threaded to avoid
949 * initialization issues in libgcrypt. */
950 curl_global_init(CURL_GLOBAL_SSL);
952 } /* }}} int cj_init */
954 void module_register(void) {
955 plugin_register_complex_config("curl_json", cj_config);
956 plugin_register_init("curl_json", cj_init);
957 } /* void module_register */