#include "collectd.h"
-#include "common.h"
-#include "utils_ignorelist.h"
+#include "utils/common/common.h"
+#include "utils/ignorelist/ignorelist.h"
#include <netapp_api.h>
#include <netapp_errno.h>
disk_t *d;
if ((cd == NULL) || (name == NULL))
- return (NULL);
+ return NULL;
for (d = cd->disks; d != NULL; d = d->next) {
if (strcmp(d->name, name) == 0)
d = calloc(1, sizeof(*d));
if (d == NULL)
- return (NULL);
+ return NULL;
d->next = NULL;
d->name = strdup(name);
if (d->name == NULL) {
sfree(d);
- return (NULL);
+ return NULL;
}
d->next = cd->disks;
int ignore_snapshot = 0;
if ((cvu == NULL) || (name == NULL))
- return (NULL);
+ return NULL;
last = cvu->volumes;
while (last != NULL) {
if (strcmp(last->name, name) == 0)
- return (last);
+ return last;
if (last->next == NULL)
break;
ignore_capacity = ignorelist_match(cvu->il_capacity, name);
ignore_snapshot = ignorelist_match(cvu->il_snapshot, name);
if ((ignore_capacity != 0) && (ignore_snapshot != 0))
- return (NULL);
+ return NULL;
/* Not found: allocate. */
new = calloc(1, sizeof(*new));
if (new == NULL)
- return (NULL);
+ return NULL;
new->next = NULL;
new->name = strdup(name);
if (new->name == NULL) {
sfree(new);
- return (NULL);
+ return NULL;
}
if (ignore_capacity == 0)
else
last->next = new;
- return (new);
+ return new;
} /* }}} data_volume_usage_t *get_volume_usage */
static data_volume_perf_t *get_volume_perf(cfg_volume_perf_t *cvp, /* {{{ */
int ignore_latency = 0;
if ((cvp == NULL) || (name == NULL))
- return (NULL);
+ return NULL;
last = cvp->volumes;
while (last != NULL) {
if (strcmp(last->name, name) == 0)
- return (last);
+ return last;
if (last->next == NULL)
break;
ignore_operations = ignorelist_match(cvp->il_operations, name);
ignore_latency = ignorelist_match(cvp->il_latency, name);
if ((ignore_octets != 0) || (ignore_operations != 0) || (ignore_latency != 0))
- return (NULL);
+ return NULL;
/* Not found: allocate. */
new = calloc(1, sizeof(*new));
if (new == NULL)
- return (NULL);
+ return NULL;
new->next = NULL;
new->name = strdup(name);
if (new->name == NULL) {
sfree(new);
- return (NULL);
+ return NULL;
}
if (ignore_octets == 0)
else
last->next = new;
- return (new);
+ return new;
} /* }}} data_volume_perf_t *get_volume_perf */
/*
if (type_inst != NULL)
sstrncpy(vl.type_instance, type_inst, sizeof(vl.type_instance));
- return (plugin_dispatch_values(&vl));
+ return plugin_dispatch_values(&vl);
} /* }}} int submit_uint64 */
static int submit_two_derive(const char *host,
{.derive = val0}, {.derive = val1},
};
- return (submit_values(host, plugin_inst, type, type_inst, values,
- STATIC_ARRAY_SIZE(values), 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) {
- return (submit_values(host, plugin_inst, type, type_inst,
- &(value_t){.derive = counter}, 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, /* {{{ */
{.gauge = val0}, {.gauge = val1},
};
- return (submit_values(host, plugin_inst, type, type_inst, values,
- STATIC_ARRAY_SIZE(values), 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) {
- return (submit_values(host, plugin_inst, type, type_inst,
- &(value_t){.gauge = d}, 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
v.gauge = 100.0 * ((gauge_t)hits) / ((gauge_t)(hits + misses));
}
- return (submit_values(host, plugin_inst, "cache_ratio", type_inst, &v, 1,
- timestamp, interval));
+ return submit_values(host, plugin_inst, "cache_ratio", type_inst, &v, 1,
+ timestamp, interval);
} /* }}} int submit_cache_ratio */
/* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
/* Copy HAVE_* flags */
old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
- return (0);
+ return 0;
} /* }}} int submit_wafl_data */
/* Submits volume performance data to the daemon, taking care to honor and
char plugin_instance[DATA_MAX_NAME_LEN];
if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL))
- return (-1);
+ return -1;
- ssnprintf(plugin_instance, sizeof(plugin_instance), "volume-%s",
- old_data->name);
+ snprintf(plugin_instance, sizeof(plugin_instance), "volume-%s",
+ old_data->name);
/* Check for and submit disk-octet values */
if (HAS_ALL_FLAGS(old_data->flags, CFG_VOLUME_PERF_IO) &&
- HAS_ALL_FLAGS(new_data->flags, HAVE_VOLUME_PERF_BYTES_READ |
- HAVE_VOLUME_PERF_BYTES_WRITE)) {
+ HAS_ALL_FLAGS(new_data->flags,
+ HAVE_VOLUME_PERF_BYTES_READ |
+ HAVE_VOLUME_PERF_BYTES_WRITE)) {
submit_two_derive(
hostname, plugin_instance, "disk_octets", /* type instance = */ NULL,
(derive_t)new_data->read_bytes, (derive_t)new_data->write_bytes,
}
/* Check for, calculate and submit disk-latency values */
- if (HAS_ALL_FLAGS(old_data->flags, CFG_VOLUME_PERF_LATENCY |
- HAVE_VOLUME_PERF_OPS_READ |
- HAVE_VOLUME_PERF_OPS_WRITE |
- HAVE_VOLUME_PERF_LATENCY_READ |
- HAVE_VOLUME_PERF_LATENCY_WRITE) &&
- HAS_ALL_FLAGS(new_data->flags, HAVE_VOLUME_PERF_OPS_READ |
- HAVE_VOLUME_PERF_OPS_WRITE |
- HAVE_VOLUME_PERF_LATENCY_READ |
- HAVE_VOLUME_PERF_LATENCY_WRITE)) {
+ if (HAS_ALL_FLAGS(old_data->flags,
+ CFG_VOLUME_PERF_LATENCY | HAVE_VOLUME_PERF_OPS_READ |
+ HAVE_VOLUME_PERF_OPS_WRITE |
+ HAVE_VOLUME_PERF_LATENCY_READ |
+ HAVE_VOLUME_PERF_LATENCY_WRITE) &&
+ HAS_ALL_FLAGS(new_data->flags,
+ HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE |
+ HAVE_VOLUME_PERF_LATENCY_READ |
+ HAVE_VOLUME_PERF_LATENCY_WRITE)) {
gauge_t latency_per_op_read;
gauge_t latency_per_op_write;
/* Copy the HAVE_* flags */
old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
- return (0);
+ return 0;
} /* }}} int submit_volume_perf_data */
static cdtime_t cna_child_get_cdtime(na_elem_t *data) /* {{{ */
t = (time_t)na_child_get_uint64(data, "timestamp", /* default = */ 0);
- return (TIME_T_TO_CDTIME_T(t));
+ return TIME_T_TO_CDTIME_T(t);
} /* }}} cdtime_t cna_child_get_cdtime */
/*
"na_elem_child (\"instances\") failed "
"for host %s.",
hostname);
- return (-1);
+ return -1;
}
plugin_inst = na_child_get_string(instances, "name");
"na_child_get_string (\"name\") failed "
"for host %s.",
hostname);
- return (-1);
+ return -1;
}
/* Iterate over all counters */
}
}
- return (
- submit_wafl_data(hostname, plugin_inst, cfg_wafl, &perf_data, interval));
+ return submit_wafl_data(hostname, plugin_inst, cfg_wafl, &perf_data,
+ interval);
} /* }}} void cna_handle_wafl_data */
static int cna_setup_wafl(cfg_wafl_t *cw) /* {{{ */
na_elem_t *e;
if (cw == NULL)
- return (EINVAL);
+ return EINVAL;
if (cw->query != NULL)
- return (0);
+ return 0;
cw->query = na_elem_new("perf-object-get-instances");
if (cw->query == NULL) {
ERROR("netapp plugin: na_elem_new failed.");
- return (-1);
+ return -1;
}
na_child_add_string(cw->query, "objectname", "wafl");
na_elem_free(cw->query);
cw->query = NULL;
ERROR("netapp plugin: na_elem_new failed.");
- return (-1);
+ return -1;
}
na_child_add_string(e, "counter", "name_cache_hit");
na_child_add_string(e, "counter", "name_cache_miss");
na_child_add(cw->query, e);
- return (0);
+ return 0;
} /* }}} int cna_setup_wafl */
static int cna_query_wafl(host_config_t *host) /* {{{ */
cdtime_t now;
if (host == NULL)
- return (EINVAL);
+ return EINVAL;
/* If WAFL was not configured, return without doing anything. */
if (host->cfg_wafl == NULL)
- return (0);
+ return 0;
now = cdtime();
if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) >
now)
- return (0);
+ return 0;
status = cna_setup_wafl(host->cfg_wafl);
if (status != 0)
- return (status);
+ return status;
assert(host->cfg_wafl->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
"host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
- return (-1);
+ return -1;
}
status = cna_handle_wafl_data(host->name, host->cfg_wafl, data,
host->cfg_wafl->interval.last_read = now;
na_elem_free(data);
- return (status);
+ return status;
} /* }}} int cna_query_wafl */
/* Data corresponding to <Disks /> */
disk_t *worst_disk = NULL;
if ((cfg_disk == NULL) || (data == NULL))
- return (EINVAL);
+ return EINVAL;
timestamp = cna_child_get_cdtime(data);
"na_elem_child (\"instances\") failed "
"for host %s.",
hostname);
- return (-1);
+ return -1;
}
/* Iterate over all children */
submit_double(hostname, "system", "percent", "disk_busy",
worst_disk->disk_busy_percent, timestamp, interval);
- return (0);
+ return 0;
} /* }}} int cna_handle_disk_data */
static int cna_setup_disk(cfg_disk_t *cd) /* {{{ */
na_elem_t *e;
if (cd == NULL)
- return (EINVAL);
+ return EINVAL;
if (cd->query != NULL)
- return (0);
+ return 0;
cd->query = na_elem_new("perf-object-get-instances");
if (cd->query == NULL) {
ERROR("netapp plugin: na_elem_new failed.");
- return (-1);
+ return -1;
}
na_child_add_string(cd->query, "objectname", "disk");
na_elem_free(cd->query);
cd->query = NULL;
ERROR("netapp plugin: na_elem_new failed.");
- return (-1);
+ return -1;
}
na_child_add_string(e, "counter", "disk_busy");
na_child_add_string(e, "counter", "base_for_disk_busy");
na_child_add(cd->query, e);
- return (0);
+ return 0;
} /* }}} int cna_setup_disk */
static int cna_query_disk(host_config_t *host) /* {{{ */
cdtime_t now;
if (host == NULL)
- return (EINVAL);
+ return EINVAL;
/* If the user did not configure disk statistics, return without doing
* anything. */
if (host->cfg_disk == NULL)
- return (0);
+ return 0;
now = cdtime();
if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) >
now)
- return (0);
+ return 0;
status = cna_setup_disk(host->cfg_disk);
if (status != 0)
- return (status);
+ return status;
assert(host->cfg_disk->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
"host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
- return (-1);
+ return -1;
}
status = cna_handle_disk_data(host->name, host->cfg_disk, data,
host->cfg_disk->interval.last_read = now;
na_elem_free(data);
- return (status);
+ return status;
} /* }}} int cna_query_disk */
/* Data corresponding to <VolumePerf /> */
"na_elem_child (\"instances\") failed "
"for host %s.",
hostname);
- return (-1);
+ return -1;
}
iter_instances = na_child_iterator(elem_instances);
submit_volume_perf_data(hostname, v, &perf_data, interval);
} /* for (volume) */
- return (0);
+ 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);
+ return EINVAL;
if (cd->query != NULL)
- return (0);
+ return 0;
cd->query = na_elem_new("perf-object-get-instances");
if (cd->query == NULL) {
ERROR("netapp plugin: na_elem_new failed.");
- return (-1);
+ return -1;
}
na_child_add_string(cd->query, "objectname", "volume");
na_elem_free(cd->query);
cd->query = NULL;
ERROR("netapp plugin: na_elem_new failed.");
- return (-1);
+ return -1;
}
na_child_add_string(e, "counter", "read_ops");
na_child_add_string(e, "counter", "write_ops");
na_child_add_string(e, "counter", "write_latency");
na_child_add(cd->query, e);
- return (0);
+ return 0;
} /* }}} int cna_setup_volume_perf */
static int cna_query_volume_perf(host_config_t *host) /* {{{ */
cdtime_t now;
if (host == NULL)
- return (EINVAL);
+ return EINVAL;
/* If the user did not configure volume performance statistics, return
* without doing anything. */
if (host->cfg_volume_perf == NULL)
- return (0);
+ return 0;
now = cdtime();
if ((host->cfg_volume_perf->interval.interval +
host->cfg_volume_perf->interval.last_read) > now)
- return (0);
+ return 0;
status = cna_setup_volume_perf(host->cfg_volume_perf);
if (status != 0)
- return (status);
+ return status;
assert(host->cfg_volume_perf->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_volume_perf->query);
"for host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
- return (-1);
+ return -1;
}
status =
host->cfg_volume_perf->interval.last_read = now;
na_elem_free(data);
- return (status);
+ return status;
} /* }}} int cna_query_volume_perf */
/* Data corresponding to <VolumeUsage /> */
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);
+ snprintf(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 (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;
/* 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 (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 {
"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))
+ 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);
v->flags &= ~HAVE_VOLUME_USAGE_ALL;
} /* for (v = cfg_volume->volumes) */
- return (0);
+ return 0;
} /* }}} int cna_submit_volume_usage_data */
/* Switch the state of a volume between online and offline and send out a
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);
+ snprintf(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);
+ snprintf(n.message, sizeof(n.message), "Volume %s is now offline.",
+ v->name);
v->flags |= IS_VOLUME_USAGE_OFFLINE;
}
- return (plugin_dispatch_notification(&n));
+ return plugin_dispatch_notification(&n);
} /* }}} int cna_change_volume_status */
static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
"na_elem_child (\"volumes\") failed "
"for host %s.",
host->name);
- return (-1);
+ return -1;
}
iter_volume = na_child_iterator(elem_volumes);
}
} /* for (elem_volume) */
- return (cna_submit_volume_usage_data(
- host->name, cfg_volume, host->cfg_volume_usage->interval.interval));
+ return cna_submit_volume_usage_data(
+ host->name, cfg_volume, host->cfg_volume_usage->interval.interval);
} /* }}} int cna_handle_volume_usage_data */
static int cna_setup_volume_usage(cfg_volume_usage_t *cvu) /* {{{ */
{
if (cvu == NULL)
- return (EINVAL);
+ return EINVAL;
if (cvu->query != NULL)
- return (0);
+ return 0;
cvu->query = na_elem_new("volume-list-info");
if (cvu->query == NULL) {
ERROR("netapp plugin: na_elem_new failed.");
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
} /* }}} int cna_setup_volume_usage */
static int cna_query_volume_usage(host_config_t *host) /* {{{ */
cdtime_t now;
if (host == NULL)
- return (EINVAL);
+ return EINVAL;
/* If the user did not configure volume_usage statistics, return without
* doing anything. */
if (host->cfg_volume_usage == NULL)
- return (0);
+ return 0;
now = cdtime();
if ((host->cfg_volume_usage->interval.interval +
host->cfg_volume_usage->interval.last_read) > now)
- return (0);
+ return 0;
status = cna_setup_volume_usage(host->cfg_volume_usage);
if (status != 0)
- return (status);
+ return status;
assert(host->cfg_volume_usage->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
"for host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
- return (-1);
+ return -1;
}
status = cna_handle_volume_usage_data(host, host->cfg_volume_usage, data);
host->cfg_volume_usage->interval.last_read = now;
na_elem_free(data);
- return (status);
+ return status;
} /* }}} int cna_query_volume_usage */
/* Data corresponding to <Quota /> */
"na_elem_child (\"quotas\") failed "
"for host %s.",
host->name);
- return (-1);
+ return -1;
}
iter_quota = na_child_iterator(elem_quotas);
if (volume_name == NULL)
continue;
- ssnprintf(plugin_instance, sizeof(plugin_instance), "quota-%s-%s",
- volume_name, tree_name);
+ snprintf(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) {
}
} /* for (elem_quota) */
- return (0);
+ return 0;
} /* }}} int cna_handle_volume_usage_data */
static int cna_setup_quota(cfg_quota_t *cq) /* {{{ */
{
if (cq == NULL)
- return (EINVAL);
+ return EINVAL;
if (cq->query != NULL)
- return (0);
+ return 0;
cq->query = na_elem_new("quota-report");
if (cq->query == NULL) {
ERROR("netapp plugin: na_elem_new failed.");
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
} /* }}} int cna_setup_quota */
static int cna_query_quota(host_config_t *host) /* {{{ */
cdtime_t now;
if (host == NULL)
- return (EINVAL);
+ return EINVAL;
/* If the user did not configure quota statistics, return without
* doing anything. */
if (host->cfg_quota == NULL)
- return (0);
+ return 0;
now = cdtime();
if ((host->cfg_quota->interval.interval +
host->cfg_quota->interval.last_read) > now)
- return (0);
+ return 0;
status = cna_setup_quota(host->cfg_quota);
if (status != 0)
- return (status);
+ return status;
assert(host->cfg_quota->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_quota->query);
"host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
- return (-1);
+ return -1;
}
status = cna_handle_quota_data(host, host->cfg_quota, data);
host->cfg_quota->interval.last_read = now;
na_elem_free(data);
- return (status);
+ return status;
} /* }}} int cna_query_quota */
/* Data corresponding to <SnapVault /> */
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);
+ return 0;
}
na_elem_iter_t status_iter = na_child_iterator(status_list);
continue;
/* possible TODO: make plugin instance configurable */
- ssnprintf(plugin_instance, sizeof(plugin_instance), "snapvault-%s",
- dest_path);
+ snprintf(plugin_instance, sizeof(plugin_instance), "snapvault-%s",
+ dest_path);
submit_double(hostname, plugin_instance, /* type = */ "delay", NULL,
(double)value, /* timestamp = */ 0, interval);
}
} /* for (status) */
- return (0);
+ return 0;
} /* }}} int cna_handle_snapvault_data */
static int cna_handle_snapvault_iter(host_config_t *host, /* {{{ */
"na_server_invoke failed for host %s: %s",
host->name, na_results_reason(data));
na_elem_free(elem);
- return (-1);
+ return -1;
}
cna_handle_snapvault_data(host->name, host->cfg_snapvault, elem,
na_elem_free(na_server_invoke(
host->srv, "snapvault-secondary-relationship-status-list-iter-end", "tag",
tag, NULL));
- return (0);
+ return 0;
} /* }}} int cna_handle_snapvault_iter */
static int cna_setup_snapvault(cfg_snapvault_t *sv) /* {{{ */
{
if (sv == NULL)
- return (EINVAL);
+ return EINVAL;
if (sv->query != NULL)
- return (0);
+ 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 -1;
}
- return (0);
+ return 0;
} /* }}} int cna_setup_snapvault */
static int cna_query_snapvault(host_config_t *host) /* {{{ */
now = cdtime();
if ((host->cfg_snapvault->interval.interval +
host->cfg_snapvault->interval.last_read) > now)
- return (0);
+ return 0;
status = cna_setup_snapvault(host->cfg_snapvault);
if (status != 0)
- return (status);
+ return status;
assert(host->cfg_snapvault->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_snapvault->query);
"for host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
- return (-1);
+ return -1;
}
status = cna_handle_snapvault_iter(host, data);
host->cfg_snapvault->interval.last_read = now;
na_elem_free(data);
- return (status);
+ return status;
} /* }}} int cna_query_snapvault */
/* Data corresponding to <System /> */
"na_elem_child (\"instances\") failed "
"for host %s.",
hostname);
- return (-1);
+ return -1;
}
instance = na_child_get_string(instances, "name");
"na_child_get_string (\"name\") failed "
"for host %s.",
hostname);
- return (-1);
+ return -1;
}
counter_iter = na_child_iterator(na_elem_child(instances, "counters"));
timestamp, interval);
}
- return (0);
+ return 0;
} /* }}} int cna_handle_system_data */
static int cna_setup_system(cfg_system_t *cs) /* {{{ */
{
if (cs == NULL)
- return (EINVAL);
+ return EINVAL;
if (cs->query != NULL)
- return (0);
+ return 0;
cs->query = na_elem_new("perf-object-get-instances");
if (cs->query == NULL) {
ERROR("netapp plugin: na_elem_new failed.");
- return (-1);
+ return -1;
}
na_child_add_string(cs->query, "objectname", "system");
- return (0);
+ return 0;
} /* }}} int cna_setup_system */
static int cna_query_system(host_config_t *host) /* {{{ */
cdtime_t now;
if (host == NULL)
- return (EINVAL);
+ return EINVAL;
/* If system statistics were not configured, return without doing anything. */
if (host->cfg_system == NULL)
- return (0);
+ return 0;
now = cdtime();
if ((host->cfg_system->interval.interval +
host->cfg_system->interval.last_read) > now)
- return (0);
+ return 0;
status = cna_setup_system(host->cfg_system);
if (status != 0)
- return (status);
+ return status;
assert(host->cfg_system->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_system->query);
"host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
- return (-1);
+ return -1;
}
status = cna_handle_system_data(host->name, host->cfg_system, data,
host->cfg_system->interval.last_read = now;
na_elem_free(data);
- return (status);
+ 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. */
cfg_volume_perf_t *cfg_volume_perf;
if ((host == NULL) || (ci == NULL))
- return (EINVAL);
+ return EINVAL;
if (host->cfg_volume_perf == NULL) {
cfg_volume_perf = calloc(1, sizeof(*cfg_volume_perf));
if (cfg_volume_perf == NULL)
- return (ENOMEM);
+ return ENOMEM;
/* Set default flags */
cfg_volume_perf->query = NULL;
cfg_volume_perf->il_octets = ignorelist_create(/* invert = */ 1);
if (cfg_volume_perf->il_octets == NULL) {
sfree(cfg_volume_perf);
- return (ENOMEM);
+ 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);
+ return ENOMEM;
}
cfg_volume_perf->il_latency = ignorelist_create(/* invert = */ 1);
ignorelist_free(cfg_volume_perf->il_octets);
ignorelist_free(cfg_volume_perf->il_operations);
sfree(cfg_volume_perf);
- return (ENOMEM);
+ return ENOMEM;
}
host->cfg_volume_perf = cfg_volume_perf;
/* if (!item || !item->key || !*item->key) continue; */
if (strcasecmp(item->key, "Interval") == 0)
- cna_config_get_interval(item, &cfg_volume_perf->interval);
+ cf_util_get_cdtime(item, &cfg_volume_perf->interval.interval);
else if (!strcasecmp(item->key, "GetIO"))
cna_config_volume_perf_option(cfg_volume_perf, item);
else if (!strcasecmp(item->key, "GetOps"))
item->key);
}
- return (0);
+ return 0;
} /* }}} int cna_config_volume_performance */
/* Handling of the "GetCapacity" and "GetSnapshot" options within a
cfg_quota_t *cfg_quota;
if ((host == NULL) || (ci == NULL))
- return (EINVAL);
+ return EINVAL;
if (host->cfg_quota == NULL) {
cfg_quota = calloc(1, sizeof(*cfg_quota));
if (cfg_quota == NULL)
- return (ENOMEM);
+ return ENOMEM;
cfg_quota->query = NULL;
host->cfg_quota = cfg_quota;
oconfig_item_t *item = ci->children + i;
if (strcasecmp(item->key, "Interval") == 0)
- cna_config_get_interval(item, &cfg_quota->interval);
+ cf_util_get_cdtime(item, &cfg_quota->interval.interval);
else
WARNING("netapp plugin: The option %s is not allowed within "
"`Quota' blocks.",
item->key);
}
- return (0);
+ return 0;
} /* }}} int cna_config_quota */
/* Corresponds to a <Disks /> block */
cfg_disk_t *cfg_disk;
if ((host == NULL) || (ci == NULL))
- return (EINVAL);
+ return EINVAL;
if (host->cfg_disk == NULL) {
cfg_disk = calloc(1, sizeof(*cfg_disk));
if (cfg_disk == NULL)
- return (ENOMEM);
+ return ENOMEM;
/* Set default flags */
cfg_disk->flags = CFG_DISK_ALL;
/* if (!item || !item->key || !*item->key) continue; */
if (strcasecmp(item->key, "Interval") == 0)
- cna_config_get_interval(item, &cfg_disk->interval);
+ cf_util_get_cdtime(item, &cfg_disk->interval.interval);
else if (strcasecmp(item->key, "GetBusy") == 0)
- cna_config_bool_to_flag(item, &cfg_disk->flags, CFG_DISK_BUSIEST);
+ cf_util_get_flag(item, &cfg_disk->flags, CFG_DISK_BUSIEST);
}
if ((cfg_disk->flags & CFG_DISK_ALL) == 0) {
host->cfg_disk = NULL;
}
- return (0);
+ return 0;
} /* }}} int cna_config_disk */
/* Corresponds to a <WAFL /> block */
cfg_wafl_t *cfg_wafl;
if ((host == NULL) || (ci == NULL))
- return (EINVAL);
+ return EINVAL;
if (host->cfg_wafl == NULL) {
cfg_wafl = calloc(1, sizeof(*cfg_wafl));
if (cfg_wafl == NULL)
- return (ENOMEM);
+ return ENOMEM;
/* Set default flags */
cfg_wafl->flags = CFG_WAFL_ALL;
oconfig_item_t *item = ci->children + i;
if (strcasecmp(item->key, "Interval") == 0)
- cna_config_get_interval(item, &cfg_wafl->interval);
+ cf_util_get_cdtime(item, &cfg_wafl->interval.interval);
else if (!strcasecmp(item->key, "GetNameCache"))
- cna_config_bool_to_flag(item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
+ cf_util_get_flag(item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
else if (!strcasecmp(item->key, "GetDirCache"))
- cna_config_bool_to_flag(item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
+ cf_util_get_flag(item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
else if (!strcasecmp(item->key, "GetBufferCache"))
- cna_config_bool_to_flag(item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
+ cf_util_get_flag(item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
else if (!strcasecmp(item->key, "GetInodeCache"))
- cna_config_bool_to_flag(item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
+ cf_util_get_flag(item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
else
WARNING("netapp plugin: The %s config option is not allowed within "
"`WAFL' blocks.",
host->cfg_wafl = NULL;
}
- return (0);
+ return 0;
} /* }}} int cna_config_wafl */
/*
cfg_volume_usage_t *cfg_volume_usage;
if ((host == NULL) || (ci == NULL))
- return (EINVAL);
+ return EINVAL;
if (host->cfg_volume_usage == NULL) {
cfg_volume_usage = calloc(1, sizeof(*cfg_volume_usage));
if (cfg_volume_usage == NULL)
- return (ENOMEM);
+ return ENOMEM;
/* Set default flags */
cfg_volume_usage->query = NULL;
cfg_volume_usage->il_capacity = ignorelist_create(/* invert = */ 1);
if (cfg_volume_usage->il_capacity == NULL) {
sfree(cfg_volume_usage);
- return (ENOMEM);
+ return ENOMEM;
}
cfg_volume_usage->il_snapshot = ignorelist_create(/* invert = */ 1);
if (cfg_volume_usage->il_snapshot == NULL) {
ignorelist_free(cfg_volume_usage->il_capacity);
sfree(cfg_volume_usage);
- return (ENOMEM);
+ return ENOMEM;
}
host->cfg_volume_usage = cfg_volume_usage;
/* if (!item || !item->key || !*item->key) continue; */
if (strcasecmp(item->key, "Interval") == 0)
- cna_config_get_interval(item, &cfg_volume_usage->interval);
+ cf_util_get_cdtime(item, &cfg_volume_usage->interval.interval);
else if (!strcasecmp(item->key, "GetCapacity"))
cna_config_volume_usage_option(cfg_volume_usage, item);
else if (!strcasecmp(item->key, "GetSnapshot"))
item->key);
}
- return (0);
+ return 0;
} /* }}} int cna_config_volume_usage */
/* Corresponds to a <SnapVault /> block */
oconfig_item_t *item = ci->children + i;
if (strcasecmp(item->key, "Interval") == 0)
- cna_config_get_interval(item, &cfg_snapvault->interval);
+ cf_util_get_cdtime(item, &cfg_snapvault->interval.interval);
else
WARNING("netapp plugin: The option %s is not allowed within "
"`SnapVault' blocks.",
cfg_system_t *cfg_system;
if ((host == NULL) || (ci == NULL))
- return (EINVAL);
+ return EINVAL;
if (host->cfg_system == NULL) {
cfg_system = calloc(1, sizeof(*cfg_system));
if (cfg_system == NULL)
- return (ENOMEM);
+ return ENOMEM;
/* Set default flags */
cfg_system->flags = CFG_SYSTEM_ALL;
oconfig_item_t *item = ci->children + i;
if (strcasecmp(item->key, "Interval") == 0) {
- cna_config_get_interval(item, &cfg_system->interval);
+ cf_util_get_cdtime(item, &cfg_system->interval.interval);
} else if (!strcasecmp(item->key, "GetCPULoad")) {
- cna_config_bool_to_flag(item, &cfg_system->flags, CFG_SYSTEM_CPU);
+ cf_util_get_flag(item, &cfg_system->flags, CFG_SYSTEM_CPU);
} else if (!strcasecmp(item->key, "GetInterfaces")) {
- cna_config_bool_to_flag(item, &cfg_system->flags, CFG_SYSTEM_NET);
+ cf_util_get_flag(item, &cfg_system->flags, CFG_SYSTEM_NET);
} else if (!strcasecmp(item->key, "GetDiskOps")) {
- cna_config_bool_to_flag(item, &cfg_system->flags, CFG_SYSTEM_OPS);
+ cf_util_get_flag(item, &cfg_system->flags, CFG_SYSTEM_OPS);
} else if (!strcasecmp(item->key, "GetDiskIO")) {
- cna_config_bool_to_flag(item, &cfg_system->flags, CFG_SYSTEM_DISK);
+ cf_util_get_flag(item, &cfg_system->flags, CFG_SYSTEM_DISK);
} else {
WARNING("netapp plugin: The %s config option is not allowed within "
"`System' blocks.",
host->cfg_system = NULL;
}
- return (0);
+ return 0;
} /* }}} int cna_config_system */
/* Corresponds to a <Host /> block. */
host = calloc(1, sizeof(*host));
if (host == NULL)
- return (NULL);
+ return NULL;
host->name = NULL;
host->protocol = NA_SERVER_TRANSPORT_HTTPS;
host->cfg_snapvault = NULL;
host->cfg_system = NULL;
- return (host);
+ return host;
} /* }}} host_config_t *cna_alloc_host */
static host_config_t *cna_shallow_clone_host(host_config_t *host) /* {{{ */
host_config_t *clone;
if (host == NULL)
- return (NULL);
+ return NULL;
clone = cna_alloc_host();
if (clone == NULL)
- return (NULL);
+ return NULL;
if (host->name != NULL) {
clone->name = strdup(host->name);
clone->interval = host->interval;
- return (clone);
+ return clone;
} /* }}} host_config_t *cna_shallow_clone_host */
static int cna_read(user_data_t *ud);
char cb_name[256];
if (host->vfiler)
- ssnprintf(cb_name, sizeof(cb_name), "netapp-%s-%s", host->name,
- host->vfiler);
+ snprintf(cb_name, sizeof(cb_name), "netapp-%s-%s", host->name,
+ host->vfiler);
else
- ssnprintf(cb_name, sizeof(cb_name), "netapp-%s", host->name);
+ snprintf(cb_name, sizeof(cb_name), "netapp-%s", host->name);
plugin_register_complex_read(
/* group = */ NULL, cb_name,
.data = host, .free_func = (void *)free_host_config,
});
- return (0);
+ return 0;
} /* }}} int cna_register_host */
static int cna_config_host(host_config_t *host, /* {{{ */
const oconfig_item_t *ci) {
oconfig_item_t *item;
- _Bool is_vfiler = 0;
+ bool is_vfiler = false;
int status;
if (!strcasecmp(ci->key, "VFiler"))
- is_vfiler = 1;
+ is_vfiler = true;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("netapp plugin: \"%s\" needs exactly one string argument. Ignoring "
"host block.",
ci->key);
- return (1);
+ return 1;
}
status = cf_util_get_string(ci, &host->name);
if (status != 0)
- return (1);
+ return 1;
for (int i = 0; i < ci->children_num; ++i) {
item = ci->children + i;
WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or "
"\"https\". Ignoring host block \"%s\".",
ci->values[0].value.string);
- return (1);
+ return 1;
}
if (!strcasecmp(item->values[0].value.string, "http"))
host->protocol = NA_SERVER_TRANSPORT_HTTP;
if (status != 0)
return status;
- return (0);
+ return 0;
} /* }}} host_config_t *cna_config_host */
/*
int major_version = 1, minor_version = 1;
if (host == NULL)
- return (EINVAL);
+ return EINVAL;
if (host->srv != NULL)
- return (0);
+ return 0;
if (host->vfiler != NULL) /* Request version 1.7 of the ONTAP API */
minor_version = 7;
host->srv = na_server_open(host->host, major_version, minor_version);
if (host->srv == NULL) {
ERROR("netapp plugin: na_server_open (%s) failed.", host->host);
- return (-1);
+ return -1;
}
na_server_set_transport_type(host->srv, host->protocol,
if (!na_server_set_vfiler(host->srv, host->vfiler)) {
ERROR("netapp plugin: Failed to connect to VFiler '%s' on host '%s'.",
host->vfiler, host->host);
- return (-1);
+ return -1;
} else {
INFO("netapp plugin: Connected to VFiler '%s' on host '%s'.",
host->vfiler, host->host);
}
}
- return (0);
+ return 0;
} /* }}} int cna_init_host */
static int cna_init(void) /* {{{ */
char err[256] = {0};
if (!na_startup(err, sizeof(err))) {
- err[sizeof(err) - 1] = 0;
+ err[sizeof(err) - 1] = '\0';
ERROR("netapp plugin: Error initializing netapp API: %s", err);
return 1;
}
- return (0);
+ return 0;
} /* }}} cna_init */
static int cna_read_internal(host_config_t *host) { /* {{{ */
status = cna_query_wafl(host);
if (status != 0)
- return (status);
+ return status;
status = cna_query_disk(host);
if (status != 0)
- return (status);
+ return status;
status = cna_query_volume_perf(host);
if (status != 0)
- return (status);
+ return status;
status = cna_query_volume_usage(host);
if (status != 0)
- return (status);
+ return status;
status = cna_query_quota(host);
if (status != 0)
- return (status);
+ return status;
status = cna_query_snapvault(host);
if (status != 0)
- return (status);
+ return status;
status = cna_query_system(host);
if (status != 0)
- return (status);
+ return status;
return 0;
} /* }}} int cna_read_internal */
int status;
if ((ud == NULL) || (ud->data == NULL))
- return (-1);
+ return -1;
host = ud->data;
status = cna_init_host(host);
if (status != 0)
- return (status);
+ return status;
status = cna_read_internal(host);
if (status != 0) {
/* Clean up system resources and stuff. */
na_shutdown();
- return (0);
+ return 0;
} /* }}} int cna_shutdown */
void module_register(void) {
plugin_register_init("netapp", cna_init);
plugin_register_shutdown("netapp", cna_shutdown);
}
-
-/* vim: set sw=2 ts=2 noet fdm=marker : */