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>
31 #include "utils_ignorelist.h"
33 #include <netapp_api.h>
34 #include <netapp_errno.h>
36 #define HAS_ALL_FLAGS(has,needs) (((has) & (needs)) == (needs))
38 typedef struct host_config_s host_config_t;
39 typedef void service_handler_t(host_config_t *host, na_elem_t *result, void *data);
46 typedef struct cna_interval_s cna_interval_t;
48 /*! Data types for WAFL statistics {{{
50 * \brief Persistent data for WAFL performance counters. (a.k.a. cache performance)
52 * The cache counters use old counter values to calculate a hit ratio for each
53 * counter. The "cfg_wafl_t" struct therefore contains old counter values along
54 * with flags, which are set if the counter is valid.
56 * The function "cna_handle_wafl_data" will fill a new structure of this kind
57 * with new values, then pass both, new and old data, to "submit_wafl_data".
58 * That function calculates the hit ratios, submits the calculated values and
59 * updates the old counter values for the next iteration.
61 #define CFG_WAFL_NAME_CACHE 0x0001
62 #define CFG_WAFL_DIR_CACHE 0x0002
63 #define CFG_WAFL_BUF_CACHE 0x0004
64 #define CFG_WAFL_INODE_CACHE 0x0008
65 #define CFG_WAFL_ALL 0x000F
66 #define HAVE_WAFL_NAME_CACHE_HIT 0x0100
67 #define HAVE_WAFL_NAME_CACHE_MISS 0x0200
68 #define HAVE_WAFL_NAME_CACHE (HAVE_WAFL_NAME_CACHE_HIT | HAVE_WAFL_NAME_CACHE_MISS)
69 #define HAVE_WAFL_FIND_DIR_HIT 0x0400
70 #define HAVE_WAFL_FIND_DIR_MISS 0x0800
71 #define HAVE_WAFL_FIND_DIR (HAVE_WAFL_FIND_DIR_HIT | HAVE_WAFL_FIND_DIR_MISS)
72 #define HAVE_WAFL_BUF_HASH_HIT 0x1000
73 #define HAVE_WAFL_BUF_HASH_MISS 0x2000
74 #define HAVE_WAFL_BUF_HASH (HAVE_WAFL_BUF_HASH_HIT | HAVE_WAFL_BUF_HASH_MISS)
75 #define HAVE_WAFL_INODE_CACHE_HIT 0x4000
76 #define HAVE_WAFL_INODE_CACHE_MISS 0x8000
77 #define HAVE_WAFL_INODE_CACHE (HAVE_WAFL_INODE_CACHE_HIT | HAVE_WAFL_INODE_CACHE_MISS)
78 #define HAVE_WAFL_ALL 0xff00
81 cna_interval_t interval;
85 uint64_t name_cache_hit;
86 uint64_t name_cache_miss;
87 uint64_t find_dir_hit;
88 uint64_t find_dir_miss;
89 uint64_t buf_hash_hit;
90 uint64_t buf_hash_miss;
91 uint64_t inode_cache_hit;
92 uint64_t inode_cache_miss;
96 /*! Data types for disk statistics {{{
98 * \brief A disk in the NetApp.
100 * A disk doesn't have any more information than its name at the moment.
101 * The name includes the "disk_" prefix.
103 #define HAVE_DISK_BUSY 0x10
104 #define HAVE_DISK_BASE 0x20
105 #define HAVE_DISK_ALL 0x30
106 typedef struct disk_s {
111 uint64_t base_for_disk_busy;
112 double disk_busy_percent;
116 #define CFG_DISK_BUSIEST 0x01
117 #define CFG_DISK_ALL 0x01
120 cna_interval_t interval;
126 /*! Data types for volume performance statistics {{{
128 * \brief Persistent data for volume performance data.
130 * The code below uses the difference of the operations and latency counters to
131 * calculate an average per-operation latency. For this, old counters need to
132 * be stored in the "data_volume_perf_t" structure. The byte-counters are just
133 * kept for completeness sake. The "flags" member indicates if each counter is
136 * The "cna_handle_volume_perf_data" function will fill a new struct of this
137 * type and pass both, old and new data, to "submit_volume_perf_data". In that
138 * function, the per-operation latency is calculated and dispatched, then the
139 * old counters are updated.
141 #define CFG_VOLUME_PERF_INIT 0x0001
142 #define CFG_VOLUME_PERF_IO 0x0002
143 #define CFG_VOLUME_PERF_OPS 0x0003
144 #define CFG_VOLUME_PERF_LATENCY 0x0008
145 #define CFG_VOLUME_PERF_ALL 0x000F
146 #define HAVE_VOLUME_PERF_BYTES_READ 0x0010
147 #define HAVE_VOLUME_PERF_BYTES_WRITE 0x0020
148 #define HAVE_VOLUME_PERF_OPS_READ 0x0040
149 #define HAVE_VOLUME_PERF_OPS_WRITE 0x0080
150 #define HAVE_VOLUME_PERF_LATENCY_READ 0x0100
151 #define HAVE_VOLUME_PERF_LATENCY_WRITE 0x0200
152 #define HAVE_VOLUME_PERF_ALL 0x03F0
153 struct data_volume_perf_s;
154 typedef struct data_volume_perf_s data_volume_perf_t;
155 struct data_volume_perf_s {
161 uint64_t write_bytes;
164 uint64_t read_latency;
165 uint64_t write_latency;
167 data_volume_perf_t *next;
171 cna_interval_t interval;
174 ignorelist_t *il_octets;
175 ignorelist_t *il_operations;
176 ignorelist_t *il_latency;
178 data_volume_perf_t *volumes;
180 /* }}} data_volume_perf_t */
182 /*! Data types for volume usage statistics {{{
184 * \brief Configuration struct for volume usage data (free / used).
186 #define CFG_VOLUME_USAGE_DF 0x0002
187 #define CFG_VOLUME_USAGE_SNAP 0x0004
188 #define CFG_VOLUME_USAGE_ALL 0x0006
189 #define HAVE_VOLUME_USAGE_NORM_FREE 0x0010
190 #define HAVE_VOLUME_USAGE_NORM_USED 0x0020
191 #define HAVE_VOLUME_USAGE_SNAP_RSVD 0x0040
192 #define HAVE_VOLUME_USAGE_SNAP_USED 0x0080
193 #define HAVE_VOLUME_USAGE_SIS_SAVED 0x0100
194 #define HAVE_VOLUME_USAGE_COMPRESS_SAVED 0x0200
195 #define HAVE_VOLUME_USAGE_DEDUP_SAVED 0x0400
196 #define HAVE_VOLUME_USAGE_ALL 0x07f0
197 #define IS_VOLUME_USAGE_OFFLINE 0x0800
198 struct data_volume_usage_s;
199 typedef struct data_volume_usage_s data_volume_usage_t;
200 struct data_volume_usage_s {
204 na_elem_t *snap_query;
208 uint64_t snap_reserved;
211 uint64_t compress_saved;
212 uint64_t dedup_saved;
214 data_volume_usage_t *next;
218 cna_interval_t interval;
221 ignorelist_t *il_capacity;
222 ignorelist_t *il_snapshot;
224 data_volume_usage_t *volumes;
225 } cfg_volume_usage_t;
226 /* }}} cfg_volume_usage_t */
228 /*! Data types for quota statistics {{{
230 * \brief Persistent data for quota statistics
233 cna_interval_t interval;
236 /* }}} cfg_quota_t */
238 /*! Data types for SnapVault statistics {{{
240 * \brief Persistent data for SnapVault(R) statistics
243 cna_interval_t interval;
246 /* }}} cfg_snapvault_t */
248 /*! Data types for system statistics {{{
250 * \brief Persistent data for system performance counters
252 #define CFG_SYSTEM_CPU 0x01
253 #define CFG_SYSTEM_NET 0x02
254 #define CFG_SYSTEM_OPS 0x04
255 #define CFG_SYSTEM_DISK 0x08
256 #define CFG_SYSTEM_ALL 0x0F
259 cna_interval_t interval;
262 /* }}} cfg_system_t */
264 struct host_config_s {
266 na_server_transport_t protocol;
275 cfg_wafl_t *cfg_wafl;
276 cfg_disk_t *cfg_disk;
277 cfg_volume_perf_t *cfg_volume_perf;
278 cfg_volume_usage_t *cfg_volume_usage;
279 cfg_quota_t *cfg_quota;
280 cfg_snapvault_t *cfg_snapvault;
281 cfg_system_t *cfg_system;
283 struct host_config_s *next;
289 * Used to free the various structures above.
291 static void free_disk (disk_t *disk) /* {{{ */
304 } /* }}} void free_disk */
306 static void free_cfg_wafl (cfg_wafl_t *cw) /* {{{ */
311 if (cw->query != NULL)
312 na_elem_free (cw->query);
315 } /* }}} void free_cfg_wafl */
317 static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
319 if (cfg_disk == NULL)
322 if (cfg_disk->query != NULL)
323 na_elem_free (cfg_disk->query);
325 free_disk (cfg_disk->disks);
327 } /* }}} void free_cfg_disk */
329 static void free_cfg_volume_perf (cfg_volume_perf_t *cvp) /* {{{ */
331 data_volume_perf_t *data;
336 /* Free the ignorelists */
337 ignorelist_free (cvp->il_octets);
338 ignorelist_free (cvp->il_operations);
339 ignorelist_free (cvp->il_latency);
341 /* Free the linked list of volumes */
345 data_volume_perf_t *next = data->next;
351 if (cvp->query != NULL)
352 na_elem_free (cvp->query);
355 } /* }}} void free_cfg_volume_perf */
357 static void free_cfg_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
359 data_volume_usage_t *data;
364 /* Free the ignorelists */
365 ignorelist_free (cvu->il_capacity);
366 ignorelist_free (cvu->il_snapshot);
368 /* Free the linked list of volumes */
372 data_volume_usage_t *next = data->next;
374 if (data->snap_query != NULL)
375 na_elem_free(data->snap_query);
380 if (cvu->query != NULL)
381 na_elem_free (cvu->query);
384 } /* }}} void free_cfg_volume_usage */
386 static void free_cfg_quota (cfg_quota_t *q) /* {{{ */
391 if (q->query != NULL)
392 na_elem_free (q->query);
395 } /* }}} void free_cfg_quota */
397 static void free_cfg_snapvault (cfg_snapvault_t *sv) /* {{{ */
402 if (sv->query != NULL)
403 na_elem_free (sv->query);
406 } /* }}} void free_cfg_snapvault */
408 static void free_cfg_system (cfg_system_t *cs) /* {{{ */
413 if (cs->query != NULL)
414 na_elem_free (cs->query);
417 } /* }}} void free_cfg_system */
419 static void free_host_config (host_config_t *hc) /* {{{ */
430 sfree (hc->username);
431 sfree (hc->password);
434 free_cfg_disk (hc->cfg_disk);
435 free_cfg_wafl (hc->cfg_wafl);
436 free_cfg_volume_perf (hc->cfg_volume_perf);
437 free_cfg_volume_usage (hc->cfg_volume_usage);
438 free_cfg_quota (hc->cfg_quota);
439 free_cfg_snapvault (hc->cfg_snapvault);
440 free_cfg_system (hc->cfg_system);
443 na_server_close (hc->srv);
447 free_host_config (next);
448 } /* }}} void free_host_config */
451 * Auxiliary functions
453 * Used to look up volumes and disks or to handle flags.
455 static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
459 if ((cd == NULL) || (name == NULL))
462 for (d = cd->disks; d != NULL; d = d->next) {
463 if (strcmp(d->name, name) == 0)
467 d = malloc(sizeof(*d));
470 memset (d, 0, 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 = malloc (sizeof (*new));
519 memset (new, 0, sizeof (*new));
522 new->name = strdup (name);
523 if (new->name == NULL)
529 if (ignore_capacity == 0)
530 new->flags |= CFG_VOLUME_USAGE_DF;
531 if (ignore_snapshot == 0) {
532 new->flags |= CFG_VOLUME_USAGE_SNAP;
533 new->snap_query = na_elem_new ("snapshot-list-info");
534 na_child_add_string(new->snap_query, "target-type", "volume");
535 na_child_add_string(new->snap_query, "target-name", name);
537 new->snap_query = NULL;
540 /* Add to end of list. */
547 } /* }}} data_volume_usage_t *get_volume_usage */
549 static data_volume_perf_t *get_volume_perf (cfg_volume_perf_t *cvp, /* {{{ */
552 data_volume_perf_t *last;
553 data_volume_perf_t *new;
555 int ignore_octets = 0;
556 int ignore_operations = 0;
557 int ignore_latency = 0;
559 if ((cvp == NULL) || (name == NULL))
565 if (strcmp (last->name, name) == 0)
568 if (last->next == NULL)
574 /* Check the ignorelists. If *all three* tell us to ignore a volume, return
576 ignore_octets = ignorelist_match (cvp->il_octets, name);
577 ignore_operations = ignorelist_match (cvp->il_operations, name);
578 ignore_latency = ignorelist_match (cvp->il_latency, name);
579 if ((ignore_octets != 0) || (ignore_operations != 0)
580 || (ignore_latency != 0))
583 /* Not found: allocate. */
584 new = malloc (sizeof (*new));
587 memset (new, 0, sizeof (*new));
590 new->name = strdup (name);
591 if (new->name == NULL)
597 if (ignore_octets == 0)
598 new->flags |= CFG_VOLUME_PERF_IO;
599 if (ignore_operations == 0)
600 new->flags |= CFG_VOLUME_PERF_OPS;
601 if (ignore_latency == 0)
602 new->flags |= CFG_VOLUME_PERF_LATENCY;
604 /* Add to end of list. */
611 } /* }}} data_volume_perf_t *get_volume_perf */
614 * Various submit functions.
616 * They all eventually call "submit_values" which creates a value_list_t and
617 * dispatches it to the daemon.
619 static int submit_values (const char *host, /* {{{ */
620 const char *plugin_inst,
621 const char *type, const char *type_inst,
622 value_t *values, int values_len,
623 cdtime_t timestamp, cdtime_t interval)
625 value_list_t vl = VALUE_LIST_INIT;
628 vl.values_len = values_len;
634 vl.interval = interval;
637 sstrncpy (vl.host, host, sizeof (vl.host));
639 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
640 sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
641 if (plugin_inst != NULL)
642 sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
643 sstrncpy (vl.type, type, sizeof (vl.type));
644 if (type_inst != NULL)
645 sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
647 return (plugin_dispatch_values (&vl));
648 } /* }}} int submit_uint64 */
650 static int submit_two_derive (const char *host, const char *plugin_inst, /* {{{ */
651 const char *type, const char *type_inst, derive_t val0, derive_t val1,
652 cdtime_t timestamp, cdtime_t interval)
656 values[0].derive = val0;
657 values[1].derive = val1;
659 return (submit_values (host, plugin_inst, type, type_inst,
660 values, 2, timestamp, interval));
661 } /* }}} int submit_two_derive */
663 static int submit_derive (const char *host, const char *plugin_inst, /* {{{ */
664 const char *type, const char *type_inst, derive_t counter,
665 cdtime_t timestamp, cdtime_t interval)
671 return (submit_values (host, plugin_inst, type, type_inst,
672 &v, 1, timestamp, interval));
673 } /* }}} int submit_derive */
675 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
676 const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
677 cdtime_t timestamp, cdtime_t interval)
681 values[0].gauge = val0;
682 values[1].gauge = val1;
684 return (submit_values (host, plugin_inst, type, type_inst,
685 values, 2, timestamp, interval));
686 } /* }}} int submit_two_gauge */
688 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
689 const char *type, const char *type_inst, double d,
690 cdtime_t timestamp, cdtime_t interval)
694 v.gauge = (gauge_t) d;
696 return (submit_values (host, plugin_inst, type, type_inst,
697 &v, 1, timestamp, interval));
698 } /* }}} int submit_uint64 */
700 /* Calculate hit ratio from old and new counters and submit the resulting
701 * percentage. Used by "submit_wafl_data". */
702 static int submit_cache_ratio (const char *host, /* {{{ */
703 const char *plugin_inst,
704 const char *type_inst,
714 if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
718 hits = new_hits - old_hits;
719 misses = new_misses - old_misses;
721 v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
726 return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
727 &v, 1, timestamp, interval));
728 } /* }}} int submit_cache_ratio */
730 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
731 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
732 cfg_wafl_t *old_data, const cfg_wafl_t *new_data, int interval)
734 /* Submit requested counters */
735 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
736 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
737 submit_cache_ratio (hostname, instance, "name_cache_hit",
738 new_data->name_cache_hit, new_data->name_cache_miss,
739 old_data->name_cache_hit, old_data->name_cache_miss,
740 new_data->timestamp, interval);
742 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
743 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
744 submit_cache_ratio (hostname, instance, "find_dir_hit",
745 new_data->find_dir_hit, new_data->find_dir_miss,
746 old_data->find_dir_hit, old_data->find_dir_miss,
747 new_data->timestamp, interval);
749 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
750 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
751 submit_cache_ratio (hostname, instance, "buf_hash_hit",
752 new_data->buf_hash_hit, new_data->buf_hash_miss,
753 old_data->buf_hash_hit, old_data->buf_hash_miss,
754 new_data->timestamp, interval);
756 if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
757 && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
758 submit_cache_ratio (hostname, instance, "inode_cache_hit",
759 new_data->inode_cache_hit, new_data->inode_cache_miss,
760 old_data->inode_cache_hit, old_data->inode_cache_miss,
761 new_data->timestamp, interval);
763 /* Clear old HAVE_* flags */
764 old_data->flags &= ~HAVE_WAFL_ALL;
766 /* Copy all counters */
767 old_data->timestamp = new_data->timestamp;
768 old_data->name_cache_hit = new_data->name_cache_hit;
769 old_data->name_cache_miss = new_data->name_cache_miss;
770 old_data->find_dir_hit = new_data->find_dir_hit;
771 old_data->find_dir_miss = new_data->find_dir_miss;
772 old_data->buf_hash_hit = new_data->buf_hash_hit;
773 old_data->buf_hash_miss = new_data->buf_hash_miss;
774 old_data->inode_cache_hit = new_data->inode_cache_hit;
775 old_data->inode_cache_miss = new_data->inode_cache_miss;
777 /* Copy HAVE_* flags */
778 old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
781 } /* }}} int submit_wafl_data */
783 /* Submits volume performance data to the daemon, taking care to honor and
784 * update flags appropriately. */
785 static int submit_volume_perf_data (const char *hostname, /* {{{ */
786 data_volume_perf_t *old_data,
787 const data_volume_perf_t *new_data, int interval)
789 char plugin_instance[DATA_MAX_NAME_LEN];
791 if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL))
794 ssnprintf (plugin_instance, sizeof (plugin_instance),
795 "volume-%s", old_data->name);
797 /* Check for and submit disk-octet values */
798 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_IO)
799 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
801 submit_two_derive (hostname, plugin_instance, "disk_octets", /* type instance = */ NULL,
802 (derive_t) new_data->read_bytes, (derive_t) new_data->write_bytes, new_data->timestamp, interval);
805 /* Check for and submit disk-operations values */
806 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_OPS)
807 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
809 submit_two_derive (hostname, plugin_instance, "disk_ops", /* type instance = */ NULL,
810 (derive_t) new_data->read_ops, (derive_t) new_data->write_ops, new_data->timestamp, interval);
813 /* Check for, calculate and submit disk-latency values */
814 if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_LATENCY
815 | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
816 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
817 && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
818 | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
820 gauge_t latency_per_op_read;
821 gauge_t latency_per_op_write;
823 latency_per_op_read = NAN;
824 latency_per_op_write = NAN;
826 /* Check if a counter wrapped around. */
827 if ((new_data->read_ops > old_data->read_ops)
828 && (new_data->read_latency > old_data->read_latency))
830 uint64_t diff_ops_read;
831 uint64_t diff_latency_read;
833 diff_ops_read = new_data->read_ops - old_data->read_ops;
834 diff_latency_read = new_data->read_latency - old_data->read_latency;
836 if (diff_ops_read > 0)
837 latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
840 if ((new_data->write_ops > old_data->write_ops)
841 && (new_data->write_latency > old_data->write_latency))
843 uint64_t diff_ops_write;
844 uint64_t diff_latency_write;
846 diff_ops_write = new_data->write_ops - old_data->write_ops;
847 diff_latency_write = new_data->write_latency - old_data->write_latency;
849 if (diff_ops_write > 0)
850 latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
853 submit_two_gauge (hostname, plugin_instance, "disk_latency", /* type instance = */ NULL,
854 latency_per_op_read, latency_per_op_write, new_data->timestamp, interval);
857 /* Clear all HAVE_* flags. */
858 old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
860 /* Copy all counters */
861 old_data->timestamp = new_data->timestamp;
862 old_data->read_bytes = new_data->read_bytes;
863 old_data->write_bytes = new_data->write_bytes;
864 old_data->read_ops = new_data->read_ops;
865 old_data->write_ops = new_data->write_ops;
866 old_data->read_latency = new_data->read_latency;
867 old_data->write_latency = new_data->write_latency;
869 /* Copy the HAVE_* flags */
870 old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
873 } /* }}} int submit_volume_perf_data */
875 static cdtime_t cna_child_get_cdtime (na_elem_t *data) /* {{{ */
879 t = (time_t) na_child_get_uint64 (data, "timestamp", /* default = */ 0);
881 return (TIME_T_TO_CDTIME_T (t));
882 } /* }}} cdtime_t cna_child_get_cdtime */
888 * These functions are called with appropriate data returned by the libnetapp
889 * interface which is parsed and submitted with the above functions.
891 /* Data corresponding to <WAFL /> */
892 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
893 na_elem_t *data, int interval)
895 cfg_wafl_t perf_data;
896 const char *plugin_inst;
898 na_elem_t *instances;
900 na_elem_iter_t counter_iter;
902 memset (&perf_data, 0, sizeof (perf_data));
904 perf_data.timestamp = cna_child_get_cdtime (data);
906 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
907 if (instances == NULL)
909 ERROR ("netapp plugin: cna_handle_wafl_data: "
910 "na_elem_child (\"instances\") failed "
911 "for host %s.", hostname);
915 plugin_inst = na_child_get_string(instances, "name");
916 if (plugin_inst == NULL)
918 ERROR ("netapp plugin: cna_handle_wafl_data: "
919 "na_child_get_string (\"name\") failed "
920 "for host %s.", hostname);
924 /* Iterate over all counters */
925 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
926 for (counter = na_iterator_next (&counter_iter);
928 counter = na_iterator_next (&counter_iter))
933 name = na_child_get_string(counter, "name");
937 value = na_child_get_uint64(counter, "value", UINT64_MAX);
938 if (value == UINT64_MAX)
941 if (!strcmp(name, "name_cache_hit")) {
942 perf_data.name_cache_hit = value;
943 perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
944 } else if (!strcmp(name, "name_cache_miss")) {
945 perf_data.name_cache_miss = value;
946 perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
947 } else if (!strcmp(name, "find_dir_hit")) {
948 perf_data.find_dir_hit = value;
949 perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
950 } else if (!strcmp(name, "find_dir_miss")) {
951 perf_data.find_dir_miss = value;
952 perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
953 } else if (!strcmp(name, "buf_hash_hit")) {
954 perf_data.buf_hash_hit = value;
955 perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
956 } else if (!strcmp(name, "buf_hash_miss")) {
957 perf_data.buf_hash_miss = value;
958 perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
959 } else if (!strcmp(name, "inode_cache_hit")) {
960 perf_data.inode_cache_hit = value;
961 perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
962 } else if (!strcmp(name, "inode_cache_miss")) {
963 perf_data.inode_cache_miss = value;
964 perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
966 DEBUG("netapp plugin: cna_handle_wafl_data: "
967 "Found unexpected child: %s "
968 "for host %s.", name, hostname);
972 return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data, interval));
973 } /* }}} void cna_handle_wafl_data */
975 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
982 if (cw->query != NULL)
985 cw->query = na_elem_new("perf-object-get-instances");
986 if (cw->query == NULL)
988 ERROR ("netapp plugin: na_elem_new failed.");
991 na_child_add_string (cw->query, "objectname", "wafl");
993 e = na_elem_new("counters");
996 na_elem_free (cw->query);
998 ERROR ("netapp plugin: na_elem_new failed.");
1001 na_child_add_string(e, "counter", "name_cache_hit");
1002 na_child_add_string(e, "counter", "name_cache_miss");
1003 na_child_add_string(e, "counter", "find_dir_hit");
1004 na_child_add_string(e, "counter", "find_dir_miss");
1005 na_child_add_string(e, "counter", "buf_hash_hit");
1006 na_child_add_string(e, "counter", "buf_hash_miss");
1007 na_child_add_string(e, "counter", "inode_cache_hit");
1008 na_child_add_string(e, "counter", "inode_cache_miss");
1010 na_child_add(cw->query, e);
1013 } /* }}} int cna_setup_wafl */
1015 static int cna_query_wafl (host_config_t *host) /* {{{ */
1024 /* If WAFL was not configured, return without doing anything. */
1025 if (host->cfg_wafl == NULL)
1029 if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
1032 status = cna_setup_wafl (host->cfg_wafl);
1035 assert (host->cfg_wafl->query != NULL);
1037 data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
1038 if (na_results_status (data) != NA_OK)
1040 ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed for host %s: %s",
1041 host->name, na_results_reason (data));
1042 na_elem_free (data);
1046 status = cna_handle_wafl_data (host->name, host->cfg_wafl, data, host->interval);
1049 host->cfg_wafl->interval.last_read = now;
1051 na_elem_free (data);
1053 } /* }}} int cna_query_wafl */
1055 /* Data corresponding to <Disks /> */
1056 static int cna_handle_disk_data (const char *hostname, /* {{{ */
1057 cfg_disk_t *cfg_disk, na_elem_t *data, cdtime_t interval)
1060 na_elem_t *instances;
1061 na_elem_t *instance;
1062 na_elem_iter_t instance_iter;
1063 disk_t *worst_disk = NULL;
1065 if ((cfg_disk == NULL) || (data == NULL))
1068 timestamp = cna_child_get_cdtime (data);
1070 instances = na_elem_child (data, "instances");
1071 if (instances == NULL)
1073 ERROR ("netapp plugin: cna_handle_disk_data: "
1074 "na_elem_child (\"instances\") failed "
1075 "for host %s.", hostname);
1079 /* Iterate over all children */
1080 instance_iter = na_child_iterator (instances);
1081 for (instance = na_iterator_next (&instance_iter);
1083 instance = na_iterator_next(&instance_iter))
1088 na_elem_iter_t counter_iterator;
1091 memset (&new_data, 0, sizeof (new_data));
1092 new_data.timestamp = timestamp;
1093 new_data.disk_busy_percent = NAN;
1095 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
1096 if (old_data == NULL)
1099 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
1100 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
1101 for (counter = na_iterator_next(&counter_iterator);
1103 counter = na_iterator_next(&counter_iterator))
1108 name = na_child_get_string(counter, "name");
1112 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1113 if (value == UINT64_MAX)
1116 if (strcmp(name, "disk_busy") == 0)
1118 new_data.disk_busy = value;
1119 new_data.flags |= HAVE_DISK_BUSY;
1121 else if (strcmp(name, "base_for_disk_busy") == 0)
1123 new_data.base_for_disk_busy = value;
1124 new_data.flags |= HAVE_DISK_BASE;
1128 DEBUG ("netapp plugin: cna_handle_disk_data: "
1129 "Counter not handled: %s = %"PRIu64,
1134 /* If all required counters are available and did not just wrap around,
1135 * calculate the busy percentage. Otherwise, the value is initialized to
1136 * NAN at the top of the for-loop. */
1137 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1138 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1139 && (new_data.disk_busy >= old_data->disk_busy)
1140 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
1145 busy_diff = new_data.disk_busy - old_data->disk_busy;
1146 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
1148 new_data.disk_busy_percent = 100.0
1149 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
1152 /* Clear HAVE_* flags */
1153 old_data->flags &= ~HAVE_DISK_ALL;
1156 old_data->timestamp = new_data.timestamp;
1157 old_data->disk_busy = new_data.disk_busy;
1158 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
1159 old_data->disk_busy_percent = new_data.disk_busy_percent;
1162 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
1164 if ((worst_disk == NULL)
1165 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
1166 worst_disk = old_data;
1167 } /* for (all disks) */
1169 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
1170 submit_double (hostname, "system", "percent", "disk_busy",
1171 worst_disk->disk_busy_percent, timestamp, interval);
1174 } /* }}} int cna_handle_disk_data */
1176 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
1183 if (cd->query != NULL)
1186 cd->query = na_elem_new ("perf-object-get-instances");
1187 if (cd->query == NULL)
1189 ERROR ("netapp plugin: na_elem_new failed.");
1192 na_child_add_string (cd->query, "objectname", "disk");
1194 e = na_elem_new("counters");
1197 na_elem_free (cd->query);
1199 ERROR ("netapp plugin: na_elem_new failed.");
1202 na_child_add_string(e, "counter", "disk_busy");
1203 na_child_add_string(e, "counter", "base_for_disk_busy");
1204 na_child_add(cd->query, e);
1207 } /* }}} int cna_setup_disk */
1209 static int cna_query_disk (host_config_t *host) /* {{{ */
1218 /* If the user did not configure disk statistics, return without doing
1220 if (host->cfg_disk == NULL)
1224 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1227 status = cna_setup_disk (host->cfg_disk);
1230 assert (host->cfg_disk->query != NULL);
1232 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1233 if (na_results_status (data) != NA_OK)
1235 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed for host %s: %s",
1236 host->name, na_results_reason (data));
1237 na_elem_free (data);
1241 status = cna_handle_disk_data (host->name, host->cfg_disk, data, host->interval);
1244 host->cfg_disk->interval.last_read = now;
1246 na_elem_free (data);
1248 } /* }}} int cna_query_disk */
1250 /* Data corresponding to <VolumePerf /> */
1251 static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
1252 cfg_volume_perf_t *cvp, na_elem_t *data, cdtime_t interval)
1255 na_elem_t *elem_instances;
1256 na_elem_iter_t iter_instances;
1257 na_elem_t *elem_instance;
1259 timestamp = cna_child_get_cdtime (data);
1261 elem_instances = na_elem_child(data, "instances");
1262 if (elem_instances == NULL)
1264 ERROR ("netapp plugin: handle_volume_perf_data: "
1265 "na_elem_child (\"instances\") failed "
1266 "for host %s.", hostname);
1270 iter_instances = na_child_iterator (elem_instances);
1271 for (elem_instance = na_iterator_next(&iter_instances);
1272 elem_instance != NULL;
1273 elem_instance = na_iterator_next(&iter_instances))
1277 data_volume_perf_t perf_data;
1278 data_volume_perf_t *v;
1280 na_elem_t *elem_counters;
1281 na_elem_iter_t iter_counters;
1282 na_elem_t *elem_counter;
1284 memset (&perf_data, 0, sizeof (perf_data));
1285 perf_data.timestamp = timestamp;
1287 name = na_child_get_string (elem_instance, "name");
1291 /* get_volume_perf may return NULL if this volume is to be ignored. */
1292 v = get_volume_perf (cvp, name);
1296 elem_counters = na_elem_child (elem_instance, "counters");
1297 if (elem_counters == NULL)
1300 iter_counters = na_child_iterator (elem_counters);
1301 for (elem_counter = na_iterator_next(&iter_counters);
1302 elem_counter != NULL;
1303 elem_counter = na_iterator_next(&iter_counters))
1308 name = na_child_get_string (elem_counter, "name");
1312 value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
1313 if (value == UINT64_MAX)
1316 if (!strcmp(name, "read_data")) {
1317 perf_data.read_bytes = value;
1318 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1319 } else if (!strcmp(name, "write_data")) {
1320 perf_data.write_bytes = value;
1321 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1322 } else if (!strcmp(name, "read_ops")) {
1323 perf_data.read_ops = value;
1324 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1325 } else if (!strcmp(name, "write_ops")) {
1326 perf_data.write_ops = value;
1327 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1328 } else if (!strcmp(name, "read_latency")) {
1329 perf_data.read_latency = value;
1330 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1331 } else if (!strcmp(name, "write_latency")) {
1332 perf_data.write_latency = value;
1333 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1335 } /* for (elem_counter) */
1337 submit_volume_perf_data (hostname, v, &perf_data, interval);
1338 } /* for (volume) */
1341 } /* }}} int cna_handle_volume_perf_data */
1343 static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
1350 if (cd->query != NULL)
1353 cd->query = na_elem_new ("perf-object-get-instances");
1354 if (cd->query == NULL)
1356 ERROR ("netapp plugin: na_elem_new failed.");
1359 na_child_add_string (cd->query, "objectname", "volume");
1361 e = na_elem_new("counters");
1364 na_elem_free (cd->query);
1366 ERROR ("netapp plugin: na_elem_new failed.");
1369 na_child_add_string(e, "counter", "read_ops");
1370 na_child_add_string(e, "counter", "write_ops");
1371 na_child_add_string(e, "counter", "read_data");
1372 na_child_add_string(e, "counter", "write_data");
1373 na_child_add_string(e, "counter", "read_latency");
1374 na_child_add_string(e, "counter", "write_latency");
1375 na_child_add(cd->query, e);
1378 } /* }}} int cna_setup_volume_perf */
1380 static int cna_query_volume_perf (host_config_t *host) /* {{{ */
1389 /* If the user did not configure volume performance statistics, return
1390 * without doing anything. */
1391 if (host->cfg_volume_perf == NULL)
1395 if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
1398 status = cna_setup_volume_perf (host->cfg_volume_perf);
1401 assert (host->cfg_volume_perf->query != NULL);
1403 data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
1404 if (na_results_status (data) != NA_OK)
1406 ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed for host %s: %s",
1407 host->name, na_results_reason (data));
1408 na_elem_free (data);
1412 status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data, host->interval);
1415 host->cfg_volume_perf->interval.last_read = now;
1417 na_elem_free (data);
1419 } /* }}} int cna_query_volume_perf */
1421 /* Data corresponding to <VolumeUsage /> */
1422 static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
1423 cfg_volume_usage_t *cfg_volume, int interval)
1425 data_volume_usage_t *v;
1427 for (v = cfg_volume->volumes; v != NULL; v = v->next)
1429 char plugin_instance[DATA_MAX_NAME_LEN];
1431 uint64_t norm_used = v->norm_used;
1432 uint64_t norm_free = v->norm_free;
1433 uint64_t sis_saved = v->sis_saved;
1434 uint64_t compress_saved = v->compress_saved;
1435 uint64_t dedup_saved = v->dedup_saved;
1436 uint64_t snap_reserve_used = 0;
1437 uint64_t snap_reserve_free = v->snap_reserved;
1438 uint64_t snap_norm_used = v->snap_used;
1440 ssnprintf (plugin_instance, sizeof (plugin_instance),
1441 "volume-%s", v->name);
1443 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD)) {
1444 if (v->snap_reserved > v->snap_used) {
1445 snap_reserve_free = v->snap_reserved - v->snap_used;
1446 snap_reserve_used = v->snap_used;
1449 snap_reserve_free = 0;
1450 snap_reserve_used = v->snap_reserved;
1451 snap_norm_used = v->snap_used - v->snap_reserved;
1455 /* The space used by snapshots but not reserved for them is included in
1456 * both, norm_used and snap_norm_used. If possible, subtract this here. */
1457 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED))
1459 if (norm_used >= snap_norm_used)
1460 norm_used -= snap_norm_used;
1463 ERROR ("netapp plugin: (norm_used = %"PRIu64") < (snap_norm_used = "
1464 "%"PRIu64") for host %s. Invalidating both.",
1465 norm_used, snap_norm_used, hostname);
1466 v->flags &= ~(HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED);
1470 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1471 submit_double (hostname, /* plugin instance = */ plugin_instance,
1472 "df_complex", "free",
1473 (double) norm_free, /* timestamp = */ 0, interval);
1475 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1476 submit_double (hostname, /* plugin instance = */ plugin_instance,
1477 "df_complex", "sis_saved",
1478 (double) sis_saved, /* timestamp = */ 0, interval);
1480 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_COMPRESS_SAVED))
1481 submit_double (hostname, /* plugin instance = */ plugin_instance,
1482 "df_complex", "compression_saved",
1483 (double) compress_saved, /* timestamp = */ 0, interval);
1485 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_DEDUP_SAVED))
1486 submit_double (hostname, /* plugin instance = */ plugin_instance,
1487 "df_complex", "dedup_saved",
1488 (double) dedup_saved, /* timestamp = */ 0, interval);
1490 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1491 submit_double (hostname, /* plugin instance = */ plugin_instance,
1492 "df_complex", "used",
1493 (double) norm_used, /* timestamp = */ 0, interval);
1495 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1496 submit_double (hostname, /* plugin instance = */ plugin_instance,
1497 "df_complex", "snap_reserved",
1498 (double) snap_reserve_free, /* timestamp = */ 0, interval);
1500 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD))
1501 submit_double (hostname, /* plugin instance = */ plugin_instance,
1502 "df_complex", "snap_reserve_used",
1503 (double) snap_reserve_used, /* timestamp = */ 0, interval);
1505 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1506 submit_double (hostname, /* plugin instance = */ plugin_instance,
1507 "df_complex", "snap_normal_used",
1508 (double) snap_norm_used, /* timestamp = */ 0, interval);
1510 /* Clear all the HAVE_* flags */
1511 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1512 } /* for (v = cfg_volume->volumes) */
1515 } /* }}} int cna_submit_volume_usage_data */
1517 /* Switch the state of a volume between online and offline and send out a
1519 static int cna_change_volume_status (const char *hostname, /* {{{ */
1520 data_volume_usage_t *v)
1524 memset (&n, 0, sizeof (&n));
1526 sstrncpy (n.host, hostname, sizeof (n.host));
1527 sstrncpy (n.plugin, "netapp", sizeof (n.plugin));
1528 sstrncpy (n.plugin_instance, v->name, sizeof (n.plugin_instance));
1530 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0) {
1531 n.severity = NOTIF_OKAY;
1532 ssnprintf (n.message, sizeof (n.message),
1533 "Volume %s is now online.", v->name);
1534 v->flags &= ~IS_VOLUME_USAGE_OFFLINE;
1536 n.severity = NOTIF_WARNING;
1537 ssnprintf (n.message, sizeof (n.message),
1538 "Volume %s is now offline.", v->name);
1539 v->flags |= IS_VOLUME_USAGE_OFFLINE;
1542 return (plugin_dispatch_notification (&n));
1543 } /* }}} int cna_change_volume_status */
1545 static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
1546 data_volume_usage_t *v)
1548 uint64_t snap_used = 0, value;
1549 na_elem_t *data, *elem_snap, *elem_snapshots;
1550 na_elem_iter_t iter_snap;
1552 data = na_server_invoke_elem(host->srv, v->snap_query);
1553 if (na_results_status(data) != NA_OK)
1555 if (na_results_errno(data) == EVOLUMEOFFLINE) {
1556 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) == 0)
1557 cna_change_volume_status (host->name, v);
1559 ERROR ("netapp plugin: cna_handle_volume_snap_usage: na_server_invoke_elem for "
1560 "volume \"%s\" on host %s failed with error %d: %s", v->name,
1561 host->name, na_results_errno(data), na_results_reason(data));
1567 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0)
1568 cna_change_volume_status (host->name, v);
1570 elem_snapshots = na_elem_child (data, "snapshots");
1571 if (elem_snapshots == NULL)
1573 ERROR ("netapp plugin: cna_handle_volume_snap_usage: "
1574 "na_elem_child (\"snapshots\") failed "
1575 "for host %s.", host->name);
1580 iter_snap = na_child_iterator (elem_snapshots);
1581 for (elem_snap = na_iterator_next (&iter_snap);
1583 elem_snap = na_iterator_next (&iter_snap))
1585 value = na_child_get_uint64(elem_snap, "cumulative-total", 0);
1586 /* "cumulative-total" is the total size of the oldest snapshot plus all
1587 * newer ones in blocks (1KB). We therefore are looking for the highest
1588 * number of all snapshots - that's the size required for the snapshots. */
1589 if (value > snap_used)
1592 na_elem_free (data);
1593 /* snap_used is in 1024 byte blocks */
1594 v->snap_used = snap_used * 1024;
1595 v->flags |= HAVE_VOLUME_USAGE_SNAP_USED;
1596 } /* }}} void cna_handle_volume_snap_usage */
1598 static void cna_handle_volume_sis_data (const host_config_t *host, /* {{{ */
1599 data_volume_usage_t *v, na_elem_t *sis)
1601 const char *sis_state;
1602 uint64_t sis_saved_reported;
1604 if (na_elem_child(sis, "sis-info"))
1605 sis = na_elem_child(sis, "sis-info");
1607 sis_state = na_child_get_string(sis, "state");
1608 if (sis_state == NULL)
1611 /* If SIS is not enabled, there's nothing left to do for this volume. */
1612 if (strcmp ("enabled", sis_state) != 0)
1615 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1616 if (sis_saved_reported == UINT64_MAX)
1619 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1620 if ((sis_saved_reported >> 32) != 0) {
1621 /* In case they ever fix this bug. */
1622 v->sis_saved = sis_saved_reported;
1623 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1624 } else { /* really hacky work-around code. {{{ */
1625 uint64_t sis_saved_percent;
1626 uint64_t sis_saved_guess;
1627 uint64_t overflow_guess;
1628 uint64_t guess1, guess2, guess3;
1630 /* Check if we have v->norm_used. Without it, we cannot calculate
1631 * sis_saved_guess. */
1632 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1635 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1636 if (sis_saved_percent > 100)
1639 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1640 * will hopefully be fixed in later versions. To work around the bug, try
1641 * to figure out how often the 32bit integer wrapped around by using the
1642 * "percentage-saved" value. Because the percentage is in the range
1643 * [0-100], this should work as long as the saved space does not exceed
1645 /* percentage-saved = size-saved / (size-saved + size-used) */
1646 if (sis_saved_percent < 100)
1647 sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1649 sis_saved_guess = v->norm_used;
1651 overflow_guess = sis_saved_guess >> 32;
1652 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1653 guess2 = (overflow_guess << 32) + sis_saved_reported;
1654 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1656 if (sis_saved_guess < guess2) {
1657 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1658 v->sis_saved = guess1;
1660 v->sis_saved = guess2;
1662 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1663 v->sis_saved = guess2;
1665 v->sis_saved = guess3;
1667 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1668 } /* }}} end of 32-bit workaround */
1669 } /* }}} void cna_handle_volume_sis_data */
1671 /* ONTAP >= 8.1 uses SIS for managing dedup and compression */
1672 static void cna_handle_volume_sis_saved (const host_config_t *host, /* {{{ */
1673 data_volume_usage_t *v, na_elem_t *sis)
1677 if (na_elem_child(sis, "sis-info"))
1678 sis = na_elem_child(sis, "sis-info");
1680 saved = na_child_get_uint64(sis, "compress-saved", UINT64_MAX);
1681 if (saved != UINT64_MAX) {
1682 v->compress_saved = saved;
1683 v->flags |= HAVE_VOLUME_USAGE_COMPRESS_SAVED;
1686 saved = na_child_get_uint64(sis, "dedup-saved", UINT64_MAX);
1687 if (saved != UINT64_MAX) {
1688 v->dedup_saved = saved;
1689 v->flags |= HAVE_VOLUME_USAGE_DEDUP_SAVED;
1691 } /* }}} void cna_handle_volume_sis_saved */
1693 static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */
1694 cfg_volume_usage_t *cfg_volume, na_elem_t *data)
1696 na_elem_t *elem_volume;
1697 na_elem_t *elem_volumes;
1698 na_elem_iter_t iter_volume;
1700 elem_volumes = na_elem_child (data, "volumes");
1701 if (elem_volumes == NULL)
1703 ERROR ("netapp plugin: cna_handle_volume_usage_data: "
1704 "na_elem_child (\"volumes\") failed "
1705 "for host %s.", host->name);
1709 iter_volume = na_child_iterator (elem_volumes);
1710 for (elem_volume = na_iterator_next (&iter_volume);
1711 elem_volume != NULL;
1712 elem_volume = na_iterator_next (&iter_volume))
1714 const char *volume_name, *state;
1716 data_volume_usage_t *v;
1721 volume_name = na_child_get_string (elem_volume, "name");
1722 if (volume_name == NULL)
1725 state = na_child_get_string (elem_volume, "state");
1726 if ((state == NULL) || (strcmp(state, "online") != 0))
1729 /* get_volume_usage may return NULL if the volume is to be ignored. */
1730 v = get_volume_usage (cfg_volume, volume_name);
1734 if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
1735 cna_handle_volume_snap_usage(host, v);
1737 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1740 /* 2^4 exa-bytes? This will take a while ;) */
1741 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1742 if (value != UINT64_MAX) {
1743 v->norm_free = value;
1744 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1747 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1748 if (value != UINT64_MAX) {
1749 v->norm_used = value;
1750 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1753 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
1754 if (value != UINT64_MAX) {
1755 /* 1 block == 1024 bytes as per API docs */
1756 v->snap_reserved = 1024 * value;
1757 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1760 sis = na_elem_child(elem_volume, "sis");
1762 cna_handle_volume_sis_data (host, v, sis);
1763 cna_handle_volume_sis_saved (host, v, sis);
1765 } /* for (elem_volume) */
1767 return (cna_submit_volume_usage_data (host->name, cfg_volume, host->interval));
1768 } /* }}} int cna_handle_volume_usage_data */
1770 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
1775 if (cvu->query != NULL)
1778 cvu->query = na_elem_new ("volume-list-info");
1779 if (cvu->query == NULL)
1781 ERROR ("netapp plugin: na_elem_new failed.");
1786 } /* }}} int cna_setup_volume_usage */
1788 static int cna_query_volume_usage (host_config_t *host) /* {{{ */
1797 /* If the user did not configure volume_usage statistics, return without
1798 * doing anything. */
1799 if (host->cfg_volume_usage == NULL)
1803 if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
1806 status = cna_setup_volume_usage (host->cfg_volume_usage);
1809 assert (host->cfg_volume_usage->query != NULL);
1811 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1812 if (na_results_status (data) != NA_OK)
1814 ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed for host %s: %s",
1815 host->name, na_results_reason (data));
1816 na_elem_free (data);
1820 status = cna_handle_volume_usage_data (host, host->cfg_volume_usage, data);
1823 host->cfg_volume_usage->interval.last_read = now;
1825 na_elem_free (data);
1827 } /* }}} int cna_query_volume_usage */
1829 /* Data corresponding to <Quota /> */
1830 static int cna_handle_quota_data (const host_config_t *host, /* {{{ */
1831 cfg_quota_t *cfg_quota, na_elem_t *data)
1833 na_elem_t *elem_quota;
1834 na_elem_t *elem_quotas;
1835 na_elem_iter_t iter_quota;
1837 elem_quotas = na_elem_child (data, "quotas");
1838 if (elem_quotas == NULL)
1840 ERROR ("netapp plugin: cna_handle_quota_data: "
1841 "na_elem_child (\"quotas\") failed "
1842 "for host %s.", host->name);
1846 iter_quota = na_child_iterator (elem_quotas);
1847 for (elem_quota = na_iterator_next (&iter_quota);
1849 elem_quota = na_iterator_next (&iter_quota))
1851 const char *quota_type, *volume_name, *tree_name;
1854 char plugin_instance[DATA_MAX_NAME_LEN];
1856 quota_type = na_child_get_string (elem_quota, "quota-type");
1857 if (quota_type == NULL)
1860 /* possible TODO: support other types as well */
1861 if (strcmp (quota_type, "tree") != 0)
1864 tree_name = na_child_get_string (elem_quota, "tree");
1865 if ((tree_name == NULL) || (*tree_name == '\0'))
1868 volume_name = na_child_get_string (elem_quota, "volume");
1869 if (volume_name == NULL)
1872 ssnprintf (plugin_instance, sizeof (plugin_instance),
1873 "quota-%s-%s", volume_name, tree_name);
1875 value = na_child_get_uint64 (elem_quota, "disk-used", UINT64_MAX);
1876 if (value != UINT64_MAX) {
1877 value *= 1024; /* disk-used reports kilobytes */
1878 submit_double (host->name, plugin_instance,
1879 /* type = */ "df_complex", /* type instance = */ NULL,
1880 (double)value, /* timestamp = */ 0, host->interval);
1883 value = na_child_get_uint64 (elem_quota, "files-used", UINT64_MAX);
1884 if (value != UINT64_MAX) {
1885 submit_double (host->name, plugin_instance,
1886 /* type = */ "files", /* type instance = */ NULL,
1887 (double)value, /* timestamp = */ 0, host->interval);
1889 } /* for (elem_quota) */
1892 } /* }}} int cna_handle_volume_usage_data */
1894 static int cna_setup_quota (cfg_quota_t *cq) /* {{{ */
1899 if (cq->query != NULL)
1902 cq->query = na_elem_new ("quota-report");
1903 if (cq->query == NULL)
1905 ERROR ("netapp plugin: na_elem_new failed.");
1910 } /* }}} int cna_setup_quota */
1912 static int cna_query_quota (host_config_t *host) /* {{{ */
1921 /* If the user did not configure quota statistics, return without
1922 * doing anything. */
1923 if (host->cfg_quota == NULL)
1927 if ((host->cfg_quota->interval.interval + host->cfg_quota->interval.last_read) > now)
1930 status = cna_setup_quota (host->cfg_quota);
1933 assert (host->cfg_quota->query != NULL);
1935 data = na_server_invoke_elem (host->srv, host->cfg_quota->query);
1936 if (na_results_status (data) != NA_OK)
1938 ERROR ("netapp plugin: cna_query_quota: na_server_invoke_elem failed for host %s: %s",
1939 host->name, na_results_reason (data));
1940 na_elem_free (data);
1944 status = cna_handle_quota_data (host, host->cfg_quota, data);
1947 host->cfg_quota->interval.last_read = now;
1949 na_elem_free (data);
1951 } /* }}} int cna_query_quota */
1953 /* Data corresponding to <SnapVault /> */
1954 static int cna_handle_snapvault_data (const char *hostname, /* {{{ */
1955 cfg_snapvault_t *cfg_snapvault, na_elem_t *data, cdtime_t interval)
1958 na_elem_iter_t status_iter;
1960 status = na_elem_child (data, "status-list");
1962 ERROR ("netapp plugin: SnapVault status record missing status-list");
1966 status_iter = na_child_iterator (status);
1967 for (status = na_iterator_next (&status_iter);
1969 status = na_iterator_next (&status_iter))
1971 const char *dest_sys, *dest_path, *src_sys, *src_path;
1972 char plugin_instance[DATA_MAX_NAME_LEN];
1975 dest_sys = na_child_get_string (status, "destination-system");
1976 dest_path = na_child_get_string (status, "destination-path");
1977 src_sys = na_child_get_string (status, "source-system");
1978 src_path = na_child_get_string (status, "source-path");
1980 if ((! dest_sys) || (! dest_path) || (! src_sys) || (! src_path))
1983 value = na_child_get_uint64 (status, "lag-time", UINT64_MAX);
1984 if (value == UINT64_MAX) /* no successful baseline transfer yet */
1987 /* possible TODO: make plugin instance configurable */
1988 ssnprintf (plugin_instance, sizeof (plugin_instance),
1989 "snapvault-%s", dest_path);
1990 submit_double (hostname, plugin_instance, /* type = */ "delay", NULL,
1991 (double)value, /* timestamp = */ 0, interval);
1993 value = na_child_get_uint64 (status, "last-transfer-duration", UINT64_MAX);
1994 if (value != UINT64_MAX)
1995 submit_double (hostname, plugin_instance, /* type = */ "duration", "last_transfer",
1996 (double)value, /* timestamp = */ 0, interval);
1998 value = na_child_get_uint64 (status, "transfer-progress", UINT64_MAX);
1999 if (value == UINT64_MAX)
2000 value = na_child_get_uint64 (status, "last-transfer-size", UINT64_MAX);
2001 if (value != UINT64_MAX) {
2002 value *= 1024; /* this is kilobytes */
2003 submit_derive (hostname, plugin_instance, /* type = */ "if_rx_octets", "transferred",
2004 value, /* timestamp = */ 0, interval);
2006 } /* for (status) */
2009 } /* }}} int cna_handle_snapvault_data */
2011 static int cna_handle_snapvault_iter (host_config_t *host, /* {{{ */
2016 uint32_t records_count;
2019 records_count = na_child_get_uint32 (data, "records", UINT32_MAX);
2020 if (records_count == UINT32_MAX)
2023 tag = na_child_get_string (data, "tag");
2027 DEBUG ("netapp plugin: Iterating %u SV records (tag = %s)", records_count, tag);
2029 for (i = 0; i < records_count; ++i) {
2032 elem = na_server_invoke (host->srv,
2033 "snapvault-secondary-relationship-status-list-iter-next",
2034 "maximum", "1", "tag", tag, NULL);
2036 if (na_results_status (elem) != NA_OK)
2038 ERROR ("netapp plugin: cna_handle_snapvault_iter: "
2039 "na_server_invoke failed for host %s: %s",
2040 host->name, na_results_reason (data));
2041 na_elem_free (elem);
2045 cna_handle_snapvault_data (host->name, host->cfg_snapvault, elem, host->interval);
2046 na_elem_free (elem);
2049 na_elem_free (na_server_invoke (host->srv,
2050 "snapvault-secondary-relationship-status-list-iter-end",
2053 } /* }}} int cna_handle_snapvault_iter */
2055 static int cna_setup_snapvault (cfg_snapvault_t *sv) /* {{{ */
2060 if (sv->query != NULL)
2063 sv->query = na_elem_new ("snapvault-secondary-relationship-status-list-iter-start");
2064 if (sv->query == NULL)
2066 ERROR ("netapp plugin: na_elem_new failed.");
2071 } /* }}} int cna_setup_snapvault */
2073 static int cna_query_snapvault (host_config_t *host) /* {{{ */
2082 if (host->cfg_snapvault == NULL)
2086 if ((host->cfg_snapvault->interval.interval + host->cfg_snapvault->interval.last_read) > now)
2089 status = cna_setup_snapvault (host->cfg_snapvault);
2092 assert (host->cfg_snapvault->query != NULL);
2094 data = na_server_invoke_elem (host->srv, host->cfg_snapvault->query);
2095 if (na_results_status (data) != NA_OK)
2097 ERROR ("netapp plugin: cna_query_snapvault: na_server_invoke_elem failed for host %s: %s",
2098 host->name, na_results_reason (data));
2099 na_elem_free (data);
2103 status = cna_handle_snapvault_iter (host, data);
2106 host->cfg_snapvault->interval.last_read = now;
2108 na_elem_free (data);
2110 } /* }}} int cna_query_snapvault */
2112 /* Data corresponding to <System /> */
2113 static int cna_handle_system_data (const char *hostname, /* {{{ */
2114 cfg_system_t *cfg_system, na_elem_t *data, int interval)
2116 na_elem_t *instances;
2118 na_elem_iter_t counter_iter;
2120 derive_t disk_read = 0, disk_written = 0;
2121 derive_t net_recv = 0, net_sent = 0;
2122 derive_t cpu_busy = 0, cpu_total = 0;
2123 uint32_t counter_flags = 0;
2125 const char *instance;
2128 timestamp = cna_child_get_cdtime (data);
2130 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
2131 if (instances == NULL)
2133 ERROR ("netapp plugin: cna_handle_system_data: "
2134 "na_elem_child (\"instances\") failed "
2135 "for host %s.", hostname);
2139 instance = na_child_get_string (instances, "name");
2140 if (instance == NULL)
2142 ERROR ("netapp plugin: cna_handle_system_data: "
2143 "na_child_get_string (\"name\") failed "
2144 "for host %s.", hostname);
2148 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
2149 for (counter = na_iterator_next (&counter_iter);
2151 counter = na_iterator_next (&counter_iter))
2156 name = na_child_get_string(counter, "name");
2160 value = na_child_get_uint64(counter, "value", UINT64_MAX);
2161 if (value == UINT64_MAX)
2164 if (!strcmp(name, "disk_data_read")) {
2165 disk_read = (derive_t) (value * 1024);
2166 counter_flags |= 0x01;
2167 } else if (!strcmp(name, "disk_data_written")) {
2168 disk_written = (derive_t) (value * 1024);
2169 counter_flags |= 0x02;
2170 } else if (!strcmp(name, "net_data_recv")) {
2171 net_recv = (derive_t) (value * 1024);
2172 counter_flags |= 0x04;
2173 } else if (!strcmp(name, "net_data_sent")) {
2174 net_sent = (derive_t) (value * 1024);
2175 counter_flags |= 0x08;
2176 } else if (!strcmp(name, "cpu_busy")) {
2177 cpu_busy = (derive_t) value;
2178 counter_flags |= 0x10;
2179 } else if (!strcmp(name, "cpu_elapsed_time")) {
2180 cpu_total = (derive_t) value;
2181 counter_flags |= 0x20;
2182 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
2183 && (value > 0) && (strlen(name) > 4)
2184 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
2185 submit_derive (hostname, instance, "disk_ops_complex", name,
2186 (derive_t) value, timestamp, interval);
2188 } /* for (counter) */
2190 if ((cfg_system->flags & CFG_SYSTEM_DISK)
2191 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
2192 submit_two_derive (hostname, instance, "disk_octets", NULL,
2193 disk_read, disk_written, timestamp, interval);
2195 if ((cfg_system->flags & CFG_SYSTEM_NET)
2196 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
2197 submit_two_derive (hostname, instance, "if_octets", NULL,
2198 net_recv, net_sent, timestamp, interval);
2200 if ((cfg_system->flags & CFG_SYSTEM_CPU)
2201 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
2203 submit_derive (hostname, instance, "cpu", "system",
2204 cpu_busy, timestamp, interval);
2205 submit_derive (hostname, instance, "cpu", "idle",
2206 cpu_total - cpu_busy, timestamp, interval);
2210 } /* }}} int cna_handle_system_data */
2212 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
2217 if (cs->query != NULL)
2220 cs->query = na_elem_new ("perf-object-get-instances");
2221 if (cs->query == NULL)
2223 ERROR ("netapp plugin: na_elem_new failed.");
2226 na_child_add_string (cs->query, "objectname", "system");
2229 } /* }}} int cna_setup_system */
2231 static int cna_query_system (host_config_t *host) /* {{{ */
2240 /* If system statistics were not configured, return without doing anything. */
2241 if (host->cfg_system == NULL)
2245 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
2248 status = cna_setup_system (host->cfg_system);
2251 assert (host->cfg_system->query != NULL);
2253 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
2254 if (na_results_status (data) != NA_OK)
2256 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed for host %s: %s",
2257 host->name, na_results_reason (data));
2258 na_elem_free (data);
2262 status = cna_handle_system_data (host->name, host->cfg_system, data, host->interval);
2265 host->cfg_system->interval.last_read = now;
2267 na_elem_free (data);
2269 } /* }}} int cna_query_system */
2272 * Configuration handling
2274 /* Sets a given flag if the boolean argument is true and unsets the flag if it
2275 * is false. On error, the flag-field is not changed. */
2276 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
2277 uint32_t *flags, uint32_t flag)
2279 if ((ci == NULL) || (flags == NULL))
2282 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2284 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
2289 if (ci->values[0].value.boolean)
2295 } /* }}} int cna_config_bool_to_flag */
2297 /* Handling of the "Interval" option which is allowed in every block. */
2298 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
2299 cna_interval_t *out_interval)
2304 status = cf_util_get_cdtime (ci, &tmp);
2308 out_interval->interval = tmp;
2309 out_interval->last_read = 0;
2312 } /* }}} int cna_config_get_interval */
2314 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
2315 * <VolumePerf /> block. */
2316 static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
2317 const oconfig_item_t *ci)
2322 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2324 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2329 name = ci->values[0].value.string;
2331 if (strcasecmp ("GetIO", ci->key) == 0)
2332 il = cvp->il_octets;
2333 else if (strcasecmp ("GetOps", ci->key) == 0)
2334 il = cvp->il_operations;
2335 else if (strcasecmp ("GetLatency", ci->key) == 0)
2336 il = cvp->il_latency;
2340 ignorelist_add (il, name);
2341 } /* }}} void cna_config_volume_perf_option */
2343 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
2344 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
2345 static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
2346 const oconfig_item_t *ci)
2350 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2352 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2357 if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
2358 il = cvp->il_octets;
2359 else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
2360 il = cvp->il_operations;
2361 else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
2362 il = cvp->il_latency;
2366 if (ci->values[0].value.boolean)
2367 ignorelist_set_invert (il, /* invert = */ 0);
2369 ignorelist_set_invert (il, /* invert = */ 1);
2370 } /* }}} void cna_config_volume_perf_default */
2372 /* Corresponds to a <Disks /> block */
2377 * IgnoreSelectedIO false
2381 * IgnoreSelectedOps false
2385 * IgnoreSelectedLatency false
2388 /* Corresponds to a <VolumePerf /> block */
2389 static int cna_config_volume_performance (host_config_t *host, /* {{{ */
2390 const oconfig_item_t *ci)
2392 cfg_volume_perf_t *cfg_volume_perf;
2395 if ((host == NULL) || (ci == NULL))
2398 if (host->cfg_volume_perf == NULL)
2400 cfg_volume_perf = malloc (sizeof (*cfg_volume_perf));
2401 if (cfg_volume_perf == NULL)
2403 memset (cfg_volume_perf, 0, sizeof (*cfg_volume_perf));
2405 /* Set default flags */
2406 cfg_volume_perf->query = NULL;
2407 cfg_volume_perf->volumes = NULL;
2409 cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
2410 if (cfg_volume_perf->il_octets == NULL)
2412 sfree (cfg_volume_perf);
2416 cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
2417 if (cfg_volume_perf->il_operations == NULL)
2419 ignorelist_free (cfg_volume_perf->il_octets);
2420 sfree (cfg_volume_perf);
2424 cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
2425 if (cfg_volume_perf->il_latency == NULL)
2427 ignorelist_free (cfg_volume_perf->il_octets);
2428 ignorelist_free (cfg_volume_perf->il_operations);
2429 sfree (cfg_volume_perf);
2433 host->cfg_volume_perf = cfg_volume_perf;
2435 cfg_volume_perf = host->cfg_volume_perf;
2437 for (i = 0; i < ci->children_num; ++i) {
2438 oconfig_item_t *item = ci->children + i;
2440 /* if (!item || !item->key || !*item->key) continue; */
2441 if (strcasecmp(item->key, "Interval") == 0)
2442 cna_config_get_interval (item, &cfg_volume_perf->interval);
2443 else if (!strcasecmp(item->key, "GetIO"))
2444 cna_config_volume_perf_option (cfg_volume_perf, item);
2445 else if (!strcasecmp(item->key, "GetOps"))
2446 cna_config_volume_perf_option (cfg_volume_perf, item);
2447 else if (!strcasecmp(item->key, "GetLatency"))
2448 cna_config_volume_perf_option (cfg_volume_perf, item);
2449 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
2450 cna_config_volume_perf_default (cfg_volume_perf, item);
2451 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
2452 cna_config_volume_perf_default (cfg_volume_perf, item);
2453 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
2454 cna_config_volume_perf_default (cfg_volume_perf, item);
2456 WARNING ("netapp plugin: The option %s is not allowed within "
2457 "`VolumePerf' blocks.", item->key);
2461 } /* }}} int cna_config_volume_performance */
2463 /* Handling of the "GetCapacity" and "GetSnapshot" options within a
2464 * <VolumeUsage /> block. */
2465 static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
2466 const oconfig_item_t *ci)
2471 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2473 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2478 name = ci->values[0].value.string;
2480 if (strcasecmp ("GetCapacity", ci->key) == 0)
2481 il = cvu->il_capacity;
2482 else if (strcasecmp ("GetSnapshot", ci->key) == 0)
2483 il = cvu->il_snapshot;
2487 ignorelist_add (il, name);
2488 } /* }}} void cna_config_volume_usage_option */
2490 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
2491 * options within a <VolumeUsage /> block. */
2492 static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
2493 const oconfig_item_t *ci)
2497 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2499 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2504 if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
2505 il = cvu->il_capacity;
2506 else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
2507 il = cvu->il_snapshot;
2511 if (ci->values[0].value.boolean)
2512 ignorelist_set_invert (il, /* invert = */ 0);
2514 ignorelist_set_invert (il, /* invert = */ 1);
2515 } /* }}} void cna_config_volume_usage_default */
2517 /* Corresponds to a <Quota /> block */
2518 static int cna_config_quota (host_config_t *host, oconfig_item_t *ci) /* {{{ */
2520 cfg_quota_t *cfg_quota;
2523 if ((host == NULL) || (ci == NULL))
2526 if (host->cfg_quota == NULL)
2528 cfg_quota = malloc (sizeof (*cfg_quota));
2529 if (cfg_quota == NULL)
2531 memset (cfg_quota, 0, sizeof (*cfg_quota));
2532 cfg_quota->query = NULL;
2534 host->cfg_quota = cfg_quota;
2536 cfg_quota = host->cfg_quota;
2538 for (i = 0; i < ci->children_num; ++i) {
2539 oconfig_item_t *item = ci->children + i;
2541 if (strcasecmp (item->key, "Interval") == 0)
2542 cna_config_get_interval (item, &cfg_quota->interval);
2544 WARNING ("netapp plugin: The option %s is not allowed within "
2545 "`Quota' blocks.", item->key);
2549 } /* }}} int cna_config_quota */
2551 /* Corresponds to a <Disks /> block */
2552 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
2553 cfg_disk_t *cfg_disk;
2556 if ((host == NULL) || (ci == NULL))
2559 if (host->cfg_disk == NULL)
2561 cfg_disk = malloc (sizeof (*cfg_disk));
2562 if (cfg_disk == NULL)
2564 memset (cfg_disk, 0, sizeof (*cfg_disk));
2566 /* Set default flags */
2567 cfg_disk->flags = CFG_DISK_ALL;
2568 cfg_disk->query = NULL;
2569 cfg_disk->disks = NULL;
2571 host->cfg_disk = cfg_disk;
2573 cfg_disk = host->cfg_disk;
2575 for (i = 0; i < ci->children_num; ++i) {
2576 oconfig_item_t *item = ci->children + i;
2578 /* if (!item || !item->key || !*item->key) continue; */
2579 if (strcasecmp(item->key, "Interval") == 0)
2580 cna_config_get_interval (item, &cfg_disk->interval);
2581 else if (strcasecmp(item->key, "GetBusy") == 0)
2582 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2585 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
2587 NOTICE ("netapp plugin: All disk related values have been disabled. "
2588 "Collection of per-disk data will be disabled entirely.");
2589 free_cfg_disk (host->cfg_disk);
2590 host->cfg_disk = NULL;
2594 } /* }}} int cna_config_disk */
2596 /* Corresponds to a <WAFL /> block */
2597 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2599 cfg_wafl_t *cfg_wafl;
2602 if ((host == NULL) || (ci == NULL))
2605 if (host->cfg_wafl == NULL)
2607 cfg_wafl = malloc (sizeof (*cfg_wafl));
2608 if (cfg_wafl == NULL)
2610 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
2612 /* Set default flags */
2613 cfg_wafl->flags = CFG_WAFL_ALL;
2615 host->cfg_wafl = cfg_wafl;
2617 cfg_wafl = host->cfg_wafl;
2619 for (i = 0; i < ci->children_num; ++i) {
2620 oconfig_item_t *item = ci->children + i;
2622 if (strcasecmp(item->key, "Interval") == 0)
2623 cna_config_get_interval (item, &cfg_wafl->interval);
2624 else if (!strcasecmp(item->key, "GetNameCache"))
2625 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2626 else if (!strcasecmp(item->key, "GetDirCache"))
2627 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2628 else if (!strcasecmp(item->key, "GetBufferCache"))
2629 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2630 else if (!strcasecmp(item->key, "GetInodeCache"))
2631 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2633 WARNING ("netapp plugin: The %s config option is not allowed within "
2634 "`WAFL' blocks.", item->key);
2637 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
2639 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
2640 "Collection of WAFL data will be disabled entirely.");
2641 free_cfg_wafl (host->cfg_wafl);
2642 host->cfg_wafl = NULL;
2646 } /* }}} int cna_config_wafl */
2650 * GetCapacity "vol0"
2651 * GetCapacity "vol1"
2652 * GetCapacity "vol2"
2653 * GetCapacity "vol3"
2654 * GetCapacity "vol4"
2655 * IgnoreSelectedCapacity false
2657 * GetSnapshot "vol0"
2658 * GetSnapshot "vol3"
2659 * GetSnapshot "vol4"
2660 * GetSnapshot "vol7"
2661 * IgnoreSelectedSnapshot false
2664 /* Corresponds to a <VolumeUsage /> block */
2665 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2666 const oconfig_item_t *ci)
2668 cfg_volume_usage_t *cfg_volume_usage;
2671 if ((host == NULL) || (ci == NULL))
2674 if (host->cfg_volume_usage == NULL)
2676 cfg_volume_usage = malloc (sizeof (*cfg_volume_usage));
2677 if (cfg_volume_usage == NULL)
2679 memset (cfg_volume_usage, 0, sizeof (*cfg_volume_usage));
2681 /* Set default flags */
2682 cfg_volume_usage->query = NULL;
2683 cfg_volume_usage->volumes = NULL;
2685 cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
2686 if (cfg_volume_usage->il_capacity == NULL)
2688 sfree (cfg_volume_usage);
2692 cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
2693 if (cfg_volume_usage->il_snapshot == NULL)
2695 ignorelist_free (cfg_volume_usage->il_capacity);
2696 sfree (cfg_volume_usage);
2700 host->cfg_volume_usage = cfg_volume_usage;
2702 cfg_volume_usage = host->cfg_volume_usage;
2704 for (i = 0; i < ci->children_num; ++i) {
2705 oconfig_item_t *item = ci->children + i;
2707 /* if (!item || !item->key || !*item->key) continue; */
2708 if (strcasecmp(item->key, "Interval") == 0)
2709 cna_config_get_interval (item, &cfg_volume_usage->interval);
2710 else if (!strcasecmp(item->key, "GetCapacity"))
2711 cna_config_volume_usage_option (cfg_volume_usage, item);
2712 else if (!strcasecmp(item->key, "GetSnapshot"))
2713 cna_config_volume_usage_option (cfg_volume_usage, item);
2714 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2715 cna_config_volume_usage_default (cfg_volume_usage, item);
2716 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2717 cna_config_volume_usage_default (cfg_volume_usage, item);
2719 WARNING ("netapp plugin: The option %s is not allowed within "
2720 "`VolumeUsage' blocks.", item->key);
2724 } /* }}} int cna_config_volume_usage */
2726 /* Corresponds to a <SnapVault /> block */
2727 static int cna_config_snapvault (host_config_t *host, /* {{{ */
2728 const oconfig_item_t *ci)
2730 cfg_snapvault_t *cfg_snapvault;
2733 if ((host == NULL) || (ci == NULL))
2736 if (host->cfg_snapvault == NULL)
2738 cfg_snapvault = malloc (sizeof (*cfg_snapvault));
2739 if (cfg_snapvault == NULL)
2741 memset (cfg_snapvault, 0, sizeof (*cfg_snapvault));
2742 cfg_snapvault->query = NULL;
2744 host->cfg_snapvault = cfg_snapvault;
2747 cfg_snapvault = host->cfg_snapvault;
2749 for (i = 0; i < ci->children_num; ++i) {
2750 oconfig_item_t *item = ci->children + i;
2752 if (strcasecmp (item->key, "Interval") == 0)
2753 cna_config_get_interval (item, &cfg_snapvault->interval);
2755 WARNING ("netapp plugin: The option %s is not allowed within "
2756 "`SnapVault' blocks.", item->key);
2760 } /* }}} int cna_config_snapvault */
2762 /* Corresponds to a <System /> block */
2763 static int cna_config_system (host_config_t *host, /* {{{ */
2766 cfg_system_t *cfg_system;
2769 if ((host == NULL) || (ci == NULL))
2772 if (host->cfg_system == NULL)
2774 cfg_system = malloc (sizeof (*cfg_system));
2775 if (cfg_system == NULL)
2777 memset (cfg_system, 0, sizeof (*cfg_system));
2779 /* Set default flags */
2780 cfg_system->flags = CFG_SYSTEM_ALL;
2781 cfg_system->query = NULL;
2783 host->cfg_system = cfg_system;
2785 cfg_system = host->cfg_system;
2787 for (i = 0; i < ci->children_num; ++i) {
2788 oconfig_item_t *item = ci->children + i;
2790 if (strcasecmp(item->key, "Interval") == 0) {
2791 cna_config_get_interval (item, &cfg_system->interval);
2792 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2793 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
2794 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2795 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
2796 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2797 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
2798 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2799 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
2801 WARNING ("netapp plugin: The %s config option is not allowed within "
2802 "`System' blocks.", item->key);
2806 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
2808 NOTICE ("netapp plugin: All system related values have been disabled. "
2809 "Collection of system data will be disabled entirely.");
2810 free_cfg_system (host->cfg_system);
2811 host->cfg_system = NULL;
2815 } /* }}} int cna_config_system */
2817 /* Corresponds to a <Host /> block. */
2818 static host_config_t *cna_alloc_host (void) /* {{{ */
2820 host_config_t *host;
2822 host = malloc(sizeof(*host));
2825 memset (host, 0, sizeof (*host));
2828 host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2830 host->username = NULL;
2831 host->password = NULL;
2832 host->vfiler = NULL;
2834 host->cfg_wafl = NULL;
2835 host->cfg_disk = NULL;
2836 host->cfg_volume_perf = NULL;
2837 host->cfg_volume_usage = NULL;
2838 host->cfg_quota = NULL;
2839 host->cfg_snapvault = NULL;
2840 host->cfg_system = NULL;
2843 } /* }}} host_config_t *cna_alloc_host */
2845 static host_config_t *cna_shallow_clone_host (host_config_t *host) /* {{{ */
2847 host_config_t *clone;
2852 clone = cna_alloc_host ();
2856 if (host->name != NULL) {
2857 clone->name = strdup (host->name);
2858 if (clone->name == NULL) {
2859 free_host_config (clone);
2864 clone->protocol = host->protocol;
2866 if (host->host != NULL) {
2867 clone->host = strdup (host->host);
2868 if (clone->host == NULL) {
2869 free_host_config (clone);
2874 clone->port = host->port;
2876 if (host->username != NULL) {
2877 clone->username = strdup (host->username);
2878 if (clone->username == NULL) {
2879 free_host_config (clone);
2883 if (host->password != NULL) {
2884 clone->password = strdup (host->password);
2885 if (clone->password == NULL) {
2886 free_host_config (clone);
2891 clone->interval = host->interval;
2894 } /* }}} host_config_t *cna_shallow_clone_host */
2896 static int cna_read (user_data_t *ud);
2898 static int cna_register_host (host_config_t *host) /* {{{ */
2901 struct timespec interval;
2905 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s-%s",
2906 host->name, host->vfiler);
2908 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name);
2910 CDTIME_T_TO_TIMESPEC (host->interval, &interval);
2912 memset (&ud, 0, sizeof (ud));
2914 ud.free_func = (void (*) (void *)) free_host_config;
2916 plugin_register_complex_read (/* group = */ NULL, cb_name,
2917 /* callback = */ cna_read,
2918 /* interval = */ (host->interval > 0) ? &interval : NULL,
2919 /* user data = */ &ud);
2922 } /* }}} int cna_register_host */
2924 static int cna_config_host (host_config_t *host, /* {{{ */
2925 const oconfig_item_t *ci)
2927 oconfig_item_t *item;
2928 _Bool is_vfiler = 0;
2932 if (! strcasecmp (ci->key, "VFiler"))
2935 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2936 WARNING ("netapp plugin: \"%s\" needs exactly one string argument. Ignoring host block.", ci->key);
2940 status = cf_util_get_string (ci, &host->name);
2944 for (i = 0; i < ci->children_num; ++i) {
2945 item = ci->children + i;
2949 if (!strcasecmp(item->key, "Address")) {
2950 status = cf_util_get_string (item, &host->host);
2951 } else if (!strcasecmp(item->key, "Port")) {
2954 tmp = cf_util_get_port_number (item);
2957 } else if (!strcasecmp(item->key, "Protocol")) {
2958 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"))) {
2959 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
2962 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
2963 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2964 } else if (!strcasecmp(item->key, "User")) {
2965 status = cf_util_get_string (item, &host->username);
2966 } else if (!strcasecmp(item->key, "Password")) {
2967 status = cf_util_get_string (item, &host->password);
2968 } else if (!strcasecmp(item->key, "Interval")) {
2969 status = cf_util_get_cdtime (item, &host->interval);
2970 } else if (!strcasecmp(item->key, "WAFL")) {
2971 cna_config_wafl(host, item);
2972 } else if (!strcasecmp(item->key, "Disks")) {
2973 cna_config_disk(host, item);
2974 } else if (!strcasecmp(item->key, "VolumePerf")) {
2975 cna_config_volume_performance(host, item);
2976 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2977 cna_config_volume_usage(host, item);
2978 } else if (!strcasecmp(item->key, "Quota")) {
2979 cna_config_quota(host, item);
2980 } else if (!strcasecmp(item->key, "SnapVault")) {
2981 cna_config_snapvault(host, item);
2982 } else if (!strcasecmp(item->key, "System")) {
2983 cna_config_system(host, item);
2984 } else if ((!strcasecmp(item->key, "VFiler")) && (! is_vfiler)) {
2985 host_config_t *vfiler;
2987 vfiler = cna_shallow_clone_host (host);
2989 ERROR ("netapp plugin: Failed to allocate host object for vfiler.");
2993 if (cna_config_host (vfiler, item)) {
2994 free_host_config (vfiler);
2998 cna_register_host (vfiler);
2999 } else if ((!strcasecmp(item->key, "VFilerName")) && is_vfiler) {
3000 status = cf_util_get_string (item, &host->vfiler);
3002 WARNING ("netapp plugin: Ignoring unknown config option \"%s\" in %s block \"%s\".",
3003 item->key, is_vfiler ? "vfiler" : "host", ci->values[0].value.string);
3010 if (host->host == NULL)
3011 host->host = strdup (host->name);
3013 if (is_vfiler && (! host->vfiler))
3014 host->vfiler = strdup (host->name);
3016 if (host->host == NULL)
3019 if (host->port <= 0)
3020 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
3022 if ((host->username == NULL) || (host->password == NULL)) {
3023 WARNING("netapp plugin: Please supply login information for host \"%s\". "
3024 "Ignoring host block.", host->name);
3032 } /* }}} host_config_t *cna_config_host */
3035 * Callbacks registered with the daemon
3037 * Pretty standard stuff here.
3039 static int cna_init_host (host_config_t *host) /* {{{ */
3041 /* Request version 1.1 of the ONTAP API */
3042 int major_version = 1, minor_version = 1;
3047 if (host->srv != NULL)
3050 if (host->vfiler != NULL) /* Request version 1.7 of the ONTAP API */
3053 host->srv = na_server_open (host->host, major_version, minor_version);
3054 if (host->srv == NULL) {
3055 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
3059 na_server_set_transport_type(host->srv, host->protocol,
3060 /* transportarg = */ NULL);
3061 na_server_set_port(host->srv, host->port);
3062 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
3063 na_server_adminuser(host->srv, host->username, host->password);
3064 na_server_set_timeout(host->srv, 5 /* seconds */);
3066 if (host->vfiler != NULL) {
3067 if (! na_server_set_vfiler (host->srv, host->vfiler)) {
3068 ERROR ("netapp plugin: Failed to connect to VFiler '%s' on host '%s'.",
3069 host->vfiler, host->host);
3073 INFO ("netapp plugin: Connected to VFiler '%s' on host '%s'.",
3074 host->vfiler, host->host);
3079 } /* }}} int cna_init_host */
3081 static int cna_init (void) /* {{{ */
3085 memset (err, 0, sizeof (err));
3086 if (!na_startup(err, sizeof(err))) {
3087 err[sizeof (err) - 1] = 0;
3088 ERROR("netapp plugin: Error initializing netapp API: %s", err);
3093 } /* }}} cna_init */
3095 static int cna_read_internal (host_config_t *host) { /* {{{ */
3098 status = cna_query_wafl (host);
3102 status = cna_query_disk (host);
3106 status = cna_query_volume_perf (host);
3110 status = cna_query_volume_usage (host);
3114 status = cna_query_quota (host);
3118 status = cna_query_snapvault (host);
3122 status = cna_query_system (host);
3127 } /* }}} int cna_read_internal */
3129 static int cna_read (user_data_t *ud) { /* {{{ */
3130 host_config_t *host;
3133 if ((ud == NULL) || (ud->data == NULL))
3138 status = cna_init_host (host);
3142 status = cna_read_internal (host);
3145 if (host->srv != NULL)
3146 na_server_close (host->srv);
3151 } /* }}} int cna_read */
3153 static int cna_config (oconfig_item_t *ci) { /* {{{ */
3155 oconfig_item_t *item;
3157 for (i = 0; i < ci->children_num; ++i) {
3158 item = ci->children + i;
3160 if (strcasecmp(item->key, "Host") == 0)
3162 host_config_t *host;
3164 host = cna_alloc_host ();
3166 ERROR ("netapp plugin: Failed to allocate host object.");
3170 if (cna_config_host (host, item) != 0) {
3171 free_host_config (host);
3175 cna_register_host (host);
3177 else /* if (item->key != "Host") */
3179 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
3183 } /* }}} int cna_config */
3185 static int cna_shutdown (void) /* {{{ */
3187 /* Clean up system resources and stuff. */
3191 } /* }}} int cna_shutdown */
3193 void module_register(void) {
3194 plugin_register_complex_config("netapp", cna_config);
3195 plugin_register_init("netapp", cna_init);
3196 plugin_register_shutdown("netapp", cna_shutdown);
3199 /* vim: set sw=2 ts=2 noet fdm=marker : */