Module: check_mk
Branch: master
Commit: 94e039be947b57e9fdf5ef5ce0c6910d6d3acc5d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=94e039be947b57…
Author: Bastian Kuhn <bk(a)mathias-kettner.de>
Date: Wed Nov 5 10:13:27 2014 +0100
Cleanup in cisco Checks
---
checks/cisco_fan | 11 +++++-----
checks/cisco_fantray | 4 +++-
checks/cisco_power | 8 +++----
checks/cisco_sensor_item.include | 45 ++++++++++++++++++++++++++++++++++++++
checks/cisco_temp_perf | 20 +++++++++--------
5 files changed, 68 insertions(+), 20 deletions(-)
diff --git a/checks/cisco_fan b/checks/cisco_fan
index 3f19223..6aec2a7 100644
--- a/checks/cisco_fan
+++ b/checks/cisco_fan
@@ -28,12 +28,12 @@ cisco_fan_states = ('', 'normal', 'warning',
'critical',
'shutdown', 'notPresent',
'notFunctioning')
def inventory_cisco_fan(info):
- return [ (line[0], None) for line in info if line[1] != '5' ]
+ return [ (cisco_sensor_item(line[0],line[-1]), None) for line in info if line[1] !=
'5' ]
def check_cisco_fan(item, params, info):
- for line in info:
- if line[0] == item:
- state = saveint(line[1])
+ for statustext, state, oid_end in info:
+ if cisco_sensor_item(statustext, oid_end) == item:
+ state = int(state)
if state == 1:
return (0, "State is: %s (%d)" % (cisco_fan_states[state],
state))
elif state == 2:
@@ -47,7 +47,8 @@ check_info["cisco_fan"] = {
'check_function': check_cisco_fan,
'inventory_function': inventory_cisco_fan,
'service_description': 'FAN %s',
- 'snmp_info': ('.1.3.6.1.4.1.9.9.13.1.4.1',
['2', '3']),
+ 'snmp_info': ('.1.3.6.1.4.1.9.9.13.1.4.1',
['2', '3', OID_END]),
'snmp_scan_function': \
lambda oid: "cisco" in oid(".1.3.6.1.2.1.1.1.0").lower(),
+ "includes" : ['cisco_sensor_item.include'],
}
diff --git a/checks/cisco_fantray b/checks/cisco_fantray
index e973cc5..8c3a7cd 100644
--- a/checks/cisco_fantray
+++ b/checks/cisco_fantray
@@ -54,5 +54,7 @@ check_info["cisco_fantray"] = {
'inventory_function' : inventory_cisco_fantray,
'service_description' : 'FAN %s',
'snmp_info' : ('.1.3.6.1.4.1.9.9.117.1.4.1.1.1', [ OID_END,
'' ]),
- 'snmp_scan_function' : lambda oid: "cisco" in
oid(".1.3.6.1.2.1.1.1.0").lower(),
+ 'snmp_scan_function' : lambda oid: "cisco" in
oid(".1.3.6.1.2.1.1.1.0").lower() \
+ # Exclude cisco_fan check:
+ and not oid(".1.3.6.1.4.1.9.9.13.1.4.1.2.*"),
}
diff --git a/checks/cisco_power b/checks/cisco_power
index de8280b..c48e4e6 100644
--- a/checks/cisco_power
+++ b/checks/cisco_power
@@ -39,16 +39,13 @@ def inventory_cisco_power(info):
for line in info:
# 5 in line[1] means cisco_power_states = notPresent
if 'RPS NotExist' not in line[1] and line[2] != '5':
- # There are many types of cisco devices supported by this check
- # but they all have difrent behaviors. So we have to use OID_END as
- # item to find a way to match them all.
- yield line[0], None
+ yield cisco_sensor_item(line[1], line[0]), None
def check_cisco_power(item, no_params, info):
for sid, textinfo, state, source in info:
state = int(state)
source = int(source)
- if sid == item:
+ if cisco_sensor_item(textinfo, sid) == item:
output = '%s, State: %s, Source: %s' % \
(textinfo, cisco_power_states[state], cisco_power_source[source])
if state == 1:
@@ -67,4 +64,5 @@ check_info["cisco_power"] = {
'snmp_info': ('.1.3.6.1.4.1.9.9.13.1.5.1', [OID_END, 2,
3, 4]),
'snmp_scan_function': \
lambda oid: "cisco" in oid(".1.3.6.1.2.1.1.1.0").lower(),
+ "includes" : ['cisco_sensor_item.include'],
}
diff --git a/checks/cisco_sensor_item.include b/checks/cisco_sensor_item.include
new file mode 100644
index 0000000..717feb8
--- /dev/null
+++ b/checks/cisco_sensor_item.include
@@ -0,0 +1,45 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2014 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at
http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# ails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+def cisco_sensor_item(trial_string, fall_back):
+ # trial_string can be:
+ # Empty
+ # A single string
+ # A string seperated by commas with status information
+ # -> Depends on the device model
+ try:
+ splited = trial_string.split(',')
+ if len(splited) == 1:
+ return trial_string
+ # Try to handle all cases found in mkzeug/walks
+ if '#' in splited[-1] or 'Power' in splited[-1]:
+ return " ".join([ x.strip() for x in
splited]).replace('#',' ')
+ if splited[-2].startswith(" Status"):
+ return " ".join([ x.strip() for x in
splited[:-2]]).replace('#',' ')
+ return " ".join([ x.strip() for x in
splited[:-1]]).replace('#',' ')
+ except:
+ return fall_back
+
diff --git a/checks/cisco_temp_perf b/checks/cisco_temp_perf
index fa619bb..de9cff2 100644
--- a/checks/cisco_temp_perf
+++ b/checks/cisco_temp_perf
@@ -58,21 +58,22 @@ cisco_temp_perf_envmon_states = {
def inventory_cisco_temp_perf(info):
inventory = []
for line in info:
- inventory.append((line[4], None))
- return inventory
+ yield cisco_sensor_item(line[0], line[4]), None
def check_cisco_temp_perf(item, _no_params, info):
- for line in info:
- if line[4] == item:
- temp = saveint(line[1])
+ for statustext, temp, max_temp, state, oid_end in info:
+ if cisco_sensor_item(statustext, oid_end) == item:
+ #FIXE saveint needed here? (See if condition)
+ temp = saveint(temp)
if temp != 0:
- perfdata = [("temp", temp, None, saveint(line[2]) )]
- temptext = ", %d degrees (%s) (critical at %d)" % (temp,
line[0], saveint(line[2]))
+ max_temp = int(max_temp)
+ perfdata = [("temp", temp, None, max_temp )]
+ temptext = ", %d degrees (critical at %d)" % (temp, max_temp)
else:
perfdata = []
temptext = ""
- state = int(line[3])
+ state = int(state)
statename = cisco_temp_perf_envmon_states.get(state, "(invalid)")
if state == 1:
return (0, "state is normal%s" % temptext, perfdata)
@@ -96,5 +97,6 @@ check_info['cisco_temp_perf'] = {
oid(".1.3.6.1.4.1.9.9.91.1.1.1.1.*") == None,
"snmp_info" : ( ".1.3.6.1.4.1.9.9.13.1.3.1",
[2, 3, 4, 6, OID_END ] ), # CISCO-SMI
- "group" : "temperature_auto"
+ "group" : "temperature_auto",
+ "includes" : ['cisco_sensor_item.include'],
}