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));
636 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
637 if (plugin_inst != NULL)
638 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
639 sstrncpy (vl.type, type, sizeof (vl.type));
640 if (type_inst != NULL)
641 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
643 return (plugin_dispatch_values (&vl));
644 } /* }}} int submit_uint64 */
646 static int submit_two_derive (const char *host, const char *plugin_inst, /* {{{ */
647 const char *type, const char *type_inst, derive_t val0, derive_t val1,
648 cdtime_t timestamp, cdtime_t interval)
655 return (submit_values (host, plugin_inst, type, type_inst,
656 values, STATIC_ARRAY_SIZE (values), timestamp, interval));
657 } /* }}} int submit_two_derive */
659 static int submit_derive (const char *host, const char *plugin_inst, /* {{{ */
660 const char *type, const char *type_inst, derive_t counter,
661 cdtime_t timestamp, cdtime_t interval)
663 return (submit_values (host, plugin_inst, type, type_inst,
664 &(value_t) { .derive = counter }, 1, timestamp, interval));
665 } /* }}} int submit_derive */
667 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
668 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
669 cdtime_t timestamp, cdtime_t interval)
676 return (submit_values (host, plugin_inst, type, type_inst,
677 values, STATIC_ARRAY_SIZE (values), timestamp, interval));
678 } /* }}} int submit_two_gauge */
680 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
681 const char *type, const char *type_inst, double d,
682 cdtime_t timestamp, cdtime_t interval)
684 return (submit_values (host, plugin_inst, type, type_inst,
685 &(value_t) { .gauge = counter }, 1, timestamp, interval));
686 } /* }}} int submit_uint64 */
688 /* Calculate hit ratio from old and new counters and submit the resulting
689 * percentage. Used by "submit_wafl_data". */
690 static int submit_cache_ratio (const char *host, /* {{{ */
691 const char *plugin_inst,
692 const char *type_inst,
700 value_t v = { .gauge = NAN };
702 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
706 hits = new_hits - old_hits;
707 misses = new_misses - old_misses;
709 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
712 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
713 &v, 1, timestamp, interval));
714 } /* }}} int submit_cache_ratio */
716 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
717 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
718 cfg_wafl_t *old_data, const cfg_wafl_t *new_data, cdtime_t interval)
720 /* Submit requested counters */
721 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
722 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
723 submit_cache_ratio (hostname, instance, "name_cache_hit",
724 new_data->name_cache_hit, new_data->name_cache_miss,
725 old_data->name_cache_hit, old_data->name_cache_miss,
726 new_data->timestamp, interval);
728 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
729 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
730 submit_cache_ratio (hostname, instance, "find_dir_hit",
731 new_data->find_dir_hit, new_data->find_dir_miss,
732 old_data->find_dir_hit, old_data->find_dir_miss,
733 new_data->timestamp, interval);
735 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
736 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
737 submit_cache_ratio (hostname, instance, "buf_hash_hit",
738 new_data->buf_hash_hit, new_data->buf_hash_miss,
739 old_data->buf_hash_hit, old_data->buf_hash_miss,
740 new_data->timestamp, interval);
742 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
743 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
744 submit_cache_ratio (hostname, instance, "inode_cache_hit",
745 new_data->inode_cache_hit, new_data->inode_cache_miss,
746 old_data->inode_cache_hit, old_data->inode_cache_miss,
747 new_data->timestamp, interval);
749 /* Clear old HAVE_* flags */
750 old_data->flags &= ~HAVE_WAFL_ALL;
752 /* Copy all counters */
753 old_data->timestamp = new_data->timestamp;
754 old_data->name_cache_hit = new_data->name_cache_hit;
755 old_data->name_cache_miss = new_data->name_cache_miss;
756 old_data->find_dir_hit = new_data->find_dir_hit;
757 old_data->find_dir_miss = new_data->find_dir_miss;
758 old_data->buf_hash_hit = new_data->buf_hash_hit;
759 old_data->buf_hash_miss = new_data->buf_hash_miss;
760 old_data->inode_cache_hit = new_data->inode_cache_hit;
761 old_data->inode_cache_miss = new_data->inode_cache_miss;
763 /* Copy HAVE_* flags */
764 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
767 } /* }}} int submit_wafl_data */
769 /* Submits volume performance data to the daemon, taking care to honor and
770 * update flags appropriately. */
771 static int submit_volume_perf_data (const char *hostname, /* {{{ */
772 data_volume_perf_t *old_data,
773 const data_volume_perf_t *new_data, int interval)
775 char plugin_instance[DATA_MAX_NAME_LEN];
777 if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL))
780 ssnprintf (plugin_instance, sizeof (plugin_instance),
781 "volume-%s", old_data->name);
783 /* Check for and submit disk-octet values */
784 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_IO)
785 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
787 submit_two_derive (hostname, plugin_instance, "disk_octets", /* type instance = */ NULL,
788 (derive_t) new_data->read_bytes, (derive_t) new_data->write_bytes, new_data->timestamp, interval);
791 /* Check for and submit disk-operations values */
792 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_OPS)
793 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
795 submit_two_derive (hostname, plugin_instance, "disk_ops", /* type instance = */ NULL,
796 (derive_t) new_data->read_ops, (derive_t) new_data->write_ops, new_data->timestamp, interval);
799 /* Check for, calculate and submit disk-latency values */
800 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_LATENCY
801 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
802 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
803 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
804 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
806 gauge_t latency_per_op_read;
807 gauge_t latency_per_op_write;
809 latency_per_op_read = NAN;
810 latency_per_op_write = NAN;
812 /* Check if a counter wrapped around. */
813 if ((new_data->read_ops > old_data->read_ops)
814 && (new_data->read_latency > old_data->read_latency))
816 uint64_t diff_ops_read;
817 uint64_t diff_latency_read;
819 diff_ops_read = new_data->read_ops - old_data->read_ops;
820 diff_latency_read = new_data->read_latency - old_data->read_latency;
822 if (diff_ops_read > 0)
823 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
826 if ((new_data->write_ops > old_data->write_ops)
827 && (new_data->write_latency > old_data->write_latency))
829 uint64_t diff_ops_write;
830 uint64_t diff_latency_write;
832 diff_ops_write = new_data->write_ops - old_data->write_ops;
833 diff_latency_write = new_data->write_latency - old_data->write_latency;
835 if (diff_ops_write > 0)
836 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
839 submit_two_gauge (hostname, plugin_instance, "disk_latency", /* type instance = */ NULL,
840 latency_per_op_read, latency_per_op_write, new_data->timestamp, interval);
843 /* Clear all HAVE_* flags. */
844 old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
846 /* Copy all counters */
847 old_data->timestamp = new_data->timestamp;
848 old_data->read_bytes = new_data->read_bytes;
849 old_data->write_bytes = new_data->write_bytes;
850 old_data->read_ops = new_data->read_ops;
851 old_data->write_ops = new_data->write_ops;
852 old_data->read_latency = new_data->read_latency;
853 old_data->write_latency = new_data->write_latency;
855 /* Copy the HAVE_* flags */
856 old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
859 } /* }}} int submit_volume_perf_data */
861 static cdtime_t cna_child_get_cdtime (na_elem_t *data) /* {{{ */
865 t = (time_t) na_child_get_uint64 (data, "timestamp", /* default = */ 0);
867 return (TIME_T_TO_CDTIME_T (t));
868 } /* }}} cdtime_t cna_child_get_cdtime */
874 * These functions are called with appropriate data returned by the libnetapp
875 * interface which is parsed and submitted with the above functions.
877 /* Data corresponding to <WAFL /> */
878 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
879 na_elem_t *data, cdtime_t interval)
881 cfg_wafl_t perf_data = { 0 };
882 const char *plugin_inst;
884 na_elem_t *instances;
885 na_elem_iter_t counter_iter;
887 perf_data.timestamp = cna_child_get_cdtime (data);
889 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
890 if (instances == NULL)
892 ERROR ("netapp plugin: cna_handle_wafl_data: "
893 "na_elem_child (\"instances\") failed "
894 "for host %s.", hostname);
898 plugin_inst = na_child_get_string(instances, "name");
899 if (plugin_inst == NULL)
901 ERROR ("netapp plugin: cna_handle_wafl_data: "
902 "na_child_get_string (\"name\") failed "
903 "for host %s.", hostname);
907 /* Iterate over all counters */
908 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
909 for (na_elem_t *counter = na_iterator_next (&counter_iter);
911 counter = na_iterator_next (&counter_iter))
916 name = na_child_get_string(counter, "name");
920 value = na_child_get_uint64(counter, "value", UINT64_MAX);
921 if (value == UINT64_MAX)
924 if (!strcmp(name, "name_cache_hit")) {
925 perf_data.name_cache_hit = value;
926 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
927 } else if (!strcmp(name, "name_cache_miss")) {
928 perf_data.name_cache_miss = value;
929 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
930 } else if (!strcmp(name, "find_dir_hit")) {
931 perf_data.find_dir_hit = value;
932 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
933 } else if (!strcmp(name, "find_dir_miss")) {
934 perf_data.find_dir_miss = value;
935 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
936 } else if (!strcmp(name, "buf_hash_hit")) {
937 perf_data.buf_hash_hit = value;
938 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
939 } else if (!strcmp(name, "buf_hash_miss")) {
940 perf_data.buf_hash_miss = value;
941 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
942 } else if (!strcmp(name, "inode_cache_hit")) {
943 perf_data.inode_cache_hit = value;
944 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
945 } else if (!strcmp(name, "inode_cache_miss")) {
946 perf_data.inode_cache_miss = value;
947 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
949 DEBUG("netapp plugin: cna_handle_wafl_data: "
950 "Found unexpected child: %s "
951 "for host %s.", name, hostname);
955 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data, interval));
956 } /* }}} void cna_handle_wafl_data */
958 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
965 if (cw->query != NULL)
968 cw->query = na_elem_new("perf-object-get-instances");
969 if (cw->query == NULL)
971 ERROR ("netapp plugin: na_elem_new failed.");
974 na_child_add_string (cw->query, "objectname", "wafl");
976 e = na_elem_new("counters");
979 na_elem_free (cw->query);
981 ERROR ("netapp plugin: na_elem_new failed.");
984 na_child_add_string(e, "counter", "name_cache_hit");
985 na_child_add_string(e, "counter", "name_cache_miss");
986 na_child_add_string(e, "counter", "find_dir_hit");
987 na_child_add_string(e, "counter", "find_dir_miss");
988 na_child_add_string(e, "counter", "buf_hash_hit");
989 na_child_add_string(e, "counter", "buf_hash_miss");
990 na_child_add_string(e, "counter", "inode_cache_hit");
991 na_child_add_string(e, "counter", "inode_cache_miss");
993 na_child_add(cw->query, e);
996 } /* }}} int cna_setup_wafl */
998 static int cna_query_wafl (host_config_t *host) /* {{{ */
1007 /* If WAFL was not configured, return without doing anything. */
1008 if (host->cfg_wafl == NULL)
1012 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
1015 status = cna_setup_wafl (host->cfg_wafl);
1018 assert (host->cfg_wafl->query != NULL);
1020 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
1021 if (na_results_status (data) != NA_OK)
1023 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed for host %s: %s",
1024 host->name, na_results_reason (data));
1025 na_elem_free (data);
1029 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data,
1030 host->cfg_wafl->interval.interval);
1033 host->cfg_wafl->interval.last_read = now;
1035 na_elem_free (data);
1037 } /* }}} int cna_query_wafl */
1039 /* Data corresponding to <Disks /> */
1040 static int cna_handle_disk_data (const char *hostname, /* {{{ */
1041 cfg_disk_t *cfg_disk, na_elem_t *data, cdtime_t interval)
1044 na_elem_t *instances;
1045 na_elem_iter_t instance_iter;
1046 disk_t *worst_disk = NULL;
1048 if ((cfg_disk == NULL) || (data == NULL))
1051 timestamp = cna_child_get_cdtime (data);
1053 instances = na_elem_child (data, "instances");
1054 if (instances == NULL)
1056 ERROR ("netapp plugin: cna_handle_disk_data: "
1057 "na_elem_child (\"instances\") failed "
1058 "for host %s.", hostname);
1062 /* Iterate over all children */
1063 instance_iter = na_child_iterator (instances);
1064 for (na_elem_t *instance = na_iterator_next (&instance_iter);
1066 instance = na_iterator_next(&instance_iter))
1069 disk_t new_data = { 0 };
1071 na_elem_iter_t counter_iterator;
1073 new_data.timestamp = timestamp;
1074 new_data.disk_busy_percent = NAN;
1076 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
1077 if (old_data == NULL)
1080 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
1081 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
1082 for (na_elem_t *counter = na_iterator_next(&counter_iterator);
1084 counter = na_iterator_next(&counter_iterator))
1089 name = na_child_get_string(counter, "name");
1093 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1094 if (value == UINT64_MAX)
1097 if (strcmp(name, "disk_busy") == 0)
1099 new_data.disk_busy = value;
1100 new_data.flags |= HAVE_DISK_BUSY;
1102 else if (strcmp(name, "base_for_disk_busy") == 0)
1104 new_data.base_for_disk_busy = value;
1105 new_data.flags |= HAVE_DISK_BASE;
1109 DEBUG ("netapp plugin: cna_handle_disk_data: "
1110 "Counter not handled: %s = %"PRIu64,
1115 /* If all required counters are available and did not just wrap around,
1116 * calculate the busy percentage. Otherwise, the value is initialized to
1117 * NAN at the top of the for-loop. */
1118 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1119 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1120 && (new_data.disk_busy >= old_data->disk_busy)
1121 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
1126 busy_diff = new_data.disk_busy - old_data->disk_busy;
1127 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
1129 new_data.disk_busy_percent = 100.0
1130 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
1133 /* Clear HAVE_* flags */
1134 old_data->flags &= ~HAVE_DISK_ALL;
1137 old_data->timestamp = new_data.timestamp;
1138 old_data->disk_busy = new_data.disk_busy;
1139 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
1140 old_data->disk_busy_percent = new_data.disk_busy_percent;
1143 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
1145 if ((worst_disk == NULL)
1146 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
1147 worst_disk = old_data;
1148 } /* for (all disks) */
1150 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
1151 submit_double (hostname, "system", "percent", "disk_busy",
1152 worst_disk->disk_busy_percent, timestamp, interval);
1155 } /* }}} int cna_handle_disk_data */
1157 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
1164 if (cd->query != NULL)
1167 cd->query = na_elem_new ("perf-object-get-instances");
1168 if (cd->query == NULL)
1170 ERROR ("netapp plugin: na_elem_new failed.");
1173 na_child_add_string (cd->query, "objectname", "disk");
1175 e = na_elem_new("counters");
1178 na_elem_free (cd->query);
1180 ERROR ("netapp plugin: na_elem_new failed.");
1183 na_child_add_string(e, "counter", "disk_busy");
1184 na_child_add_string(e, "counter", "base_for_disk_busy");
1185 na_child_add(cd->query, e);
1188 } /* }}} int cna_setup_disk */
1190 static int cna_query_disk (host_config_t *host) /* {{{ */
1199 /* If the user did not configure disk statistics, return without doing
1201 if (host->cfg_disk == NULL)
1205 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1208 status = cna_setup_disk (host->cfg_disk);
1211 assert (host->cfg_disk->query != NULL);
1213 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1214 if (na_results_status (data) != NA_OK)
1216 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed for host %s: %s",
1217 host->name, na_results_reason (data));
1218 na_elem_free (data);
1222 status = cna_handle_disk_data (host->name, host->cfg_disk, data,
1223 host->cfg_disk->interval.interval);
1226 host->cfg_disk->interval.last_read = now;
1228 na_elem_free (data);
1230 } /* }}} int cna_query_disk */
1232 /* Data corresponding to <VolumePerf /> */
1233 static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
1234 cfg_volume_perf_t *cvp, na_elem_t *data, cdtime_t interval)
1237 na_elem_t *elem_instances;
1238 na_elem_iter_t iter_instances;
1240 timestamp = cna_child_get_cdtime (data);
1242 elem_instances = na_elem_child(data, "instances");
1243 if (elem_instances == NULL)
1245 ERROR ("netapp plugin: handle_volume_perf_data: "
1246 "na_elem_child (\"instances\") failed "
1247 "for host %s.", hostname);
1251 iter_instances = na_child_iterator (elem_instances);
1252 for (na_elem_t *elem_instance = na_iterator_next(&iter_instances);
1253 elem_instance != NULL;
1254 elem_instance = na_iterator_next(&iter_instances))
1258 data_volume_perf_t perf_data = { 0 };
1259 data_volume_perf_t *v;
1261 na_elem_t *elem_counters;
1262 na_elem_iter_t iter_counters;
1264 perf_data.timestamp = timestamp;
1266 name = na_child_get_string (elem_instance, "name");
1270 /* get_volume_perf may return NULL if this volume is to be ignored. */
1271 v = get_volume_perf (cvp, name);
1275 elem_counters = na_elem_child (elem_instance, "counters");
1276 if (elem_counters == NULL)
1279 iter_counters = na_child_iterator (elem_counters);
1280 for (na_elem_t *elem_counter = na_iterator_next(&iter_counters);
1281 elem_counter != NULL;
1282 elem_counter = na_iterator_next(&iter_counters))
1287 name = na_child_get_string (elem_counter, "name");
1291 value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
1292 if (value == UINT64_MAX)
1295 if (!strcmp(name, "read_data")) {
1296 perf_data.read_bytes = value;
1297 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1298 } else if (!strcmp(name, "write_data")) {
1299 perf_data.write_bytes = value;
1300 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1301 } else if (!strcmp(name, "read_ops")) {
1302 perf_data.read_ops = value;
1303 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1304 } else if (!strcmp(name, "write_ops")) {
1305 perf_data.write_ops = value;
1306 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1307 } else if (!strcmp(name, "read_latency")) {
1308 perf_data.read_latency = value;
1309 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1310 } else if (!strcmp(name, "write_latency")) {
1311 perf_data.write_latency = value;
1312 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1314 } /* for (elem_counter) */
1316 submit_volume_perf_data (hostname, v, &perf_data, interval);
1317 } /* for (volume) */
1320 } /* }}} int cna_handle_volume_perf_data */
1322 static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
1329 if (cd->query != NULL)
1332 cd->query = na_elem_new ("perf-object-get-instances");
1333 if (cd->query == NULL)
1335 ERROR ("netapp plugin: na_elem_new failed.");
1338 na_child_add_string (cd->query, "objectname", "volume");
1340 e = na_elem_new("counters");
1343 na_elem_free (cd->query);
1345 ERROR ("netapp plugin: na_elem_new failed.");
1348 na_child_add_string(e, "counter", "read_ops");
1349 na_child_add_string(e, "counter", "write_ops");
1350 na_child_add_string(e, "counter", "read_data");
1351 na_child_add_string(e, "counter", "write_data");
1352 na_child_add_string(e, "counter", "read_latency");
1353 na_child_add_string(e, "counter", "write_latency");
1354 na_child_add(cd->query, e);
1357 } /* }}} int cna_setup_volume_perf */
1359 static int cna_query_volume_perf (host_config_t *host) /* {{{ */
1368 /* If the user did not configure volume performance statistics, return
1369 * without doing anything. */
1370 if (host->cfg_volume_perf == NULL)
1374 if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
1377 status = cna_setup_volume_perf (host->cfg_volume_perf);
1380 assert (host->cfg_volume_perf->query != NULL);
1382 data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
1383 if (na_results_status (data) != NA_OK)
1385 ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed for host %s: %s",
1386 host->name, na_results_reason (data));
1387 na_elem_free (data);
1391 status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data,
1392 host->cfg_volume_perf->interval.interval);
1395 host->cfg_volume_perf->interval.last_read = now;
1397 na_elem_free (data);
1399 } /* }}} int cna_query_volume_perf */
1401 /* Data corresponding to <VolumeUsage /> */
1402 static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
1403 cfg_volume_usage_t *cfg_volume, int interval)
1405 for (data_volume_usage_t *v = cfg_volume->volumes; v != NULL; v = v->next)
1407 char plugin_instance[DATA_MAX_NAME_LEN];
1409 uint64_t norm_used = v->norm_used;
1410 uint64_t norm_free = v->norm_free;
1411 uint64_t sis_saved = v->sis_saved;
1412 uint64_t compress_saved = v->compress_saved;
1413 uint64_t dedup_saved = v->dedup_saved;
1414 uint64_t snap_reserve_used = 0;
1415 uint64_t snap_reserve_free = v->snap_reserved;
1416 uint64_t snap_norm_used = v->snap_used;
1418 ssnprintf (plugin_instance, sizeof (plugin_instance),
1419 "volume-%s", v->name);
1421 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD)) {
1422 if (v->snap_reserved > v->snap_used) {
1423 snap_reserve_free = v->snap_reserved - v->snap_used;
1424 snap_reserve_used = v->snap_used;
1427 snap_reserve_free = 0;
1428 snap_reserve_used = v->snap_reserved;
1429 snap_norm_used = v->snap_used - v->snap_reserved;
1433 /* The space used by snapshots but not reserved for them is included in
1434 * both, norm_used and snap_norm_used. If possible, subtract this here. */
1435 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED))
1437 if (norm_used >= snap_norm_used)
1438 norm_used -= snap_norm_used;
1441 ERROR ("netapp plugin: (norm_used = %"PRIu64") < (snap_norm_used = "
1442 "%"PRIu64") for host %s. Invalidating both.",
1443 norm_used, snap_norm_used, hostname);
1444 v->flags &= ~(HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED);
1448 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1449 submit_double (hostname, /* plugin instance = */ plugin_instance,
1450 "df_complex", "free",
1451 (double) norm_free, /* timestamp = */ 0, interval);
1453 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1454 submit_double (hostname, /* plugin instance = */ plugin_instance,
1455 "df_complex", "sis_saved",
1456 (double) sis_saved, /* timestamp = */ 0, interval);
1458 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_COMPRESS_SAVED))
1459 submit_double (hostname, /* plugin instance = */ plugin_instance,
1460 "df_complex", "compression_saved",
1461 (double) compress_saved, /* timestamp = */ 0, interval);
1463 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_DEDUP_SAVED))
1464 submit_double (hostname, /* plugin instance = */ plugin_instance,
1465 "df_complex", "dedup_saved",
1466 (double) dedup_saved, /* timestamp = */ 0, interval);
1468 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1469 submit_double (hostname, /* plugin instance = */ plugin_instance,
1470 "df_complex", "used",
1471 (double) norm_used, /* timestamp = */ 0, interval);
1473 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1474 submit_double (hostname, /* plugin instance = */ plugin_instance,
1475 "df_complex", "snap_reserved",
1476 (double) snap_reserve_free, /* timestamp = */ 0, interval);
1478 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD))
1479 submit_double (hostname, /* plugin instance = */ plugin_instance,
1480 "df_complex", "snap_reserve_used",
1481 (double) snap_reserve_used, /* timestamp = */ 0, interval);
1483 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1484 submit_double (hostname, /* plugin instance = */ plugin_instance,
1485 "df_complex", "snap_normal_used",
1486 (double) snap_norm_used, /* timestamp = */ 0, interval);
1488 /* Clear all the HAVE_* flags */
1489 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1490 } /* for (v = cfg_volume->volumes) */
1493 } /* }}} int cna_submit_volume_usage_data */
1495 /* Switch the state of a volume between online and offline and send out a
1497 static int cna_change_volume_status (const char *hostname, /* {{{ */
1498 data_volume_usage_t *v)
1500 notification_t n = { 0 };
1503 sstrncpy (n.host, hostname, sizeof (n.host));
1504 sstrncpy (n.plugin, "netapp", sizeof (n.plugin));
1505 sstrncpy (n.plugin_instance, v->name, sizeof (n.plugin_instance));
1507 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0) {
1508 n.severity = NOTIF_OKAY;
1509 ssnprintf (n.message, sizeof (n.message),
1510 "Volume %s is now online.", v->name);
1511 v->flags &= ~IS_VOLUME_USAGE_OFFLINE;
1513 n.severity = NOTIF_WARNING;
1514 ssnprintf (n.message, sizeof (n.message),
1515 "Volume %s is now offline.", v->name);
1516 v->flags |= IS_VOLUME_USAGE_OFFLINE;
1519 return (plugin_dispatch_notification (&n));
1520 } /* }}} int cna_change_volume_status */
1522 static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
1523 data_volume_usage_t *v)
1525 uint64_t snap_used = 0, value;
1526 na_elem_t *data, *elem_snapshots;
1527 na_elem_iter_t iter_snap;
1529 data = na_server_invoke_elem(host->srv, v->snap_query);
1530 if (na_results_status(data) != NA_OK)
1532 if (na_results_errno(data) == EVOLUMEOFFLINE) {
1533 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) == 0)
1534 cna_change_volume_status (host->name, v);
1536 ERROR ("netapp plugin: cna_handle_volume_snap_usage: na_server_invoke_elem for "
1537 "volume \"%s\" on host %s failed with error %d: %s", v->name,
1538 host->name, na_results_errno(data), na_results_reason(data));
1544 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0)
1545 cna_change_volume_status (host->name, v);
1547 elem_snapshots = na_elem_child (data, "snapshots");
1548 if (elem_snapshots == NULL)
1550 ERROR ("netapp plugin: cna_handle_volume_snap_usage: "
1551 "na_elem_child (\"snapshots\") failed "
1552 "for host %s.", host->name);
1557 iter_snap = na_child_iterator (elem_snapshots);
1558 for (na_elem_t *elem_snap = na_iterator_next (&iter_snap);
1560 elem_snap = na_iterator_next (&iter_snap))
1562 value = na_child_get_uint64(elem_snap, "cumulative-total", 0);
1563 /* "cumulative-total" is the total size of the oldest snapshot plus all
1564 * newer ones in blocks (1KB). We therefore are looking for the highest
1565 * number of all snapshots - that's the size required for the snapshots. */
1566 if (value > snap_used)
1569 na_elem_free (data);
1570 /* snap_used is in 1024 byte blocks */
1571 v->snap_used = snap_used * 1024;
1572 v->flags |= HAVE_VOLUME_USAGE_SNAP_USED;
1573 } /* }}} void cna_handle_volume_snap_usage */
1575 static void cna_handle_volume_sis_data (const host_config_t *host, /* {{{ */
1576 data_volume_usage_t *v, na_elem_t *sis)
1578 const char *sis_state;
1579 uint64_t sis_saved_reported;
1581 if (na_elem_child(sis, "sis-info"))
1582 sis = na_elem_child(sis, "sis-info");
1584 sis_state = na_child_get_string(sis, "state");
1585 if (sis_state == NULL)
1588 /* If SIS is not enabled, there's nothing left to do for this volume. */
1589 if (strcmp ("enabled", sis_state) != 0)
1592 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1593 if (sis_saved_reported == UINT64_MAX)
1596 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1597 if ((sis_saved_reported >> 32) != 0) {
1598 /* In case they ever fix this bug. */
1599 v->sis_saved = sis_saved_reported;
1600 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1601 } else { /* really hacky work-around code. {{{ */
1602 uint64_t sis_saved_percent;
1603 uint64_t sis_saved_guess;
1604 uint64_t overflow_guess;
1605 uint64_t guess1, guess2, guess3;
1607 /* Check if we have v->norm_used. Without it, we cannot calculate
1608 * sis_saved_guess. */
1609 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1612 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1613 if (sis_saved_percent > 100)
1616 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1617 * will hopefully be fixed in later versions. To work around the bug, try
1618 * to figure out how often the 32bit integer wrapped around by using the
1619 * "percentage-saved" value. Because the percentage is in the range
1620 * [0-100], this should work as long as the saved space does not exceed
1622 /* percentage-saved = size-saved / (size-saved + size-used) */
1623 if (sis_saved_percent < 100)
1624 sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1626 sis_saved_guess = v->norm_used;
1628 overflow_guess = sis_saved_guess >> 32;
1629 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1630 guess2 = (overflow_guess << 32) + sis_saved_reported;
1631 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1633 if (sis_saved_guess < guess2) {
1634 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1635 v->sis_saved = guess1;
1637 v->sis_saved = guess2;
1639 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1640 v->sis_saved = guess2;
1642 v->sis_saved = guess3;
1644 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1645 } /* }}} end of 32-bit workaround */
1646 } /* }}} void cna_handle_volume_sis_data */
1648 /* ONTAP >= 8.1 uses SIS for managing dedup and compression */
1649 static void cna_handle_volume_sis_saved (const host_config_t *host, /* {{{ */
1650 data_volume_usage_t *v, na_elem_t *sis)
1654 if (na_elem_child(sis, "sis-info"))
1655 sis = na_elem_child(sis, "sis-info");
1657 saved = na_child_get_uint64(sis, "compress-saved", UINT64_MAX);
1658 if (saved != UINT64_MAX) {
1659 v->compress_saved = saved;
1660 v->flags |= HAVE_VOLUME_USAGE_COMPRESS_SAVED;
1663 saved = na_child_get_uint64(sis, "dedup-saved", UINT64_MAX);
1664 if (saved != UINT64_MAX) {
1665 v->dedup_saved = saved;
1666 v->flags |= HAVE_VOLUME_USAGE_DEDUP_SAVED;
1668 } /* }}} void cna_handle_volume_sis_saved */
1670 static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */
1671 cfg_volume_usage_t *cfg_volume, na_elem_t *data)
1673 na_elem_t *elem_volumes;
1674 na_elem_iter_t iter_volume;
1676 elem_volumes = na_elem_child (data, "volumes");
1677 if (elem_volumes == NULL)
1679 ERROR ("netapp plugin: cna_handle_volume_usage_data: "
1680 "na_elem_child (\"volumes\") failed "
1681 "for host %s.", host->name);
1685 iter_volume = na_child_iterator (elem_volumes);
1686 for (na_elem_t *elem_volume = na_iterator_next (&iter_volume);
1687 elem_volume != NULL;
1688 elem_volume = na_iterator_next (&iter_volume))
1690 const char *volume_name, *state;
1692 data_volume_usage_t *v;
1697 volume_name = na_child_get_string (elem_volume, "name");
1698 if (volume_name == NULL)
1701 state = na_child_get_string (elem_volume, "state");
1702 if ((state == NULL) || (strcmp(state, "online") != 0))
1705 /* get_volume_usage may return NULL if the volume is to be ignored. */
1706 v = get_volume_usage (cfg_volume, volume_name);
1710 if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
1711 cna_handle_volume_snap_usage(host, v);
1713 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1716 /* 2^4 exa-bytes? This will take a while ;) */
1717 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1718 if (value != UINT64_MAX) {
1719 v->norm_free = value;
1720 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1723 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1724 if (value != UINT64_MAX) {
1725 v->norm_used = value;
1726 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1729 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
1730 if (value != UINT64_MAX) {
1731 /* 1 block == 1024 bytes as per API docs */
1732 v->snap_reserved = 1024 * value;
1733 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1736 sis = na_elem_child(elem_volume, "sis");
1738 cna_handle_volume_sis_data (host, v, sis);
1739 cna_handle_volume_sis_saved (host, v, sis);
1741 } /* for (elem_volume) */
1743 return (cna_submit_volume_usage_data (host->name, cfg_volume,
1744 host->cfg_volume_usage->interval.interval));
1745 } /* }}} int cna_handle_volume_usage_data */
1747 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
1752 if (cvu->query != NULL)
1755 cvu->query = na_elem_new ("volume-list-info");
1756 if (cvu->query == NULL)
1758 ERROR ("netapp plugin: na_elem_new failed.");
1763 } /* }}} int cna_setup_volume_usage */
1765 static int cna_query_volume_usage (host_config_t *host) /* {{{ */
1774 /* If the user did not configure volume_usage statistics, return without
1775 * doing anything. */
1776 if (host->cfg_volume_usage == NULL)
1780 if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
1783 status = cna_setup_volume_usage (host->cfg_volume_usage);
1786 assert (host->cfg_volume_usage->query != NULL);
1788 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1789 if (na_results_status (data) != NA_OK)
1791 ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed for host %s: %s",
1792 host->name, na_results_reason (data));
1793 na_elem_free (data);
1797 status = cna_handle_volume_usage_data (host, host->cfg_volume_usage, data);
1800 host->cfg_volume_usage->interval.last_read = now;
1802 na_elem_free (data);
1804 } /* }}} int cna_query_volume_usage */
1806 /* Data corresponding to <Quota /> */
1807 static int cna_handle_quota_data (const host_config_t *host, /* {{{ */
1808 cfg_quota_t *cfg_quota, na_elem_t *data)
1810 na_elem_t *elem_quotas;
1811 na_elem_iter_t iter_quota;
1813 elem_quotas = na_elem_child (data, "quotas");
1814 if (elem_quotas == NULL)
1816 ERROR ("netapp plugin: cna_handle_quota_data: "
1817 "na_elem_child (\"quotas\") failed "
1818 "for host %s.", host->name);
1822 iter_quota = na_child_iterator (elem_quotas);
1823 for (na_elem_t *elem_quota = na_iterator_next (&iter_quota);
1825 elem_quota = na_iterator_next (&iter_quota))
1827 const char *quota_type, *volume_name, *tree_name;
1830 char plugin_instance[DATA_MAX_NAME_LEN];
1832 quota_type = na_child_get_string (elem_quota, "quota-type");
1833 if (quota_type == NULL)
1836 /* possible TODO: support other types as well */
1837 if (strcmp (quota_type, "tree") != 0)
1840 tree_name = na_child_get_string (elem_quota, "tree");
1841 if ((tree_name == NULL) || (*tree_name == '\0'))
1844 volume_name = na_child_get_string (elem_quota, "volume");
1845 if (volume_name == NULL)
1848 ssnprintf (plugin_instance, sizeof (plugin_instance),
1849 "quota-%s-%s", volume_name, tree_name);
1851 value = na_child_get_uint64 (elem_quota, "disk-used", UINT64_MAX);
1852 if (value != UINT64_MAX) {
1853 value *= 1024; /* disk-used reports kilobytes */
1854 submit_double (host->name, plugin_instance,
1855 /* type = */ "df_complex", /* type instance = */ NULL,
1856 (double)value, /* timestamp = */ 0,
1857 host->cfg_quota->interval.interval);
1860 value = na_child_get_uint64 (elem_quota, "files-used", UINT64_MAX);
1861 if (value != UINT64_MAX) {
1862 submit_double (host->name, plugin_instance,
1863 /* type = */ "files", /* type instance = */ NULL,
1864 (double)value, /* timestamp = */ 0,
1865 host->cfg_quota->interval.interval);
1867 } /* for (elem_quota) */
1870 } /* }}} int cna_handle_volume_usage_data */
1872 static int cna_setup_quota (cfg_quota_t *cq) /* {{{ */
1877 if (cq->query != NULL)
1880 cq->query = na_elem_new ("quota-report");
1881 if (cq->query == NULL)
1883 ERROR ("netapp plugin: na_elem_new failed.");
1888 } /* }}} int cna_setup_quota */
1890 static int cna_query_quota (host_config_t *host) /* {{{ */
1899 /* If the user did not configure quota statistics, return without
1900 * doing anything. */
1901 if (host->cfg_quota == NULL)
1905 if ((host->cfg_quota->interval.interval + host->cfg_quota->interval.last_read) > now)
1908 status = cna_setup_quota (host->cfg_quota);
1911 assert (host->cfg_quota->query != NULL);
1913 data = na_server_invoke_elem (host->srv, host->cfg_quota->query);
1914 if (na_results_status (data) != NA_OK)
1916 ERROR ("netapp plugin: cna_query_quota: na_server_invoke_elem failed for host %s: %s",
1917 host->name, na_results_reason (data));
1918 na_elem_free (data);
1922 status = cna_handle_quota_data (host, host->cfg_quota, data);
1925 host->cfg_quota->interval.last_read = now;
1927 na_elem_free (data);
1929 } /* }}} int cna_query_quota */
1931 /* Data corresponding to <SnapVault /> */
1932 static int cna_handle_snapvault_data (const char *hostname, /* {{{ */
1933 cfg_snapvault_t *cfg_snapvault, na_elem_t *data, cdtime_t interval)
1935 na_elem_iter_t status_iter;
1937 status = na_elem_child (data, "status-list");
1939 ERROR ("netapp plugin: SnapVault status record missing status-list");
1943 status_iter = na_child_iterator (status);
1944 for (na_elem_t *status = na_iterator_next (&status_iter);
1946 status = na_iterator_next (&status_iter))
1948 const char *dest_sys, *dest_path, *src_sys, *src_path;
1949 char plugin_instance[DATA_MAX_NAME_LEN];
1952 dest_sys = na_child_get_string (status, "destination-system");
1953 dest_path = na_child_get_string (status, "destination-path");
1954 src_sys = na_child_get_string (status, "source-system");
1955 src_path = na_child_get_string (status, "source-path");
1957 if ((! dest_sys) || (! dest_path) || (! src_sys) || (! src_path))
1960 value = na_child_get_uint64 (status, "lag-time", UINT64_MAX);
1961 if (value == UINT64_MAX) /* no successful baseline transfer yet */
1964 /* possible TODO: make plugin instance configurable */
1965 ssnprintf (plugin_instance, sizeof (plugin_instance),
1966 "snapvault-%s", dest_path);
1967 submit_double (hostname, plugin_instance, /* type = */ "delay", NULL,
1968 (double)value, /* timestamp = */ 0, interval);
1970 value = na_child_get_uint64 (status, "last-transfer-duration", UINT64_MAX);
1971 if (value != UINT64_MAX)
1972 submit_double (hostname, plugin_instance, /* type = */ "duration", "last_transfer",
1973 (double)value, /* timestamp = */ 0, interval);
1975 value = na_child_get_uint64 (status, "transfer-progress", UINT64_MAX);
1976 if (value == UINT64_MAX)
1977 value = na_child_get_uint64 (status, "last-transfer-size", UINT64_MAX);
1978 if (value != UINT64_MAX) {
1979 value *= 1024; /* this is kilobytes */
1980 submit_derive (hostname, plugin_instance, /* type = */ "if_rx_octets", "transferred",
1981 value, /* timestamp = */ 0, interval);
1983 } /* for (status) */
1986 } /* }}} int cna_handle_snapvault_data */
1988 static int cna_handle_snapvault_iter (host_config_t *host, /* {{{ */
1993 uint32_t records_count;
1995 records_count = na_child_get_uint32 (data, "records", UINT32_MAX);
1996 if (records_count == UINT32_MAX)
1999 tag = na_child_get_string (data, "tag");
2003 DEBUG ("netapp plugin: Iterating %u SV records (tag = %s)", records_count, tag);
2005 for (uint32_t i = 0; i < records_count; ++i) {
2008 elem = na_server_invoke (host->srv,
2009 "snapvault-secondary-relationship-status-list-iter-next",
2010 "maximum", "1", "tag", tag, NULL);
2012 if (na_results_status (elem) != NA_OK)
2014 ERROR ("netapp plugin: cna_handle_snapvault_iter: "
2015 "na_server_invoke failed for host %s: %s",
2016 host->name, na_results_reason (data));
2017 na_elem_free (elem);
2021 cna_handle_snapvault_data (host->name, host->cfg_snapvault, elem,
2022 host->cfg_snapvault->interval.interval);
2023 na_elem_free (elem);
2026 na_elem_free (na_server_invoke (host->srv,
2027 "snapvault-secondary-relationship-status-list-iter-end",
2030 } /* }}} int cna_handle_snapvault_iter */
2032 static int cna_setup_snapvault (cfg_snapvault_t *sv) /* {{{ */
2037 if (sv->query != NULL)
2040 sv->query = na_elem_new ("snapvault-secondary-relationship-status-list-iter-start");
2041 if (sv->query == NULL)
2043 ERROR ("netapp plugin: na_elem_new failed.");
2048 } /* }}} int cna_setup_snapvault */
2050 static int cna_query_snapvault (host_config_t *host) /* {{{ */
2059 if (host->cfg_snapvault == NULL)
2063 if ((host->cfg_snapvault->interval.interval + host->cfg_snapvault->interval.last_read) > now)
2066 status = cna_setup_snapvault (host->cfg_snapvault);
2069 assert (host->cfg_snapvault->query != NULL);
2071 data = na_server_invoke_elem (host->srv, host->cfg_snapvault->query);
2072 if (na_results_status (data) != NA_OK)
2074 ERROR ("netapp plugin: cna_query_snapvault: na_server_invoke_elem failed for host %s: %s",
2075 host->name, na_results_reason (data));
2076 na_elem_free (data);
2080 status = cna_handle_snapvault_iter (host, data);
2083 host->cfg_snapvault->interval.last_read = now;
2085 na_elem_free (data);
2087 } /* }}} int cna_query_snapvault */
2089 /* Data corresponding to <System /> */
2090 static int cna_handle_system_data (const char *hostname, /* {{{ */
2091 cfg_system_t *cfg_system, na_elem_t *data, int interval)
2093 na_elem_t *instances;
2094 na_elem_iter_t counter_iter;
2096 derive_t disk_read = 0, disk_written = 0;
2097 derive_t net_recv = 0, net_sent = 0;
2098 derive_t cpu_busy = 0, cpu_total = 0;
2099 uint32_t counter_flags = 0;
2101 const char *instance;
2104 timestamp = cna_child_get_cdtime (data);
2106 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
2107 if (instances == NULL)
2109 ERROR ("netapp plugin: cna_handle_system_data: "
2110 "na_elem_child (\"instances\") failed "
2111 "for host %s.", hostname);
2115 instance = na_child_get_string (instances, "name");
2116 if (instance == NULL)
2118 ERROR ("netapp plugin: cna_handle_system_data: "
2119 "na_child_get_string (\"name\") failed "
2120 "for host %s.", hostname);
2124 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
2125 for (na_elem_t *counter = na_iterator_next (&counter_iter);
2127 counter = na_iterator_next (&counter_iter))
2132 name = na_child_get_string(counter, "name");
2136 value = na_child_get_uint64(counter, "value", UINT64_MAX);
2137 if (value == UINT64_MAX)
2140 if (!strcmp(name, "disk_data_read")) {
2141 disk_read = (derive_t) (value * 1024);
2142 counter_flags |= 0x01;
2143 } else if (!strcmp(name, "disk_data_written")) {
2144 disk_written = (derive_t) (value * 1024);
2145 counter_flags |= 0x02;
2146 } else if (!strcmp(name, "net_data_recv")) {
2147 net_recv = (derive_t) (value * 1024);
2148 counter_flags |= 0x04;
2149 } else if (!strcmp(name, "net_data_sent")) {
2150 net_sent = (derive_t) (value * 1024);
2151 counter_flags |= 0x08;
2152 } else if (!strcmp(name, "cpu_busy")) {
2153 cpu_busy = (derive_t) value;
2154 counter_flags |= 0x10;
2155 } else if (!strcmp(name, "cpu_elapsed_time")) {
2156 cpu_total = (derive_t) value;
2157 counter_flags |= 0x20;
2158 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
2159 && (value > 0) && (strlen(name) > 4)
2160 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
2161 submit_derive (hostname, instance, "disk_ops_complex", name,
2162 (derive_t) value, timestamp, interval);
2164 } /* for (counter) */
2166 if ((cfg_system->flags & CFG_SYSTEM_DISK)
2167 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
2168 submit_two_derive (hostname, instance, "disk_octets", NULL,
2169 disk_read, disk_written, timestamp, interval);
2171 if ((cfg_system->flags & CFG_SYSTEM_NET)
2172 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
2173 submit_two_derive (hostname, instance, "if_octets", NULL,
2174 net_recv, net_sent, timestamp, interval);
2176 if ((cfg_system->flags & CFG_SYSTEM_CPU)
2177 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
2179 submit_derive (hostname, instance, "cpu", "system",
2180 cpu_busy, timestamp, interval);
2181 submit_derive (hostname, instance, "cpu", "idle",
2182 cpu_total - cpu_busy, timestamp, interval);
2186 } /* }}} int cna_handle_system_data */
2188 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
2193 if (cs->query != NULL)
2196 cs->query = na_elem_new ("perf-object-get-instances");
2197 if (cs->query == NULL)
2199 ERROR ("netapp plugin: na_elem_new failed.");
2202 na_child_add_string (cs->query, "objectname", "system");
2205 } /* }}} int cna_setup_system */
2207 static int cna_query_system (host_config_t *host) /* {{{ */
2216 /* If system statistics were not configured, return without doing anything. */
2217 if (host->cfg_system == NULL)
2221 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
2224 status = cna_setup_system (host->cfg_system);
2227 assert (host->cfg_system->query != NULL);
2229 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
2230 if (na_results_status (data) != NA_OK)
2232 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed for host %s: %s",
2233 host->name, na_results_reason (data));
2234 na_elem_free (data);
2238 status = cna_handle_system_data (host->name, host->cfg_system, data,
2239 host->cfg_system->interval.interval);
2242 host->cfg_system->interval.last_read = now;
2244 na_elem_free (data);
2246 } /* }}} int cna_query_system */
2249 * Configuration handling
2251 /* Sets a given flag if the boolean argument is true and unsets the flag if it
2252 * is false. On error, the flag-field is not changed. */
2253 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
2254 uint32_t *flags, uint32_t flag)
2256 if ((ci == NULL) || (flags == NULL))
2259 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2261 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
2266 if (ci->values[0].value.boolean)
2272 } /* }}} int cna_config_bool_to_flag */
2274 /* Handling of the "Interval" option which is allowed in every block. */
2275 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
2276 cna_interval_t *out_interval)
2281 status = cf_util_get_cdtime (ci, &tmp);
2285 out_interval->interval = tmp;
2286 out_interval->last_read = 0;
2289 } /* }}} int cna_config_get_interval */
2291 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
2292 * <VolumePerf /> block. */
2293 static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
2294 const oconfig_item_t *ci)
2299 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2301 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2306 name = ci->values[0].value.string;
2308 if (strcasecmp ("GetIO", ci->key) == 0)
2309 il = cvp->il_octets;
2310 else if (strcasecmp ("GetOps", ci->key) == 0)
2311 il = cvp->il_operations;
2312 else if (strcasecmp ("GetLatency", ci->key) == 0)
2313 il = cvp->il_latency;
2317 ignorelist_add (il, name);
2318 } /* }}} void cna_config_volume_perf_option */
2320 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
2321 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
2322 static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
2323 const oconfig_item_t *ci)
2327 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2329 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2334 if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
2335 il = cvp->il_octets;
2336 else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
2337 il = cvp->il_operations;
2338 else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
2339 il = cvp->il_latency;
2343 if (ci->values[0].value.boolean)
2344 ignorelist_set_invert (il, /* invert = */ 0);
2346 ignorelist_set_invert (il, /* invert = */ 1);
2347 } /* }}} void cna_config_volume_perf_default */
2349 /* Corresponds to a <Disks /> block */
2354 * IgnoreSelectedIO false
2358 * IgnoreSelectedOps false
2362 * IgnoreSelectedLatency false
2365 /* Corresponds to a <VolumePerf /> block */
2366 static int cna_config_volume_performance (host_config_t *host, /* {{{ */
2367 const oconfig_item_t *ci)
2369 cfg_volume_perf_t *cfg_volume_perf;
2371 if ((host == NULL) || (ci == NULL))
2374 if (host->cfg_volume_perf == NULL)
2376 cfg_volume_perf = calloc (1, sizeof (*cfg_volume_perf));
2377 if (cfg_volume_perf == NULL)
2380 /* Set default flags */
2381 cfg_volume_perf->query = NULL;
2382 cfg_volume_perf->volumes = NULL;
2384 cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
2385 if (cfg_volume_perf->il_octets == NULL)
2387 sfree (cfg_volume_perf);
2391 cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
2392 if (cfg_volume_perf->il_operations == NULL)
2394 ignorelist_free (cfg_volume_perf->il_octets);
2395 sfree (cfg_volume_perf);
2399 cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
2400 if (cfg_volume_perf->il_latency == NULL)
2402 ignorelist_free (cfg_volume_perf->il_octets);
2403 ignorelist_free (cfg_volume_perf->il_operations);
2404 sfree (cfg_volume_perf);
2408 host->cfg_volume_perf = cfg_volume_perf;
2410 cfg_volume_perf = host->cfg_volume_perf;
2412 for (int i = 0; i < ci->children_num; ++i) {
2413 oconfig_item_t *item = ci->children + i;
2415 /* if (!item || !item->key || !*item->key) continue; */
2416 if (strcasecmp(item->key, "Interval") == 0)
2417 cna_config_get_interval (item, &cfg_volume_perf->interval);
2418 else if (!strcasecmp(item->key, "GetIO"))
2419 cna_config_volume_perf_option (cfg_volume_perf, item);
2420 else if (!strcasecmp(item->key, "GetOps"))
2421 cna_config_volume_perf_option (cfg_volume_perf, item);
2422 else if (!strcasecmp(item->key, "GetLatency"))
2423 cna_config_volume_perf_option (cfg_volume_perf, item);
2424 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
2425 cna_config_volume_perf_default (cfg_volume_perf, item);
2426 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
2427 cna_config_volume_perf_default (cfg_volume_perf, item);
2428 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
2429 cna_config_volume_perf_default (cfg_volume_perf, item);
2431 WARNING ("netapp plugin: The option %s is not allowed within "
2432 "`VolumePerf' blocks.", item->key);
2436 } /* }}} int cna_config_volume_performance */
2438 /* Handling of the "GetCapacity" and "GetSnapshot" options within a
2439 * <VolumeUsage /> block. */
2440 static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
2441 const oconfig_item_t *ci)
2446 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2448 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2453 name = ci->values[0].value.string;
2455 if (strcasecmp ("GetCapacity", ci->key) == 0)
2456 il = cvu->il_capacity;
2457 else if (strcasecmp ("GetSnapshot", ci->key) == 0)
2458 il = cvu->il_snapshot;
2462 ignorelist_add (il, name);
2463 } /* }}} void cna_config_volume_usage_option */
2465 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
2466 * options within a <VolumeUsage /> block. */
2467 static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
2468 const oconfig_item_t *ci)
2472 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2474 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2479 if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
2480 il = cvu->il_capacity;
2481 else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
2482 il = cvu->il_snapshot;
2486 if (ci->values[0].value.boolean)
2487 ignorelist_set_invert (il, /* invert = */ 0);
2489 ignorelist_set_invert (il, /* invert = */ 1);
2490 } /* }}} void cna_config_volume_usage_default */
2492 /* Corresponds to a <Quota /> block */
2493 static int cna_config_quota (host_config_t *host, oconfig_item_t *ci) /* {{{ */
2495 cfg_quota_t *cfg_quota;
2497 if ((host == NULL) || (ci == NULL))
2500 if (host->cfg_quota == NULL)
2502 cfg_quota = calloc (1, sizeof (*cfg_quota));
2503 if (cfg_quota == NULL)
2505 cfg_quota->query = NULL;
2507 host->cfg_quota = cfg_quota;
2509 cfg_quota = host->cfg_quota;
2511 for (int i = 0; i < ci->children_num; ++i) {
2512 oconfig_item_t *item = ci->children + i;
2514 if (strcasecmp (item->key, "Interval") == 0)
2515 cna_config_get_interval (item, &cfg_quota->interval);
2517 WARNING ("netapp plugin: The option %s is not allowed within "
2518 "`Quota' blocks.", item->key);
2522 } /* }}} int cna_config_quota */
2524 /* Corresponds to a <Disks /> block */
2525 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
2526 cfg_disk_t *cfg_disk;
2528 if ((host == NULL) || (ci == NULL))
2531 if (host->cfg_disk == NULL)
2533 cfg_disk = calloc (1, sizeof (*cfg_disk));
2534 if (cfg_disk == NULL)
2537 /* Set default flags */
2538 cfg_disk->flags = CFG_DISK_ALL;
2539 cfg_disk->query = NULL;
2540 cfg_disk->disks = NULL;
2542 host->cfg_disk = cfg_disk;
2544 cfg_disk = host->cfg_disk;
2546 for (int i = 0; i < ci->children_num; ++i) {
2547 oconfig_item_t *item = ci->children + i;
2549 /* if (!item || !item->key || !*item->key) continue; */
2550 if (strcasecmp(item->key, "Interval") == 0)
2551 cna_config_get_interval (item, &cfg_disk->interval);
2552 else if (strcasecmp(item->key, "GetBusy") == 0)
2553 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2556 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
2558 NOTICE ("netapp plugin: All disk related values have been disabled. "
2559 "Collection of per-disk data will be disabled entirely.");
2560 free_cfg_disk (host->cfg_disk);
2561 host->cfg_disk = NULL;
2565 } /* }}} int cna_config_disk */
2567 /* Corresponds to a <WAFL /> block */
2568 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2570 cfg_wafl_t *cfg_wafl;
2572 if ((host == NULL) || (ci == NULL))
2575 if (host->cfg_wafl == NULL)
2577 cfg_wafl = calloc (1, sizeof (*cfg_wafl));
2578 if (cfg_wafl == NULL)
2581 /* Set default flags */
2582 cfg_wafl->flags = CFG_WAFL_ALL;
2584 host->cfg_wafl = cfg_wafl;
2586 cfg_wafl = host->cfg_wafl;
2588 for (int i = 0; i < ci->children_num; ++i) {
2589 oconfig_item_t *item = ci->children + i;
2591 if (strcasecmp(item->key, "Interval") == 0)
2592 cna_config_get_interval (item, &cfg_wafl->interval);
2593 else if (!strcasecmp(item->key, "GetNameCache"))
2594 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2595 else if (!strcasecmp(item->key, "GetDirCache"))
2596 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2597 else if (!strcasecmp(item->key, "GetBufferCache"))
2598 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2599 else if (!strcasecmp(item->key, "GetInodeCache"))
2600 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2602 WARNING ("netapp plugin: The %s config option is not allowed within "
2603 "`WAFL' blocks.", item->key);
2606 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
2608 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
2609 "Collection of WAFL data will be disabled entirely.");
2610 free_cfg_wafl (host->cfg_wafl);
2611 host->cfg_wafl = NULL;
2615 } /* }}} int cna_config_wafl */
2619 * GetCapacity "vol0"
2620 * GetCapacity "vol1"
2621 * GetCapacity "vol2"
2622 * GetCapacity "vol3"
2623 * GetCapacity "vol4"
2624 * IgnoreSelectedCapacity false
2626 * GetSnapshot "vol0"
2627 * GetSnapshot "vol3"
2628 * GetSnapshot "vol4"
2629 * GetSnapshot "vol7"
2630 * IgnoreSelectedSnapshot false
2633 /* Corresponds to a <VolumeUsage /> block */
2634 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2635 const oconfig_item_t *ci)
2637 cfg_volume_usage_t *cfg_volume_usage;
2639 if ((host == NULL) || (ci == NULL))
2642 if (host->cfg_volume_usage == NULL)
2644 cfg_volume_usage = calloc (1, sizeof (*cfg_volume_usage));
2645 if (cfg_volume_usage == NULL)
2648 /* Set default flags */
2649 cfg_volume_usage->query = NULL;
2650 cfg_volume_usage->volumes = NULL;
2652 cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
2653 if (cfg_volume_usage->il_capacity == NULL)
2655 sfree (cfg_volume_usage);
2659 cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
2660 if (cfg_volume_usage->il_snapshot == NULL)
2662 ignorelist_free (cfg_volume_usage->il_capacity);
2663 sfree (cfg_volume_usage);
2667 host->cfg_volume_usage = cfg_volume_usage;
2669 cfg_volume_usage = host->cfg_volume_usage;
2671 for (int i = 0; i < ci->children_num; ++i) {
2672 oconfig_item_t *item = ci->children + i;
2674 /* if (!item || !item->key || !*item->key) continue; */
2675 if (strcasecmp(item->key, "Interval") == 0)
2676 cna_config_get_interval (item, &cfg_volume_usage->interval);
2677 else if (!strcasecmp(item->key, "GetCapacity"))
2678 cna_config_volume_usage_option (cfg_volume_usage, item);
2679 else if (!strcasecmp(item->key, "GetSnapshot"))
2680 cna_config_volume_usage_option (cfg_volume_usage, item);
2681 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2682 cna_config_volume_usage_default (cfg_volume_usage, item);
2683 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2684 cna_config_volume_usage_default (cfg_volume_usage, item);
2686 WARNING ("netapp plugin: The option %s is not allowed within "
2687 "`VolumeUsage' blocks.", item->key);
2691 } /* }}} int cna_config_volume_usage */
2693 /* Corresponds to a <SnapVault /> block */
2694 static int cna_config_snapvault (host_config_t *host, /* {{{ */
2695 const oconfig_item_t *ci)
2697 cfg_snapvault_t *cfg_snapvault;
2699 if ((host == NULL) || (ci == NULL))
2702 if (host->cfg_snapvault == NULL)
2704 cfg_snapvault = calloc (1, sizeof (*cfg_snapvault));
2705 if (cfg_snapvault == NULL)
2707 cfg_snapvault->query = NULL;
2709 host->cfg_snapvault = cfg_snapvault;
2712 cfg_snapvault = host->cfg_snapvault;
2714 for (int i = 0; i < ci->children_num; ++i) {
2715 oconfig_item_t *item = ci->children + i;
2717 if (strcasecmp (item->key, "Interval") == 0)
2718 cna_config_get_interval (item, &cfg_snapvault->interval);
2720 WARNING ("netapp plugin: The option %s is not allowed within "
2721 "`SnapVault' blocks.", item->key);
2725 } /* }}} int cna_config_snapvault */
2727 /* Corresponds to a <System /> block */
2728 static int cna_config_system (host_config_t *host, /* {{{ */
2731 cfg_system_t *cfg_system;
2733 if ((host == NULL) || (ci == NULL))
2736 if (host->cfg_system == NULL)
2738 cfg_system = calloc (1, sizeof (*cfg_system));
2739 if (cfg_system == NULL)
2742 /* Set default flags */
2743 cfg_system->flags = CFG_SYSTEM_ALL;
2744 cfg_system->query = NULL;
2746 host->cfg_system = cfg_system;
2748 cfg_system = host->cfg_system;
2750 for (int i = 0; i < ci->children_num; ++i) {
2751 oconfig_item_t *item = ci->children + i;
2753 if (strcasecmp(item->key, "Interval") == 0) {
2754 cna_config_get_interval (item, &cfg_system->interval);
2755 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2756 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
2757 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2758 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
2759 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2760 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
2761 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2762 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
2764 WARNING ("netapp plugin: The %s config option is not allowed within "
2765 "`System' blocks.", item->key);
2769 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
2771 NOTICE ("netapp plugin: All system related values have been disabled. "
2772 "Collection of system data will be disabled entirely.");
2773 free_cfg_system (host->cfg_system);
2774 host->cfg_system = NULL;
2778 } /* }}} int cna_config_system */
2780 /* Corresponds to a <Host /> block. */
2781 static host_config_t *cna_alloc_host (void) /* {{{ */
2783 host_config_t *host;
2785 host = calloc (1, sizeof (*host));
2790 host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2792 host->username = NULL;
2793 host->password = NULL;
2794 host->vfiler = NULL;
2796 host->cfg_wafl = NULL;
2797 host->cfg_disk = NULL;
2798 host->cfg_volume_perf = NULL;
2799 host->cfg_volume_usage = NULL;
2800 host->cfg_quota = NULL;
2801 host->cfg_snapvault = NULL;
2802 host->cfg_system = NULL;
2805 } /* }}} host_config_t *cna_alloc_host */
2807 static host_config_t *cna_shallow_clone_host (host_config_t *host) /* {{{ */
2809 host_config_t *clone;
2814 clone = cna_alloc_host ();
2818 if (host->name != NULL) {
2819 clone->name = strdup (host->name);
2820 if (clone->name == NULL) {
2821 free_host_config (clone);
2826 clone->protocol = host->protocol;
2828 if (host->host != NULL) {
2829 clone->host = strdup (host->host);
2830 if (clone->host == NULL) {
2831 free_host_config (clone);
2836 clone->port = host->port;
2838 if (host->username != NULL) {
2839 clone->username = strdup (host->username);
2840 if (clone->username == NULL) {
2841 free_host_config (clone);
2845 if (host->password != NULL) {
2846 clone->password = strdup (host->password);
2847 if (clone->password == NULL) {
2848 free_host_config (clone);
2853 clone->interval = host->interval;
2856 } /* }}} host_config_t *cna_shallow_clone_host */
2858 static int cna_read (user_data_t *ud);
2860 static int cna_register_host (host_config_t *host) /* {{{ */
2865 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s-%s",
2866 host->name, host->vfiler);
2868 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name);
2870 plugin_register_complex_read (/* group = */ NULL, cb_name,
2871 /* callback = */ cna_read,
2872 /* interval = */ host->interval,
2875 .free_func = (void *) free_host_config,
2879 } /* }}} int cna_register_host */
2881 static int cna_config_host (host_config_t *host, /* {{{ */
2882 const oconfig_item_t *ci)
2884 oconfig_item_t *item;
2885 _Bool is_vfiler = 0;
2888 if (! strcasecmp (ci->key, "VFiler"))
2891 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2892 WARNING ("netapp plugin: \"%s\" needs exactly one string argument. Ignoring host block.", ci->key);
2896 status = cf_util_get_string (ci, &host->name);
2900 for (int i = 0; i < ci->children_num; ++i) {
2901 item = ci->children + i;
2905 if (!strcasecmp(item->key, "Address")) {
2906 status = cf_util_get_string (item, &host->host);
2907 } else if (!strcasecmp(item->key, "Port")) {
2910 tmp = cf_util_get_port_number (item);
2913 } else if (!strcasecmp(item->key, "Protocol")) {
2914 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"))) {
2915 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
2918 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
2919 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2920 } else if (!strcasecmp(item->key, "User")) {
2921 status = cf_util_get_string (item, &host->username);
2922 } else if (!strcasecmp(item->key, "Password")) {
2923 status = cf_util_get_string (item, &host->password);
2924 } else if (!strcasecmp(item->key, "Interval")) {
2925 status = cf_util_get_cdtime (item, &host->interval);
2926 } else if (!strcasecmp(item->key, "WAFL")) {
2927 cna_config_wafl(host, item);
2928 } else if (!strcasecmp(item->key, "Disks")) {
2929 cna_config_disk(host, item);
2930 } else if (!strcasecmp(item->key, "VolumePerf")) {
2931 cna_config_volume_performance(host, item);
2932 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2933 cna_config_volume_usage(host, item);
2934 } else if (!strcasecmp(item->key, "Quota")) {
2935 cna_config_quota(host, item);
2936 } else if (!strcasecmp(item->key, "SnapVault")) {
2937 cna_config_snapvault(host, item);
2938 } else if (!strcasecmp(item->key, "System")) {
2939 cna_config_system(host, item);
2940 } else if ((!strcasecmp(item->key, "VFiler")) && (! is_vfiler)) {
2941 host_config_t *vfiler;
2943 vfiler = cna_shallow_clone_host (host);
2945 ERROR ("netapp plugin: Failed to allocate host object for vfiler.");
2949 if (cna_config_host (vfiler, item)) {
2950 free_host_config (vfiler);
2954 cna_register_host (vfiler);
2955 } else if ((!strcasecmp(item->key, "VFilerName")) && is_vfiler) {
2956 status = cf_util_get_string (item, &host->vfiler);
2958 WARNING ("netapp plugin: Ignoring unknown config option \"%s\" in %s block \"%s\".",
2959 item->key, is_vfiler ? "vfiler" : "host", ci->values[0].value.string);
2966 if (host->host == NULL)
2967 host->host = strdup (host->name);
2969 if (is_vfiler && (! host->vfiler))
2970 host->vfiler = strdup (host->name);
2972 if (host->host == NULL)
2975 if (host->port <= 0)
2976 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
2978 if ((host->username == NULL) || (host->password == NULL)) {
2979 WARNING("netapp plugin: Please supply login information for host \"%s\". "
2980 "Ignoring host block.", host->name);
2988 } /* }}} host_config_t *cna_config_host */
2991 * Callbacks registered with the daemon
2993 * Pretty standard stuff here.
2995 static int cna_init_host (host_config_t *host) /* {{{ */
2997 /* Request version 1.1 of the ONTAP API */
2998 int major_version = 1, minor_version = 1;
3003 if (host->srv != NULL)
3006 if (host->vfiler != NULL) /* Request version 1.7 of the ONTAP API */
3009 host->srv = na_server_open (host->host, major_version, minor_version);
3010 if (host->srv == NULL) {
3011 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
3015 na_server_set_transport_type(host->srv, host->protocol,
3016 /* transportarg = */ NULL);
3017 na_server_set_port(host->srv, host->port);
3018 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
3019 na_server_adminuser(host->srv, host->username, host->password);
3020 na_server_set_timeout(host->srv, 5 /* seconds */);
3022 if (host->vfiler != NULL) {
3023 if (! na_server_set_vfiler (host->srv, host->vfiler)) {
3024 ERROR ("netapp plugin: Failed to connect to VFiler '%s' on host '%s'.",
3025 host->vfiler, host->host);
3029 INFO ("netapp plugin: Connected to VFiler '%s' on host '%s'.",
3030 host->vfiler, host->host);
3035 } /* }}} int cna_init_host */
3037 static int cna_init (void) /* {{{ */
3039 char err[256] = { 0 };
3041 if (!na_startup(err, sizeof(err))) {
3042 err[sizeof (err) - 1] = 0;
3043 ERROR("netapp plugin: Error initializing netapp API: %s", err);
3048 } /* }}} cna_init */
3050 static int cna_read_internal (host_config_t *host) { /* {{{ */
3053 status = cna_query_wafl (host);
3057 status = cna_query_disk (host);
3061 status = cna_query_volume_perf (host);
3065 status = cna_query_volume_usage (host);
3069 status = cna_query_quota (host);
3073 status = cna_query_snapvault (host);
3077 status = cna_query_system (host);
3082 } /* }}} int cna_read_internal */
3084 static int cna_read (user_data_t *ud) { /* {{{ */
3085 host_config_t *host;
3088 if ((ud == NULL) || (ud->data == NULL))
3093 status = cna_init_host (host);
3097 status = cna_read_internal (host);
3100 if (host->srv != NULL)
3101 na_server_close (host->srv);
3106 } /* }}} int cna_read */
3108 static int cna_config (oconfig_item_t *ci) { /* {{{ */
3109 oconfig_item_t *item;
3111 for (int i = 0; i < ci->children_num; ++i) {
3112 item = ci->children + i;
3114 if (strcasecmp(item->key, "Host") == 0)
3116 host_config_t *host;
3118 host = cna_alloc_host ();
3120 ERROR ("netapp plugin: Failed to allocate host object.");
3124 if (cna_config_host (host, item) != 0) {
3125 free_host_config (host);
3129 cna_register_host (host);
3131 else /* if (item->key != "Host") */
3133 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
3137 } /* }}} int cna_config */
3139 static int cna_shutdown (void) /* {{{ */
3141 /* Clean up system resources and stuff. */
3145 } /* }}} int cna_shutdown */
3147 void module_register(void) {
3148 plugin_register_complex_config("netapp", cna_config);
3149 plugin_register_init("netapp", cna_init);
3150 plugin_register_shutdown("netapp", cna_shutdown);
3153 /* vim: set sw=2 ts=2 noet fdm=marker : */