+/* Data corresponding to <VolumePerf /> */
+static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
+ cfg_volume_perf_t *cvp, na_elem_t *data, int interval)
+{
+ time_t timestamp;
+ na_elem_t *elem_instances;
+ na_elem_iter_t iter_instances;
+ na_elem_t *elem_instance;
+
+ timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
+
+ elem_instances = na_elem_child(data, "instances");
+ if (elem_instances == NULL)
+ {
+ ERROR ("netapp plugin: handle_volume_perf_data: "
+ "na_elem_child (\"instances\") failed "
+ "for host %s.", hostname);
+ return (-1);
+ }
+
+ iter_instances = na_child_iterator (elem_instances);
+ for (elem_instance = na_iterator_next(&iter_instances);
+ elem_instance != NULL;
+ elem_instance = na_iterator_next(&iter_instances))
+ {
+ const char *name;
+
+ data_volume_perf_t perf_data;
+ data_volume_perf_t *v;
+
+ na_elem_t *elem_counters;
+ na_elem_iter_t iter_counters;
+ na_elem_t *elem_counter;
+
+ memset (&perf_data, 0, sizeof (perf_data));
+ perf_data.timestamp = timestamp;
+
+ name = na_child_get_string (elem_instance, "name");
+ if (name == NULL)
+ continue;
+
+ /* get_volume_perf may return NULL if this volume is to be ignored. */
+ v = get_volume_perf (cvp, name);
+ if (v == NULL)
+ continue;
+
+ elem_counters = na_elem_child (elem_instance, "counters");
+ if (elem_counters == NULL)
+ continue;
+
+ iter_counters = na_child_iterator (elem_counters);
+ for (elem_counter = na_iterator_next(&iter_counters);
+ elem_counter != NULL;
+ elem_counter = na_iterator_next(&iter_counters))
+ {
+ const char *name;
+ uint64_t value;
+
+ name = na_child_get_string (elem_counter, "name");
+ if (name == NULL)
+ continue;
+
+ value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
+ if (value == UINT64_MAX)
+ continue;
+
+ if (!strcmp(name, "read_data")) {
+ perf_data.read_bytes = value;
+ perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
+ } else if (!strcmp(name, "write_data")) {
+ perf_data.write_bytes = value;
+ perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
+ } else if (!strcmp(name, "read_ops")) {
+ perf_data.read_ops = value;
+ perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
+ } else if (!strcmp(name, "write_ops")) {
+ perf_data.write_ops = value;
+ perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
+ } else if (!strcmp(name, "read_latency")) {
+ perf_data.read_latency = value;
+ perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
+ } else if (!strcmp(name, "write_latency")) {
+ perf_data.write_latency = value;
+ perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
+ }
+ } /* for (elem_counter) */
+
+ submit_volume_perf_data (hostname, v, &perf_data, interval);
+ } /* for (volume) */
+
+ return (0);
+} /* }}} int cna_handle_volume_perf_data */
+
+static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
+{
+ na_elem_t *e;
+
+ if (cd == NULL)
+ return (EINVAL);
+
+ if (cd->query != NULL)
+ return (0);
+
+ cd->query = na_elem_new ("perf-object-get-instances");
+ if (cd->query == NULL)
+ {
+ ERROR ("netapp plugin: na_elem_new failed.");
+ return (-1);
+ }
+ na_child_add_string (cd->query, "objectname", "volume");
+
+ e = na_elem_new("counters");
+ if (e == NULL)
+ {
+ na_elem_free (cd->query);
+ cd->query = NULL;
+ ERROR ("netapp plugin: na_elem_new failed.");
+ return (-1);
+ }
+ na_child_add_string(e, "counter", "read_ops");
+ na_child_add_string(e, "counter", "write_ops");
+ na_child_add_string(e, "counter", "read_data");
+ na_child_add_string(e, "counter", "write_data");
+ na_child_add_string(e, "counter", "read_latency");
+ na_child_add_string(e, "counter", "write_latency");
+ na_child_add(cd->query, e);
+
+ return (0);
+} /* }}} int cna_setup_volume_perf */
+
+static int cna_query_volume_perf (host_config_t *host) /* {{{ */
+{
+ na_elem_t *data;
+ int status;
+ time_t now;
+
+ if (host == NULL)
+ return (EINVAL);
+
+ /* If the user did not configure volume performance statistics, return
+ * without doing anything. */
+ if (host->cfg_volume_perf == NULL)
+ return (0);
+
+ now = time (NULL);
+ if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
+ return (0);
+
+ status = cna_setup_volume_perf (host->cfg_volume_perf);
+ if (status != 0)
+ return (status);
+ assert (host->cfg_volume_perf->query != NULL);
+
+ data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
+ if (na_results_status (data) != NA_OK)
+ {
+ ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed for host %s: %s",
+ host->name, na_results_reason (data));
+ na_elem_free (data);
+ return (-1);
+ }
+
+ status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data, host->interval);
+
+ if (status == 0)
+ host->cfg_volume_perf->interval.last_read = now;
+
+ na_elem_free (data);
+ return (status);
+} /* }}} int cna_query_volume_perf */
+
+/* Data corresponding to <VolumeUsage /> */
+static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
+ cfg_volume_usage_t *cfg_volume, int interval)
+{
+ data_volume_usage_t *v;
+
+ for (v = cfg_volume->volumes; v != NULL; v = v->next)
+ {
+ char plugin_instance[DATA_MAX_NAME_LEN];
+
+ uint64_t norm_used = v->norm_used;
+ uint64_t norm_free = v->norm_free;
+ uint64_t sis_saved = v->sis_saved;
+ uint64_t snap_reserve_used = 0;
+ uint64_t snap_reserve_free = v->snap_reserved;
+ uint64_t snap_norm_used = v->snap_used;
+
+ ssnprintf (plugin_instance, sizeof (plugin_instance),
+ "volume-%s", v->name);
+
+ if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD)) {
+ if (v->snap_reserved > v->snap_used) {
+ snap_reserve_free = v->snap_reserved - v->snap_used;
+ snap_reserve_used = v->snap_used;
+ snap_norm_used = 0;
+ } else {
+ snap_reserve_free = 0;
+ snap_reserve_used = v->snap_reserved;
+ snap_norm_used = v->snap_used - v->snap_reserved;
+ }
+ }
+
+ /* The space used by snapshots but not reserved for them is included in
+ * both, norm_used and snap_norm_used. If possible, subtract this here. */
+ if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED))
+ {
+ if (norm_used >= snap_norm_used)
+ norm_used -= snap_norm_used;
+ else
+ {
+ ERROR ("netapp plugin: (norm_used = %"PRIu64") < (snap_norm_used = "
+ "%"PRIu64") for host %s. Invalidating both.",
+ norm_used, snap_norm_used, hostname);
+ v->flags &= ~(HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED);
+ }
+ }
+
+ if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
+ submit_double (hostname, /* plugin instance = */ plugin_instance,
+ "df_complex", "free",
+ (double) norm_free, /* timestamp = */ 0, interval);
+
+ if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
+ submit_double (hostname, /* plugin instance = */ plugin_instance,
+ "df_complex", "sis_saved",
+ (double) sis_saved, /* timestamp = */ 0, interval);
+
+ if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
+ submit_double (hostname, /* plugin instance = */ plugin_instance,
+ "df_complex", "used",
+ (double) norm_used, /* timestamp = */ 0, interval);
+
+ if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
+ submit_double (hostname, /* plugin instance = */ plugin_instance,
+ "df_complex", "snap_reserved",
+ (double) snap_reserve_free, /* timestamp = */ 0, interval);
+
+ if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD))
+ submit_double (hostname, /* plugin instance = */ plugin_instance,
+ "df_complex", "snap_reserve_used",
+ (double) snap_reserve_used, /* timestamp = */ 0, interval);
+
+ if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
+ submit_double (hostname, /* plugin instance = */ plugin_instance,
+ "df_complex", "snap_normal_used",
+ (double) snap_norm_used, /* timestamp = */ 0, interval);
+
+ /* Clear all the HAVE_* flags */
+ v->flags &= ~HAVE_VOLUME_USAGE_ALL;
+ } /* for (v = cfg_volume->volumes) */
+
+ return (0);
+} /* }}} int cna_submit_volume_usage_data */
+
+/* Switch the state of a volume between online and offline and send out a
+ * notification. */
+static int cna_change_volume_status (const char *hostname, /* {{{ */
+ data_volume_usage_t *v)
+{
+ notification_t n;
+
+ memset (&n, 0, sizeof (&n));
+ n.time = time (NULL);
+ sstrncpy (n.host, hostname, sizeof (n.host));
+ sstrncpy (n.plugin, "netapp", sizeof (n.plugin));
+ sstrncpy (n.plugin_instance, v->name, sizeof (n.plugin_instance));
+
+ if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0) {
+ n.severity = NOTIF_OKAY;
+ ssnprintf (n.message, sizeof (n.message),
+ "Volume %s is now online.", v->name);
+ v->flags &= ~IS_VOLUME_USAGE_OFFLINE;
+ } else {
+ n.severity = NOTIF_WARNING;
+ ssnprintf (n.message, sizeof (n.message),
+ "Volume %s is now offline.", v->name);
+ v->flags |= IS_VOLUME_USAGE_OFFLINE;
+ }
+
+ return (plugin_dispatch_notification (&n));
+} /* }}} int cna_change_volume_status */
+
+static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
+ data_volume_usage_t *v)
+{
+ uint64_t snap_used = 0, value;
+ na_elem_t *data, *elem_snap, *elem_snapshots;
+ na_elem_iter_t iter_snap;
+
+ data = na_server_invoke_elem(host->srv, v->snap_query);
+ if (na_results_status(data) != NA_OK)
+ {
+ if (na_results_errno(data) == EVOLUMEOFFLINE) {
+ if ((v->flags & IS_VOLUME_USAGE_OFFLINE) == 0)
+ cna_change_volume_status (host->name, v);