Module: check_mk
Branch: master
Commit: 1befcf519fd8bce536fe87e867f95c34866a0d94
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1befcf519fd8bc…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Dec 19 17:34:49 2013 +0100
Cleaned up source code of a few checks
---
checks/cisco_fantray | 48 +++++++++++++++++++++++++-----------------------
checks/uptime | 22 ++++++++++++++--------
checks/uptime.include | 37 ++++++++++++++++++++-----------------
checks/viprinet_serial | 17 ++++++++++++-----
4 files changed, 71 insertions(+), 53 deletions(-)
diff --git a/checks/cisco_fantray b/checks/cisco_fantray
index 6c3fc18..752ea1c 100644
--- a/checks/cisco_fantray
+++ b/checks/cisco_fantray
@@ -24,33 +24,35 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-cisco_fan_states = ('', 'unknown', 'up', 'down',
'warning')
+
+cisco_fantray_state_names = {
+ '1': 3, "status is reported as 'unknown'",
+ '2': 0, "powered on",
+ '3': 2, "powered down",
+ '4': 2, "partial failure, needs replacement as soon as possible."
+}
def inventory_cisco_fantray(info):
- if info and info[0]:
- #Some Cisco switches reporting not available fans as down,
- #so we cant invenorize fans reported as down
- return [ (line[0], None) for line in info if line[1] != '3' ]
+ inventory = []
+ for fan_id, state in info:
+ if state != '3': # skip fans reported as down (might be missing)
+ inventory.append((fan_id, None))
+ return inventory
+
+def check_cisco_fantray(item, _no_params, info):
+ for fan_id, state in info:
+ if fan_id == item:
+ result, state_name = \
+ cisco_fantray_state_names.get(state, (3, "unexpected(%s)" %
state))
+ return result, state_name
-def check_cisco_fantray(item, params, info):
- for line in info:
- if line[0] == item:
- state = saveint(line[1])
- status = [ "", "unknown", "up",
"down", "warning" ]
- if state == 2:
- return (0, "State is %s (%d)" % (status[state], state))
- elif state in ( 0, 1, 4 ):
- return (1, "State is %s (%d)" % (status[state], state))
- else:
- return (2, "State is %s (%d)" % (status[state], state))
- return (3, "item not found in snmp data")
+ return (3, "No information about fan with this ID")
check_info["cisco_fantray"] = {
- 'check_function': check_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(),
+ 'check_function' : check_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(),
}
diff --git a/checks/uptime b/checks/uptime
index f95ab5c..3f35469 100644
--- a/checks/uptime
+++ b/checks/uptime
@@ -24,19 +24,25 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
+
+# Example output from agent:
+# <<<uptime>>>
+# 15876.96 187476.72
+
def inventory_uptime(info):
- if len(info) >= 1 and len(info[0]) >= 1:
+ if info:
return [ (None, {}) ]
def check_uptime(_no_item, params, info):
- return check_uptime_seconds(params, float(info[0][0]))
+ uptime_sec = float(info[0][0])
+ return check_uptime_seconds(params, uptime_sec)
check_info["uptime"] = {
- 'check_function': check_uptime,
- 'inventory_function': inventory_uptime,
- 'service_description': 'Uptime',
- 'has_perfdata': True,
- 'includes': [ 'uptime.include' ],
- 'group': 'uptime',
+ 'check_function' : check_uptime,
+ 'inventory_function' : inventory_uptime,
+ 'service_description' : 'Uptime',
+ 'has_perfdata' : True,
+ 'includes' : [ 'uptime.include' ],
+ 'group' : 'uptime',
}
diff --git a/checks/uptime.include b/checks/uptime.include
index 1404750..0d7a43c 100644
--- a/checks/uptime.include
+++ b/checks/uptime.include
@@ -31,37 +31,40 @@
# "max" : ( 86400 * 7, 86400 * 14), # Maximum required uptime (warn, crit)
# }
-def check_uptime_seconds(params, uptime):
- seconds = uptime % 60
- rem = uptime / 60
- minutes = rem % 60
- hours = (rem % 1440) / 60
- days = rem / 1440
- now = int(time.time())
- since = time.strftime("%c", time.localtime(now - uptime))
- state = 0
- infotext = "up since %s (%dd %02d:%02d:%02d)" % (since, days, hours,
minutes, seconds)
+def check_uptime_sec(params, uptime_sec):
+ seconds = uptime_sec % 60
+ rem = uptime_sec / 60
+ minutes = rem % 60
+ hours = (rem % 1440) / 60
+ days = rem / 1440
+ since = time.strftime("%c", time.localtime(time.time() - uptime_sec))
- if params == None: # legacy
+ state = 0
+ infotext = "up since %s (%dd %02d:%02d:%02d)" % \
+ (since, days, hours, minutes, seconds)
+
+ if params == None: # legacy: support older versions of parameters
params = {}
if "min" in params:
warn, crit = params["min"]
- if uptime < crit:
+ if uptime_sec < crit:
state = 2
- elif uptime < warn:
+ elif uptime_sec < warn:
state = max(state, 1)
+
if state:
infotext += ", not up long enough!"
if "max" in params:
warn, crit = params["max"]
- if uptime > crit:
+ if uptime_sec > crit:
state = 2
- elif uptime > warn:
+ elif uptime_sec > warn:
state = max(state, 1)
- if uptime > warn:
+
+ if uptime_sec > warn:
infotext += ", up too long!"
- return (state, infotext, [ ("uptime", uptime) ])
+ return (state, infotext, [ ("uptime", uptime_sec) ])
diff --git a/checks/viprinet_serial b/checks/viprinet_serial
index 0106fb4..d9d4240 100644
--- a/checks/viprinet_serial
+++ b/checks/viprinet_serial
@@ -24,12 +24,19 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
+
+def inventory_viprinet_serial(info):
+ if info:
+ return [(None, None)]
+
+def check_viprinet_serial(_no_item, _no_params, info):
+ return 0, info[0][0]
+
+
check_info["viprinet_serial"] = {
- 'check_function' : lambda _no_item, _no_params, info: (0,
info[0][0]),
- 'inventory_function' : lambda info: len(info) > 0 and [(None, None)] or
[],
+ 'check_function' : check_viprinet_serial,
+ 'inventory_function' : inventory_viprinet_serial,
'service_description' : "Serial Number",
- 'has_perfdata' : False,
'snmp_info' : (".1.3.6.1.4.1.35424.1.1", [2]),
- 'snmp_scan_function' : lambda oid: oid(".1.3.6.1.2.1.1.2.0") in
[".1.3.6.1.4.1.35424"],
+ 'snmp_scan_function' : lambda oid: oid(".1.3.6.1.2.1.1.2.0") ==
".1.3.6.1.4.1.35424",
}
-