2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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
):
36 for (sid_instance
, node
), lines
in parse_sap_hana(info
).iteritems():
41 inst
= parsed
.setdefault((sid_instance
, node
), {})
49 inst
[key
] = SAP_HANA_MAYBE(_parse_maybe_bool(value
), value
)
56 inst
[key
] = int(line
[index
])
59 inst
["expiration_date"] = line
[6]
63 def _parse_maybe_bool(value
):
64 if value
.lower() == "true":
66 elif value
.lower() == "false":
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
:
82 yield 0, 'On node: %s' % node
84 enforced
= data
['enforced']
86 yield _check_product_usage(data
['size'], data
['limit'], params
)
87 elif enforced
.bool is None:
88 yield 3, "Status: unknown[%s]" % enforced
.value
90 yield 0, "Status: unlimited"
92 permanent
= data
["permanent"]
94 yield 0, 'License: %s' % permanent
.value
96 yield 1, 'License: not %s' % permanent
.value
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
):
111 params
.get('license_size', (None, None)),
112 human_readable_func
=get_bytes_human_readable
,
116 usage_perc
= 100.0 * size
/ limit
117 except ZeroDivisionError:
118 yield 1, 'Usage: cannot calculate'
123 params
['license_usage'],
124 human_readable_func
=get_percent_human_readable
,
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,
136 'default_levels_variable': 'sap_hana_license_default_levels',
137 'group': 'sap_hana_license',