From: Ruben Kerkhof Date: Fri, 15 Apr 2016 18:40:11 +0000 (+0200) Subject: Merge pull request #1634 from BrandonArp/add_write_http_headers X-Git-Tag: collectd-5.6.0~349 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=ff9e11ade5cfabf32c63fb19fc76cbbc4186bc5b;hp=-c;p=collectd.git Merge pull request #1634 from BrandonArp/add_write_http_headers add http headers functionality to write_http plugin --- ff9e11ade5cfabf32c63fb19fc76cbbc4186bc5b diff --combined src/collectd.conf.pod index f99818ce,805fce4b..2da6fe40 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@@ -208,7 -208,9 +208,7 @@@ I may be specified to filter w in combination with recursively including a directory to easily be able to arbitrarily mix configuration files and other documents (e.g. README files). The given example is similar to the first example above but includes all files -matching C<*.conf> in any subdirectory of C: - - Include "/etc/collectd.d" "*.conf" +matching C<*.conf> in any subdirectory of C. =back @@@ -7575,6 -7577,12 +7575,12 @@@ authentication Password required to load the private key in B. + =item B
I
+ + A HTTP header to add to the request. Multiple headers are added if this option is specified more than once. Example: + + Header "X-Custom-Header: custom_value" + =item B B|B|B|B|B|B Define which SSL protocol version must be used. By default C will @@@ -8948,8 -8956,6 +8954,8 @@@ Available options =item B I +=item B I I + Set the appropriate field to the given string. The strings for plugin instance and type instance may be empty, the strings for host and plugin may not be empty. It's currently not possible to set the type of a value this way. diff --combined src/write_http.c index c817749f,27337813..9a405117 --- a/src/write_http.c +++ b/src/write_http.c @@@ -156,7 -156,6 +156,6 @@@ static int wh_callback_init (wh_callbac curl_easy_setopt (cb->curl, CURLOPT_NOSIGNAL, 1L); curl_easy_setopt (cb->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT); - cb->headers = NULL; cb->headers = curl_slist_append (cb->headers, "Accept: */*"); if (cb->format == WH_FORMAT_JSON) cb->headers = curl_slist_append (cb->headers, "Content-Type: application/json"); @@@ -183,7 -182,7 +182,7 @@@ if (cb->pass != NULL) credentials_size += strlen (cb->pass); - cb->credentials = (char *) malloc (credentials_size); + cb->credentials = malloc (credentials_size); if (cb->credentials == NULL) { ERROR ("curl plugin: malloc failed."); @@@ -540,6 -539,25 +539,25 @@@ static int config_set_format (wh_callba return (0); } /* }}} int config_set_format */ + static int wh_config_append_string (const char *name, struct curl_slist **dest, /* {{{ */ + oconfig_item_t *ci) + { + struct curl_slist *temp = NULL; + if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) + { + WARNING ("write_http plugin: `%s' needs exactly one string argument.", name); + return (-1); + } + + temp = curl_slist_append(*dest, ci->values[0].value.string); + if (temp == NULL) + return (-1); + + *dest = temp; + + return (0); + } /* }}} int wh_config_append_string */ + static int wh_config_node (oconfig_item_t *ci) /* {{{ */ { wh_callback_t *cb; @@@ -549,12 -567,13 +567,12 @@@ int status = 0; int i; - cb = malloc (sizeof (*cb)); + cb = calloc (1, sizeof (*cb)); if (cb == NULL) { - ERROR ("write_http plugin: malloc failed."); + ERROR ("write_http plugin: calloc failed."); return (-1); } - memset (cb, 0, sizeof (*cb)); cb->verify_peer = 1; cb->verify_host = 1; cb->format = WH_FORMAT_COMMAND; @@@ -642,6 -661,8 +660,8 @@@ status = cf_util_get_int (child, &cb->timeout); else if (strcasecmp ("LogHttpError", child->key) == 0) status = cf_util_get_boolean (child, &cb->log_http_error); + else if (strcasecmp ("Header", child->key) == 0) + status = wh_config_append_string ("Header", &cb->headers, child); else { ERROR ("write_http plugin: Invalid configuration "