2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
10 # | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 # tails. You should have received a copy of the GNU General Public
23 # License along with GNU Make; see the file COPYING. If not, write
24 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 # Boston, MA 02110-1301 USA.
27 # Example output from agent on success:
29 # /Volumes/Backup/Backups.backupdb/macvm/2013-11-28-202610
31 # Example output from agent on failure:
33 # Unable to locate machine directory for host.
35 factory_settings
["timemachine_default_levels"] = {
36 "age": (86400, 172800) # 1d/2d
40 def inventory_timemachine(info
):
41 if " ".join(info
[0]) != "Unable to locate machine directory for host.":
45 def check_timemachine(item
, params
, info
):
46 line
= " ".join(info
[0]) # We expect at least one line
47 if not line
.startswith("/Volumes/"):
48 return 2, "Backup seems to have failed, message was: " + line
50 tokens
= line
.split("/")
51 timestamp
= tokens
[-1]
52 backup_timeb
= time
.strptime(timestamp
, "%Y-%m-%d-%H%M%S")
53 backup_time
= time
.mktime(backup_timeb
)
54 backup_age
= time
.time() - backup_time
57 return 3, "Timestamp of last backup is in the future: " + timestamp
59 infotext
= "Last backup was at %s (%s ago)" % (time
.strftime("%c", backup_timeb
),
60 get_age_human_readable(backup_age
))
62 warn
, crit
= params
['age']
63 if backup_age
>= crit
:
65 infotext
+= ", more than %s ago" % get_age_human_readable(crit
)
66 elif backup_age
>= warn
:
68 infotext
+= ", more than %s ago" % get_age_human_readable(warn
)
72 return state
, infotext
75 check_info
["timemachine"] = {
76 "check_function": check_timemachine
,
77 "inventory_function": inventory_timemachine
,
78 "default_levels_variable": "timemachine_default_levels",
79 "service_description": "Backup Timemachine",
80 "group": "backup_timemachine",