From 39a1828548656b7f1fe486d48b8a08bf475277f1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20Kundr=C3=A1t?= Date: Wed, 25 Mar 2015 18:06:50 +0100 Subject: [PATCH] curl_json: Add support for specifying a connection timeout There's apparently no need to init the config values in the `db` struct; memset() is used earlier in the process. This patch doesn't change this convention. --- src/collectd.conf.pod | 1 + src/curl_json.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 788ffd45..6b76c911 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -1562,6 +1562,7 @@ URL. By default the global B setting will be used. =item B
I
=item B I +=item B I These options behave exactly equivalent to the appropriate options of the I plugin. Please see there for a detailed description. diff --git a/src/curl_json.c b/src/curl_json.c index 09db7866..4cd4aec9 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -78,6 +78,7 @@ struct cj_s /* {{{ */ struct curl_slist *headers; char *post_body; cdtime_t interval; + int timeout; CURL *curl; char curl_errbuf[CURL_ERROR_SIZE]; @@ -649,6 +650,10 @@ static int cj_init_curl (cj_t *db) /* {{{ */ curl_easy_setopt (db->curl, CURLOPT_HTTPHEADER, db->headers); if (db->post_body != NULL) curl_easy_setopt (db->curl, CURLOPT_POSTFIELDS, db->post_body); + curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, + db->timeout > 0 ? + db->timeout : + ( db->interval > 0 ? db->interval : cf_get_default_interval () )); return (0); } /* }}} int cj_init_curl */ @@ -720,6 +725,8 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */ status = cj_config_add_key (db, child); else if (strcasecmp ("Interval", child->key) == 0) status = cf_util_get_cdtime(child, &db->interval); + else if (strcasecmp ("Timeout", child->key) == 0) + status = cf_util_get_int (child, &db->timeout); else { WARNING ("curl_json plugin: Option `%s' not allowed here.", child->key); -- 2.30.2