summaryrefslogtreecommitdiffstats
path: root/src/plugins/influxdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/influxdb.c')
-rw-r--r--src/plugins/influxdb.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/plugins/influxdb.c b/src/plugins/influxdb.c
index a175c0e..3403eb3 100644
--- a/src/plugins/influxdb.c
+++ b/src/plugins/influxdb.c
@@ -25,6 +25,9 @@
#include "tsdb.h"
#include "wrap-json.h"
+static char* default_db_host = DEFAULT_DBHOST;
+static char default_db_port[64] = DEFAULT_DBPORT;
+
CTLP_CAPI_REGISTER("influxdb");
CTLP_ONLOAD(plugin, ret)
@@ -32,6 +35,30 @@ CTLP_ONLOAD(plugin, ret)
int err = 0;
char* result;
size_t result_size;
+
+ // Check if default host & port are set in harvester-config.json file
+ if (plugin->paramsJ) {
+ const char* host = NULL;
+ int port = -1;
+ int ret;
+
+ AFB_API_NOTICE(plugin->api, "params detected to change default host+port : %s", json_object_to_json_string(plugin->paramsJ));
+ ret = wrap_json_unpack(plugin->paramsJ, "{ss si}",
+ "host", &host, "port", &port);
+ if (ret == 0) {
+ if (host && strlen(host) > 0)
+ // SEB do we need strdup ??
+ default_db_host = strdup(host);
+ if (port > 0) {
+ snprintf(default_db_port, sizeof(default_db_host) - 1, "%d", port);
+ }
+ } else {
+ AFB_API_ERROR(plugin->api, "decoding params : %s", wrap_json_get_error_string(ret));
+ }
+ }
+
+ //
+
CURL* request = curl_wrap_prepare_get(get_url(NULL, NULL, "/ping"), NULL, NULL);
struct reader_args r_args = { NULL, NULL, 1000000 };
@@ -75,8 +102,8 @@ size_t make_url(char* url, size_t l_url, const char* host, const char* port, con
bzero(url, l_url);
/* Handle default host and port */
- host = host ? host : DEFAULT_DBHOST;
- port = port ? port : DEFAULT_DBPORT;
+ host = host ? host : default_db_host;
+ port = port ? port : default_db_port;
strncat(url, host, l_url - strlen(url) - 1);
strcat(url, ":");
@@ -104,8 +131,8 @@ char* get_url(const char* host, const char* port, const char* endpoint)
static char* url = NULL;
static size_t urlSz = 0;
- host = host ? host : DEFAULT_DBHOST;
- port = port ? port : DEFAULT_DBPORT;
+ host = host ? host : default_db_host;
+ port = port ? port : default_db_port;
size_t newSz = strlen(host) + 1 + strlen(port) + 1 + strlen(endpoint) + 1;
if (urlSz < newSz) {