Module: check_mk
Branch: master
Commit: 82eb780adc9f79036f8c5c84b447756c78e10398
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=82eb780adc9f79…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Jun 3 16:52:20 2015 +0200
raritan_pdu_ocprot: merge two checks into one
---
checks/raritan_pdu_ocprot | 126 +++++++++++++++++++--------------------------
1 file changed, 52 insertions(+), 74 deletions(-)
diff --git a/checks/raritan_pdu_ocprot b/checks/raritan_pdu_ocprot
index 1a18ad9..b97aa52 100644
--- a/checks/raritan_pdu_ocprot
+++ b/checks/raritan_pdu_ocprot
@@ -24,100 +24,78 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-
-def parse_raritan_pdu_ocprot(info):
- parsed = {}
- for line in info:
- if line[0].endswith("15"):
- ocprotid = "C" + line[0].split(".")[1]
- if parsed.get(ocprotid) == None:
- parsed[ocprotid] = {}
- parsed[ocprotid]["state"] = line[1]
- elif line[0].endswith("1"):
- ocprotid = "C" + line[0].split(".")[1]
- if parsed.get(ocprotid) == None:
- parsed[ocprotid] = {}
- parsed[ocprotid]["current"] = float(line[2]) / 10
- return parsed
-
-
-#.
-# .--Current-------------------------------------------------------------.
-# | ____ _ |
-# | / ___| _ _ __ _ __ ___ _ __ | |_ |
-# | | | | | | | '__| '__/ _ \ '_ \| __| |
-# | | |__| |_| | | | | | __/ | | | |_ |
-# | \____\__,_|_| |_| \___|_| |_|\__| |
-# | |
-# '----------------------------------------------------------------------'
-
raritan_pdu_ocprot_current_default_levels = (14.0, 15.0)
+# Example for info:
+# [['1.1.1', '4', '0'],
+# ['1.1.15', '1', '0'],
+# ['1.2.1', '4', '0'],
+# ['1.2.15', '1', '0'],
+# ['1.3.1', '4', '0'],
+# ['1.3.15', '1', '0'],
+# ['1.4.1', '4', '0'],
+# ['1.4.15', '1', '0'],
+# ['1.5.1', '4', '0'],
+# ['1.5.15', '1', '0'],
+# ['1.6.1', '4', '0'],
+# ['1.6.15', '1', '0']]
+# Raritan implements a strange way of indexing here. The two last components
+# of the OID should really be swapped!
-def inventory_raritan_pdu_ocprot_current(parsed):
- for ocprotid in parsed:
- yield ocprotid, "raritan_pdu_ocprot_current_default_levels"
-
-
-def check_raritan_pdu_ocprot_current(item, params, parsed):
- current = parsed[item]["current"]
- warn, crit = params
+def parse_raritan_pdu_ocprot(info):
+ parsed = {}
+ for end_oid, state, value in info:
+ protector_id = "C" + end_oid.split(".")[1] # 1.5.1 -->
Item will be "C5"
- infotext = "%.1f A" % current
- levelstext = " (warn/crit at %.1f/%.1f A)" % (warn, crit)
+ if end_oid.endswith(".15"):
+ parsed.setdefault(protector_id, {})["state"] = state
+ elif end_oid.endswith(".1"):
+ parsed.setdefault(protector_id, {})["current"] = float(value) / 10
- if current >= crit:
- status = 2
- infotext += levelstext
- elif current >= warn:
- status = 1
- infotext += levelstext
- else:
- status = 0
+ pprint.pprint(parsed)
+ return parsed
- perfdata = [ ("current", current, warn, crit) ]
- return status, infotext, perfdata
+def inventory_raritan_pdu_ocprot(parsed):
+ for protector_id in parsed:
+ yield protector_id, "raritan_pdu_ocprot_current_default_levels"
-check_info["raritan_pdu_ocprot.current"] = {
- "inventory_function" : inventory_raritan_pdu_ocprot_current,
- "check_function" : check_raritan_pdu_ocprot_current,
- "service_description" : "Overcurrent Protector Current
%s",
- "has_perfdata" : True,
- "group" : "ocprot_current",
-}
+def check_raritan_pdu_ocprot(item, params, parsed):
+ states = {
+ "-1" : (3, "Overcurrent protector information is
unavailable"),
+ "0" : (2, "Overcurrent protector is open"),
+ "1" : (0, "Overcurrent protector is closed"),
+ }
+ if item in parsed:
+ yield states[parsed[item]["state"]]
-#.
-# .--Status--------------------------------------------------------------.
-# | ____ _ _ |
-# | / ___|| |_ __ _| |_ _ _ ___ |
-# | \___ \| __/ _` | __| | | / __| |
-# | ___) | || (_| | |_| |_| \__ \ |
-# | |____/ \__\__,_|\__|\__,_|___/ |
-# | |
-# '----------------------------------------------------------------------'
+ current = parsed[item]["current"]
+ warn, crit = params
-def inventory_raritan_pdu_ocprot(parsed):
- for ocprotid in parsed:
- yield ocprotid, None
+ infotext = "Current: %.1f A" % current
+ levelstext = " (warn/crit at %.1f/%.1f A)" % (warn, crit)
+ if current >= crit:
+ status = 2
+ infotext += levelstext
+ elif current >= warn:
+ status = 1
+ infotext += levelstext
+ else:
+ status = 0
-def check_raritan_pdu_ocprot(item, _no_params, parsed):
- states = {
- "-1" : (3, "Overcurrent protector information is
unavailable"),
- "0" : (2, "Overcurrent protector is open"),
- "1" : (0, "Overcurrent protector is closed"),
- }
- return states[parsed[item]["state"]]
+ perfdata = [ ("current", current, warn, crit) ]
+ yield status, infotext, perfdata
check_info["raritan_pdu_ocprot"] = {
"parse_function" : parse_raritan_pdu_ocprot,
"inventory_function" : inventory_raritan_pdu_ocprot,
"check_function" : check_raritan_pdu_ocprot,
- "service_description" : "Overcurrent Protector Status %s",
+ "service_description" : "Overcurrent Protector %s",
+ "group" : "ocprot_current",
"snmp_info" : (".1.3.6.1.4.1.13742.6.5.3.3.1", [
OID_END,
"3",