Module: check_mk
Branch: master
Commit: db10a491b838b38fe4fb0cf10efa5de69a23a5c7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=db10a491b838b3…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Tue Apr 9 16:08:06 2019 +0200
esx_vsphere_datastores: refactor to yield & check_levels
Change-Id: I477dadd24ffb8621029fa4aae9022a1cbb7e83ce
---
checks/esx_vsphere_datastores | 77 ++++++++++------------
.../datasets/esx_vsphere_datastores_regression.py | 47 ++++++-------
2 files changed, 54 insertions(+), 70 deletions(-)
diff --git a/checks/esx_vsphere_datastores b/checks/esx_vsphere_datastores
index 887d556..9a7f7c8 100644
--- a/checks/esx_vsphere_datastores
+++ b/checks/esx_vsphere_datastores
@@ -59,52 +59,41 @@ def parse_esx_vsphere_datastores(info):
@get_parsed_item_data
def check_esx_vsphere_datastores(item, params, data):
- mib = 1024.0**2
- size_bytes = data["capacity"]
- avail_bytes = data["freeSpace"]
- #size_mb = store["capacity"] / mib
- #avail_mb = store["freeSpace"] / mib
-
- state, infotext, perfdata = df_check_filesystem_single(item, size_bytes / mib,
- avail_bytes / mib, 0, None,
None, params)
-
- if 'uncommitted' in data:
- uncommitted_bytes = data["uncommitted"]
- used_bytes = size_bytes - avail_bytes
- prov_bytes = used_bytes + uncommitted_bytes
- if size_bytes == 0:
- prov_percent = 0
- else:
- prov_percent = (prov_bytes * 100.) / size_bytes
-
- prov_txt = ''
- warn, crit = None, None
- if 'provisioning_levels' in params:
- warn, crit = params['provisioning_levels']
- levels_text = " (warn/crit at %.1f%%/%.1f%%)" % (warn, crit)
- if prov_percent >= crit:
- state = max(state, 2)
- prov_txt = levels_text + '(!!)'
- elif prov_percent >= warn:
- state = max(state, 1)
- prov_txt = levels_text + '(!)'
-
- infotext += ", uncommitted: %s, provisioning: %s%s" %
(get_bytes_human_readable(
- uncommitted_bytes), get_percent_human_readable(prov_percent), prov_txt)
-
- if perfdata:
- perfdata.append(('uncommitted', uncommitted_bytes / mib))
- if warn:
- scale = size_bytes / mib / 100.
- perfdata.append(('overprovisioned', prov_bytes / mib, scale *
warn, scale * crit))
- else:
- perfdata.append(('overprovisioned', prov_bytes / mib))
-
if not data["accessible"]:
- state = 2
- infotext = "inaccessible(!!), " + infotext
+ yield 2, "inaccessible"
- return state, infotext, perfdata
+ mib = 1024.0**2
+ size_bytes = data.get("capacity")
+ avail_bytes = data.get("freeSpace")
+ if size_bytes is None or avail_bytes is None:
+ return
+
+ yield df_check_filesystem_single( # pylint: disable=undefined-variable
+ item, size_bytes / mib, avail_bytes / mib, 0, None, None, params)
+
+ uncommitted_bytes = data.get("uncommitted")
+ if uncommitted_bytes is None:
+ return
+ text_uncommitted = "Uncommitted: %s" %
get_bytes_human_readable(uncommitted_bytes)
+ yield 0, text_uncommitted, [('uncommitted', uncommitted_bytes / mib)]
+
+ used_bytes = size_bytes - avail_bytes
+ prov_bytes = used_bytes + uncommitted_bytes
+ prov_percent = (prov_bytes * 100.) / size_bytes if size_bytes != 0 else 0
+
+ warn, crit = params.get('provisioning_levels', (None, None))
+ yield check_levels(
+ prov_percent,
+ None, (warn, crit),
+ human_readable_func=get_percent_human_readable,
+ infoname="Provisioning")
+
+ if warn is not None:
+ # convert percent to abs MiB
+ scale = size_bytes / mib / 100.
+ yield 0, "", [('overprovisioned', prov_bytes / mib, scale *
warn, scale * crit)]
+ else:
+ yield 0, "", [('overprovisioned', prov_bytes / mib)]
check_info['esx_vsphere_datastores'] = {
diff --git a/tests/unit/checks/generictests/datasets/esx_vsphere_datastores_regression.py
b/tests/unit/checks/generictests/datasets/esx_vsphere_datastores_regression.py
index 273ba3a..37c9743 100644
--- a/tests/unit/checks/generictests/datasets/esx_vsphere_datastores_regression.py
+++ b/tests/unit/checks/generictests/datasets/esx_vsphere_datastores_regression.py
@@ -35,19 +35,16 @@ checks = {'': [(u'WIN-0100-MCC15-M-L000-SSD',
'show_reserved': False,
'trend_perfdata': True,
'trend_range': 24},
- [(0,
- '24.7% used (1012.89 GB of 4.00 TB), trend: 0.00 B / 24 hours,
uncommitted: 0.00 B, provisioning: 24.7%',
- [(u'WIN-0100-MCC15-M-L000-SSD',
- 1037195.0,
- 3355238.4,
- 3774643.2,
- 0,
- 4194048.0),
- ('fs_size', 4194048.0, None, None, None, None),
- ('growth', 0.0, None, None, None, None),
- ('trend', 0, None, None, 0, 174752.0),
- ('uncommitted', 0.0, None, None, None, None),
- ('overprovisioned', 1037195.0, None, None, None, None)])]),
+ [(0, '24.7% used (1012.89 GB of 4.00 TB), trend: 0.00 B / 24
hours', [
+ ('WIN-0100-MCC15-M-L000-SSD', 1037195.0, 3355238.4,
3774643.2, 0, 4194048.0),
+ ('fs_size', 4194048.0, None, None, None, None),
+ ('growth', 0.0, None, None, None, None),
+ ('trend', 0, None, None, 0, 174752.0),
+ ]),
+ (0, 'Uncommitted: 0.00 B', [('uncommitted', 0.0, None,
None, None, None)]),
+ (0, 'Provisioning: 24.7%', []),
+ (0, "", [('overprovisioned', 1037195.0, None, None,
None, None)]),
+ ]),
(u'WIN-0108-MCC35-U-L008-SSD-EXC2',
{'inodes_levels': (10.0, 5.0),
'levels': (80.0, 90.0),
@@ -58,16 +55,14 @@ checks = {'': [(u'WIN-0100-MCC15-M-L000-SSD',
'show_reserved': False,
'trend_perfdata': True,
'trend_range': 24},
- [(0,
- '78.2% used (9.38 of 12.00 TB), trend: 0.00 B / 24 hours,
uncommitted: 0.00 B, provisioning: 78.2%',
- [(u'WIN-0108-MCC35-U-L008-SSD-EXC2',
- 9836700.0,
- 10066124.8,
- 11324390.4,
- 0,
- 12582656.0),
- ('fs_size', 12582656.0, None, None, None, None),
- ('growth', 0.0, None, None, None, None),
- ('trend', 0, None, None, 0, 524277.3333333333),
- ('uncommitted', 0.0, None, None, None, None),
- ('overprovisioned', 9836700.0, None, None, None, None)])])]}
+ [(0, '78.2% used (9.38 of 12.00 TB), trend: 0.00 B / 24 hours',
[
+ (u'WIN-0108-MCC35-U-L008-SSD-EXC2', 9836700.0, 10066124.8,
11324390.4, 0, 12582656.0),
+ ('fs_size', 12582656.0, None, None, None, None),
+ ('growth', 0.0, None, None, None, None),
+ ('trend', 0, None, None, 0, 524277.3333333333),
+ ]),
+ (0, 'Uncommitted: 0.00 B', [('uncommitted', 0.0, None,
None, None, None)]),
+ (0, 'Provisioning: 78.2%', []),
+ (0, "", [('overprovisioned', 9836700.0, None, None,
None, None)]),
+ ])],
+}