X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fwrite_stackdriver.c;h=fd0192a064aef60da5fa8f87d58ca5a81879dcd2;hb=434efdd75ae1fc215a65a30c982af100506c0404;hp=eb60ea9ceb45d3a7260c359c50c44420196b8416;hpb=74d6bcc2d388d191f856b4905ea333dd36702a4b;p=collectd.git diff --git a/src/write_stackdriver.c b/src/write_stackdriver.c index eb60ea9c..fd0192a0 100644 --- a/src/write_stackdriver.c +++ b/src/write_stackdriver.c @@ -22,12 +22,12 @@ #include "collectd.h" -#include "common.h" #include "configfile.h" #include "plugin.h" -#include "utils_format_stackdriver.h" -#include "utils_gce.h" -#include "utils_oauth.h" +#include "utils/common/common.h" +#include "utils/format_stackdriver/format_stackdriver.h" +#include "utils/gce/gce.h" +#include "utils/oauth/oauth.h" #include #include @@ -139,14 +139,17 @@ static api_error_t *parse_api_error(char const *body) { yajl_val code = yajl_tree_get(root, (char const *[]){"error", "code", NULL}, yajl_t_number); - if (code != NULL) { + if (YAJL_IS_INTEGER(code)) { err->code = YAJL_GET_INTEGER(code); } yajl_val message = yajl_tree_get( root, (char const *[]){"error", "message", NULL}, yajl_t_string); - if (message != NULL) { - err->message = strdup(YAJL_GET_STRING(message)); + if (YAJL_IS_STRING(message)) { + char const *m = YAJL_GET_STRING(message); + if (m != NULL) { + err->message = strdup(m); + } } return err; @@ -187,6 +190,12 @@ static int do_post(wg_callback_t *cb, char const *url, void const *payload, curl_easy_setopt(cb->curl, CURLOPT_POST, 1L); curl_easy_setopt(cb->curl, CURLOPT_URL, url); + long timeout_ms = 2 * CDTIME_T_TO_MS(plugin_get_interval()); + if (timeout_ms < 10000) { + timeout_ms = 10000; + } + curl_easy_setopt(cb->curl, CURLOPT_TIMEOUT_MS, timeout_ms); + /* header */ char *auth_header = wg_get_authorization_header(cb); if (auth_header == NULL) { @@ -216,8 +225,10 @@ static int do_post(wg_callback_t *cb, char const *url, void const *payload, if (status != CURLE_OK) { ERROR("write_stackdriver plugin: POST %s failed: %s", url, cb->curl_errbuf); - sfree(ret_content->memory); - ret_content->size = 0; + if (ret_content != NULL) { + sfree(ret_content->memory); + ret_content->size = 0; + } return -1; } @@ -225,10 +236,10 @@ static int do_post(wg_callback_t *cb, char const *url, void const *payload, curl_easy_getinfo(cb->curl, CURLINFO_RESPONSE_CODE, &http_code); if (ret_content != NULL) { - if ((status >= 400) && (status < 500)) { + if ((http_code >= 400) && (http_code < 500)) { ERROR("write_stackdriver plugin: POST %s: %s", url, API_ERROR_STRING(parse_api_error(ret_content->memory))); - } else if (status >= 500) { + } else if (http_code >= 500) { WARNING("write_stackdriver plugin: POST %s: %s", url, ret_content->memory); } @@ -330,11 +341,6 @@ static int wg_flush_nolock(cdtime_t timeout, wg_callback_t *cb) /* {{{ */ char *payload = sd_output_reset(cb->formatter); int status = wg_call_timeseries_write(cb, payload); - if (status != 0) { - ERROR("write_stackdriver plugin: Sending buffer failed with status %d.", - status); - } - wg_reset_buffer(cb); return status; } /* }}} wg_flush_nolock */