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, cdtime_t 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, cdtime_t 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,
1047 host->cfg_wafl->interval.interval);
1050 host->cfg_wafl->interval.last_read = now;
1052 na_elem_free (data);
1054 } /* }}} int cna_query_wafl */
1056 /* Data corresponding to <Disks /> */
1057 static int cna_handle_disk_data (const char *hostname, /* {{{ */
1058 cfg_disk_t *cfg_disk, na_elem_t *data, cdtime_t interval)
1061 na_elem_t *instances;
1062 na_elem_t *instance;
1063 na_elem_iter_t instance_iter;
1064 disk_t *worst_disk = NULL;
1066 if ((cfg_disk == NULL) || (data == NULL))
1069 timestamp = cna_child_get_cdtime (data);
1071 instances = na_elem_child (data, "instances");
1072 if (instances == NULL)
1074 ERROR ("netapp plugin: cna_handle_disk_data: "
1075 "na_elem_child (\"instances\") failed "
1076 "for host %s.", hostname);
1080 /* Iterate over all children */
1081 instance_iter = na_child_iterator (instances);
1082 for (instance = na_iterator_next (&instance_iter);
1084 instance = na_iterator_next(&instance_iter))
1089 na_elem_iter_t counter_iterator;
1092 memset (&new_data, 0, sizeof (new_data));
1093 new_data.timestamp = timestamp;
1094 new_data.disk_busy_percent = NAN;
1096 old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
1097 if (old_data == NULL)
1100 /* Look for the "disk_busy" and "base_for_disk_busy" counters */
1101 counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
1102 for (counter = na_iterator_next(&counter_iterator);
1104 counter = na_iterator_next(&counter_iterator))
1109 name = na_child_get_string(counter, "name");
1113 value = na_child_get_uint64(counter, "value", UINT64_MAX);
1114 if (value == UINT64_MAX)
1117 if (strcmp(name, "disk_busy") == 0)
1119 new_data.disk_busy = value;
1120 new_data.flags |= HAVE_DISK_BUSY;
1122 else if (strcmp(name, "base_for_disk_busy") == 0)
1124 new_data.base_for_disk_busy = value;
1125 new_data.flags |= HAVE_DISK_BASE;
1129 DEBUG ("netapp plugin: cna_handle_disk_data: "
1130 "Counter not handled: %s = %"PRIu64,
1135 /* If all required counters are available and did not just wrap around,
1136 * calculate the busy percentage. Otherwise, the value is initialized to
1137 * NAN at the top of the for-loop. */
1138 if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1139 && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
1140 && (new_data.disk_busy >= old_data->disk_busy)
1141 && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
1146 busy_diff = new_data.disk_busy - old_data->disk_busy;
1147 base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
1149 new_data.disk_busy_percent = 100.0
1150 * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
1153 /* Clear HAVE_* flags */
1154 old_data->flags &= ~HAVE_DISK_ALL;
1157 old_data->timestamp = new_data.timestamp;
1158 old_data->disk_busy = new_data.disk_busy;
1159 old_data->base_for_disk_busy = new_data.base_for_disk_busy;
1160 old_data->disk_busy_percent = new_data.disk_busy_percent;
1163 old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
1165 if ((worst_disk == NULL)
1166 || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
1167 worst_disk = old_data;
1168 } /* for (all disks) */
1170 if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
1171 submit_double (hostname, "system", "percent", "disk_busy",
1172 worst_disk->disk_busy_percent, timestamp, interval);
1175 } /* }}} int cna_handle_disk_data */
1177 static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
1184 if (cd->query != NULL)
1187 cd->query = na_elem_new ("perf-object-get-instances");
1188 if (cd->query == NULL)
1190 ERROR ("netapp plugin: na_elem_new failed.");
1193 na_child_add_string (cd->query, "objectname", "disk");
1195 e = na_elem_new("counters");
1198 na_elem_free (cd->query);
1200 ERROR ("netapp plugin: na_elem_new failed.");
1203 na_child_add_string(e, "counter", "disk_busy");
1204 na_child_add_string(e, "counter", "base_for_disk_busy");
1205 na_child_add(cd->query, e);
1208 } /* }}} int cna_setup_disk */
1210 static int cna_query_disk (host_config_t *host) /* {{{ */
1219 /* If the user did not configure disk statistics, return without doing
1221 if (host->cfg_disk == NULL)
1225 if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
1228 status = cna_setup_disk (host->cfg_disk);
1231 assert (host->cfg_disk->query != NULL);
1233 data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
1234 if (na_results_status (data) != NA_OK)
1236 ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed for host %s: %s",
1237 host->name, na_results_reason (data));
1238 na_elem_free (data);
1242 status = cna_handle_disk_data (host->name, host->cfg_disk, data,
1243 host->cfg_disk->interval.interval);
1246 host->cfg_disk->interval.last_read = now;
1248 na_elem_free (data);
1250 } /* }}} int cna_query_disk */
1252 /* Data corresponding to <VolumePerf /> */
1253 static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
1254 cfg_volume_perf_t *cvp, na_elem_t *data, cdtime_t interval)
1257 na_elem_t *elem_instances;
1258 na_elem_iter_t iter_instances;
1259 na_elem_t *elem_instance;
1261 timestamp = cna_child_get_cdtime (data);
1263 elem_instances = na_elem_child(data, "instances");
1264 if (elem_instances == NULL)
1266 ERROR ("netapp plugin: handle_volume_perf_data: "
1267 "na_elem_child (\"instances\") failed "
1268 "for host %s.", hostname);
1272 iter_instances = na_child_iterator (elem_instances);
1273 for (elem_instance = na_iterator_next(&iter_instances);
1274 elem_instance != NULL;
1275 elem_instance = na_iterator_next(&iter_instances))
1279 data_volume_perf_t perf_data;
1280 data_volume_perf_t *v;
1282 na_elem_t *elem_counters;
1283 na_elem_iter_t iter_counters;
1284 na_elem_t *elem_counter;
1286 memset (&perf_data, 0, sizeof (perf_data));
1287 perf_data.timestamp = timestamp;
1289 name = na_child_get_string (elem_instance, "name");
1293 /* get_volume_perf may return NULL if this volume is to be ignored. */
1294 v = get_volume_perf (cvp, name);
1298 elem_counters = na_elem_child (elem_instance, "counters");
1299 if (elem_counters == NULL)
1302 iter_counters = na_child_iterator (elem_counters);
1303 for (elem_counter = na_iterator_next(&iter_counters);
1304 elem_counter != NULL;
1305 elem_counter = na_iterator_next(&iter_counters))
1310 name = na_child_get_string (elem_counter, "name");
1314 value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
1315 if (value == UINT64_MAX)
1318 if (!strcmp(name, "read_data")) {
1319 perf_data.read_bytes = value;
1320 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
1321 } else if (!strcmp(name, "write_data")) {
1322 perf_data.write_bytes = value;
1323 perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
1324 } else if (!strcmp(name, "read_ops")) {
1325 perf_data.read_ops = value;
1326 perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
1327 } else if (!strcmp(name, "write_ops")) {
1328 perf_data.write_ops = value;
1329 perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
1330 } else if (!strcmp(name, "read_latency")) {
1331 perf_data.read_latency = value;
1332 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
1333 } else if (!strcmp(name, "write_latency")) {
1334 perf_data.write_latency = value;
1335 perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
1337 } /* for (elem_counter) */
1339 submit_volume_perf_data (hostname, v, &perf_data, interval);
1340 } /* for (volume) */
1343 } /* }}} int cna_handle_volume_perf_data */
1345 static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
1352 if (cd->query != NULL)
1355 cd->query = na_elem_new ("perf-object-get-instances");
1356 if (cd->query == NULL)
1358 ERROR ("netapp plugin: na_elem_new failed.");
1361 na_child_add_string (cd->query, "objectname", "volume");
1363 e = na_elem_new("counters");
1366 na_elem_free (cd->query);
1368 ERROR ("netapp plugin: na_elem_new failed.");
1371 na_child_add_string(e, "counter", "read_ops");
1372 na_child_add_string(e, "counter", "write_ops");
1373 na_child_add_string(e, "counter", "read_data");
1374 na_child_add_string(e, "counter", "write_data");
1375 na_child_add_string(e, "counter", "read_latency");
1376 na_child_add_string(e, "counter", "write_latency");
1377 na_child_add(cd->query, e);
1380 } /* }}} int cna_setup_volume_perf */
1382 static int cna_query_volume_perf (host_config_t *host) /* {{{ */
1391 /* If the user did not configure volume performance statistics, return
1392 * without doing anything. */
1393 if (host->cfg_volume_perf == NULL)
1397 if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
1400 status = cna_setup_volume_perf (host->cfg_volume_perf);
1403 assert (host->cfg_volume_perf->query != NULL);
1405 data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
1406 if (na_results_status (data) != NA_OK)
1408 ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed for host %s: %s",
1409 host->name, na_results_reason (data));
1410 na_elem_free (data);
1414 status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data,
1415 host->cfg_volume_perf->interval.interval);
1418 host->cfg_volume_perf->interval.last_read = now;
1420 na_elem_free (data);
1422 } /* }}} int cna_query_volume_perf */
1424 /* Data corresponding to <VolumeUsage /> */
1425 static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
1426 cfg_volume_usage_t *cfg_volume, int interval)
1428 data_volume_usage_t *v;
1430 for (v = cfg_volume->volumes; v != NULL; v = v->next)
1432 char plugin_instance[DATA_MAX_NAME_LEN];
1434 uint64_t norm_used = v->norm_used;
1435 uint64_t norm_free = v->norm_free;
1436 uint64_t sis_saved = v->sis_saved;
1437 uint64_t compress_saved = v->compress_saved;
1438 uint64_t dedup_saved = v->dedup_saved;
1439 uint64_t snap_reserve_used = 0;
1440 uint64_t snap_reserve_free = v->snap_reserved;
1441 uint64_t snap_norm_used = v->snap_used;
1443 ssnprintf (plugin_instance, sizeof (plugin_instance),
1444 "volume-%s", v->name);
1446 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD)) {
1447 if (v->snap_reserved > v->snap_used) {
1448 snap_reserve_free = v->snap_reserved - v->snap_used;
1449 snap_reserve_used = v->snap_used;
1452 snap_reserve_free = 0;
1453 snap_reserve_used = v->snap_reserved;
1454 snap_norm_used = v->snap_used - v->snap_reserved;
1458 /* The space used by snapshots but not reserved for them is included in
1459 * both, norm_used and snap_norm_used. If possible, subtract this here. */
1460 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED))
1462 if (norm_used >= snap_norm_used)
1463 norm_used -= snap_norm_used;
1466 ERROR ("netapp plugin: (norm_used = %"PRIu64") < (snap_norm_used = "
1467 "%"PRIu64") for host %s. Invalidating both.",
1468 norm_used, snap_norm_used, hostname);
1469 v->flags &= ~(HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED);
1473 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
1474 submit_double (hostname, /* plugin instance = */ plugin_instance,
1475 "df_complex", "free",
1476 (double) norm_free, /* timestamp = */ 0, interval);
1478 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
1479 submit_double (hostname, /* plugin instance = */ plugin_instance,
1480 "df_complex", "sis_saved",
1481 (double) sis_saved, /* timestamp = */ 0, interval);
1483 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_COMPRESS_SAVED))
1484 submit_double (hostname, /* plugin instance = */ plugin_instance,
1485 "df_complex", "compression_saved",
1486 (double) compress_saved, /* timestamp = */ 0, interval);
1488 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_DEDUP_SAVED))
1489 submit_double (hostname, /* plugin instance = */ plugin_instance,
1490 "df_complex", "dedup_saved",
1491 (double) dedup_saved, /* timestamp = */ 0, interval);
1493 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
1494 submit_double (hostname, /* plugin instance = */ plugin_instance,
1495 "df_complex", "used",
1496 (double) norm_used, /* timestamp = */ 0, interval);
1498 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
1499 submit_double (hostname, /* plugin instance = */ plugin_instance,
1500 "df_complex", "snap_reserved",
1501 (double) snap_reserve_free, /* timestamp = */ 0, interval);
1503 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD))
1504 submit_double (hostname, /* plugin instance = */ plugin_instance,
1505 "df_complex", "snap_reserve_used",
1506 (double) snap_reserve_used, /* timestamp = */ 0, interval);
1508 if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
1509 submit_double (hostname, /* plugin instance = */ plugin_instance,
1510 "df_complex", "snap_normal_used",
1511 (double) snap_norm_used, /* timestamp = */ 0, interval);
1513 /* Clear all the HAVE_* flags */
1514 v->flags &= ~HAVE_VOLUME_USAGE_ALL;
1515 } /* for (v = cfg_volume->volumes) */
1518 } /* }}} int cna_submit_volume_usage_data */
1520 /* Switch the state of a volume between online and offline and send out a
1522 static int cna_change_volume_status (const char *hostname, /* {{{ */
1523 data_volume_usage_t *v)
1527 memset (&n, 0, sizeof (&n));
1529 sstrncpy (n.host, hostname, sizeof (n.host));
1530 sstrncpy (n.plugin, "netapp", sizeof (n.plugin));
1531 sstrncpy (n.plugin_instance, v->name, sizeof (n.plugin_instance));
1533 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0) {
1534 n.severity = NOTIF_OKAY;
1535 ssnprintf (n.message, sizeof (n.message),
1536 "Volume %s is now online.", v->name);
1537 v->flags &= ~IS_VOLUME_USAGE_OFFLINE;
1539 n.severity = NOTIF_WARNING;
1540 ssnprintf (n.message, sizeof (n.message),
1541 "Volume %s is now offline.", v->name);
1542 v->flags |= IS_VOLUME_USAGE_OFFLINE;
1545 return (plugin_dispatch_notification (&n));
1546 } /* }}} int cna_change_volume_status */
1548 static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
1549 data_volume_usage_t *v)
1551 uint64_t snap_used = 0, value;
1552 na_elem_t *data, *elem_snap, *elem_snapshots;
1553 na_elem_iter_t iter_snap;
1555 data = na_server_invoke_elem(host->srv, v->snap_query);
1556 if (na_results_status(data) != NA_OK)
1558 if (na_results_errno(data) == EVOLUMEOFFLINE) {
1559 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) == 0)
1560 cna_change_volume_status (host->name, v);
1562 ERROR ("netapp plugin: cna_handle_volume_snap_usage: na_server_invoke_elem for "
1563 "volume \"%s\" on host %s failed with error %d: %s", v->name,
1564 host->name, na_results_errno(data), na_results_reason(data));
1570 if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0)
1571 cna_change_volume_status (host->name, v);
1573 elem_snapshots = na_elem_child (data, "snapshots");
1574 if (elem_snapshots == NULL)
1576 ERROR ("netapp plugin: cna_handle_volume_snap_usage: "
1577 "na_elem_child (\"snapshots\") failed "
1578 "for host %s.", host->name);
1583 iter_snap = na_child_iterator (elem_snapshots);
1584 for (elem_snap = na_iterator_next (&iter_snap);
1586 elem_snap = na_iterator_next (&iter_snap))
1588 value = na_child_get_uint64(elem_snap, "cumulative-total", 0);
1589 /* "cumulative-total" is the total size of the oldest snapshot plus all
1590 * newer ones in blocks (1KB). We therefore are looking for the highest
1591 * number of all snapshots - that's the size required for the snapshots. */
1592 if (value > snap_used)
1595 na_elem_free (data);
1596 /* snap_used is in 1024 byte blocks */
1597 v->snap_used = snap_used * 1024;
1598 v->flags |= HAVE_VOLUME_USAGE_SNAP_USED;
1599 } /* }}} void cna_handle_volume_snap_usage */
1601 static void cna_handle_volume_sis_data (const host_config_t *host, /* {{{ */
1602 data_volume_usage_t *v, na_elem_t *sis)
1604 const char *sis_state;
1605 uint64_t sis_saved_reported;
1607 if (na_elem_child(sis, "sis-info"))
1608 sis = na_elem_child(sis, "sis-info");
1610 sis_state = na_child_get_string(sis, "state");
1611 if (sis_state == NULL)
1614 /* If SIS is not enabled, there's nothing left to do for this volume. */
1615 if (strcmp ("enabled", sis_state) != 0)
1618 sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
1619 if (sis_saved_reported == UINT64_MAX)
1622 /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
1623 if ((sis_saved_reported >> 32) != 0) {
1624 /* In case they ever fix this bug. */
1625 v->sis_saved = sis_saved_reported;
1626 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1627 } else { /* really hacky work-around code. {{{ */
1628 uint64_t sis_saved_percent;
1629 uint64_t sis_saved_guess;
1630 uint64_t overflow_guess;
1631 uint64_t guess1, guess2, guess3;
1633 /* Check if we have v->norm_used. Without it, we cannot calculate
1634 * sis_saved_guess. */
1635 if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
1638 sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
1639 if (sis_saved_percent > 100)
1642 /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
1643 * will hopefully be fixed in later versions. To work around the bug, try
1644 * to figure out how often the 32bit integer wrapped around by using the
1645 * "percentage-saved" value. Because the percentage is in the range
1646 * [0-100], this should work as long as the saved space does not exceed
1648 /* percentage-saved = size-saved / (size-saved + size-used) */
1649 if (sis_saved_percent < 100)
1650 sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
1652 sis_saved_guess = v->norm_used;
1654 overflow_guess = sis_saved_guess >> 32;
1655 guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
1656 guess2 = (overflow_guess << 32) + sis_saved_reported;
1657 guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
1659 if (sis_saved_guess < guess2) {
1660 if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
1661 v->sis_saved = guess1;
1663 v->sis_saved = guess2;
1665 if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
1666 v->sis_saved = guess2;
1668 v->sis_saved = guess3;
1670 v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
1671 } /* }}} end of 32-bit workaround */
1672 } /* }}} void cna_handle_volume_sis_data */
1674 /* ONTAP >= 8.1 uses SIS for managing dedup and compression */
1675 static void cna_handle_volume_sis_saved (const host_config_t *host, /* {{{ */
1676 data_volume_usage_t *v, na_elem_t *sis)
1680 if (na_elem_child(sis, "sis-info"))
1681 sis = na_elem_child(sis, "sis-info");
1683 saved = na_child_get_uint64(sis, "compress-saved", UINT64_MAX);
1684 if (saved != UINT64_MAX) {
1685 v->compress_saved = saved;
1686 v->flags |= HAVE_VOLUME_USAGE_COMPRESS_SAVED;
1689 saved = na_child_get_uint64(sis, "dedup-saved", UINT64_MAX);
1690 if (saved != UINT64_MAX) {
1691 v->dedup_saved = saved;
1692 v->flags |= HAVE_VOLUME_USAGE_DEDUP_SAVED;
1694 } /* }}} void cna_handle_volume_sis_saved */
1696 static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */
1697 cfg_volume_usage_t *cfg_volume, na_elem_t *data)
1699 na_elem_t *elem_volume;
1700 na_elem_t *elem_volumes;
1701 na_elem_iter_t iter_volume;
1703 elem_volumes = na_elem_child (data, "volumes");
1704 if (elem_volumes == NULL)
1706 ERROR ("netapp plugin: cna_handle_volume_usage_data: "
1707 "na_elem_child (\"volumes\") failed "
1708 "for host %s.", host->name);
1712 iter_volume = na_child_iterator (elem_volumes);
1713 for (elem_volume = na_iterator_next (&iter_volume);
1714 elem_volume != NULL;
1715 elem_volume = na_iterator_next (&iter_volume))
1717 const char *volume_name, *state;
1719 data_volume_usage_t *v;
1724 volume_name = na_child_get_string (elem_volume, "name");
1725 if (volume_name == NULL)
1728 state = na_child_get_string (elem_volume, "state");
1729 if ((state == NULL) || (strcmp(state, "online") != 0))
1732 /* get_volume_usage may return NULL if the volume is to be ignored. */
1733 v = get_volume_usage (cfg_volume, volume_name);
1737 if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
1738 cna_handle_volume_snap_usage(host, v);
1740 if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
1743 /* 2^4 exa-bytes? This will take a while ;) */
1744 value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
1745 if (value != UINT64_MAX) {
1746 v->norm_free = value;
1747 v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
1750 value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
1751 if (value != UINT64_MAX) {
1752 v->norm_used = value;
1753 v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
1756 value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
1757 if (value != UINT64_MAX) {
1758 /* 1 block == 1024 bytes as per API docs */
1759 v->snap_reserved = 1024 * value;
1760 v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
1763 sis = na_elem_child(elem_volume, "sis");
1765 cna_handle_volume_sis_data (host, v, sis);
1766 cna_handle_volume_sis_saved (host, v, sis);
1768 } /* for (elem_volume) */
1770 return (cna_submit_volume_usage_data (host->name, cfg_volume,
1771 host->cfg_volume_usage->interval.interval));
1772 } /* }}} int cna_handle_volume_usage_data */
1774 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
1779 if (cvu->query != NULL)
1782 cvu->query = na_elem_new ("volume-list-info");
1783 if (cvu->query == NULL)
1785 ERROR ("netapp plugin: na_elem_new failed.");
1790 } /* }}} int cna_setup_volume_usage */
1792 static int cna_query_volume_usage (host_config_t *host) /* {{{ */
1801 /* If the user did not configure volume_usage statistics, return without
1802 * doing anything. */
1803 if (host->cfg_volume_usage == NULL)
1807 if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
1810 status = cna_setup_volume_usage (host->cfg_volume_usage);
1813 assert (host->cfg_volume_usage->query != NULL);
1815 data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
1816 if (na_results_status (data) != NA_OK)
1818 ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed for host %s: %s",
1819 host->name, na_results_reason (data));
1820 na_elem_free (data);
1824 status = cna_handle_volume_usage_data (host, host->cfg_volume_usage, data);
1827 host->cfg_volume_usage->interval.last_read = now;
1829 na_elem_free (data);
1831 } /* }}} int cna_query_volume_usage */
1833 /* Data corresponding to <Quota /> */
1834 static int cna_handle_quota_data (const host_config_t *host, /* {{{ */
1835 cfg_quota_t *cfg_quota, na_elem_t *data)
1837 na_elem_t *elem_quota;
1838 na_elem_t *elem_quotas;
1839 na_elem_iter_t iter_quota;
1841 elem_quotas = na_elem_child (data, "quotas");
1842 if (elem_quotas == NULL)
1844 ERROR ("netapp plugin: cna_handle_quota_data: "
1845 "na_elem_child (\"quotas\") failed "
1846 "for host %s.", host->name);
1850 iter_quota = na_child_iterator (elem_quotas);
1851 for (elem_quota = na_iterator_next (&iter_quota);
1853 elem_quota = na_iterator_next (&iter_quota))
1855 const char *quota_type, *volume_name, *tree_name;
1858 char plugin_instance[DATA_MAX_NAME_LEN];
1860 quota_type = na_child_get_string (elem_quota, "quota-type");
1861 if (quota_type == NULL)
1864 /* possible TODO: support other types as well */
1865 if (strcmp (quota_type, "tree") != 0)
1868 tree_name = na_child_get_string (elem_quota, "tree");
1869 if ((tree_name == NULL) || (*tree_name == '\0'))
1872 volume_name = na_child_get_string (elem_quota, "volume");
1873 if (volume_name == NULL)
1876 ssnprintf (plugin_instance, sizeof (plugin_instance),
1877 "quota-%s-%s", volume_name, tree_name);
1879 value = na_child_get_uint64 (elem_quota, "disk-used", UINT64_MAX);
1880 if (value != UINT64_MAX) {
1881 value *= 1024; /* disk-used reports kilobytes */
1882 submit_double (host->name, plugin_instance,
1883 /* type = */ "df_complex", /* type instance = */ NULL,
1884 (double)value, /* timestamp = */ 0,
1885 host->cfg_quota->interval.interval);
1888 value = na_child_get_uint64 (elem_quota, "files-used", UINT64_MAX);
1889 if (value != UINT64_MAX) {
1890 submit_double (host->name, plugin_instance,
1891 /* type = */ "files", /* type instance = */ NULL,
1892 (double)value, /* timestamp = */ 0,
1893 host->cfg_quota->interval.interval);
1895 } /* for (elem_quota) */
1898 } /* }}} int cna_handle_volume_usage_data */
1900 static int cna_setup_quota (cfg_quota_t *cq) /* {{{ */
1905 if (cq->query != NULL)
1908 cq->query = na_elem_new ("quota-report");
1909 if (cq->query == NULL)
1911 ERROR ("netapp plugin: na_elem_new failed.");
1916 } /* }}} int cna_setup_quota */
1918 static int cna_query_quota (host_config_t *host) /* {{{ */
1927 /* If the user did not configure quota statistics, return without
1928 * doing anything. */
1929 if (host->cfg_quota == NULL)
1933 if ((host->cfg_quota->interval.interval + host->cfg_quota->interval.last_read) > now)
1936 status = cna_setup_quota (host->cfg_quota);
1939 assert (host->cfg_quota->query != NULL);
1941 data = na_server_invoke_elem (host->srv, host->cfg_quota->query);
1942 if (na_results_status (data) != NA_OK)
1944 ERROR ("netapp plugin: cna_query_quota: na_server_invoke_elem failed for host %s: %s",
1945 host->name, na_results_reason (data));
1946 na_elem_free (data);
1950 status = cna_handle_quota_data (host, host->cfg_quota, data);
1953 host->cfg_quota->interval.last_read = now;
1955 na_elem_free (data);
1957 } /* }}} int cna_query_quota */
1959 /* Data corresponding to <SnapVault /> */
1960 static int cna_handle_snapvault_data (const char *hostname, /* {{{ */
1961 cfg_snapvault_t *cfg_snapvault, na_elem_t *data, cdtime_t interval)
1964 na_elem_iter_t status_iter;
1966 status = na_elem_child (data, "status-list");
1968 ERROR ("netapp plugin: SnapVault status record missing status-list");
1972 status_iter = na_child_iterator (status);
1973 for (status = na_iterator_next (&status_iter);
1975 status = na_iterator_next (&status_iter))
1977 const char *dest_sys, *dest_path, *src_sys, *src_path;
1978 char plugin_instance[DATA_MAX_NAME_LEN];
1981 dest_sys = na_child_get_string (status, "destination-system");
1982 dest_path = na_child_get_string (status, "destination-path");
1983 src_sys = na_child_get_string (status, "source-system");
1984 src_path = na_child_get_string (status, "source-path");
1986 if ((! dest_sys) || (! dest_path) || (! src_sys) || (! src_path))
1989 value = na_child_get_uint64 (status, "lag-time", UINT64_MAX);
1990 if (value == UINT64_MAX) /* no successful baseline transfer yet */
1993 /* possible TODO: make plugin instance configurable */
1994 ssnprintf (plugin_instance, sizeof (plugin_instance),
1995 "snapvault-%s", dest_path);
1996 submit_double (hostname, plugin_instance, /* type = */ "delay", NULL,
1997 (double)value, /* timestamp = */ 0, interval);
1999 value = na_child_get_uint64 (status, "last-transfer-duration", UINT64_MAX);
2000 if (value != UINT64_MAX)
2001 submit_double (hostname, plugin_instance, /* type = */ "duration", "last_transfer",
2002 (double)value, /* timestamp = */ 0, interval);
2004 value = na_child_get_uint64 (status, "transfer-progress", UINT64_MAX);
2005 if (value == UINT64_MAX)
2006 value = na_child_get_uint64 (status, "last-transfer-size", UINT64_MAX);
2007 if (value != UINT64_MAX) {
2008 value *= 1024; /* this is kilobytes */
2009 submit_derive (hostname, plugin_instance, /* type = */ "if_rx_octets", "transferred",
2010 value, /* timestamp = */ 0, interval);
2012 } /* for (status) */
2015 } /* }}} int cna_handle_snapvault_data */
2017 static int cna_handle_snapvault_iter (host_config_t *host, /* {{{ */
2022 uint32_t records_count;
2025 records_count = na_child_get_uint32 (data, "records", UINT32_MAX);
2026 if (records_count == UINT32_MAX)
2029 tag = na_child_get_string (data, "tag");
2033 DEBUG ("netapp plugin: Iterating %u SV records (tag = %s)", records_count, tag);
2035 for (i = 0; i < records_count; ++i) {
2038 elem = na_server_invoke (host->srv,
2039 "snapvault-secondary-relationship-status-list-iter-next",
2040 "maximum", "1", "tag", tag, NULL);
2042 if (na_results_status (elem) != NA_OK)
2044 ERROR ("netapp plugin: cna_handle_snapvault_iter: "
2045 "na_server_invoke failed for host %s: %s",
2046 host->name, na_results_reason (data));
2047 na_elem_free (elem);
2051 cna_handle_snapvault_data (host->name, host->cfg_snapvault, elem,
2052 host->cfg_snapvault->interval.interval);
2053 na_elem_free (elem);
2056 na_elem_free (na_server_invoke (host->srv,
2057 "snapvault-secondary-relationship-status-list-iter-end",
2060 } /* }}} int cna_handle_snapvault_iter */
2062 static int cna_setup_snapvault (cfg_snapvault_t *sv) /* {{{ */
2067 if (sv->query != NULL)
2070 sv->query = na_elem_new ("snapvault-secondary-relationship-status-list-iter-start");
2071 if (sv->query == NULL)
2073 ERROR ("netapp plugin: na_elem_new failed.");
2078 } /* }}} int cna_setup_snapvault */
2080 static int cna_query_snapvault (host_config_t *host) /* {{{ */
2089 if (host->cfg_snapvault == NULL)
2093 if ((host->cfg_snapvault->interval.interval + host->cfg_snapvault->interval.last_read) > now)
2096 status = cna_setup_snapvault (host->cfg_snapvault);
2099 assert (host->cfg_snapvault->query != NULL);
2101 data = na_server_invoke_elem (host->srv, host->cfg_snapvault->query);
2102 if (na_results_status (data) != NA_OK)
2104 ERROR ("netapp plugin: cna_query_snapvault: na_server_invoke_elem failed for host %s: %s",
2105 host->name, na_results_reason (data));
2106 na_elem_free (data);
2110 status = cna_handle_snapvault_iter (host, data);
2113 host->cfg_snapvault->interval.last_read = now;
2115 na_elem_free (data);
2117 } /* }}} int cna_query_snapvault */
2119 /* Data corresponding to <System /> */
2120 static int cna_handle_system_data (const char *hostname, /* {{{ */
2121 cfg_system_t *cfg_system, na_elem_t *data, int interval)
2123 na_elem_t *instances;
2125 na_elem_iter_t counter_iter;
2127 derive_t disk_read = 0, disk_written = 0;
2128 derive_t net_recv = 0, net_sent = 0;
2129 derive_t cpu_busy = 0, cpu_total = 0;
2130 uint32_t counter_flags = 0;
2132 const char *instance;
2135 timestamp = cna_child_get_cdtime (data);
2137 instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
2138 if (instances == NULL)
2140 ERROR ("netapp plugin: cna_handle_system_data: "
2141 "na_elem_child (\"instances\") failed "
2142 "for host %s.", hostname);
2146 instance = na_child_get_string (instances, "name");
2147 if (instance == NULL)
2149 ERROR ("netapp plugin: cna_handle_system_data: "
2150 "na_child_get_string (\"name\") failed "
2151 "for host %s.", hostname);
2155 counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
2156 for (counter = na_iterator_next (&counter_iter);
2158 counter = na_iterator_next (&counter_iter))
2163 name = na_child_get_string(counter, "name");
2167 value = na_child_get_uint64(counter, "value", UINT64_MAX);
2168 if (value == UINT64_MAX)
2171 if (!strcmp(name, "disk_data_read")) {
2172 disk_read = (derive_t) (value * 1024);
2173 counter_flags |= 0x01;
2174 } else if (!strcmp(name, "disk_data_written")) {
2175 disk_written = (derive_t) (value * 1024);
2176 counter_flags |= 0x02;
2177 } else if (!strcmp(name, "net_data_recv")) {
2178 net_recv = (derive_t) (value * 1024);
2179 counter_flags |= 0x04;
2180 } else if (!strcmp(name, "net_data_sent")) {
2181 net_sent = (derive_t) (value * 1024);
2182 counter_flags |= 0x08;
2183 } else if (!strcmp(name, "cpu_busy")) {
2184 cpu_busy = (derive_t) value;
2185 counter_flags |= 0x10;
2186 } else if (!strcmp(name, "cpu_elapsed_time")) {
2187 cpu_total = (derive_t) value;
2188 counter_flags |= 0x20;
2189 } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
2190 && (value > 0) && (strlen(name) > 4)
2191 && (!strcmp(name + strlen(name) - 4, "_ops"))) {
2192 submit_derive (hostname, instance, "disk_ops_complex", name,
2193 (derive_t) value, timestamp, interval);
2195 } /* for (counter) */
2197 if ((cfg_system->flags & CFG_SYSTEM_DISK)
2198 && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
2199 submit_two_derive (hostname, instance, "disk_octets", NULL,
2200 disk_read, disk_written, timestamp, interval);
2202 if ((cfg_system->flags & CFG_SYSTEM_NET)
2203 && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
2204 submit_two_derive (hostname, instance, "if_octets", NULL,
2205 net_recv, net_sent, timestamp, interval);
2207 if ((cfg_system->flags & CFG_SYSTEM_CPU)
2208 && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
2210 submit_derive (hostname, instance, "cpu", "system",
2211 cpu_busy, timestamp, interval);
2212 submit_derive (hostname, instance, "cpu", "idle",
2213 cpu_total - cpu_busy, timestamp, interval);
2217 } /* }}} int cna_handle_system_data */
2219 static int cna_setup_system (cfg_system_t *cs) /* {{{ */
2224 if (cs->query != NULL)
2227 cs->query = na_elem_new ("perf-object-get-instances");
2228 if (cs->query == NULL)
2230 ERROR ("netapp plugin: na_elem_new failed.");
2233 na_child_add_string (cs->query, "objectname", "system");
2236 } /* }}} int cna_setup_system */
2238 static int cna_query_system (host_config_t *host) /* {{{ */
2247 /* If system statistics were not configured, return without doing anything. */
2248 if (host->cfg_system == NULL)
2252 if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
2255 status = cna_setup_system (host->cfg_system);
2258 assert (host->cfg_system->query != NULL);
2260 data = na_server_invoke_elem(host->srv, host->cfg_system->query);
2261 if (na_results_status (data) != NA_OK)
2263 ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed for host %s: %s",
2264 host->name, na_results_reason (data));
2265 na_elem_free (data);
2269 status = cna_handle_system_data (host->name, host->cfg_system, data,
2270 host->cfg_system->interval.interval);
2273 host->cfg_system->interval.last_read = now;
2275 na_elem_free (data);
2277 } /* }}} int cna_query_system */
2280 * Configuration handling
2282 /* Sets a given flag if the boolean argument is true and unsets the flag if it
2283 * is false. On error, the flag-field is not changed. */
2284 static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
2285 uint32_t *flags, uint32_t flag)
2287 if ((ci == NULL) || (flags == NULL))
2290 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2292 WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
2297 if (ci->values[0].value.boolean)
2303 } /* }}} int cna_config_bool_to_flag */
2305 /* Handling of the "Interval" option which is allowed in every block. */
2306 static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
2307 cna_interval_t *out_interval)
2312 status = cf_util_get_cdtime (ci, &tmp);
2316 out_interval->interval = tmp;
2317 out_interval->last_read = 0;
2320 } /* }}} int cna_config_get_interval */
2322 /* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
2323 * <VolumePerf /> block. */
2324 static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
2325 const oconfig_item_t *ci)
2330 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2332 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2337 name = ci->values[0].value.string;
2339 if (strcasecmp ("GetIO", ci->key) == 0)
2340 il = cvp->il_octets;
2341 else if (strcasecmp ("GetOps", ci->key) == 0)
2342 il = cvp->il_operations;
2343 else if (strcasecmp ("GetLatency", ci->key) == 0)
2344 il = cvp->il_latency;
2348 ignorelist_add (il, name);
2349 } /* }}} void cna_config_volume_perf_option */
2351 /* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
2352 * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
2353 static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
2354 const oconfig_item_t *ci)
2358 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2360 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2365 if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
2366 il = cvp->il_octets;
2367 else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
2368 il = cvp->il_operations;
2369 else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
2370 il = cvp->il_latency;
2374 if (ci->values[0].value.boolean)
2375 ignorelist_set_invert (il, /* invert = */ 0);
2377 ignorelist_set_invert (il, /* invert = */ 1);
2378 } /* }}} void cna_config_volume_perf_default */
2380 /* Corresponds to a <Disks /> block */
2385 * IgnoreSelectedIO false
2389 * IgnoreSelectedOps false
2393 * IgnoreSelectedLatency false
2396 /* Corresponds to a <VolumePerf /> block */
2397 static int cna_config_volume_performance (host_config_t *host, /* {{{ */
2398 const oconfig_item_t *ci)
2400 cfg_volume_perf_t *cfg_volume_perf;
2403 if ((host == NULL) || (ci == NULL))
2406 if (host->cfg_volume_perf == NULL)
2408 cfg_volume_perf = malloc (sizeof (*cfg_volume_perf));
2409 if (cfg_volume_perf == NULL)
2411 memset (cfg_volume_perf, 0, sizeof (*cfg_volume_perf));
2413 /* Set default flags */
2414 cfg_volume_perf->query = NULL;
2415 cfg_volume_perf->volumes = NULL;
2417 cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
2418 if (cfg_volume_perf->il_octets == NULL)
2420 sfree (cfg_volume_perf);
2424 cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
2425 if (cfg_volume_perf->il_operations == NULL)
2427 ignorelist_free (cfg_volume_perf->il_octets);
2428 sfree (cfg_volume_perf);
2432 cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
2433 if (cfg_volume_perf->il_latency == NULL)
2435 ignorelist_free (cfg_volume_perf->il_octets);
2436 ignorelist_free (cfg_volume_perf->il_operations);
2437 sfree (cfg_volume_perf);
2441 host->cfg_volume_perf = cfg_volume_perf;
2443 cfg_volume_perf = host->cfg_volume_perf;
2445 for (i = 0; i < ci->children_num; ++i) {
2446 oconfig_item_t *item = ci->children + i;
2448 /* if (!item || !item->key || !*item->key) continue; */
2449 if (strcasecmp(item->key, "Interval") == 0)
2450 cna_config_get_interval (item, &cfg_volume_perf->interval);
2451 else if (!strcasecmp(item->key, "GetIO"))
2452 cna_config_volume_perf_option (cfg_volume_perf, item);
2453 else if (!strcasecmp(item->key, "GetOps"))
2454 cna_config_volume_perf_option (cfg_volume_perf, item);
2455 else if (!strcasecmp(item->key, "GetLatency"))
2456 cna_config_volume_perf_option (cfg_volume_perf, item);
2457 else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
2458 cna_config_volume_perf_default (cfg_volume_perf, item);
2459 else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
2460 cna_config_volume_perf_default (cfg_volume_perf, item);
2461 else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
2462 cna_config_volume_perf_default (cfg_volume_perf, item);
2464 WARNING ("netapp plugin: The option %s is not allowed within "
2465 "`VolumePerf' blocks.", item->key);
2469 } /* }}} int cna_config_volume_performance */
2471 /* Handling of the "GetCapacity" and "GetSnapshot" options within a
2472 * <VolumeUsage /> block. */
2473 static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
2474 const oconfig_item_t *ci)
2479 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
2481 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2486 name = ci->values[0].value.string;
2488 if (strcasecmp ("GetCapacity", ci->key) == 0)
2489 il = cvu->il_capacity;
2490 else if (strcasecmp ("GetSnapshot", ci->key) == 0)
2491 il = cvu->il_snapshot;
2495 ignorelist_add (il, name);
2496 } /* }}} void cna_config_volume_usage_option */
2498 /* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
2499 * options within a <VolumeUsage /> block. */
2500 static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
2501 const oconfig_item_t *ci)
2505 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
2507 WARNING ("netapp plugin: The %s option requires exactly one string argument.",
2512 if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
2513 il = cvu->il_capacity;
2514 else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
2515 il = cvu->il_snapshot;
2519 if (ci->values[0].value.boolean)
2520 ignorelist_set_invert (il, /* invert = */ 0);
2522 ignorelist_set_invert (il, /* invert = */ 1);
2523 } /* }}} void cna_config_volume_usage_default */
2525 /* Corresponds to a <Quota /> block */
2526 static int cna_config_quota (host_config_t *host, oconfig_item_t *ci) /* {{{ */
2528 cfg_quota_t *cfg_quota;
2531 if ((host == NULL) || (ci == NULL))
2534 if (host->cfg_quota == NULL)
2536 cfg_quota = malloc (sizeof (*cfg_quota));
2537 if (cfg_quota == NULL)
2539 memset (cfg_quota, 0, sizeof (*cfg_quota));
2540 cfg_quota->query = NULL;
2542 host->cfg_quota = cfg_quota;
2544 cfg_quota = host->cfg_quota;
2546 for (i = 0; i < ci->children_num; ++i) {
2547 oconfig_item_t *item = ci->children + i;
2549 if (strcasecmp (item->key, "Interval") == 0)
2550 cna_config_get_interval (item, &cfg_quota->interval);
2552 WARNING ("netapp plugin: The option %s is not allowed within "
2553 "`Quota' blocks.", item->key);
2557 } /* }}} int cna_config_quota */
2559 /* Corresponds to a <Disks /> block */
2560 static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
2561 cfg_disk_t *cfg_disk;
2564 if ((host == NULL) || (ci == NULL))
2567 if (host->cfg_disk == NULL)
2569 cfg_disk = malloc (sizeof (*cfg_disk));
2570 if (cfg_disk == NULL)
2572 memset (cfg_disk, 0, sizeof (*cfg_disk));
2574 /* Set default flags */
2575 cfg_disk->flags = CFG_DISK_ALL;
2576 cfg_disk->query = NULL;
2577 cfg_disk->disks = NULL;
2579 host->cfg_disk = cfg_disk;
2581 cfg_disk = host->cfg_disk;
2583 for (i = 0; i < ci->children_num; ++i) {
2584 oconfig_item_t *item = ci->children + i;
2586 /* if (!item || !item->key || !*item->key) continue; */
2587 if (strcasecmp(item->key, "Interval") == 0)
2588 cna_config_get_interval (item, &cfg_disk->interval);
2589 else if (strcasecmp(item->key, "GetBusy") == 0)
2590 cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
2593 if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
2595 NOTICE ("netapp plugin: All disk related values have been disabled. "
2596 "Collection of per-disk data will be disabled entirely.");
2597 free_cfg_disk (host->cfg_disk);
2598 host->cfg_disk = NULL;
2602 } /* }}} int cna_config_disk */
2604 /* Corresponds to a <WAFL /> block */
2605 static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
2607 cfg_wafl_t *cfg_wafl;
2610 if ((host == NULL) || (ci == NULL))
2613 if (host->cfg_wafl == NULL)
2615 cfg_wafl = malloc (sizeof (*cfg_wafl));
2616 if (cfg_wafl == NULL)
2618 memset (cfg_wafl, 0, sizeof (*cfg_wafl));
2620 /* Set default flags */
2621 cfg_wafl->flags = CFG_WAFL_ALL;
2623 host->cfg_wafl = cfg_wafl;
2625 cfg_wafl = host->cfg_wafl;
2627 for (i = 0; i < ci->children_num; ++i) {
2628 oconfig_item_t *item = ci->children + i;
2630 if (strcasecmp(item->key, "Interval") == 0)
2631 cna_config_get_interval (item, &cfg_wafl->interval);
2632 else if (!strcasecmp(item->key, "GetNameCache"))
2633 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
2634 else if (!strcasecmp(item->key, "GetDirCache"))
2635 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
2636 else if (!strcasecmp(item->key, "GetBufferCache"))
2637 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
2638 else if (!strcasecmp(item->key, "GetInodeCache"))
2639 cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
2641 WARNING ("netapp plugin: The %s config option is not allowed within "
2642 "`WAFL' blocks.", item->key);
2645 if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
2647 NOTICE ("netapp plugin: All WAFL related values have been disabled. "
2648 "Collection of WAFL data will be disabled entirely.");
2649 free_cfg_wafl (host->cfg_wafl);
2650 host->cfg_wafl = NULL;
2654 } /* }}} int cna_config_wafl */
2658 * GetCapacity "vol0"
2659 * GetCapacity "vol1"
2660 * GetCapacity "vol2"
2661 * GetCapacity "vol3"
2662 * GetCapacity "vol4"
2663 * IgnoreSelectedCapacity false
2665 * GetSnapshot "vol0"
2666 * GetSnapshot "vol3"
2667 * GetSnapshot "vol4"
2668 * GetSnapshot "vol7"
2669 * IgnoreSelectedSnapshot false
2672 /* Corresponds to a <VolumeUsage /> block */
2673 static int cna_config_volume_usage(host_config_t *host, /* {{{ */
2674 const oconfig_item_t *ci)
2676 cfg_volume_usage_t *cfg_volume_usage;
2679 if ((host == NULL) || (ci == NULL))
2682 if (host->cfg_volume_usage == NULL)
2684 cfg_volume_usage = malloc (sizeof (*cfg_volume_usage));
2685 if (cfg_volume_usage == NULL)
2687 memset (cfg_volume_usage, 0, sizeof (*cfg_volume_usage));
2689 /* Set default flags */
2690 cfg_volume_usage->query = NULL;
2691 cfg_volume_usage->volumes = NULL;
2693 cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
2694 if (cfg_volume_usage->il_capacity == NULL)
2696 sfree (cfg_volume_usage);
2700 cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
2701 if (cfg_volume_usage->il_snapshot == NULL)
2703 ignorelist_free (cfg_volume_usage->il_capacity);
2704 sfree (cfg_volume_usage);
2708 host->cfg_volume_usage = cfg_volume_usage;
2710 cfg_volume_usage = host->cfg_volume_usage;
2712 for (i = 0; i < ci->children_num; ++i) {
2713 oconfig_item_t *item = ci->children + i;
2715 /* if (!item || !item->key || !*item->key) continue; */
2716 if (strcasecmp(item->key, "Interval") == 0)
2717 cna_config_get_interval (item, &cfg_volume_usage->interval);
2718 else if (!strcasecmp(item->key, "GetCapacity"))
2719 cna_config_volume_usage_option (cfg_volume_usage, item);
2720 else if (!strcasecmp(item->key, "GetSnapshot"))
2721 cna_config_volume_usage_option (cfg_volume_usage, item);
2722 else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
2723 cna_config_volume_usage_default (cfg_volume_usage, item);
2724 else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
2725 cna_config_volume_usage_default (cfg_volume_usage, item);
2727 WARNING ("netapp plugin: The option %s is not allowed within "
2728 "`VolumeUsage' blocks.", item->key);
2732 } /* }}} int cna_config_volume_usage */
2734 /* Corresponds to a <SnapVault /> block */
2735 static int cna_config_snapvault (host_config_t *host, /* {{{ */
2736 const oconfig_item_t *ci)
2738 cfg_snapvault_t *cfg_snapvault;
2741 if ((host == NULL) || (ci == NULL))
2744 if (host->cfg_snapvault == NULL)
2746 cfg_snapvault = malloc (sizeof (*cfg_snapvault));
2747 if (cfg_snapvault == NULL)
2749 memset (cfg_snapvault, 0, sizeof (*cfg_snapvault));
2750 cfg_snapvault->query = NULL;
2752 host->cfg_snapvault = cfg_snapvault;
2755 cfg_snapvault = host->cfg_snapvault;
2757 for (i = 0; i < ci->children_num; ++i) {
2758 oconfig_item_t *item = ci->children + i;
2760 if (strcasecmp (item->key, "Interval") == 0)
2761 cna_config_get_interval (item, &cfg_snapvault->interval);
2763 WARNING ("netapp plugin: The option %s is not allowed within "
2764 "`SnapVault' blocks.", item->key);
2768 } /* }}} int cna_config_snapvault */
2770 /* Corresponds to a <System /> block */
2771 static int cna_config_system (host_config_t *host, /* {{{ */
2774 cfg_system_t *cfg_system;
2777 if ((host == NULL) || (ci == NULL))
2780 if (host->cfg_system == NULL)
2782 cfg_system = malloc (sizeof (*cfg_system));
2783 if (cfg_system == NULL)
2785 memset (cfg_system, 0, sizeof (*cfg_system));
2787 /* Set default flags */
2788 cfg_system->flags = CFG_SYSTEM_ALL;
2789 cfg_system->query = NULL;
2791 host->cfg_system = cfg_system;
2793 cfg_system = host->cfg_system;
2795 for (i = 0; i < ci->children_num; ++i) {
2796 oconfig_item_t *item = ci->children + i;
2798 if (strcasecmp(item->key, "Interval") == 0) {
2799 cna_config_get_interval (item, &cfg_system->interval);
2800 } else if (!strcasecmp(item->key, "GetCPULoad")) {
2801 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
2802 } else if (!strcasecmp(item->key, "GetInterfaces")) {
2803 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
2804 } else if (!strcasecmp(item->key, "GetDiskOps")) {
2805 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
2806 } else if (!strcasecmp(item->key, "GetDiskIO")) {
2807 cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
2809 WARNING ("netapp plugin: The %s config option is not allowed within "
2810 "`System' blocks.", item->key);
2814 if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
2816 NOTICE ("netapp plugin: All system related values have been disabled. "
2817 "Collection of system data will be disabled entirely.");
2818 free_cfg_system (host->cfg_system);
2819 host->cfg_system = NULL;
2823 } /* }}} int cna_config_system */
2825 /* Corresponds to a <Host /> block. */
2826 static host_config_t *cna_alloc_host (void) /* {{{ */
2828 host_config_t *host;
2830 host = malloc(sizeof(*host));
2833 memset (host, 0, sizeof (*host));
2836 host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2838 host->username = NULL;
2839 host->password = NULL;
2840 host->vfiler = NULL;
2842 host->cfg_wafl = NULL;
2843 host->cfg_disk = NULL;
2844 host->cfg_volume_perf = NULL;
2845 host->cfg_volume_usage = NULL;
2846 host->cfg_quota = NULL;
2847 host->cfg_snapvault = NULL;
2848 host->cfg_system = NULL;
2851 } /* }}} host_config_t *cna_alloc_host */
2853 static host_config_t *cna_shallow_clone_host (host_config_t *host) /* {{{ */
2855 host_config_t *clone;
2860 clone = cna_alloc_host ();
2864 if (host->name != NULL) {
2865 clone->name = strdup (host->name);
2866 if (clone->name == NULL) {
2867 free_host_config (clone);
2872 clone->protocol = host->protocol;
2874 if (host->host != NULL) {
2875 clone->host = strdup (host->host);
2876 if (clone->host == NULL) {
2877 free_host_config (clone);
2882 clone->port = host->port;
2884 if (host->username != NULL) {
2885 clone->username = strdup (host->username);
2886 if (clone->username == NULL) {
2887 free_host_config (clone);
2891 if (host->password != NULL) {
2892 clone->password = strdup (host->password);
2893 if (clone->password == NULL) {
2894 free_host_config (clone);
2899 clone->interval = host->interval;
2902 } /* }}} host_config_t *cna_shallow_clone_host */
2904 static int cna_read (user_data_t *ud);
2906 static int cna_register_host (host_config_t *host) /* {{{ */
2912 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s-%s",
2913 host->name, host->vfiler);
2915 ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name);
2917 memset (&ud, 0, sizeof (ud));
2919 ud.free_func = (void (*) (void *)) free_host_config;
2921 plugin_register_complex_read (/* group = */ NULL, cb_name,
2922 /* callback = */ cna_read,
2923 /* interval = */ host->interval,
2924 /* user data = */ &ud);
2927 } /* }}} int cna_register_host */
2929 static int cna_config_host (host_config_t *host, /* {{{ */
2930 const oconfig_item_t *ci)
2932 oconfig_item_t *item;
2933 _Bool is_vfiler = 0;
2937 if (! strcasecmp (ci->key, "VFiler"))
2940 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
2941 WARNING ("netapp plugin: \"%s\" needs exactly one string argument. Ignoring host block.", ci->key);
2945 status = cf_util_get_string (ci, &host->name);
2949 for (i = 0; i < ci->children_num; ++i) {
2950 item = ci->children + i;
2954 if (!strcasecmp(item->key, "Address")) {
2955 status = cf_util_get_string (item, &host->host);
2956 } else if (!strcasecmp(item->key, "Port")) {
2959 tmp = cf_util_get_port_number (item);
2962 } else if (!strcasecmp(item->key, "Protocol")) {
2963 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"))) {
2964 WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
2967 if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
2968 else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
2969 } else if (!strcasecmp(item->key, "User")) {
2970 status = cf_util_get_string (item, &host->username);
2971 } else if (!strcasecmp(item->key, "Password")) {
2972 status = cf_util_get_string (item, &host->password);
2973 } else if (!strcasecmp(item->key, "Interval")) {
2974 status = cf_util_get_cdtime (item, &host->interval);
2975 } else if (!strcasecmp(item->key, "WAFL")) {
2976 cna_config_wafl(host, item);
2977 } else if (!strcasecmp(item->key, "Disks")) {
2978 cna_config_disk(host, item);
2979 } else if (!strcasecmp(item->key, "VolumePerf")) {
2980 cna_config_volume_performance(host, item);
2981 } else if (!strcasecmp(item->key, "VolumeUsage")) {
2982 cna_config_volume_usage(host, item);
2983 } else if (!strcasecmp(item->key, "Quota")) {
2984 cna_config_quota(host, item);
2985 } else if (!strcasecmp(item->key, "SnapVault")) {
2986 cna_config_snapvault(host, item);
2987 } else if (!strcasecmp(item->key, "System")) {
2988 cna_config_system(host, item);
2989 } else if ((!strcasecmp(item->key, "VFiler")) && (! is_vfiler)) {
2990 host_config_t *vfiler;
2992 vfiler = cna_shallow_clone_host (host);
2994 ERROR ("netapp plugin: Failed to allocate host object for vfiler.");
2998 if (cna_config_host (vfiler, item)) {
2999 free_host_config (vfiler);
3003 cna_register_host (vfiler);
3004 } else if ((!strcasecmp(item->key, "VFilerName")) && is_vfiler) {
3005 status = cf_util_get_string (item, &host->vfiler);
3007 WARNING ("netapp plugin: Ignoring unknown config option \"%s\" in %s block \"%s\".",
3008 item->key, is_vfiler ? "vfiler" : "host", ci->values[0].value.string);
3015 if (host->host == NULL)
3016 host->host = strdup (host->name);
3018 if (is_vfiler && (! host->vfiler))
3019 host->vfiler = strdup (host->name);
3021 if (host->host == NULL)
3024 if (host->port <= 0)
3025 host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
3027 if ((host->username == NULL) || (host->password == NULL)) {
3028 WARNING("netapp plugin: Please supply login information for host \"%s\". "
3029 "Ignoring host block.", host->name);
3037 } /* }}} host_config_t *cna_config_host */
3040 * Callbacks registered with the daemon
3042 * Pretty standard stuff here.
3044 static int cna_init_host (host_config_t *host) /* {{{ */
3046 /* Request version 1.1 of the ONTAP API */
3047 int major_version = 1, minor_version = 1;
3052 if (host->srv != NULL)
3055 if (host->vfiler != NULL) /* Request version 1.7 of the ONTAP API */
3058 host->srv = na_server_open (host->host, major_version, minor_version);
3059 if (host->srv == NULL) {
3060 ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
3064 na_server_set_transport_type(host->srv, host->protocol,
3065 /* transportarg = */ NULL);
3066 na_server_set_port(host->srv, host->port);
3067 na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
3068 na_server_adminuser(host->srv, host->username, host->password);
3069 na_server_set_timeout(host->srv, 5 /* seconds */);
3071 if (host->vfiler != NULL) {
3072 if (! na_server_set_vfiler (host->srv, host->vfiler)) {
3073 ERROR ("netapp plugin: Failed to connect to VFiler '%s' on host '%s'.",
3074 host->vfiler, host->host);
3078 INFO ("netapp plugin: Connected to VFiler '%s' on host '%s'.",
3079 host->vfiler, host->host);
3084 } /* }}} int cna_init_host */
3086 static int cna_init (void) /* {{{ */
3090 memset (err, 0, sizeof (err));
3091 if (!na_startup(err, sizeof(err))) {
3092 err[sizeof (err) - 1] = 0;
3093 ERROR("netapp plugin: Error initializing netapp API: %s", err);
3098 } /* }}} cna_init */
3100 static int cna_read_internal (host_config_t *host) { /* {{{ */
3103 status = cna_query_wafl (host);
3107 status = cna_query_disk (host);
3111 status = cna_query_volume_perf (host);
3115 status = cna_query_volume_usage (host);
3119 status = cna_query_quota (host);
3123 status = cna_query_snapvault (host);
3127 status = cna_query_system (host);
3132 } /* }}} int cna_read_internal */
3134 static int cna_read (user_data_t *ud) { /* {{{ */
3135 host_config_t *host;
3138 if ((ud == NULL) || (ud->data == NULL))
3143 status = cna_init_host (host);
3147 status = cna_read_internal (host);
3150 if (host->srv != NULL)
3151 na_server_close (host->srv);
3156 } /* }}} int cna_read */
3158 static int cna_config (oconfig_item_t *ci) { /* {{{ */
3160 oconfig_item_t *item;
3162 for (i = 0; i < ci->children_num; ++i) {
3163 item = ci->children + i;
3165 if (strcasecmp(item->key, "Host") == 0)
3167 host_config_t *host;
3169 host = cna_alloc_host ();
3171 ERROR ("netapp plugin: Failed to allocate host object.");
3175 if (cna_config_host (host, item) != 0) {
3176 free_host_config (host);
3180 cna_register_host (host);
3182 else /* if (item->key != "Host") */
3184 WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
3188 } /* }}} int cna_config */
3190 static int cna_shutdown (void) /* {{{ */
3192 /* Clean up system resources and stuff. */
3196 } /* }}} int cna_shutdown */
3198 void module_register(void) {
3199 plugin_register_complex_config("netapp", cna_config);
3200 plugin_register_init("netapp", cna_init);
3201 plugin_register_shutdown("netapp", cna_shutdown);
3204 /* vim: set sw=2 ts=2 noet fdm=marker : */