Module: check_mk
Branch: master
Commit: 30766e52ad06a7924c54725dad11a7065c1a8a6a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=30766e52ad06a7…
Author: Bernd Stroessenreuther <bs(a)mathias-kettner.de>
Date: Tue Dec 10 13:47:41 2013 +0100
timemachine: new check
Checks the age of latest backup by timemachine on MAC OS and compares the age against
given levels.
---
.werks/86 | 8 ++++
ChangeLog | 1 +
agents/check_mk_agent.macosx | 5 +++
checkman/timemachine | 38 ++++++++++++++++
checks/timemachine | 80 ++++++++++++++++++++++++++++++++++
web/plugins/wato/check_parameters.py | 20 +++++++++
6 files changed, 152 insertions(+)
diff --git a/.werks/86 b/.werks/86
new file mode 100644
index 0000000..7001943
--- /dev/null
+++ b/.werks/86
@@ -0,0 +1,8 @@
+Title: timemachine: new check
+Level: 2
+Component: checks
+Version: 1.2.3i8
+Date: 1386679588
+Class: feature
+
+Checks the age of latest backup by timemachine on MAC OS and compares the age against
given levels.
diff --git a/ChangeLog b/ChangeLog
index 5e4a1a4..50f066a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,7 @@
* 0073 moxa_iologik_register: new check to monitor moxa e2000 series registers
* 0105 apc_humidity: New Check for humidity levels on APC Devices
* 0106 3ware_units: The verifying state is now handled as ok...
+ * 0086 timemachine: new check...
* 0103 FIX: services: Fixed bug with service inventory defined in main.mk...
* 0299 FIX: borcade_mlx_fan: Prettified output, handling "other" state now
* 0300 FIX: cisco_fru_power: Trying not to inventorize not plugged in FRUs...
diff --git a/agents/check_mk_agent.macosx b/agents/check_mk_agent.macosx
index 263b757..2e0f533 100755
--- a/agents/check_mk_agent.macosx
+++ b/agents/check_mk_agent.macosx
@@ -88,6 +88,11 @@ if [ -r "$MK_CONFDIR/fileinfo.cfg" ] ; then
stat -f "%N|%z|%m" $(cat "$MK_CONFDIR/fileinfo.cfg")
fi
+if type tmutil >/dev/null
+then
+ echo '<<<timemachine>>>'
+ tmutil latestbackup
+fi
###############################
# Things up for takers:
diff --git a/checkman/timemachine b/checkman/timemachine
new file mode 100644
index 0000000..6300966
--- /dev/null
+++ b/checkman/timemachine
@@ -0,0 +1,38 @@
+title: Age of latest backup by timemachine
+agents: macosx
+catalog: os/services
+license: GPL
+distribution: check_mk
+description:
+ Checks the age of latest backup by timemachine.
+ Therefor on the agent the command {tmutil latestbackup} is executed.
+
+ Returns {WARN} or {CRIT} if the latest backup is older than given ages.
+ Returns {CRIT} if the tmutil command returns an error.
+
+examples:
+ # set default levels to 21600 sec (6h) for WARN and 43200 sec (12h) for CRIT
+ backup_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),
+ ]
+
+ # or use individual levels for warn and crit
+ checks += [
+ ("MyMAC", "timemachine", None, {'age': (10000, 20000)}),
+ ]
+
+inventory:
+ Finds exactly one service on every MAC OS machine having tmutil installed.
+
+[parameters]
+parameters (dict): with the element
+{"age"}: (int, int): {WARN} and {CRIT} levels for maximum age of latest backup
+ in seconds
+
+[configuration]
+backup_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
new file mode 100644
index 0000000..8fb0b00
--- /dev/null
+++ b/checks/timemachine
@@ -0,0 +1,80 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2013 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at
http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# ails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+# Example output from agent on success:
+# <<<timemachine>>>
+# /Volumes/Backup/Backups.backupdb/macvm/2013-11-28-202610
+#
+# Example output from agent on failure:
+# <<<timemachine>>>
+# Unable to locate machine directory for host.
+
+import datetime, time, re
+
+backup_timemachine_default_levels = { "age": ( 86400, 172800 ) } # 1d/2d
+
+def inventory_timemachine(info):
+ return [(None, backup_timemachine_default_levels)]
+
+def check_timemachine(item, params, info):
+ if len(info[0]) > 1:
+ message = " ".join(info[0])
+ return 2, "Backup seems to have failed, message was: %s" % message
+
+ warn, crit = params['age']
+ now = datetime.datetime.now()
+ tokens = info[0][0].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
+
+ 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:
+ state = 2
+ return state, "Last Backup was at %s (age %s)" % (backuptime, backupage)
+
+check_info["timemachine"] = {
+ "check_function" : check_timemachine,
+ "inventory_function" : inventory_timemachine,
+ "service_description" : "Backup Timemachine",
+ "group" : "backup_timemachine",
+ "has_perfdata" : False,
+}
diff --git a/web/plugins/wato/check_parameters.py b/web/plugins/wato/check_parameters.py
index 89824f5..914ce58 100644
--- a/web/plugins/wato/check_parameters.py
+++ b/web/plugins/wato/check_parameters.py
@@ -2435,6 +2435,26 @@ register_check_parameters(
register_check_parameters(
subgroup_applications,
+ "backup_timemachine",
+ _("Age of timemachine backup"),
+ Dictionary(
+ elements = [
+ ("age",
+ Tuple(
+ title = _("Maximum age of latest timemachine backup"),
+ elements = [
+ Age(title = _("Warning if older than"), default_value =
86400),
+ Age(title = _("Critical if older than"), default_value =
172800)
+ ]
+ )
+ )]
+ ),
+ None,
+ None
+)
+
+register_check_parameters(
+ subgroup_applications,
"mssql_counters_locks",
_("MSSQL Locks"),
Dictionary(