summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f4c495d)
raw | patch | inline | side by side (parent: f4c495d)
author | Florian Forster <octo@collectd.org> | |
Sat, 27 Aug 2011 19:29:42 +0000 (15:29 -0400) | ||
committer | Florian Forster <octo@collectd.org> | |
Sat, 27 Aug 2011 19:32:45 +0000 (15:32 -0400) |
When the key of the parent object is empty, don't use it. The previous code led
to type instances starting with a dash, e.g. "-foo".
Also, be more verbose when unable to resolve types.
Change-Id: Ib5f55efe1acc1e819ac3189b6780a4e998bf9c9f
to type instances starting with a dash, e.g. "-foo".
Also, be more verbose when unable to resolve types.
Change-Id: Ib5f55efe1acc1e819ac3189b6780a4e998bf9c9f
src/curl_json.c | patch | blob | history |
diff --git a/src/curl_json.c b/src/curl_json.c
index 55527282ce6ff32a20da6b84062907e47234561a..968fc93c3214cf36fd08acedbdf57dc2a60a0948 100644 (file)
--- a/src/curl_json.c
+++ b/src/curl_json.c
#include "plugin.h"
#include "configfile.h"
#include "utils_avltree.h"
+#include "utils_complain.h"
#include <curl/curl.h>
#include <yajl/yajl_parse.h>
ds = plugin_get_ds (key->type);
if (ds == NULL)
- return -1; /* let plugin_write do the complaining */
- else
- return ds->ds[0].type; /* XXX support ds->ds_len > 1 */
+ {
+ static char type[DATA_MAX_NAME_LEN] = "!!!invalid!!!";
+
+ assert (key->type != NULL);
+ if (strcmp (type, key->type) != 0)
+ {
+ ERROR ("curl_json plugin: Unable to look up DS type \"%s\".",
+ key->type);
+ sstrncpy (type, key->type, sizeof (type));
+ }
+
+ return -1;
+ }
+ else if (ds->ds_num > 1)
+ {
+ static c_complain_t complaint = C_COMPLAIN_INIT_STATIC;
+
+ c_complain_once (LOG_WARNING, &complaint,
+ "curl_json plugin: The type \"%s\" has more than one data source. "
+ "This is currently not supported. I will return the type of the "
+ "first data source, but this will likely lead to problems later on.",
+ key->type);
+ }
+
+ return ds->ds[0].type;
}
/* yajl callbacks */
buffer[sizeof (buffer) - 1] = 0;
type = cj_get_type (key);
+ if (type < 0)
+ return (CJ_CB_CONTINUE);
endptr = NULL;
errno = 0;
host = db->host;
if (key->instance == NULL)
- ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%s-%s",
- db->state[db->depth-1].name, db->state[db->depth].name);
+ {
+ if ((db->depth == 0) || (strcmp ("", db->state[db->depth-1].name) == 0))
+ sstrncpy (vl.type_instance, db->state[db->depth].name, sizeof (vl.type_instance));
+ else
+ ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%s-%s",
+ db->state[db->depth-1].name, db->state[db->depth].name);
+ }
else
sstrncpy (vl.type_instance, key->instance, sizeof (vl.type_instance));