+/* Data corresponding to <Quota /> */
+static int cna_handle_quota_data (const host_config_t *host, /* {{{ */
+ cfg_quota_t *cfg_quota, na_elem_t *data)
+{
+ na_elem_t *elem_quota;
+ na_elem_t *elem_quotas;
+ na_elem_iter_t iter_quota;
+
+ elem_quotas = na_elem_child (data, "quotas");
+ if (elem_quotas == NULL)
+ {
+ ERROR ("netapp plugin: cna_handle_quota_data: "
+ "na_elem_child (\"quotas\") failed "
+ "for host %s.", host->name);
+ return (-1);
+ }
+
+ iter_quota = na_child_iterator (elem_quotas);
+ for (elem_quota = na_iterator_next (&iter_quota);
+ elem_quota != NULL;
+ elem_quota = na_iterator_next (&iter_quota))
+ {
+ const char *quota_type, *volume_name, *tree_name;
+ uint64_t value;
+
+ char plugin_instance[DATA_MAX_NAME_LEN];
+
+ quota_type = na_child_get_string (elem_quota, "quota-type");
+ if (quota_type == NULL)
+ continue;
+
+ /* possible TODO: support other types as well */
+ if (strcmp (quota_type, "tree") != 0)
+ continue;
+
+ tree_name = na_child_get_string (elem_quota, "tree");
+ if ((tree_name == NULL) || (*tree_name == '\0'))
+ continue;
+
+ volume_name = na_child_get_string (elem_quota, "volume");
+ if (volume_name == NULL)
+ continue;
+
+ ssnprintf (plugin_instance, sizeof (plugin_instance),
+ "quota-%s-%s", volume_name, tree_name);
+
+ value = na_child_get_uint64 (elem_quota, "disk-used", UINT64_MAX);
+ if (value != UINT64_MAX) {
+ value *= 1024; /* disk-used reports kilobytes */
+ submit_double (host->name, plugin_instance,
+ /* type = */ "df_complex", /* type instance = */ NULL,
+ (double)value, /* timestamp = */ 0,
+ host->cfg_quota->interval.interval);
+ }
+
+ value = na_child_get_uint64 (elem_quota, "files-used", UINT64_MAX);
+ if (value != UINT64_MAX) {
+ submit_double (host->name, plugin_instance,
+ /* type = */ "files", /* type instance = */ NULL,
+ (double)value, /* timestamp = */ 0,
+ host->cfg_quota->interval.interval);
+ }
+ } /* for (elem_quota) */
+
+ return (0);
+} /* }}} int cna_handle_volume_usage_data */
+
+static int cna_setup_quota (cfg_quota_t *cq) /* {{{ */
+{
+ if (cq == NULL)
+ return (EINVAL);
+
+ if (cq->query != NULL)
+ return (0);
+
+ cq->query = na_elem_new ("quota-report");
+ if (cq->query == NULL)
+ {
+ ERROR ("netapp plugin: na_elem_new failed.");
+ return (-1);
+ }
+
+ return (0);
+} /* }}} int cna_setup_quota */
+
+static int cna_query_quota (host_config_t *host) /* {{{ */
+{
+ na_elem_t *data;
+ int status;
+ cdtime_t now;
+
+ if (host == NULL)
+ return (EINVAL);
+
+ /* If the user did not configure quota statistics, return without
+ * doing anything. */
+ if (host->cfg_quota == NULL)
+ return (0);
+
+ now = cdtime ();
+ if ((host->cfg_quota->interval.interval + host->cfg_quota->interval.last_read) > now)
+ return (0);
+
+ status = cna_setup_quota (host->cfg_quota);
+ if (status != 0)
+ return (status);
+ assert (host->cfg_quota->query != NULL);
+
+ data = na_server_invoke_elem (host->srv, host->cfg_quota->query);
+ if (na_results_status (data) != NA_OK)
+ {
+ ERROR ("netapp plugin: cna_query_quota: na_server_invoke_elem failed for host %s: %s",
+ host->name, na_results_reason (data));
+ na_elem_free (data);
+ return (-1);
+ }
+
+ status = cna_handle_quota_data (host, host->cfg_quota, data);
+
+ if (status == 0)
+ host->cfg_quota->interval.last_read = now;
+
+ na_elem_free (data);
+ return (status);
+} /* }}} int cna_query_quota */
+
+/* Data corresponding to <SnapVault /> */
+static int cna_handle_snapvault_data (const char *hostname, /* {{{ */
+ cfg_snapvault_t *cfg_snapvault, na_elem_t *data, cdtime_t interval)
+{
+ na_elem_t *status;
+ na_elem_iter_t status_iter;
+
+ status = na_elem_child (data, "status-list");
+ if (! status) {
+ ERROR ("netapp plugin: SnapVault status record missing status-list");
+ return (0);
+ }
+
+ status_iter = na_child_iterator (status);
+ for (status = na_iterator_next (&status_iter);
+ status != NULL;
+ status = na_iterator_next (&status_iter))
+ {
+ const char *dest_sys, *dest_path, *src_sys, *src_path;
+ char plugin_instance[DATA_MAX_NAME_LEN];
+ uint64_t value;
+
+ dest_sys = na_child_get_string (status, "destination-system");
+ dest_path = na_child_get_string (status, "destination-path");
+ src_sys = na_child_get_string (status, "source-system");
+ src_path = na_child_get_string (status, "source-path");
+
+ if ((! dest_sys) || (! dest_path) || (! src_sys) || (! src_path))
+ continue;
+
+ value = na_child_get_uint64 (status, "lag-time", UINT64_MAX);
+ if (value == UINT64_MAX) /* no successful baseline transfer yet */
+ continue;
+
+ /* possible TODO: make plugin instance configurable */
+ ssnprintf (plugin_instance, sizeof (plugin_instance),
+ "snapvault-%s", dest_path);
+ submit_double (hostname, plugin_instance, /* type = */ "delay", NULL,
+ (double)value, /* timestamp = */ 0, interval);
+
+ value = na_child_get_uint64 (status, "last-transfer-duration", UINT64_MAX);
+ if (value != UINT64_MAX)
+ submit_double (hostname, plugin_instance, /* type = */ "duration", "last_transfer",
+ (double)value, /* timestamp = */ 0, interval);
+
+ value = na_child_get_uint64 (status, "transfer-progress", UINT64_MAX);
+ if (value == UINT64_MAX)
+ value = na_child_get_uint64 (status, "last-transfer-size", UINT64_MAX);
+ if (value != UINT64_MAX) {
+ value *= 1024; /* this is kilobytes */
+ submit_derive (hostname, plugin_instance, /* type = */ "if_rx_octets", "transferred",
+ value, /* timestamp = */ 0, interval);
+ }
+ } /* for (status) */
+
+ return (0);
+} /* }}} int cna_handle_snapvault_data */
+
+static int cna_handle_snapvault_iter (host_config_t *host, /* {{{ */
+ na_elem_t *data)
+{
+ const char *tag;
+
+ uint32_t records_count;
+ uint32_t i;
+
+ records_count = na_child_get_uint32 (data, "records", UINT32_MAX);
+ if (records_count == UINT32_MAX)
+ return 0;
+
+ tag = na_child_get_string (data, "tag");
+ if (! tag)
+ return 0;
+
+ DEBUG ("netapp plugin: Iterating %u SV records (tag = %s)", records_count, tag);
+
+ for (i = 0; i < records_count; ++i) {
+ na_elem_t *elem;
+
+ elem = na_server_invoke (host->srv,
+ "snapvault-secondary-relationship-status-list-iter-next",
+ "maximum", "1", "tag", tag, NULL);
+
+ if (na_results_status (elem) != NA_OK)
+ {
+ ERROR ("netapp plugin: cna_handle_snapvault_iter: "
+ "na_server_invoke failed for host %s: %s",
+ host->name, na_results_reason (data));
+ na_elem_free (elem);
+ return (-1);
+ }
+
+ cna_handle_snapvault_data (host->name, host->cfg_snapvault, elem,
+ host->cfg_snapvault->interval.interval);
+ na_elem_free (elem);
+ }
+
+ na_elem_free (na_server_invoke (host->srv,
+ "snapvault-secondary-relationship-status-list-iter-end",
+ "tag", tag, NULL));
+ return (0);
+} /* }}} int cna_handle_snapvault_iter */
+
+static int cna_setup_snapvault (cfg_snapvault_t *sv) /* {{{ */
+{
+ if (sv == NULL)
+ return (EINVAL);
+
+ if (sv->query != NULL)
+ return (0);
+
+ sv->query = na_elem_new ("snapvault-secondary-relationship-status-list-iter-start");
+ if (sv->query == NULL)
+ {
+ ERROR ("netapp plugin: na_elem_new failed.");
+ return (-1);
+ }
+
+ return (0);
+} /* }}} int cna_setup_snapvault */
+
+static int cna_query_snapvault (host_config_t *host) /* {{{ */
+{
+ na_elem_t *data;
+ int status;
+ cdtime_t now;
+
+ if (host == NULL)
+ return EINVAL;
+
+ if (host->cfg_snapvault == NULL)
+ return 0;
+
+ now = cdtime ();
+ if ((host->cfg_snapvault->interval.interval + host->cfg_snapvault->interval.last_read) > now)
+ return (0);
+
+ status = cna_setup_snapvault (host->cfg_snapvault);
+ if (status != 0)
+ return (status);
+ assert (host->cfg_snapvault->query != NULL);
+
+ data = na_server_invoke_elem (host->srv, host->cfg_snapvault->query);
+ if (na_results_status (data) != NA_OK)
+ {
+ ERROR ("netapp plugin: cna_query_snapvault: na_server_invoke_elem failed for host %s: %s",
+ host->name, na_results_reason (data));
+ na_elem_free (data);
+ return (-1);
+ }
+
+ status = cna_handle_snapvault_iter (host, data);
+
+ if (status == 0)
+ host->cfg_snapvault->interval.last_read = now;
+
+ na_elem_free (data);
+ return (status);
+} /* }}} int cna_query_snapvault */
+