2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
10 # | Copyright Mathias Kettner 2018 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.
28 def parse_k8s_surge(value
, total
):
30 Returns the upper level for replicas which is considered critical
31 (hence the +1 in the return value). Values may be given as an
32 absolute number or in percent.
34 if isinstance(value
, int):
35 return value
+ total
+ 1
36 percentage
= 1.0 + float(value
.rstrip('%')) / 100.0
37 return math
.ceil(percentage
* total
) + 1
40 def parse_k8s_unavailability(value
, total
):
42 Returns the lower level for replicas which is still considered ok.
43 Values may be given as an absolute number or in percent.
45 if isinstance(value
, int):
47 percentage
= 1.0 - float(value
.rstrip('%')) / 100.0
48 return math
.floor(percentage
* total
)
51 def inventory_k8s_replicas(parsed
):
52 if parsed
['ready_replicas'] is not None and parsed
['replicas'] is not None:
56 def check_k8s_replicas(_no_item
, params
, parsed
):
57 ready
, total
= parsed
['ready_replicas'], parsed
['replicas']
58 paused
, strategy
= parsed
['paused'], parsed
['strategy_type']
60 if paused
or strategy
== 'Recreate':
61 crit
, crit_lower
= None, None
62 elif strategy
== 'RollingUpdate':
63 crit
= parse_k8s_surge(parsed
['max_surge'], total
)
64 crit_lower
= parse_k8s_unavailability(parsed
['max_unavailable'], total
)
66 yield 3, "Unknown deployment strategy: %s" % strategy
70 infotext
= "Ready: %s/%s" % (ready
, total
)
72 infotext
+= ' (paused)'
73 if crit
is not None and ready
>= crit
:
75 infotext
+= " (crit at %d)" % crit
76 if crit_lower
is not None and ready
< crit_lower
:
78 infotext
+= " (crit below %d)" % crit_lower
81 ('ready_replicas', ready
, None, crit
),
82 ('total_replicas', total
),
84 yield state
, infotext
, perfdata
87 strategy_infotext
= "Strategy: %s" % parsed
['strategy_type']
88 if strategy
== 'RollingUpdate':
89 strategy_infotext
+= " (max unavailable: %s, max surge: %s)" % (
90 parsed
['max_unavailable'],
93 yield 0, strategy_infotext
96 check_info
['k8s_replicas'] = {
97 'parse_function': parse_k8s
,
98 'inventory_function': inventory_k8s_replicas
,
99 'check_function': check_k8s_replicas
,
100 'service_description': 'Replicas',
101 'has_perfdata': True,
102 'includes': ['k8s.include'],