Cleanup config.nodes_of
[check_mk.git] / checks / casa_cpu_util
blob466292fd865b6ea84b7995a985d7d9a012eb56b7
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.
28 def parse_casa_info_util(info):
29 entity_names = {int(k): v for k, v in (x for x in info[0])}
30 data = {}
31 for entry in info[1]:
32 entry_nr = int(entry[0])
33 name = entity_names[entry_nr] # e.g. "Module 1 QEM".
34 # Drop "QEM" in order to be consistent with other DTCS checks...
35 if name.startswith("Module "):
36 name = name.rsplit(None, 1)[0]
37 data[name] = {
38 "cpu_util": entry[1],
40 return data
43 def inventory_casa_cpu_util(info):
44 data = parse_casa_info_util(info)
45 inventory = []
46 for key, value in data.items():
47 if value.get("cpu_util"):
48 inventory.append((key, {}))
49 return inventory
52 def check_casa_cpu_util(item, params, info):
53 data = parse_casa_info_util(info)
54 if item in data:
55 state = 0
56 value = int(data[item]["cpu_util"])
57 levels_text = ""
58 error_text = ""
59 warn, crit = None, None
60 if "levels" in params:
61 warn, crit = params["levels"]
62 levels_text = "(warn/crit at %s%%/%s%%)" % (warn, crit)
63 if value > crit:
64 state = 2
65 elif value > warn:
66 state = 1
67 else:
68 levels_text = ""
69 infotext = "%d%% %s%s" % (value, error_text, levels_text)
70 perfdata = [("util", value, warn, crit, 0, 100)]
71 return (state, infotext, perfdata)
72 else:
73 return 3, "%s not found in SNMP output" % item
76 check_info["casa_cpu_util"] = {
77 "check_function": check_casa_cpu_util,
78 "inventory_function": inventory_casa_cpu_util,
79 "service_description": "CPU utilization %s",
80 "has_perfdata": True,
81 "group": "cpu_utilization_multiitem",
82 "snmp_scan_function": lambda oid: oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.20858.2."),
83 "snmp_info": [
84 (".1.3.6.1.2.1.47.1.1.1.1.2", [OID_END, '']), # Entity descriptions, quite long...
85 (".1.3.6.1.4.1.20858.10.13.1.1.1.4", [OID_END, '']), # CPU utilization