Cleanup config.nodes_of
[check_mk.git] / checks / netapp_api_volumes
blob141a136666586a47aaa23bc8e5a8f1ed4a74bd75
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 # tails. You should have received a copy of the GNU General Public
23 # License along with GNU Make; see the file COPYING. If not, write
24 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 # Boston, MA 02110-1301 USA.
27 # <<<netapp_api_volumes:sep(9)>>>
28 # volume vol0 size-available 556613632 state online files-total 25876 files-used 8646 size-total 848203776 fcp_write_data 0 fcp_read_data 0cifs_write_data 0 iscsi_read_latency 0 iscsi_write_data 0 read_data 201265528798 nfs_write_latency 977623886 san_write_latency 0 san_write_data 0read_latency 1529821621 cifs_read_latency 0 fcp_write_latency 0 fcp_read_latency 0 iscsi_write_latency 0 nfs_read_latency 1491050012 iscsi_read_data 0 instance_name vol0 cifs_read_data 0 nfs_read_data 197072260981 write_latency 1528780977 san_read_data 0 san_read_latency 0 write_data 13926719804 nfs_write_data 2789744628 cifs_write_latency 0
31 def parse_netapp_api_volumes(info):
32 volumes = {}
33 for line in info:
34 volume = {}
35 name = line[0].split(" ", 1)[1]
36 for element in line[1:]:
37 tokens = element.split(" ", 1)
38 volume[tokens[0]] = tokens[1]
40 # Clustermode specific
41 if "vserver_name" in volume:
42 name = "%s.%s" % (volume["vserver_name"], volume["name"])
44 volumes[name] = volume
46 return volumes
49 def inventory_netapp_api_volumes(parsed):
50 for volume in parsed.keys():
51 yield volume, {}
54 # Cannot use decorator get_parsed_item_data for this check function due to the
55 # specific error message for legacy checks with a UUID as item
56 def check_netapp_api_volumes(item, params, parsed):
57 volume = parsed.get(item)
58 if not volume:
59 if len(item.split("-")) > 4:
60 return 3, "The service description with a UUID is no longer supported. Please do a rediscovery."
61 return
63 if volume.get("state") != "online":
64 return 1, "Volume is %s" % volume.get("state")
66 mega = 1024.0 * 1024.0
67 size_total = int(volume.get("size-total")) / mega
68 size_avail = int(volume.get("size-available")) / mega
69 inodes_total = int(volume.get("files-total"))
70 inodes_avail = inodes_total - int(volume.get("files-used"))
71 state, info, perf = df_check_filesystem_single(item, size_total, size_avail, 0, inodes_total,
72 inodes_avail, params)
74 counter_wrapped = False
75 counters = []
76 now = time.time()
77 base = {}
79 perf_protocols = params.get("perfdata", [])
80 for protocol in ["", "nfs_", "cifs_", "san_", "fcp_", "iscsi_"]:
81 if protocol[:-1] not in perf_protocols:
82 continue
83 for mode in ["read_", "write_", "other_"]:
84 for field, factor, format_text in [
85 ("data", None, None),
86 ("ops", None, "%s: %.2f 1/s"),
87 ("latency", 10000.0, "%s: %.2f ms"),
89 key = protocol + mode + field
90 value = volume.get(key)
91 if value is not None:
92 value = int(value)
93 try:
94 delta = get_rate(
95 "netapp_api_volumes.%s.%s" % (item, key), now, value, onwrap=RAISE)
96 perf.append((key, delta))
98 # Quite hacky.. this base information is used later on by the "latency" field
99 if field == "ops":
100 if delta == 0.0:
101 base[key] = 1.0
102 else:
103 base[key] = float(delta)
105 if protocol == "" and mode in ["read_", "write_"]:
106 if factor:
107 delta = delta / (factor * base[protocol + mode + "ops"])
108 if format_text:
109 counters.append(format_text % (key, delta))
110 else:
111 counters.append("%s: %s" % (key, get_bytes_human_readable(delta)))
112 except MKCounterWrapped:
113 counter_wrapped = True
115 if not counter_wrapped:
116 info += ", " + ", ".join(counters)
118 return state, info, perf
121 check_info["netapp_api_volumes"] = {
122 'check_function': check_netapp_api_volumes,
123 'inventory_function': inventory_netapp_api_volumes,
124 'parse_function': parse_netapp_api_volumes,
125 'service_description': 'Volume %s',
126 'has_perfdata': True,
127 'group': "netapp_volumes",
128 'includes': ["size_trend.include", "df.include", "netapp_api.include"],
129 "default_levels_variable": "filesystem_default_levels",