Module: check_mk
Branch: master
Commit: 403d0cdf8bc30e7f680c668aad86cca831ab14c8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=403d0cdf8bc30e…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Jan 22 14:38:13 2014 +0100
hitachi_hnas_fan: internal code cleanup
---
checks/hitachi_hnas_fan | 89 +++++++++++++++++++++--------------------------
1 file changed, 40 insertions(+), 49 deletions(-)
diff --git a/checks/hitachi_hnas_fan b/checks/hitachi_hnas_fan
index ff766db..6d5e539 100644
--- a/checks/hitachi_hnas_fan
+++ b/checks/hitachi_hnas_fan
@@ -26,76 +26,67 @@
def inventory_hitachi_hnas_fan(info):
inventory = []
- for clusternode, id, fitted_status, speed_status, speed in info:
- inventory.append( (clusternode + "." + id, None) )
+ for clusternode, fan_id, fitted_status, speed_status, speed in info:
+ inventory.append( (clusternode + "." + fan_id, None) )
return inventory
+
def check_hitachi_hnas_fan(item, _no_params, info):
- rc = 0
- fan_fitted_status_map = ( ("", 3), # 0
- ("ok", 0), # 1
- ("okIdWrong", 1), # 2
- ("notFitted", 2), # 3
- ("unknown", 3), # 4
- )
+ fitted_status_map = (
+ ("ok", 0), # 1
+ ("okIdWrong(!)", 1), # 2
+ ("notFitted(!!)", 2), # 3
+ ("unknown(!)", 1) # 4
+ )
+
+ speed_status_map = (
+ ("ok", 0), # 1
+ ("warning(!)", 1), # 2
+ ("severe(!!)", 2), # 3
+ ("unknown(!)", 1), # 4
+ )
- fan_speed_status_map = ( ("", 3), # 0
- ("ok", 0), # 1
- ("warning", 1), # 2
- ("severe", 2), # 3
- ("unknown", 3), # 4
- )
- errorstring = ( "", " (!)", " (!!)", "")
+ for clusternode, fan_id, fitted_status, speed_status, speed in info:
+ if clusternode + "." + fan_id == item:
+ fitted_status = int(fitted_status)
+ speed_status = int(speed_status)
+ speed = int(speed)
+ infotext = "PNode %s fan %s" % (clusternode, fan_id)
- for clusternode, id, fitted_status, speed_status, speed in info:
- if clusternode + "." + id == item:
- fitted_status=int(fitted_status)
- speed_status=int(speed_status)
- speed=int(speed)
- message = "PNode %s Fan %s" % (clusternode, id)
+ worststate = 0
# check fitted status
- if fitted_status == 0 or fitted_status >= len(fan_fitted_status_map):
- message += " fitted status unidentified %s" % fitted_status
- rc = 3
- else:
- message += " fitted status is %s%s" % (
fan_fitted_status_map[fitted_status][0],
errorstring[fan_fitted_status_map[fitted_status][1]] )
- rc = fan_fitted_status_map[fitted_status][1]
+ name, state = fitted_status_map[fitted_status - 1]
+ infotext += ", fitted status is %s" % name
+ worststate = max(worststate, state)
# check speed status
- if speed_status == 0 or speed_status >= len(fan_speed_status_map):
- message += ", speed status unidentified %s" % speed_status
- if rc == 0:
- rc = 3
- # if rc is already warning or critical, keep it
- else:
- message += ", speed status is %s%s" % (
fan_speed_status_map[speed_status][0], errorstring[fan_speed_status_map[speed_status][1]]
)
- if fan_speed_status_map[speed_status][1] == 1:
- if rc == 2:
- rc = 2
- else:
- rc = 1
- elif fan_speed_status_map[speed_status][1] == 2:
- rc = 2
- elif fan_speed_status_map[speed_status][1] == 3:
- if rc == 0:
- rc = 3
+ name, state = speed_status_map[speed_status - 1]
+ infotext += ", speed status is %s" % name
+ worststate = max(worststate, state)
# report speed
- message += ", speed is %s rpm" % speed
+ infotext += ", speed is %s rpm" % speed
perfdata = [ ('fanspeed', str(speed) + 'rpm', '',
'', 0, '') ]
- return rc, message, perfdata
+ return worststate, infotext, perfdata
return 3, "No fan %s found" % item
+
+
check_info["hitachi_hnas_fan"] = {
"check_function" : check_hitachi_hnas_fan,
"inventory_function" : inventory_hitachi_hnas_fan,
"service_description" : "Fan %s",
"has_perfdata" : True,
- "snmp_info" : (".1.3.6.1.4.1.11096.6.1.1.1.2.1.11.1",
[1, 2, 3, 4, 5]),
- # fanClusterNode, fanIndex, fanFittedStatus,
fanSpeedStatus, fanSpeed
+ "snmp_info" : (".1.3.6.1.4.1.11096.6.1.1.1.2.1.11.1",
[
+ 1, # fanClusterNode
+ 2, # fanIndex
+ 3, # fanFittedStatus
+ 4, # fanSpeedStatus
+ 5, # fanSpeed
+ ]),
"snmp_scan_function" : lambda oid:
oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.11096.6"),
}