+ 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;
+
+ /* if (!item || !item->key || !*item->key) continue; */
+ if (strcasecmp(item->key, "Interval") == 0)
+ cna_config_get_interval (item, &cfg_volume_perf->interval);
+ else if (!strcasecmp(item->key, "GetIO"))
+ cna_config_volume_perf_option (cfg_volume_perf, item);
+ else if (!strcasecmp(item->key, "GetOps"))
+ cna_config_volume_perf_option (cfg_volume_perf, item);
+ else if (!strcasecmp(item->key, "GetLatency"))
+ cna_config_volume_perf_option (cfg_volume_perf, item);
+ else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
+ cna_config_volume_perf_default (cfg_volume_perf, item);
+ else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
+ cna_config_volume_perf_default (cfg_volume_perf, item);
+ else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
+ cna_config_volume_perf_default (cfg_volume_perf, item);
+ else
+ WARNING ("netapp plugin: The option %s is not allowed within "
+ "`VolumePerf' blocks.", item->key);
+ }
+
+ return (0);
+} /* }}} int cna_config_volume_performance */
+
+/* Handling of the "GetCapacity" and "GetSnapshot" options within a
+ * <VolumeUsage /> block. */
+static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
+ 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 ("GetCapacity", ci->key) == 0)
+ il = cvu->il_capacity;
+ else if (strcasecmp ("GetSnapshot", ci->key) == 0)
+ il = cvu->il_snapshot;
+ else
+ return;
+
+ ignorelist_add (il, name);
+} /* }}} void cna_config_volume_usage_option */
+
+/* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
+ * options within a <VolumeUsage /> block. */
+static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
+ 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 ("IgnoreSelectedCapacity", ci->key) == 0)
+ il = cvu->il_capacity;
+ else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
+ il = cvu->il_snapshot;
+ 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_usage_default */
+
+/* Corresponds to a <Quota /> block */
+static int cna_config_quota (host_config_t *host, oconfig_item_t *ci) /* {{{ */
+{
+ cfg_quota_t *cfg_quota;
+ int i;
+
+ if ((host == NULL) || (ci == NULL))
+ return (EINVAL);
+
+ if (host->cfg_quota == NULL)
+ {
+ cfg_quota = malloc (sizeof (*cfg_quota));
+ if (cfg_quota == NULL)
+ return (ENOMEM);
+ memset (cfg_quota, 0, sizeof (*cfg_quota));
+ cfg_quota->query = NULL;