X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcurl_json.c;h=3a5a3ab87d7bd0a8320e88e5de5c4d08947d6222;hb=f87af5a58fa6a51d0268e47a0e55988db692a372;hp=09db7866fa8bdbc3465184c6820e38e3a94ee868;hpb=4c88746c9a916eb93f2ea4a2d83edd803b7ec06c;p=collectd.git diff --git a/src/curl_json.c b/src/curl_json.c index 09db7866..3a5a3ab8 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]; @@ -650,6 +651,17 @@ static int cj_init_curl (cj_t *db) /* {{{ */ if (db->post_body != NULL) curl_easy_setopt (db->curl, CURLOPT_POSTFIELDS, db->post_body); +#ifdef HAVE_CURLOPT_TIMEOUT_MS + if (db->timeout >= 0) + curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, (long) db->timeout); + else if (db->interval > 0) + curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, + CDTIME_T_TO_MS(db->timeout)); + else + curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, + CDTIME_T_TO_MS(plugin_get_interval())); +#endif + return (0); } /* }}} int cj_init_curl */ @@ -675,6 +687,8 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */ } memset (db, 0, sizeof (*db)); + db->timeout = -1; + if (strcasecmp ("URL", ci->key) == 0) status = cf_util_get_string (ci, &db->url); else if (strcasecmp ("Sock", ci->key) == 0) @@ -720,6 +734,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);