struct curl_slist *headers;
char *post_body;
cdtime_t interval;
+ int timeout;
CURL *curl;
char curl_errbuf[CURL_ERROR_SIZE];
buffer[sizeof (buffer) - 1] = 0;
if ((key == NULL) || !CJ_IS_KEY (key)) {
- if (key != NULL)
+ if (key != NULL && !db->state[db->depth].in_array/*can be inhomogeneous*/)
NOTICE ("curl_json plugin: Found \"%s\", but the configuration expects"
" a map.", buffer);
- cj_cb_inc_array_index (ctx, /* update_key = */ 0);
- return (CJ_CB_CONTINUE);
- } else {
+ cj_cb_inc_array_index (ctx, /* update_key = */ 1);
+ key = db->state[db->depth].key;
+ if (key == NULL) {
+ return (CJ_CB_CONTINUE);
+ }
+ }
+ else
+ {
cj_cb_inc_array_index (ctx, /* update_key = */ 1);
}
memcpy (name, in_name, name_len);
name[name_len] = 0;
- if (c_avl_get (tree, name, (void *) &value) == 0)
- db->state[db->depth].key = value;
+ if (c_avl_get (tree, name, (void *) &value) == 0) {
+ if (CJ_IS_KEY((cj_key_t*)value)) {
+ db->state[db->depth].key = value;
+ }
+ else {
+ db->state[db->depth].tree = (c_avl_tree_t*) value;
+ }
+ }
else if (c_avl_get (tree, CJ_ANY, (void *) &value) == 0)
- db->state[db->depth].key = value;
+ if (CJ_IS_KEY((cj_key_t*)value)) {
+ db->state[db->depth].key = value;
+ }
+ else {
+ db->state[db->depth].tree = (c_avl_tree_t*) value;
+ }
else
db->state[db->depth].key = NULL;
}
curl_easy_setopt (db->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
curl_easy_setopt (db->curl, CURLOPT_ERRORBUFFER, db->curl_errbuf);
curl_easy_setopt (db->curl, CURLOPT_URL, db->url);
+ curl_easy_setopt (db->curl, CURLOPT_FOLLOWLOCATION, 1L);
+ curl_easy_setopt (db->curl, CURLOPT_MAXREDIRS, 50L);
if (db->user != NULL)
{
if (db->post_body != NULL)
curl_easy_setopt (db->curl, CURLOPT_POSTFIELDS, db->post_body);
+ if (db->timeout >= 0)
+ curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, 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()));
+
return (0);
} /* }}} int cj_init_curl */
}
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)
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);