summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/influxdb-writer.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/plugins/influxdb-writer.c b/src/plugins/influxdb-writer.c
index a7ce8fc..e22c2bd 100644
--- a/src/plugins/influxdb-writer.c
+++ b/src/plugins/influxdb-writer.c
@@ -50,16 +50,19 @@ void influxdb_write_curl_cb(void *closure, int status, CURL *curl, const char *r
}
}
-
-static void serialize_list_to_query(char *query, struct list *node) {
+// query: destination buffer
+// node: head node of the list
+// list_sep: separator to append in front of the list
+// item_sep: separator to append between items of the list
+static void serialize_list_to_query(char *query, struct list *node, const char *list_sep, const char *item_sep) {
bool first = true;
while(node != NULL) {
if(first) {
- concatenate(query, node->key, " ");
+ concatenate(query, node->key, list_sep);
first = false;
} else {
- concatenate(query, node->key, ",");
+ concatenate(query, node->key, item_sep);
}
if(json_object_is_type(node->value, json_type_string))
@@ -77,13 +80,15 @@ static size_t format_write_args(char *query, struct series_t *serie)
strncat(query, serie->name, strlen(serie->name));
- serialize_list_to_query(query, serie->serie_columns.tags);
- serialize_list_to_query(query, serie->serie_columns.fields);
-
- asprintf(&ts, "%lu", serie->timestamp);
- concatenate(query, ts, " ");
+ serialize_list_to_query(query, serie->serie_columns.tags, ",", ",");
+ serialize_list_to_query(query, serie->serie_columns.fields, " ", ",");
- return strlen(query);
+ if (asprintf(&ts, "%lu", serie->timestamp) > 0) {
+ concatenate(query, ts, " ");
+ free(ts);
+ return strlen(query);
+ }
+ return -1;
}
CURL *make_curl_write_post(afb_api_t apiHandle, const char *url, json_object *metricsJ)
@@ -121,7 +126,7 @@ CURL *make_curl_write_post(afb_api_t apiHandle, const char *url, json_object *me
}
else {
len_write = format_write_args(write, serie);
- if(len_write) {
+ if(len_write > 0) {
post_data[i] = malloc(len_write + 1);
strcpy(post_data[i], write);
memset(write, 0, len_write);