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, void *data);
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 performance)
53 * The cache counters use old counter values to calculate a hit ratio for each
54 * counter. The "cfg_wafl_t" struct therefore contains old counter values along
55 * with flags, which are set if the counter is valid.
57 * The function "cna_handle_wafl_data" will fill a new structure of this kind
58 * with new values, then pass both, new and old data, to "submit_wafl_data".
59 * That function calculates the hit ratios, submits the calculated values and
60 * updates the old counter values for the next iteration.
62 #define CFG_WAFL_NAME_CACHE 0x0001
63 #define CFG_WAFL_DIR_CACHE 0x0002
64 #define CFG_WAFL_BUF_CACHE 0x0004
65 #define CFG_WAFL_INODE_CACHE 0x0008
66 #define CFG_WAFL_ALL 0x000F
67 #define HAVE_WAFL_NAME_CACHE_HIT 0x0100
68 #define HAVE_WAFL_NAME_CACHE_MISS 0x0200
69 #define HAVE_WAFL_NAME_CACHE (HAVE_WAFL_NAME_CACHE_HIT | HAVE_WAFL_NAME_CACHE_MISS)
70 #define HAVE_WAFL_FIND_DIR_HIT 0x0400
71 #define HAVE_WAFL_FIND_DIR_MISS 0x0800
72 #define HAVE_WAFL_FIND_DIR (HAVE_WAFL_FIND_DIR_HIT | HAVE_WAFL_FIND_DIR_MISS)
73 #define HAVE_WAFL_BUF_HASH_HIT 0x1000
74 #define HAVE_WAFL_BUF_HASH_MISS 0x2000
75 #define HAVE_WAFL_BUF_HASH (HAVE_WAFL_BUF_HASH_HIT | HAVE_WAFL_BUF_HASH_MISS)
76 #define HAVE_WAFL_INODE_CACHE_HIT 0x4000
77 #define HAVE_WAFL_INODE_CACHE_MISS 0x8000
78 #define HAVE_WAFL_INODE_CACHE (HAVE_WAFL_INODE_CACHE_HIT | HAVE_WAFL_INODE_CACHE_MISS)
79 #define HAVE_WAFL_ALL 0xff00
82 cna_interval_t interval;
86 uint64_t name_cache_hit;
87 uint64_t name_cache_miss;
88 uint64_t find_dir_hit;
89 uint64_t find_dir_miss;
90 uint64_t buf_hash_hit;
91 uint64_t buf_hash_miss;
92 uint64_t inode_cache_hit;
93 uint64_t inode_cache_miss;
97 /*! Data types for disk statistics {{{
99 * \brief A disk in the NetApp.
101 * A disk doesn't have any more information than its name at the moment.
102 * The name includes the "disk_" prefix.
104 #define HAVE_DISK_BUSY 0x10
105 #define HAVE_DISK_BASE 0x20
106 #define HAVE_DISK_ALL 0x30
107 typedef struct disk_s {
112 uint64_t base_for_disk_busy;
113 double disk_busy_percent;
117 #define CFG_DISK_BUSIEST 0x01
118 #define CFG_DISK_ALL 0x01
121 cna_interval_t interval;
127 /*! Data types for volume performance statistics {{{
129 * \brief Persistent data for volume performance data.
131 * The code below uses the difference of the operations and latency counters to
132 * calculate an average per-operation latency. For this, old counters need to
133 * be stored in the "data_volume_perf_t" structure. The byte-counters are just
134 * kept for completeness sake. The "flags" member indicates if each counter is
137 * The "cna_handle_volume_perf_data" function will fill a new struct of this
138 * type and pass both, old and new data, to "submit_volume_perf_data". In that
139 * function, the per-operation latency is calculated and dispatched, then the
140 * old counters are updated.
142 #define CFG_VOLUME_PERF_INIT 0x0001
143 #define CFG_VOLUME_PERF_IO 0x0002
144 #define CFG_VOLUME_PERF_OPS 0x0003
145 #define CFG_VOLUME_PERF_LATENCY 0x0008
146 #define CFG_VOLUME_PERF_ALL 0x000F
147 #define HAVE_VOLUME_PERF_BYTES_READ 0x0010
148 #define HAVE_VOLUME_PERF_BYTES_WRITE 0x0020
149 #define HAVE_VOLUME_PERF_OPS_READ 0x0040
150 #define HAVE_VOLUME_PERF_OPS_WRITE 0x0080
151 #define HAVE_VOLUME_PERF_LATENCY_READ 0x0100
152 #define HAVE_VOLUME_PERF_LATENCY_WRITE 0x0200
153 #define HAVE_VOLUME_PERF_ALL 0x03F0
154 struct data_volume_perf_s;
155 typedef struct data_volume_perf_s data_volume_perf_t;
156 struct data_volume_perf_s {
162 uint64_t write_bytes;
165 uint64_t read_latency;
166 uint64_t write_latency;
168 data_volume_perf_t *next;
172 cna_interval_t interval;
175 ignorelist_t *il_octets;
176 ignorelist_t *il_operations;
177 ignorelist_t *il_latency;
179 data_volume_perf_t *volumes;
181 /* }}} data_volume_perf_t */
183 /*! Data types for volume usage statistics {{{
185 * \brief Configuration struct for volume usage data (free / used).
187 #define CFG_VOLUME_USAGE_DF 0x0002
188 #define CFG_VOLUME_USAGE_SNAP 0x0004
189 #define CFG_VOLUME_USAGE_ALL 0x0006
190 #define HAVE_VOLUME_USAGE_NORM_FREE 0x0010
191 #define HAVE_VOLUME_USAGE_NORM_USED 0x0020
192 #define HAVE_VOLUME_USAGE_SNAP_RSVD 0x0040
193 #define HAVE_VOLUME_USAGE_SNAP_USED 0x0080
194 #define HAVE_VOLUME_USAGE_SIS_SAVED 0x0100
195 #define HAVE_VOLUME_USAGE_COMPRESS_SAVED 0x0200
196 #define HAVE_VOLUME_USAGE_DEDUP_SAVED 0x0400
197 #define HAVE_VOLUME_USAGE_ALL 0x07f0
198 #define IS_VOLUME_USAGE_OFFLINE 0x0800
199 struct data_volume_usage_s;
200 typedef struct data_volume_usage_s data_volume_usage_t;
201 struct data_volume_usage_s {
205 na_elem_t *snap_query;
209 uint64_t snap_reserved;
212 uint64_t compress_saved;
213 uint64_t dedup_saved;
215 data_volume_usage_t *next;
219 cna_interval_t interval;
222 ignorelist_t *il_capacity;
223 ignorelist_t *il_snapshot;
225 data_volume_usage_t *volumes;
226 } cfg_volume_usage_t;
227 /* }}} cfg_volume_usage_t */
229 /*! Data types for quota statistics {{{
231 * \brief Persistent data for quota statistics
234 cna_interval_t interval;
237 /* }}} cfg_quota_t */
239 /*! Data types for SnapVault statistics {{{
241 * \brief Persistent data for SnapVault(R) statistics
244 cna_interval_t interval;
247 /* }}} cfg_snapvault_t */
249 /*! Data types for system statistics {{{
251 * \brief Persistent data for system performance counters
253 #define CFG_SYSTEM_CPU 0x01
254 #define CFG_SYSTEM_NET 0x02
255 #define CFG_SYSTEM_OPS 0x04
256 #define CFG_SYSTEM_DISK 0x08
257 #define CFG_SYSTEM_ALL 0x0F
260 cna_interval_t interval;
263 /* }}} cfg_system_t */
265 struct host_config_s {
267 na_server_transport_t protocol;
276 cfg_wafl_t *cfg_wafl;
277 cfg_disk_t *cfg_disk;
278 cfg_volume_perf_t *cfg_volume_perf;
279 cfg_volume_usage_t *cfg_volume_usage;
280 cfg_quota_t *cfg_quota;
281 cfg_snapvault_t *cfg_snapvault;
282 cfg_system_t *cfg_system;
284 struct host_config_s *next;
290 * Used to free the various structures above.
292 static void free_disk (disk_t *disk) /* {{{ */
305 } /* }}} void free_disk */
307 static void free_cfg_wafl (cfg_wafl_t *cw) /* {{{ */
312 if (cw->query != NULL)
313 na_elem_free (cw->query);
316 } /* }}} void free_cfg_wafl */
318 static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
320 if (cfg_disk == NULL)
323 if (cfg_disk->query != NULL)
324 na_elem_free (cfg_disk->query);
326 free_disk (cfg_disk->disks);
328 } /* }}} void free_cfg_disk */
330 static void free_cfg_volume_perf (cfg_volume_perf_t *cvp) /* {{{ */
332 data_volume_perf_t *data;
337 /* Free the ignorelists */
338 ignorelist_free (cvp->il_octets);
339 ignorelist_free (cvp->il_operations);
340 ignorelist_free (cvp->il_latency);
342 /* Free the linked list of volumes */
346 data_volume_perf_t *next = data->next;
352 if (cvp->query != NULL)
353 na_elem_free (cvp->query);
356 } /* }}} void free_cfg_volume_perf */
358 static void free_cfg_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
360 data_volume_usage_t *data;
365 /* Free the ignorelists */
366 ignorelist_free (cvu->il_capacity);
367 ignorelist_free (cvu->il_snapshot);
369 /* Free the linked list of volumes */
373 data_volume_usage_t *next = data->next;
375 if (data->snap_query != NULL)
376 na_elem_free(data->snap_query);
381 if (cvu->query != NULL)
382 na_elem_free (cvu->query);
385 } /* }}} void free_cfg_volume_usage */
387 static void free_cfg_quota (cfg_quota_t *q) /* {{{ */
392 if (q->query != NULL)
393 na_elem_free (q->query);
396 } /* }}} void free_cfg_quota */
398 static void free_cfg_snapvault (cfg_snapvault_t *sv) /* {{{ */
403 if (sv->query != NULL)
404 na_elem_free (sv->query);
407 } /* }}} void free_cfg_snapvault */
409 static void free_cfg_system (cfg_system_t *cs) /* {{{ */
414 if (cs->query != NULL)
415 na_elem_free (cs->query);
418 } /* }}} void free_cfg_system */
420 static void free_host_config (host_config_t *hc) /* {{{ */
431 sfree (hc->username);
432 sfree (hc->password);
435 free_cfg_disk (hc->cfg_disk);
436 free_cfg_wafl (hc->cfg_wafl);
437 free_cfg_volume_perf (hc->cfg_volume_perf);
438 free_cfg_volume_usage (hc->cfg_volume_usage);
439 free_cfg_quota (hc->cfg_quota);
440 free_cfg_snapvault (hc->cfg_snapvault);
441 free_cfg_system (hc->cfg_system);
444 na_server_close (hc->srv);
448 free_host_config (next);
449 } /* }}} void free_host_config */
452 * Auxiliary functions
454 * Used to look up volumes and disks or to handle flags.
456 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
460 if ((cd == NULL) || (name == NULL))
463 for (d = cd->disks; d != NULL; d = d->next) {
464 if (strcmp(d->name, name) == 0)
468 d = calloc (1, sizeof (*d));
473 d->name = strdup(name);
474 if (d->name == NULL) {
483 } /* }}} disk_t *get_disk */
485 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))
500 if (strcmp (last->name, name) == 0)
503 if (last->next == NULL)
509 /* 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)
528 if (ignore_capacity == 0)
529 new->flags |= CFG_VOLUME_USAGE_DF;
530 if (ignore_snapshot == 0) {
531 new->flags |= CFG_VOLUME_USAGE_SNAP;
532 new->snap_query = na_elem_new ("snapshot-list-info");
533 na_child_add_string(new->snap_query, "target-type", "volume");
534 na_child_add_string(new->snap_query, "target-name", name);
536 new->snap_query = NULL;
539 /* Add to end of list. */
546 } /* }}} data_volume_usage_t *get_volume_usage */
548 static data_volume_perf_t *get_volume_perf (cfg_volume_perf_t *cvp, /* {{{ */
551 data_volume_perf_t *last;
552 data_volume_perf_t *new;
554 int ignore_octets = 0;
555 int ignore_operations = 0;
556 int ignore_latency = 0;
558 if ((cvp == NULL) || (name == NULL))
564 if (strcmp (last->name, name) == 0)
567 if (last->next == NULL)
573 /* Check the ignorelists. If *all three* tell us to ignore a volume, return
575 ignore_octets = ignorelist_match (cvp->il_octets, name);
576 ignore_operations = ignorelist_match (cvp->il_operations, name);
577 ignore_latency = ignorelist_match (cvp->il_latency, name);
578 if ((ignore_octets != 0) || (ignore_operations != 0)
579 || (ignore_latency != 0))
582 /* Not found: allocate. */
583 new = calloc (1, sizeof (*new));
588 new->name = strdup (name);
589 if (new->name == NULL)
595 if (ignore_octets == 0)
596 new->flags |= CFG_VOLUME_PERF_IO;
597 if (ignore_operations == 0)
598 new->flags |= CFG_VOLUME_PERF_OPS;
599 if (ignore_latency == 0)
600 new->flags |= CFG_VOLUME_PERF_LATENCY;
602 /* Add to end of list. */
609 } /* }}} data_volume_perf_t *get_volume_perf */
612 * Various submit functions.
614 * They all eventually call "submit_values" which creates a value_list_t and
615 * dispatches it to the daemon.
617 static int submit_values (const char *host, /* {{{ */
618 const char *plugin_inst,
619 const char *type, const char *type_inst,
620 value_t *values, size_t values_len,
621 cdtime_t timestamp, cdtime_t interval)
623 value_list_t vl = VALUE_LIST_INIT;
626 vl.values_len = values_len;
632 vl.interval = interval;
635 sstrncpy (vl.host, host, sizeof (vl.host));
637 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
638 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
639 if (plugin_inst != NULL)
640 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
641 sstrncpy (vl.type, type, sizeof (vl.type));
642 if (type_inst != NULL)
643 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
645 return (plugin_dispatch_values (&vl));
646 } /* }}} int submit_uint64 */
648 static int submit_two_derive (const char *host, const char *plugin_inst, /* {{{ */
649 const char *type, const char *type_inst, derive_t val0, derive_t val1,
650 cdtime_t timestamp, cdtime_t interval)
657 return (submit_values (host, plugin_inst, type, type_inst,
658 values, STATIC_ARRAY_SIZE (values), timestamp, interval));
659 } /* }}} int submit_two_derive */
661 static int submit_derive (const char *host, const char *plugin_inst, /* {{{ */
662 const char *type, const char *type_inst, derive_t counter,
663 cdtime_t timestamp, cdtime_t interval)
665 return (submit_values (host, plugin_inst, type, type_inst,
666 &(value_t) { .derive = counter }, 1, timestamp, interval));
667 } /* }}} int submit_derive */
669 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
670 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
671 cdtime_t timestamp, cdtime_t interval)
678 return (submit_values (host, plugin_inst, type, type_inst,
679 values, STATIC_ARRAY_SIZE (values), timestamp, interval));
680 } /* }}} int submit_two_gauge */
682 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
683 const char *type, const char *type_inst, double d,
684 cdtime_t timestamp, cdtime_t interval)
686 return (submit_values (host, plugin_inst, type, type_inst,
687 &(value_t) { .gauge = counter }, 1, timestamp, interval));
688 } /* }}} int submit_uint64 */
690 /* Calculate hit ratio from old and new counters and submit the resulting
691 * percentage. Used by "submit_wafl_data". */
692 static int submit_cache_ratio (const char *host, /* {{{ */
693 const char *plugin_inst,
694 const char *type_inst,
702 value_t v = { .gauge = NAN };
704 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
708 hits = new_hits - old_hits;
709 misses = new_misses - old_misses;
711 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
714 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
715 &v, 1, timestamp, interval));
716 } /* }}} int submit_cache_ratio */
718 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
719 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
720 cfg_wafl_t *old_data, const cfg_wafl_t *new_data, cdtime_t interval)
722 /* Submit requested counters */
723 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
724 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
725 submit_cache_ratio (hostname, instance, "name_cache_hit",
726 new_data->name_cache_hit, new_data->name_cache_miss,
727 old_data->name_cache_hit, old_data->name_cache_miss,
728 new_data->timestamp, interval);
730 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
731 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
732 submit_cache_ratio (hostname, instance, "find_dir_hit",
733 new_data->find_dir_hit, new_data->find_dir_miss,
734 old_data->find_dir_hit, old_data->find_dir_miss,
735 new_data->timestamp, interval);
737 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
738 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
739 submit_cache_ratio (hostname, instance, "buf_hash_hit",
740 new_data->buf_hash_hit, new_data->buf_hash_miss,
741 old_data->buf_hash_hit, old_data->buf_hash_miss,
742 new_data->timestamp, interval);
744 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
745 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
746 submit_cache_ratio (hostname, instance, "inode_cache_hit",
747 new_data->inode_cache_hit, new_data->inode_cache_miss,
748 old_data->inode_cache_hit, old_data->inode_cache_miss,
749 new_data->timestamp, interval);
751 /* Clear old HAVE_* flags */
752 old_data->flags &= ~HAVE_WAFL_ALL;
754 /* Copy all counters */
755 old_data->timestamp = new_data->timestamp;
756 old_data->name_cache_hit = new_data->name_cache_hit;
757 old_data->name_cache_miss = new_data->name_cache_miss;
758 old_data->find_dir_hit = new_data->find_dir_hit;
759 old_data->find_dir_miss = new_data->find_dir_miss;
760 old_data->buf_hash_hit = new_data->buf_hash_hit;
761 old_data->buf_hash_miss = new_data->buf_hash_miss;
762 old_data->inode_cache_hit = new_data->inode_cache_hit;
763 old_data->inode_cache_miss = new_data->inode_cache_miss;
765 /* Copy HAVE_* flags */
766 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
769 } /* }}} int submit_wafl_data */
771 /* Submits volume performance data to the daemon, taking care to honor and
772 * update flags appropriately. */
773 static int submit_volume_perf_data (const char *hostname, /* {{{ */
774 data_volume_perf_t *old_data,
775 const data_volume_perf_t *new_data, int interval)
777 char plugin_instance[DATA_MAX_NAME_LEN];
779 if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL))
782 ssnprintf (plugin_instance, sizeof (plugin_instance),
783 "volume-%s", old_data->name);
785 /* Check for and submit disk-octet values */
786 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_IO)
787 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
789 submit_two_derive (hostname, plugin_instance, "disk_octets", /* type instance = */ NULL,
790 (derive_t) new_data->read_bytes, (derive_t) new_data->write_bytes, new_data->timestamp, interval);
793 /* Check for and submit disk-operations values */
794 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_OPS)
795 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
797 submit_two_derive (hostname, plugin_instance, "disk_ops", /* type instance = */ NULL,
798 (derive_t) new_data->read_ops, (derive_t) new_data->write_ops, new_data->timestamp, interval);
801 /* Check for, calculate and submit disk-latency values */
802 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_LATENCY
803 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
804 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
805 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
806 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
808 gauge_t latency_per_op_read;
809 gauge_t latency_per_op_write;
811 latency_per_op_read = NAN;
812 latency_per_op_write = NAN;
814 /* Check if a counter wrapped around. */
815 if ((new_data->read_ops > old_data->read_ops)
816 && (new_data->read_latency > old_data->read_latency))
818 uint64_t diff_ops_read;
819 uint64_t diff_latency_read;
821 diff_ops_read = new_data->read_ops - old_data->read_ops;
822 diff_latency_read = new_data->read_latency - old_data->read_latency;
824 if (diff_ops_read > 0)
825 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
828 if ((new_data->write_ops > old_data->write_ops)
829 && (new_data->write_latency > old_data->write_latency))
831 uint64_t diff_ops_write;
832 uint64_t diff_latency_write;
834 diff_ops_write = new_data->write_ops - old_data->write_ops;
835 diff_latency_write = new_data->write_latency - old_data->write_latency;
837 if (diff_ops_write > 0)
838 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
841 submit_two_gauge (hostname, plugin_instance, "disk_latency", /* type instance = */ NULL,
842 latency_per_op_read, latency_per_op_write, new_data->timestamp, interval);
845 /* Clear all HAVE_* flags. */
846 old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
848 /* Copy all counters */
849 old_data->timestamp = new_data->timestamp;
850 old_data->read_bytes = new_data->read_bytes;
851 old_data->write_bytes = new_data->write_bytes;
852 old_data->read_ops = new_data->read_ops;
853 old_data->write_ops = new_data->write_ops;
854 old_data->read_latency = new_data->read_latency;
855 old_data->write_latency = new_data->write_latency;
857 /* Copy the HAVE_* flags */
858 old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
861 } /* }}} int submit_volume_perf_data */
863 static cdtime_t cna_child_get_cdtime (na_elem_t *data) /* {{{ */
867 t = (time_t) na_child_get_uint64 (data, "timestamp", /* default = */ 0);
869 return (TIME_T_TO_CDTIME_T (t));
870 } /* }}} cdtime_t cna_child_get_cdtime */
876 * These functions are called with appropriate data returned by the libnetapp
877 * interface which is parsed and submitted with the above functions.
879 /* Data corresponding to <WAFL /> */
880 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
881 na_elem_t *data, cdtime_t interval)
883 cfg_wafl_t perf_data = { 0 };
884 const char *plugin_inst;
886 na_elem_t *instances;
887 na_elem_iter_t counter_iter;
889 perf_data.timestamp = cna_child_get_cdtime (data);
891 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
892 if (instances == NULL)
894 ERROR ("netapp plugin: cna_handle_wafl_data: "
895 "na_elem_child (\"instances\") failed "
896 "for host %s.", hostname);
900 plugin_inst = na_child_get_string(instances, "name");
901 if (plugin_inst == NULL)
903 ERROR ("netapp plugin: cna_handle_wafl_data: "
904 "na_child_get_string (\"name\") failed "
905 "for host %s.", hostname);
909 /* Iterate over all counters */
910 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
911 for (na_elem_t *counter = na_iterator_next (&counter_iter);
913 counter = na_iterator_next (&counter_iter))
918 name = na_child_get_string(counter, "name");
922 value = na_child_get_uint64(counter, "value", UINT64_MAX);
923 if (value == UINT64_MAX)
926 if (!strcmp(name, "name_cache_hit")) {
927 perf_data.name_cache_hit = value;
928 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
929 } else if (!strcmp(name, "name_cache_miss")) {
930 perf_data.name_cache_miss = value;
931 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
932 } else if (!strcmp(name, "find_dir_hit")) {
933 perf_data.find_dir_hit = value;
934 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
935 } else if (!strcmp(name, "find_dir_miss")) {
936 perf_data.find_dir_miss = value;
937 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
938 } else if (!strcmp(name, "buf_hash_hit")) {
939 perf_data.buf_hash_hit = value;
940 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
941 } else if (!strcmp(name, "buf_hash_miss")) {
942 perf_data.buf_hash_miss = value;
943 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
944 } else if (!strcmp(name, "inode_cache_hit")) {
945 perf_data.inode_cache_hit = value;
946 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
947 } else if (!strcmp(name, "inode_cache_miss")) {
948 perf_data.inode_cache_miss = value;
949 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
951 DEBUG("netapp plugin: cna_handle_wafl_data: "
952 "Found unexpected child: %s "
953 "for host %s.", name, hostname);
957 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data, interval));
958 } /* }}} void cna_handle_wafl_data */
960 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
967 if (cw->query != NULL)
970 cw->query = na_elem_new("perf-object-get-instances");
971 if (cw->query == NULL)
973 ERROR ("netapp plugin: na_elem_new failed.");
976 na_child_add_string (cw->query, "objectname", "wafl");
978 e = na_elem_new("counters");
981 na_elem_free (cw->query);
983 ERROR ("netapp plugin: na_elem_new failed.");
986 na_child_add_string(e, "counter", "name_cache_hit");
987 na_child_add_string(e, "counter", "name_cache_miss");
988 na_child_add_string(e, "counter", "find_dir_hit");
989 na_child_add_string(e, "counter", "find_dir_miss");
990 na_child_add_string(e, "counter", "buf_hash_hit");
991 na_child_add_string(e, "counter", "buf_hash_miss");
992 na_child_add_string(e, "counter", "inode_cache_hit");
993 na_child_add_string(e, "counter", "inode_cache_miss");
995 na_child_add(cw->query, e);
998 } /* }}} int cna_setup_wafl */
1000 static int cna_query_wafl (host_config_t *host) /* {{{ */
1009 /* If WAFL was not configured, return without doing anything. */
1010 if (host->cfg_wafl == NULL)
1014 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
1017 status = cna_setup_wafl (host->cfg_wafl);
1020 assert (host->cfg_wafl->query != NULL);
1022 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
1023 if (na_results_status (data) != NA_OK)
1025 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed for host %s: %s",
1026 host->name, na_results_reason (data));
1027 na_elem_free (data);
1031 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data,
1032 host->cfg_wafl->interval.interval);
1035 host->cfg_wafl->interval.last_read = now;
1037 na_elem_free (data);
1039 } /* }}} int cna_query_wafl */
1041 /* Data corresponding to <Disks /> */
1042 static int cna_handle_disk_data (const char *hostname, /* {{{ */
1043 cfg_disk_t *cfg_disk, na_elem_t *data, cdtime_t interval)
1046 na_elem_t *instances;
1047 na_elem_iter_t instance_iter;
1048 disk_t *worst_disk = NULL;
1050 if ((cfg_disk == NULL) || (data == NULL))
1053 timestamp = cna_child_get_cdtime (data);
1055 instances = na_elem_child (data, "instances");
1056 if (instances == NULL)
1058 ERROR ("netapp plugin: cna_handle_disk_data: "
1059 "na_elem_child (\"instances\") failed "
1060 "for host %s.", hostname);
1064 /* Iterate over all children */
1065 instance_iter = na_child_iterator (instances);
1066 for (na_elem_t *instance = na_iterator_next (&instance_iter);
1068 instance = na_iterator_next(&instance_iter))
1071 disk_t new_data = { 0 };
1073 na_elem_iter_t counter_iterator;
1075 new_data.timestamp = timestamp;
1076 new_data.disk_busy_percent = NAN;
1078 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
1079 if (old_data == NULL)
1082 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
1083 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
1084 for (na_elem_t *counter = na_iterator_next(&counter_iterator);
1086 counter = na_iterator_next(&counter_iterator))
1091 name = na_child_get_string(counter, "name");
1095 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1096 if (value == UINT64_MAX)
1099 if (strcmp(name, "disk_busy") == 0)
1101 new_data.disk_busy = value;
1102 new_data.flags |= HAVE_DISK_BUSY;
1104 else if (strcmp(name, "base_for_disk_busy") == 0)
1106 new_data.base_for_disk_busy = value;
1107 new_data.flags |= HAVE_DISK_BASE;
1111 DEBUG ("netapp plugin: cna_handle_disk_data: "
1112 "Counter not handled: %s = %"PRIu64,
1117 /* If all required counters are available and did not just wrap around,
1118 * calculate the busy percentage. Otherwise, the value is initialized to
1119 * NAN at the top of the for-loop. */
1120 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1121 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1122 && (new_data.disk_busy >= old_data->disk_busy)
1123 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
1128 busy_diff = new_data.disk_busy - old_data->disk_busy;
1129 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
1131 new_data.disk_busy_percent = 100.0
1132 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
1135 /* Clear HAVE_* flags */
1136 old_data->flags &= ~HAVE_DISK_ALL;
1139 old_data->timestamp = new_data.timestamp;
1140 old_data->disk_busy = new_data.disk_busy;
1141 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
1142 old_data->disk_busy_percent = new_data.disk_busy_percent;
1145 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
1147 if ((worst_disk == NULL)
1148 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
1149 worst_disk = old_data;
1150 } /* for (all disks) */
1152 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
1153 submit_double (hostname, "system", "percent", "disk_busy",
1154 worst_disk->disk_busy_percent, timestamp, interval);
1157 } /* }}} int cna_handle_disk_data */
1159 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
1166 if (cd->query != NULL)
1169 cd->query = na_elem_new ("perf-object-get-instances");
1170 if (cd->query == NULL)
1172 ERROR ("netapp plugin: na_elem_new failed.");
1175 na_child_add_string (cd->query, "objectname", "disk");
1177 e = na_elem_new("counters");
1180 na_elem_free (cd->query);
1182 ERROR ("netapp plugin: na_elem_new failed.");
1185 na_child_add_string(e, "counter", "disk_busy");
1186 na_child_add_string(e, "counter", "base_for_disk_busy");
1187 na_child_add(cd->query, e);
1190 } /* }}} int cna_setup_disk */
1192 static int cna_query_disk (host_config_t *host) /* {{{ */
1201 /* If the user did not configure disk statistics, return without doing
1203 if (host->cfg_disk == NULL)
1207 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1210 status = cna_setup_disk (host->cfg_disk);
1213 assert (host->cfg_disk->query != NULL);
1215 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1216 if (na_results_status (data) != NA_OK)
1218 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed for host %s: %s",
1219 host->name, na_results_reason (data));
1220 na_elem_free (data);
1224 status = cna_handle_disk_data (host->name, host->cfg_disk, data,
1225 host->cfg_disk->interval.interval);
1228 host->cfg_disk->interval.last_read = now;
1230 na_elem_free (data);
1232 } /* }}} int cna_query_disk */
1234 /* Data corresponding to <VolumePerf /> */
1235 static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
1236 cfg_volume_perf_t *cvp, na_elem_t *data, cdtime_t interval)
1239 na_elem_t *elem_instances;
1240 na_elem_iter_t iter_instances;
1242 timestamp = cna_child_get_cdtime (data);
1244 elem_instances = na_elem_child(data, "instances");
1245 if (elem_instances == NULL)
1247 ERROR ("netapp plugin: handle_volume_perf_data: "
1248 "na_elem_child (\"instances\") failed "
1249 "for host %s.", hostname);
1253 iter_instances = na_child_iterator (elem_instances);
1254 for (na_elem_t *elem_instance = na_iterator_next(&iter_instances);
1255 elem_instance != NULL;
1256 elem_instance = na_iterator_next(&iter_instances))
1260 data_volume_perf_t perf_data = { 0 };
1261 data_volume_perf_t *v;
1263 na_elem_t *elem_counters;
1264 na_elem_iter_t iter_counters;
1266 perf_data.timestamp = timestamp;
1268 name = na_child_get_string (elem_instance, "name");
1272 /* get_volume_perf may return NULL if this volume is to be ignored. */
1273 v = get_volume_perf (cvp, name);
1277 elem_counters = na_elem_child (elem_instance, "counters");
1278 if (elem_counters == NULL)
1281 iter_counters = na_child_iterator (elem_counters);
1282 for (na_elem_t *elem_counter = na_iterator_next(&iter_counters);
1283 elem_counter != NULL;
1284 elem_counter = na_iterator_next(&iter_counters))
1289 name = na_child_get_string (elem_counter, "name");
1293 value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
1294 if (value == UINT64_MAX)
1297 if (!strcmp(name, "read_data")) {
1298 perf_data.read_bytes = value;
1299 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1300 } else if (!strcmp(name, "write_data")) {
1301 perf_data.write_bytes = value;
1302 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1303 } else if (!strcmp(name, "read_ops")) {
1304 perf_data.read_ops = value;
1305 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1306 } else if (!strcmp(name, "write_ops")) {
1307 perf_data.write_ops = value;
1308 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1309 } else if (!strcmp(name, "read_latency")) {
1310 perf_data.read_latency = value;
1311 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1312 } else if (!strcmp(name, "write_latency")) {
1313 perf_data.write_latency = value;
1314 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1316 } /* for (elem_counter) */
1318 submit_volume_perf_data (hostname, v, &perf_data, interval);
1319 } /* for (volume) */
1322 } /* }}} int cna_handle_volume_perf_data */
1324 static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
1331 if (cd->query != NULL)
1334 cd->query = na_elem_new ("perf-object-get-instances");
1335 if (cd->query == NULL)
1337 ERROR ("netapp plugin: na_elem_new failed.");
1340 na_child_add_string (cd->query, "objectname", "volume");
1342 e = na_elem_new("counters");
1345 na_elem_free (cd->query);
1347 ERROR ("netapp plugin: na_elem_new failed.");
1350 na_child_add_string(e, "counter", "read_ops");
1351 na_child_add_string(e, "counter", "write_ops");
1352 na_child_add_string(e, "counter", "read_data");
1353 na_child_add_string(e, "counter", "write_data");
1354 na_child_add_string(e, "counter", "read_latency");
1355 na_child_add_string(e, "counter", "write_latency");
1356 na_child_add(cd->query, e);
1359 } /* }}} int cna_setup_volume_perf */
1361 static int cna_query_volume_perf (host_config_t *host) /* {{{ */
1370 /* If the user did not configure volume performance statistics, return
1371 * without doing anything. */
1372 if (host->cfg_volume_perf == NULL)
1376 if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
1379 status = cna_setup_volume_perf (host->cfg_volume_perf);
1382 assert (host->cfg_volume_perf->query != NULL);
1384 data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
1385 if (na_results_status (data) != NA_OK)
1387 ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed for host %s: %s",
1388 host->name, na_results_reason (data));
1389 na_elem_free (data);
1393 status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data,
1394 host->cfg_volume_perf->interval.interval);
1397 host->cfg_volume_perf->interval.last_read = now;
1399 na_elem_free (data);
1401 } /* }}} int cna_query_volume_perf */
1403 /* Data corresponding to <VolumeUsage /> */
1404 static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
1405 cfg_volume_usage_t *cfg_volume, int interval)
1407 for (data_volume_usage_t *v = cfg_volume->volumes; v != NULL; v = v->next)
1409 char plugin_instance[DATA_MAX_NAME_LEN];
1411 uint64_t norm_used = v->norm_used;
1412 uint64_t norm_free = v->norm_free;
1413 uint64_t sis_saved = v->sis_saved;
1414 uint64_t compress_saved = v->compress_saved;
1415 uint64_t dedup_saved = v->dedup_saved;
1416 uint64_t snap_reserve_used = 0;
1417 uint64_t snap_reserve_free = v->snap_reserved;
1418 uint64_t snap_norm_used = v->snap_used;
1420 ssnprintf (plugin_instance, sizeof (plugin_instance),
1421 "volume-%s", v->name);
1423 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD)) {
1424 if (v->snap_reserved > v->snap_used) {
1425 snap_reserve_free = v->snap_reserved - v->snap_used;
1426 snap_reserve_used = v->snap_used;
1429 snap_reserve_free = 0;
1430 snap_reserve_used = v->snap_reserved;
1431 snap_norm_used = v->snap_used - v->snap_reserved;
1435 /* The space used by snapshots but not reserved for them is included in
1436 * both, norm_used and snap_norm_used. If possible, subtract this here. */
1437 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED))
1439 if (norm_used >= snap_norm_used)
1440 norm_used -= snap_norm_used;
1443 ERROR ("netapp plugin: (norm_used = %"PRIu64") < (snap_norm_used = "
1444 "%"PRIu64") for host %s. Invalidating both.",
1445 norm_used, snap_norm_used, hostname);
1446 v->flags &= ~(HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED);
1450 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1451 submit_double (hostname, /* plugin instance = */ plugin_instance,
1452 "df_complex", "free",
1453 (double) norm_free, /* timestamp = */ 0, interval);
1455 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1456 submit_double (hostname, /* plugin instance = */ plugin_instance,
1457 "df_complex", "sis_saved",
1458 (double) sis_saved, /* timestamp = */ 0, interval);
1460 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_COMPRESS_SAVED))
1461 submit_double (hostname, /* plugin instance = */ plugin_instance,
1462 "df_complex", "compression_saved",
1463 (double) compress_saved, /* timestamp = */ 0, interval);
1465 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_DEDUP_SAVED))
1466 submit_double (hostname, /* plugin instance = */ plugin_instance,
1467 "df_complex", "dedup_saved",
1468 (double) dedup_saved, /* timestamp = */ 0, interval);
1470 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1471 submit_double (hostname, /* plugin instance = */ plugin_instance,
1472 "df_complex", "used",
1473 (double) norm_used, /* timestamp = */ 0, interval);
1475 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1476 submit_double (hostname, /* plugin instance = */ plugin_instance,
1477 "df_complex", "snap_reserved",
1478 (double) snap_reserve_free, /* timestamp = */ 0, interval);
1480 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD))
1481 submit_double (hostname, /* plugin instance = */ plugin_instance,
1482 "df_complex", "snap_reserve_used",
1483 (double) snap_reserve_used, /* timestamp = */ 0, interval);
1485 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1486 submit_double (hostname, /* plugin instance = */ plugin_instance,
1487 "df_complex", "snap_normal_used",
1488 (double) snap_norm_used, /* timestamp = */ 0, interval);
1490 /* Clear all the HAVE_* flags */
1491 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1492 } /* for (v = cfg_volume->volumes) */
1495 } /* }}} int cna_submit_volume_usage_data */
1497 /* Switch the state of a volume between online and offline and send out a
1499 static int cna_change_volume_status (const char *hostname, /* {{{ */
1500 data_volume_usage_t *v)
1502 notification_t n = { 0 };
1505 sstrncpy (n.host, hostname, sizeof (n.host));
1506 sstrncpy (n.plugin, "netapp", sizeof (n.plugin));
1507 sstrncpy (n.plugin_instance, v->name, sizeof (n.plugin_instance));
1509 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0) {
1510 n.severity = NOTIF_OKAY;
1511 ssnprintf (n.message, sizeof (n.message),
1512 "Volume %s is now online.", v->name);
1513 v->flags &= ~IS_VOLUME_USAGE_OFFLINE;
1515 n.severity = NOTIF_WARNING;
1516 ssnprintf (n.message, sizeof (n.message),
1517 "Volume %s is now offline.", v->name);
1518 v->flags |= IS_VOLUME_USAGE_OFFLINE;
1521 return (plugin_dispatch_notification (&n));
1522 } /* }}} int cna_change_volume_status */
1524 static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
1525 data_volume_usage_t *v)
1527 uint64_t snap_used = 0, value;
1528 na_elem_t *data, *elem_snapshots;
1529 na_elem_iter_t iter_snap;
1531 data = na_server_invoke_elem(host->srv, v->snap_query);
1532 if (na_results_status(data) != NA_OK)
1534 if (na_results_errno(data) == EVOLUMEOFFLINE) {
1535 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) == 0)
1536 cna_change_volume_status (host->name, v);
1538 ERROR ("netapp plugin: cna_handle_volume_snap_usage: na_server_invoke_elem for "
1539 "volume \"%s\" on host %s failed with error %d: %s", v->name,
1540 host->name, na_results_errno(data), na_results_reason(data));
1546 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0)
1547 cna_change_volume_status (host->name, v);
1549 elem_snapshots = na_elem_child (data, "snapshots");
1550 if (elem_snapshots == NULL)
1552 ERROR ("netapp plugin: cna_handle_volume_snap_usage: "
1553 "na_elem_child (\"snapshots\") failed "
1554 "for host %s.", host->name);
1559 iter_snap = na_child_iterator (elem_snapshots);
1560 for (na_elem_t *elem_snap = na_iterator_next (&iter_snap);
1562 elem_snap = na_iterator_next (&iter_snap))
1564 value = na_child_get_uint64(elem_snap, "cumulative-total", 0);
1565 /* "cumulative-total" is the total size of the oldest snapshot plus all
1566 * newer ones in blocks (1KB). We therefore are looking for the highest
1567 * number of all snapshots - that's the size required for the snapshots. */
1568 if (value > snap_used)
1571 na_elem_free (data);
1572 /* snap_used is in 1024 byte blocks */
1573 v->snap_used = snap_used * 1024;
1574 v->flags |= HAVE_VOLUME_USAGE_SNAP_USED;
1575 } /* }}} void cna_handle_volume_snap_usage */
1577 static void cna_handle_volume_sis_data (const host_config_t *host, /* {{{ */
1578 data_volume_usage_t *v, na_elem_t *sis)
1580 const char *sis_state;
1581 uint64_t sis_saved_reported;
1583 if (na_elem_child(sis, "sis-info"))
1584 sis = na_elem_child(sis, "sis-info");
1586 sis_state = na_child_get_string(sis, "state");
1587 if (sis_state == NULL)
1590 /* If SIS is not enabled, there's nothing left to do for this volume. */
1591 if (strcmp ("enabled", sis_state) != 0)
1594 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1595 if (sis_saved_reported == UINT64_MAX)
1598 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1599 if ((sis_saved_reported >> 32) != 0) {
1600 /* In case they ever fix this bug. */
1601 v->sis_saved = sis_saved_reported;
1602 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1603 } else { /* really hacky work-around code. {{{ */
1604 uint64_t sis_saved_percent;
1605 uint64_t sis_saved_guess;
1606 uint64_t overflow_guess;
1607 uint64_t guess1, guess2, guess3;
1609 /* Check if we have v->norm_used. Without it, we cannot calculate
1610 * sis_saved_guess. */
1611 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1614 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1615 if (sis_saved_percent > 100)
1618 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1619 * will hopefully be fixed in later versions. To work around the bug, try
1620 * to figure out how often the 32bit integer wrapped around by using the
1621 * "percentage-saved" value. Because the percentage is in the range
1622 * [0-100], this should work as long as the saved space does not exceed
1624 /* percentage-saved = size-saved / (size-saved + size-used) */
1625 if (sis_saved_percent < 100)
1626 sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1628 sis_saved_guess = v->norm_used;
1630 overflow_guess = sis_saved_guess >> 32;
1631 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1632 guess2 = (overflow_guess << 32) + sis_saved_reported;
1633 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1635 if (sis_saved_guess < guess2) {
1636 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1637 v->sis_saved = guess1;
1639 v->sis_saved = guess2;
1641 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1642 v->sis_saved = guess2;
1644 v->sis_saved = guess3;
1646 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1647 } /* }}} end of 32-bit workaround */
1648 } /* }}} void cna_handle_volume_sis_data */
1650 /* ONTAP >= 8.1 uses SIS for managing dedup and compression */
1651 static void cna_handle_volume_sis_saved (const host_config_t *host, /* {{{ */
1652 data_volume_usage_t *v, na_elem_t *sis)
1656 if (na_elem_child(sis, "sis-info"))
1657 sis = na_elem_child(sis, "sis-info");
1659 saved = na_child_get_uint64(sis, "compress-saved", UINT64_MAX);
1660 if (saved != UINT64_MAX) {
1661 v->compress_saved = saved;
1662 v->flags |= HAVE_VOLUME_USAGE_COMPRESS_SAVED;
1665 saved = na_child_get_uint64(sis, "dedup-saved", UINT64_MAX);
1666 if (saved != UINT64_MAX) {
1667 v->dedup_saved = saved;
1668 v->flags |= HAVE_VOLUME_USAGE_DEDUP_SAVED;
1670 } /* }}} void cna_handle_volume_sis_saved */
1672 static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */
1673 cfg_volume_usage_t *cfg_volume, na_elem_t *data)
1675 na_elem_t *elem_volumes;
1676 na_elem_iter_t iter_volume;
1678 elem_volumes = na_elem_child (data, "volumes");
1679 if (elem_volumes == NULL)
1681 ERROR ("netapp plugin: cna_handle_volume_usage_data: "
1682 "na_elem_child (\"volumes\") failed "
1683 "for host %s.", host->name);
1687 iter_volume = na_child_iterator (elem_volumes);
1688 for (na_elem_t *elem_volume = na_iterator_next (&iter_volume);
1689 elem_volume != NULL;
1690 elem_volume = na_iterator_next (&iter_volume))
1692 const char *volume_name, *state;
1694 data_volume_usage_t *v;
1699 volume_name = na_child_get_string (elem_volume, "name");
1700 if (volume_name == NULL)
1703 state = na_child_get_string (elem_volume, "state");
1704 if ((state == NULL) || (strcmp(state, "online") != 0))
1707 /* get_volume_usage may return NULL if the volume is to be ignored. */
1708 v = get_volume_usage (cfg_volume, volume_name);
1712 if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
1713 cna_handle_volume_snap_usage(host, v);
1715 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1718 /* 2^4 exa-bytes? This will take a while ;) */
1719 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1720 if (value != UINT64_MAX) {
1721 v->norm_free = value;
1722 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1725 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1726 if (value != UINT64_MAX) {
1727 v->norm_used = value;
1728 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1731 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
1732 if (value != UINT64_MAX) {
1733 /* 1 block == 1024 bytes as per API docs */
1734 v->snap_reserved = 1024 * value;
1735 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1738 sis = na_elem_child(elem_volume, "sis");
1740 cna_handle_volume_sis_data (host, v, sis);
1741 cna_handle_volume_sis_saved (host, v, sis);
1743 } /* for (elem_volume) */
1745 return (cna_submit_volume_usage_data (host->name, cfg_volume,
1746 host->cfg_volume_usage->interval.interval));
1747 } /* }}} int cna_handle_volume_usage_data */
1749 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
1754 if (cvu->query != NULL)
1757 cvu->query = na_elem_new ("volume-list-info");
1758 if (cvu->query == NULL)
1760 ERROR ("netapp plugin: na_elem_new failed.");
1765 } /* }}} int cna_setup_volume_usage */
1767 static int cna_query_volume_usage (host_config_t *host) /* {{{ */
1776 /* If the user did not configure volume_usage statistics, return without
1777 * doing anything. */
1778 if (host->cfg_volume_usage == NULL)
1782 if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
1785 status = cna_setup_volume_usage (host->cfg_volume_usage);
1788 assert (host->cfg_volume_usage->query != NULL);
1790 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1791 if (na_results_status (data) != NA_OK)
1793 ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed for host %s: %s",
1794 host->name, na_results_reason (data));
1795 na_elem_free (data);
1799 status = cna_handle_volume_usage_data (host, host->cfg_volume_usage, data);
1802 host->cfg_volume_usage->interval.last_read = now;
1804 na_elem_free (data);
1806 } /* }}} int cna_query_volume_usage */
1808 /* Data corresponding to <Quota /> */
1809 static int cna_handle_quota_data (const host_config_t *host, /* {{{ */
1810 cfg_quota_t *cfg_quota, na_elem_t *data)
1812 na_elem_t *elem_quotas;
1813 na_elem_iter_t iter_quota;
1815 elem_quotas = na_elem_child (data, "quotas");
1816 if (elem_quotas == NULL)
1818 ERROR ("netapp plugin: cna_handle_quota_data: "
1819 "na_elem_child (\"quotas\") failed "
1820 "for host %s.", host->name);
1824 iter_quota = na_child_iterator (elem_quotas);
1825 for (na_elem_t *elem_quota = na_iterator_next (&iter_quota);
1827 elem_quota = na_iterator_next (&iter_quota))
1829 const char *quota_type, *volume_name, *tree_name;
1832 char plugin_instance[DATA_MAX_NAME_LEN];
1834 quota_type = na_child_get_string (elem_quota, "quota-type");
1835 if (quota_type == NULL)
1838 /* possible TODO: support other types as well */
1839 if (strcmp (quota_type, "tree") != 0)
1842 tree_name = na_child_get_string (elem_quota, "tree");
1843 if ((tree_name == NULL) || (*tree_name == '\0'))
1846 volume_name = na_child_get_string (elem_quota, "volume");
1847 if (volume_name == NULL)
1850 ssnprintf (plugin_instance, sizeof (plugin_instance),
1851 "quota-%s-%s", volume_name, tree_name);
1853 value = na_child_get_uint64 (elem_quota, "disk-used", UINT64_MAX);
1854 if (value != UINT64_MAX) {
1855 value *= 1024; /* disk-used reports kilobytes */
1856 submit_double (host->name, plugin_instance,
1857 /* type = */ "df_complex", /* type instance = */ NULL,
1858 (double)value, /* timestamp = */ 0,
1859 host->cfg_quota->interval.interval);
1862 value = na_child_get_uint64 (elem_quota, "files-used", UINT64_MAX);
1863 if (value != UINT64_MAX) {
1864 submit_double (host->name, plugin_instance,
1865 /* type = */ "files", /* type instance = */ NULL,
1866 (double)value, /* timestamp = */ 0,
1867 host->cfg_quota->interval.interval);
1869 } /* for (elem_quota) */
1872 } /* }}} int cna_handle_volume_usage_data */
1874 static int cna_setup_quota (cfg_quota_t *cq) /* {{{ */
1879 if (cq->query != NULL)
1882 cq->query = na_elem_new ("quota-report");
1883 if (cq->query == NULL)
1885 ERROR ("netapp plugin: na_elem_new failed.");
1890 } /* }}} int cna_setup_quota */
1892 static int cna_query_quota (host_config_t *host) /* {{{ */
1901 /* If the user did not configure quota statistics, return without
1902 * doing anything. */
1903 if (host->cfg_quota == NULL)
1907 if ((host->cfg_quota->interval.interval + host->cfg_quota->interval.last_read) > now)
1910 status = cna_setup_quota (host->cfg_quota);
1913 assert (host->cfg_quota->query != NULL);
1915 data = na_server_invoke_elem (host->srv, host->cfg_quota->query);
1916 if (na_results_status (data) != NA_OK)
1918 ERROR ("netapp plugin: cna_query_quota: na_server_invoke_elem failed for host %s: %s",
1919 host->name, na_results_reason (data));
1920 na_elem_free (data);
1924 status = cna_handle_quota_data (host, host->cfg_quota, data);
1927 host->cfg_quota->interval.last_read = now;
1929 na_elem_free (data);
1931 } /* }}} int cna_query_quota */
1933 /* Data corresponding to <SnapVault /> */
1934 static int cna_handle_snapvault_data (const char *hostname, /* {{{ */
1935 cfg_snapvault_t *cfg_snapvault, na_elem_t *data, cdtime_t interval)
1937 na_elem_iter_t status_iter;
1939 status = na_elem_child (data, "status-list");
1941 ERROR ("netapp plugin: SnapVault status record missing status-list");
1945 status_iter = na_child_iterator (status);
1946 for (na_elem_t *status = na_iterator_next (&status_iter);
1948 status = na_iterator_next (&status_iter))
1950 const char *dest_sys, *dest_path, *src_sys, *src_path;
1951 char plugin_instance[DATA_MAX_NAME_LEN];
1954 dest_sys = na_child_get_string (status, "destination-system");
1955 dest_path = na_child_get_string (status, "destination-path");
1956 src_sys = na_child_get_string (status, "source-system");
1957 src_path = na_child_get_string (status, "source-path");
1959 if ((! dest_sys) || (! dest_path) || (! src_sys) || (! src_path))
1962 value = na_child_get_uint64 (status, "lag-time", UINT64_MAX);
1963 if (value == UINT64_MAX) /* no successful baseline transfer yet */
1966 /* possible TODO: make plugin instance configurable */
1967 ssnprintf (plugin_instance, sizeof (plugin_instance),
1968 "snapvault-%s", dest_path);
1969 submit_double (hostname, plugin_instance, /* type = */ "delay", NULL,
1970 (double)value, /* timestamp = */ 0, interval);
1972 value = na_child_get_uint64 (status, "last-transfer-duration", UINT64_MAX);
1973 if (value != UINT64_MAX)
1974 submit_double (hostname, plugin_instance, /* type = */ "duration", "last_transfer",
1975 (double)value, /* timestamp = */ 0, interval);
1977 value = na_child_get_uint64 (status, "transfer-progress", UINT64_MAX);
1978 if (value == UINT64_MAX)
1979 value = na_child_get_uint64 (status, "last-transfer-size", UINT64_MAX);
1980 if (value != UINT64_MAX) {
1981 value *= 1024; /* this is kilobytes */
1982 submit_derive (hostname, plugin_instance, /* type = */ "if_rx_octets", "transferred",
1983 value, /* timestamp = */ 0, interval);
1985 } /* for (status) */
1988 } /* }}} int cna_handle_snapvault_data */
1990 static int cna_handle_snapvault_iter (host_config_t *host, /* {{{ */
1995 uint32_t records_count;
1997 records_count = na_child_get_uint32 (data, "records", UINT32_MAX);
1998 if (records_count == UINT32_MAX)
2001 tag = na_child_get_string (data, "tag");
2005 DEBUG ("netapp plugin: Iterating %u SV records (tag = %s)", records_count, tag);
2007 for (uint32_t i = 0; i < records_count; ++i) {
2010 elem = na_server_invoke (host->srv,
2011 "snapvault-secondary-relationship-status-list-iter-next",
2012 "maximum", "1", "tag", tag, NULL);
2014 if (na_results_status (elem) != NA_OK)
2016 ERROR ("netapp plugin: cna_handle_snapvault_iter: "
2017 "na_server_invoke failed for host %s: %s",
2018 host->name, na_results_reason (data));
2019 na_elem_free (elem);
2023 cna_handle_snapvault_data (host->name, host->cfg_snapvault, elem,
2024 host->cfg_snapvault->interval.interval);
2025 na_elem_free (elem);
2028 na_elem_free (na_server_invoke (host->srv,
2029 "snapvault-secondary-relationship-status-list-iter-end",
2032 } /* }}} int cna_handle_snapvault_iter */
2034 static int cna_setup_snapvault (cfg_snapvault_t *sv) /* {{{ */
2039 if (sv->query != NULL)
2042 sv->query = na_elem_new ("snapvault-secondary-relationship-status-list-iter-start");
2043 if (sv->query == NULL)
2045 ERROR ("netapp plugin: na_elem_new failed.");
2050 } /* }}} int cna_setup_snapvault */
2052 static int cna_query_snapvault (host_config_t *host) /* {{{ */
2061 if (host->cfg_snapvault == NULL)
2065 if ((host->cfg_snapvault->interval.interval + host->cfg_snapvault->interval.last_read) > now)
2068 status = cna_setup_snapvault (host->cfg_snapvault);
2071 assert (host->cfg_snapvault->query != NULL);
2073 data = na_server_invoke_elem (host->srv, host->cfg_snapvault->query);
2074 if (na_results_status (data) != NA_OK)
2076 ERROR ("netapp plugin: cna_query_snapvault: na_server_invoke_elem failed for host %s: %s",
2077 host->name, na_results_reason (data));
2078 na_elem_free (data);
2082 status = cna_handle_snapvault_iter (host, data);
2085 host->cfg_snapvault->interval.last_read = now;
2087 na_elem_free (data);
2089 } /* }}} int cna_query_snapvault */
2091 /* Data corresponding to <System /> */
2092 static int cna_handle_system_data (const char *hostname, /* {{{ */
2093 cfg_system_t *cfg_system, na_elem_t *data, int interval)
2095 na_elem_t *instances;
2096 na_elem_iter_t counter_iter;
2098 derive_t disk_read = 0, disk_written = 0;
2099 derive_t net_recv = 0, net_sent = 0;
2100 derive_t cpu_busy = 0, cpu_total = 0;
2101 uint32_t counter_flags = 0;
2103 const char *instance;
2106 timestamp = cna_child_get_cdtime (data);
2108 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
2109 if (instances == NULL)
2111 ERROR ("netapp plugin: cna_handle_system_data: "
2112 "na_elem_child (\"instances\") failed "
2113 "for host %s.", hostname);
2117 instance = na_child_get_string (instances, "name");
2118 if (instance == NULL)
2120 ERROR ("netapp plugin: cna_handle_system_data: "
2121 "na_child_get_string (\"name\") failed "
2122 "for host %s.", hostname);
2126 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
2127 for (na_elem_t *counter = na_iterator_next (&counter_iter);
2129 counter = na_iterator_next (&counter_iter))
2134 name = na_child_get_string(counter, "name");
2138 value = na_child_get_uint64(counter, "value", UINT64_MAX);
2139 if (value == UINT64_MAX)
2142 if (!strcmp(name, "disk_data_read")) {
2143 disk_read = (derive_t) (value * 1024);
2144 counter_flags |= 0x01;
2145 } else if (!strcmp(name, "disk_data_written")) {
2146 disk_written = (derive_t) (value * 1024);
2147 counter_flags |= 0x02;
2148 } else if (!strcmp(name, "net_data_recv")) {
2149 net_recv = (derive_t) (value * 1024);
2150 counter_flags |= 0x04;
2151 } else if (!strcmp(name, "net_data_sent")) {
2152 net_sent = (derive_t) (value * 1024);
2153 counter_flags |= 0x08;
2154 } else if (!strcmp(name, "cpu_busy")) {
2155 cpu_busy = (derive_t) value;
2156 counter_flags |= 0x10;
2157 } else if (!strcmp(name, "cpu_elapsed_time")) {
2158 cpu_total = (derive_t) value;
2159 counter_flags |= 0x20;
2160 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
2161 && (value > 0) && (strlen(name) > 4)
2162 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
2163 submit_derive (hostname, instance, "disk_ops_complex", name,
2164 (derive_t) value, timestamp, interval);
2166 } /* for (counter) */
2168 if ((cfg_system->flags & CFG_SYSTEM_DISK)
2169 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
2170 submit_two_derive (hostname, instance, "disk_octets", NULL,
2171 disk_read, disk_written, timestamp, interval);
2173 if ((cfg_system->flags & CFG_SYSTEM_NET)
2174 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
2175 submit_two_derive (hostname, instance, "if_octets", NULL,
2176 net_recv, net_sent, timestamp, interval);
2178 if ((cfg_system->flags & CFG_SYSTEM_CPU)
2179 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
2181 submit_derive (hostname, instance, "cpu", "system",
2182 cpu_busy, timestamp, interval);
2183 submit_derive (hostname, instance, "cpu", "idle",
2184 cpu_total - cpu_busy, timestamp, interval);
2188 } /* }}} int cna_handle_system_data */
2190 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
2195 if (cs->query != NULL)
2198 cs->query = na_elem_new ("perf-object-get-instances");
2199 if (cs->query == NULL)
2201 ERROR ("netapp plugin: na_elem_new failed.");
2204 na_child_add_string (cs->query, "objectname", "system");
2207 } /* }}} int cna_setup_system */
2209 static int cna_query_system (host_config_t *host) /* {{{ */
2218 /* If system statistics were not configured, return without doing anything. */
2219 if (host->cfg_system == NULL)
2223 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
2226 status = cna_setup_system (host->cfg_system);
2229 assert (host->cfg_system->query != NULL);
2231 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
2232 if (na_results_status (data) != NA_OK)
2234 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed for host %s: %s",
2235 host->name, na_results_reason (data));
2236 na_elem_free (data);
2240 status = cna_handle_system_data (host->name, host->cfg_system, data,
2241 host->cfg_system->interval.interval);
2244 host->cfg_system->interval.last_read = now;
2246 na_elem_free (data);
2248 } /* }}} int cna_query_system */
2251 * Configuration handling
2253 /* Sets a given flag if the boolean argument is true and unsets the flag if it
2254 * is false. On error, the flag-field is not changed. */
2255 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
2256 uint32_t *flags, uint32_t flag)
2258 if ((ci == NULL) || (flags == NULL))
2261 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2263 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
2268 if (ci->values[0].value.boolean)
2274 } /* }}} int cna_config_bool_to_flag */
2276 /* Handling of the "Interval" option which is allowed in every block. */
2277 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
2278 cna_interval_t *out_interval)
2283 status = cf_util_get_cdtime (ci, &tmp);
2287 out_interval->interval = tmp;
2288 out_interval->last_read = 0;
2291 } /* }}} int cna_config_get_interval */
2293 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
2294 * <VolumePerf /> block. */
2295 static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
2296 const oconfig_item_t *ci)
2301 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2303 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2308 name = ci->values[0].value.string;
2310 if (strcasecmp ("GetIO", ci->key) == 0)
2311 il = cvp->il_octets;
2312 else if (strcasecmp ("GetOps", ci->key) == 0)
2313 il = cvp->il_operations;
2314 else if (strcasecmp ("GetLatency", ci->key) == 0)
2315 il = cvp->il_latency;
2319 ignorelist_add (il, name);
2320 } /* }}} void cna_config_volume_perf_option */
2322 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
2323 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
2324 static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
2325 const oconfig_item_t *ci)
2329 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2331 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2336 if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
2337 il = cvp->il_octets;
2338 else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
2339 il = cvp->il_operations;
2340 else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
2341 il = cvp->il_latency;
2345 if (ci->values[0].value.boolean)
2346 ignorelist_set_invert (il, /* invert = */ 0);
2348 ignorelist_set_invert (il, /* invert = */ 1);
2349 } /* }}} void cna_config_volume_perf_default */
2351 /* Corresponds to a <Disks /> block */
2356 * IgnoreSelectedIO false
2360 * IgnoreSelectedOps false
2364 * IgnoreSelectedLatency false
2367 /* Corresponds to a <VolumePerf /> block */
2368 static int cna_config_volume_performance (host_config_t *host, /* {{{ */
2369 const oconfig_item_t *ci)
2371 cfg_volume_perf_t *cfg_volume_perf;
2373 if ((host == NULL) || (ci == NULL))
2376 if (host->cfg_volume_perf == NULL)
2378 cfg_volume_perf = calloc (1, sizeof (*cfg_volume_perf));
2379 if (cfg_volume_perf == NULL)
2382 /* Set default flags */
2383 cfg_volume_perf->query = NULL;
2384 cfg_volume_perf->volumes = NULL;
2386 cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
2387 if (cfg_volume_perf->il_octets == NULL)
2389 sfree (cfg_volume_perf);
2393 cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
2394 if (cfg_volume_perf->il_operations == NULL)
2396 ignorelist_free (cfg_volume_perf->il_octets);
2397 sfree (cfg_volume_perf);
2401 cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
2402 if (cfg_volume_perf->il_latency == NULL)
2404 ignorelist_free (cfg_volume_perf->il_octets);
2405 ignorelist_free (cfg_volume_perf->il_operations);
2406 sfree (cfg_volume_perf);
2410 host->cfg_volume_perf = cfg_volume_perf;
2412 cfg_volume_perf = host->cfg_volume_perf;
2414 for (int i = 0; i < ci->children_num; ++i) {
2415 oconfig_item_t *item = ci->children + i;
2417 /* if (!item || !item->key || !*item->key) continue; */
2418 if (strcasecmp(item->key, "Interval") == 0)
2419 cna_config_get_interval (item, &cfg_volume_perf->interval);
2420 else if (!strcasecmp(item->key, "GetIO"))
2421 cna_config_volume_perf_option (cfg_volume_perf, item);
2422 else if (!strcasecmp(item->key, "GetOps"))
2423 cna_config_volume_perf_option (cfg_volume_perf, item);
2424 else if (!strcasecmp(item->key, "GetLatency"))
2425 cna_config_volume_perf_option (cfg_volume_perf, item);
2426 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
2427 cna_config_volume_perf_default (cfg_volume_perf, item);
2428 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
2429 cna_config_volume_perf_default (cfg_volume_perf, item);
2430 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
2431 cna_config_volume_perf_default (cfg_volume_perf, item);
2433 WARNING ("netapp plugin: The option %s is not allowed within "
2434 "`VolumePerf' blocks.", item->key);
2438 } /* }}} int cna_config_volume_performance */
2440 /* Handling of the "GetCapacity" and "GetSnapshot" options within a
2441 * <VolumeUsage /> block. */
2442 static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
2443 const oconfig_item_t *ci)
2448 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2450 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2455 name = ci->values[0].value.string;
2457 if (strcasecmp ("GetCapacity", ci->key) == 0)
2458 il = cvu->il_capacity;
2459 else if (strcasecmp ("GetSnapshot", ci->key) == 0)
2460 il = cvu->il_snapshot;
2464 ignorelist_add (il, name);
2465 } /* }}} void cna_config_volume_usage_option */
2467 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
2468 * options within a <VolumeUsage /> block. */
2469 static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
2470 const oconfig_item_t *ci)
2474 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2476 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2481 if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
2482 il = cvu->il_capacity;
2483 else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
2484 il = cvu->il_snapshot;
2488 if (ci->values[0].value.boolean)
2489 ignorelist_set_invert (il, /* invert = */ 0);
2491 ignorelist_set_invert (il, /* invert = */ 1);
2492 } /* }}} void cna_config_volume_usage_default */
2494 /* Corresponds to a <Quota /> block */
2495 static int cna_config_quota (host_config_t *host, oconfig_item_t *ci) /* {{{ */
2497 cfg_quota_t *cfg_quota;
2499 if ((host == NULL) || (ci == NULL))
2502 if (host->cfg_quota == NULL)
2504 cfg_quota = calloc (1, sizeof (*cfg_quota));
2505 if (cfg_quota == NULL)
2507 cfg_quota->query = NULL;
2509 host->cfg_quota = cfg_quota;
2511 cfg_quota = host->cfg_quota;
2513 for (int i = 0; i < ci->children_num; ++i) {
2514 oconfig_item_t *item = ci->children + i;
2516 if (strcasecmp (item->key, "Interval") == 0)
2517 cna_config_get_interval (item, &cfg_quota->interval);
2519 WARNING ("netapp plugin: The option %s is not allowed within "
2520 "`Quota' blocks.", item->key);
2524 } /* }}} int cna_config_quota */
2526 /* Corresponds to a <Disks /> block */
2527 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
2528 cfg_disk_t *cfg_disk;
2530 if ((host == NULL) || (ci == NULL))
2533 if (host->cfg_disk == NULL)
2535 cfg_disk = calloc (1, sizeof (*cfg_disk));
2536 if (cfg_disk == NULL)
2539 /* Set default flags */
2540 cfg_disk->flags = CFG_DISK_ALL;
2541 cfg_disk->query = NULL;
2542 cfg_disk->disks = NULL;
2544 host->cfg_disk = cfg_disk;
2546 cfg_disk = host->cfg_disk;
2548 for (int i = 0; i < ci->children_num; ++i) {
2549 oconfig_item_t *item = ci->children + i;
2551 /* if (!item || !item->key || !*item->key) continue; */
2552 if (strcasecmp(item->key, "Interval") == 0)
2553 cna_config_get_interval (item, &cfg_disk->interval);
2554 else if (strcasecmp(item->key, "GetBusy") == 0)
2555 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2558 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
2560 NOTICE ("netapp plugin: All disk related values have been disabled. "
2561 "Collection of per-disk data will be disabled entirely.");
2562 free_cfg_disk (host->cfg_disk);
2563 host->cfg_disk = NULL;
2567 } /* }}} int cna_config_disk */
2569 /* Corresponds to a <WAFL /> block */
2570 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2572 cfg_wafl_t *cfg_wafl;
2574 if ((host == NULL) || (ci == NULL))
2577 if (host->cfg_wafl == NULL)
2579 cfg_wafl = calloc (1, sizeof (*cfg_wafl));
2580 if (cfg_wafl == NULL)
2583 /* Set default flags */
2584 cfg_wafl->flags = CFG_WAFL_ALL;
2586 host->cfg_wafl = cfg_wafl;
2588 cfg_wafl = host->cfg_wafl;
2590 for (int i = 0; i < ci->children_num; ++i) {
2591 oconfig_item_t *item = ci->children + i;
2593 if (strcasecmp(item->key, "Interval") == 0)
2594 cna_config_get_interval (item, &cfg_wafl->interval);
2595 else if (!strcasecmp(item->key, "GetNameCache"))
2596 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2597 else if (!strcasecmp(item->key, "GetDirCache"))
2598 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2599 else if (!strcasecmp(item->key, "GetBufferCache"))
2600 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2601 else if (!strcasecmp(item->key, "GetInodeCache"))
2602 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2604 WARNING ("netapp plugin: The %s config option is not allowed within "
2605 "`WAFL' blocks.", item->key);
2608 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
2610 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
2611 "Collection of WAFL data will be disabled entirely.");
2612 free_cfg_wafl (host->cfg_wafl);
2613 host->cfg_wafl = NULL;
2617 } /* }}} int cna_config_wafl */
2621 * GetCapacity "vol0"
2622 * GetCapacity "vol1"
2623 * GetCapacity "vol2"
2624 * GetCapacity "vol3"
2625 * GetCapacity "vol4"
2626 * IgnoreSelectedCapacity false
2628 * GetSnapshot "vol0"
2629 * GetSnapshot "vol3"
2630 * GetSnapshot "vol4"
2631 * GetSnapshot "vol7"
2632 * IgnoreSelectedSnapshot false
2635 /* Corresponds to a <VolumeUsage /> block */
2636 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2637 const oconfig_item_t *ci)
2639 cfg_volume_usage_t *cfg_volume_usage;
2641 if ((host == NULL) || (ci == NULL))
2644 if (host->cfg_volume_usage == NULL)
2646 cfg_volume_usage = calloc (1, sizeof (*cfg_volume_usage));
2647 if (cfg_volume_usage == NULL)
2650 /* Set default flags */
2651 cfg_volume_usage->query = NULL;
2652 cfg_volume_usage->volumes = NULL;
2654 cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
2655 if (cfg_volume_usage->il_capacity == NULL)
2657 sfree (cfg_volume_usage);
2661 cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
2662 if (cfg_volume_usage->il_snapshot == NULL)
2664 ignorelist_free (cfg_volume_usage->il_capacity);
2665 sfree (cfg_volume_usage);
2669 host->cfg_volume_usage = cfg_volume_usage;
2671 cfg_volume_usage = host->cfg_volume_usage;
2673 for (int i = 0; i < ci->children_num; ++i) {
2674 oconfig_item_t *item = ci->children + i;
2676 /* if (!item || !item->key || !*item->key) continue; */
2677 if (strcasecmp(item->key, "Interval") == 0)
2678 cna_config_get_interval (item, &cfg_volume_usage->interval);
2679 else if (!strcasecmp(item->key, "GetCapacity"))
2680 cna_config_volume_usage_option (cfg_volume_usage, item);
2681 else if (!strcasecmp(item->key, "GetSnapshot"))
2682 cna_config_volume_usage_option (cfg_volume_usage, item);
2683 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2684 cna_config_volume_usage_default (cfg_volume_usage, item);
2685 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2686 cna_config_volume_usage_default (cfg_volume_usage, item);
2688 WARNING ("netapp plugin: The option %s is not allowed within "
2689 "`VolumeUsage' blocks.", item->key);
2693 } /* }}} int cna_config_volume_usage */
2695 /* Corresponds to a <SnapVault /> block */
2696 static int cna_config_snapvault (host_config_t *host, /* {{{ */
2697 const oconfig_item_t *ci)
2699 cfg_snapvault_t *cfg_snapvault;
2701 if ((host == NULL) || (ci == NULL))
2704 if (host->cfg_snapvault == NULL)
2706 cfg_snapvault = calloc (1, sizeof (*cfg_snapvault));
2707 if (cfg_snapvault == NULL)
2709 cfg_snapvault->query = NULL;
2711 host->cfg_snapvault = cfg_snapvault;
2714 cfg_snapvault = host->cfg_snapvault;
2716 for (int i = 0; i < ci->children_num; ++i) {
2717 oconfig_item_t *item = ci->children + i;
2719 if (strcasecmp (item->key, "Interval") == 0)
2720 cna_config_get_interval (item, &cfg_snapvault->interval);
2722 WARNING ("netapp plugin: The option %s is not allowed within "
2723 "`SnapVault' blocks.", item->key);
2727 } /* }}} int cna_config_snapvault */
2729 /* Corresponds to a <System /> block */
2730 static int cna_config_system (host_config_t *host, /* {{{ */
2733 cfg_system_t *cfg_system;
2735 if ((host == NULL) || (ci == NULL))
2738 if (host->cfg_system == NULL)
2740 cfg_system = calloc (1, sizeof (*cfg_system));
2741 if (cfg_system == NULL)
2744 /* Set default flags */
2745 cfg_system->flags = CFG_SYSTEM_ALL;
2746 cfg_system->query = NULL;
2748 host->cfg_system = cfg_system;
2750 cfg_system = host->cfg_system;
2752 for (int i = 0; i < ci->children_num; ++i) {
2753 oconfig_item_t *item = ci->children + i;
2755 if (strcasecmp(item->key, "Interval") == 0) {
2756 cna_config_get_interval (item, &cfg_system->interval);
2757 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2758 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
2759 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2760 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
2761 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2762 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
2763 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2764 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
2766 WARNING ("netapp plugin: The %s config option is not allowed within "
2767 "`System' blocks.", item->key);
2771 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
2773 NOTICE ("netapp plugin: All system related values have been disabled. "
2774 "Collection of system data will be disabled entirely.");
2775 free_cfg_system (host->cfg_system);
2776 host->cfg_system = NULL;
2780 } /* }}} int cna_config_system */
2782 /* Corresponds to a <Host /> block. */
2783 static host_config_t *cna_alloc_host (void) /* {{{ */
2785 host_config_t *host;
2787 host = calloc (1, sizeof (*host));
2792 host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2794 host->username = NULL;
2795 host->password = NULL;
2796 host->vfiler = NULL;
2798 host->cfg_wafl = NULL;
2799 host->cfg_disk = NULL;
2800 host->cfg_volume_perf = NULL;
2801 host->cfg_volume_usage = NULL;
2802 host->cfg_quota = NULL;
2803 host->cfg_snapvault = NULL;
2804 host->cfg_system = NULL;
2807 } /* }}} host_config_t *cna_alloc_host */
2809 static host_config_t *cna_shallow_clone_host (host_config_t *host) /* {{{ */
2811 host_config_t *clone;
2816 clone = cna_alloc_host ();
2820 if (host->name != NULL) {
2821 clone->name = strdup (host->name);
2822 if (clone->name == NULL) {
2823 free_host_config (clone);
2828 clone->protocol = host->protocol;
2830 if (host->host != NULL) {
2831 clone->host = strdup (host->host);
2832 if (clone->host == NULL) {
2833 free_host_config (clone);
2838 clone->port = host->port;
2840 if (host->username != NULL) {
2841 clone->username = strdup (host->username);
2842 if (clone->username == NULL) {
2843 free_host_config (clone);
2847 if (host->password != NULL) {
2848 clone->password = strdup (host->password);
2849 if (clone->password == NULL) {
2850 free_host_config (clone);
2855 clone->interval = host->interval;
2858 } /* }}} host_config_t *cna_shallow_clone_host */
2860 static int cna_read (user_data_t *ud);
2862 static int cna_register_host (host_config_t *host) /* {{{ */
2867 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s-%s",
2868 host->name, host->vfiler);
2870 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name);
2872 plugin_register_complex_read (/* group = */ NULL, cb_name,
2873 /* callback = */ cna_read,
2874 /* interval = */ host->interval,
2877 .free_func = (void *) free_host_config,
2881 } /* }}} int cna_register_host */
2883 static int cna_config_host (host_config_t *host, /* {{{ */
2884 const oconfig_item_t *ci)
2886 oconfig_item_t *item;
2887 _Bool is_vfiler = 0;
2890 if (! strcasecmp (ci->key, "VFiler"))
2893 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2894 WARNING ("netapp plugin: \"%s\" needs exactly one string argument. Ignoring host block.", ci->key);
2898 status = cf_util_get_string (ci, &host->name);
2902 for (int i = 0; i < ci->children_num; ++i) {
2903 item = ci->children + i;
2907 if (!strcasecmp(item->key, "Address")) {
2908 status = cf_util_get_string (item, &host->host);
2909 } else if (!strcasecmp(item->key, "Port")) {
2912 tmp = cf_util_get_port_number (item);
2915 } else if (!strcasecmp(item->key, "Protocol")) {
2916 if ((item->values_num != 1) || (item->values[0].type != OCONFIG_TYPE_STRING) || (strcasecmp(item->values[0].value.string, "http") && strcasecmp(item->values[0].value.string, "https"))) {
2917 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
2920 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
2921 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2922 } else if (!strcasecmp(item->key, "User")) {
2923 status = cf_util_get_string (item, &host->username);
2924 } else if (!strcasecmp(item->key, "Password")) {
2925 status = cf_util_get_string (item, &host->password);
2926 } else if (!strcasecmp(item->key, "Interval")) {
2927 status = cf_util_get_cdtime (item, &host->interval);
2928 } else if (!strcasecmp(item->key, "WAFL")) {
2929 cna_config_wafl(host, item);
2930 } else if (!strcasecmp(item->key, "Disks")) {
2931 cna_config_disk(host, item);
2932 } else if (!strcasecmp(item->key, "VolumePerf")) {
2933 cna_config_volume_performance(host, item);
2934 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2935 cna_config_volume_usage(host, item);
2936 } else if (!strcasecmp(item->key, "Quota")) {
2937 cna_config_quota(host, item);
2938 } else if (!strcasecmp(item->key, "SnapVault")) {
2939 cna_config_snapvault(host, item);
2940 } else if (!strcasecmp(item->key, "System")) {
2941 cna_config_system(host, item);
2942 } else if ((!strcasecmp(item->key, "VFiler")) && (! is_vfiler)) {
2943 host_config_t *vfiler;
2945 vfiler = cna_shallow_clone_host (host);
2947 ERROR ("netapp plugin: Failed to allocate host object for vfiler.");
2951 if (cna_config_host (vfiler, item)) {
2952 free_host_config (vfiler);
2956 cna_register_host (vfiler);
2957 } else if ((!strcasecmp(item->key, "VFilerName")) && is_vfiler) {
2958 status = cf_util_get_string (item, &host->vfiler);
2960 WARNING ("netapp plugin: Ignoring unknown config option \"%s\" in %s block \"%s\".",
2961 item->key, is_vfiler ? "vfiler" : "host", ci->values[0].value.string);
2968 if (host->host == NULL)
2969 host->host = strdup (host->name);
2971 if (is_vfiler && (! host->vfiler))
2972 host->vfiler = strdup (host->name);
2974 if (host->host == NULL)
2977 if (host->port <= 0)
2978 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
2980 if ((host->username == NULL) || (host->password == NULL)) {
2981 WARNING("netapp plugin: Please supply login information for host \"%s\". "
2982 "Ignoring host block.", host->name);
2990 } /* }}} host_config_t *cna_config_host */
2993 * Callbacks registered with the daemon
2995 * Pretty standard stuff here.
2997 static int cna_init_host (host_config_t *host) /* {{{ */
2999 /* Request version 1.1 of the ONTAP API */
3000 int major_version = 1, minor_version = 1;
3005 if (host->srv != NULL)
3008 if (host->vfiler != NULL) /* Request version 1.7 of the ONTAP API */
3011 host->srv = na_server_open (host->host, major_version, minor_version);
3012 if (host->srv == NULL) {
3013 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
3017 na_server_set_transport_type(host->srv, host->protocol,
3018 /* transportarg = */ NULL);
3019 na_server_set_port(host->srv, host->port);
3020 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
3021 na_server_adminuser(host->srv, host->username, host->password);
3022 na_server_set_timeout(host->srv, 5 /* seconds */);
3024 if (host->vfiler != NULL) {
3025 if (! na_server_set_vfiler (host->srv, host->vfiler)) {
3026 ERROR ("netapp plugin: Failed to connect to VFiler '%s' on host '%s'.",
3027 host->vfiler, host->host);
3031 INFO ("netapp plugin: Connected to VFiler '%s' on host '%s'.",
3032 host->vfiler, host->host);
3037 } /* }}} int cna_init_host */
3039 static int cna_init (void) /* {{{ */
3041 char err[256] = { 0 };
3043 if (!na_startup(err, sizeof(err))) {
3044 err[sizeof (err) - 1] = 0;
3045 ERROR("netapp plugin: Error initializing netapp API: %s", err);
3050 } /* }}} cna_init */
3052 static int cna_read_internal (host_config_t *host) { /* {{{ */
3055 status = cna_query_wafl (host);
3059 status = cna_query_disk (host);
3063 status = cna_query_volume_perf (host);
3067 status = cna_query_volume_usage (host);
3071 status = cna_query_quota (host);
3075 status = cna_query_snapvault (host);
3079 status = cna_query_system (host);
3084 } /* }}} int cna_read_internal */
3086 static int cna_read (user_data_t *ud) { /* {{{ */
3087 host_config_t *host;
3090 if ((ud == NULL) || (ud->data == NULL))
3095 status = cna_init_host (host);
3099 status = cna_read_internal (host);
3102 if (host->srv != NULL)
3103 na_server_close (host->srv);
3108 } /* }}} int cna_read */
3110 static int cna_config (oconfig_item_t *ci) { /* {{{ */
3111 oconfig_item_t *item;
3113 for (int i = 0; i < ci->children_num; ++i) {
3114 item = ci->children + i;
3116 if (strcasecmp(item->key, "Host") == 0)
3118 host_config_t *host;
3120 host = cna_alloc_host ();
3122 ERROR ("netapp plugin: Failed to allocate host object.");
3126 if (cna_config_host (host, item) != 0) {
3127 free_host_config (host);
3131 cna_register_host (host);
3133 else /* if (item->key != "Host") */
3135 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
3139 } /* }}} int cna_config */
3141 static int cna_shutdown (void) /* {{{ */
3143 /* Clean up system resources and stuff. */
3147 } /* }}} int cna_shutdown */
3149 void module_register(void) {
3150 plugin_register_complex_config("netapp", cna_config);
3151 plugin_register_init("netapp", cna_init);
3152 plugin_register_shutdown("netapp", cna_shutdown);
3155 /* vim: set sw=2 ts=2 noet fdm=marker : */