+ return (0);
+} /* }}} int cna_setup_volume_usage */
+
+static int cna_query_volume_usage (host_config_t *host) /* {{{ */
+{
+ na_elem_t *data;
+ int status;
+ cdtime_t now;
+
+ if (host == NULL)
+ return (EINVAL);
+
+ /* If the user did not configure volume_usage statistics, return without
+ * doing anything. */
+ if (host->cfg_volume_usage == NULL)
+ return (0);
+
+ now = cdtime ();
+ if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
+ return (0);
+
+ status = cna_setup_volume_usage (host->cfg_volume_usage);
+ if (status != 0)
+ return (status);
+ assert (host->cfg_volume_usage->query != NULL);
+
+ data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
+ if (na_results_status (data) != NA_OK)
+ {
+ ERROR ("netapp plugin: cna_query_volume_usage: 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_usage_data (host, host->cfg_volume_usage, data);
+
+ if (status == 0)
+ host->cfg_volume_usage->interval.last_read = now;
+
+ na_elem_free (data);
+ return (status);
+} /* }}} int cna_query_volume_usage */
+
+/* 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 */
+
+/* Data corresponding to <System /> */
+static int cna_handle_system_data (const char *hostname, /* {{{ */
+ cfg_system_t *cfg_system, na_elem_t *data, int interval)
+{
+ na_elem_t *instances;
+ na_elem_t *counter;
+ na_elem_iter_t counter_iter;
+
+ derive_t disk_read = 0, disk_written = 0;
+ derive_t net_recv = 0, net_sent = 0;
+ derive_t cpu_busy = 0, cpu_total = 0;
+ uint32_t counter_flags = 0;
+
+ const char *instance;
+ cdtime_t timestamp;
+
+ timestamp = cna_child_get_cdtime (data);
+
+ instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
+ if (instances == NULL)
+ {
+ ERROR ("netapp plugin: cna_handle_system_data: "
+ "na_elem_child (\"instances\") failed "
+ "for host %s.", hostname);
+ return (-1);
+ }
+
+ instance = na_child_get_string (instances, "name");
+ if (instance == NULL)
+ {
+ ERROR ("netapp plugin: cna_handle_system_data: "
+ "na_child_get_string (\"name\") failed "
+ "for host %s.", hostname);
+ return (-1);
+ }
+
+ counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
+ for (counter = na_iterator_next (&counter_iter);
+ counter != NULL;
+ counter = na_iterator_next (&counter_iter))
+ {
+ const char *name;
+ uint64_t value;
+
+ name = na_child_get_string(counter, "name");
+ if (name == NULL)
+ continue;
+
+ value = na_child_get_uint64(counter, "value", UINT64_MAX);
+ if (value == UINT64_MAX)
+ continue;
+
+ if (!strcmp(name, "disk_data_read")) {
+ disk_read = (derive_t) (value * 1024);
+ counter_flags |= 0x01;
+ } else if (!strcmp(name, "disk_data_written")) {
+ disk_written = (derive_t) (value * 1024);
+ counter_flags |= 0x02;
+ } else if (!strcmp(name, "net_data_recv")) {
+ net_recv = (derive_t) (value * 1024);
+ counter_flags |= 0x04;
+ } else if (!strcmp(name, "net_data_sent")) {
+ net_sent = (derive_t) (value * 1024);
+ counter_flags |= 0x08;
+ } else if (!strcmp(name, "cpu_busy")) {
+ cpu_busy = (derive_t) value;
+ counter_flags |= 0x10;
+ } else if (!strcmp(name, "cpu_elapsed_time")) {
+ cpu_total = (derive_t) value;
+ counter_flags |= 0x20;
+ } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
+ && (value > 0) && (strlen(name) > 4)
+ && (!strcmp(name + strlen(name) - 4, "_ops"))) {
+ submit_derive (hostname, instance, "disk_ops_complex", name,
+ (derive_t) value, timestamp, interval);
+ }
+ } /* for (counter) */
+
+ if ((cfg_system->flags & CFG_SYSTEM_DISK)
+ && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
+ submit_two_derive (hostname, instance, "disk_octets", NULL,
+ disk_read, disk_written, timestamp, interval);
+
+ if ((cfg_system->flags & CFG_SYSTEM_NET)
+ && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
+ submit_two_derive (hostname, instance, "if_octets", NULL,
+ net_recv, net_sent, timestamp, interval);
+
+ if ((cfg_system->flags & CFG_SYSTEM_CPU)
+ && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
+ {
+ submit_derive (hostname, instance, "cpu", "system",
+ cpu_busy, timestamp, interval);
+ submit_derive (hostname, instance, "cpu", "idle",
+ cpu_total - cpu_busy, timestamp, interval);
+ }
+
+ return (0);
+} /* }}} int cna_handle_system_data */
+
+static int cna_setup_system (cfg_system_t *cs) /* {{{ */
+{
+ if (cs == NULL)
+ return (EINVAL);
+
+ if (cs->query != NULL)
+ return (0);
+
+ cs->query = na_elem_new ("perf-object-get-instances");
+ if (cs->query == NULL)
+ {
+ ERROR ("netapp plugin: na_elem_new failed.");
+ return (-1);
+ }
+ na_child_add_string (cs->query, "objectname", "system");
+
+ return (0);
+} /* }}} int cna_setup_system */
+
+static int cna_query_system (host_config_t *host) /* {{{ */
+{
+ na_elem_t *data;
+ int status;
+ cdtime_t now;
+
+ if (host == NULL)
+ return (EINVAL);
+
+ /* If system statistics were not configured, return without doing anything. */
+ if (host->cfg_system == NULL)
+ return (0);
+
+ now = cdtime ();
+ if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
+ return (0);
+
+ status = cna_setup_system (host->cfg_system);
+ if (status != 0)
+ return (status);
+ assert (host->cfg_system->query != NULL);
+
+ data = na_server_invoke_elem(host->srv, host->cfg_system->query);
+ if (na_results_status (data) != NA_OK)
+ {
+ ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed for host %s: %s",
+ host->name, na_results_reason (data));
+ na_elem_free (data);
+ return (-1);
+ }
+
+ status = cna_handle_system_data (host->name, host->cfg_system, data,
+ host->cfg_system->interval.interval);
+
+ if (status == 0)
+ host->cfg_system->interval.last_read = now;
+
+ na_elem_free (data);
+ return (status);
+} /* }}} int cna_query_system */
+
+/*
+ * Configuration handling
+ */
+/* Sets a given flag if the boolean argument is true and unsets the flag if it
+ * is false. On error, the flag-field is not changed. */
+static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
+ uint32_t *flags, uint32_t flag)
+{
+ if ((ci == NULL) || (flags == NULL))
+ return (EINVAL);
+
+ if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
+ {
+ WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
+ ci->key);
+ return (-1);
+ }
+
+ if (ci->values[0].value.boolean)
+ *flags |= flag;
+ else
+ *flags &= ~flag;
+
+ return (0);
+} /* }}} int cna_config_bool_to_flag */
+
+/* Handling of the "Interval" option which is allowed in every block. */
+static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
+ cna_interval_t *out_interval)
+{
+ cdtime_t tmp = 0;
+ int status;
+
+ status = cf_util_get_cdtime (ci, &tmp);
+ if (status != 0)
+ return (status);
+
+ out_interval->interval = tmp;
+ out_interval->last_read = 0;
+
+ return (0);
+} /* }}} int cna_config_get_interval */
+
+/* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
+ * <VolumePerf /> block. */
+static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
+ const oconfig_item_t *ci)
+{
+ char *name;
+ ignorelist_t * il;
+
+ if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
+ {
+ WARNING ("netapp plugin: The %s option requires exactly one string argument.",
+ ci->key);
+ return;
+ }
+
+ name = ci->values[0].value.string;
+
+ if (strcasecmp ("GetIO", ci->key) == 0)
+ il = cvp->il_octets;
+ else if (strcasecmp ("GetOps", ci->key) == 0)
+ il = cvp->il_operations;
+ else if (strcasecmp ("GetLatency", ci->key) == 0)
+ il = cvp->il_latency;
+ else
+ return;
+
+ ignorelist_add (il, name);
+} /* }}} void cna_config_volume_perf_option */
+
+/* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
+ * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
+static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
+ const oconfig_item_t *ci)
+{
+ ignorelist_t *il;
+
+ if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
+ {
+ WARNING ("netapp plugin: The %s option requires exactly one string argument.",
+ ci->key);
+ return;
+ }
+
+ if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
+ il = cvp->il_octets;
+ else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
+ il = cvp->il_operations;
+ else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
+ il = cvp->il_latency;
+ else
+ return;
+
+ if (ci->values[0].value.boolean)
+ ignorelist_set_invert (il, /* invert = */ 0);
+ else
+ ignorelist_set_invert (il, /* invert = */ 1);
+} /* }}} void cna_config_volume_perf_default */
+
+/* Corresponds to a <Disks /> block */
+/*
+ * <VolumePerf>
+ * GetIO "vol0"
+ * GetIO "vol1"
+ * IgnoreSelectedIO false
+ *
+ * GetOps "vol0"
+ * GetOps "vol2"
+ * IgnoreSelectedOps false
+ *
+ * GetLatency "vol2"
+ * GetLatency "vol3"
+ * IgnoreSelectedLatency false
+ * </VolumePerf>
+ */
+/* Corresponds to a <VolumePerf /> block */
+static int cna_config_volume_performance (host_config_t *host, /* {{{ */
+ const oconfig_item_t *ci)
+{
+ cfg_volume_perf_t *cfg_volume_perf;
+ int i;
+
+ if ((host == NULL) || (ci == NULL))
+ return (EINVAL);
+
+ if (host->cfg_volume_perf == NULL)
+ {
+ cfg_volume_perf = malloc (sizeof (*cfg_volume_perf));
+ if (cfg_volume_perf == NULL)
+ return (ENOMEM);
+ memset (cfg_volume_perf, 0, sizeof (*cfg_volume_perf));
+
+ /* Set default flags */
+ cfg_volume_perf->query = NULL;
+ cfg_volume_perf->volumes = NULL;
+
+ cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
+ if (cfg_volume_perf->il_octets == NULL)
+ {
+ sfree (cfg_volume_perf);
+ return (ENOMEM);
+ }
+
+ cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
+ if (cfg_volume_perf->il_operations == NULL)
+ {
+ ignorelist_free (cfg_volume_perf->il_octets);
+ sfree (cfg_volume_perf);
+ return (ENOMEM);
+ }
+
+ cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
+ if (cfg_volume_perf->il_latency == NULL)
+ {
+ ignorelist_free (cfg_volume_perf->il_octets);
+ ignorelist_free (cfg_volume_perf->il_operations);
+ sfree (cfg_volume_perf);
+ return (ENOMEM);
+ }
+
+ host->cfg_volume_perf = cfg_volume_perf;
+ }
+ cfg_volume_perf = host->cfg_volume_perf;
+
+ for (i = 0; i < ci->children_num; ++i) {
+ oconfig_item_t *item = ci->children + i;