Merge pull request #2874 from elfiesmelfie/feat_virt_block_info
[collectd.git] / src / write_stackdriver.c
index 7be3c67..fd0192a 100644 (file)
 
 #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 <curl/curl.h>
 #include <pthread.h>
@@ -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;
@@ -222,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;
   }
 
@@ -231,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);
     }
@@ -336,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 */