[checkmk-commits] esx_vsphere_datastores: use check API

Moritz Kiemer mo at mathias-kettner.de
Wed Apr 10 10:40:24 CEST 2019


Module: check_mk
Branch: master
Commit: ae95b7539b96f0d5ec4ed988c8e73e586632090b
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ae95b7539b96f0d5ec4ed988c8e73e586632090b

Author: Moritz Kiemer <mo at mathias-kettner.de>
Date:   Tue Apr  9 15:23:50 2019 +0200

esx_vsphere_datastores: use check API

Change-Id: I176089f9805ecad39b0cd1559e2e78a80480f723

---

 checks/esx_vsphere_datastores | 28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)

diff --git a/checks/esx_vsphere_datastores b/checks/esx_vsphere_datastores
index 459472b..887d556 100644
--- a/checks/esx_vsphere_datastores
+++ b/checks/esx_vsphere_datastores
@@ -34,7 +34,7 @@
 # url /vmfs/volumes/513df1e9-12fd7366-ac5a-e41f13e69eaa
 
 
-def esx_vsphere_datastores_parse(info):
+def parse_esx_vsphere_datastores(info):
     stores = {}
     for line in info:
         if line[0].startswith('['):
@@ -57,28 +57,19 @@ def esx_vsphere_datastores_parse(info):
     return stores
 
 
-def inventory_esx_vsphere_datastores(info):
-    stores = esx_vsphere_datastores_parse(info)
-    return [(name, {}) for name in stores]
-
-
-def check_esx_vsphere_datastores(item, params, info):
-    stores = esx_vsphere_datastores_parse(info)
-    if item not in stores:
-        return 3, "Datastore not existing"
-    store = stores[item]
-
+ at get_parsed_item_data
+def check_esx_vsphere_datastores(item, params, data):
     mib = 1024.0**2
-    size_bytes = store["capacity"]
-    avail_bytes = store["freeSpace"]
+    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 store:
-        uncommitted_bytes = store["uncommitted"]
+    if 'uncommitted' in data:
+        uncommitted_bytes = data["uncommitted"]
         used_bytes = size_bytes - avail_bytes
         prov_bytes = used_bytes + uncommitted_bytes
         if size_bytes == 0:
@@ -109,7 +100,7 @@ def check_esx_vsphere_datastores(item, params, info):
             else:
                 perfdata.append(('overprovisioned', prov_bytes / mib))
 
-    if not store["accessible"]:
+    if not data["accessible"]:
         state = 2
         infotext = "inaccessible(!!), " + infotext
 
@@ -117,7 +108,8 @@ def check_esx_vsphere_datastores(item, params, info):
 
 
 check_info['esx_vsphere_datastores'] = {
-    "inventory_function": inventory_esx_vsphere_datastores,
+    "parse_function": parse_esx_vsphere_datastores,
+    "inventory_function": discover(),
     "check_function": check_esx_vsphere_datastores,
     "service_description": "Filesystem %s",
     "includes": ['size_trend.include', 'df.include'],



More information about the checkmk-commits mailing list