Cleanup config.nodes_of
[check_mk.git] / checks / sap_hana_license
blob138722281710a60f517d628e906df5cb90b491f5
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2019 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 factory_settings['sap_hana_license_default_levels'] = {
28 'license_usage': (80.0, 90.0),
31 SAP_HANA_MAYBE = collections.namedtuple("SAP_HANA_MAYBE", ["bool", "value"])
34 def parse_sap_hana_license(info):
35 parsed = {}
36 for (sid_instance, node), lines in parse_sap_hana(info).iteritems():
37 for line in lines:
38 if len(line) < 7:
39 continue
41 inst = parsed.setdefault((sid_instance, node), {})
42 for index, key, in [
43 (0, "enforced"),
44 (1, "permanent"),
45 (2, "locked"),
46 (5, "valid"),
48 value = line[index]
49 inst[key] = SAP_HANA_MAYBE(_parse_maybe_bool(value), value)
51 for index, key, in [
52 (3, "size"),
53 (4, "limit"),
55 try:
56 inst[key] = int(line[index])
57 except ValueError:
58 pass
59 inst["expiration_date"] = line[6]
60 return parsed
63 def _parse_maybe_bool(value):
64 if value.lower() == "true":
65 return True
66 elif value.lower() == "false":
67 return False
68 return
71 def inventory_sap_hana_license(parsed):
72 for (sid_instance, _node) in parsed.iterkeys():
73 yield sid_instance, {}
76 def check_sap_hana_license(item, params, parsed):
77 for (sid_instance, node), data in parsed.iteritems():
78 if item != sid_instance:
79 continue
81 if node:
82 yield 0, 'On node: %s' % node
84 enforced = data['enforced']
85 if enforced.bool:
86 yield _check_product_usage(data['size'], data['limit'], params)
87 elif enforced.bool is None:
88 yield 3, "Status: unknown[%s]" % enforced.value
89 else:
90 yield 0, "Status: unlimited"
92 permanent = data["permanent"]
93 if permanent.bool:
94 yield 0, 'License: %s' % permanent.value
95 else:
96 yield 1, 'License: not %s' % permanent.value
98 valid = data["valid"]
99 if not valid.bool:
100 yield 1, 'not %s' % valid.value
102 expiration_date = data["expiration_date"]
103 if expiration_date != "?":
104 yield 1, 'Expiration date: %s' % expiration_date
107 def _check_product_usage(size, limit, params):
108 yield check_levels(
109 size,
110 "license_size",
111 params.get('license_size', (None, None)),
112 human_readable_func=get_bytes_human_readable,
113 infoname="Size")
115 try:
116 usage_perc = 100.0 * size / limit
117 except ZeroDivisionError:
118 yield 1, 'Usage: cannot calculate'
119 else:
120 yield check_levels(
121 usage_perc,
122 "license_usage",
123 params['license_usage'],
124 human_readable_func=get_percent_human_readable,
125 infoname="Usage")
128 check_info['sap_hana_license'] = {
129 'parse_function': parse_sap_hana_license,
130 'inventory_function': inventory_sap_hana_license,
131 'check_function': check_sap_hana_license,
132 'service_description': 'SAP HANA License %s',
133 'includes': ['sap_hana.include'],
134 "has_perfdata": True,
135 "node_info": True,
136 'default_levels_variable': 'sap_hana_license_default_levels',
137 'group': 'sap_hana_license',