Cleanup config.nodes_of
[check_mk.git] / checks / dhcp_pools.include
blob95339c88db51a160b563ede6771a513e222526b3
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2015 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 # new params format
28 # params = {
29 # 'free_leases' : (warn, crit),
30 # 'used_leases' : (warn, crit),
31 # }
34 def check_dhcp_pools_levels(free, used, pending, size, params):
35 if isinstance(params, tuple):
36 # In case of win_dhcp_pools old params are percent but of type
37 # integer, thus we have to change them into floats
38 params = {"free_leases": (float(params[0]), float(params[1]))}
40 for what, value in [("free", free), ("used", used)]:
41 state = 0
42 value_abs = value
44 if size == 0:
45 value_perc = 0
46 else:
47 value_perc = float(value) / size * 100.0
49 infotext = "%s: %d leases (%.1f%%)" % (what, value, value_perc)
50 if params.get("%s_leases" % what, ""):
51 warn, crit = params["%s_leases" % what]
52 if isinstance(warn, float): # here we have levels in percent
53 value = value_perc
54 text_format = "%.1f"
55 unit = "%%"
56 warn_abs = int(size * (warn / 100.0))
57 crit_abs = int(size * (crit / 100.0))
58 else: # otherwise we use absolute values as integers
59 text_format = "%d"
60 unit = " %s pool entries" % what
61 warn_abs = warn
62 crit_abs = crit
64 if value < crit:
65 state = 2
66 elif value < warn:
67 state = 1
69 if state:
70 infotext_format = " (warn/crit below " + text_format + "/" + text_format + unit + ")"
71 infotext += infotext_format % (warn, crit)
73 else:
74 warn_abs = None
75 crit_abs = None
77 yield state, infotext, [("%s_dhcp_leases" % what, value_abs, warn_abs, crit_abs, 0, size)]
79 if pending is not None:
80 yield 0, "%d leases pending" % pending, [("pending_dhcp_leases", pending, None, None, 0,
81 size)]