netapp plugin: Fix compilation problems.
[collectd.git] / src / netapp.c
index 4944416..45144bf 100644 (file)
@@ -611,8 +611,9 @@ static data_volume_perf_t *get_volume_perf(cfg_volume_perf_t *cvp, /* {{{ */
  */
 static int submit_values(const char *host, /* {{{ */
                          const char *plugin_inst, const char *type,
-                         const char *type_inst, value_t *values, int values_len,
-                         cdtime_t timestamp, cdtime_t interval) {
+                         const char *type_inst, value_t *values,
+                         size_t values_len, cdtime_t timestamp,
+                         cdtime_t interval) {
   value_list_t vl = VALUE_LIST_INIT;
 
   vl.values = values;
@@ -626,8 +627,6 @@ static int submit_values(const char *host, /* {{{ */
 
   if (host != NULL)
     sstrncpy(vl.host, host, sizeof(vl.host));
-  else
-    sstrncpy(vl.host, hostname_g, sizeof(vl.host));
   sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
   if (plugin_inst != NULL)
     sstrncpy(vl.plugin_instance, plugin_inst, sizeof(vl.plugin_instance));
@@ -643,49 +642,39 @@ static int submit_two_derive(const char *host,
                              const char *type, const char *type_inst,
                              derive_t val0, derive_t val1, cdtime_t timestamp,
                              cdtime_t interval) {
-  value_t values[2];
-
-  values[0].derive = val0;
-  values[1].derive = val1;
+  value_t values[] = {
+      {.derive = val0}, {.derive = val1},
+  };
 
-  return (submit_values(host, plugin_inst, type, type_inst, values, 2,
-                        timestamp, interval));
+  return (submit_values(host, plugin_inst, type, type_inst, values,
+                        STATIC_ARRAY_SIZE(values), timestamp, interval));
 } /* }}} int submit_two_derive */
 
 static int submit_derive(const char *host, const char *plugin_inst, /* {{{ */
                          const char *type, const char *type_inst,
                          derive_t counter, cdtime_t timestamp,
                          cdtime_t interval) {
-  value_t v;
-
-  v.derive = counter;
-
-  return (submit_values(host, plugin_inst, type, type_inst, &v, 1, timestamp,
-                        interval));
+  return (submit_values(host, plugin_inst, type, type_inst,
+                        &(value_t){.derive = counter}, 1, timestamp, interval));
 } /* }}} int submit_derive */
 
 static int submit_two_gauge(const char *host, const char *plugin_inst, /* {{{ */
                             const char *type, const char *type_inst,
                             gauge_t val0, gauge_t val1, cdtime_t timestamp,
                             cdtime_t interval) {
-  value_t values[2];
+  value_t values[] = {
+      {.gauge = val0}, {.gauge = val1},
+  };
 
-  values[0].gauge = val0;
-  values[1].gauge = val1;
-
-  return (submit_values(host, plugin_inst, type, type_inst, values, 2,
-                        timestamp, interval));
+  return (submit_values(host, plugin_inst, type, type_inst, values,
+                        STATIC_ARRAY_SIZE(values), timestamp, interval));
 } /* }}} int submit_two_gauge */
 
 static int submit_double(const char *host, const char *plugin_inst, /* {{{ */
                          const char *type, const char *type_inst, double d,
                          cdtime_t timestamp, cdtime_t interval) {
-  value_t v;
-
-  v.gauge = (gauge_t)d;
-
-  return (submit_values(host, plugin_inst, type, type_inst, &v, 1, timestamp,
-                        interval));
+  return (submit_values(host, plugin_inst, type, type_inst,
+                        &(value_t){.gauge = d}, 1, timestamp, interval));
 } /* }}} int submit_uint64 */
 
 /* Calculate hit ratio from old and new counters and submit the resulting
@@ -695,7 +684,7 @@ static int submit_cache_ratio(const char *host, /* {{{ */
                               uint64_t new_hits, uint64_t new_misses,
                               uint64_t old_hits, uint64_t old_misses,
                               cdtime_t timestamp, cdtime_t interval) {
-  value_t v;
+  value_t v = {.gauge = NAN};
 
   if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
     uint64_t hits;
@@ -705,8 +694,6 @@ static int submit_cache_ratio(const char *host, /* {{{ */
     misses = new_misses - old_misses;
 
     v.gauge = 100.0 * ((gauge_t)hits) / ((gauge_t)(hits + misses));
-  } else {
-    v.gauge = NAN;
   }
 
   return (submit_values(host, plugin_inst, "cache_ratio", type_inst, &v, 1,
@@ -1923,15 +1910,13 @@ static int cna_query_quota(host_config_t *host) /* {{{ */
 static int cna_handle_snapvault_data(const char *hostname, /* {{{ */
                                      cfg_snapvault_t *cfg_snapvault,
                                      na_elem_t *data, cdtime_t interval) {
-  na_elem_iter_t status_iter;
-
-  status = na_elem_child(data, "status-list");
-  if (!status) {
+  na_elem_t *status_list = na_elem_child(data, "status-list");
+  if (status_list == NULL) {
     ERROR("netapp plugin: SnapVault status record missing status-list");
     return (0);
   }
 
-  status_iter = na_child_iterator(status);
+  na_elem_iter_t status_iter = na_child_iterator(status_list);
   for (na_elem_t *status = na_iterator_next(&status_iter); status != NULL;
        status = na_iterator_next(&status_iter)) {
     const char *dest_sys, *dest_path, *src_sys, *src_path;
@@ -2834,13 +2819,13 @@ static int cna_register_host(host_config_t *host) /* {{{ */
   else
     ssnprintf(cb_name, sizeof(cb_name), "netapp-%s", host->name);
 
-  user_data_t ud = {.data = host,
-                    .free_func = (void (*)(void *))free_host_config};
-
-  plugin_register_complex_read(/* group = */ NULL, cb_name,
-                               /* callback  = */ cna_read,
-                               /* interval  = */ host->interval,
-                               /* user data = */ &ud);
+  plugin_register_complex_read(
+      /* group = */ NULL, cb_name,
+      /* callback  = */ cna_read,
+      /* interval  = */ host->interval,
+      &(user_data_t){
+          .data = host, .free_func = (void *)free_host_config,
+      });
 
   return (0);
 } /* }}} int cna_register_host */