Module: check_mk
Branch: master
Commit: 1fd758e94b0392bfe5c18c57cf800a4442211ba4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1fd758e94b0392…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Dec 9 10:39:00 2014 +0100
#1729 FIX apc_symmetra_test: Cleaned up check, fixed exception when self test date is
zero
---
.werks/1729 | 9 +++++++++
ChangeLog | 1 +
checks/apc_symmetra_test | 37 ++++++++++++++-----------------------
3 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/.werks/1729 b/.werks/1729
new file mode 100644
index 0000000..92358e0
--- /dev/null
+++ b/.werks/1729
@@ -0,0 +1,9 @@
+Title: apc_symmetra_test: Cleaned up check, fixed exception when self test date is zero
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.5i7
+Date: 1418117821
+Class: fix
+
+
diff --git a/ChangeLog b/ChangeLog
index c84e5a0..f36b86b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -139,6 +139,7 @@
* 1696 FIX: cisco_temp_sensor: Value reported of check was not always correct
(precision was wrong)...
* 1727 FIX: cisco_secure: Fixed inventory exception when port security is not
enabled
* 1728 FIX: cisco_temp_perf: Not inventorized anymore for hosts supporting
cisco_temp_sensor
+ * 1729 FIX: apc_symmetra_test: Cleaned up check, fixed exception when self test date
is zero
Multisite:
* 1508 Allow input of plugin output and perfdata when faking check results...
diff --git a/checks/apc_symmetra_test b/checks/apc_symmetra_test
index 25f297e..35d2fd1 100644
--- a/checks/apc_symmetra_test
+++ b/checks/apc_symmetra_test
@@ -52,53 +52,44 @@
# ::= { upsAdvTest 4 }
#
-import datetime
-# What the F**k! Importing of module is absolutely discouraged in checks.
-# Also we use time in check_mk, not datetime.
-
-ups_test_default = ( 0, 0 )
+ups_test_default = (0, 0)
def check_apc_test(item, params, info):
- warn, crit = params
+ days_warn, days_crit = params
if not info:
return 3, "Data Missing"
- line = info[0]
- DiagnosticsResults = saveint(line[0])
- LastDiagnosticsDate = line[1]
+ last_result = int(info[0][0])
+ last_date = info[0][1]
- if LastDiagnosticsDate == 'Unknown':
+ if last_date == 'Unknown' or len(last_date) not in [8, 10]:
return 3, "Date of last self test is unknown"
- month, day, year = map(saveint, LastDiagnosticsDate.split('/'))
- last_diag_date = datetime.date( year, month, day)
- today = datetime.date.today()
- diag_diff = today - last_diag_date
- dcrit = datetime.timedelta(days=crit)
- dwarn = datetime.timedelta(days=warn)
+ year_format = len(last_date) == 8 and '%y' or '%Y'
+ last_ts = time.mktime(time.strptime(last_date, '%m/%d/'+year_format))
+ days_diff = (time.time() - last_ts) / 86400
diagnostic_status_text = { 1:"OK", 2:"failed",
3:"invalid", 4:"in progress" }
state = 0
diag_label = ""
- if DiagnosticsResults == 2:
+ if last_result == 2:
state = 2
diag_label = "(!!)"
- elif DiagnosticsResults == 3:
+ elif last_result == 3:
state = 1
diag_label = "(!)"
time_label = ""
- if crit != 0 and diag_diff >= dcrit:
+ if days_crit and days_diff >= days_crit:
state = 2
time_label = "(!!)"
- elif warn != 0 and diag_diff >= dwarn:
+ elif days_warn and days_diff >= days_warn:
state = max(state, 1)
time_label = "(!)"
- ResultsDetail = "Result of self test: %s%s, Date of last test: %s%s" \
- % (diagnostic_status_text.get(DiagnosticsResults), diag_label,
LastDiagnosticsDate, time_label)
+ return state, "Result of self test: %s%s, Date of last test: %s%s" % \
+ (diagnostic_status_text.get(last_result, '-'), diag_label, last_date,
time_label)
- return (state, ResultsDetail )
def inventory_apc_test(info):
if info: