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:
29 # [[[site:heute2:encrypted]]]
30 # {'bytes_per_second': 0,
31 # 'finished': 1467733556.67532,
32 # 'output': '2016-07-05 17:45:56 --- Starting backup (Check_MK-Klappspaten-heute2-encrypted) ---\n2016-07-05 17:45:56 Cleaning up previously completed backup\n2016-07-05 17:45:56
33 # --- Backup completed (Duration: 0:00:00, Size: 6.49 MB, IO: 0.00 B/s) ---\n',
36 # 'started': 1467733556.39216,
37 # 'state': 'finished',
41 # [[[system:backup-single]]]
43 # "bytes_per_second": 141691.8939750615,
44 # "finished": 1468914936.47381,
45 # "next_schedule": 1468973400.0,
46 # "output": "2016-07-19 07:55:07 --- Starting backup (Check_MK_Appliance-alleine-backup+single to klappspaten) ---\n2016-07-19 07:55:07 Performing system backup (system.tar)\n2016-07-19 07:55:10 Performing system data backup (system-data.tar)\n2016-07-19 07:55:19 Performing site backup: migrate\n2016-07-19 07:55:19 The Check_MK version of this site does not support online backups. The site seems to be at least partially running. Stopping the site during backup and starting it again after completion.\n2016-07-19 07:55:19 Stopping site\n2016-07-19 07:55:23 Start offline site backup\n2016-07-19 07:55:23 Starting site again\n2016-07-19 07:55:27 Performing site backup: test\n2016-07-19 07:55:35 Verifying backup consistency\n2016-07-19 07:55:36 Cleaning up previously completed backup\n2016-07-19 07:55:36 --- Backup completed (Duration: 0:00:28, Size: 380.65 MB, IO: 138.37 kB/s) ---\n",
49 # "started": 1468914907.521488,
50 # "state": "finished",
55 # TODO: Refactor this.
56 def parse_mkbackup(info
):
61 job
, json_data
= None, ""
64 if line
.startswith("[[["):
65 head
= line
[3:-3].split(":")
67 site_id
, job_id
= head
[1:]
68 sites
= parsed
.setdefault("site", {})
69 jobs
= sites
.setdefault(site_id
, {})
70 job
= jobs
[job_id
] = {}
73 system
= parsed
.setdefault("system", {})
74 job
= system
[job_id
] = {}
79 job
.update(json
.loads(json_data
))
85 def check_mkbackup(job_state
):
86 if job_state
["state"] in ["started", "running"]:
87 duration
= time
.time() - job_state
["started"]
89 yield (0, "The job is running for %s since %s" % (
90 get_age_human_readable(duration
), get_timestamp_human_readable(job_state
["started"])),
91 [("backup_duration", duration
), ("backup_avgspeed", job_state
["bytes_per_second"])])
93 elif job_state
["state"] == "finished":
94 if job_state
["success"] is False:
95 yield 2, "Backup failed"
97 yield 0, "Backup completed"
99 duration
= job_state
["finished"] - job_state
["started"]
100 yield (0, "it was running for %s from %s till %s" %
101 (get_age_human_readable(duration
), get_timestamp_human_readable(
102 job_state
["started"]), get_timestamp_human_readable(job_state
["finished"])),
103 [("backup_duration", duration
), ("backup_avgspeed", job_state
["bytes_per_second"])])
105 if "size" in job_state
:
106 yield (0, "Size: %s" % get_bytes_human_readable(job_state
["size"]),
107 [("backup_size", job_state
["size"])])
109 next_run
= job_state
["next_schedule"]
110 if next_run
== "disabled":
111 yield 1, "Schedule is currently disabled"
113 elif next_run
is not None:
114 if next_run
< time
.time():
118 yield state
, "Next run: %s" % get_timestamp_human_readable(next_run
)
121 def inventory_mkbackup_system(parsed
):
122 for job_id
in parsed
.get("system", {}).keys():
126 def check_mkbackup_system(item
, _no_params
, parsed
):
127 job_state
= parsed
.get("system", {}).get(item
)
131 return check_mkbackup(job_state
)
134 check_info
["mkbackup"] = {
135 "parse_function": parse_mkbackup
,
136 "inventory_function": inventory_mkbackup_system
,
137 "check_function": check_mkbackup_system
,
138 "service_description": "Backup %s",
139 "has_perfdata": True,
143 def inventory_mkbackup_site(parsed
):
144 for site_id
, jobs
in parsed
.get("site", {}).items():
145 for job_id
in jobs
.keys():
146 yield "%s backup %s" % (site_id
, job_id
), {}
149 def check_mkbackup_site(item
, _no_params
, parsed
):
150 site_id
, job_id
= item
.split(" backup ")
151 job_state
= parsed
.get("site", {}).get(site_id
, {}).get(job_id
)
155 return check_mkbackup(job_state
)
158 check_info
["mkbackup.site"] = {
159 "inventory_function": inventory_mkbackup_site
,
160 "check_function": check_mkbackup_site
,
161 "service_description": "OMD %s",
162 "has_perfdata": True,