Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / db2_sort_overflow
blob627c2bae94e184fdd296808a54d8890faba66c6a
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_sort_overflow>>>
28 # [[[test:datenbank1]]]
29 # Total sorts 100
30 # Sort overflows 3
32 factory_settings["db2_sort_overflow_default_levels"] = {"levels_perc": (2.0, 4.0)}
35 def inventory_db2_sort_overflow(parsed):
36 for key in parsed[1].iterkeys():
37 yield key, {}
40 def check_db2_sort_overflow(item, params, parsed):
41 db = parsed[1].get(item)
42 if not db:
43 raise MKCounterWrapped("Login into database failed")
45 total, overflows = tuple(float(x[-1]) for x in db)
46 if total > 0:
47 overflow_perc = overflows * 100 / total
48 else:
49 overflow_perc = 0.0
50 warn, crit = params.get("levels_perc")
51 if overflow_perc >= crit:
52 yield 2, "%.1f%% sort overflow (leves at %.1f%%/%.1f%%)" % \
53 (overflow_perc, warn, crit)
54 elif overflow_perc >= warn:
55 yield 1, "%.1f%% sort overflow (leves at %.1f%%/%.1f%%)" % \
56 (overflow_perc, warn, crit)
57 else:
58 yield 0, "%.1f%% sort overflow" % overflow_perc
60 yield 0, "Sort overflows: %d" % overflows
61 yield 0, "Total sorts: %d" % total, [("sort_overflow", overflow_perc, warn, crit, 0, 100)]
64 check_info['db2_sort_overflow'] = {
65 "parse_function": parse_db2_dbs,
66 "service_description": "DB2 Sort Overflow %s",
67 "check_function": check_db2_sort_overflow,
68 "inventory_function": inventory_db2_sort_overflow,
69 "has_perfdata": True,
70 "group": "db2_sortoverflow",
71 "default_levels_variable": "db2_sort_overflow_default_levels",
72 "includes": ["db2.include"]