Module: check_mk
Branch: master
Commit: 65699e0b82e21da0f1852dfc73a663f6d17059d5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=65699e0b82e21d…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Fri May 3 09:14:18 2019 +0200
cisco_cpu_multiitem: cleanup
Change-Id: I6306a3f941b31381e7b0c237b231bd3aa1a9f4ac
---
checks/cisco_cpu_multiitem | 64 +++++++++-------------
.../datasets/cisco_cpu_multiitem_regression.py | 2 +-
2 files changed, 26 insertions(+), 40 deletions(-)
diff --git a/checks/cisco_cpu_multiitem b/checks/cisco_cpu_multiitem
index d5c344c..dd38a85 100644
--- a/checks/cisco_cpu_multiitem
+++ b/checks/cisco_cpu_multiitem
@@ -31,64 +31,50 @@ factory_settings['cisco_cpu_multiitem_default_levels'] = {
def parse_cisco_cpu_multiitem(info):
ph_idx_to_desc = {}
- parsed = {}
for idx, desc in info[1]:
if desc.lower().startswith("cpu "):
desc = desc[4:]
ph_idx_to_desc[idx] = desc
+ parsed = {}
for idx, util in info[0]:
- if idx in ph_idx_to_desc:
- name = ph_idx_to_desc[idx]
- else:
- name = idx
- parsed[name] = {
- 'util': float(util),
- }
+ name = ph_idx_to_desc.get(idx, idx)
+ try:
+ parsed[name] = {'util': float(util)}
+ except ValueError:
+ pass
return parsed
-def inventory_cisco_cpu_multiitem(parsed):
- for name in parsed:
- yield name, {}
-
-
-def check_cisco_cpu_multiitem(item, params, parsed):
+@get_parsed_item_data
+def check_cisco_cpu_multiitem(_no_item, params, data):
warn, crit = params['levels']
- if item in parsed:
- util = parsed[item]['util']
-
- state = 0
- if util >= crit:
- state = 2
- elif util >= warn:
- state = 1
-
- infotext = "%s%% utilization in the last 5 minutes" % util
- if state > 0:
- infotext += " (warn/crit at %s%%/%s%%)" % (warn, crit)
-
- yield state, infotext, [("util", util, warn, crit, 0, 100)]
+ value = data['util']
+ state, infotext = check_levels(
+ value,
+ None, (warn, crit),
+ human_readable_func=get_percent_human_readable,
+ infoname="Utilization in the last 5 minutes")[:2]
+ yield state, infotext, [("util", value, warn, crit, 0, 100)]
- else:
- yield 3, "No information about the CPU utilization available"
check_info["cisco_cpu_multiitem"] = {
'parse_function' : parse_cisco_cpu_multiitem,
'check_function' : check_cisco_cpu_multiitem,
- 'inventory_function' : inventory_cisco_cpu_multiitem,
+ 'inventory_function' : discover(),
"group" : "cpu_utilization_multiitem",
"default_levels_variable" :
"cisco_cpu_multiitem_default_levels",
'service_description' : 'CPU utilization %s',
'has_perfdata' : True,
- 'snmp_info' : [('.1.3.6.1.4.1.9.9.109.1.1.1', [
- '1.2', # cpmCPUTotalPhysicalIndex
- '1.8', # cpmCPUTotal5minRev
- ]),
- ('.1.3.6.1.2.1.47.1.1.1', [
- OID_END, #OID index
- '1.7', # entPhysicalName
- ])],
+ 'snmp_info' : [
+ ('.1.3.6.1.4.1.9.9.109.1.1.1', [
+ '1.2', # cpmCPUTotalPhysicalIndex
+ '1.8', # cpmCPUTotal5minRev
+ ]),
+ ('.1.3.6.1.2.1.47.1.1.1', [
+ OID_END, #OID index
+ '1.7', # entPhysicalName
+ ])],
'snmp_scan_function' : lambda oid: 'cisco' in
oid('.1.3.6.1.2.1.1.1.0').lower() and \
oid('.1.3.6.1.4.1.9.9.109.1.1.1.*') is
None,
}
diff --git a/tests/unit/checks/generictests/datasets/cisco_cpu_multiitem_regression.py
b/tests/unit/checks/generictests/datasets/cisco_cpu_multiitem_regression.py
index eb7f457..d4995fe 100644
--- a/tests/unit/checks/generictests/datasets/cisco_cpu_multiitem_regression.py
+++ b/tests/unit/checks/generictests/datasets/cisco_cpu_multiitem_regression.py
@@ -14,5 +14,5 @@ discovery = {'': [(u'0', {})]}
checks = {'': [(u'0',
{'levels': (80.0, 90.0)},
[(0,
- '24.0% utilization in the last 5 minutes',
+ 'Utilization in the last 5 minutes: 24.0%',
[('util', 24.0, 80.0, 90.0, 0, 100)])])]}