Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / db2_counters
blob48aea55f072d4e92c421c1bc74c8cfdfb34ac460
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 # <<<db2_counters>>>
28 # TIMESTAMP 1426610723
29 # db2taddm:CMDBS1 deadlocks 0
30 # db2taddm:CMDBS1 lockwaits 99
31 # db2taddm:CMDBS1 sortoverflows 2387
32 # TIMESTAMP 1426610763
33 # db2taddm:CMDBS6 deadlocks 99
34 # db2taddm:CMDBS6 lockwaits 91
35 # db2taddm:CMDBS6 sortoverflows 237
36 #### Example for database in DPF mode
37 # TIMESTAMP 1439976757
38 # db2ifa:DDST1 node 0 iasv0091 0
39 # db2ifa:DDST1 node 1 iasv0091 1
40 # db2ifa:DDST1 node 2 iasv0091 2
41 # db2ifa:DDST1 node 3 iasv0091 3
42 # db2ifa:DDST1 node 4 iasv0091 4
43 # db2ifa:DDST1 node 5 iasv0091 5
44 # db2ifa:DDST1 deadlocks 0
45 # db2ifa:DDST1 deadlocks 0
46 # db2ifa:DDST1 deadlocks 0
47 # db2ifa:DDST1 deadlocks 0
48 # db2ifa:DDST1 deadlocks 0
49 # db2ifa:DDST1 deadlocks 0
50 # db2ifa:DDST1 lockwaits 0
51 # db2ifa:DDST1 lockwaits 0
52 # db2ifa:DDST1 lockwaits 0
53 # db2ifa:DDST1 lockwaits 0
54 # db2ifa:DDST1 lockwaits 0
55 # db2ifa:DDST1 lockwaits 80
57 factory_settings["db2_counters_default_levels"] = {}
59 db2_counters_map = {
60 "deadlocks": "Deadlocks",
61 "lockwaits": "Lockwaits",
65 def parse_db2_counters(info):
66 dbs = {}
67 timestamp = 0
68 node_infos = []
69 element_offset = {}
70 for line in info:
71 if line[0].startswith("TIMESTAMP"):
72 element_offset = {}
73 node_infos = []
74 timestamp = int(line[1])
75 elif line[1] == "node":
76 node_infos.append(" ".join(line[2:]))
77 # Some databases run in DPF mode. Means that the database is split over several nodes
78 # The counter information also differs for each node. We create one service per DPF node
79 elif line[1] in db2_counters_map.keys():
80 if node_infos:
81 element_offset.setdefault(line[1], 0)
82 offset = element_offset[line[1]]
83 key = "%s DPF %s" % (line[0], node_infos[offset])
84 element_offset[line[1]] += 1
85 else:
86 key = line[0]
87 dbs.setdefault(key, {"TIMESTAMP": timestamp})
88 dbs[key][line[1]] = line[2]
90 # The timestamp is still used for legacy reasons
91 # The instance specific timestamp is now available in the dbs
92 return timestamp, dbs
95 def inventory_db2_counters(parsed):
96 if len(parsed) == 2:
97 for db in parsed[1]:
98 yield db, {}
101 def check_db2_counters(item, params, parsed):
102 default_timestamp = parsed[0]
103 db = parsed[1].get(item)
104 if not db:
105 raise MKCounterWrapped("Login into database failed")
107 wrapped = False
108 timestamp = db.get("TIMESTAMP", default_timestamp)
109 for counter, label in db2_counters_map.items():
110 try:
111 value = float(db[counter])
112 except ValueError:
113 yield 2, "Invalid value: " + db[counter]
114 continue
116 try:
117 rate = get_rate("db2_counters.%s.%s" % (item, counter), timestamp, value, onwrap=RAISE)
118 except MKCounterWrapped:
119 wrapped = True
120 continue
122 warn, crit = params.get(counter, (None, None))
123 perfdata = [(counter, rate, warn, crit)]
124 if crit is not None and rate >= crit:
125 yield 2, "%s: %.1f/s" % (label, rate), perfdata
126 elif warn is not None and rate >= warn:
127 yield 1, "%s: %.1f/s" % (label, rate), perfdata
128 else:
129 yield 0, "%s: %.1f/s" % (label, rate), perfdata
131 if wrapped:
132 raise MKCounterWrapped("Some counter(s) wrapped, no data this time")
135 check_info['db2_counters'] = {
136 "parse_function": parse_db2_counters,
137 "service_description": "DB2 Counters %s",
138 "check_function": check_db2_counters,
139 "inventory_function": inventory_db2_counters,
140 "has_perfdata": True,
141 "group": "db2_counters",
142 "includes": ["db2.include"],
143 "default_levels_variable": "db2_counters_default_levels",