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, int 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)
654 values[0].derive = val0;
655 values[1].derive = val1;
657 return (submit_values (host, plugin_inst, type, type_inst,
658 values, 2, 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)
669 return (submit_values (host, plugin_inst, type, type_inst,
670 &v, 1, timestamp, interval));
671 } /* }}} int submit_derive */
673 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
674 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
675 cdtime_t timestamp, cdtime_t interval)
679 values[0].gauge = val0;
680 values[1].gauge = val1;
682 return (submit_values (host, plugin_inst, type, type_inst,
683 values, 2, timestamp, interval));
684 } /* }}} int submit_two_gauge */
686 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
687 const char *type, const char *type_inst, double d,
688 cdtime_t timestamp, cdtime_t interval)
692 v.gauge = (gauge_t) d;
694 return (submit_values (host, plugin_inst, type, type_inst,
695 &v, 1, timestamp, interval));
696 } /* }}} int submit_uint64 */
698 /* Calculate hit ratio from old and new counters and submit the resulting
699 * percentage. Used by "submit_wafl_data". */
700 static int submit_cache_ratio (const char *host, /* {{{ */
701 const char *plugin_inst,
702 const char *type_inst,
712 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
716 hits = new_hits - old_hits;
717 misses = new_misses - old_misses;
719 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
724 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
725 &v, 1, timestamp, interval));
726 } /* }}} int submit_cache_ratio */
728 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
729 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
730 cfg_wafl_t *old_data, const cfg_wafl_t *new_data, cdtime_t interval)
732 /* Submit requested counters */
733 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
734 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
735 submit_cache_ratio (hostname, instance, "name_cache_hit",
736 new_data->name_cache_hit, new_data->name_cache_miss,
737 old_data->name_cache_hit, old_data->name_cache_miss,
738 new_data->timestamp, interval);
740 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
741 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
742 submit_cache_ratio (hostname, instance, "find_dir_hit",
743 new_data->find_dir_hit, new_data->find_dir_miss,
744 old_data->find_dir_hit, old_data->find_dir_miss,
745 new_data->timestamp, interval);
747 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
748 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
749 submit_cache_ratio (hostname, instance, "buf_hash_hit",
750 new_data->buf_hash_hit, new_data->buf_hash_miss,
751 old_data->buf_hash_hit, old_data->buf_hash_miss,
752 new_data->timestamp, interval);
754 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
755 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
756 submit_cache_ratio (hostname, instance, "inode_cache_hit",
757 new_data->inode_cache_hit, new_data->inode_cache_miss,
758 old_data->inode_cache_hit, old_data->inode_cache_miss,
759 new_data->timestamp, interval);
761 /* Clear old HAVE_* flags */
762 old_data->flags &= ~HAVE_WAFL_ALL;
764 /* Copy all counters */
765 old_data->timestamp = new_data->timestamp;
766 old_data->name_cache_hit = new_data->name_cache_hit;
767 old_data->name_cache_miss = new_data->name_cache_miss;
768 old_data->find_dir_hit = new_data->find_dir_hit;
769 old_data->find_dir_miss = new_data->find_dir_miss;
770 old_data->buf_hash_hit = new_data->buf_hash_hit;
771 old_data->buf_hash_miss = new_data->buf_hash_miss;
772 old_data->inode_cache_hit = new_data->inode_cache_hit;
773 old_data->inode_cache_miss = new_data->inode_cache_miss;
775 /* Copy HAVE_* flags */
776 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
779 } /* }}} int submit_wafl_data */
781 /* Submits volume performance data to the daemon, taking care to honor and
782 * update flags appropriately. */
783 static int submit_volume_perf_data (const char *hostname, /* {{{ */
784 data_volume_perf_t *old_data,
785 const data_volume_perf_t *new_data, int interval)
787 char plugin_instance[DATA_MAX_NAME_LEN];
789 if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL))
792 ssnprintf (plugin_instance, sizeof (plugin_instance),
793 "volume-%s", old_data->name);
795 /* Check for and submit disk-octet values */
796 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_IO)
797 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
799 submit_two_derive (hostname, plugin_instance, "disk_octets", /* type instance = */ NULL,
800 (derive_t) new_data->read_bytes, (derive_t) new_data->write_bytes, new_data->timestamp, interval);
803 /* Check for and submit disk-operations values */
804 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_OPS)
805 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
807 submit_two_derive (hostname, plugin_instance, "disk_ops", /* type instance = */ NULL,
808 (derive_t) new_data->read_ops, (derive_t) new_data->write_ops, new_data->timestamp, interval);
811 /* Check for, calculate and submit disk-latency values */
812 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_LATENCY
813 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
814 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
815 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
816 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
818 gauge_t latency_per_op_read;
819 gauge_t latency_per_op_write;
821 latency_per_op_read = NAN;
822 latency_per_op_write = NAN;
824 /* Check if a counter wrapped around. */
825 if ((new_data->read_ops > old_data->read_ops)
826 && (new_data->read_latency > old_data->read_latency))
828 uint64_t diff_ops_read;
829 uint64_t diff_latency_read;
831 diff_ops_read = new_data->read_ops - old_data->read_ops;
832 diff_latency_read = new_data->read_latency - old_data->read_latency;
834 if (diff_ops_read > 0)
835 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
838 if ((new_data->write_ops > old_data->write_ops)
839 && (new_data->write_latency > old_data->write_latency))
841 uint64_t diff_ops_write;
842 uint64_t diff_latency_write;
844 diff_ops_write = new_data->write_ops - old_data->write_ops;
845 diff_latency_write = new_data->write_latency - old_data->write_latency;
847 if (diff_ops_write > 0)
848 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
851 submit_two_gauge (hostname, plugin_instance, "disk_latency", /* type instance = */ NULL,
852 latency_per_op_read, latency_per_op_write, new_data->timestamp, interval);
855 /* Clear all HAVE_* flags. */
856 old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
858 /* Copy all counters */
859 old_data->timestamp = new_data->timestamp;
860 old_data->read_bytes = new_data->read_bytes;
861 old_data->write_bytes = new_data->write_bytes;
862 old_data->read_ops = new_data->read_ops;
863 old_data->write_ops = new_data->write_ops;
864 old_data->read_latency = new_data->read_latency;
865 old_data->write_latency = new_data->write_latency;
867 /* Copy the HAVE_* flags */
868 old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
871 } /* }}} int submit_volume_perf_data */
873 static cdtime_t cna_child_get_cdtime (na_elem_t *data) /* {{{ */
877 t = (time_t) na_child_get_uint64 (data, "timestamp", /* default = */ 0);
879 return (TIME_T_TO_CDTIME_T (t));
880 } /* }}} cdtime_t cna_child_get_cdtime */
886 * These functions are called with appropriate data returned by the libnetapp
887 * interface which is parsed and submitted with the above functions.
889 /* Data corresponding to <WAFL /> */
890 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
891 na_elem_t *data, cdtime_t interval)
893 cfg_wafl_t perf_data = { 0 };
894 const char *plugin_inst;
896 na_elem_t *instances;
897 na_elem_iter_t counter_iter;
899 perf_data.timestamp = cna_child_get_cdtime (data);
901 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
902 if (instances == NULL)
904 ERROR ("netapp plugin: cna_handle_wafl_data: "
905 "na_elem_child (\"instances\") failed "
906 "for host %s.", hostname);
910 plugin_inst = na_child_get_string(instances, "name");
911 if (plugin_inst == NULL)
913 ERROR ("netapp plugin: cna_handle_wafl_data: "
914 "na_child_get_string (\"name\") failed "
915 "for host %s.", hostname);
919 /* Iterate over all counters */
920 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
921 for (na_elem_t *counter = na_iterator_next (&counter_iter);
923 counter = na_iterator_next (&counter_iter))
928 name = na_child_get_string(counter, "name");
932 value = na_child_get_uint64(counter, "value", UINT64_MAX);
933 if (value == UINT64_MAX)
936 if (!strcmp(name, "name_cache_hit")) {
937 perf_data.name_cache_hit = value;
938 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
939 } else if (!strcmp(name, "name_cache_miss")) {
940 perf_data.name_cache_miss = value;
941 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
942 } else if (!strcmp(name, "find_dir_hit")) {
943 perf_data.find_dir_hit = value;
944 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
945 } else if (!strcmp(name, "find_dir_miss")) {
946 perf_data.find_dir_miss = value;
947 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
948 } else if (!strcmp(name, "buf_hash_hit")) {
949 perf_data.buf_hash_hit = value;
950 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
951 } else if (!strcmp(name, "buf_hash_miss")) {
952 perf_data.buf_hash_miss = value;
953 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
954 } else if (!strcmp(name, "inode_cache_hit")) {
955 perf_data.inode_cache_hit = value;
956 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
957 } else if (!strcmp(name, "inode_cache_miss")) {
958 perf_data.inode_cache_miss = value;
959 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
961 DEBUG("netapp plugin: cna_handle_wafl_data: "
962 "Found unexpected child: %s "
963 "for host %s.", name, hostname);
967 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data, interval));
968 } /* }}} void cna_handle_wafl_data */
970 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
977 if (cw->query != NULL)
980 cw->query = na_elem_new("perf-object-get-instances");
981 if (cw->query == NULL)
983 ERROR ("netapp plugin: na_elem_new failed.");
986 na_child_add_string (cw->query, "objectname", "wafl");
988 e = na_elem_new("counters");
991 na_elem_free (cw->query);
993 ERROR ("netapp plugin: na_elem_new failed.");
996 na_child_add_string(e, "counter", "name_cache_hit");
997 na_child_add_string(e, "counter", "name_cache_miss");
998 na_child_add_string(e, "counter", "find_dir_hit");
999 na_child_add_string(e, "counter", "find_dir_miss");
1000 na_child_add_string(e, "counter", "buf_hash_hit");
1001 na_child_add_string(e, "counter", "buf_hash_miss");
1002 na_child_add_string(e, "counter", "inode_cache_hit");
1003 na_child_add_string(e, "counter", "inode_cache_miss");
1005 na_child_add(cw->query, e);
1008 } /* }}} int cna_setup_wafl */
1010 static int cna_query_wafl (host_config_t *host) /* {{{ */
1019 /* If WAFL was not configured, return without doing anything. */
1020 if (host->cfg_wafl == NULL)
1024 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
1027 status = cna_setup_wafl (host->cfg_wafl);
1030 assert (host->cfg_wafl->query != NULL);
1032 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
1033 if (na_results_status (data) != NA_OK)
1035 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed for host %s: %s",
1036 host->name, na_results_reason (data));
1037 na_elem_free (data);
1041 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data,
1042 host->cfg_wafl->interval.interval);
1045 host->cfg_wafl->interval.last_read = now;
1047 na_elem_free (data);
1049 } /* }}} int cna_query_wafl */
1051 /* Data corresponding to <Disks /> */
1052 static int cna_handle_disk_data (const char *hostname, /* {{{ */
1053 cfg_disk_t *cfg_disk, na_elem_t *data, cdtime_t interval)
1056 na_elem_t *instances;
1057 na_elem_iter_t instance_iter;
1058 disk_t *worst_disk = NULL;
1060 if ((cfg_disk == NULL) || (data == NULL))
1063 timestamp = cna_child_get_cdtime (data);
1065 instances = na_elem_child (data, "instances");
1066 if (instances == NULL)
1068 ERROR ("netapp plugin: cna_handle_disk_data: "
1069 "na_elem_child (\"instances\") failed "
1070 "for host %s.", hostname);
1074 /* Iterate over all children */
1075 instance_iter = na_child_iterator (instances);
1076 for (na_elem_t *instance = na_iterator_next (&instance_iter);
1078 instance = na_iterator_next(&instance_iter))
1081 disk_t new_data = { 0 };
1083 na_elem_iter_t counter_iterator;
1085 new_data.timestamp = timestamp;
1086 new_data.disk_busy_percent = NAN;
1088 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
1089 if (old_data == NULL)
1092 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
1093 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
1094 for (na_elem_t *counter = na_iterator_next(&counter_iterator);
1096 counter = na_iterator_next(&counter_iterator))
1101 name = na_child_get_string(counter, "name");
1105 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1106 if (value == UINT64_MAX)
1109 if (strcmp(name, "disk_busy") == 0)
1111 new_data.disk_busy = value;
1112 new_data.flags |= HAVE_DISK_BUSY;
1114 else if (strcmp(name, "base_for_disk_busy") == 0)
1116 new_data.base_for_disk_busy = value;
1117 new_data.flags |= HAVE_DISK_BASE;
1121 DEBUG ("netapp plugin: cna_handle_disk_data: "
1122 "Counter not handled: %s = %"PRIu64,
1127 /* If all required counters are available and did not just wrap around,
1128 * calculate the busy percentage. Otherwise, the value is initialized to
1129 * NAN at the top of the for-loop. */
1130 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1131 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1132 && (new_data.disk_busy >= old_data->disk_busy)
1133 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
1138 busy_diff = new_data.disk_busy - old_data->disk_busy;
1139 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
1141 new_data.disk_busy_percent = 100.0
1142 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
1145 /* Clear HAVE_* flags */
1146 old_data->flags &= ~HAVE_DISK_ALL;
1149 old_data->timestamp = new_data.timestamp;
1150 old_data->disk_busy = new_data.disk_busy;
1151 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
1152 old_data->disk_busy_percent = new_data.disk_busy_percent;
1155 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
1157 if ((worst_disk == NULL)
1158 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
1159 worst_disk = old_data;
1160 } /* for (all disks) */
1162 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
1163 submit_double (hostname, "system", "percent", "disk_busy",
1164 worst_disk->disk_busy_percent, timestamp, interval);
1167 } /* }}} int cna_handle_disk_data */
1169 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
1176 if (cd->query != NULL)
1179 cd->query = na_elem_new ("perf-object-get-instances");
1180 if (cd->query == NULL)
1182 ERROR ("netapp plugin: na_elem_new failed.");
1185 na_child_add_string (cd->query, "objectname", "disk");
1187 e = na_elem_new("counters");
1190 na_elem_free (cd->query);
1192 ERROR ("netapp plugin: na_elem_new failed.");
1195 na_child_add_string(e, "counter", "disk_busy");
1196 na_child_add_string(e, "counter", "base_for_disk_busy");
1197 na_child_add(cd->query, e);
1200 } /* }}} int cna_setup_disk */
1202 static int cna_query_disk (host_config_t *host) /* {{{ */
1211 /* If the user did not configure disk statistics, return without doing
1213 if (host->cfg_disk == NULL)
1217 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1220 status = cna_setup_disk (host->cfg_disk);
1223 assert (host->cfg_disk->query != NULL);
1225 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1226 if (na_results_status (data) != NA_OK)
1228 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed for host %s: %s",
1229 host->name, na_results_reason (data));
1230 na_elem_free (data);
1234 status = cna_handle_disk_data (host->name, host->cfg_disk, data,
1235 host->cfg_disk->interval.interval);
1238 host->cfg_disk->interval.last_read = now;
1240 na_elem_free (data);
1242 } /* }}} int cna_query_disk */
1244 /* Data corresponding to <VolumePerf /> */
1245 static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
1246 cfg_volume_perf_t *cvp, na_elem_t *data, cdtime_t interval)
1249 na_elem_t *elem_instances;
1250 na_elem_iter_t iter_instances;
1252 timestamp = cna_child_get_cdtime (data);
1254 elem_instances = na_elem_child(data, "instances");
1255 if (elem_instances == NULL)
1257 ERROR ("netapp plugin: handle_volume_perf_data: "
1258 "na_elem_child (\"instances\") failed "
1259 "for host %s.", hostname);
1263 iter_instances = na_child_iterator (elem_instances);
1264 for (na_elem_t *elem_instance = na_iterator_next(&iter_instances);
1265 elem_instance != NULL;
1266 elem_instance = na_iterator_next(&iter_instances))
1270 data_volume_perf_t perf_data = { 0 };
1271 data_volume_perf_t *v;
1273 na_elem_t *elem_counters;
1274 na_elem_iter_t iter_counters;
1276 perf_data.timestamp = timestamp;
1278 name = na_child_get_string (elem_instance, "name");
1282 /* get_volume_perf may return NULL if this volume is to be ignored. */
1283 v = get_volume_perf (cvp, name);
1287 elem_counters = na_elem_child (elem_instance, "counters");
1288 if (elem_counters == NULL)
1291 iter_counters = na_child_iterator (elem_counters);
1292 for (na_elem_t *elem_counter = na_iterator_next(&iter_counters);
1293 elem_counter != NULL;
1294 elem_counter = na_iterator_next(&iter_counters))
1299 name = na_child_get_string (elem_counter, "name");
1303 value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
1304 if (value == UINT64_MAX)
1307 if (!strcmp(name, "read_data")) {
1308 perf_data.read_bytes = value;
1309 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1310 } else if (!strcmp(name, "write_data")) {
1311 perf_data.write_bytes = value;
1312 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1313 } else if (!strcmp(name, "read_ops")) {
1314 perf_data.read_ops = value;
1315 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1316 } else if (!strcmp(name, "write_ops")) {
1317 perf_data.write_ops = value;
1318 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1319 } else if (!strcmp(name, "read_latency")) {
1320 perf_data.read_latency = value;
1321 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1322 } else if (!strcmp(name, "write_latency")) {
1323 perf_data.write_latency = value;
1324 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1326 } /* for (elem_counter) */
1328 submit_volume_perf_data (hostname, v, &perf_data, interval);
1329 } /* for (volume) */
1332 } /* }}} int cna_handle_volume_perf_data */
1334 static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
1341 if (cd->query != NULL)
1344 cd->query = na_elem_new ("perf-object-get-instances");
1345 if (cd->query == NULL)
1347 ERROR ("netapp plugin: na_elem_new failed.");
1350 na_child_add_string (cd->query, "objectname", "volume");
1352 e = na_elem_new("counters");
1355 na_elem_free (cd->query);
1357 ERROR ("netapp plugin: na_elem_new failed.");
1360 na_child_add_string(e, "counter", "read_ops");
1361 na_child_add_string(e, "counter", "write_ops");
1362 na_child_add_string(e, "counter", "read_data");
1363 na_child_add_string(e, "counter", "write_data");
1364 na_child_add_string(e, "counter", "read_latency");
1365 na_child_add_string(e, "counter", "write_latency");
1366 na_child_add(cd->query, e);
1369 } /* }}} int cna_setup_volume_perf */
1371 static int cna_query_volume_perf (host_config_t *host) /* {{{ */
1380 /* If the user did not configure volume performance statistics, return
1381 * without doing anything. */
1382 if (host->cfg_volume_perf == NULL)
1386 if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
1389 status = cna_setup_volume_perf (host->cfg_volume_perf);
1392 assert (host->cfg_volume_perf->query != NULL);
1394 data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
1395 if (na_results_status (data) != NA_OK)
1397 ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed for host %s: %s",
1398 host->name, na_results_reason (data));
1399 na_elem_free (data);
1403 status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data,
1404 host->cfg_volume_perf->interval.interval);
1407 host->cfg_volume_perf->interval.last_read = now;
1409 na_elem_free (data);
1411 } /* }}} int cna_query_volume_perf */
1413 /* Data corresponding to <VolumeUsage /> */
1414 static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
1415 cfg_volume_usage_t *cfg_volume, int interval)
1417 for (data_volume_usage_t *v = cfg_volume->volumes; v != NULL; v = v->next)
1419 char plugin_instance[DATA_MAX_NAME_LEN];
1421 uint64_t norm_used = v->norm_used;
1422 uint64_t norm_free = v->norm_free;
1423 uint64_t sis_saved = v->sis_saved;
1424 uint64_t compress_saved = v->compress_saved;
1425 uint64_t dedup_saved = v->dedup_saved;
1426 uint64_t snap_reserve_used = 0;
1427 uint64_t snap_reserve_free = v->snap_reserved;
1428 uint64_t snap_norm_used = v->snap_used;
1430 ssnprintf (plugin_instance, sizeof (plugin_instance),
1431 "volume-%s", v->name);
1433 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD)) {
1434 if (v->snap_reserved > v->snap_used) {
1435 snap_reserve_free = v->snap_reserved - v->snap_used;
1436 snap_reserve_used = v->snap_used;
1439 snap_reserve_free = 0;
1440 snap_reserve_used = v->snap_reserved;
1441 snap_norm_used = v->snap_used - v->snap_reserved;
1445 /* The space used by snapshots but not reserved for them is included in
1446 * both, norm_used and snap_norm_used. If possible, subtract this here. */
1447 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED))
1449 if (norm_used >= snap_norm_used)
1450 norm_used -= snap_norm_used;
1453 ERROR ("netapp plugin: (norm_used = %"PRIu64") < (snap_norm_used = "
1454 "%"PRIu64") for host %s. Invalidating both.",
1455 norm_used, snap_norm_used, hostname);
1456 v->flags &= ~(HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED);
1460 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1461 submit_double (hostname, /* plugin instance = */ plugin_instance,
1462 "df_complex", "free",
1463 (double) norm_free, /* timestamp = */ 0, interval);
1465 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1466 submit_double (hostname, /* plugin instance = */ plugin_instance,
1467 "df_complex", "sis_saved",
1468 (double) sis_saved, /* timestamp = */ 0, interval);
1470 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_COMPRESS_SAVED))
1471 submit_double (hostname, /* plugin instance = */ plugin_instance,
1472 "df_complex", "compression_saved",
1473 (double) compress_saved, /* timestamp = */ 0, interval);
1475 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_DEDUP_SAVED))
1476 submit_double (hostname, /* plugin instance = */ plugin_instance,
1477 "df_complex", "dedup_saved",
1478 (double) dedup_saved, /* timestamp = */ 0, interval);
1480 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1481 submit_double (hostname, /* plugin instance = */ plugin_instance,
1482 "df_complex", "used",
1483 (double) norm_used, /* timestamp = */ 0, interval);
1485 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1486 submit_double (hostname, /* plugin instance = */ plugin_instance,
1487 "df_complex", "snap_reserved",
1488 (double) snap_reserve_free, /* timestamp = */ 0, interval);
1490 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD))
1491 submit_double (hostname, /* plugin instance = */ plugin_instance,
1492 "df_complex", "snap_reserve_used",
1493 (double) snap_reserve_used, /* timestamp = */ 0, interval);
1495 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1496 submit_double (hostname, /* plugin instance = */ plugin_instance,
1497 "df_complex", "snap_normal_used",
1498 (double) snap_norm_used, /* timestamp = */ 0, interval);
1500 /* Clear all the HAVE_* flags */
1501 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1502 } /* for (v = cfg_volume->volumes) */
1505 } /* }}} int cna_submit_volume_usage_data */
1507 /* Switch the state of a volume between online and offline and send out a
1509 static int cna_change_volume_status (const char *hostname, /* {{{ */
1510 data_volume_usage_t *v)
1512 notification_t n = { 0 };
1515 sstrncpy (n.host, hostname, sizeof (n.host));
1516 sstrncpy (n.plugin, "netapp", sizeof (n.plugin));
1517 sstrncpy (n.plugin_instance, v->name, sizeof (n.plugin_instance));
1519 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0) {
1520 n.severity = NOTIF_OKAY;
1521 ssnprintf (n.message, sizeof (n.message),
1522 "Volume %s is now online.", v->name);
1523 v->flags &= ~IS_VOLUME_USAGE_OFFLINE;
1525 n.severity = NOTIF_WARNING;
1526 ssnprintf (n.message, sizeof (n.message),
1527 "Volume %s is now offline.", v->name);
1528 v->flags |= IS_VOLUME_USAGE_OFFLINE;
1531 return (plugin_dispatch_notification (&n));
1532 } /* }}} int cna_change_volume_status */
1534 static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
1535 data_volume_usage_t *v)
1537 uint64_t snap_used = 0, value;
1538 na_elem_t *data, *elem_snapshots;
1539 na_elem_iter_t iter_snap;
1541 data = na_server_invoke_elem(host->srv, v->snap_query);
1542 if (na_results_status(data) != NA_OK)
1544 if (na_results_errno(data) == EVOLUMEOFFLINE) {
1545 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) == 0)
1546 cna_change_volume_status (host->name, v);
1548 ERROR ("netapp plugin: cna_handle_volume_snap_usage: na_server_invoke_elem for "
1549 "volume \"%s\" on host %s failed with error %d: %s", v->name,
1550 host->name, na_results_errno(data), na_results_reason(data));
1556 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0)
1557 cna_change_volume_status (host->name, v);
1559 elem_snapshots = na_elem_child (data, "snapshots");
1560 if (elem_snapshots == NULL)
1562 ERROR ("netapp plugin: cna_handle_volume_snap_usage: "
1563 "na_elem_child (\"snapshots\") failed "
1564 "for host %s.", host->name);
1569 iter_snap = na_child_iterator (elem_snapshots);
1570 for (na_elem_t *elem_snap = na_iterator_next (&iter_snap);
1572 elem_snap = na_iterator_next (&iter_snap))
1574 value = na_child_get_uint64(elem_snap, "cumulative-total", 0);
1575 /* "cumulative-total" is the total size of the oldest snapshot plus all
1576 * newer ones in blocks (1KB). We therefore are looking for the highest
1577 * number of all snapshots - that's the size required for the snapshots. */
1578 if (value > snap_used)
1581 na_elem_free (data);
1582 /* snap_used is in 1024 byte blocks */
1583 v->snap_used = snap_used * 1024;
1584 v->flags |= HAVE_VOLUME_USAGE_SNAP_USED;
1585 } /* }}} void cna_handle_volume_snap_usage */
1587 static void cna_handle_volume_sis_data (const host_config_t *host, /* {{{ */
1588 data_volume_usage_t *v, na_elem_t *sis)
1590 const char *sis_state;
1591 uint64_t sis_saved_reported;
1593 if (na_elem_child(sis, "sis-info"))
1594 sis = na_elem_child(sis, "sis-info");
1596 sis_state = na_child_get_string(sis, "state");
1597 if (sis_state == NULL)
1600 /* If SIS is not enabled, there's nothing left to do for this volume. */
1601 if (strcmp ("enabled", sis_state) != 0)
1604 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1605 if (sis_saved_reported == UINT64_MAX)
1608 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1609 if ((sis_saved_reported >> 32) != 0) {
1610 /* In case they ever fix this bug. */
1611 v->sis_saved = sis_saved_reported;
1612 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1613 } else { /* really hacky work-around code. {{{ */
1614 uint64_t sis_saved_percent;
1615 uint64_t sis_saved_guess;
1616 uint64_t overflow_guess;
1617 uint64_t guess1, guess2, guess3;
1619 /* Check if we have v->norm_used. Without it, we cannot calculate
1620 * sis_saved_guess. */
1621 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1624 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1625 if (sis_saved_percent > 100)
1628 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1629 * will hopefully be fixed in later versions. To work around the bug, try
1630 * to figure out how often the 32bit integer wrapped around by using the
1631 * "percentage-saved" value. Because the percentage is in the range
1632 * [0-100], this should work as long as the saved space does not exceed
1634 /* percentage-saved = size-saved / (size-saved + size-used) */
1635 if (sis_saved_percent < 100)
1636 sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1638 sis_saved_guess = v->norm_used;
1640 overflow_guess = sis_saved_guess >> 32;
1641 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1642 guess2 = (overflow_guess << 32) + sis_saved_reported;
1643 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1645 if (sis_saved_guess < guess2) {
1646 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1647 v->sis_saved = guess1;
1649 v->sis_saved = guess2;
1651 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1652 v->sis_saved = guess2;
1654 v->sis_saved = guess3;
1656 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1657 } /* }}} end of 32-bit workaround */
1658 } /* }}} void cna_handle_volume_sis_data */
1660 /* ONTAP >= 8.1 uses SIS for managing dedup and compression */
1661 static void cna_handle_volume_sis_saved (const host_config_t *host, /* {{{ */
1662 data_volume_usage_t *v, na_elem_t *sis)
1666 if (na_elem_child(sis, "sis-info"))
1667 sis = na_elem_child(sis, "sis-info");
1669 saved = na_child_get_uint64(sis, "compress-saved", UINT64_MAX);
1670 if (saved != UINT64_MAX) {
1671 v->compress_saved = saved;
1672 v->flags |= HAVE_VOLUME_USAGE_COMPRESS_SAVED;
1675 saved = na_child_get_uint64(sis, "dedup-saved", UINT64_MAX);
1676 if (saved != UINT64_MAX) {
1677 v->dedup_saved = saved;
1678 v->flags |= HAVE_VOLUME_USAGE_DEDUP_SAVED;
1680 } /* }}} void cna_handle_volume_sis_saved */
1682 static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */
1683 cfg_volume_usage_t *cfg_volume, na_elem_t *data)
1685 na_elem_t *elem_volumes;
1686 na_elem_iter_t iter_volume;
1688 elem_volumes = na_elem_child (data, "volumes");
1689 if (elem_volumes == NULL)
1691 ERROR ("netapp plugin: cna_handle_volume_usage_data: "
1692 "na_elem_child (\"volumes\") failed "
1693 "for host %s.", host->name);
1697 iter_volume = na_child_iterator (elem_volumes);
1698 for (na_elem_t *elem_volume = na_iterator_next (&iter_volume);
1699 elem_volume != NULL;
1700 elem_volume = na_iterator_next (&iter_volume))
1702 const char *volume_name, *state;
1704 data_volume_usage_t *v;
1709 volume_name = na_child_get_string (elem_volume, "name");
1710 if (volume_name == NULL)
1713 state = na_child_get_string (elem_volume, "state");
1714 if ((state == NULL) || (strcmp(state, "online") != 0))
1717 /* get_volume_usage may return NULL if the volume is to be ignored. */
1718 v = get_volume_usage (cfg_volume, volume_name);
1722 if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
1723 cna_handle_volume_snap_usage(host, v);
1725 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1728 /* 2^4 exa-bytes? This will take a while ;) */
1729 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1730 if (value != UINT64_MAX) {
1731 v->norm_free = value;
1732 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1735 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1736 if (value != UINT64_MAX) {
1737 v->norm_used = value;
1738 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1741 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
1742 if (value != UINT64_MAX) {
1743 /* 1 block == 1024 bytes as per API docs */
1744 v->snap_reserved = 1024 * value;
1745 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1748 sis = na_elem_child(elem_volume, "sis");
1750 cna_handle_volume_sis_data (host, v, sis);
1751 cna_handle_volume_sis_saved (host, v, sis);
1753 } /* for (elem_volume) */
1755 return (cna_submit_volume_usage_data (host->name, cfg_volume,
1756 host->cfg_volume_usage->interval.interval));
1757 } /* }}} int cna_handle_volume_usage_data */
1759 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
1764 if (cvu->query != NULL)
1767 cvu->query = na_elem_new ("volume-list-info");
1768 if (cvu->query == NULL)
1770 ERROR ("netapp plugin: na_elem_new failed.");
1775 } /* }}} int cna_setup_volume_usage */
1777 static int cna_query_volume_usage (host_config_t *host) /* {{{ */
1786 /* If the user did not configure volume_usage statistics, return without
1787 * doing anything. */
1788 if (host->cfg_volume_usage == NULL)
1792 if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
1795 status = cna_setup_volume_usage (host->cfg_volume_usage);
1798 assert (host->cfg_volume_usage->query != NULL);
1800 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1801 if (na_results_status (data) != NA_OK)
1803 ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed for host %s: %s",
1804 host->name, na_results_reason (data));
1805 na_elem_free (data);
1809 status = cna_handle_volume_usage_data (host, host->cfg_volume_usage, data);
1812 host->cfg_volume_usage->interval.last_read = now;
1814 na_elem_free (data);
1816 } /* }}} int cna_query_volume_usage */
1818 /* Data corresponding to <Quota /> */
1819 static int cna_handle_quota_data (const host_config_t *host, /* {{{ */
1820 cfg_quota_t *cfg_quota, na_elem_t *data)
1822 na_elem_t *elem_quotas;
1823 na_elem_iter_t iter_quota;
1825 elem_quotas = na_elem_child (data, "quotas");
1826 if (elem_quotas == NULL)
1828 ERROR ("netapp plugin: cna_handle_quota_data: "
1829 "na_elem_child (\"quotas\") failed "
1830 "for host %s.", host->name);
1834 iter_quota = na_child_iterator (elem_quotas);
1835 for (na_elem_t *elem_quota = na_iterator_next (&iter_quota);
1837 elem_quota = na_iterator_next (&iter_quota))
1839 const char *quota_type, *volume_name, *tree_name;
1842 char plugin_instance[DATA_MAX_NAME_LEN];
1844 quota_type = na_child_get_string (elem_quota, "quota-type");
1845 if (quota_type == NULL)
1848 /* possible TODO: support other types as well */
1849 if (strcmp (quota_type, "tree") != 0)
1852 tree_name = na_child_get_string (elem_quota, "tree");
1853 if ((tree_name == NULL) || (*tree_name == '\0'))
1856 volume_name = na_child_get_string (elem_quota, "volume");
1857 if (volume_name == NULL)
1860 ssnprintf (plugin_instance, sizeof (plugin_instance),
1861 "quota-%s-%s", volume_name, tree_name);
1863 value = na_child_get_uint64 (elem_quota, "disk-used", UINT64_MAX);
1864 if (value != UINT64_MAX) {
1865 value *= 1024; /* disk-used reports kilobytes */
1866 submit_double (host->name, plugin_instance,
1867 /* type = */ "df_complex", /* type instance = */ NULL,
1868 (double)value, /* timestamp = */ 0,
1869 host->cfg_quota->interval.interval);
1872 value = na_child_get_uint64 (elem_quota, "files-used", UINT64_MAX);
1873 if (value != UINT64_MAX) {
1874 submit_double (host->name, plugin_instance,
1875 /* type = */ "files", /* type instance = */ NULL,
1876 (double)value, /* timestamp = */ 0,
1877 host->cfg_quota->interval.interval);
1879 } /* for (elem_quota) */
1882 } /* }}} int cna_handle_volume_usage_data */
1884 static int cna_setup_quota (cfg_quota_t *cq) /* {{{ */
1889 if (cq->query != NULL)
1892 cq->query = na_elem_new ("quota-report");
1893 if (cq->query == NULL)
1895 ERROR ("netapp plugin: na_elem_new failed.");
1900 } /* }}} int cna_setup_quota */
1902 static int cna_query_quota (host_config_t *host) /* {{{ */
1911 /* If the user did not configure quota statistics, return without
1912 * doing anything. */
1913 if (host->cfg_quota == NULL)
1917 if ((host->cfg_quota->interval.interval + host->cfg_quota->interval.last_read) > now)
1920 status = cna_setup_quota (host->cfg_quota);
1923 assert (host->cfg_quota->query != NULL);
1925 data = na_server_invoke_elem (host->srv, host->cfg_quota->query);
1926 if (na_results_status (data) != NA_OK)
1928 ERROR ("netapp plugin: cna_query_quota: na_server_invoke_elem failed for host %s: %s",
1929 host->name, na_results_reason (data));
1930 na_elem_free (data);
1934 status = cna_handle_quota_data (host, host->cfg_quota, data);
1937 host->cfg_quota->interval.last_read = now;
1939 na_elem_free (data);
1941 } /* }}} int cna_query_quota */
1943 /* Data corresponding to <SnapVault /> */
1944 static int cna_handle_snapvault_data (const char *hostname, /* {{{ */
1945 cfg_snapvault_t *cfg_snapvault, na_elem_t *data, cdtime_t interval)
1947 na_elem_iter_t status_iter;
1949 status = na_elem_child (data, "status-list");
1951 ERROR ("netapp plugin: SnapVault status record missing status-list");
1955 status_iter = na_child_iterator (status);
1956 for (na_elem_t *status = na_iterator_next (&status_iter);
1958 status = na_iterator_next (&status_iter))
1960 const char *dest_sys, *dest_path, *src_sys, *src_path;
1961 char plugin_instance[DATA_MAX_NAME_LEN];
1964 dest_sys = na_child_get_string (status, "destination-system");
1965 dest_path = na_child_get_string (status, "destination-path");
1966 src_sys = na_child_get_string (status, "source-system");
1967 src_path = na_child_get_string (status, "source-path");
1969 if ((! dest_sys) || (! dest_path) || (! src_sys) || (! src_path))
1972 value = na_child_get_uint64 (status, "lag-time", UINT64_MAX);
1973 if (value == UINT64_MAX) /* no successful baseline transfer yet */
1976 /* possible TODO: make plugin instance configurable */
1977 ssnprintf (plugin_instance, sizeof (plugin_instance),
1978 "snapvault-%s", dest_path);
1979 submit_double (hostname, plugin_instance, /* type = */ "delay", NULL,
1980 (double)value, /* timestamp = */ 0, interval);
1982 value = na_child_get_uint64 (status, "last-transfer-duration", UINT64_MAX);
1983 if (value != UINT64_MAX)
1984 submit_double (hostname, plugin_instance, /* type = */ "duration", "last_transfer",
1985 (double)value, /* timestamp = */ 0, interval);
1987 value = na_child_get_uint64 (status, "transfer-progress", UINT64_MAX);
1988 if (value == UINT64_MAX)
1989 value = na_child_get_uint64 (status, "last-transfer-size", UINT64_MAX);
1990 if (value != UINT64_MAX) {
1991 value *= 1024; /* this is kilobytes */
1992 submit_derive (hostname, plugin_instance, /* type = */ "if_rx_octets", "transferred",
1993 value, /* timestamp = */ 0, interval);
1995 } /* for (status) */
1998 } /* }}} int cna_handle_snapvault_data */
2000 static int cna_handle_snapvault_iter (host_config_t *host, /* {{{ */
2005 uint32_t records_count;
2007 records_count = na_child_get_uint32 (data, "records", UINT32_MAX);
2008 if (records_count == UINT32_MAX)
2011 tag = na_child_get_string (data, "tag");
2015 DEBUG ("netapp plugin: Iterating %u SV records (tag = %s)", records_count, tag);
2017 for (uint32_t i = 0; i < records_count; ++i) {
2020 elem = na_server_invoke (host->srv,
2021 "snapvault-secondary-relationship-status-list-iter-next",
2022 "maximum", "1", "tag", tag, NULL);
2024 if (na_results_status (elem) != NA_OK)
2026 ERROR ("netapp plugin: cna_handle_snapvault_iter: "
2027 "na_server_invoke failed for host %s: %s",
2028 host->name, na_results_reason (data));
2029 na_elem_free (elem);
2033 cna_handle_snapvault_data (host->name, host->cfg_snapvault, elem,
2034 host->cfg_snapvault->interval.interval);
2035 na_elem_free (elem);
2038 na_elem_free (na_server_invoke (host->srv,
2039 "snapvault-secondary-relationship-status-list-iter-end",
2042 } /* }}} int cna_handle_snapvault_iter */
2044 static int cna_setup_snapvault (cfg_snapvault_t *sv) /* {{{ */
2049 if (sv->query != NULL)
2052 sv->query = na_elem_new ("snapvault-secondary-relationship-status-list-iter-start");
2053 if (sv->query == NULL)
2055 ERROR ("netapp plugin: na_elem_new failed.");
2060 } /* }}} int cna_setup_snapvault */
2062 static int cna_query_snapvault (host_config_t *host) /* {{{ */
2071 if (host->cfg_snapvault == NULL)
2075 if ((host->cfg_snapvault->interval.interval + host->cfg_snapvault->interval.last_read) > now)
2078 status = cna_setup_snapvault (host->cfg_snapvault);
2081 assert (host->cfg_snapvault->query != NULL);
2083 data = na_server_invoke_elem (host->srv, host->cfg_snapvault->query);
2084 if (na_results_status (data) != NA_OK)
2086 ERROR ("netapp plugin: cna_query_snapvault: na_server_invoke_elem failed for host %s: %s",
2087 host->name, na_results_reason (data));
2088 na_elem_free (data);
2092 status = cna_handle_snapvault_iter (host, data);
2095 host->cfg_snapvault->interval.last_read = now;
2097 na_elem_free (data);
2099 } /* }}} int cna_query_snapvault */
2101 /* Data corresponding to <System /> */
2102 static int cna_handle_system_data (const char *hostname, /* {{{ */
2103 cfg_system_t *cfg_system, na_elem_t *data, int interval)
2105 na_elem_t *instances;
2106 na_elem_iter_t counter_iter;
2108 derive_t disk_read = 0, disk_written = 0;
2109 derive_t net_recv = 0, net_sent = 0;
2110 derive_t cpu_busy = 0, cpu_total = 0;
2111 uint32_t counter_flags = 0;
2113 const char *instance;
2116 timestamp = cna_child_get_cdtime (data);
2118 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
2119 if (instances == NULL)
2121 ERROR ("netapp plugin: cna_handle_system_data: "
2122 "na_elem_child (\"instances\") failed "
2123 "for host %s.", hostname);
2127 instance = na_child_get_string (instances, "name");
2128 if (instance == NULL)
2130 ERROR ("netapp plugin: cna_handle_system_data: "
2131 "na_child_get_string (\"name\") failed "
2132 "for host %s.", hostname);
2136 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
2137 for (na_elem_t *counter = na_iterator_next (&counter_iter);
2139 counter = na_iterator_next (&counter_iter))
2144 name = na_child_get_string(counter, "name");
2148 value = na_child_get_uint64(counter, "value", UINT64_MAX);
2149 if (value == UINT64_MAX)
2152 if (!strcmp(name, "disk_data_read")) {
2153 disk_read = (derive_t) (value * 1024);
2154 counter_flags |= 0x01;
2155 } else if (!strcmp(name, "disk_data_written")) {
2156 disk_written = (derive_t) (value * 1024);
2157 counter_flags |= 0x02;
2158 } else if (!strcmp(name, "net_data_recv")) {
2159 net_recv = (derive_t) (value * 1024);
2160 counter_flags |= 0x04;
2161 } else if (!strcmp(name, "net_data_sent")) {
2162 net_sent = (derive_t) (value * 1024);
2163 counter_flags |= 0x08;
2164 } else if (!strcmp(name, "cpu_busy")) {
2165 cpu_busy = (derive_t) value;
2166 counter_flags |= 0x10;
2167 } else if (!strcmp(name, "cpu_elapsed_time")) {
2168 cpu_total = (derive_t) value;
2169 counter_flags |= 0x20;
2170 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
2171 && (value > 0) && (strlen(name) > 4)
2172 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
2173 submit_derive (hostname, instance, "disk_ops_complex", name,
2174 (derive_t) value, timestamp, interval);
2176 } /* for (counter) */
2178 if ((cfg_system->flags & CFG_SYSTEM_DISK)
2179 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
2180 submit_two_derive (hostname, instance, "disk_octets", NULL,
2181 disk_read, disk_written, timestamp, interval);
2183 if ((cfg_system->flags & CFG_SYSTEM_NET)
2184 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
2185 submit_two_derive (hostname, instance, "if_octets", NULL,
2186 net_recv, net_sent, timestamp, interval);
2188 if ((cfg_system->flags & CFG_SYSTEM_CPU)
2189 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
2191 submit_derive (hostname, instance, "cpu", "system",
2192 cpu_busy, timestamp, interval);
2193 submit_derive (hostname, instance, "cpu", "idle",
2194 cpu_total - cpu_busy, timestamp, interval);
2198 } /* }}} int cna_handle_system_data */
2200 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
2205 if (cs->query != NULL)
2208 cs->query = na_elem_new ("perf-object-get-instances");
2209 if (cs->query == NULL)
2211 ERROR ("netapp plugin: na_elem_new failed.");
2214 na_child_add_string (cs->query, "objectname", "system");
2217 } /* }}} int cna_setup_system */
2219 static int cna_query_system (host_config_t *host) /* {{{ */
2228 /* If system statistics were not configured, return without doing anything. */
2229 if (host->cfg_system == NULL)
2233 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
2236 status = cna_setup_system (host->cfg_system);
2239 assert (host->cfg_system->query != NULL);
2241 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
2242 if (na_results_status (data) != NA_OK)
2244 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed for host %s: %s",
2245 host->name, na_results_reason (data));
2246 na_elem_free (data);
2250 status = cna_handle_system_data (host->name, host->cfg_system, data,
2251 host->cfg_system->interval.interval);
2254 host->cfg_system->interval.last_read = now;
2256 na_elem_free (data);
2258 } /* }}} int cna_query_system */
2261 * Configuration handling
2263 /* Sets a given flag if the boolean argument is true and unsets the flag if it
2264 * is false. On error, the flag-field is not changed. */
2265 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
2266 uint32_t *flags, uint32_t flag)
2268 if ((ci == NULL) || (flags == NULL))
2271 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2273 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
2278 if (ci->values[0].value.boolean)
2284 } /* }}} int cna_config_bool_to_flag */
2286 /* Handling of the "Interval" option which is allowed in every block. */
2287 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
2288 cna_interval_t *out_interval)
2293 status = cf_util_get_cdtime (ci, &tmp);
2297 out_interval->interval = tmp;
2298 out_interval->last_read = 0;
2301 } /* }}} int cna_config_get_interval */
2303 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
2304 * <VolumePerf /> block. */
2305 static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
2306 const oconfig_item_t *ci)
2311 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2313 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2318 name = ci->values[0].value.string;
2320 if (strcasecmp ("GetIO", ci->key) == 0)
2321 il = cvp->il_octets;
2322 else if (strcasecmp ("GetOps", ci->key) == 0)
2323 il = cvp->il_operations;
2324 else if (strcasecmp ("GetLatency", ci->key) == 0)
2325 il = cvp->il_latency;
2329 ignorelist_add (il, name);
2330 } /* }}} void cna_config_volume_perf_option */
2332 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
2333 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
2334 static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
2335 const oconfig_item_t *ci)
2339 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2341 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2346 if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
2347 il = cvp->il_octets;
2348 else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
2349 il = cvp->il_operations;
2350 else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
2351 il = cvp->il_latency;
2355 if (ci->values[0].value.boolean)
2356 ignorelist_set_invert (il, /* invert = */ 0);
2358 ignorelist_set_invert (il, /* invert = */ 1);
2359 } /* }}} void cna_config_volume_perf_default */
2361 /* Corresponds to a <Disks /> block */
2366 * IgnoreSelectedIO false
2370 * IgnoreSelectedOps false
2374 * IgnoreSelectedLatency false
2377 /* Corresponds to a <VolumePerf /> block */
2378 static int cna_config_volume_performance (host_config_t *host, /* {{{ */
2379 const oconfig_item_t *ci)
2381 cfg_volume_perf_t *cfg_volume_perf;
2383 if ((host == NULL) || (ci == NULL))
2386 if (host->cfg_volume_perf == NULL)
2388 cfg_volume_perf = calloc (1, sizeof (*cfg_volume_perf));
2389 if (cfg_volume_perf == NULL)
2392 /* Set default flags */
2393 cfg_volume_perf->query = NULL;
2394 cfg_volume_perf->volumes = NULL;
2396 cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
2397 if (cfg_volume_perf->il_octets == NULL)
2399 sfree (cfg_volume_perf);
2403 cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
2404 if (cfg_volume_perf->il_operations == NULL)
2406 ignorelist_free (cfg_volume_perf->il_octets);
2407 sfree (cfg_volume_perf);
2411 cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
2412 if (cfg_volume_perf->il_latency == NULL)
2414 ignorelist_free (cfg_volume_perf->il_octets);
2415 ignorelist_free (cfg_volume_perf->il_operations);
2416 sfree (cfg_volume_perf);
2420 host->cfg_volume_perf = cfg_volume_perf;
2422 cfg_volume_perf = host->cfg_volume_perf;
2424 for (int i = 0; i < ci->children_num; ++i) {
2425 oconfig_item_t *item = ci->children + i;
2427 /* if (!item || !item->key || !*item->key) continue; */
2428 if (strcasecmp(item->key, "Interval") == 0)
2429 cna_config_get_interval (item, &cfg_volume_perf->interval);
2430 else if (!strcasecmp(item->key, "GetIO"))
2431 cna_config_volume_perf_option (cfg_volume_perf, item);
2432 else if (!strcasecmp(item->key, "GetOps"))
2433 cna_config_volume_perf_option (cfg_volume_perf, item);
2434 else if (!strcasecmp(item->key, "GetLatency"))
2435 cna_config_volume_perf_option (cfg_volume_perf, item);
2436 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
2437 cna_config_volume_perf_default (cfg_volume_perf, item);
2438 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
2439 cna_config_volume_perf_default (cfg_volume_perf, item);
2440 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
2441 cna_config_volume_perf_default (cfg_volume_perf, item);
2443 WARNING ("netapp plugin: The option %s is not allowed within "
2444 "`VolumePerf' blocks.", item->key);
2448 } /* }}} int cna_config_volume_performance */
2450 /* Handling of the "GetCapacity" and "GetSnapshot" options within a
2451 * <VolumeUsage /> block. */
2452 static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
2453 const oconfig_item_t *ci)
2458 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2460 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2465 name = ci->values[0].value.string;
2467 if (strcasecmp ("GetCapacity", ci->key) == 0)
2468 il = cvu->il_capacity;
2469 else if (strcasecmp ("GetSnapshot", ci->key) == 0)
2470 il = cvu->il_snapshot;
2474 ignorelist_add (il, name);
2475 } /* }}} void cna_config_volume_usage_option */
2477 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
2478 * options within a <VolumeUsage /> block. */
2479 static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
2480 const oconfig_item_t *ci)
2484 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2486 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2491 if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
2492 il = cvu->il_capacity;
2493 else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
2494 il = cvu->il_snapshot;
2498 if (ci->values[0].value.boolean)
2499 ignorelist_set_invert (il, /* invert = */ 0);
2501 ignorelist_set_invert (il, /* invert = */ 1);
2502 } /* }}} void cna_config_volume_usage_default */
2504 /* Corresponds to a <Quota /> block */
2505 static int cna_config_quota (host_config_t *host, oconfig_item_t *ci) /* {{{ */
2507 cfg_quota_t *cfg_quota;
2509 if ((host == NULL) || (ci == NULL))
2512 if (host->cfg_quota == NULL)
2514 cfg_quota = calloc (1, sizeof (*cfg_quota));
2515 if (cfg_quota == NULL)
2517 cfg_quota->query = NULL;
2519 host->cfg_quota = cfg_quota;
2521 cfg_quota = host->cfg_quota;
2523 for (int i = 0; i < ci->children_num; ++i) {
2524 oconfig_item_t *item = ci->children + i;
2526 if (strcasecmp (item->key, "Interval") == 0)
2527 cna_config_get_interval (item, &cfg_quota->interval);
2529 WARNING ("netapp plugin: The option %s is not allowed within "
2530 "`Quota' blocks.", item->key);
2534 } /* }}} int cna_config_quota */
2536 /* Corresponds to a <Disks /> block */
2537 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
2538 cfg_disk_t *cfg_disk;
2540 if ((host == NULL) || (ci == NULL))
2543 if (host->cfg_disk == NULL)
2545 cfg_disk = calloc (1, sizeof (*cfg_disk));
2546 if (cfg_disk == NULL)
2549 /* Set default flags */
2550 cfg_disk->flags = CFG_DISK_ALL;
2551 cfg_disk->query = NULL;
2552 cfg_disk->disks = NULL;
2554 host->cfg_disk = cfg_disk;
2556 cfg_disk = host->cfg_disk;
2558 for (int i = 0; i < ci->children_num; ++i) {
2559 oconfig_item_t *item = ci->children + i;
2561 /* if (!item || !item->key || !*item->key) continue; */
2562 if (strcasecmp(item->key, "Interval") == 0)
2563 cna_config_get_interval (item, &cfg_disk->interval);
2564 else if (strcasecmp(item->key, "GetBusy") == 0)
2565 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2568 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
2570 NOTICE ("netapp plugin: All disk related values have been disabled. "
2571 "Collection of per-disk data will be disabled entirely.");
2572 free_cfg_disk (host->cfg_disk);
2573 host->cfg_disk = NULL;
2577 } /* }}} int cna_config_disk */
2579 /* Corresponds to a <WAFL /> block */
2580 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2582 cfg_wafl_t *cfg_wafl;
2584 if ((host == NULL) || (ci == NULL))
2587 if (host->cfg_wafl == NULL)
2589 cfg_wafl = calloc (1, sizeof (*cfg_wafl));
2590 if (cfg_wafl == NULL)
2593 /* Set default flags */
2594 cfg_wafl->flags = CFG_WAFL_ALL;
2596 host->cfg_wafl = cfg_wafl;
2598 cfg_wafl = host->cfg_wafl;
2600 for (int i = 0; i < ci->children_num; ++i) {
2601 oconfig_item_t *item = ci->children + i;
2603 if (strcasecmp(item->key, "Interval") == 0)
2604 cna_config_get_interval (item, &cfg_wafl->interval);
2605 else if (!strcasecmp(item->key, "GetNameCache"))
2606 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2607 else if (!strcasecmp(item->key, "GetDirCache"))
2608 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2609 else if (!strcasecmp(item->key, "GetBufferCache"))
2610 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2611 else if (!strcasecmp(item->key, "GetInodeCache"))
2612 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2614 WARNING ("netapp plugin: The %s config option is not allowed within "
2615 "`WAFL' blocks.", item->key);
2618 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
2620 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
2621 "Collection of WAFL data will be disabled entirely.");
2622 free_cfg_wafl (host->cfg_wafl);
2623 host->cfg_wafl = NULL;
2627 } /* }}} int cna_config_wafl */
2631 * GetCapacity "vol0"
2632 * GetCapacity "vol1"
2633 * GetCapacity "vol2"
2634 * GetCapacity "vol3"
2635 * GetCapacity "vol4"
2636 * IgnoreSelectedCapacity false
2638 * GetSnapshot "vol0"
2639 * GetSnapshot "vol3"
2640 * GetSnapshot "vol4"
2641 * GetSnapshot "vol7"
2642 * IgnoreSelectedSnapshot false
2645 /* Corresponds to a <VolumeUsage /> block */
2646 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2647 const oconfig_item_t *ci)
2649 cfg_volume_usage_t *cfg_volume_usage;
2651 if ((host == NULL) || (ci == NULL))
2654 if (host->cfg_volume_usage == NULL)
2656 cfg_volume_usage = calloc (1, sizeof (*cfg_volume_usage));
2657 if (cfg_volume_usage == NULL)
2660 /* Set default flags */
2661 cfg_volume_usage->query = NULL;
2662 cfg_volume_usage->volumes = NULL;
2664 cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
2665 if (cfg_volume_usage->il_capacity == NULL)
2667 sfree (cfg_volume_usage);
2671 cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
2672 if (cfg_volume_usage->il_snapshot == NULL)
2674 ignorelist_free (cfg_volume_usage->il_capacity);
2675 sfree (cfg_volume_usage);
2679 host->cfg_volume_usage = cfg_volume_usage;
2681 cfg_volume_usage = host->cfg_volume_usage;
2683 for (int i = 0; i < ci->children_num; ++i) {
2684 oconfig_item_t *item = ci->children + i;
2686 /* if (!item || !item->key || !*item->key) continue; */
2687 if (strcasecmp(item->key, "Interval") == 0)
2688 cna_config_get_interval (item, &cfg_volume_usage->interval);
2689 else if (!strcasecmp(item->key, "GetCapacity"))
2690 cna_config_volume_usage_option (cfg_volume_usage, item);
2691 else if (!strcasecmp(item->key, "GetSnapshot"))
2692 cna_config_volume_usage_option (cfg_volume_usage, item);
2693 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2694 cna_config_volume_usage_default (cfg_volume_usage, item);
2695 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2696 cna_config_volume_usage_default (cfg_volume_usage, item);
2698 WARNING ("netapp plugin: The option %s is not allowed within "
2699 "`VolumeUsage' blocks.", item->key);
2703 } /* }}} int cna_config_volume_usage */
2705 /* Corresponds to a <SnapVault /> block */
2706 static int cna_config_snapvault (host_config_t *host, /* {{{ */
2707 const oconfig_item_t *ci)
2709 cfg_snapvault_t *cfg_snapvault;
2711 if ((host == NULL) || (ci == NULL))
2714 if (host->cfg_snapvault == NULL)
2716 cfg_snapvault = calloc (1, sizeof (*cfg_snapvault));
2717 if (cfg_snapvault == NULL)
2719 cfg_snapvault->query = NULL;
2721 host->cfg_snapvault = cfg_snapvault;
2724 cfg_snapvault = host->cfg_snapvault;
2726 for (int i = 0; i < ci->children_num; ++i) {
2727 oconfig_item_t *item = ci->children + i;
2729 if (strcasecmp (item->key, "Interval") == 0)
2730 cna_config_get_interval (item, &cfg_snapvault->interval);
2732 WARNING ("netapp plugin: The option %s is not allowed within "
2733 "`SnapVault' blocks.", item->key);
2737 } /* }}} int cna_config_snapvault */
2739 /* Corresponds to a <System /> block */
2740 static int cna_config_system (host_config_t *host, /* {{{ */
2743 cfg_system_t *cfg_system;
2745 if ((host == NULL) || (ci == NULL))
2748 if (host->cfg_system == NULL)
2750 cfg_system = calloc (1, sizeof (*cfg_system));
2751 if (cfg_system == NULL)
2754 /* Set default flags */
2755 cfg_system->flags = CFG_SYSTEM_ALL;
2756 cfg_system->query = NULL;
2758 host->cfg_system = cfg_system;
2760 cfg_system = host->cfg_system;
2762 for (int i = 0; i < ci->children_num; ++i) {
2763 oconfig_item_t *item = ci->children + i;
2765 if (strcasecmp(item->key, "Interval") == 0) {
2766 cna_config_get_interval (item, &cfg_system->interval);
2767 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2768 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
2769 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2770 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
2771 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2772 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
2773 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2774 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
2776 WARNING ("netapp plugin: The %s config option is not allowed within "
2777 "`System' blocks.", item->key);
2781 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
2783 NOTICE ("netapp plugin: All system related values have been disabled. "
2784 "Collection of system data will be disabled entirely.");
2785 free_cfg_system (host->cfg_system);
2786 host->cfg_system = NULL;
2790 } /* }}} int cna_config_system */
2792 /* Corresponds to a <Host /> block. */
2793 static host_config_t *cna_alloc_host (void) /* {{{ */
2795 host_config_t *host;
2797 host = calloc (1, sizeof (*host));
2802 host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2804 host->username = NULL;
2805 host->password = NULL;
2806 host->vfiler = NULL;
2808 host->cfg_wafl = NULL;
2809 host->cfg_disk = NULL;
2810 host->cfg_volume_perf = NULL;
2811 host->cfg_volume_usage = NULL;
2812 host->cfg_quota = NULL;
2813 host->cfg_snapvault = NULL;
2814 host->cfg_system = NULL;
2817 } /* }}} host_config_t *cna_alloc_host */
2819 static host_config_t *cna_shallow_clone_host (host_config_t *host) /* {{{ */
2821 host_config_t *clone;
2826 clone = cna_alloc_host ();
2830 if (host->name != NULL) {
2831 clone->name = strdup (host->name);
2832 if (clone->name == NULL) {
2833 free_host_config (clone);
2838 clone->protocol = host->protocol;
2840 if (host->host != NULL) {
2841 clone->host = strdup (host->host);
2842 if (clone->host == NULL) {
2843 free_host_config (clone);
2848 clone->port = host->port;
2850 if (host->username != NULL) {
2851 clone->username = strdup (host->username);
2852 if (clone->username == NULL) {
2853 free_host_config (clone);
2857 if (host->password != NULL) {
2858 clone->password = strdup (host->password);
2859 if (clone->password == NULL) {
2860 free_host_config (clone);
2865 clone->interval = host->interval;
2868 } /* }}} host_config_t *cna_shallow_clone_host */
2870 static int cna_read (user_data_t *ud);
2872 static int cna_register_host (host_config_t *host) /* {{{ */
2877 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s-%s",
2878 host->name, host->vfiler);
2880 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name);
2882 plugin_register_complex_read (/* group = */ NULL, cb_name,
2883 /* callback = */ cna_read,
2884 /* interval = */ host->interval,
2887 .free_func = (void *) free_host_config,
2891 } /* }}} int cna_register_host */
2893 static int cna_config_host (host_config_t *host, /* {{{ */
2894 const oconfig_item_t *ci)
2896 oconfig_item_t *item;
2897 _Bool is_vfiler = 0;
2900 if (! strcasecmp (ci->key, "VFiler"))
2903 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2904 WARNING ("netapp plugin: \"%s\" needs exactly one string argument. Ignoring host block.", ci->key);
2908 status = cf_util_get_string (ci, &host->name);
2912 for (int i = 0; i < ci->children_num; ++i) {
2913 item = ci->children + i;
2917 if (!strcasecmp(item->key, "Address")) {
2918 status = cf_util_get_string (item, &host->host);
2919 } else if (!strcasecmp(item->key, "Port")) {
2922 tmp = cf_util_get_port_number (item);
2925 } else if (!strcasecmp(item->key, "Protocol")) {
2926 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"))) {
2927 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
2930 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
2931 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2932 } else if (!strcasecmp(item->key, "User")) {
2933 status = cf_util_get_string (item, &host->username);
2934 } else if (!strcasecmp(item->key, "Password")) {
2935 status = cf_util_get_string (item, &host->password);
2936 } else if (!strcasecmp(item->key, "Interval")) {
2937 status = cf_util_get_cdtime (item, &host->interval);
2938 } else if (!strcasecmp(item->key, "WAFL")) {
2939 cna_config_wafl(host, item);
2940 } else if (!strcasecmp(item->key, "Disks")) {
2941 cna_config_disk(host, item);
2942 } else if (!strcasecmp(item->key, "VolumePerf")) {
2943 cna_config_volume_performance(host, item);
2944 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2945 cna_config_volume_usage(host, item);
2946 } else if (!strcasecmp(item->key, "Quota")) {
2947 cna_config_quota(host, item);
2948 } else if (!strcasecmp(item->key, "SnapVault")) {
2949 cna_config_snapvault(host, item);
2950 } else if (!strcasecmp(item->key, "System")) {
2951 cna_config_system(host, item);
2952 } else if ((!strcasecmp(item->key, "VFiler")) && (! is_vfiler)) {
2953 host_config_t *vfiler;
2955 vfiler = cna_shallow_clone_host (host);
2957 ERROR ("netapp plugin: Failed to allocate host object for vfiler.");
2961 if (cna_config_host (vfiler, item)) {
2962 free_host_config (vfiler);
2966 cna_register_host (vfiler);
2967 } else if ((!strcasecmp(item->key, "VFilerName")) && is_vfiler) {
2968 status = cf_util_get_string (item, &host->vfiler);
2970 WARNING ("netapp plugin: Ignoring unknown config option \"%s\" in %s block \"%s\".",
2971 item->key, is_vfiler ? "vfiler" : "host", ci->values[0].value.string);
2978 if (host->host == NULL)
2979 host->host = strdup (host->name);
2981 if (is_vfiler && (! host->vfiler))
2982 host->vfiler = strdup (host->name);
2984 if (host->host == NULL)
2987 if (host->port <= 0)
2988 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
2990 if ((host->username == NULL) || (host->password == NULL)) {
2991 WARNING("netapp plugin: Please supply login information for host \"%s\". "
2992 "Ignoring host block.", host->name);
3000 } /* }}} host_config_t *cna_config_host */
3003 * Callbacks registered with the daemon
3005 * Pretty standard stuff here.
3007 static int cna_init_host (host_config_t *host) /* {{{ */
3009 /* Request version 1.1 of the ONTAP API */
3010 int major_version = 1, minor_version = 1;
3015 if (host->srv != NULL)
3018 if (host->vfiler != NULL) /* Request version 1.7 of the ONTAP API */
3021 host->srv = na_server_open (host->host, major_version, minor_version);
3022 if (host->srv == NULL) {
3023 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
3027 na_server_set_transport_type(host->srv, host->protocol,
3028 /* transportarg = */ NULL);
3029 na_server_set_port(host->srv, host->port);
3030 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
3031 na_server_adminuser(host->srv, host->username, host->password);
3032 na_server_set_timeout(host->srv, 5 /* seconds */);
3034 if (host->vfiler != NULL) {
3035 if (! na_server_set_vfiler (host->srv, host->vfiler)) {
3036 ERROR ("netapp plugin: Failed to connect to VFiler '%s' on host '%s'.",
3037 host->vfiler, host->host);
3041 INFO ("netapp plugin: Connected to VFiler '%s' on host '%s'.",
3042 host->vfiler, host->host);
3047 } /* }}} int cna_init_host */
3049 static int cna_init (void) /* {{{ */
3051 char err[256] = { 0 };
3053 if (!na_startup(err, sizeof(err))) {
3054 err[sizeof (err) - 1] = 0;
3055 ERROR("netapp plugin: Error initializing netapp API: %s", err);
3060 } /* }}} cna_init */
3062 static int cna_read_internal (host_config_t *host) { /* {{{ */
3065 status = cna_query_wafl (host);
3069 status = cna_query_disk (host);
3073 status = cna_query_volume_perf (host);
3077 status = cna_query_volume_usage (host);
3081 status = cna_query_quota (host);
3085 status = cna_query_snapvault (host);
3089 status = cna_query_system (host);
3094 } /* }}} int cna_read_internal */
3096 static int cna_read (user_data_t *ud) { /* {{{ */
3097 host_config_t *host;
3100 if ((ud == NULL) || (ud->data == NULL))
3105 status = cna_init_host (host);
3109 status = cna_read_internal (host);
3112 if (host->srv != NULL)
3113 na_server_close (host->srv);
3118 } /* }}} int cna_read */
3120 static int cna_config (oconfig_item_t *ci) { /* {{{ */
3121 oconfig_item_t *item;
3123 for (int i = 0; i < ci->children_num; ++i) {
3124 item = ci->children + i;
3126 if (strcasecmp(item->key, "Host") == 0)
3128 host_config_t *host;
3130 host = cna_alloc_host ();
3132 ERROR ("netapp plugin: Failed to allocate host object.");
3136 if (cna_config_host (host, item) != 0) {
3137 free_host_config (host);
3141 cna_register_host (host);
3143 else /* if (item->key != "Host") */
3145 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
3149 } /* }}} int cna_config */
3151 static int cna_shutdown (void) /* {{{ */
3153 /* Clean up system resources and stuff. */
3157 } /* }}} int cna_shutdown */
3159 void module_register(void) {
3160 plugin_register_complex_config("netapp", cna_config);
3161 plugin_register_init("netapp", cna_init);
3162 plugin_register_shutdown("netapp", cna_shutdown);
3165 /* vim: set sw=2 ts=2 noet fdm=marker : */