Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / plesk_backups
blob4c5f788dbe4123a8449516c30a03b8854037b85b
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
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.
28 def inventory_plesk_backups(info):
29 inventory = []
30 for line in info:
31 inventory.append((line[0], {}))
32 return inventory
35 def check_plesk_backups(item, params, info):
36 for line in info:
37 if item != line[0]:
38 continue
40 if len(line) != 5 or line[1] != '0':
41 if line[1] == '2':
42 return (3, 'Error in agent (%s)' % ' '.join(line[1:]))
44 elif line[1] == '4':
45 state = params.get('no_backup_configured_state', 1)
46 return (state, 'No backup configured')
48 elif line[1] == '5':
49 state = params.get('no_backup_found_state', 1)
50 return (state, 'No backup found')
52 return (3, 'Unexpected line %r' % line)
54 _domain, _rc, timestamp, size, total_size = line
55 size = saveint(size)
56 total_size = saveint(total_size)
57 timestamp = saveint(timestamp)
59 status = 0
60 output = []
61 perfdata = []
63 # 1. check last backup size not 0 bytes
64 status_txt = ''
65 if size == 0:
66 status = 2
67 status_txt = ' (!!)'
68 output.append('Last Backup - Size: %s%s' % (get_bytes_human_readable(size), status_txt))
69 perfdata.append(('last_backup_size', size))
71 age_seconds = int(time.time()) - timestamp
72 seconds = age_seconds % 60
73 rem = age_seconds / 60
74 minutes = rem % 60
75 hours = (rem % 1440) / 60
76 days = rem / 1440
78 # 2. check age of last backup < 24h
79 status_txt = ''
80 warn, crit = None, None
81 if 'backup_age' in params:
82 warn, crit = params['backup_age']
83 if age_seconds > params['backup_age'][1]:
84 status = max(status, 2)
85 status_txt = ' (!!)'
86 elif age_seconds > params['backup_age'][0]:
87 status = max(status, 1)
88 status_txt = ' (!)'
90 backup_time = time.strftime("%c", time.localtime(timestamp))
91 output.append('Age: %s (%dd %02d:%02d:%02d)%s' % (backup_time, days, hours, minutes,
92 seconds, status_txt))
93 perfdata.append(('last_backup_age', age_seconds, warn, crit))
95 # 3. check total size of directory above configured threshold
96 status_txt = ''
97 warn, crit = None, None
98 if 'total_size' in params:
99 warn, crit = params['total_size']
100 if total_size > params['total_size'][1]:
101 status = max(status, 2)
102 status_txt = ' (!!)'
103 elif total_size > params['total_size'][0]:
104 status = max(status, 1)
105 status_txt = ' (!)'
106 output.append('Total Size: %s%s' % (get_bytes_human_readable(total_size), status_txt))
107 perfdata.append(('total_size', total_size))
109 return (status, ', '.join(output), perfdata)
111 return (3, 'Domain not found')
114 check_info['plesk_backups'] = {
115 'check_function': check_plesk_backups,
116 'inventory_function': inventory_plesk_backups,
117 'service_description': "Plesk Backup %s",
118 'has_perfdata': True,
119 'group': 'plesk_backups',