2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # ------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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 # No used space check for Tablsspaces with CONTENTS in ('TEMPORARY','UNDO')
28 # It is impossible to check the used space in UNDO and TEMPORARY Tablespaces
29 # These Types of Tablespaces are ignored in this plugin.
30 # This restriction is only working with newer agents, because we need an
31 # additional parameter at end if each datafile
33 # <<<db2_tablespaces>>>
34 # [[[db2taddm:CMDBS1]]]
35 # SYSCATSPACE DMS NORMAL 786304 786432 704224 82080
36 # USERSPACE1 DMS NORMAL 16874496 16875520 7010176 9809920
37 # SYSTOOLSPACE DMS NORMAL 32640 32768 3600 29040
38 # LARGESPACE2 DMS NORMAL 80896 81920 3072 77824
39 # TEMPSPACE1 SMS NORMAL 32 32 32 959659392
40 # USERSPACE2 SMS NORMAL 1327488 1327488 1327488 119957424
41 # LARGETEMP2 SMS NORMAL 32 32 32 119957424
42 # USERSPACE3 SMS NORMAL 1626712 1626712 1626712 119957424
43 # MYTMPSPACE SMS NORMAL 64 64 64 959659392
44 # SYSTOOLSTMPSPACE SMS NORMAL 32 32 32 959659392
46 factory_settings
["db2_tablespaces_default_levels"] = {
47 "levels": (10.0, 5.0),
48 "magic_normsize": 1000,
52 def inventory_db2_tablespaces(parsed
):
53 for instance
, values
in parsed
[1].items():
54 for table
in values
[1:]:
55 yield "%s.%s" % (instance
, table
[0]), {}
58 def check_db2_tablespaces(item
, params
, parsed
):
60 instance
, tbsname
= item
.split('.')
62 yield 3, 'Invalid check item given (must be <instance>.<tablespace>)'
65 db
= parsed
[1].get(instance
)
67 raise MKCounterWrapped("Login into database failed")
69 db_tables
= {x
[0]: x
[1:] for x
in db
[1:]}
70 tablespace
= db_tables
.get(tbsname
)
75 tablespace_dict
= dict(zip(headers
[1:], tablespace
))
77 tbsp_type
= tablespace_dict
["TBSP_TYPE"]
78 tbsp_state
= tablespace_dict
["TBSP_STATE"]
79 usable
= float(tablespace_dict
["TBSP_USABLE_SIZE_KB"]) * 1024
80 total
= float(tablespace_dict
["TBSP_TOTAL_SIZE_KB"]) * 1024
81 used
= float(tablespace_dict
["TBSP_USED_SIZE_KB"]) * 1024
82 free
= float(tablespace_dict
["TBSP_FREE_SIZE_KB"]) * 1024
84 if tbsp_type
== "SMS":
85 usable
= free
# for SMS free size is the amount of disk space available to the db file
87 perc_free
= 100.0 - used
/ usable
* 100.0
88 warn
, crit
, levels_text
, as_perc
= db_get_tablespace_levels_in_bytes(usable
, params
)
90 perfdata
= [("tablespace_size", usable
, max(0, total
- (warn
or 0)), max(
91 0, total
- (crit
or 0))), ("tablespace_used", used
), ("tablespace_max_size", total
)]
92 yield 0, "%.1f%% free" % perc_free
, perfdata
94 if crit
and free
<= crit
:
95 yield 2, "only %s left %s" % (as_perc
and ("%.1f%%" % perc_free
) or \
96 get_bytes_human_readable(used
), levels_text
)
97 elif warn
and free
<= warn
:
98 yield 1, "only %s left %s" % (as_perc
and ("%.1f%%" % perc_free
) or \
99 get_bytes_human_readable(used
), levels_text
)
100 yield 0, "%s of %s used" % (get_bytes_human_readable(used
), get_bytes_human_readable(usable
))
102 yield tbsp_state
.lower() != "normal" and 1 or 0, "State: %s" % tbsp_state
103 yield 0, "Type: %s" % tbsp_type
106 check_info
['db2_tablespaces'] = {
107 "parse_function": parse_db2_dbs
,
108 "service_description": "DB2 Tablespace %s",
109 "check_function": check_db2_tablespaces
,
110 "inventory_function": inventory_db2_tablespaces
,
111 "has_perfdata": True,
112 "group": "db2_tablespaces",
113 "default_levels_variable": "db2_tablespaces_default_levels",
114 "includes": ["db.include", "db2.include"]