Module: check_mk
Branch: master
Commit: 9e9953bca7e6b8cd7f8b557d8917fdbc9313a5c0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9e9953bca7e6b8…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Jun 29 15:13:55 2015 +0200
#2382 FIX mssql_backup: Formating age output more human friendly
---
.werks/2382 | 10 ++++++++++
ChangeLog | 1 +
checks/mssql_backup | 18 +++++++-----------
3 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/.werks/2382 b/.werks/2382
new file mode 100644
index 0000000..8bf6680
--- /dev/null
+++ b/.werks/2382
@@ -0,0 +1,10 @@
+Title: mssql_backup: Formating age output more human friendly
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.7i3
+Date: 1435583553
+
+
diff --git a/ChangeLog b/ChangeLog
index 2d319c9..513ef39 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -17,6 +17,7 @@
* 2363 FIX: jolokia_metrics.uptime: Do not inventory instances where Uptime is
missing - avoid crashed check
* 2381 FIX: emc_datadomain_fans: Made check more robust against broken SNMP output
* 2366 FIX: carel_sensors: fix crash in case of missing temperature sensor
+ * 2382 FIX: mssql_backup: Formating age output more human friendly
Multisite:
* 2314 FIX: Availability: fixed exception when grouping by host or service group
diff --git a/checks/mssql_backup b/checks/mssql_backup
index 5de613c..615c25a 100644
--- a/checks/mssql_backup
+++ b/checks/mssql_backup
@@ -24,10 +24,6 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-
-# TODO: Remove this. Use time.strptime and time.strftime!!
-import datetime
-
# <<<mssql_backup>>>
# MSSQL_SQLEXPRESS test123 1331207325
@@ -50,14 +46,13 @@ def check_mssql_backup(item, params, info):
if item == inst + ' ' + tablespace:
if last_backup_date:
- dt = datetime.datetime(*time.strptime(last_backup_date + ' ' +
last_backup_time, '%Y-%m-%d %H:%M:%S')[:6])
+ timestamp = time.mktime(time.strptime(last_backup_date + ' ' +
last_backup_time,
+ '%Y-%m-%d %H:%M:%S'))
else:
- dt = datetime.datetime.fromtimestamp(saveint(last_backup_timestamp))
+ timestamp = int(last_backup_timestamp)
state = 0
- # Would be so nice to use delta.total_seconds(). But we must care about
python < 2.7
- delta = datetime.datetime.now() - dt
- sec_ago = (delta.microseconds + (delta.seconds + delta.days * 24 * 3600) *
10**6) / 10**6
+ sec_ago = time.time() - timestamp
if params is not None:
if sec_ago >= params[1]:
@@ -68,8 +63,9 @@ def check_mssql_backup(item, params, info):
else:
perfdata = [('seconds', sec_ago)]
- return (state, 'Last backup was at %s (%ds ago)' %
- (dt.strftime('%Y-%m-%d %H:%M:%S'), sec_ago), perfdata)
+ return (state, 'Last backup was at %s (%s ago)' %
+ (time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp)),
+ get_age_human_readable(sec_ago)), perfdata)
return (3, 'Tablespace %s could not be found' % item)