Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / db2_backup
blobd7a6c3478001b6400fa9b7ab695d78495ef452a8
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # ------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2015 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 # <<<db2_backup>>>
28 # [[[db2taddm:CMDBS1]]]
29 # 2015-03-12-04.00.13.000000
31 db2_backup_default_levels = (86400 * 14, 86400 * 28)
34 def inventory_db2_backup(parsed):
35 for instance in parsed[1]:
36 yield instance, "db2_backup_default_levels"
39 def check_db2_backup(item, params, parsed):
40 db = parsed[1].get(item)
41 if not db:
42 raise MKCounterWrapped("Login into database failed")
44 try:
45 last_backup = time.mktime(time.strptime(db[0][0][:19], "%Y-%m-%d-%H.%M.%S"))
46 except:
47 if db[0][0] == "-":
48 yield 1, "No backup available"
49 else:
50 yield 3, "Last backup contains an invalid timestamp: %s" % db[0][0]
51 return
53 age = time.time() - last_backup
54 if params:
55 warn, crit = params
56 if age >= crit:
57 yield 2, "Time since last backup: %s" % get_age_human_readable(age)
58 elif age >= warn:
59 yield 1, "Time since last backup: %s" % get_age_human_readable(age)
60 else:
61 yield 0, "Time since last backup: %s" % get_age_human_readable(age)
62 else:
63 yield 0, "Time since last backup: %s" % get_age_human_readable(age)
66 check_info['db2_backup'] = {
67 "parse_function": parse_db2_dbs,
68 "service_description": "DB2 Backup %s",
69 "check_function": check_db2_backup,
70 "inventory_function": inventory_db2_backup,
71 "group": "db2_backup",
72 "includes": ["db2.include"],