Cleanup config.nodes_of
[check_mk.git] / checks / netapp_api_cpu
blob62d3d2dd934d3c9374e8aa553a57f4b7a98a59ac
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 # 7mode
28 # <<<netapp_api_cpu:sep(9)>>>
29 # cpu_busy 8362860064
30 # num_processors 2
32 # clustermode
33 # cpu-info clu1-01 num_processors 2
34 # cpu-info clu1-02 num_processors 2
35 # cpu-info clu1-01 cpu_busy 5340000 nvram-battery-status battery_ok
36 # cpu-info clu1-02 cpu_busy 5400000 nvram-battery-status battery_ok
38 netapp_api_cpu_default_levels = (90.0, 95.0)
40 factory_settings["netapp_api_cpu_cm_default_levels"] = {"levels": (90.0, 95.0)}
43 def parse_netapp_api_cpu(info):
44 cpu_info = {}
45 for line in info:
46 if line[0].startswith("cpu-info"): # clustermode
47 _, node_name = line[0].split()
48 cpu_info.setdefault("clustermode", {})
49 for entry in line[1:]:
50 key, value = entry.split()
51 cpu_info["clustermode"].setdefault(node_name, {})
52 cpu_info["clustermode"][node_name][key] = value
53 else:
54 cpu_info.setdefault("7mode", {})
55 cpu_info["7mode"][line[0]] = line[1]
56 return cpu_info
59 def inventory_netapp_api_cpu_utilization(parsed):
60 if "7mode" in parsed:
61 yield (None, "netapp_api_cpu_default_levels")
64 def inventory_netapp_api_cpu(parsed):
65 if "clustermode" in parsed:
66 for node in parsed.get("clustermode", {}).keys():
67 yield node, {}
70 def check_netapp_api_cpu_utilization(item, params, parsed, mode):
71 mode_data = parsed.get(mode)
72 if item:
73 data = mode_data.get(item)
74 if data is None:
75 return 3, "No data available!"
76 else:
77 data = mode_data
79 now = time.time()
81 cpu_busy = int(data["cpu_busy"])
82 num_cpus_str = data.get("num_processors")
83 ticks_per_sec = get_rate("netapp_api_cpu.utilization", now, cpu_busy, onwrap=RAISE)
84 cpusecs_per_sec = ticks_per_sec / 1000000.0
85 used_perc = 100.0 * cpusecs_per_sec
87 # Due to timeing invariancies the measured level can become > 100%.
88 # This makes users unhappy, so cut it off.
89 if used_perc < 0:
90 used_perc = 0
91 elif used_perc > 100:
92 used_perc = 100
94 state, infotext, perfdata = check_cpu_util(used_perc, params, now).next()
95 if num_cpus_str is not None:
96 num_cpus = int(num_cpus_str)
97 perfdata[0] = perfdata[0][:5] + (num_cpus,)
98 infotext += ", %d CPUs" % num_cpus
99 return state, infotext, perfdata
102 # Clustermode CPU utilization
103 check_info["netapp_api_cpu"] = {
104 "parse_function": parse_netapp_api_cpu,
105 "inventory_function": inventory_netapp_api_cpu,
106 "check_function": lambda item, params, parsed: check_netapp_api_cpu_utilization(
107 item, params, parsed, "clustermode"),
108 "service_description": "CPU utilization Node %s",
109 "has_perfdata": True,
110 "group": "cpu_utilization_multiitem",
111 "includes": ["cpu_util.include", "netapp_api.include"]
114 # 7Mode CPU utilization
115 check_info["netapp_api_cpu.utilization"] = {
116 "inventory_function": inventory_netapp_api_cpu_utilization,
117 "check_function": lambda item, params, parsed: check_netapp_api_cpu_utilization(
118 item, params, parsed, "7mode"),
119 "service_description": "CPU utilization",
120 "default_levels_variable": "netapp_api_cpu_cm_default_levels",
121 "has_perfdata": True,
122 "group": "cpu_utilization",
123 "includes": ["cpu_util.include"]
127 def inventory_netapp_api_nvram_bat(parsed):
128 for node, values in parsed.get("clustermode", {}).items():
129 if "nvram-battery-status" in values:
130 yield node, None
133 def check_netapp_api_nvram_bat(item, _no_params, parsed):
134 state_map = {
135 "battery_ok": 0,
136 "battery_partially_discharged": 0,
137 "battery_fully_discharged ": 2,
138 "battery_not_present": 2,
139 "battery_near_end_of_life": 1,
140 "battery_at_end_of_life": 2,
141 "battery_unknown": 3,
142 "battery_over_charged": 1,
143 "battery_fully_charged": 0
146 info = parsed.get("clustermode", {}).get(item)
147 if not info or "nvram-battery-status" not in info:
148 return
150 yield state_map.get(info["nvram-battery-status"], 3), "Status: %s" %\
151 info["nvram-battery-status"].replace("_", " ").title()
154 # Clustermode NVRAM Bat
155 check_info["netapp_api_cpu.nvram_bat"] = {
156 "inventory_function": inventory_netapp_api_nvram_bat,
157 "check_function": check_netapp_api_nvram_bat,
158 "service_description": "NVRAM Battery %s",
159 "has_perfdata": True,
160 "includes": ["cpu_util.include", "netapp_api.include"]