Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / mysql_slave
blob1dfdf90369b02b626dc1af8aed54082ce9fe02ce
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 # FIXME: Crapy copy n paste! Consolidate with other mysql_* parse functions
29 def parse_mysql_slave(info):
30 def parse_line(l):
31 if ':' in l[0]:
32 val = ' '.join(l[1:])
34 # Parse some values
35 try:
36 val = int(val)
37 except ValueError:
38 if val == 'Yes':
39 val = True
40 elif val == 'No':
41 val = False
42 elif val == 'None':
43 val = None
44 return line[0][:-1], val
45 return None, None
47 parsed = {}
48 instance = False
49 for line in info:
50 if line[0].startswith("[["):
51 instance = line[0][2:-2]
52 if instance == "":
53 instance = "mysql"
54 parsed[instance] = {}
55 elif instance:
56 key, value = parse_line(line)
57 if key:
58 parsed[instance][key] = value
60 # Support for old Plugin version
61 if not instance:
62 parsed['mysql'] = {}
63 for line in info:
64 key, value = parse_line(line)
65 if key:
66 parsed['mysql'][key] = value
68 return parsed
71 @discover
72 def inventory_mysql_slave(key, values):
73 return len(values) > 0
76 @get_parsed_item_data
77 def check_mysql_slave(item, params, data):
78 state = 0
79 perfdata = []
80 output = []
82 if data['Slave_IO_Running']:
83 output.append('Slave-IO: running')
85 if data['Relay_Log_Space']:
86 output.append('Relay Log: %s' % get_bytes_human_readable(data['Relay_Log_Space']))
87 perfdata.append(('relay_log_space', data['Relay_Log_Space']))
89 else:
90 output.append('Slave-IO: not running(!!)')
91 state = 2
93 if data['Slave_SQL_Running']:
94 output.append('Slave-SQL: running')
96 # Makes only sense to monitor the age when the SQL slave is running
97 if data['Seconds_Behind_Master'] == 'NULL':
98 output.append('Time behind master: NULL (Lost connection?)(!!)')
99 state = 2
100 else:
101 out = 'Time behind Master: %s' % get_age_human_readable(data['Seconds_Behind_Master'])
102 warn, crit = params.get('seconds_behind_master', (None, None))
103 if crit is not None and data['Seconds_Behind_Master'] > crit:
104 state = 2
105 out += '(!!)'
106 elif warn is not None and data['Seconds_Behind_Master'] > warn:
107 state = max(state, 1)
108 out += '(!)'
109 output.append(out)
110 perfdata.append(('sync_latency', data['Seconds_Behind_Master'], warn, crit))
111 else:
112 output.append('Slave-SQL: not running(!!)')
113 state = 2
115 return state, ', '.join(output), perfdata
118 check_info['mysql_slave'] = {
119 "parse_function": parse_mysql_slave,
120 "inventory_function": inventory_mysql_slave,
121 "check_function": check_mysql_slave,
122 "service_description": "MySQL DB Slave %s",
123 "has_perfdata": True,
124 "group": "mysql_slave",