From: Jan Kundrát Date: Sat, 21 Feb 2015 15:12:27 +0000 (+0100) Subject: curl: Add support for specifying a connection timeout X-Git-Tag: collectd-5.5.0~56^2~11 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=60bcd476c4c3f275f891e1c7ef979624fb44909c;p=collectd.git curl: Add support for specifying a connection timeout --- diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index bd781074..788ffd45 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -1469,6 +1469,14 @@ plugin below on how matches are defined. If the B or B options are set to B, B blocks are optional. +=item B I + +The B option sets the overall timeout for each request. Make sure that +collectd is configured with enough C, otherwise an overly long +timeout could block other plugins. By default or when set to B<0>, a timeout +equal to the B is used. Prior to version 5.5.0, there was no timeout +and requests might hang indefinitely. + =back =head2 Plugin C diff --git a/src/curl.c b/src/curl.c index 0e5d2cfa..50315391 100644 --- a/src/curl.c +++ b/src/curl.c @@ -66,6 +66,7 @@ struct web_page_s /* {{{ */ char *post_body; _Bool response_time; _Bool response_code; + int timeout; CURL *curl; char curl_errbuf[CURL_ERROR_SIZE]; @@ -409,6 +410,7 @@ static int cc_page_init_curl (web_page_t *wp) /* {{{ */ curl_easy_setopt (wp->curl, CURLOPT_HTTPHEADER, wp->headers); if (wp->post_body != NULL) curl_easy_setopt (wp->curl, CURLOPT_POSTFIELDS, wp->post_body); + curl_easy_setopt (wp->curl, CURLOPT_TIMEOUT_MS, wp->timeout > 0 ? wp->timeout : cf_get_default_interval ()); return (0); } /* }}} int cc_page_init_curl */ @@ -440,6 +442,7 @@ static int cc_config_add_page (oconfig_item_t *ci) /* {{{ */ page->verify_host = 1; page->response_time = 0; page->response_code = 0; + page->timeout = 0; page->instance = strdup (ci->values[0].value.string); if (page->instance == NULL) @@ -480,6 +483,8 @@ static int cc_config_add_page (oconfig_item_t *ci) /* {{{ */ status = cc_config_append_string ("Header", &page->headers, child); else if (strcasecmp ("Post", child->key) == 0) status = cf_util_get_string (child, &page->post_body); + else if (strcasecmp ("Timeout", child->key) == 0) + status = cf_util_get_int (child, &page->timeout); else { WARNING ("curl plugin: Option `%s' not allowed here.", child->key);