Module: check_mk
Branch: master
Commit: f3c8aaa68bdf43480870137cb3b76e647aa9a55f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f3c8aaa68bdf43…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Dec 5 11:43:56 2014 +0100
#1703 FIX ups_test: Fix computation of time since last self test
Instead of the time since the last self test of the battery, the check used
the time the last test has <i>lasted</i>. So this check did not trigger
an alarm every - just for the summary state of the last test.
Thanks for the bug report to Cyril Pawelko!
---
.werks/1703 | 13 ++++++++++
ChangeLog | 1 +
checks/snmp_uptime | 12 +--------
checks/ups_test | 65 +++++++++++++++++++++++--------------------------
checks/uptime.include | 11 +++++++++
5 files changed, 56 insertions(+), 46 deletions(-)
diff --git a/.werks/1703 b/.werks/1703
new file mode 100644
index 0000000..08f05ef
--- /dev/null
+++ b/.werks/1703
@@ -0,0 +1,13 @@
+Title: ups_test: Fix computation of time since last self test
+Level: 2
+Component: checks
+Compatible: compat
+Version: 1.2.5i7
+Date: 1417776132
+Class: fix
+
+Instead of the time since the last self test of the battery, the check used
+the time the last test has <i>lasted</i>. So this check did not trigger
+an alarm every - just for the summary state of the last test.
+
+Thanks for the bug report to Cyril Pawelko!
diff --git a/ChangeLog b/ChangeLog
index 60ba542..05e9e70 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -117,6 +117,7 @@
* 1682 FIX: cmciii_lcp_waterflow: Check can now deal with devices with a different
setup
* 1701 FIX: Correctly show absolute level for CPU load in case of warn/crit...
* 1702 FIX: Fix check_notify_count: notification had been counted twice...
+ * 1703 FIX: ups_test: Fix computation of time since last self test...
Multisite:
* 1508 Allow input of plugin output and perfdata when faking check results...
diff --git a/checks/snmp_uptime b/checks/snmp_uptime
index 8cc9ddb..f2dde6b 100644
--- a/checks/snmp_uptime
+++ b/checks/snmp_uptime
@@ -29,18 +29,8 @@ def inventory_snmp_uptime(info):
if len(info) > 0 and len(info[0]) >= 1:
return [ (None, {}) ]
-
def check_snmp_uptime(checktype, params, info):
- ticks = info[0][0]
- try:
- if len(ticks) < 3:
- uptime = 0
- else:
- uptime = int(ticks[:-2])
- except:
- days, h, m, s = ticks.split(":")
- uptime = (int(days) * 86400 ) + (int(h) * 3600) + (int(m) * 60) + int(float(s))
-
+ uptime = parse_snmp_uptime(info[0][0])
return check_uptime_seconds(params, uptime)
diff --git a/checks/ups_test b/checks/ups_test
index ccbdc59..0324b58 100644
--- a/checks/ups_test
+++ b/checks/ups_test
@@ -76,58 +76,53 @@
# value of upsTestResultsSummary is noTestsInitiated(6),
# upsTestStartTime has the value 0."
-# OID: 1.3.6.1.2.1.33.1.7.6
-# Description:
-# upsTestElapsedTime OBJECT-TYPE
-# SYNTAX TimeInterval
-# MAX-ACCESS read-only
-# STATUS current
-# DESCRIPTION
-# "The amount of time, in TimeTicks, since the test in
-# progress was initiated, or, if no test is in progress,
-# the previous test took to complete. If the value of
-# TestResultsSummary is noTestsInitiated(6),
-# upsTestElapsedTime has the value 0."
-
-ups_test_default = ( 0, 0 )
+ups_test_default = (0, 0)
def inventory_ups_test(info):
- if info:
+ if info[1]:
return [ (None, "ups_test_default") ]
def check_ups_test(_no_item, params, info):
warn, crit = params
- line = info[0]
- ResultsSummary, StartTime, ElapsedTime = map(saveint, line[:-1])
- message = line[3]
+ uptime_info, bat_info = info
+ ResultsSummary, StartTime, upsTestResultsDetail = bat_info[0]
+ uptime = parse_snmp_uptime(uptime_info[0][0])
+ start_time = parse_snmp_uptime(StartTime)
# State of test
state = 0
- if ResultsSummary in [ 3, 4 ]:
+ print ResultsSummary
+ if ResultsSummary in [ '3', '4' ]:
state = 2
- elif ResultsSummary in [ 2, 6 ]:
+ elif ResultsSummary in [ '2' ]:
state = 1
- if message or state:
- yield state, message
+ if upsTestResultsDetail or state:
+ yield state, upsTestResultsDetail
- # Elapsed time
- ElapsedTime = ElapsedTime/100
+ # Elapsed time since last start of test
+ elapsed = uptime - start_time
state = 0
- if crit and ElapsedTime >= crit * 86400:
+ if crit and elapsed >= crit * 86400:
state = 2
- elif warn and ElapsedTime >= warn * 86400:
+ elif warn and elapsed >= warn * 86400:
state = 1
- yield state, "time elapsed since test: %s" %
get_age_human_readable(ElapsedTime)
+ if start_time:
+ yield state, "time elapsed since start of last test: %s" %
get_age_human_readable(elapsed)
+ else:
+ yield state, "no battery test since start of device (%s ago)" %
get_age_human_readable(uptime)
check_info['ups_test'] = {
- "inventory_function" : inventory_ups_test,
- "check_function" : check_ups_test,
- "service_description" : "Self Test",
- "has_perfdata" : False,
- "group" : "ups_test",
- "snmp_info" : ( ".1.3.6.1.2.1.33.1.7", [ 3, 5, 6, 4 ] ),
- "snmp_scan_function" : lambda oid: oid(".1.3.6.1.2.1.1.2.0") in [
".1.3.6.1.4.1.534.1", ".1.3.6.1.4.1.818.1.100.1.2" ]
-
+ "inventory_function" : inventory_ups_test,
+ "check_function" : check_ups_test,
+ "service_description" : "Self Test",
+ "has_perfdata" : False,
+ "group" : "ups_test",
+ "snmp_info" : [
+ ('.1.3.6.1.2.1.1', ['3.0']), #
sysUptime
+ ( ".1.3.6.1.2.1.33.1.7", [ 3, 5, 4 ] ),
+ ],
+ "snmp_scan_function" : lambda oid: oid(".1.3.6.1.2.1.1.2.0")
in [ ".1.3.6.1.4.1.534.1", ".1.3.6.1.4.1.818.1.100.1.2" ],
+ "includes" : [ 'uptime.include' ],
}
diff --git a/checks/uptime.include b/checks/uptime.include
index 099cb3f..fda4b81 100644
--- a/checks/uptime.include
+++ b/checks/uptime.include
@@ -25,6 +25,17 @@
# Boston, MA 02110-1301 USA.
+
+def parse_snmp_uptime(ticks):
+ try:
+ if len(ticks) < 3:
+ return 0
+ else:
+ return int(ticks[:-2])
+ except:
+ days, h, m, s = ticks.split(":")
+ return (int(days) * 86400 ) + (int(h) * 3600) + (int(m) * 60) + int(float(s))
+
# Example for params:
# {
# "min" : ( 7200, 3600 ), # Minimum required uptime (warn, crit)