2 * collectd - src/write_http.c
3 * Copyright (C) 2009 Paul Sadauskas
4 * Copyright (C) 2009 Doug MacEachern
5 * Copyright (C) 2007-2014 Florian octo Forster
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; only version 2 of the License is applicable.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 * Florian octo Forster <octo at collectd.org>
22 * Doug MacEachern <dougm@hyperic.com>
23 * Paul Sadauskas <psadauskas@gmail.com>
30 #include "utils_format_json.h"
31 #include "utils_format_kairosdb.h"
33 #include <curl/curl.h>
35 #ifndef WRITE_HTTP_DEFAULT_BUFFER_SIZE
36 #define WRITE_HTTP_DEFAULT_BUFFER_SIZE 4096
42 struct wh_callback_s {
60 time_t low_speed_time;
63 #define WH_FORMAT_COMMAND 0
64 #define WH_FORMAT_JSON 1
65 #define WH_FORMAT_KAIROSDB 2
68 _Bool send_notifications;
71 struct curl_slist *headers;
72 char curl_errbuf[CURL_ERROR_SIZE];
75 size_t send_buffer_size;
76 size_t send_buffer_free;
77 size_t send_buffer_fill;
78 cdtime_t send_buffer_init_time;
80 pthread_mutex_t send_lock;
84 typedef struct wh_callback_s wh_callback_t;
86 static char **http_attrs;
87 static size_t http_attrs_num;
89 static void wh_log_http_error(wh_callback_t *cb) {
90 if (!cb->log_http_error)
95 curl_easy_getinfo(cb->curl, CURLINFO_RESPONSE_CODE, &http_code);
98 INFO("write_http plugin: HTTP Error code: %lu", http_code);
101 static void wh_reset_buffer(wh_callback_t *cb) /* {{{ */
103 if ((cb == NULL) || (cb->send_buffer == NULL))
106 memset(cb->send_buffer, 0, cb->send_buffer_size);
107 cb->send_buffer_free = cb->send_buffer_size;
108 cb->send_buffer_fill = 0;
109 cb->send_buffer_init_time = cdtime();
111 if (cb->format == WH_FORMAT_JSON || cb->format == WH_FORMAT_KAIROSDB) {
112 format_json_initialize(cb->send_buffer, &cb->send_buffer_fill,
113 &cb->send_buffer_free);
115 } /* }}} wh_reset_buffer */
117 /* must hold cb->send_lock when calling */
118 static int wh_post_nolock(wh_callback_t *cb, char const *data) /* {{{ */
122 curl_easy_setopt(cb->curl, CURLOPT_URL, cb->location);
123 curl_easy_setopt(cb->curl, CURLOPT_POSTFIELDS, data);
124 status = curl_easy_perform(cb->curl);
126 wh_log_http_error(cb);
128 if (status != CURLE_OK) {
129 ERROR("write_http plugin: curl_easy_perform failed with "
131 status, cb->curl_errbuf);
134 } /* }}} wh_post_nolock */
136 static int wh_callback_init(wh_callback_t *cb) /* {{{ */
138 if (cb->curl != NULL)
141 cb->curl = curl_easy_init();
142 if (cb->curl == NULL) {
143 ERROR("curl plugin: curl_easy_init failed.");
147 if (cb->low_speed_limit > 0 && cb->low_speed_time > 0) {
148 curl_easy_setopt(cb->curl, CURLOPT_LOW_SPEED_LIMIT,
149 (long)(cb->low_speed_limit * cb->low_speed_time));
150 curl_easy_setopt(cb->curl, CURLOPT_LOW_SPEED_TIME,
151 (long)cb->low_speed_time);
154 #ifdef HAVE_CURLOPT_TIMEOUT_MS
156 curl_easy_setopt(cb->curl, CURLOPT_TIMEOUT_MS, (long)cb->timeout);
159 curl_easy_setopt(cb->curl, CURLOPT_NOSIGNAL, 1L);
160 curl_easy_setopt(cb->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
162 cb->headers = curl_slist_append(cb->headers, "Accept: */*");
163 if (cb->format == WH_FORMAT_JSON || cb->format == WH_FORMAT_KAIROSDB)
165 curl_slist_append(cb->headers, "Content-Type: application/json");
167 cb->headers = curl_slist_append(cb->headers, "Content-Type: text/plain");
168 cb->headers = curl_slist_append(cb->headers, "Expect:");
169 curl_easy_setopt(cb->curl, CURLOPT_HTTPHEADER, cb->headers);
171 curl_easy_setopt(cb->curl, CURLOPT_ERRORBUFFER, cb->curl_errbuf);
172 curl_easy_setopt(cb->curl, CURLOPT_FOLLOWLOCATION, 1L);
173 curl_easy_setopt(cb->curl, CURLOPT_MAXREDIRS, 50L);
175 if (cb->user != NULL) {
176 #ifdef HAVE_CURLOPT_USERNAME
177 curl_easy_setopt(cb->curl, CURLOPT_USERNAME, cb->user);
178 curl_easy_setopt(cb->curl, CURLOPT_PASSWORD,
179 (cb->pass == NULL) ? "" : cb->pass);
181 size_t credentials_size;
183 credentials_size = strlen(cb->user) + 2;
184 if (cb->pass != NULL)
185 credentials_size += strlen(cb->pass);
187 cb->credentials = malloc(credentials_size);
188 if (cb->credentials == NULL) {
189 ERROR("curl plugin: malloc failed.");
193 snprintf(cb->credentials, credentials_size, "%s:%s", cb->user,
194 (cb->pass == NULL) ? "" : cb->pass);
195 curl_easy_setopt(cb->curl, CURLOPT_USERPWD, cb->credentials);
197 curl_easy_setopt(cb->curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
200 curl_easy_setopt(cb->curl, CURLOPT_SSL_VERIFYPEER, (long)cb->verify_peer);
201 curl_easy_setopt(cb->curl, CURLOPT_SSL_VERIFYHOST, cb->verify_host ? 2L : 0L);
202 curl_easy_setopt(cb->curl, CURLOPT_SSLVERSION, cb->sslversion);
203 if (cb->cacert != NULL)
204 curl_easy_setopt(cb->curl, CURLOPT_CAINFO, cb->cacert);
205 if (cb->capath != NULL)
206 curl_easy_setopt(cb->curl, CURLOPT_CAPATH, cb->capath);
208 if (cb->clientkey != NULL && cb->clientcert != NULL) {
209 curl_easy_setopt(cb->curl, CURLOPT_SSLKEY, cb->clientkey);
210 curl_easy_setopt(cb->curl, CURLOPT_SSLCERT, cb->clientcert);
212 if (cb->clientkeypass != NULL)
213 curl_easy_setopt(cb->curl, CURLOPT_SSLKEYPASSWD, cb->clientkeypass);
219 } /* }}} int wh_callback_init */
221 static int wh_flush_nolock(cdtime_t timeout, wh_callback_t *cb) /* {{{ */
225 DEBUG("write_http plugin: wh_flush_nolock: timeout = %.3f; "
226 "send_buffer_fill = %zu;",
227 CDTIME_T_TO_DOUBLE(timeout), cb->send_buffer_fill);
229 /* timeout == 0 => flush unconditionally */
234 if ((cb->send_buffer_init_time + timeout) > now)
238 if (cb->format == WH_FORMAT_COMMAND) {
239 if (cb->send_buffer_fill == 0) {
240 cb->send_buffer_init_time = cdtime();
244 status = wh_post_nolock(cb, cb->send_buffer);
246 } else if (cb->format == WH_FORMAT_JSON || cb->format == WH_FORMAT_KAIROSDB) {
247 if (cb->send_buffer_fill <= 2) {
248 cb->send_buffer_init_time = cdtime();
252 status = format_json_finalize(cb->send_buffer, &cb->send_buffer_fill,
253 &cb->send_buffer_free);
255 ERROR("write_http: wh_flush_nolock: "
256 "format_json_finalize failed.");
261 status = wh_post_nolock(cb, cb->send_buffer);
264 ERROR("write_http: wh_flush_nolock: "
265 "Unknown format: %i",
271 } /* }}} wh_flush_nolock */
273 static int wh_flush(cdtime_t timeout, /* {{{ */
274 const char *identifier __attribute__((unused)),
275 user_data_t *user_data) {
279 if (user_data == NULL)
282 cb = user_data->data;
284 pthread_mutex_lock(&cb->send_lock);
286 if (wh_callback_init(cb) != 0) {
287 ERROR("write_http plugin: wh_callback_init failed.");
288 pthread_mutex_unlock(&cb->send_lock);
292 status = wh_flush_nolock(timeout, cb);
293 pthread_mutex_unlock(&cb->send_lock);
296 } /* }}} int wh_flush */
298 static void wh_callback_free(void *data) /* {{{ */
307 if (cb->send_buffer != NULL)
308 wh_flush_nolock(/* timeout = */ 0, cb);
310 if (cb->curl != NULL) {
311 curl_easy_cleanup(cb->curl);
315 if (cb->headers != NULL) {
316 curl_slist_free_all(cb->headers);
324 sfree(cb->credentials);
327 sfree(cb->clientkey);
328 sfree(cb->clientcert);
329 sfree(cb->clientkeypass);
330 sfree(cb->send_buffer);
333 } /* }}} void wh_callback_free */
335 static int wh_write_command(const data_set_t *ds,
336 const value_list_t *vl, /* {{{ */
338 char key[10 * DATA_MAX_NAME_LEN];
345 /* sanity checks, primarily to make static analyzers happy. */
346 if ((cb == NULL) || (cb->send_buffer == NULL))
349 if (strcmp(ds->type, vl->type) != 0) {
350 ERROR("write_http plugin: DS type does not match "
355 /* Copy the identifier to `key' and escape it. */
356 status = FORMAT_VL(key, sizeof(key), vl);
358 ERROR("write_http plugin: error with format_name");
361 escape_string(key, sizeof(key));
363 /* Convert the values to an ASCII representation and put that into
365 status = format_values(values, sizeof(values), ds, vl, cb->store_rates);
367 ERROR("write_http plugin: error with "
368 "wh_value_list_to_string");
372 command_len = (size_t)snprintf(command, sizeof(command),
373 "PUTVAL %s interval=%.3f %s\r\n", key,
374 CDTIME_T_TO_DOUBLE(vl->interval), values);
375 if (command_len >= sizeof(command)) {
376 ERROR("write_http plugin: Command buffer too small: "
382 pthread_mutex_lock(&cb->send_lock);
383 if (wh_callback_init(cb) != 0) {
384 ERROR("write_http plugin: wh_callback_init failed.");
385 pthread_mutex_unlock(&cb->send_lock);
389 if (command_len >= cb->send_buffer_free) {
390 status = wh_flush_nolock(/* timeout = */ 0, cb);
392 pthread_mutex_unlock(&cb->send_lock);
396 assert(command_len < cb->send_buffer_free);
398 /* Make scan-build happy. */
399 assert(cb->send_buffer != NULL);
401 /* `command_len + 1' because `command_len' does not include the
402 * trailing null byte. Neither does `send_buffer_fill'. */
403 memcpy(cb->send_buffer + cb->send_buffer_fill, command, command_len + 1);
404 cb->send_buffer_fill += command_len;
405 cb->send_buffer_free -= command_len;
407 DEBUG("write_http plugin: <%s> buffer %zu/%zu (%g%%) \"%s\"", cb->location,
408 cb->send_buffer_fill, cb->send_buffer_size,
409 100.0 * ((double)cb->send_buffer_fill) / ((double)cb->send_buffer_size),
412 /* Check if we have enough space for this command. */
413 pthread_mutex_unlock(&cb->send_lock);
416 } /* }}} int wh_write_command */
418 static int wh_write_json(const data_set_t *ds, const value_list_t *vl, /* {{{ */
422 pthread_mutex_lock(&cb->send_lock);
423 if (wh_callback_init(cb) != 0) {
424 ERROR("write_http plugin: wh_callback_init failed.");
425 pthread_mutex_unlock(&cb->send_lock);
430 format_json_value_list(cb->send_buffer, &cb->send_buffer_fill,
431 &cb->send_buffer_free, ds, vl, cb->store_rates);
432 if (status == -ENOMEM) {
433 status = wh_flush_nolock(/* timeout = */ 0, cb);
436 pthread_mutex_unlock(&cb->send_lock);
441 format_json_value_list(cb->send_buffer, &cb->send_buffer_fill,
442 &cb->send_buffer_free, ds, vl, cb->store_rates);
445 pthread_mutex_unlock(&cb->send_lock);
449 DEBUG("write_http plugin: <%s> buffer %zu/%zu (%g%%)", cb->location,
450 cb->send_buffer_fill, cb->send_buffer_size,
451 100.0 * ((double)cb->send_buffer_fill) /
452 ((double)cb->send_buffer_size));
454 /* Check if we have enough space for this command. */
455 pthread_mutex_unlock(&cb->send_lock);
458 } /* }}} int wh_write_json */
460 static int wh_write_kairosdb(const data_set_t *ds,
461 const value_list_t *vl, /* {{{ */
465 pthread_mutex_lock(&cb->send_lock);
467 if (cb->curl == NULL) {
468 status = wh_callback_init(cb);
470 ERROR("write_http plugin: wh_callback_init failed.");
471 pthread_mutex_unlock(&cb->send_lock);
476 status = format_kairosdb_value_list(
477 cb->send_buffer, &cb->send_buffer_fill, &cb->send_buffer_free, ds, vl,
478 cb->store_rates, (char const *const *)http_attrs, http_attrs_num,
480 if (status == -ENOMEM) {
481 status = wh_flush_nolock(/* timeout = */ 0, cb);
484 pthread_mutex_unlock(&cb->send_lock);
488 status = format_kairosdb_value_list(
489 cb->send_buffer, &cb->send_buffer_fill, &cb->send_buffer_free, ds, vl,
490 cb->store_rates, (char const *const *)http_attrs, http_attrs_num,
494 pthread_mutex_unlock(&cb->send_lock);
498 DEBUG("write_http plugin: <%s> buffer %zu/%zu (%g%%)", cb->location,
499 cb->send_buffer_fill, cb->send_buffer_size,
500 100.0 * ((double)cb->send_buffer_fill) /
501 ((double)cb->send_buffer_size));
503 /* Check if we have enough space for this command. */
504 pthread_mutex_unlock(&cb->send_lock);
507 } /* }}} int wh_write_kairosdb */
509 static int wh_write(const data_set_t *ds, const value_list_t *vl, /* {{{ */
510 user_data_t *user_data) {
514 if (user_data == NULL)
517 cb = user_data->data;
518 assert(cb->send_metrics);
520 switch (cb->format) {
522 status = wh_write_json(ds, vl, cb);
524 case WH_FORMAT_KAIROSDB:
525 status = wh_write_kairosdb(ds, vl, cb);
528 status = wh_write_command(ds, vl, cb);
532 } /* }}} int wh_write */
534 static int wh_notify(notification_t const *n, user_data_t *ud) /* {{{ */
540 if ((ud == NULL) || (ud->data == NULL))
544 assert(cb->send_notifications);
546 status = format_json_notification(alert, sizeof(alert), n);
548 ERROR("write_http plugin: formatting notification failed");
552 pthread_mutex_lock(&cb->send_lock);
553 if (wh_callback_init(cb) != 0) {
554 ERROR("write_http plugin: wh_callback_init failed.");
555 pthread_mutex_unlock(&cb->send_lock);
559 status = wh_post_nolock(cb, alert);
560 pthread_mutex_unlock(&cb->send_lock);
563 } /* }}} int wh_notify */
565 static int config_set_format(wh_callback_t *cb, /* {{{ */
566 oconfig_item_t *ci) {
569 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
570 WARNING("write_http plugin: The `%s' config option "
571 "needs exactly one string argument.",
576 string = ci->values[0].value.string;
577 if (strcasecmp("Command", string) == 0)
578 cb->format = WH_FORMAT_COMMAND;
579 else if (strcasecmp("JSON", string) == 0)
580 cb->format = WH_FORMAT_JSON;
581 else if (strcasecmp("KAIROSDB", string) == 0)
582 cb->format = WH_FORMAT_KAIROSDB;
584 ERROR("write_http plugin: Invalid format string: %s", string);
589 } /* }}} int config_set_format */
591 static int wh_config_append_string(const char *name,
592 struct curl_slist **dest, /* {{{ */
593 oconfig_item_t *ci) {
594 struct curl_slist *temp = NULL;
595 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
596 WARNING("write_http plugin: `%s' needs exactly one string argument.", name);
600 temp = curl_slist_append(*dest, ci->values[0].value.string);
607 } /* }}} int wh_config_append_string */
609 static int wh_config_node(oconfig_item_t *ci) /* {{{ */
613 char callback_name[DATA_MAX_NAME_LEN];
616 cb = calloc(1, sizeof(*cb));
618 ERROR("write_http plugin: calloc failed.");
623 cb->format = WH_FORMAT_COMMAND;
624 cb->sslversion = CURL_SSLVERSION_DEFAULT;
625 cb->low_speed_limit = 0;
627 cb->log_http_error = 0;
629 cb->send_metrics = 1;
630 cb->send_notifications = 0;
633 pthread_mutex_init(&cb->send_lock, /* attr = */ NULL);
635 cf_util_get_string(ci, &cb->name);
637 /* FIXME: Remove this legacy mode in version 6. */
638 if (strcasecmp("URL", ci->key) == 0)
639 cf_util_get_string(ci, &cb->location);
641 for (int i = 0; i < ci->children_num; i++) {
642 oconfig_item_t *child = ci->children + i;
644 if (strcasecmp("URL", child->key) == 0)
645 status = cf_util_get_string(child, &cb->location);
646 else if (strcasecmp("User", child->key) == 0)
647 status = cf_util_get_string(child, &cb->user);
648 else if (strcasecmp("Password", child->key) == 0)
649 status = cf_util_get_string(child, &cb->pass);
650 else if (strcasecmp("VerifyPeer", child->key) == 0)
651 status = cf_util_get_boolean(child, &cb->verify_peer);
652 else if (strcasecmp("VerifyHost", child->key) == 0)
653 status = cf_util_get_boolean(child, &cb->verify_host);
654 else if (strcasecmp("CACert", child->key) == 0)
655 status = cf_util_get_string(child, &cb->cacert);
656 else if (strcasecmp("CAPath", child->key) == 0)
657 status = cf_util_get_string(child, &cb->capath);
658 else if (strcasecmp("ClientKey", child->key) == 0)
659 status = cf_util_get_string(child, &cb->clientkey);
660 else if (strcasecmp("ClientCert", child->key) == 0)
661 status = cf_util_get_string(child, &cb->clientcert);
662 else if (strcasecmp("ClientKeyPass", child->key) == 0)
663 status = cf_util_get_string(child, &cb->clientkeypass);
664 else if (strcasecmp("SSLVersion", child->key) == 0) {
667 status = cf_util_get_string(child, &value);
671 if (value == NULL || strcasecmp("default", value) == 0)
672 cb->sslversion = CURL_SSLVERSION_DEFAULT;
673 else if (strcasecmp("SSLv2", value) == 0)
674 cb->sslversion = CURL_SSLVERSION_SSLv2;
675 else if (strcasecmp("SSLv3", value) == 0)
676 cb->sslversion = CURL_SSLVERSION_SSLv3;
677 else if (strcasecmp("TLSv1", value) == 0)
678 cb->sslversion = CURL_SSLVERSION_TLSv1;
679 #if (LIBCURL_VERSION_MAJOR > 7) || \
680 (LIBCURL_VERSION_MAJOR == 7 && LIBCURL_VERSION_MINOR >= 34)
681 else if (strcasecmp("TLSv1_0", value) == 0)
682 cb->sslversion = CURL_SSLVERSION_TLSv1_0;
683 else if (strcasecmp("TLSv1_1", value) == 0)
684 cb->sslversion = CURL_SSLVERSION_TLSv1_1;
685 else if (strcasecmp("TLSv1_2", value) == 0)
686 cb->sslversion = CURL_SSLVERSION_TLSv1_2;
689 ERROR("write_http plugin: Invalid SSLVersion "
696 } else if (strcasecmp("Format", child->key) == 0)
697 status = config_set_format(cb, child);
698 else if (strcasecmp("Metrics", child->key) == 0)
699 cf_util_get_boolean(child, &cb->send_metrics);
700 else if (strcasecmp("Notifications", child->key) == 0)
701 cf_util_get_boolean(child, &cb->send_notifications);
702 else if (strcasecmp("StoreRates", child->key) == 0)
703 status = cf_util_get_boolean(child, &cb->store_rates);
704 else if (strcasecmp("BufferSize", child->key) == 0)
705 status = cf_util_get_int(child, &buffer_size);
706 else if (strcasecmp("LowSpeedLimit", child->key) == 0)
707 status = cf_util_get_int(child, &cb->low_speed_limit);
708 else if (strcasecmp("Timeout", child->key) == 0)
709 status = cf_util_get_int(child, &cb->timeout);
710 else if (strcasecmp("LogHttpError", child->key) == 0)
711 status = cf_util_get_boolean(child, &cb->log_http_error);
712 else if (strcasecmp("Header", child->key) == 0)
713 status = wh_config_append_string("Header", &cb->headers, child);
714 else if (strcasecmp("Attribute", child->key) == 0) {
718 if (child->values_num != 2) {
719 WARNING("write_http plugin: Attribute need both a key and a value.");
722 if (child->values[0].type != OCONFIG_TYPE_STRING ||
723 child->values[1].type != OCONFIG_TYPE_STRING) {
724 WARNING("write_http plugin: Attribute needs string arguments.");
727 if ((key = strdup(child->values[0].value.string)) == NULL) {
728 WARNING("cannot allocate memory for attribute key.");
731 if ((val = strdup(child->values[1].value.string)) == NULL) {
732 WARNING("cannot allocate memory for attribute value.");
736 strarray_add(&http_attrs, &http_attrs_num, key);
737 strarray_add(&http_attrs, &http_attrs_num, val);
738 DEBUG("write_http plugin: got attribute: %s => %s", key, val);
741 } else if (strcasecmp("TTL", child->key) == 0) {
742 status = cf_util_get_int(child, &cb->data_ttl);
744 ERROR("write_http plugin: Invalid configuration "
755 wh_callback_free(cb);
759 if (cb->location == NULL) {
760 ERROR("write_http plugin: no URL defined for instance '%s'", cb->name);
761 wh_callback_free(cb);
765 if (!cb->send_metrics && !cb->send_notifications) {
766 ERROR("write_http plugin: Neither metrics nor notifications "
767 "are enabled for \"%s\".",
769 wh_callback_free(cb);
773 if (cb->low_speed_limit > 0)
774 cb->low_speed_time = CDTIME_T_TO_TIME_T(plugin_get_interval());
776 /* Determine send_buffer_size. */
777 cb->send_buffer_size = WRITE_HTTP_DEFAULT_BUFFER_SIZE;
778 if (buffer_size >= 1024)
779 cb->send_buffer_size = (size_t)buffer_size;
780 else if (buffer_size != 0)
781 ERROR("write_http plugin: Ignoring invalid BufferSize setting (%d).",
784 /* Allocate the buffer. */
785 cb->send_buffer = malloc(cb->send_buffer_size);
786 if (cb->send_buffer == NULL) {
787 ERROR("write_http plugin: malloc(%zu) failed.", cb->send_buffer_size);
788 wh_callback_free(cb);
791 /* Nulls the buffer and sets ..._free and ..._fill. */
794 snprintf(callback_name, sizeof(callback_name), "write_http/%s", cb->name);
795 DEBUG("write_http: Registering write callback '%s' with URL '%s'",
796 callback_name, cb->location);
798 user_data_t user_data = {
799 .data = cb, .free_func = wh_callback_free,
802 if (cb->send_metrics) {
803 plugin_register_write(callback_name, wh_write, &user_data);
804 user_data.free_func = NULL;
806 plugin_register_flush(callback_name, wh_flush, &user_data);
809 if (cb->send_notifications) {
810 plugin_register_notification(callback_name, wh_notify, &user_data);
811 user_data.free_func = NULL;
815 } /* }}} int wh_config_node */
817 static int wh_config(oconfig_item_t *ci) /* {{{ */
819 for (int i = 0; i < ci->children_num; i++) {
820 oconfig_item_t *child = ci->children + i;
822 if (strcasecmp("Node", child->key) == 0)
823 wh_config_node(child);
824 /* FIXME: Remove this legacy mode in version 6. */
825 else if (strcasecmp("URL", child->key) == 0) {
826 WARNING("write_http plugin: Legacy <URL> block found. "
827 "Please use <Node> instead.");
828 wh_config_node(child);
830 ERROR("write_http plugin: Invalid configuration "
837 } /* }}} int wh_config */
839 static int wh_init(void) /* {{{ */
841 /* Call this while collectd is still single-threaded to avoid
842 * initialization issues in libgcrypt. */
843 curl_global_init(CURL_GLOBAL_SSL);
845 } /* }}} int wh_init */
847 void module_register(void) /* {{{ */
849 plugin_register_complex_config("write_http", wh_config);
850 plugin_register_init("write_http", wh_init);
851 } /* }}} void module_register */