2 * collectd - src/netapp.c
3 * Copyright (C) 2009,2010 Sven Trenkel
4 * Copyright (C) 2012-2013 teamix GmbH
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Sven Trenkel <collectd at semidefinite.de>
26 * Sebastian 'tokkee' Harl <sh@teamix.net>
32 #include "utils_ignorelist.h"
34 #include <netapp_api.h>
35 #include <netapp_errno.h>
37 #define HAS_ALL_FLAGS(has, needs) (((has) & (needs)) == (needs))
39 typedef struct host_config_s host_config_t;
40 typedef void service_handler_t(host_config_t *host, na_elem_t *result,
43 struct cna_interval_s {
47 typedef struct cna_interval_s cna_interval_t;
49 /*! Data types for WAFL statistics {{{
51 * \brief Persistent data for WAFL performance counters. (a.k.a. cache
54 * The cache counters use old counter values to calculate a hit ratio for each
55 * counter. The "cfg_wafl_t" struct therefore contains old counter values along
56 * with flags, which are set if the counter is valid.
58 * The function "cna_handle_wafl_data" will fill a new structure of this kind
59 * with new values, then pass both, new and old data, to "submit_wafl_data".
60 * That function calculates the hit ratios, submits the calculated values and
61 * updates the old counter values for the next iteration.
63 #define CFG_WAFL_NAME_CACHE 0x0001
64 #define CFG_WAFL_DIR_CACHE 0x0002
65 #define CFG_WAFL_BUF_CACHE 0x0004
66 #define CFG_WAFL_INODE_CACHE 0x0008
67 #define CFG_WAFL_ALL 0x000F
68 #define HAVE_WAFL_NAME_CACHE_HIT 0x0100
69 #define HAVE_WAFL_NAME_CACHE_MISS 0x0200
70 #define HAVE_WAFL_NAME_CACHE \
71 (HAVE_WAFL_NAME_CACHE_HIT | HAVE_WAFL_NAME_CACHE_MISS)
72 #define HAVE_WAFL_FIND_DIR_HIT 0x0400
73 #define HAVE_WAFL_FIND_DIR_MISS 0x0800
74 #define HAVE_WAFL_FIND_DIR (HAVE_WAFL_FIND_DIR_HIT | HAVE_WAFL_FIND_DIR_MISS)
75 #define HAVE_WAFL_BUF_HASH_HIT 0x1000
76 #define HAVE_WAFL_BUF_HASH_MISS 0x2000
77 #define HAVE_WAFL_BUF_HASH (HAVE_WAFL_BUF_HASH_HIT | HAVE_WAFL_BUF_HASH_MISS)
78 #define HAVE_WAFL_INODE_CACHE_HIT 0x4000
79 #define HAVE_WAFL_INODE_CACHE_MISS 0x8000
80 #define HAVE_WAFL_INODE_CACHE \
81 (HAVE_WAFL_INODE_CACHE_HIT | HAVE_WAFL_INODE_CACHE_MISS)
82 #define HAVE_WAFL_ALL 0xff00
85 cna_interval_t interval;
89 uint64_t name_cache_hit;
90 uint64_t name_cache_miss;
91 uint64_t find_dir_hit;
92 uint64_t find_dir_miss;
93 uint64_t buf_hash_hit;
94 uint64_t buf_hash_miss;
95 uint64_t inode_cache_hit;
96 uint64_t inode_cache_miss;
100 /*! Data types for disk statistics {{{
102 * \brief A disk in the NetApp.
104 * A disk doesn't have any more information than its name at the moment.
105 * The name includes the "disk_" prefix.
107 #define HAVE_DISK_BUSY 0x10
108 #define HAVE_DISK_BASE 0x20
109 #define HAVE_DISK_ALL 0x30
110 typedef struct disk_s {
115 uint64_t base_for_disk_busy;
116 double disk_busy_percent;
120 #define CFG_DISK_BUSIEST 0x01
121 #define CFG_DISK_ALL 0x01
124 cna_interval_t interval;
130 /*! Data types for volume performance statistics {{{
132 * \brief Persistent data for volume performance data.
134 * The code below uses the difference of the operations and latency counters to
135 * calculate an average per-operation latency. For this, old counters need to
136 * be stored in the "data_volume_perf_t" structure. The byte-counters are just
137 * kept for completeness sake. The "flags" member indicates if each counter is
140 * The "cna_handle_volume_perf_data" function will fill a new struct of this
141 * type and pass both, old and new data, to "submit_volume_perf_data". In that
142 * function, the per-operation latency is calculated and dispatched, then the
143 * old counters are updated.
145 #define CFG_VOLUME_PERF_INIT 0x0001
146 #define CFG_VOLUME_PERF_IO 0x0002
147 #define CFG_VOLUME_PERF_OPS 0x0003
148 #define CFG_VOLUME_PERF_LATENCY 0x0008
149 #define CFG_VOLUME_PERF_ALL 0x000F
150 #define HAVE_VOLUME_PERF_BYTES_READ 0x0010
151 #define HAVE_VOLUME_PERF_BYTES_WRITE 0x0020
152 #define HAVE_VOLUME_PERF_OPS_READ 0x0040
153 #define HAVE_VOLUME_PERF_OPS_WRITE 0x0080
154 #define HAVE_VOLUME_PERF_LATENCY_READ 0x0100
155 #define HAVE_VOLUME_PERF_LATENCY_WRITE 0x0200
156 #define HAVE_VOLUME_PERF_ALL 0x03F0
157 struct data_volume_perf_s;
158 typedef struct data_volume_perf_s data_volume_perf_t;
159 struct data_volume_perf_s {
165 uint64_t write_bytes;
168 uint64_t read_latency;
169 uint64_t write_latency;
171 data_volume_perf_t *next;
175 cna_interval_t interval;
178 ignorelist_t *il_octets;
179 ignorelist_t *il_operations;
180 ignorelist_t *il_latency;
182 data_volume_perf_t *volumes;
184 /* }}} data_volume_perf_t */
186 /*! Data types for volume usage statistics {{{
188 * \brief Configuration struct for volume usage data (free / used).
190 #define CFG_VOLUME_USAGE_DF 0x0002
191 #define CFG_VOLUME_USAGE_SNAP 0x0004
192 #define CFG_VOLUME_USAGE_ALL 0x0006
193 #define HAVE_VOLUME_USAGE_NORM_FREE 0x0010
194 #define HAVE_VOLUME_USAGE_NORM_USED 0x0020
195 #define HAVE_VOLUME_USAGE_SNAP_RSVD 0x0040
196 #define HAVE_VOLUME_USAGE_SNAP_USED 0x0080
197 #define HAVE_VOLUME_USAGE_SIS_SAVED 0x0100
198 #define HAVE_VOLUME_USAGE_COMPRESS_SAVED 0x0200
199 #define HAVE_VOLUME_USAGE_DEDUP_SAVED 0x0400
200 #define HAVE_VOLUME_USAGE_ALL 0x07f0
201 #define IS_VOLUME_USAGE_OFFLINE 0x0800
202 struct data_volume_usage_s;
203 typedef struct data_volume_usage_s data_volume_usage_t;
204 struct data_volume_usage_s {
208 na_elem_t *snap_query;
212 uint64_t snap_reserved;
215 uint64_t compress_saved;
216 uint64_t dedup_saved;
218 data_volume_usage_t *next;
222 cna_interval_t interval;
225 ignorelist_t *il_capacity;
226 ignorelist_t *il_snapshot;
228 data_volume_usage_t *volumes;
229 } cfg_volume_usage_t;
230 /* }}} cfg_volume_usage_t */
232 /*! Data types for quota statistics {{{
234 * \brief Persistent data for quota statistics
237 cna_interval_t interval;
240 /* }}} cfg_quota_t */
242 /*! Data types for SnapVault statistics {{{
244 * \brief Persistent data for SnapVault(R) statistics
247 cna_interval_t interval;
250 /* }}} cfg_snapvault_t */
252 /*! Data types for system statistics {{{
254 * \brief Persistent data for system performance counters
256 #define CFG_SYSTEM_CPU 0x01
257 #define CFG_SYSTEM_NET 0x02
258 #define CFG_SYSTEM_OPS 0x04
259 #define CFG_SYSTEM_DISK 0x08
260 #define CFG_SYSTEM_ALL 0x0F
263 cna_interval_t interval;
266 /* }}} cfg_system_t */
268 struct host_config_s {
270 na_server_transport_t protocol;
279 cfg_wafl_t *cfg_wafl;
280 cfg_disk_t *cfg_disk;
281 cfg_volume_perf_t *cfg_volume_perf;
282 cfg_volume_usage_t *cfg_volume_usage;
283 cfg_quota_t *cfg_quota;
284 cfg_snapvault_t *cfg_snapvault;
285 cfg_system_t *cfg_system;
287 struct host_config_s *next;
293 * Used to free the various structures above.
295 static void free_disk(disk_t *disk) /* {{{ */
308 } /* }}} void free_disk */
310 static void free_cfg_wafl(cfg_wafl_t *cw) /* {{{ */
315 if (cw->query != NULL)
316 na_elem_free(cw->query);
319 } /* }}} void free_cfg_wafl */
321 static void free_cfg_disk(cfg_disk_t *cfg_disk) /* {{{ */
323 if (cfg_disk == NULL)
326 if (cfg_disk->query != NULL)
327 na_elem_free(cfg_disk->query);
329 free_disk(cfg_disk->disks);
331 } /* }}} void free_cfg_disk */
333 static void free_cfg_volume_perf(cfg_volume_perf_t *cvp) /* {{{ */
335 data_volume_perf_t *data;
340 /* Free the ignorelists */
341 ignorelist_free(cvp->il_octets);
342 ignorelist_free(cvp->il_operations);
343 ignorelist_free(cvp->il_latency);
345 /* Free the linked list of volumes */
347 while (data != NULL) {
348 data_volume_perf_t *next = data->next;
354 if (cvp->query != NULL)
355 na_elem_free(cvp->query);
358 } /* }}} void free_cfg_volume_perf */
360 static void free_cfg_volume_usage(cfg_volume_usage_t *cvu) /* {{{ */
362 data_volume_usage_t *data;
367 /* Free the ignorelists */
368 ignorelist_free(cvu->il_capacity);
369 ignorelist_free(cvu->il_snapshot);
371 /* Free the linked list of volumes */
373 while (data != NULL) {
374 data_volume_usage_t *next = data->next;
376 if (data->snap_query != NULL)
377 na_elem_free(data->snap_query);
382 if (cvu->query != NULL)
383 na_elem_free(cvu->query);
386 } /* }}} void free_cfg_volume_usage */
388 static void free_cfg_quota(cfg_quota_t *q) /* {{{ */
393 if (q->query != NULL)
394 na_elem_free(q->query);
397 } /* }}} void free_cfg_quota */
399 static void free_cfg_snapvault(cfg_snapvault_t *sv) /* {{{ */
404 if (sv->query != NULL)
405 na_elem_free(sv->query);
408 } /* }}} void free_cfg_snapvault */
410 static void free_cfg_system(cfg_system_t *cs) /* {{{ */
415 if (cs->query != NULL)
416 na_elem_free(cs->query);
419 } /* }}} void free_cfg_system */
421 static void free_host_config(host_config_t *hc) /* {{{ */
436 free_cfg_disk(hc->cfg_disk);
437 free_cfg_wafl(hc->cfg_wafl);
438 free_cfg_volume_perf(hc->cfg_volume_perf);
439 free_cfg_volume_usage(hc->cfg_volume_usage);
440 free_cfg_quota(hc->cfg_quota);
441 free_cfg_snapvault(hc->cfg_snapvault);
442 free_cfg_system(hc->cfg_system);
445 na_server_close(hc->srv);
449 free_host_config(next);
450 } /* }}} void free_host_config */
453 * Auxiliary functions
455 * Used to look up volumes and disks or to handle flags.
457 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
461 if ((cd == NULL) || (name == NULL))
464 for (d = cd->disks; d != NULL; d = d->next) {
465 if (strcmp(d->name, name) == 0)
469 d = calloc(1, sizeof(*d));
474 d->name = strdup(name);
475 if (d->name == NULL) {
484 } /* }}} disk_t *get_disk */
486 static data_volume_usage_t *get_volume_usage(cfg_volume_usage_t *cvu, /* {{{ */
488 data_volume_usage_t *last;
489 data_volume_usage_t *new;
491 int ignore_capacity = 0;
492 int ignore_snapshot = 0;
494 if ((cvu == NULL) || (name == NULL))
498 while (last != NULL) {
499 if (strcmp(last->name, name) == 0)
502 if (last->next == NULL)
508 /* Check the ignorelists. If *both* tell us to ignore a volume, return NULL.
510 ignore_capacity = ignorelist_match(cvu->il_capacity, name);
511 ignore_snapshot = ignorelist_match(cvu->il_snapshot, name);
512 if ((ignore_capacity != 0) && (ignore_snapshot != 0))
515 /* Not found: allocate. */
516 new = calloc(1, sizeof(*new));
521 new->name = strdup(name);
522 if (new->name == NULL) {
527 if (ignore_capacity == 0)
528 new->flags |= CFG_VOLUME_USAGE_DF;
529 if (ignore_snapshot == 0) {
530 new->flags |= CFG_VOLUME_USAGE_SNAP;
531 new->snap_query = na_elem_new("snapshot-list-info");
532 na_child_add_string(new->snap_query, "target-type", "volume");
533 na_child_add_string(new->snap_query, "target-name", name);
535 new->snap_query = NULL;
538 /* Add to end of list. */
545 } /* }}} data_volume_usage_t *get_volume_usage */
547 static data_volume_perf_t *get_volume_perf(cfg_volume_perf_t *cvp, /* {{{ */
549 data_volume_perf_t *last;
550 data_volume_perf_t *new;
552 int ignore_octets = 0;
553 int ignore_operations = 0;
554 int ignore_latency = 0;
556 if ((cvp == NULL) || (name == NULL))
560 while (last != NULL) {
561 if (strcmp(last->name, name) == 0)
564 if (last->next == NULL)
570 /* Check the ignorelists. If *all three* tell us to ignore a volume, return
572 ignore_octets = ignorelist_match(cvp->il_octets, name);
573 ignore_operations = ignorelist_match(cvp->il_operations, name);
574 ignore_latency = ignorelist_match(cvp->il_latency, name);
575 if ((ignore_octets != 0) || (ignore_operations != 0) || (ignore_latency != 0))
578 /* Not found: allocate. */
579 new = calloc(1, sizeof(*new));
584 new->name = strdup(name);
585 if (new->name == NULL) {
590 if (ignore_octets == 0)
591 new->flags |= CFG_VOLUME_PERF_IO;
592 if (ignore_operations == 0)
593 new->flags |= CFG_VOLUME_PERF_OPS;
594 if (ignore_latency == 0)
595 new->flags |= CFG_VOLUME_PERF_LATENCY;
597 /* Add to end of list. */
604 } /* }}} data_volume_perf_t *get_volume_perf */
607 * Various submit functions.
609 * They all eventually call "submit_values" which creates a value_list_t and
610 * dispatches it to the daemon.
612 static int submit_values(const char *host, /* {{{ */
613 const char *plugin_inst, const char *type,
614 const char *type_inst, value_t *values,
615 size_t values_len, cdtime_t timestamp,
617 value_list_t vl = VALUE_LIST_INIT;
620 vl.values_len = values_len;
626 vl.interval = interval;
629 sstrncpy(vl.host, host, sizeof(vl.host));
630 sstrncpy(vl.plugin, "netapp", sizeof(vl.plugin));
631 if (plugin_inst != NULL)
632 sstrncpy(vl.plugin_instance, plugin_inst, sizeof(vl.plugin_instance));
633 sstrncpy(vl.type, type, sizeof(vl.type));
634 if (type_inst != NULL)
635 sstrncpy(vl.type_instance, type_inst, sizeof(vl.type_instance));
637 return (plugin_dispatch_values(&vl));
638 } /* }}} int submit_uint64 */
640 static int submit_two_derive(const char *host,
641 const char *plugin_inst, /* {{{ */
642 const char *type, const char *type_inst,
643 derive_t val0, derive_t val1, cdtime_t timestamp,
646 {.derive = val0}, {.derive = val1},
649 return (submit_values(host, plugin_inst, type, type_inst, values,
650 STATIC_ARRAY_SIZE(values), timestamp, interval));
651 } /* }}} int submit_two_derive */
653 static int submit_derive(const char *host, const char *plugin_inst, /* {{{ */
654 const char *type, const char *type_inst,
655 derive_t counter, cdtime_t timestamp,
657 return (submit_values(host, plugin_inst, type, type_inst,
658 &(value_t){.derive = counter}, 1, timestamp, interval));
659 } /* }}} int submit_derive */
661 static int submit_two_gauge(const char *host, const char *plugin_inst, /* {{{ */
662 const char *type, const char *type_inst,
663 gauge_t val0, gauge_t val1, cdtime_t timestamp,
666 {.gauge = val0}, {.gauge = val1},
669 return (submit_values(host, plugin_inst, type, type_inst, values,
670 STATIC_ARRAY_SIZE(values), timestamp, interval));
671 } /* }}} int submit_two_gauge */
673 static int submit_double(const char *host, const char *plugin_inst, /* {{{ */
674 const char *type, const char *type_inst, double d,
675 cdtime_t timestamp, cdtime_t interval) {
676 return (submit_values(host, plugin_inst, type, type_inst,
677 &(value_t){.gauge = d}, 1, timestamp, interval));
678 } /* }}} int submit_uint64 */
680 /* Calculate hit ratio from old and new counters and submit the resulting
681 * percentage. Used by "submit_wafl_data". */
682 static int submit_cache_ratio(const char *host, /* {{{ */
683 const char *plugin_inst, const char *type_inst,
684 uint64_t new_hits, uint64_t new_misses,
685 uint64_t old_hits, uint64_t old_misses,
686 cdtime_t timestamp, cdtime_t interval) {
687 value_t v = {.gauge = NAN};
689 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
693 hits = new_hits - old_hits;
694 misses = new_misses - old_misses;
696 v.gauge = 100.0 * ((gauge_t)hits) / ((gauge_t)(hits + misses));
699 return (submit_values(host, plugin_inst, "cache_ratio", type_inst, &v, 1,
700 timestamp, interval));
701 } /* }}} int submit_cache_ratio */
703 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
704 static int submit_wafl_data(const char *hostname,
705 const char *instance, /* {{{ */
706 cfg_wafl_t *old_data, const cfg_wafl_t *new_data,
708 /* Submit requested counters */
709 if (HAS_ALL_FLAGS(old_data->flags,
710 CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE) &&
711 HAS_ALL_FLAGS(new_data->flags, HAVE_WAFL_NAME_CACHE))
712 submit_cache_ratio(hostname, instance, "name_cache_hit",
713 new_data->name_cache_hit, new_data->name_cache_miss,
714 old_data->name_cache_hit, old_data->name_cache_miss,
715 new_data->timestamp, interval);
717 if (HAS_ALL_FLAGS(old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR) &&
718 HAS_ALL_FLAGS(new_data->flags, HAVE_WAFL_FIND_DIR))
719 submit_cache_ratio(hostname, instance, "find_dir_hit",
720 new_data->find_dir_hit, new_data->find_dir_miss,
721 old_data->find_dir_hit, old_data->find_dir_miss,
722 new_data->timestamp, interval);
724 if (HAS_ALL_FLAGS(old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH) &&
725 HAS_ALL_FLAGS(new_data->flags, HAVE_WAFL_BUF_HASH))
726 submit_cache_ratio(hostname, instance, "buf_hash_hit",
727 new_data->buf_hash_hit, new_data->buf_hash_miss,
728 old_data->buf_hash_hit, old_data->buf_hash_miss,
729 new_data->timestamp, interval);
731 if (HAS_ALL_FLAGS(old_data->flags,
732 CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE) &&
733 HAS_ALL_FLAGS(new_data->flags, HAVE_WAFL_INODE_CACHE))
734 submit_cache_ratio(hostname, instance, "inode_cache_hit",
735 new_data->inode_cache_hit, new_data->inode_cache_miss,
736 old_data->inode_cache_hit, old_data->inode_cache_miss,
737 new_data->timestamp, interval);
739 /* Clear old HAVE_* flags */
740 old_data->flags &= ~HAVE_WAFL_ALL;
742 /* Copy all counters */
743 old_data->timestamp = new_data->timestamp;
744 old_data->name_cache_hit = new_data->name_cache_hit;
745 old_data->name_cache_miss = new_data->name_cache_miss;
746 old_data->find_dir_hit = new_data->find_dir_hit;
747 old_data->find_dir_miss = new_data->find_dir_miss;
748 old_data->buf_hash_hit = new_data->buf_hash_hit;
749 old_data->buf_hash_miss = new_data->buf_hash_miss;
750 old_data->inode_cache_hit = new_data->inode_cache_hit;
751 old_data->inode_cache_miss = new_data->inode_cache_miss;
753 /* Copy HAVE_* flags */
754 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
757 } /* }}} int submit_wafl_data */
759 /* Submits volume performance data to the daemon, taking care to honor and
760 * update flags appropriately. */
761 static int submit_volume_perf_data(const char *hostname, /* {{{ */
762 data_volume_perf_t *old_data,
763 const data_volume_perf_t *new_data,
765 char plugin_instance[DATA_MAX_NAME_LEN];
767 if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL))
770 ssnprintf(plugin_instance, sizeof(plugin_instance), "volume-%s",
773 /* Check for and submit disk-octet values */
774 if (HAS_ALL_FLAGS(old_data->flags, CFG_VOLUME_PERF_IO) &&
775 HAS_ALL_FLAGS(new_data->flags, HAVE_VOLUME_PERF_BYTES_READ |
776 HAVE_VOLUME_PERF_BYTES_WRITE)) {
778 hostname, plugin_instance, "disk_octets", /* type instance = */ NULL,
779 (derive_t)new_data->read_bytes, (derive_t)new_data->write_bytes,
780 new_data->timestamp, interval);
783 /* Check for and submit disk-operations values */
784 if (HAS_ALL_FLAGS(old_data->flags, CFG_VOLUME_PERF_OPS) &&
785 HAS_ALL_FLAGS(new_data->flags,
786 HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE)) {
787 submit_two_derive(hostname, plugin_instance, "disk_ops",
788 /* type instance = */ NULL, (derive_t)new_data->read_ops,
789 (derive_t)new_data->write_ops, new_data->timestamp,
793 /* Check for, calculate and submit disk-latency values */
794 if (HAS_ALL_FLAGS(old_data->flags, CFG_VOLUME_PERF_LATENCY |
795 HAVE_VOLUME_PERF_OPS_READ |
796 HAVE_VOLUME_PERF_OPS_WRITE |
797 HAVE_VOLUME_PERF_LATENCY_READ |
798 HAVE_VOLUME_PERF_LATENCY_WRITE) &&
799 HAS_ALL_FLAGS(new_data->flags, HAVE_VOLUME_PERF_OPS_READ |
800 HAVE_VOLUME_PERF_OPS_WRITE |
801 HAVE_VOLUME_PERF_LATENCY_READ |
802 HAVE_VOLUME_PERF_LATENCY_WRITE)) {
803 gauge_t latency_per_op_read;
804 gauge_t latency_per_op_write;
806 latency_per_op_read = NAN;
807 latency_per_op_write = NAN;
809 /* Check if a counter wrapped around. */
810 if ((new_data->read_ops > old_data->read_ops) &&
811 (new_data->read_latency > old_data->read_latency)) {
812 uint64_t diff_ops_read;
813 uint64_t diff_latency_read;
815 diff_ops_read = new_data->read_ops - old_data->read_ops;
816 diff_latency_read = new_data->read_latency - old_data->read_latency;
818 if (diff_ops_read > 0)
819 latency_per_op_read =
820 ((gauge_t)diff_latency_read) / ((gauge_t)diff_ops_read);
823 if ((new_data->write_ops > old_data->write_ops) &&
824 (new_data->write_latency > old_data->write_latency)) {
825 uint64_t diff_ops_write;
826 uint64_t diff_latency_write;
828 diff_ops_write = new_data->write_ops - old_data->write_ops;
829 diff_latency_write = new_data->write_latency - old_data->write_latency;
831 if (diff_ops_write > 0)
832 latency_per_op_write =
833 ((gauge_t)diff_latency_write) / ((gauge_t)diff_ops_write);
836 submit_two_gauge(hostname, plugin_instance, "disk_latency",
837 /* type instance = */ NULL, latency_per_op_read,
838 latency_per_op_write, new_data->timestamp, interval);
841 /* Clear all HAVE_* flags. */
842 old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
844 /* Copy all counters */
845 old_data->timestamp = new_data->timestamp;
846 old_data->read_bytes = new_data->read_bytes;
847 old_data->write_bytes = new_data->write_bytes;
848 old_data->read_ops = new_data->read_ops;
849 old_data->write_ops = new_data->write_ops;
850 old_data->read_latency = new_data->read_latency;
851 old_data->write_latency = new_data->write_latency;
853 /* Copy the HAVE_* flags */
854 old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
857 } /* }}} int submit_volume_perf_data */
859 static cdtime_t cna_child_get_cdtime(na_elem_t *data) /* {{{ */
863 t = (time_t)na_child_get_uint64(data, "timestamp", /* default = */ 0);
865 return (TIME_T_TO_CDTIME_T(t));
866 } /* }}} cdtime_t cna_child_get_cdtime */
871 * These functions are called with appropriate data returned by the libnetapp
872 * interface which is parsed and submitted with the above functions.
874 /* Data corresponding to <WAFL /> */
875 static int cna_handle_wafl_data(const char *hostname,
876 cfg_wafl_t *cfg_wafl, /* {{{ */
877 na_elem_t *data, cdtime_t interval) {
878 cfg_wafl_t perf_data = {0};
879 const char *plugin_inst;
881 na_elem_t *instances;
882 na_elem_iter_t counter_iter;
884 perf_data.timestamp = cna_child_get_cdtime(data);
886 instances = na_elem_child(na_elem_child(data, "instances"), "instance-data");
887 if (instances == NULL) {
888 ERROR("netapp plugin: cna_handle_wafl_data: "
889 "na_elem_child (\"instances\") failed "
895 plugin_inst = na_child_get_string(instances, "name");
896 if (plugin_inst == NULL) {
897 ERROR("netapp plugin: cna_handle_wafl_data: "
898 "na_child_get_string (\"name\") failed "
904 /* Iterate over all counters */
905 counter_iter = na_child_iterator(na_elem_child(instances, "counters"));
906 for (na_elem_t *counter = na_iterator_next(&counter_iter); counter != NULL;
907 counter = na_iterator_next(&counter_iter)) {
911 name = na_child_get_string(counter, "name");
915 value = na_child_get_uint64(counter, "value", UINT64_MAX);
916 if (value == UINT64_MAX)
919 if (!strcmp(name, "name_cache_hit")) {
920 perf_data.name_cache_hit = value;
921 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
922 } else if (!strcmp(name, "name_cache_miss")) {
923 perf_data.name_cache_miss = value;
924 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
925 } else if (!strcmp(name, "find_dir_hit")) {
926 perf_data.find_dir_hit = value;
927 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
928 } else if (!strcmp(name, "find_dir_miss")) {
929 perf_data.find_dir_miss = value;
930 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
931 } else if (!strcmp(name, "buf_hash_hit")) {
932 perf_data.buf_hash_hit = value;
933 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
934 } else if (!strcmp(name, "buf_hash_miss")) {
935 perf_data.buf_hash_miss = value;
936 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
937 } else if (!strcmp(name, "inode_cache_hit")) {
938 perf_data.inode_cache_hit = value;
939 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
940 } else if (!strcmp(name, "inode_cache_miss")) {
941 perf_data.inode_cache_miss = value;
942 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
944 DEBUG("netapp plugin: cna_handle_wafl_data: "
945 "Found unexpected child: %s "
952 submit_wafl_data(hostname, plugin_inst, cfg_wafl, &perf_data, interval));
953 } /* }}} void cna_handle_wafl_data */
955 static int cna_setup_wafl(cfg_wafl_t *cw) /* {{{ */
962 if (cw->query != NULL)
965 cw->query = na_elem_new("perf-object-get-instances");
966 if (cw->query == NULL) {
967 ERROR("netapp plugin: na_elem_new failed.");
970 na_child_add_string(cw->query, "objectname", "wafl");
972 e = na_elem_new("counters");
974 na_elem_free(cw->query);
976 ERROR("netapp plugin: na_elem_new failed.");
979 na_child_add_string(e, "counter", "name_cache_hit");
980 na_child_add_string(e, "counter", "name_cache_miss");
981 na_child_add_string(e, "counter", "find_dir_hit");
982 na_child_add_string(e, "counter", "find_dir_miss");
983 na_child_add_string(e, "counter", "buf_hash_hit");
984 na_child_add_string(e, "counter", "buf_hash_miss");
985 na_child_add_string(e, "counter", "inode_cache_hit");
986 na_child_add_string(e, "counter", "inode_cache_miss");
988 na_child_add(cw->query, e);
991 } /* }}} int cna_setup_wafl */
993 static int cna_query_wafl(host_config_t *host) /* {{{ */
1002 /* If WAFL was not configured, return without doing anything. */
1003 if (host->cfg_wafl == NULL)
1007 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) >
1011 status = cna_setup_wafl(host->cfg_wafl);
1014 assert(host->cfg_wafl->query != NULL);
1016 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
1017 if (na_results_status(data) != NA_OK) {
1018 ERROR("netapp plugin: cna_query_wafl: na_server_invoke_elem failed for "
1020 host->name, na_results_reason(data));
1025 status = cna_handle_wafl_data(host->name, host->cfg_wafl, data,
1026 host->cfg_wafl->interval.interval);
1029 host->cfg_wafl->interval.last_read = now;
1033 } /* }}} int cna_query_wafl */
1035 /* Data corresponding to <Disks /> */
1036 static int cna_handle_disk_data(const char *hostname, /* {{{ */
1037 cfg_disk_t *cfg_disk, na_elem_t *data,
1038 cdtime_t interval) {
1040 na_elem_t *instances;
1041 na_elem_iter_t instance_iter;
1042 disk_t *worst_disk = NULL;
1044 if ((cfg_disk == NULL) || (data == NULL))
1047 timestamp = cna_child_get_cdtime(data);
1049 instances = na_elem_child(data, "instances");
1050 if (instances == NULL) {
1051 ERROR("netapp plugin: cna_handle_disk_data: "
1052 "na_elem_child (\"instances\") failed "
1058 /* Iterate over all children */
1059 instance_iter = na_child_iterator(instances);
1060 for (na_elem_t *instance = na_iterator_next(&instance_iter); instance != NULL;
1061 instance = na_iterator_next(&instance_iter)) {
1063 disk_t new_data = {0};
1065 na_elem_iter_t counter_iterator;
1067 new_data.timestamp = timestamp;
1068 new_data.disk_busy_percent = NAN;
1070 old_data = get_disk(cfg_disk, na_child_get_string(instance, "name"));
1071 if (old_data == NULL)
1074 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
1075 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
1076 for (na_elem_t *counter = na_iterator_next(&counter_iterator);
1077 counter != NULL; counter = na_iterator_next(&counter_iterator)) {
1081 name = na_child_get_string(counter, "name");
1085 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1086 if (value == UINT64_MAX)
1089 if (strcmp(name, "disk_busy") == 0) {
1090 new_data.disk_busy = value;
1091 new_data.flags |= HAVE_DISK_BUSY;
1092 } else if (strcmp(name, "base_for_disk_busy") == 0) {
1093 new_data.base_for_disk_busy = value;
1094 new_data.flags |= HAVE_DISK_BASE;
1096 DEBUG("netapp plugin: cna_handle_disk_data: "
1097 "Counter not handled: %s = %" PRIu64,
1102 /* If all required counters are available and did not just wrap around,
1103 * calculate the busy percentage. Otherwise, the value is initialized to
1104 * NAN at the top of the for-loop. */
1105 if (HAS_ALL_FLAGS(old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE) &&
1106 HAS_ALL_FLAGS(new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE) &&
1107 (new_data.disk_busy >= old_data->disk_busy) &&
1108 (new_data.base_for_disk_busy > old_data->base_for_disk_busy)) {
1112 busy_diff = new_data.disk_busy - old_data->disk_busy;
1113 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
1115 new_data.disk_busy_percent =
1116 100.0 * ((gauge_t)busy_diff) / ((gauge_t)base_diff);
1119 /* Clear HAVE_* flags */
1120 old_data->flags &= ~HAVE_DISK_ALL;
1123 old_data->timestamp = new_data.timestamp;
1124 old_data->disk_busy = new_data.disk_busy;
1125 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
1126 old_data->disk_busy_percent = new_data.disk_busy_percent;
1129 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
1131 if ((worst_disk == NULL) ||
1132 (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
1133 worst_disk = old_data;
1134 } /* for (all disks) */
1136 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
1137 submit_double(hostname, "system", "percent", "disk_busy",
1138 worst_disk->disk_busy_percent, timestamp, interval);
1141 } /* }}} int cna_handle_disk_data */
1143 static int cna_setup_disk(cfg_disk_t *cd) /* {{{ */
1150 if (cd->query != NULL)
1153 cd->query = na_elem_new("perf-object-get-instances");
1154 if (cd->query == NULL) {
1155 ERROR("netapp plugin: na_elem_new failed.");
1158 na_child_add_string(cd->query, "objectname", "disk");
1160 e = na_elem_new("counters");
1162 na_elem_free(cd->query);
1164 ERROR("netapp plugin: na_elem_new failed.");
1167 na_child_add_string(e, "counter", "disk_busy");
1168 na_child_add_string(e, "counter", "base_for_disk_busy");
1169 na_child_add(cd->query, e);
1172 } /* }}} int cna_setup_disk */
1174 static int cna_query_disk(host_config_t *host) /* {{{ */
1183 /* If the user did not configure disk statistics, return without doing
1185 if (host->cfg_disk == NULL)
1189 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) >
1193 status = cna_setup_disk(host->cfg_disk);
1196 assert(host->cfg_disk->query != NULL);
1198 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1199 if (na_results_status(data) != NA_OK) {
1200 ERROR("netapp plugin: cna_query_disk: na_server_invoke_elem failed for "
1202 host->name, na_results_reason(data));
1207 status = cna_handle_disk_data(host->name, host->cfg_disk, data,
1208 host->cfg_disk->interval.interval);
1211 host->cfg_disk->interval.last_read = now;
1215 } /* }}} int cna_query_disk */
1217 /* Data corresponding to <VolumePerf /> */
1218 static int cna_handle_volume_perf_data(const char *hostname, /* {{{ */
1219 cfg_volume_perf_t *cvp, na_elem_t *data,
1220 cdtime_t interval) {
1222 na_elem_t *elem_instances;
1223 na_elem_iter_t iter_instances;
1225 timestamp = cna_child_get_cdtime(data);
1227 elem_instances = na_elem_child(data, "instances");
1228 if (elem_instances == NULL) {
1229 ERROR("netapp plugin: handle_volume_perf_data: "
1230 "na_elem_child (\"instances\") failed "
1236 iter_instances = na_child_iterator(elem_instances);
1237 for (na_elem_t *elem_instance = na_iterator_next(&iter_instances);
1238 elem_instance != NULL;
1239 elem_instance = na_iterator_next(&iter_instances)) {
1242 data_volume_perf_t perf_data = {0};
1243 data_volume_perf_t *v;
1245 na_elem_t *elem_counters;
1246 na_elem_iter_t iter_counters;
1248 perf_data.timestamp = timestamp;
1250 name = na_child_get_string(elem_instance, "name");
1254 /* get_volume_perf may return NULL if this volume is to be ignored. */
1255 v = get_volume_perf(cvp, name);
1259 elem_counters = na_elem_child(elem_instance, "counters");
1260 if (elem_counters == NULL)
1263 iter_counters = na_child_iterator(elem_counters);
1264 for (na_elem_t *elem_counter = na_iterator_next(&iter_counters);
1265 elem_counter != NULL;
1266 elem_counter = na_iterator_next(&iter_counters)) {
1270 name = na_child_get_string(elem_counter, "name");
1274 value = na_child_get_uint64(elem_counter, "value", UINT64_MAX);
1275 if (value == UINT64_MAX)
1278 if (!strcmp(name, "read_data")) {
1279 perf_data.read_bytes = value;
1280 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1281 } else if (!strcmp(name, "write_data")) {
1282 perf_data.write_bytes = value;
1283 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1284 } else if (!strcmp(name, "read_ops")) {
1285 perf_data.read_ops = value;
1286 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1287 } else if (!strcmp(name, "write_ops")) {
1288 perf_data.write_ops = value;
1289 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1290 } else if (!strcmp(name, "read_latency")) {
1291 perf_data.read_latency = value;
1292 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1293 } else if (!strcmp(name, "write_latency")) {
1294 perf_data.write_latency = value;
1295 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1297 } /* for (elem_counter) */
1299 submit_volume_perf_data(hostname, v, &perf_data, interval);
1300 } /* for (volume) */
1303 } /* }}} int cna_handle_volume_perf_data */
1305 static int cna_setup_volume_perf(cfg_volume_perf_t *cd) /* {{{ */
1312 if (cd->query != NULL)
1315 cd->query = na_elem_new("perf-object-get-instances");
1316 if (cd->query == NULL) {
1317 ERROR("netapp plugin: na_elem_new failed.");
1320 na_child_add_string(cd->query, "objectname", "volume");
1322 e = na_elem_new("counters");
1324 na_elem_free(cd->query);
1326 ERROR("netapp plugin: na_elem_new failed.");
1329 na_child_add_string(e, "counter", "read_ops");
1330 na_child_add_string(e, "counter", "write_ops");
1331 na_child_add_string(e, "counter", "read_data");
1332 na_child_add_string(e, "counter", "write_data");
1333 na_child_add_string(e, "counter", "read_latency");
1334 na_child_add_string(e, "counter", "write_latency");
1335 na_child_add(cd->query, e);
1338 } /* }}} int cna_setup_volume_perf */
1340 static int cna_query_volume_perf(host_config_t *host) /* {{{ */
1349 /* If the user did not configure volume performance statistics, return
1350 * without doing anything. */
1351 if (host->cfg_volume_perf == NULL)
1355 if ((host->cfg_volume_perf->interval.interval +
1356 host->cfg_volume_perf->interval.last_read) > now)
1359 status = cna_setup_volume_perf(host->cfg_volume_perf);
1362 assert(host->cfg_volume_perf->query != NULL);
1364 data = na_server_invoke_elem(host->srv, host->cfg_volume_perf->query);
1365 if (na_results_status(data) != NA_OK) {
1366 ERROR("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed "
1368 host->name, na_results_reason(data));
1374 cna_handle_volume_perf_data(host->name, host->cfg_volume_perf, data,
1375 host->cfg_volume_perf->interval.interval);
1378 host->cfg_volume_perf->interval.last_read = now;
1382 } /* }}} int cna_query_volume_perf */
1384 /* Data corresponding to <VolumeUsage /> */
1385 static int cna_submit_volume_usage_data(const char *hostname, /* {{{ */
1386 cfg_volume_usage_t *cfg_volume,
1388 for (data_volume_usage_t *v = cfg_volume->volumes; v != NULL; v = v->next) {
1389 char plugin_instance[DATA_MAX_NAME_LEN];
1391 uint64_t norm_used = v->norm_used;
1392 uint64_t norm_free = v->norm_free;
1393 uint64_t sis_saved = v->sis_saved;
1394 uint64_t compress_saved = v->compress_saved;
1395 uint64_t dedup_saved = v->dedup_saved;
1396 uint64_t snap_reserve_used = 0;
1397 uint64_t snap_reserve_free = v->snap_reserved;
1398 uint64_t snap_norm_used = v->snap_used;
1400 ssnprintf(plugin_instance, sizeof(plugin_instance), "volume-%s", v->name);
1402 if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_SNAP_USED |
1403 HAVE_VOLUME_USAGE_SNAP_RSVD)) {
1404 if (v->snap_reserved > v->snap_used) {
1405 snap_reserve_free = v->snap_reserved - v->snap_used;
1406 snap_reserve_used = v->snap_used;
1409 snap_reserve_free = 0;
1410 snap_reserve_used = v->snap_reserved;
1411 snap_norm_used = v->snap_used - v->snap_reserved;
1415 /* The space used by snapshots but not reserved for them is included in
1416 * both, norm_used and snap_norm_used. If possible, subtract this here. */
1417 if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_NORM_USED |
1418 HAVE_VOLUME_USAGE_SNAP_USED)) {
1419 if (norm_used >= snap_norm_used)
1420 norm_used -= snap_norm_used;
1422 ERROR("netapp plugin: (norm_used = %" PRIu64 ") < (snap_norm_used = "
1423 "%" PRIu64 ") for host %s. Invalidating both.",
1424 norm_used, snap_norm_used, hostname);
1426 ~(HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED);
1430 if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1431 submit_double(hostname, /* plugin instance = */ plugin_instance,
1432 "df_complex", "free", (double)norm_free,
1433 /* timestamp = */ 0, interval);
1435 if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1436 submit_double(hostname, /* plugin instance = */ plugin_instance,
1437 "df_complex", "sis_saved", (double)sis_saved,
1438 /* timestamp = */ 0, interval);
1440 if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_COMPRESS_SAVED))
1441 submit_double(hostname, /* plugin instance = */ plugin_instance,
1442 "df_complex", "compression_saved", (double)compress_saved,
1443 /* timestamp = */ 0, interval);
1445 if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_DEDUP_SAVED))
1446 submit_double(hostname, /* plugin instance = */ plugin_instance,
1447 "df_complex", "dedup_saved", (double)dedup_saved,
1448 /* timestamp = */ 0, interval);
1450 if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1451 submit_double(hostname, /* plugin instance = */ plugin_instance,
1452 "df_complex", "used", (double)norm_used,
1453 /* timestamp = */ 0, interval);
1455 if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1456 submit_double(hostname, /* plugin instance = */ plugin_instance,
1457 "df_complex", "snap_reserved", (double)snap_reserve_free,
1458 /* timestamp = */ 0, interval);
1460 if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_SNAP_USED |
1461 HAVE_VOLUME_USAGE_SNAP_RSVD))
1462 submit_double(hostname, /* plugin instance = */ plugin_instance,
1463 "df_complex", "snap_reserve_used",
1464 (double)snap_reserve_used, /* timestamp = */ 0, interval);
1466 if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1467 submit_double(hostname, /* plugin instance = */ plugin_instance,
1468 "df_complex", "snap_normal_used", (double)snap_norm_used,
1469 /* timestamp = */ 0, interval);
1471 /* Clear all the HAVE_* flags */
1472 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1473 } /* for (v = cfg_volume->volumes) */
1476 } /* }}} int cna_submit_volume_usage_data */
1478 /* Switch the state of a volume between online and offline and send out a
1480 static int cna_change_volume_status(const char *hostname, /* {{{ */
1481 data_volume_usage_t *v) {
1482 notification_t n = {0};
1485 sstrncpy(n.host, hostname, sizeof(n.host));
1486 sstrncpy(n.plugin, "netapp", sizeof(n.plugin));
1487 sstrncpy(n.plugin_instance, v->name, sizeof(n.plugin_instance));
1489 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0) {
1490 n.severity = NOTIF_OKAY;
1491 ssnprintf(n.message, sizeof(n.message), "Volume %s is now online.",
1493 v->flags &= ~IS_VOLUME_USAGE_OFFLINE;
1495 n.severity = NOTIF_WARNING;
1496 ssnprintf(n.message, sizeof(n.message), "Volume %s is now offline.",
1498 v->flags |= IS_VOLUME_USAGE_OFFLINE;
1501 return (plugin_dispatch_notification(&n));
1502 } /* }}} int cna_change_volume_status */
1504 static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
1505 data_volume_usage_t *v) {
1506 uint64_t snap_used = 0, value;
1507 na_elem_t *data, *elem_snapshots;
1508 na_elem_iter_t iter_snap;
1510 data = na_server_invoke_elem(host->srv, v->snap_query);
1511 if (na_results_status(data) != NA_OK) {
1512 if (na_results_errno(data) == EVOLUMEOFFLINE) {
1513 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) == 0)
1514 cna_change_volume_status(host->name, v);
1516 ERROR("netapp plugin: cna_handle_volume_snap_usage: "
1517 "na_server_invoke_elem for "
1518 "volume \"%s\" on host %s failed with error %d: %s",
1519 v->name, host->name, na_results_errno(data),
1520 na_results_reason(data));
1526 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0)
1527 cna_change_volume_status(host->name, v);
1529 elem_snapshots = na_elem_child(data, "snapshots");
1530 if (elem_snapshots == NULL) {
1531 ERROR("netapp plugin: cna_handle_volume_snap_usage: "
1532 "na_elem_child (\"snapshots\") failed "
1539 iter_snap = na_child_iterator(elem_snapshots);
1540 for (na_elem_t *elem_snap = na_iterator_next(&iter_snap); elem_snap != NULL;
1541 elem_snap = na_iterator_next(&iter_snap)) {
1542 value = na_child_get_uint64(elem_snap, "cumulative-total", 0);
1543 /* "cumulative-total" is the total size of the oldest snapshot plus all
1544 * newer ones in blocks (1KB). We therefore are looking for the highest
1545 * number of all snapshots - that's the size required for the snapshots. */
1546 if (value > snap_used)
1550 /* snap_used is in 1024 byte blocks */
1551 v->snap_used = snap_used * 1024;
1552 v->flags |= HAVE_VOLUME_USAGE_SNAP_USED;
1553 } /* }}} void cna_handle_volume_snap_usage */
1555 static void cna_handle_volume_sis_data(const host_config_t *host, /* {{{ */
1556 data_volume_usage_t *v, na_elem_t *sis) {
1557 const char *sis_state;
1558 uint64_t sis_saved_reported;
1560 if (na_elem_child(sis, "sis-info"))
1561 sis = na_elem_child(sis, "sis-info");
1563 sis_state = na_child_get_string(sis, "state");
1564 if (sis_state == NULL)
1567 /* If SIS is not enabled, there's nothing left to do for this volume. */
1568 if (strcmp("enabled", sis_state) != 0)
1571 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1572 if (sis_saved_reported == UINT64_MAX)
1575 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1576 if ((sis_saved_reported >> 32) != 0) {
1577 /* In case they ever fix this bug. */
1578 v->sis_saved = sis_saved_reported;
1579 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1580 } else { /* really hacky work-around code. {{{ */
1581 uint64_t sis_saved_percent;
1582 uint64_t sis_saved_guess;
1583 uint64_t overflow_guess;
1584 uint64_t guess1, guess2, guess3;
1586 /* Check if we have v->norm_used. Without it, we cannot calculate
1587 * sis_saved_guess. */
1588 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1592 na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1593 if (sis_saved_percent > 100)
1596 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1597 * will hopefully be fixed in later versions. To work around the bug, try
1598 * to figure out how often the 32bit integer wrapped around by using the
1599 * "percentage-saved" value. Because the percentage is in the range
1600 * [0-100], this should work as long as the saved space does not exceed
1602 /* percentage-saved = size-saved / (size-saved + size-used) */
1603 if (sis_saved_percent < 100)
1605 v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1607 sis_saved_guess = v->norm_used;
1609 overflow_guess = sis_saved_guess >> 32;
1610 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported
1611 : sis_saved_reported;
1612 guess2 = (overflow_guess << 32) + sis_saved_reported;
1613 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1615 if (sis_saved_guess < guess2) {
1616 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1617 v->sis_saved = guess1;
1619 v->sis_saved = guess2;
1621 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1622 v->sis_saved = guess2;
1624 v->sis_saved = guess3;
1626 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1627 } /* }}} end of 32-bit workaround */
1628 } /* }}} void cna_handle_volume_sis_data */
1630 /* ONTAP >= 8.1 uses SIS for managing dedup and compression */
1631 static void cna_handle_volume_sis_saved(const host_config_t *host, /* {{{ */
1632 data_volume_usage_t *v,
1636 if (na_elem_child(sis, "sis-info"))
1637 sis = na_elem_child(sis, "sis-info");
1639 saved = na_child_get_uint64(sis, "compress-saved", UINT64_MAX);
1640 if (saved != UINT64_MAX) {
1641 v->compress_saved = saved;
1642 v->flags |= HAVE_VOLUME_USAGE_COMPRESS_SAVED;
1645 saved = na_child_get_uint64(sis, "dedup-saved", UINT64_MAX);
1646 if (saved != UINT64_MAX) {
1647 v->dedup_saved = saved;
1648 v->flags |= HAVE_VOLUME_USAGE_DEDUP_SAVED;
1650 } /* }}} void cna_handle_volume_sis_saved */
1652 static int cna_handle_volume_usage_data(const host_config_t *host, /* {{{ */
1653 cfg_volume_usage_t *cfg_volume,
1655 na_elem_t *elem_volumes;
1656 na_elem_iter_t iter_volume;
1658 elem_volumes = na_elem_child(data, "volumes");
1659 if (elem_volumes == NULL) {
1660 ERROR("netapp plugin: cna_handle_volume_usage_data: "
1661 "na_elem_child (\"volumes\") failed "
1667 iter_volume = na_child_iterator(elem_volumes);
1668 for (na_elem_t *elem_volume = na_iterator_next(&iter_volume);
1669 elem_volume != NULL; elem_volume = na_iterator_next(&iter_volume)) {
1670 const char *volume_name, *state;
1672 data_volume_usage_t *v;
1677 volume_name = na_child_get_string(elem_volume, "name");
1678 if (volume_name == NULL)
1681 state = na_child_get_string(elem_volume, "state");
1682 if ((state == NULL) || (strcmp(state, "online") != 0))
1685 /* get_volume_usage may return NULL if the volume is to be ignored. */
1686 v = get_volume_usage(cfg_volume, volume_name);
1690 if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
1691 cna_handle_volume_snap_usage(host, v);
1693 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1696 /* 2^4 exa-bytes? This will take a while ;) */
1697 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1698 if (value != UINT64_MAX) {
1699 v->norm_free = value;
1700 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1703 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1704 if (value != UINT64_MAX) {
1705 v->norm_used = value;
1706 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1709 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved",
1711 if (value != UINT64_MAX) {
1712 /* 1 block == 1024 bytes as per API docs */
1713 v->snap_reserved = 1024 * value;
1714 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1717 sis = na_elem_child(elem_volume, "sis");
1719 cna_handle_volume_sis_data(host, v, sis);
1720 cna_handle_volume_sis_saved(host, v, sis);
1722 } /* for (elem_volume) */
1724 return (cna_submit_volume_usage_data(
1725 host->name, cfg_volume, host->cfg_volume_usage->interval.interval));
1726 } /* }}} int cna_handle_volume_usage_data */
1728 static int cna_setup_volume_usage(cfg_volume_usage_t *cvu) /* {{{ */
1733 if (cvu->query != NULL)
1736 cvu->query = na_elem_new("volume-list-info");
1737 if (cvu->query == NULL) {
1738 ERROR("netapp plugin: na_elem_new failed.");
1743 } /* }}} int cna_setup_volume_usage */
1745 static int cna_query_volume_usage(host_config_t *host) /* {{{ */
1754 /* If the user did not configure volume_usage statistics, return without
1755 * doing anything. */
1756 if (host->cfg_volume_usage == NULL)
1760 if ((host->cfg_volume_usage->interval.interval +
1761 host->cfg_volume_usage->interval.last_read) > now)
1764 status = cna_setup_volume_usage(host->cfg_volume_usage);
1767 assert(host->cfg_volume_usage->query != NULL);
1769 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1770 if (na_results_status(data) != NA_OK) {
1771 ERROR("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed "
1773 host->name, na_results_reason(data));
1778 status = cna_handle_volume_usage_data(host, host->cfg_volume_usage, data);
1781 host->cfg_volume_usage->interval.last_read = now;
1785 } /* }}} int cna_query_volume_usage */
1787 /* Data corresponding to <Quota /> */
1788 static int cna_handle_quota_data(const host_config_t *host, /* {{{ */
1789 cfg_quota_t *cfg_quota, na_elem_t *data) {
1790 na_elem_t *elem_quotas;
1791 na_elem_iter_t iter_quota;
1793 elem_quotas = na_elem_child(data, "quotas");
1794 if (elem_quotas == NULL) {
1795 ERROR("netapp plugin: cna_handle_quota_data: "
1796 "na_elem_child (\"quotas\") failed "
1802 iter_quota = na_child_iterator(elem_quotas);
1803 for (na_elem_t *elem_quota = na_iterator_next(&iter_quota);
1804 elem_quota != NULL; elem_quota = na_iterator_next(&iter_quota)) {
1805 const char *quota_type, *volume_name, *tree_name;
1808 char plugin_instance[DATA_MAX_NAME_LEN];
1810 quota_type = na_child_get_string(elem_quota, "quota-type");
1811 if (quota_type == NULL)
1814 /* possible TODO: support other types as well */
1815 if (strcmp(quota_type, "tree") != 0)
1818 tree_name = na_child_get_string(elem_quota, "tree");
1819 if ((tree_name == NULL) || (*tree_name == '\0'))
1822 volume_name = na_child_get_string(elem_quota, "volume");
1823 if (volume_name == NULL)
1826 ssnprintf(plugin_instance, sizeof(plugin_instance), "quota-%s-%s",
1827 volume_name, tree_name);
1829 value = na_child_get_uint64(elem_quota, "disk-used", UINT64_MAX);
1830 if (value != UINT64_MAX) {
1831 value *= 1024; /* disk-used reports kilobytes */
1832 submit_double(host->name, plugin_instance,
1833 /* type = */ "df_complex", /* type instance = */ NULL,
1834 (double)value, /* timestamp = */ 0,
1835 host->cfg_quota->interval.interval);
1838 value = na_child_get_uint64(elem_quota, "files-used", UINT64_MAX);
1839 if (value != UINT64_MAX) {
1840 submit_double(host->name, plugin_instance,
1841 /* type = */ "files", /* type instance = */ NULL,
1842 (double)value, /* timestamp = */ 0,
1843 host->cfg_quota->interval.interval);
1845 } /* for (elem_quota) */
1848 } /* }}} int cna_handle_volume_usage_data */
1850 static int cna_setup_quota(cfg_quota_t *cq) /* {{{ */
1855 if (cq->query != NULL)
1858 cq->query = na_elem_new("quota-report");
1859 if (cq->query == NULL) {
1860 ERROR("netapp plugin: na_elem_new failed.");
1865 } /* }}} int cna_setup_quota */
1867 static int cna_query_quota(host_config_t *host) /* {{{ */
1876 /* If the user did not configure quota statistics, return without
1877 * doing anything. */
1878 if (host->cfg_quota == NULL)
1882 if ((host->cfg_quota->interval.interval +
1883 host->cfg_quota->interval.last_read) > now)
1886 status = cna_setup_quota(host->cfg_quota);
1889 assert(host->cfg_quota->query != NULL);
1891 data = na_server_invoke_elem(host->srv, host->cfg_quota->query);
1892 if (na_results_status(data) != NA_OK) {
1893 ERROR("netapp plugin: cna_query_quota: na_server_invoke_elem failed for "
1895 host->name, na_results_reason(data));
1900 status = cna_handle_quota_data(host, host->cfg_quota, data);
1903 host->cfg_quota->interval.last_read = now;
1907 } /* }}} int cna_query_quota */
1909 /* Data corresponding to <SnapVault /> */
1910 static int cna_handle_snapvault_data(const char *hostname, /* {{{ */
1911 cfg_snapvault_t *cfg_snapvault,
1912 na_elem_t *data, cdtime_t interval) {
1913 na_elem_t *status_list = na_elem_child(data, "status-list");
1914 if (status_list == NULL) {
1915 ERROR("netapp plugin: SnapVault status record missing status-list");
1919 na_elem_iter_t status_iter = na_child_iterator(status_list);
1920 for (na_elem_t *status = na_iterator_next(&status_iter); status != NULL;
1921 status = na_iterator_next(&status_iter)) {
1922 const char *dest_sys, *dest_path, *src_sys, *src_path;
1923 char plugin_instance[DATA_MAX_NAME_LEN];
1926 dest_sys = na_child_get_string(status, "destination-system");
1927 dest_path = na_child_get_string(status, "destination-path");
1928 src_sys = na_child_get_string(status, "source-system");
1929 src_path = na_child_get_string(status, "source-path");
1931 if ((!dest_sys) || (!dest_path) || (!src_sys) || (!src_path))
1934 value = na_child_get_uint64(status, "lag-time", UINT64_MAX);
1935 if (value == UINT64_MAX) /* no successful baseline transfer yet */
1938 /* possible TODO: make plugin instance configurable */
1939 ssnprintf(plugin_instance, sizeof(plugin_instance), "snapvault-%s",
1941 submit_double(hostname, plugin_instance, /* type = */ "delay", NULL,
1942 (double)value, /* timestamp = */ 0, interval);
1944 value = na_child_get_uint64(status, "last-transfer-duration", UINT64_MAX);
1945 if (value != UINT64_MAX)
1946 submit_double(hostname, plugin_instance, /* type = */ "duration",
1947 "last_transfer", (double)value, /* timestamp = */ 0,
1950 value = na_child_get_uint64(status, "transfer-progress", UINT64_MAX);
1951 if (value == UINT64_MAX)
1952 value = na_child_get_uint64(status, "last-transfer-size", UINT64_MAX);
1953 if (value != UINT64_MAX) {
1954 value *= 1024; /* this is kilobytes */
1955 submit_derive(hostname, plugin_instance, /* type = */ "if_rx_octets",
1956 "transferred", value, /* timestamp = */ 0, interval);
1958 } /* for (status) */
1961 } /* }}} int cna_handle_snapvault_data */
1963 static int cna_handle_snapvault_iter(host_config_t *host, /* {{{ */
1967 uint32_t records_count;
1969 records_count = na_child_get_uint32(data, "records", UINT32_MAX);
1970 if (records_count == UINT32_MAX)
1973 tag = na_child_get_string(data, "tag");
1977 DEBUG("netapp plugin: Iterating %u SV records (tag = %s)", records_count,
1980 for (uint32_t i = 0; i < records_count; ++i) {
1983 elem = na_server_invoke(
1984 host->srv, "snapvault-secondary-relationship-status-list-iter-next",
1985 "maximum", "1", "tag", tag, NULL);
1987 if (na_results_status(elem) != NA_OK) {
1988 ERROR("netapp plugin: cna_handle_snapvault_iter: "
1989 "na_server_invoke failed for host %s: %s",
1990 host->name, na_results_reason(data));
1995 cna_handle_snapvault_data(host->name, host->cfg_snapvault, elem,
1996 host->cfg_snapvault->interval.interval);
2000 na_elem_free(na_server_invoke(
2001 host->srv, "snapvault-secondary-relationship-status-list-iter-end", "tag",
2004 } /* }}} int cna_handle_snapvault_iter */
2006 static int cna_setup_snapvault(cfg_snapvault_t *sv) /* {{{ */
2011 if (sv->query != NULL)
2015 na_elem_new("snapvault-secondary-relationship-status-list-iter-start");
2016 if (sv->query == NULL) {
2017 ERROR("netapp plugin: na_elem_new failed.");
2022 } /* }}} int cna_setup_snapvault */
2024 static int cna_query_snapvault(host_config_t *host) /* {{{ */
2033 if (host->cfg_snapvault == NULL)
2037 if ((host->cfg_snapvault->interval.interval +
2038 host->cfg_snapvault->interval.last_read) > now)
2041 status = cna_setup_snapvault(host->cfg_snapvault);
2044 assert(host->cfg_snapvault->query != NULL);
2046 data = na_server_invoke_elem(host->srv, host->cfg_snapvault->query);
2047 if (na_results_status(data) != NA_OK) {
2048 ERROR("netapp plugin: cna_query_snapvault: na_server_invoke_elem failed "
2050 host->name, na_results_reason(data));
2055 status = cna_handle_snapvault_iter(host, data);
2058 host->cfg_snapvault->interval.last_read = now;
2062 } /* }}} int cna_query_snapvault */
2064 /* Data corresponding to <System /> */
2065 static int cna_handle_system_data(const char *hostname, /* {{{ */
2066 cfg_system_t *cfg_system, na_elem_t *data,
2068 na_elem_t *instances;
2069 na_elem_iter_t counter_iter;
2071 derive_t disk_read = 0, disk_written = 0;
2072 derive_t net_recv = 0, net_sent = 0;
2073 derive_t cpu_busy = 0, cpu_total = 0;
2074 uint32_t counter_flags = 0;
2076 const char *instance;
2079 timestamp = cna_child_get_cdtime(data);
2081 instances = na_elem_child(na_elem_child(data, "instances"), "instance-data");
2082 if (instances == NULL) {
2083 ERROR("netapp plugin: cna_handle_system_data: "
2084 "na_elem_child (\"instances\") failed "
2090 instance = na_child_get_string(instances, "name");
2091 if (instance == NULL) {
2092 ERROR("netapp plugin: cna_handle_system_data: "
2093 "na_child_get_string (\"name\") failed "
2099 counter_iter = na_child_iterator(na_elem_child(instances, "counters"));
2100 for (na_elem_t *counter = na_iterator_next(&counter_iter); counter != NULL;
2101 counter = na_iterator_next(&counter_iter)) {
2105 name = na_child_get_string(counter, "name");
2109 value = na_child_get_uint64(counter, "value", UINT64_MAX);
2110 if (value == UINT64_MAX)
2113 if (!strcmp(name, "disk_data_read")) {
2114 disk_read = (derive_t)(value * 1024);
2115 counter_flags |= 0x01;
2116 } else if (!strcmp(name, "disk_data_written")) {
2117 disk_written = (derive_t)(value * 1024);
2118 counter_flags |= 0x02;
2119 } else if (!strcmp(name, "net_data_recv")) {
2120 net_recv = (derive_t)(value * 1024);
2121 counter_flags |= 0x04;
2122 } else if (!strcmp(name, "net_data_sent")) {
2123 net_sent = (derive_t)(value * 1024);
2124 counter_flags |= 0x08;
2125 } else if (!strcmp(name, "cpu_busy")) {
2126 cpu_busy = (derive_t)value;
2127 counter_flags |= 0x10;
2128 } else if (!strcmp(name, "cpu_elapsed_time")) {
2129 cpu_total = (derive_t)value;
2130 counter_flags |= 0x20;
2131 } else if ((cfg_system->flags & CFG_SYSTEM_OPS) && (value > 0) &&
2132 (strlen(name) > 4) &&
2133 (!strcmp(name + strlen(name) - 4, "_ops"))) {
2134 submit_derive(hostname, instance, "disk_ops_complex", name,
2135 (derive_t)value, timestamp, interval);
2137 } /* for (counter) */
2139 if ((cfg_system->flags & CFG_SYSTEM_DISK) &&
2140 (HAS_ALL_FLAGS(counter_flags, 0x01 | 0x02)))
2141 submit_two_derive(hostname, instance, "disk_octets", NULL, disk_read,
2142 disk_written, timestamp, interval);
2144 if ((cfg_system->flags & CFG_SYSTEM_NET) &&
2145 (HAS_ALL_FLAGS(counter_flags, 0x04 | 0x08)))
2146 submit_two_derive(hostname, instance, "if_octets", NULL, net_recv, net_sent,
2147 timestamp, interval);
2149 if ((cfg_system->flags & CFG_SYSTEM_CPU) &&
2150 (HAS_ALL_FLAGS(counter_flags, 0x10 | 0x20))) {
2151 submit_derive(hostname, instance, "cpu", "system", cpu_busy, timestamp,
2153 submit_derive(hostname, instance, "cpu", "idle", cpu_total - cpu_busy,
2154 timestamp, interval);
2158 } /* }}} int cna_handle_system_data */
2160 static int cna_setup_system(cfg_system_t *cs) /* {{{ */
2165 if (cs->query != NULL)
2168 cs->query = na_elem_new("perf-object-get-instances");
2169 if (cs->query == NULL) {
2170 ERROR("netapp plugin: na_elem_new failed.");
2173 na_child_add_string(cs->query, "objectname", "system");
2176 } /* }}} int cna_setup_system */
2178 static int cna_query_system(host_config_t *host) /* {{{ */
2187 /* If system statistics were not configured, return without doing anything. */
2188 if (host->cfg_system == NULL)
2192 if ((host->cfg_system->interval.interval +
2193 host->cfg_system->interval.last_read) > now)
2196 status = cna_setup_system(host->cfg_system);
2199 assert(host->cfg_system->query != NULL);
2201 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
2202 if (na_results_status(data) != NA_OK) {
2203 ERROR("netapp plugin: cna_query_system: na_server_invoke_elem failed for "
2205 host->name, na_results_reason(data));
2210 status = cna_handle_system_data(host->name, host->cfg_system, data,
2211 host->cfg_system->interval.interval);
2214 host->cfg_system->interval.last_read = now;
2218 } /* }}} int cna_query_system */
2221 * Configuration handling
2223 /* Sets a given flag if the boolean argument is true and unsets the flag if it
2224 * is false. On error, the flag-field is not changed. */
2225 static int cna_config_bool_to_flag(const oconfig_item_t *ci, /* {{{ */
2226 uint32_t *flags, uint32_t flag) {
2227 if ((ci == NULL) || (flags == NULL))
2230 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
2231 WARNING("netapp plugin: The %s option needs exactly one boolean argument.",
2236 if (ci->values[0].value.boolean)
2242 } /* }}} int cna_config_bool_to_flag */
2244 /* Handling of the "Interval" option which is allowed in every block. */
2245 static int cna_config_get_interval(const oconfig_item_t *ci, /* {{{ */
2246 cna_interval_t *out_interval) {
2250 status = cf_util_get_cdtime(ci, &tmp);
2254 out_interval->interval = tmp;
2255 out_interval->last_read = 0;
2258 } /* }}} int cna_config_get_interval */
2260 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
2261 * <VolumePerf /> block. */
2262 static void cna_config_volume_perf_option(cfg_volume_perf_t *cvp, /* {{{ */
2263 const oconfig_item_t *ci) {
2267 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2269 "netapp plugin: The %s option requires exactly one string argument.",
2274 name = ci->values[0].value.string;
2276 if (strcasecmp("GetIO", ci->key) == 0)
2277 il = cvp->il_octets;
2278 else if (strcasecmp("GetOps", ci->key) == 0)
2279 il = cvp->il_operations;
2280 else if (strcasecmp("GetLatency", ci->key) == 0)
2281 il = cvp->il_latency;
2285 ignorelist_add(il, name);
2286 } /* }}} void cna_config_volume_perf_option */
2288 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
2289 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
2290 static void cna_config_volume_perf_default(cfg_volume_perf_t *cvp, /* {{{ */
2291 const oconfig_item_t *ci) {
2294 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
2296 "netapp plugin: The %s option requires exactly one string argument.",
2301 if (strcasecmp("IgnoreSelectedIO", ci->key) == 0)
2302 il = cvp->il_octets;
2303 else if (strcasecmp("IgnoreSelectedOps", ci->key) == 0)
2304 il = cvp->il_operations;
2305 else if (strcasecmp("IgnoreSelectedLatency", ci->key) == 0)
2306 il = cvp->il_latency;
2310 if (ci->values[0].value.boolean)
2311 ignorelist_set_invert(il, /* invert = */ 0);
2313 ignorelist_set_invert(il, /* invert = */ 1);
2314 } /* }}} void cna_config_volume_perf_default */
2316 /* Corresponds to a <Disks /> block */
2321 * IgnoreSelectedIO false
2325 * IgnoreSelectedOps false
2329 * IgnoreSelectedLatency false
2332 /* Corresponds to a <VolumePerf /> block */
2333 static int cna_config_volume_performance(host_config_t *host, /* {{{ */
2334 const oconfig_item_t *ci) {
2335 cfg_volume_perf_t *cfg_volume_perf;
2337 if ((host == NULL) || (ci == NULL))
2340 if (host->cfg_volume_perf == NULL) {
2341 cfg_volume_perf = calloc(1, sizeof(*cfg_volume_perf));
2342 if (cfg_volume_perf == NULL)
2345 /* Set default flags */
2346 cfg_volume_perf->query = NULL;
2347 cfg_volume_perf->volumes = NULL;
2349 cfg_volume_perf->il_octets = ignorelist_create(/* invert = */ 1);
2350 if (cfg_volume_perf->il_octets == NULL) {
2351 sfree(cfg_volume_perf);
2355 cfg_volume_perf->il_operations = ignorelist_create(/* invert = */ 1);
2356 if (cfg_volume_perf->il_operations == NULL) {
2357 ignorelist_free(cfg_volume_perf->il_octets);
2358 sfree(cfg_volume_perf);
2362 cfg_volume_perf->il_latency = ignorelist_create(/* invert = */ 1);
2363 if (cfg_volume_perf->il_latency == NULL) {
2364 ignorelist_free(cfg_volume_perf->il_octets);
2365 ignorelist_free(cfg_volume_perf->il_operations);
2366 sfree(cfg_volume_perf);
2370 host->cfg_volume_perf = cfg_volume_perf;
2372 cfg_volume_perf = host->cfg_volume_perf;
2374 for (int i = 0; i < ci->children_num; ++i) {
2375 oconfig_item_t *item = ci->children + i;
2377 /* if (!item || !item->key || !*item->key) continue; */
2378 if (strcasecmp(item->key, "Interval") == 0)
2379 cna_config_get_interval(item, &cfg_volume_perf->interval);
2380 else if (!strcasecmp(item->key, "GetIO"))
2381 cna_config_volume_perf_option(cfg_volume_perf, item);
2382 else if (!strcasecmp(item->key, "GetOps"))
2383 cna_config_volume_perf_option(cfg_volume_perf, item);
2384 else if (!strcasecmp(item->key, "GetLatency"))
2385 cna_config_volume_perf_option(cfg_volume_perf, item);
2386 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
2387 cna_config_volume_perf_default(cfg_volume_perf, item);
2388 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
2389 cna_config_volume_perf_default(cfg_volume_perf, item);
2390 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
2391 cna_config_volume_perf_default(cfg_volume_perf, item);
2393 WARNING("netapp plugin: The option %s is not allowed within "
2394 "`VolumePerf' blocks.",
2399 } /* }}} int cna_config_volume_performance */
2401 /* Handling of the "GetCapacity" and "GetSnapshot" options within a
2402 * <VolumeUsage /> block. */
2403 static void cna_config_volume_usage_option(cfg_volume_usage_t *cvu, /* {{{ */
2404 const oconfig_item_t *ci) {
2408 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2410 "netapp plugin: The %s option requires exactly one string argument.",
2415 name = ci->values[0].value.string;
2417 if (strcasecmp("GetCapacity", ci->key) == 0)
2418 il = cvu->il_capacity;
2419 else if (strcasecmp("GetSnapshot", ci->key) == 0)
2420 il = cvu->il_snapshot;
2424 ignorelist_add(il, name);
2425 } /* }}} void cna_config_volume_usage_option */
2427 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
2428 * options within a <VolumeUsage /> block. */
2429 static void cna_config_volume_usage_default(cfg_volume_usage_t *cvu, /* {{{ */
2430 const oconfig_item_t *ci) {
2433 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
2435 "netapp plugin: The %s option requires exactly one string argument.",
2440 if (strcasecmp("IgnoreSelectedCapacity", ci->key) == 0)
2441 il = cvu->il_capacity;
2442 else if (strcasecmp("IgnoreSelectedSnapshot", ci->key) == 0)
2443 il = cvu->il_snapshot;
2447 if (ci->values[0].value.boolean)
2448 ignorelist_set_invert(il, /* invert = */ 0);
2450 ignorelist_set_invert(il, /* invert = */ 1);
2451 } /* }}} void cna_config_volume_usage_default */
2453 /* Corresponds to a <Quota /> block */
2454 static int cna_config_quota(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2456 cfg_quota_t *cfg_quota;
2458 if ((host == NULL) || (ci == NULL))
2461 if (host->cfg_quota == NULL) {
2462 cfg_quota = calloc(1, sizeof(*cfg_quota));
2463 if (cfg_quota == NULL)
2465 cfg_quota->query = NULL;
2467 host->cfg_quota = cfg_quota;
2469 cfg_quota = host->cfg_quota;
2471 for (int i = 0; i < ci->children_num; ++i) {
2472 oconfig_item_t *item = ci->children + i;
2474 if (strcasecmp(item->key, "Interval") == 0)
2475 cna_config_get_interval(item, &cfg_quota->interval);
2477 WARNING("netapp plugin: The option %s is not allowed within "
2483 } /* }}} int cna_config_quota */
2485 /* Corresponds to a <Disks /> block */
2486 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
2487 cfg_disk_t *cfg_disk;
2489 if ((host == NULL) || (ci == NULL))
2492 if (host->cfg_disk == NULL) {
2493 cfg_disk = calloc(1, sizeof(*cfg_disk));
2494 if (cfg_disk == NULL)
2497 /* Set default flags */
2498 cfg_disk->flags = CFG_DISK_ALL;
2499 cfg_disk->query = NULL;
2500 cfg_disk->disks = NULL;
2502 host->cfg_disk = cfg_disk;
2504 cfg_disk = host->cfg_disk;
2506 for (int i = 0; i < ci->children_num; ++i) {
2507 oconfig_item_t *item = ci->children + i;
2509 /* if (!item || !item->key || !*item->key) continue; */
2510 if (strcasecmp(item->key, "Interval") == 0)
2511 cna_config_get_interval(item, &cfg_disk->interval);
2512 else if (strcasecmp(item->key, "GetBusy") == 0)
2513 cna_config_bool_to_flag(item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2516 if ((cfg_disk->flags & CFG_DISK_ALL) == 0) {
2517 NOTICE("netapp plugin: All disk related values have been disabled. "
2518 "Collection of per-disk data will be disabled entirely.");
2519 free_cfg_disk(host->cfg_disk);
2520 host->cfg_disk = NULL;
2524 } /* }}} int cna_config_disk */
2526 /* Corresponds to a <WAFL /> block */
2527 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2529 cfg_wafl_t *cfg_wafl;
2531 if ((host == NULL) || (ci == NULL))
2534 if (host->cfg_wafl == NULL) {
2535 cfg_wafl = calloc(1, sizeof(*cfg_wafl));
2536 if (cfg_wafl == NULL)
2539 /* Set default flags */
2540 cfg_wafl->flags = CFG_WAFL_ALL;
2542 host->cfg_wafl = cfg_wafl;
2544 cfg_wafl = host->cfg_wafl;
2546 for (int i = 0; i < ci->children_num; ++i) {
2547 oconfig_item_t *item = ci->children + i;
2549 if (strcasecmp(item->key, "Interval") == 0)
2550 cna_config_get_interval(item, &cfg_wafl->interval);
2551 else if (!strcasecmp(item->key, "GetNameCache"))
2552 cna_config_bool_to_flag(item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2553 else if (!strcasecmp(item->key, "GetDirCache"))
2554 cna_config_bool_to_flag(item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2555 else if (!strcasecmp(item->key, "GetBufferCache"))
2556 cna_config_bool_to_flag(item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2557 else if (!strcasecmp(item->key, "GetInodeCache"))
2558 cna_config_bool_to_flag(item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2560 WARNING("netapp plugin: The %s config option is not allowed within "
2565 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0) {
2566 NOTICE("netapp plugin: All WAFL related values have been disabled. "
2567 "Collection of WAFL data will be disabled entirely.");
2568 free_cfg_wafl(host->cfg_wafl);
2569 host->cfg_wafl = NULL;
2573 } /* }}} int cna_config_wafl */
2577 * GetCapacity "vol0"
2578 * GetCapacity "vol1"
2579 * GetCapacity "vol2"
2580 * GetCapacity "vol3"
2581 * GetCapacity "vol4"
2582 * IgnoreSelectedCapacity false
2584 * GetSnapshot "vol0"
2585 * GetSnapshot "vol3"
2586 * GetSnapshot "vol4"
2587 * GetSnapshot "vol7"
2588 * IgnoreSelectedSnapshot false
2591 /* Corresponds to a <VolumeUsage /> block */
2592 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2593 const oconfig_item_t *ci) {
2594 cfg_volume_usage_t *cfg_volume_usage;
2596 if ((host == NULL) || (ci == NULL))
2599 if (host->cfg_volume_usage == NULL) {
2600 cfg_volume_usage = calloc(1, sizeof(*cfg_volume_usage));
2601 if (cfg_volume_usage == NULL)
2604 /* Set default flags */
2605 cfg_volume_usage->query = NULL;
2606 cfg_volume_usage->volumes = NULL;
2608 cfg_volume_usage->il_capacity = ignorelist_create(/* invert = */ 1);
2609 if (cfg_volume_usage->il_capacity == NULL) {
2610 sfree(cfg_volume_usage);
2614 cfg_volume_usage->il_snapshot = ignorelist_create(/* invert = */ 1);
2615 if (cfg_volume_usage->il_snapshot == NULL) {
2616 ignorelist_free(cfg_volume_usage->il_capacity);
2617 sfree(cfg_volume_usage);
2621 host->cfg_volume_usage = cfg_volume_usage;
2623 cfg_volume_usage = host->cfg_volume_usage;
2625 for (int i = 0; i < ci->children_num; ++i) {
2626 oconfig_item_t *item = ci->children + i;
2628 /* if (!item || !item->key || !*item->key) continue; */
2629 if (strcasecmp(item->key, "Interval") == 0)
2630 cna_config_get_interval(item, &cfg_volume_usage->interval);
2631 else if (!strcasecmp(item->key, "GetCapacity"))
2632 cna_config_volume_usage_option(cfg_volume_usage, item);
2633 else if (!strcasecmp(item->key, "GetSnapshot"))
2634 cna_config_volume_usage_option(cfg_volume_usage, item);
2635 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2636 cna_config_volume_usage_default(cfg_volume_usage, item);
2637 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2638 cna_config_volume_usage_default(cfg_volume_usage, item);
2640 WARNING("netapp plugin: The option %s is not allowed within "
2641 "`VolumeUsage' blocks.",
2646 } /* }}} int cna_config_volume_usage */
2648 /* Corresponds to a <SnapVault /> block */
2649 static int cna_config_snapvault(host_config_t *host, /* {{{ */
2650 const oconfig_item_t *ci) {
2651 cfg_snapvault_t *cfg_snapvault;
2653 if ((host == NULL) || (ci == NULL))
2656 if (host->cfg_snapvault == NULL) {
2657 cfg_snapvault = calloc(1, sizeof(*cfg_snapvault));
2658 if (cfg_snapvault == NULL)
2660 cfg_snapvault->query = NULL;
2662 host->cfg_snapvault = cfg_snapvault;
2665 cfg_snapvault = host->cfg_snapvault;
2667 for (int i = 0; i < ci->children_num; ++i) {
2668 oconfig_item_t *item = ci->children + i;
2670 if (strcasecmp(item->key, "Interval") == 0)
2671 cna_config_get_interval(item, &cfg_snapvault->interval);
2673 WARNING("netapp plugin: The option %s is not allowed within "
2674 "`SnapVault' blocks.",
2679 } /* }}} int cna_config_snapvault */
2681 /* Corresponds to a <System /> block */
2682 static int cna_config_system(host_config_t *host, /* {{{ */
2683 oconfig_item_t *ci) {
2684 cfg_system_t *cfg_system;
2686 if ((host == NULL) || (ci == NULL))
2689 if (host->cfg_system == NULL) {
2690 cfg_system = calloc(1, sizeof(*cfg_system));
2691 if (cfg_system == NULL)
2694 /* Set default flags */
2695 cfg_system->flags = CFG_SYSTEM_ALL;
2696 cfg_system->query = NULL;
2698 host->cfg_system = cfg_system;
2700 cfg_system = host->cfg_system;
2702 for (int i = 0; i < ci->children_num; ++i) {
2703 oconfig_item_t *item = ci->children + i;
2705 if (strcasecmp(item->key, "Interval") == 0) {
2706 cna_config_get_interval(item, &cfg_system->interval);
2707 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2708 cna_config_bool_to_flag(item, &cfg_system->flags, CFG_SYSTEM_CPU);
2709 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2710 cna_config_bool_to_flag(item, &cfg_system->flags, CFG_SYSTEM_NET);
2711 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2712 cna_config_bool_to_flag(item, &cfg_system->flags, CFG_SYSTEM_OPS);
2713 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2714 cna_config_bool_to_flag(item, &cfg_system->flags, CFG_SYSTEM_DISK);
2716 WARNING("netapp plugin: The %s config option is not allowed within "
2722 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0) {
2723 NOTICE("netapp plugin: All system related values have been disabled. "
2724 "Collection of system data will be disabled entirely.");
2725 free_cfg_system(host->cfg_system);
2726 host->cfg_system = NULL;
2730 } /* }}} int cna_config_system */
2732 /* Corresponds to a <Host /> block. */
2733 static host_config_t *cna_alloc_host(void) /* {{{ */
2735 host_config_t *host;
2737 host = calloc(1, sizeof(*host));
2742 host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2744 host->username = NULL;
2745 host->password = NULL;
2746 host->vfiler = NULL;
2748 host->cfg_wafl = NULL;
2749 host->cfg_disk = NULL;
2750 host->cfg_volume_perf = NULL;
2751 host->cfg_volume_usage = NULL;
2752 host->cfg_quota = NULL;
2753 host->cfg_snapvault = NULL;
2754 host->cfg_system = NULL;
2757 } /* }}} host_config_t *cna_alloc_host */
2759 static host_config_t *cna_shallow_clone_host(host_config_t *host) /* {{{ */
2761 host_config_t *clone;
2766 clone = cna_alloc_host();
2770 if (host->name != NULL) {
2771 clone->name = strdup(host->name);
2772 if (clone->name == NULL) {
2773 free_host_config(clone);
2778 clone->protocol = host->protocol;
2780 if (host->host != NULL) {
2781 clone->host = strdup(host->host);
2782 if (clone->host == NULL) {
2783 free_host_config(clone);
2788 clone->port = host->port;
2790 if (host->username != NULL) {
2791 clone->username = strdup(host->username);
2792 if (clone->username == NULL) {
2793 free_host_config(clone);
2797 if (host->password != NULL) {
2798 clone->password = strdup(host->password);
2799 if (clone->password == NULL) {
2800 free_host_config(clone);
2805 clone->interval = host->interval;
2808 } /* }}} host_config_t *cna_shallow_clone_host */
2810 static int cna_read(user_data_t *ud);
2812 static int cna_register_host(host_config_t *host) /* {{{ */
2817 ssnprintf(cb_name, sizeof(cb_name), "netapp-%s-%s", host->name,
2820 ssnprintf(cb_name, sizeof(cb_name), "netapp-%s", host->name);
2822 plugin_register_complex_read(
2823 /* group = */ NULL, cb_name,
2824 /* callback = */ cna_read,
2825 /* interval = */ host->interval,
2827 .data = host, .free_func = (void *)free_host_config,
2831 } /* }}} int cna_register_host */
2833 static int cna_config_host(host_config_t *host, /* {{{ */
2834 const oconfig_item_t *ci) {
2835 oconfig_item_t *item;
2836 _Bool is_vfiler = 0;
2839 if (!strcasecmp(ci->key, "VFiler"))
2842 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2843 WARNING("netapp plugin: \"%s\" needs exactly one string argument. Ignoring "
2849 status = cf_util_get_string(ci, &host->name);
2853 for (int i = 0; i < ci->children_num; ++i) {
2854 item = ci->children + i;
2858 if (!strcasecmp(item->key, "Address")) {
2859 status = cf_util_get_string(item, &host->host);
2860 } else if (!strcasecmp(item->key, "Port")) {
2863 tmp = cf_util_get_port_number(item);
2866 } else if (!strcasecmp(item->key, "Protocol")) {
2867 if ((item->values_num != 1) ||
2868 (item->values[0].type != OCONFIG_TYPE_STRING) ||
2869 (strcasecmp(item->values[0].value.string, "http") &&
2870 strcasecmp(item->values[0].value.string, "https"))) {
2871 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or "
2872 "\"https\". Ignoring host block \"%s\".",
2873 ci->values[0].value.string);
2876 if (!strcasecmp(item->values[0].value.string, "http"))
2877 host->protocol = NA_SERVER_TRANSPORT_HTTP;
2879 host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2880 } else if (!strcasecmp(item->key, "User")) {
2881 status = cf_util_get_string(item, &host->username);
2882 } else if (!strcasecmp(item->key, "Password")) {
2883 status = cf_util_get_string(item, &host->password);
2884 } else if (!strcasecmp(item->key, "Interval")) {
2885 status = cf_util_get_cdtime(item, &host->interval);
2886 } else if (!strcasecmp(item->key, "WAFL")) {
2887 cna_config_wafl(host, item);
2888 } else if (!strcasecmp(item->key, "Disks")) {
2889 cna_config_disk(host, item);
2890 } else if (!strcasecmp(item->key, "VolumePerf")) {
2891 cna_config_volume_performance(host, item);
2892 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2893 cna_config_volume_usage(host, item);
2894 } else if (!strcasecmp(item->key, "Quota")) {
2895 cna_config_quota(host, item);
2896 } else if (!strcasecmp(item->key, "SnapVault")) {
2897 cna_config_snapvault(host, item);
2898 } else if (!strcasecmp(item->key, "System")) {
2899 cna_config_system(host, item);
2900 } else if ((!strcasecmp(item->key, "VFiler")) && (!is_vfiler)) {
2901 host_config_t *vfiler;
2903 vfiler = cna_shallow_clone_host(host);
2905 ERROR("netapp plugin: Failed to allocate host object for vfiler.");
2909 if (cna_config_host(vfiler, item)) {
2910 free_host_config(vfiler);
2914 cna_register_host(vfiler);
2915 } else if ((!strcasecmp(item->key, "VFilerName")) && is_vfiler) {
2916 status = cf_util_get_string(item, &host->vfiler);
2918 WARNING("netapp plugin: Ignoring unknown config option \"%s\" in %s "
2920 item->key, is_vfiler ? "vfiler" : "host",
2921 ci->values[0].value.string);
2928 if (host->host == NULL)
2929 host->host = strdup(host->name);
2931 if (is_vfiler && (!host->vfiler))
2932 host->vfiler = strdup(host->name);
2934 if (host->host == NULL)
2937 if (host->port <= 0)
2938 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
2940 if ((host->username == NULL) || (host->password == NULL)) {
2941 WARNING("netapp plugin: Please supply login information for host \"%s\". "
2942 "Ignoring host block.",
2951 } /* }}} host_config_t *cna_config_host */
2954 * Callbacks registered with the daemon
2956 * Pretty standard stuff here.
2958 static int cna_init_host(host_config_t *host) /* {{{ */
2960 /* Request version 1.1 of the ONTAP API */
2961 int major_version = 1, minor_version = 1;
2966 if (host->srv != NULL)
2969 if (host->vfiler != NULL) /* Request version 1.7 of the ONTAP API */
2972 host->srv = na_server_open(host->host, major_version, minor_version);
2973 if (host->srv == NULL) {
2974 ERROR("netapp plugin: na_server_open (%s) failed.", host->host);
2978 na_server_set_transport_type(host->srv, host->protocol,
2979 /* transportarg = */ NULL);
2980 na_server_set_port(host->srv, host->port);
2981 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
2982 na_server_adminuser(host->srv, host->username, host->password);
2983 na_server_set_timeout(host->srv, 5 /* seconds */);
2985 if (host->vfiler != NULL) {
2986 if (!na_server_set_vfiler(host->srv, host->vfiler)) {
2987 ERROR("netapp plugin: Failed to connect to VFiler '%s' on host '%s'.",
2988 host->vfiler, host->host);
2991 INFO("netapp plugin: Connected to VFiler '%s' on host '%s'.",
2992 host->vfiler, host->host);
2997 } /* }}} int cna_init_host */
2999 static int cna_init(void) /* {{{ */
3001 char err[256] = {0};
3003 if (!na_startup(err, sizeof(err))) {
3004 err[sizeof(err) - 1] = 0;
3005 ERROR("netapp plugin: Error initializing netapp API: %s", err);
3010 } /* }}} cna_init */
3012 static int cna_read_internal(host_config_t *host) { /* {{{ */
3015 status = cna_query_wafl(host);
3019 status = cna_query_disk(host);
3023 status = cna_query_volume_perf(host);
3027 status = cna_query_volume_usage(host);
3031 status = cna_query_quota(host);
3035 status = cna_query_snapvault(host);
3039 status = cna_query_system(host);
3044 } /* }}} int cna_read_internal */
3046 static int cna_read(user_data_t *ud) { /* {{{ */
3047 host_config_t *host;
3050 if ((ud == NULL) || (ud->data == NULL))
3055 status = cna_init_host(host);
3059 status = cna_read_internal(host);
3061 if (host->srv != NULL)
3062 na_server_close(host->srv);
3067 } /* }}} int cna_read */
3069 static int cna_config(oconfig_item_t *ci) { /* {{{ */
3070 oconfig_item_t *item;
3072 for (int i = 0; i < ci->children_num; ++i) {
3073 item = ci->children + i;
3075 if (strcasecmp(item->key, "Host") == 0) {
3076 host_config_t *host;
3078 host = cna_alloc_host();
3080 ERROR("netapp plugin: Failed to allocate host object.");
3084 if (cna_config_host(host, item) != 0) {
3085 free_host_config(host);
3089 cna_register_host(host);
3090 } else /* if (item->key != "Host") */
3092 WARNING("netapp plugin: Ignoring unknown config option \"%s\".",
3097 } /* }}} int cna_config */
3099 static int cna_shutdown(void) /* {{{ */
3101 /* Clean up system resources and stuff. */
3105 } /* }}} int cna_shutdown */
3107 void module_register(void) {
3108 plugin_register_complex_config("netapp", cna_config);
3109 plugin_register_init("netapp", cna_init);
3110 plugin_register_shutdown("netapp", cna_shutdown);