Code

collectd.conf(5): Document the per-plugin interval configuration.
[collectd.git] / src / curl_json.c
index 988ed58df3442459d23ef25b20894df6f82ae21e..3f77b7e1f04c39609b6b1874df104dfdd506b4f4 100644 (file)
@@ -621,6 +621,7 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */
   {
     user_data_t ud;
     char cb_name[DATA_MAX_NAME_LEN];
+    struct timespec cb_interval;
 
     if (db->instance == NULL)
       db->instance = strdup("default");
@@ -635,8 +636,14 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */
     ssnprintf (cb_name, sizeof (cb_name), "curl_json-%s-%s",
                db->instance, db->url);
 
-    plugin_register_complex_read (/* group = */ NULL, cb_name, cj_read,
-                                  /* interval = */ NULL, &ud);
+    CDTIME_T_TO_TIMESPEC (plugin_interval, &cb_interval);
+
+    plugin_register_complex_read (/* group = */ NULL,
+                                  /* name = */ cb_name,
+                                  /* callback = */ cj_read,
+                                  /* interval = */ (plugin_interval != 0)
+                                    ? &cb_interval : NULL,
+                                  /* user_data = */ &ud);
   }
   else
   {
@@ -690,7 +697,7 @@ static int cj_config (oconfig_item_t *ci) /* {{{ */
 
 static void cj_submit (cj_t *db, cj_key_t *key, value_t *value) /* {{{ */
 {
-  value_list_t vl = VALUE_LIST_INIT;
+  value_list_t vl = VALUE_LIST_INIT (plugin_interval);
   char *host;
 
   vl.values     = value;
@@ -763,7 +770,11 @@ static int cj_curl_perform (cj_t *db, CURL *curl) /* {{{ */
     return (-1);
   }
 
-  status = yajl_parse_complete (db->yajl);
+#if HAVE_YAJL_V2
+    status = yajl_complete_parse(db->yajl);
+#else
+    status = yajl_parse_complete(db->yajl);
+#endif
   if (status != yajl_status_ok)
   {
     unsigned char *errmsg;
@@ -803,8 +814,9 @@ static int cj_read (user_data_t *ud) /* {{{ */
   return cj_curl_perform (db, db->curl);
 } /* }}} int cj_read */
 
-void module_register (void)
+void module_register (plugin_loaddata_t *data)
 {
+  PLUGIN_INIT_INTERVAL (data);
   plugin_register_complex_config ("curl_json", cj_config);
 } /* void module_register */