**/
#include "collectd.h"
+
#include "common.h"
#include "utils_ignorelist.h"
return d;
}
- d = malloc (sizeof (*d));
+ d = calloc (1, sizeof (*d));
if (d == NULL)
return (NULL);
- memset (d, 0, sizeof (*d));
d->next = NULL;
d->name = strdup(name);
return (NULL);
/* Not found: allocate. */
- new = malloc (sizeof (*new));
+ new = calloc (1, sizeof (*new));
if (new == NULL)
return (NULL);
- memset (new, 0, sizeof (*new));
new->next = NULL;
new->name = strdup (name);
return (NULL);
/* Not found: allocate. */
- new = malloc (sizeof (*new));
+ new = calloc (1, sizeof (*new));
if (new == NULL)
return (NULL);
- memset (new, 0, sizeof (*new));
new->next = NULL;
new->name = strdup (name);
} /* }}} cdtime_t cna_child_get_cdtime */
-/*
+/*
* Query functions
*
* These functions are called with appropriate data returned by the libnetapp
static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
na_elem_t *data, cdtime_t interval)
{
- cfg_wafl_t perf_data;
+ cfg_wafl_t perf_data = { 0 };
const char *plugin_inst;
na_elem_t *instances;
- na_elem_t *counter;
na_elem_iter_t counter_iter;
- memset (&perf_data, 0, sizeof (perf_data));
-
perf_data.timestamp = cna_child_get_cdtime (data);
instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
/* Iterate over all counters */
counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
- for (counter = na_iterator_next (&counter_iter);
+ for (na_elem_t *counter = na_iterator_next (&counter_iter);
counter != NULL;
counter = na_iterator_next (&counter_iter))
{
{
cdtime_t timestamp;
na_elem_t *instances;
- na_elem_t *instance;
na_elem_iter_t instance_iter;
disk_t *worst_disk = NULL;
if ((cfg_disk == NULL) || (data == NULL))
return (EINVAL);
-
+
timestamp = cna_child_get_cdtime (data);
instances = na_elem_child (data, "instances");
/* Iterate over all children */
instance_iter = na_child_iterator (instances);
- for (instance = na_iterator_next (&instance_iter);
+ for (na_elem_t *instance = na_iterator_next (&instance_iter);
instance != NULL;
instance = na_iterator_next(&instance_iter))
{
disk_t *old_data;
- disk_t new_data;
+ disk_t new_data = { 0 };
na_elem_iter_t counter_iterator;
- na_elem_t *counter;
- memset (&new_data, 0, sizeof (new_data));
new_data.timestamp = timestamp;
new_data.disk_busy_percent = NAN;
/* Look for the "disk_busy" and "base_for_disk_busy" counters */
counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
- for (counter = na_iterator_next(&counter_iterator);
+ for (na_elem_t *counter = na_iterator_next(&counter_iterator);
counter != NULL;
counter = na_iterator_next(&counter_iterator))
{
cdtime_t timestamp;
na_elem_t *elem_instances;
na_elem_iter_t iter_instances;
- na_elem_t *elem_instance;
-
+
timestamp = cna_child_get_cdtime (data);
elem_instances = na_elem_child(data, "instances");
}
iter_instances = na_child_iterator (elem_instances);
- for (elem_instance = na_iterator_next(&iter_instances);
+ for (na_elem_t *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 perf_data = { 0 };
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");
continue;
iter_counters = na_child_iterator (elem_counters);
- for (elem_counter = na_iterator_next(&iter_counters);
+ for (na_elem_t *elem_counter = na_iterator_next(&iter_counters);
elem_counter != NULL;
elem_counter = na_iterator_next(&iter_counters))
{
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)
+ for (data_volume_usage_t *v = cfg_volume->volumes; v != NULL; v = v->next)
{
char plugin_instance[DATA_MAX_NAME_LEN];
static int cna_change_volume_status (const char *hostname, /* {{{ */
data_volume_usage_t *v)
{
- notification_t n;
+ notification_t n = { 0 };
- memset (&n, 0, sizeof (n));
n.time = cdtime ();
sstrncpy (n.host, hostname, sizeof (n.host));
sstrncpy (n.plugin, "netapp", sizeof (n.plugin));
data_volume_usage_t *v)
{
uint64_t snap_used = 0, value;
- na_elem_t *data, *elem_snap, *elem_snapshots;
+ na_elem_t *data, *elem_snapshots;
na_elem_iter_t iter_snap;
data = na_server_invoke_elem(host->srv, v->snap_query);
}
iter_snap = na_child_iterator (elem_snapshots);
- for (elem_snap = na_iterator_next (&iter_snap);
+ for (na_elem_t *elem_snap = na_iterator_next (&iter_snap);
elem_snap != NULL;
elem_snap = na_iterator_next (&iter_snap))
{
static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */
cfg_volume_usage_t *cfg_volume, na_elem_t *data)
{
- na_elem_t *elem_volume;
na_elem_t *elem_volumes;
na_elem_iter_t iter_volume;
}
iter_volume = na_child_iterator (elem_volumes);
- for (elem_volume = na_iterator_next (&iter_volume);
+ for (na_elem_t *elem_volume = na_iterator_next (&iter_volume);
elem_volume != NULL;
elem_volume = na_iterator_next (&iter_volume))
{
if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
cna_handle_volume_snap_usage(host, v);
-
+
if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
continue;
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;
}
iter_quota = na_child_iterator (elem_quotas);
- for (elem_quota = na_iterator_next (&iter_quota);
+ for (na_elem_t *elem_quota = na_iterator_next (&iter_quota);
elem_quota != NULL;
elem_quota = na_iterator_next (&iter_quota))
{
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");
}
status_iter = na_child_iterator (status);
- for (status = na_iterator_next (&status_iter);
+ for (na_elem_t *status = na_iterator_next (&status_iter);
status != NULL;
status = na_iterator_next (&status_iter))
{
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)
DEBUG ("netapp plugin: Iterating %u SV records (tag = %s)", records_count, tag);
- for (i = 0; i < records_count; ++i) {
+ for (uint32_t i = 0; i < records_count; ++i) {
na_elem_t *elem;
elem = na_server_invoke (host->srv,
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;
const char *instance;
cdtime_t timestamp;
-
+
timestamp = cna_child_get_cdtime (data);
instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
}
counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
- for (counter = na_iterator_next (&counter_iter);
+ for (na_elem_t *counter = na_iterator_next (&counter_iter);
counter != NULL;
counter = na_iterator_next (&counter_iter))
{
&& (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,
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));
+ cfg_volume_perf = calloc (1, 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;
host->cfg_volume_perf = cfg_volume_perf;
}
cfg_volume_perf = host->cfg_volume_perf;
-
- for (i = 0; i < ci->children_num; ++i) {
+
+ for (int 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);
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));
+ cfg_quota = calloc (1, sizeof (*cfg_quota));
if (cfg_quota == NULL)
return (ENOMEM);
- memset (cfg_quota, 0, sizeof (*cfg_quota));
cfg_quota->query = NULL;
host->cfg_quota = cfg_quota;
}
cfg_quota = host->cfg_quota;
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
oconfig_item_t *item = ci->children + i;
if (strcasecmp (item->key, "Interval") == 0)
/* Corresponds to a <Disks /> block */
static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
cfg_disk_t *cfg_disk;
- int i;
if ((host == NULL) || (ci == NULL))
return (EINVAL);
if (host->cfg_disk == NULL)
{
- cfg_disk = malloc (sizeof (*cfg_disk));
+ cfg_disk = calloc (1, sizeof (*cfg_disk));
if (cfg_disk == NULL)
return (ENOMEM);
- memset (cfg_disk, 0, sizeof (*cfg_disk));
/* Set default flags */
cfg_disk->flags = CFG_DISK_ALL;
host->cfg_disk = cfg_disk;
}
cfg_disk = host->cfg_disk;
-
- for (i = 0; i < ci->children_num; ++i) {
+
+ for (int 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_disk->interval);
static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
{
cfg_wafl_t *cfg_wafl;
- int i;
if ((host == NULL) || (ci == NULL))
return (EINVAL);
if (host->cfg_wafl == NULL)
{
- cfg_wafl = malloc (sizeof (*cfg_wafl));
+ cfg_wafl = calloc (1, sizeof (*cfg_wafl));
if (cfg_wafl == NULL)
return (ENOMEM);
- memset (cfg_wafl, 0, sizeof (*cfg_wafl));
/* Set default flags */
cfg_wafl->flags = CFG_WAFL_ALL;
}
cfg_wafl = host->cfg_wafl;
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
oconfig_item_t *item = ci->children + i;
-
+
if (strcasecmp(item->key, "Interval") == 0)
cna_config_get_interval (item, &cfg_wafl->interval);
else if (!strcasecmp(item->key, "GetNameCache"))
const oconfig_item_t *ci)
{
cfg_volume_usage_t *cfg_volume_usage;
- int i;
if ((host == NULL) || (ci == NULL))
return (EINVAL);
if (host->cfg_volume_usage == NULL)
{
- cfg_volume_usage = malloc (sizeof (*cfg_volume_usage));
+ cfg_volume_usage = calloc (1, sizeof (*cfg_volume_usage));
if (cfg_volume_usage == NULL)
return (ENOMEM);
- memset (cfg_volume_usage, 0, sizeof (*cfg_volume_usage));
/* Set default flags */
cfg_volume_usage->query = NULL;
host->cfg_volume_usage = cfg_volume_usage;
}
cfg_volume_usage = host->cfg_volume_usage;
-
- for (i = 0; i < ci->children_num; ++i) {
+
+ for (int 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_usage->interval);
const oconfig_item_t *ci)
{
cfg_snapvault_t *cfg_snapvault;
- int i;
if ((host == NULL) || (ci == NULL))
return EINVAL;
if (host->cfg_snapvault == NULL)
{
- cfg_snapvault = malloc (sizeof (*cfg_snapvault));
+ cfg_snapvault = calloc (1, sizeof (*cfg_snapvault));
if (cfg_snapvault == NULL)
return ENOMEM;
- memset (cfg_snapvault, 0, sizeof (*cfg_snapvault));
cfg_snapvault->query = NULL;
host->cfg_snapvault = cfg_snapvault;
cfg_snapvault = host->cfg_snapvault;
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
oconfig_item_t *item = ci->children + i;
if (strcasecmp (item->key, "Interval") == 0)
oconfig_item_t *ci)
{
cfg_system_t *cfg_system;
- int i;
-
+
if ((host == NULL) || (ci == NULL))
return (EINVAL);
if (host->cfg_system == NULL)
{
- cfg_system = malloc (sizeof (*cfg_system));
+ cfg_system = calloc (1, sizeof (*cfg_system));
if (cfg_system == NULL)
return (ENOMEM);
- memset (cfg_system, 0, sizeof (*cfg_system));
/* Set default flags */
cfg_system->flags = CFG_SYSTEM_ALL;
}
cfg_system = host->cfg_system;
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
oconfig_item_t *item = ci->children + i;
if (strcasecmp(item->key, "Interval") == 0) {
{
host_config_t *host;
- host = malloc (sizeof (*host));
- if (! host)
+ host = calloc (1, sizeof (*host));
+ if (host == NULL)
return (NULL);
- memset (host, 0, sizeof (*host));
host->name = NULL;
host->protocol = NA_SERVER_TRANSPORT_HTTPS;
static int cna_register_host (host_config_t *host) /* {{{ */
{
char cb_name[256];
- user_data_t ud;
+ user_data_t ud = { 0 };
if (host->vfiler)
ssnprintf (cb_name, sizeof (cb_name), "netapp-%s-%s",
else
ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name);
- memset (&ud, 0, sizeof (ud));
ud.data = host;
ud.free_func = (void (*) (void *)) free_host_config;
oconfig_item_t *item;
_Bool is_vfiler = 0;
int status;
- int i;
if (! strcasecmp (ci->key, "VFiler"))
is_vfiler = 1;
if (status != 0)
return (1);
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
item = ci->children + i;
status = 0;
static int cna_init (void) /* {{{ */
{
- char err[256];
+ char err[256] = { 0 };
- memset (err, 0, sizeof (err));
if (!na_startup(err, sizeof(err))) {
err[sizeof (err) - 1] = 0;
ERROR("netapp plugin: Error initializing netapp API: %s", err);
} /* }}} int cna_read */
static int cna_config (oconfig_item_t *ci) { /* {{{ */
- int i;
oconfig_item_t *item;
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
item = ci->children + i;
if (strcasecmp(item->key, "Host") == 0)