Module: check_mk
Branch: master
Commit: d609c77ab0b0c303d7e93f436c934b2960e3ff12
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d609c77ab0b0c3…
Author: Kenneth Okoh <ko(a)mathias-kettner.de>
Date: Fri Oct 12 10:11:13 2018 +0200
hp_proliant_psu: Refactored handling of PSU Total from check to parse function
Change-Id: I71e059776bda85b1fbd3abb6104dd7f65648026c
---
checks/hp_proliant_psu | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/checks/hp_proliant_psu b/checks/hp_proliant_psu
index f6040c5..f6c34c0 100644
--- a/checks/hp_proliant_psu
+++ b/checks/hp_proliant_psu
@@ -53,6 +53,10 @@ def parse_hp_proliant_psu(info):
int(used), int(capacity_maximum))
except ValueError:
pass
+ if parsed:
+ PsuTotal = collections.namedtuple("Psu", ['used',
'max'])
+ parsed['Total'] = PsuTotal(sum(v.used for v in parsed.values()),
+ sum(v.max for v in parsed.values()))
return parsed
@@ -60,23 +64,17 @@ def inventory_hp_proliant_psu(parsed):
"""Inventorizes all present PSUs, as well as the Sum over all
PSUs"""
for item in parsed:
yield item, None
- yield 'Total', None
def check_hp_proliant_psu(item, params, parsed):
-
psu = parsed.get(item)
- if psu is not None:
+ if psu is None:
+ yield 3, "item not found in snmp data"
+ return
+ elif item != 'Total':
yield 0, "Chassis %s/Bay %s" % (psu.chassis, psu.bay)
snmp_state, status = condition_map[psu.condition]
yield status, 'State: "%s"' % snmp_state
- elif item != 'Total':
- yield 3, "item not found in snmp data"
- return
- else: # compute Total
- PsuTotal = collections.namedtuple("Psu", ['used',
'max'])
- psu = PsuTotal(sum(v.used for v in parsed.values()),
- sum(v.max for v in parsed.values()))
# usage info
info = 'Usage: %d Watts' % psu.used