Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / db.include
blob64f3faafc4eb104089a3a1fa08b896607254ec1b
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 # 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
34 def db_get_tablespace_levels_in_bytes(size_bytes, params):
35 # If the magic factor is used, take table size and magic factor
36 # into account in order to move levels
37 magic = params.get("magic")
39 # Use tablespace size dependent dynamic levels or static levels
40 if isinstance(params.get("levels"), tuple):
41 warn, crit = params.get("levels")
42 else:
43 # A list of levels. Choose the correct one depending on the
44 # size of the current tablespace
45 for to_size, this_levels in params.get("levels"):
46 if size_bytes > to_size:
47 warn, crit = this_levels
48 break
49 else:
50 return None, None, "", False
52 # warn/crit level are float => percentages of max size, otherwise MB
53 if isinstance(warn, float):
54 output_as_percentage = True
55 if magic:
56 normsize = params["magic_normsize"] * 1024 * 1024
57 hbytes_size = size_bytes / float(normsize)
58 felt_size = hbytes_size**magic
59 scale = felt_size / hbytes_size
60 warn *= scale
61 crit *= scale
62 max_warning_level, max_critical_level = params["magic_maxlevels"]
63 warn = min(warn, max_warning_level)
64 crit = min(crit, max_critical_level)
65 levels_text = " (warn/crit at %.1f%%/%.1f%%)" % (warn, crit)
66 warn_bytes = warn * size_bytes / 100
67 crit_bytes = crit * size_bytes / 100
69 # Absolute free space in MB
70 else:
71 output_as_percentage = False
72 warn_bytes = warn * 1024 * 1024
73 crit_bytes = crit * 1024 * 1024
74 levels_text = " (warn/crit at %s/%s)" % (get_bytes_human_readable(warn_bytes),
75 get_bytes_human_readable(crit_bytes))
77 return warn_bytes, crit_bytes, levels_text, output_as_percentage