aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/CMakeLists.txt6
-rw-r--r--src/plugins/influxdb-reader.c38
-rw-r--r--src/plugins/influxdb-writer.c30
-rw-r--r--src/plugins/influxdb.c12
-rw-r--r--src/plugins/influxdb.h2
5 files changed, 41 insertions, 47 deletions
diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt
index e366685..603e5a0 100644
--- a/src/plugins/CMakeLists.txt
+++ b/src/plugins/CMakeLists.txt
@@ -34,11 +34,5 @@ PROJECT_TARGET_ADD(influxdb)
OUTPUT_NAME ${TARGET_NAME}
)
- # Library dependencies (include updates automatically)
- TARGET_LINK_LIBRARIES(${TARGET_NAME}
- afb-helpers
- ${link_libraries}
- )
-
target_include_directories(${TARGET_NAME}
PRIVATE "${CMAKE_SOURCE_DIR}/app-controller-submodule/ctl-lib")
diff --git a/src/plugins/influxdb-reader.c b/src/plugins/influxdb-reader.c
index 7b184dd..d7ddac7 100644
--- a/src/plugins/influxdb-reader.c
+++ b/src/plugins/influxdb-reader.c
@@ -29,7 +29,7 @@
struct metrics_list {
struct series_t serie;
json_object *metricsJ;
- AFB_ApiT api;
+ afb_api_t api;
};
static void fill_n_send_values(void *c, json_object *valuesJ)
@@ -45,7 +45,7 @@ static void fill_n_send_values(void *c, json_object *valuesJ)
else {
if(set_value(m_list->serie.serie_columns.tags, valuesJ, i)) {
if(set_value(m_list->serie.serie_columns.fields, valuesJ, j)) {
- AFB_ApiError(m_list->api, "No tags nor fields fits.");
+ AFB_API_ERROR(m_list->api, "No tags nor fields fits.");
}
j++;
}
@@ -86,7 +86,7 @@ static void unpack_metric_from_db(void *ml, json_object *metricJ)
"name", &m_list->serie.name,
"columns", &columnsJ,
"values", &valuesJ)) {
- AFB_ApiError(m_list->api, "Unpacking metric goes wrong");
+ AFB_API_ERROR(m_list->api, "Unpacking metric goes wrong");
return;
}
@@ -94,7 +94,7 @@ static void unpack_metric_from_db(void *ml, json_object *metricJ)
wrap_json_array_for_all(valuesJ, fill_n_send_values, m_list);
}
-static json_object *unpack_series(AFB_ApiT apiHandle, json_object *seriesJ)
+static json_object *unpack_series(afb_api_t apiHandle, json_object *seriesJ)
{
struct metrics_list m_list = {
.serie = {
@@ -114,7 +114,7 @@ static json_object *unpack_series(AFB_ApiT apiHandle, json_object *seriesJ)
return m_list.metricsJ;
}
-static void forward_to_garner(AFB_ApiT apiHandle, const char *result, size_t size)
+static void forward_to_garner(afb_api_t apiHandle, const char *result, size_t size)
{
int id = 0;
json_object *resultsJ = NULL,
@@ -135,13 +135,13 @@ static void forward_to_garner(AFB_ApiT apiHandle, const char *result, size_t siz
if(seriesJ) {
metrics2send = unpack_series(apiHandle, seriesJ);
if(json_object_array_length(metrics2send)) {
- if(AFB_ServiceSync(apiHandle, "garner", "write", metrics2send, &call_resultJ)) {
- AFB_ApiError(apiHandle, "Metrics were sent but not done, an error happens. Details: %s", json_object_to_json_string(call_resultJ));
+ if(afb_api_call_sync_legacy(apiHandle, "garner", "write", metrics2send, &call_resultJ)) {
+ AFB_API_ERROR(apiHandle, "Metrics were sent but not done, an error happens. Details: %s", json_object_to_json_string(call_resultJ));
}
}
}
else {
- AFB_ApiError(apiHandle, "Empty response. Request results was:\n%s", result);
+ AFB_API_ERROR(apiHandle, "Empty response. Request results was:\n%s", result);
}
}
@@ -149,26 +149,26 @@ static void influxdb_read_curl_cb(void *closure, int status, CURL *curl, const c
{
if(!closure)
return;
- AFB_ApiT apiHandle = (AFB_ApiT)closure;
+ afb_api_t apiHandle = (afb_api_t)closure;
long rep_code = curl_wrap_response_code_get(curl);
switch(rep_code) {
case 200:
- AFB_ApiDebug(apiHandle, "Read correctly done");
+ AFB_API_DEBUG(apiHandle, "Read correctly done");
forward_to_garner(apiHandle, result, size);
break;
case 400:
- AFB_ApiError(apiHandle, "Unacceptable request. %s", result);
+ AFB_API_ERROR(apiHandle, "Unacceptable request. %s", result);
break;
case 401:
- AFB_ApiError(apiHandle, "Invalid authentication. %s", result);
+ AFB_API_ERROR(apiHandle, "Invalid authentication. %s", result);
break;
default:
- AFB_ApiError(apiHandle, "Unexptected behavior. %s", result);
+ AFB_API_ERROR(apiHandle, "Unexptected behavior. %s", result);
break;
}
}
-static CURL *make_curl_query_get(AFB_ApiT apiHandle, const char *url)
+static CURL *make_curl_query_get(afb_api_t apiHandle, const char *url)
{
CURL *curl;
char *args[5];
@@ -184,7 +184,7 @@ static CURL *make_curl_query_get(AFB_ApiT apiHandle, const char *url)
args[4] = NULL;
length_now = asprintf(&now, "%lu", get_ts());
- int rootdir_fd = AFB_RootDirGetFD(apiHandle);
+ int rootdir_fd = afb_api_rootdir_get_fd(apiHandle);
int fd_last_read = openat(rootdir_fd, "last_db_read", O_CREAT | O_RDWR, S_IRWXU);
if (fd_last_read < 0)
return NULL;
@@ -193,7 +193,7 @@ static CURL *make_curl_query_get(AFB_ApiT apiHandle, const char *url)
else write the last timestamp */
if(read(fd_last_read, last_ts, sizeof(last_ts)) == 0) {
if(write(fd_last_read, now, length_now) != length_now)
- AFB_ApiError(apiHandle, "Error writing last_db_read file: %s\n", strerror( errno ));
+ AFB_API_ERROR(apiHandle, "Error writing last_db_read file: %s\n", strerror( errno ));
}
else {
strcat(query, " WHERE time >= ");
@@ -201,7 +201,7 @@ static CURL *make_curl_query_get(AFB_ApiT apiHandle, const char *url)
close(fd_last_read);
fd_last_read = openat(rootdir_fd, "last_db_read", O_TRUNC | O_RDWR);
if (write(fd_last_read, now, length_now) != length_now)
- AFB_ApiError(apiHandle, "Error writing last_db_read file: %s", strerror( errno ));
+ AFB_API_ERROR(apiHandle, "Error writing last_db_read file: %s", strerror( errno ));
}
args[3] = query;
@@ -245,8 +245,8 @@ CTLP_CAPI(read_from_influxdb, source, argsJ, eventJ)
struct sd_event_source *evtSource = NULL;
/* Set a cyclic cb call each 1s to call the read callback */
- sd_event_now(AFB_GetEventLoop(source->api), CLOCK_MONOTONIC, &usec);
- err = sd_event_add_time(AFB_GetEventLoop(source->api), &evtSource, CLOCK_MONOTONIC, usec+1000000, 250, influxdb_read, (void*)source);
+ sd_event_now(afb_api_get_event_loop(source->api), CLOCK_MONOTONIC, &usec);
+ err = sd_event_add_time(afb_api_get_event_loop(source->api), &evtSource, CLOCK_MONOTONIC, usec+1000000, 250, influxdb_read, (void*)source);
if(!err)
err = sd_event_source_set_enabled(evtSource, SD_EVENT_ON);
diff --git a/src/plugins/influxdb-writer.c b/src/plugins/influxdb-writer.c
index e02612d..9090a32 100644
--- a/src/plugins/influxdb-writer.c
+++ b/src/plugins/influxdb-writer.c
@@ -23,29 +23,29 @@
void influxdb_write_curl_cb(void *closure, int status, CURL *curl, const char *result, size_t size)
{
- AFB_ReqT request = (AFB_ReqT)closure;
+ afb_req_t request = (afb_req_t)closure;
long rep_code = curl_wrap_response_code_get(curl);
switch(rep_code) {
case 204:
- AFB_ReqDebug(request, "Request correctly written");
- AFB_ReqSuccess(request, NULL, "Request has been successfully writen");
+ AFB_REQ_DEBUG(request, "Request correctly written");
+ afb_req_success(request, NULL, "Request has been successfully writen");
break;
case 400:
- AFB_ReqFail(request, "Bad request", result);
+ afb_req_fail(request, "Bad request", result);
break;
case 401:
- AFB_ReqFail(request, "Unauthorized access", result);
+ afb_req_fail(request, "Unauthorized access", result);
break;
case 404:
- AFB_ReqFail(request, "Not found", result);
- AFB_ReqNotice(request, "Attempt to create the DB '"DEFAULT_DB"'");
+ afb_req_fail(request, "Not found", result);
+ AFB_REQ_NOTICE(request, "Attempt to create the DB '"DEFAULT_DB"'");
create_database(request);
break;
case 500:
- AFB_ReqFailF(request, "Timeout", "Overloaded server: %s", result);
+ afb_req_fail_f(request, "Timeout", "Overloaded server: %s", result);
break;
default:
- AFB_ReqFail(request, "Failure", "Unexpected behavior.");
+ afb_req_fail(request, "Failure", "Unexpected behavior.");
break;
}
}
@@ -88,7 +88,7 @@ static size_t format_write_args(char *query, struct series_t *serie)
return strlen(query);
}
-CURL *make_curl_write_post(AFB_ApiT apiHandle, const char *url, json_object *metricsJ)
+CURL *make_curl_write_post(afb_api_t apiHandle, const char *url, json_object *metricsJ)
{
CURL *curl = NULL;
size_t lpd = 0, len_write = 0, i = 0;
@@ -114,7 +114,7 @@ CURL *make_curl_write_post(AFB_ApiT apiHandle, const char *url, json_object *met
memset(serie, 0, sizeof(struct series_t));
if(unpack_metric_from_api(json_object_array_get_idx(metricsArrayJ, i), serie)) {
- AFB_ApiError(apiHandle, "ERROR unpacking metric. %s", json_object_to_json_string(metricsArrayJ));
+ AFB_API_ERROR(apiHandle, "ERROR unpacking metric. %s", json_object_to_json_string(metricsArrayJ));
break;
}
else {
@@ -144,7 +144,7 @@ CURL *make_curl_write_post(AFB_ApiT apiHandle, const char *url, json_object *met
return curl;
}
-CURL *influxdb_write(AFB_ApiT apiHandle, const char* host, const char *port, json_object *metricJ)
+CURL *influxdb_write(afb_api_t apiHandle, const char* host, const char *port, json_object *metricJ)
{
char url[URL_MAXIMUM_LENGTH]; /* Safe limit for most popular web browser */
make_url(url, sizeof(url), host, port, "write");
@@ -153,12 +153,12 @@ CURL *influxdb_write(AFB_ApiT apiHandle, const char* host, const char *port, jso
CTLP_CAPI(write_to_influxdb, source, argsJ, eventJ)
{
- AFB_ReqT request = source->request;
+ afb_req_t request = source->request;
const char *port = NULL;
const char *host = NULL;
CURL *curl_request;
- json_object *req_args = AFB_ReqJson(request),
+ json_object *req_args = afb_req_json(request),
*portJ = NULL,
*metric = NULL;
@@ -166,7 +166,7 @@ CTLP_CAPI(write_to_influxdb, source, argsJ, eventJ)
"host", &host,
"port", &portJ,
"metric", &metric) || ! metric)
- AFB_ReqFail(request, "Failed", "Error processing arguments. Miss metric\
+ afb_req_fail(request, "Failed", "Error processing arguments. Miss metric\
JSON object or malformed");
else
port = json_object_is_type(portJ, json_type_null) ?
diff --git a/src/plugins/influxdb.c b/src/plugins/influxdb.c
index 92f1f89..2cfd551 100644
--- a/src/plugins/influxdb.c
+++ b/src/plugins/influxdb.c
@@ -40,7 +40,7 @@ CTLP_ONLOAD(plugin, ret)
curl_wrap_perform(request, &result, &result_size);
if (curl_wrap_response_code_get(request) != 204) {
- AFB_ApiError(plugin->api, "InfluxDB not reachable, please start it");
+ AFB_API_ERROR(plugin->api, "InfluxDB not reachable, please start it");
err = ERROR;
}
@@ -59,10 +59,10 @@ CTLP_CAPI(influxdb_ping, source, argsJ, eventJ)
curl_wrap_perform(curl_req, &result, &result_size);
if (curl_wrap_response_code_get(curl_req) != 204) {
- AFB_ApiError(source->api, "InfluxDB is offline.");
+ AFB_API_ERROR(source->api, "InfluxDB is offline.");
ret = ERROR;
} else {
- AFB_ApiNotice(source->api, "InfluxDB is up and running.");
+ AFB_API_NOTICE(source->api, "InfluxDB is up and running.");
}
curl_easy_cleanup(curl_req);
@@ -88,7 +88,7 @@ size_t make_url(char* url, size_t l_url, const char* host, const char* port, con
return strlen(url);
}
-int create_database(AFB_ReqT request)
+int create_database(afb_req_t request)
{
int ret = 0;
char* result;
@@ -103,14 +103,14 @@ int create_database(AFB_ReqT request)
curl_wrap_perform(curl_req, &result, &result_size);
if (curl_wrap_response_code_get(request) != 200) {
- AFB_ReqError(request, "Can't create database.");
+ AFB_REQ_ERROR(request, "Can't create database.");
ret = ERROR;
}
curl_easy_cleanup(curl_req);
if (ret == 0)
- AFB_ReqNotice(request, "Database '" DEFAULT_DB "' created");
+ AFB_REQ_NOTICE(request, "Database '" DEFAULT_DB "' created");
return ret;
}
diff --git a/src/plugins/influxdb.h b/src/plugins/influxdb.h
index cd7b222..3c60e27 100644
--- a/src/plugins/influxdb.h
+++ b/src/plugins/influxdb.h
@@ -38,7 +38,7 @@ struct series_t {
uint64_t timestamp;
};
-int create_database(AFB_ReqT request);
+int create_database(afb_req_t request);
int unpack_metric_from_api(json_object* m, struct series_t* serie);