summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-04-24 09:21:47 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2018-07-10 23:41:14 +0200
commite7ca1205b5efec2788ddac7d298f5493c0e628ad (patch)
tree28a249ce660f3613441179b9d0c09fe608f8dbd3
parent7beb985dc148287de3af9d72929909b88480e2a9 (diff)
Externalize Curl dependency within afb-helpers
Change-Id: I50a4c6f440730a8776f7bb5c58c756c35bca5db8 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--src/plugins/influxdb-writer.c2
-rw-r--r--src/plugins/influxdb.c31
2 files changed, 31 insertions, 2 deletions
diff --git a/src/plugins/influxdb-writer.c b/src/plugins/influxdb-writer.c
index 4ffa8c9..ba0a801 100644
--- a/src/plugins/influxdb-writer.c
+++ b/src/plugins/influxdb-writer.c
@@ -134,7 +134,7 @@ CURL *make_curl_write_post(const char *url, json_object *metricsJ)
/* Check that we just do not broke the for loop before trying preparing CURL
request object */
curl = i == lpd ?
- curl_wrap_prepare_post_binary(url, NULL, " ", (const char * const*)post_data) : NULL;
+ curl_wrap_prepare_post_unescaped(url, NULL, " ", (const char * const*)post_data) : NULL;
free(serie);
free(post_data);
diff --git a/src/plugins/influxdb.c b/src/plugins/influxdb.c
index 77f78f7..b08eb9e 100644
--- a/src/plugins/influxdb.c
+++ b/src/plugins/influxdb.c
@@ -62,7 +62,7 @@ int create_database()
post_data[0] = "q=CREATE DATABASE \""DEFAULT_DB"\"";
post_data[1] = NULL;
- CURL *request = curl_wrap_prepare_post_binary("localhost:"DEFAULT_DBPORT"/query",NULL, " ", post_data);
+ CURL *request = curl_wrap_prepare_post_unescaped("localhost:"DEFAULT_DBPORT"/query",NULL, " ", post_data);
curl_wrap_perform(request, &result, &result_size);
if(curl_wrap_response_code_get(request) != 200) {
@@ -78,6 +78,31 @@ int create_database()
return ret;
}
+void unpack_values(void *l, json_object *valuesJ, const char *key)
+{
+ struct list *oneList = (struct list *)l;
+
+ /* Append a suffix to be able to differentiate tags and fields at reading
+ time */
+ char *suffixed_key = calloc(1, strlen(key) + 3);
+ strcpy(suffixed_key, key);
+ strcat(suffixed_key, "_f");
+
+ add_elt(&oneList, suffixed_key, valuesJ);
+}
+
+void unpack_metadata(void *l, json_object *valuesJ, const char *key)
+{
+ struct list *oneList = (struct list *)l;
+
+ /* Append a suffix to be able to differentiate tags and fields at reading
+ time */
+ char *suffixed_key = calloc(1, strlen(key) +3);
+ strcat(suffixed_key, "_t");
+
+ add_elt(&oneList, suffixed_key, valuesJ);
+}
+
void unpacking_from_api(void *s, json_object *valueJ, const char *key)
{
size_t key_length = strlen(key);
@@ -88,6 +113,10 @@ void unpacking_from_api(void *s, json_object *valueJ, const char *key)
serie->name = json_object_get_string(valueJ);
else if(strcasecmp("timestamp", key) == 0)
serie->timestamp = get_ts();
+ else if(strcasecmp("metadata", key) == 0)
+ wrap_json_object_for_all(valueJ, unpack_metadata, (void*)serie->serie_columns.tags);
+ else if(strcasecmp("value", key) == 0 || strcasecmp("values", key) == 0)
+ wrap_json_object_for_all(valueJ, unpack_values, (void*)serie->serie_columns.fields);
/* Treat all key looking for tag and field object. Those ones could be find
with the last 2 character. '_t' for tag and '_f' that are the keys that
could be indefinite. Cf influxdb documentation: