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 # <<<mssql_tablespaces>>>
28 # MSSQL_SQLEXPRESS master 5.25 MB 1.59 MB 2464 KB 1096 KB 1024 KB 344 KB
29 # MSSQL_SQLEXPRESS model 3.00 MB 1.13 MB 1152 KB 472 KB 632 KB 48 KB
30 # MSSQL_SQLEXPRESS msdb 18.13 MB 4.05 MB 10960 KB 8336 KB 2080 KB 544 KB
31 # MSSQL_SQLEXPRESS tempdb 2.75 MB 1.08 MB 1200 KB 480 KB 672 KB 48 KB
32 # MSSQL_SQLEXPRESS test123 4.00 MB 1.78 MB 1248 KB 528 KB 648 KB 72 KB
36 # 2: db size (Size of the current database in megabytes.
37 # database_size includes both data and log files.)
39 # 4: unallocated space (Space in the database that has not been reserved for database objects.)
41 # 6: reserved space (Total amount of space allocated by objects in the database.)
43 # 8: Total amount of space used by data.
45 # 10: Total amount of space used by indexes.
47 # 12: Total amount of space reserved for objects in the database, but not yet used.
50 factory_settings
["mssql_tablespace_default_levels"] = {}
53 def parse_mssql_tablespaces(info
):
54 def to_bytes(value
, uom
):
55 exponent
= {'KB': 1, 'MB': 2, 'GB': 3, 'TB': 4}.get(uom
, 0)
57 return float(value
) * (1024**exponent
)
66 pairs
= zip(line
[:14:2], line
[1:14:2])
67 item
= "%s %s" % pairs
[0]
68 keys
= ('size', 'unallocated', 'reserved', 'data', 'indexes', 'unused')
69 values
= (to_bytes(*p
) for p
in pairs
[1:])
70 data
= dict(zip(keys
, values
))
72 if len(line
) > 14 and line
[14].startswith("ERROR: "):
73 data
["error"] = line
[14][7:]
75 parsed
.setdefault(item
, data
)
80 def check_mssql_tablespaces(item
, params
, parsed
):
81 tablespace
= parsed
.get(item
)
82 if tablespace
is None:
83 # Assume general connection problem to the database, which is reported
84 # by the "X Instance" service and skip this check.
85 raise MKCounterWrapped("Tablespace not found")
87 size
= tablespace
["size"]
88 if "error" in tablespace
:
89 yield 2, tablespace
["error"]
92 levels
= params
.get("size", (None, None))
94 size
, 'size', levels
, human_readable_func
=get_bytes_human_readable
, infoname
="Size")
96 for key
, title
, is_upper
in [
97 ('unallocated', 'Unallocated space', False),
98 ('reserved', 'Reserved space', True),
99 ('data', 'Data', True),
100 ('indexes', 'Indexes', True),
101 ('unused', 'Unused', True),
103 value_bytes
= tablespace
[key
]
104 if value_bytes
is None:
107 infotext
= '%s: %s' % (title
, get_bytes_human_readable(value_bytes
))
109 value_perc
= 100.0 * value_bytes
/ size
110 infotext
+= ", %s" % get_percent_human_readable(value_perc
)
111 except (TypeError, ZeroDivisionError):
114 warn
, crit
= params
.get(key
, (None, None))
115 if isinstance(crit
, float) and value_perc
is not None:
117 readable_f
= get_percent_human_readable
118 elif isinstance(warn
, int):
120 readable_f
= get_bytes_human_readable
126 if is_upper
and value
>= crit
or not is_upper
and value
<= crit
:
128 elif is_upper
and value
>= warn
or not is_upper
and value
<= warn
:
131 infotext
+= " (warn/crit %s %s/%s)" % (
132 ('below', 'at')[is_upper
], readable_f(warn
), readable_f(crit
))
133 yield state
, infotext
136 check_info
['mssql_tablespaces'] = {
137 'parse_function': parse_mssql_tablespaces
,
138 'inventory_function': discover(),
139 'check_function': check_mssql_tablespaces
,
140 'service_description': 'MSSQL %s Sizes',
141 'group': 'mssql_tablespaces',
142 'has_perfdata': True,
143 'default_levels_variable': 'mssql_tablespace_default_levels',