Module: check_mk
Branch: master
Commit: ec49b739b8d36a9dce4ae4e503d2f7ac97d17bf9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ec49b739b8d36a…
Author: Marcel Arentz <ma(a)mathias-kettner.de>
Date: Wed Feb 22 12:04:01 2017 +0100
refactoring blade_blades
Change-Id: I874e47be03d5588d9a6e80731be83f768ac7988a
---
checks/blade_blades | 91 +++++++++++++++++++++++++----------------------------
1 file changed, 43 insertions(+), 48 deletions(-)
diff --git a/checks/blade_blades b/checks/blade_blades
index 0624ca1..7eb4965 100644
--- a/checks/blade_blades
+++ b/checks/blade_blades
@@ -24,60 +24,55 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-# Author: Lars Michelsen <lm(a)mathias-kettner.de>
-# Mappings for translating SNMP states to nagios states
-blade_blades_exists_states = (2, 0)
-blade_blades_power_states = (1, 0)
-blade_blades_health_states = (3, 0, 1, 2)
+def parse_blade_blades(info):
+ map_states = {
+ 'exist_state' : ((2, "no"), (0, "yes")),
+ 'power_state' : ((1, "off"), (0, "on")),
+ 'health_state' : ((3, "unknown"), (0, "good"), (1,
"warning"), (2, "bad")),
+ }
-# Name mappings
-blade_blades_exists_labels = ('no', 'yes')
-blade_blades_power_labels = ('off', 'on')
-blade_blades_health_labels = ('unknown', 'good', 'warning',
'bad')
-
-def inventory_blade_blades(info):
- # find only blades that are powered on
- return [ (line[0], '', line[1]) for line in info if line[2] == '1' ]
-
-def check_blade_blades(item, params, info):
+ parsed = {}
for line in info:
- if line[0] == item:
- exists, power_state, health_state = map(saveint, line[1:4])
- name = line[4]
+ parsed[line[0]] = [
+ map_states['exist_state'][int(line[1])],
+ map_states['power_state'][int(line[2])],
+ map_states['health_state'][int(line[3])],
+ line[4]
+ ]
+
+ return parsed
- state = 0
- output = '%s: ' % (name)
+def inventory_blade_blades(parsed):
+ for key, value in parsed.iteritems():
+ if not parsed[key][1][1] == "off": # Only inventory powered on blades
+ yield (key, None)
- for label, part_state, nag_state, state_label in (
- ('Exists', exists, blade_blades_exists_states[exists],
blade_blades_exists_labels[exists]),
- ('Power', power_state,
blade_blades_power_states[power_state], blade_blades_power_labels[power_state]),
- ('Health', health_state,
blade_blades_health_states[health_state], blade_blades_health_labels[health_state])):
- output += '%s: %s' % (label, state_label)
- if nag_state == 1:
- output += ' (!)'
- elif nag_state == 2:
- output += ' (!!)'
- elif nag_state == 3:
- output += ' (UNKNOWN)'
- state = max(state, nag_state)
- output += ', '
+def check_blade_blades(item, _no_params, parsed):
+ for key, values in parsed.iteritems():
+ if item == key:
+ # name
+ yield 0, values[3]
+ # exist_state
+ yield values[0][0], "Exists: %s" % values[0][1]
+ # power_state
+ yield values[1][0], "Power: %s" % values[1][1]
+ # health_state
+ yield values[2][0], "Health: %s" % values[2][1]
- return (state, output.rstrip(', '))
- return (3, "no data for '%s' in SNMP info" % item)
check_info["blade_blades"] = {
- 'check_function': check_blade_blades,
- 'inventory_function': inventory_blade_blades,
- 'service_description': 'Blade %s',
- 'snmp_info': (
- ".1.3.6.1.4.1.2.3.51.2.22.1.5.1.1", [ # BLADE-MIB
- 2, # bladeId
- 3, # bladeExists
- 4, # bladePowerState
- 5, # bladeHealthState
- 6, # bladeName
- ]),
- 'snmp_scan_function': \
- lambda oid: re.match('(BladeCenter|BladeCenter Advanced|IBM Flex Chassis)
Management Module', oid(".1.3.6.1.2.1.1.1.0")) != None,
+ 'parse_function' : parse_blade_blades,
+ 'inventory_function' : inventory_blade_blades,
+ 'check_function' : check_blade_blades,
+ 'service_description' : "Blade %s",
+ 'snmp_info' : (".1.3.6.1.4.1.2.3.51.2.22.1.5.1.1", [ #
BLADE-MIB
+ 2, # bladeId
+ 3, # bladeExists
+ 4, # bladePowerState
+ 5, # bladeHealthState
+ 6, # bladeName
+ ]),
+ 'snmp_scan_function' : lambda oid: re.match('(BladeCenter|BladeCenter
Advanced|IBM Flex Chassis) Management Module', \
+ oid(".1.3.6.1.2.1.1.1.0")) != None,
}