From 4b0440039f4f3cf47346de666ac775dfb3c74e9b Mon Sep 17 00:00:00 2001 From: Marc Fournier Date: Sat, 4 Apr 2015 22:29:22 +0200 Subject: [PATCH] ascent: Add support for specifying a connection timeout --- src/ascent.c | 12 +++++++++++- src/collectd.conf.pod | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ascent.c b/src/ascent.c index e9d25bd5..66640d99 100644 --- a/src/ascent.c +++ b/src/ascent.c @@ -102,6 +102,7 @@ static char *pass = NULL; static char *verify_peer = NULL; static char *verify_host = NULL; static char *cacert = NULL; +static char *timeout = NULL; static CURL *curl = NULL; @@ -117,7 +118,8 @@ static const char *config_keys[] = "Password", "VerifyPeer", "VerifyHost", - "CACert" + "CACert", + "Timeout", }; static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); @@ -518,6 +520,8 @@ static int ascent_config (const char *key, const char *value) /* {{{ */ return (config_set (&verify_host, value)); else if (strcasecmp (key, "CACert") == 0) return (config_set (&cacert, value)); + else if (strcasecmp (key, "Timeout") == 0) + return (config_set (&timeout, value)); else return (-1); } /* }}} int ascent_config */ @@ -586,6 +590,12 @@ static int ascent_init (void) /* {{{ */ if (cacert != NULL) curl_easy_setopt (curl, CURLOPT_CAINFO, cacert); + if (timeout != NULL) + curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, atoi(timeout)); + else + curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, + CDTIME_T_TO_MS(plugin_get_interval())); + return (0); } /* }}} int ascent_init */ diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 991a8032..25bb25a4 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -869,6 +869,12 @@ File that holds one or more SSL certificates. If you want to use HTTPS you will possibly need this option. What CA certificates come bundled with C and are checked by default depends on the distribution you use. +=item B I + +The B option sets the overall timeout for HTTP requests, in +milliseconds. By default, the configured B is used to set the +timeout. + =back =head2 Plugin C -- 2.30.2