X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcurl_json.c;h=cc8b4ad3cb487360fee998148cfeaa67ca4dfd93;hb=3427c2e266c04d67848bda913caa730a395c7295;hp=857e276bb585e16a9f872d4863f43e86c20d1e2d;hpb=0471475841a912322c50200c5fb7a45b790ad576;p=collectd.git diff --git a/src/curl_json.c b/src/curl_json.c index 857e276b..cc8b4ad3 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -26,6 +26,7 @@ #include "plugin.h" #include "configfile.h" #include "utils_avltree.h" +#include "utils_complain.h" #include #include @@ -144,9 +145,31 @@ static int cj_get_type (cj_key_t *key) 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 */ @@ -704,8 +727,13 @@ static void cj_submit (cj_t *db, cj_key_t *key, value_t *value) /* {{{ */ 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));