Module: check_mk
Branch: master
Commit: 3953b543d1583b74bd2a0a939d25884aeb24e063
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3953b543d1583b…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Jan 9 17:42:24 2014 +0100
FIX timemachine: do not inventorize check when timemachine is not used
---
.werks/444 | 10 +++++++
ChangeLog | 1 +
checkman/timemachine | 6 ++---
checks/timemachine | 72 ++++++++++++++++++++++++++------------------------
4 files changed, 51 insertions(+), 38 deletions(-)
diff --git a/.werks/444 b/.werks/444
new file mode 100644
index 0000000..eef9838
--- /dev/null
+++ b/.werks/444
@@ -0,0 +1,10 @@
+Title: timemachine: do not inventorize check when timemachine is not used
+Level: 1
+Component: checks
+Class: fix
+State: unknown
+Version: 1.2.5i1
+Date: 1389285719
+Targetversion: future
+
+
diff --git a/ChangeLog b/ChangeLog
index 541f95e..4f156a2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -89,6 +89,7 @@
* 0253 FIX: windows agent: fixed crash on processing eventlog records...
* 0403 FIX: mem.used: Prefer statgrab on FreeBSD for supporting more than 4GB...
* 0404 FIX: cups_queues: fix exception in case of alternative time format...
+ * 0444 FIX: timemachine: do not inventorize check when timemachine is not used
Multisite:
* 0371 Added log class filter to hostsvcevents view
diff --git a/checkman/timemachine b/checkman/timemachine
index 6300966..2ddb63b 100644
--- a/checkman/timemachine
+++ b/checkman/timemachine
@@ -12,11 +12,11 @@ description:
examples:
# set default levels to 21600 sec (6h) for WARN and 43200 sec (12h) for CRIT
- backup_timemachine_default_levels = { "age": ( 86400, 172800 ) }
+ timemachine_default_levels = { "age": ( 86400, 172800 ) }
# Check timemachine backups on a box called MyMAC with default levels
checks += [
- ("MyMAC", "timemachine", None,
backup_timemachine_default_levels),
+ ("MyMAC", "timemachine", None, timemachine_default_levels),
]
# or use individual levels for warn and crit
@@ -33,6 +33,6 @@ parameters (dict): with the element
in seconds
[configuration]
-backup_timemachine_default_levels(dict): The standard levels for {WARN} and
+timemachine_default_levels(dict): The standard levels for {WARN} and
{CRIT}, preset to { "age": ( 86400, 172800 ) } which is 1 day / 2 days
diff --git a/checks/timemachine b/checks/timemachine
index d77e3cb..ee9219b 100644
--- a/checks/timemachine
+++ b/checks/timemachine
@@ -32,49 +32,51 @@
# <<<timemachine>>>
# Unable to locate machine directory for host.
-import datetime, time, re
-backup_timemachine_default_levels = { "age": ( 86400, 172800 ) } # 1d/2d
+factory_settings["timemachine_default_levels"] = {
+ "age": ( 86400, 172800 ) # 1d/2d
+}
+
def inventory_timemachine(info):
- return [(None, backup_timemachine_default_levels)]
+ if " ".join(info[0]) != "Unable to locate machine directory for
host.":
+ return [ (None, {}) ]
+
def check_timemachine(item, params, info):
- message = " ".join(info[0])
- if not
re.match('/Volumes/.+/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]$',
message):
- return 2, "Backup seems to have failed, message was: %s" % message
+ line = " ".join(info[0]) # We expect at least one line
+ if not line.startswith("/Volumes/"):
+ return 2, "Backup seems to have failed, message was: " + line
- warn, crit = params['age']
- now = datetime.datetime.now()
- tokens = message.split("/")
- timestamp = tokens[-1]
- state = 0
- result =
re.match('([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])-([0-9][0-9])([0-9][0-9])([0-9][0-9])',
timestamp)
- if result == None:
- return 3, "Timestamp of last backup in unknown format: %s" % timestamp
- y = int(result.group(1))
- m = int(result.group(2))
- d = int(result.group(3))
- H = int(result.group(4))
- M = int(result.group(5))
- S = int(result.group(6))
- backuptime = datetime.datetime( y, m, d, H, M, S)
- maxage_warn = datetime.timedelta(seconds=warn)
- maxage_crit = datetime.timedelta(seconds=crit)
- backupage = now - backuptime
+ tokens = line.split("/")
+ timestamp = tokens[-1]
+ backup_timeb = time.strptime(timestamp, "%Y-%m-%d-%H%M%S")
+ backup_time = time.mktime(backup_timeb)
+ backup_age = time.time() - backup_time
- if backuptime > now:
- return 1, "Time problem: The last backup has a timestamp in the future:
%s" % backuptime
- if backupage > maxage_warn:
- state = 1
- if backupage > maxage_crit:
+ if backup_age < 0:
+ return 3, "Timestamp of last backup is in the future: " + timestamp
+
+ infotext = "Last backup was at %s (%s ago)" % (
+ time.strftime("%c", backup_timeb),
get_age_human_readable(backup_age))
+
+ warn, crit = params['age']
+ if backup_age >= crit:
state = 2
- return state, "Last Backup was at %s (age %s)" % (backuptime, backupage)
+ infotext += ", more than %s ago" % get_age_human_readable(crit)
+ elif backup_age >= warn:
+ state = 1
+ infotext += ", more than %s ago" % get_age_human_readable(warn)
+ else:
+ state = 0
+
+ return state, infotext
+
check_info["timemachine"] = {
- "check_function" : check_timemachine,
- "inventory_function" : inventory_timemachine,
- "service_description" : "Backup Timemachine",
- "group" : "backup_timemachine",
- "has_perfdata" : False,
+ "check_function" : check_timemachine,
+ "inventory_function" : inventory_timemachine,
+ "default_levels_variable" : "timemachine_default_levels",
+ "service_description" : "Backup Timemachine",
+ "group" : "backup_timemachine",
}