Cleanup config.nodes_of
[check_mk.git] / checks / arbor.include
blobed364c2d78449f0be88223b8edfe5207873d4bf8
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2015 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 # .--Common--------------------------------------------------------------.
28 # | ____ |
29 # | / ___|___ _ __ ___ _ __ ___ ___ _ __ |
30 # | | | / _ \| '_ ` _ \| '_ ` _ \ / _ \| '_ \ |
31 # | | |__| (_) | | | | | | | | | | | (_) | | | | |
32 # | \____\___/|_| |_| |_|_| |_| |_|\___/|_| |_| |
33 # | |
34 # '----------------------------------------------------------------------'
37 def arbor_test_threshold(perc, name, warn, crit):
38 status = perc > crit and 2\
39 or perc > warn and 1\
40 or 0
41 infotext = "%s used: %d%%" % (name, perc)
43 if status > 0:
44 infotext += " (warn/crit at %.1f%%/%.1f%%) (%s)" % (warn, crit, "!" * status)
45 return status, infotext
49 # .--Memory--------------------------------------------------------------.
50 # | __ __ |
51 # | | \/ | ___ _ __ ___ ___ _ __ _ _ |
52 # | | |\/| |/ _ \ '_ ` _ \ / _ \| '__| | | | |
53 # | | | | | __/ | | | | | (_) | | | |_| | |
54 # | |_| |_|\___|_| |_| |_|\___/|_| \__, | |
55 # | |___/ |
56 # '----------------------------------------------------------------------'
58 factory_settings["arbor_memory_default_levels"] = {
59 "levels_ram": ("perc_used", (80.0, 90.0)),
60 "levels_swap": ("perc_used", (80.0, 90.0)),
64 def inventory_arbor_memory(parsed):
65 if len(parsed) > 0:
66 return [(None, {})]
69 def check_arbor_memory(no_item, params, parsed):
70 def worst_status(*args):
71 order = [0, 1, 3, 2]
72 return sorted(args, key=lambda x: order[x], reverse=True)[0]
74 def combine_infotext(*blocks):
75 return ", ".join([b for b in blocks if b])
77 ram_perc, swap_perc = map(int, parsed['memory'])
79 ram_warn, ram_crit = params['levels_ram'][1]
80 swap_warn, swap_crit = params['levels_swap'][1]
82 ram_status, ram_info = arbor_test_threshold(ram_perc, "RAM", ram_warn, ram_crit)
83 swap_status, swap_info = arbor_test_threshold(swap_perc, "Swap", swap_warn, swap_crit)
85 infotext = combine_infotext(ram_info, swap_info)
87 perfdata = [
88 ('mem_used_percent', ram_perc, ram_warn, ram_crit),
89 ('swap_used_percent', swap_perc, swap_warn, swap_crit),
92 return worst_status(ram_status, swap_status), infotext, perfdata
96 # .--CPU Load------------------------------------------------------------.
97 # | ____ ____ _ _ _ _ |
98 # | / ___| _ \| | | | | | ___ __ _ __| | |
99 # | | | | |_) | | | | | | / _ \ / _` |/ _` | |
100 # | | |___| __/| |_| | | |__| (_) | (_| | (_| | |
101 # | \____|_| \___/ |_____\___/ \__,_|\__,_| |
102 # | |
103 # '----------------------------------------------------------------------'
105 arbor_cpuload_default_levels = (5.0, 10.0)
108 def inventory_arbor_cpu_load(parsed):
109 if "cpu_loads" in parsed:
110 return [(None, "arbor_cpuload_default_levels")]
113 def check_arbor_cpu_load(no_item, params, parsed):
114 load = [float(x) / 100.0 for x in parsed['cpu_loads']]
115 return check_cpu_load_generic(params, load, 1)
119 # .--Disk Usage----------------------------------------------------------.
120 # | ____ _ _ _ _ |
121 # | | _ \(_)___| | __ | | | |___ __ _ __ _ ___ |
122 # | | | | | / __| |/ / | | | / __|/ _` |/ _` |/ _ \ |
123 # | | |_| | \__ \ < | |_| \__ \ (_| | (_| | __/ |
124 # | |____/|_|___/_|\_\ \___/|___/\__,_|\__, |\___| |
125 # | |___/ |
126 # '----------------------------------------------------------------------'
129 def inventory_arbor_disk_usage(parsed):
130 if "disk" in parsed:
131 return [("/", {})]
134 def check_arbor_disk_usage(no_item, params, parsed):
135 usage = int(parsed['disk'])
136 status, infotext = arbor_test_threshold(usage, "Disk", *params['levels'])
137 return status, infotext, [('disk_utilization', float(usage) / 100.0)]
141 # .--Host Fault----------------------------------------------------------.
142 # | _ _ _ _____ _ _ |
143 # | | | | | ___ ___| |_ | ___|_ _ _ _| | |_ |
144 # | | |_| |/ _ \/ __| __| | |_ / _` | | | | | __| |
145 # | | _ | (_) \__ \ |_ | _| (_| | |_| | | |_ |
146 # | |_| |_|\___/|___/\__| |_| \__,_|\__,_|_|\__| |
147 # | |
148 # '----------------------------------------------------------------------'
151 def inventory_arbor_host_fault(parsed):
152 if 'host_fault' in parsed:
153 return [(None, None)]
156 def check_arbor_host_fault(no_item, no_params, parsed):
157 status = 0
158 if parsed['host_fault'] != "No Fault":
159 status = 2
160 return status, parsed['host_fault']
164 # .--Drop Rate-----------------------------------------------------------.
165 # | ____ ____ _ |
166 # | | _ \ _ __ ___ _ __ | _ \ __ _| |_ ___ |
167 # | | | | | '__/ _ \| '_ \ | |_) / _` | __/ _ \ |
168 # | | |_| | | | (_) | |_) | | _ < (_| | || __/ |
169 # | |____/|_| \___/| .__/ |_| \_\__,_|\__\___| |
170 # | |_| |
171 # '----------------------------------------------------------------------'
174 def inventory_arbor_drop_rate(parsed):
175 if 'drop_rate' in parsed:
176 return [("Overrun", {})]
179 def check_arbor_drop_rate(no_item, params, parsed):
180 drop_rate = int(parsed['drop_rate'])
181 infotext = '%s pps' % drop_rate
183 lower_status = 0
184 lower_levels = params.get('levels_lower')
185 if lower_levels:
186 warn, crit = lower_levels
188 if drop_rate <= crit:
189 lower_status, label = 2, '(!!)'
190 elif drop_rate <= warn:
191 lower_status, label = 1, '(!)'
193 if lower_status:
194 infotext += ' (warn/crit below %.1f/%.1f)%s' % (warn, crit, label)
196 upper_status = 0
197 upper_levels = params.get('levels')
198 if upper_levels:
199 warn, crit = upper_levels
201 if drop_rate >= crit:
202 upper_status, label = 2, '(!!)'
203 elif drop_rate >= warn:
204 upper_status, label = 1, '(!)'
206 if upper_status:
207 infotext += ' (warn/crit above %.1f/%.1f)%s' % (warn, crit, label)
209 perfdata = [("if_in_pkts", drop_rate, warn, crit)]
210 else:
211 perfdata = [("if_in_pkts", drop_rate)]
213 status = max(lower_status, upper_status)
214 yield status, infotext, perfdata