Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / cisco_ip_sla
blob4a369e3cd53907beb4cfe0f0bcfec7353cb5af6e
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.
27 factory_settings['cisco_ip_sla_default_levels'] = {
28 'state': 'active',
29 'connection_lost_occured': 'no',
30 'timeout_occured': 'no',
31 'completion_time_over_treshold_occured': 'no',
32 'latest_rtt_completion_time': (250, 500),
33 'latest_rtt_state': 'ok',
37 def parse_cisco_ip_sla(info):
38 # since the RTT Index, Owner and Tag don't have to be set we use
39 # indices for the different items
40 precisions = [list_.pop() for list_ in info[0]]
41 precisions = {str(i): 'ms' if p[0] == '1' else 'us' for i, p in enumerate(precisions)}
43 rtt_types = {
44 '1': 'echo',
45 '2': 'path echo',
46 '3': 'file IO',
47 '4': 'script',
48 '5': 'UDP echo',
49 '6': 'TCP connect',
50 '7': 'HTTP',
51 '8': 'DNS',
52 '9': 'jitter',
53 '10': 'DLSw',
54 '11': 'DHCP',
55 '12': 'FTP',
56 '13': 'VoIP',
57 '14': 'RTP',
58 '15': 'LSP group',
59 '16': 'ICMP jitter',
60 '17': 'LSP ping',
61 '18': 'LSP trace',
62 '19': 'ethernet ping',
63 '20': 'ethernet jitter',
64 '21': 'LSP ping pseudowire',
67 states = {
68 '1': 'reset',
69 '2': 'orderly stop',
70 '3': 'immediate stop',
71 '4': 'pending',
72 '5': 'inactive',
73 '6': 'active',
74 '7': 'restart',
77 rtt_states = {
78 '0': 'other',
79 '1': 'ok',
80 '2': 'disconnected',
81 '3': 'over threshold',
82 '4': 'timeout',
83 '5': 'busy',
84 '6': 'not connected',
85 '7': 'dropped',
86 '8': 'sequence error',
87 '9': 'verify error',
88 '10': 'application specific error',
91 def to_ip_address(int_list):
92 if len(int_list) == 4:
93 return '%d.%d.%d.%d' % tuple(int_list)
94 elif len(int_list) == 6:
95 return '%d:%d:%d:%d:%d:%d' % tuple(int_list)
96 return ''
98 #contains description, parse function, unit and type
99 contents = [
100 ( # rttMonEchoAdminEntry
101 ('Target address', to_ip_address, '', None),
102 ('Source address', to_ip_address, '', None),
104 ( # rttMonCtrlAdminEntry
105 ('Owner', None, '', None),
106 ('Tag', None, '', None),
107 ('RTT type', lambda x: rtt_types.get(x, 'unknown'), '', 'option'),
108 ('Threshold', int, 'ms', 'option'),
110 ( # rttMonCtrlOperEntry
111 ('State', lambda x: states.get(x, 'unknown'), '', 'option'),
112 ('Text', None, '', None),
113 ('Connection lost occured', lambda x: 'yes' if x == '1' else 'no', '', 'option'),
114 ('Timeout occured', lambda x: 'yes' if x == '1' else 'no', '', 'option'),
115 ('Completion time over treshold occured', lambda x: 'yes' if x == '1' else 'no', '',
116 'option'),
118 ( # rttMonLatestRttOperEntry
119 ('Latest RTT completion time', int, 'ms/us', 'level'),
120 ('Latest RTT state', lambda x: rtt_states.get(x, 'unknown'), '', 'option'),
124 parsed = {}
125 for content, entries in zip(contents, info):
126 if not entries:
127 continue
129 for index, entry in enumerate(entries):
130 index = str(index)
131 parsed.setdefault(index, [])
132 for (description, parser, unit, type_), value in zip(content, entry):
133 if parser:
134 value = parser(value)
135 if unit == 'ms/us':
136 unit = precisions[index]
137 parsed[index].append((description, value, unit, type_))
139 return parsed
142 def inventory_cisco_ip_sla(parsed):
143 for index in parsed:
144 yield index, {}
147 @get_parsed_item_data
148 def check_cisco_ip_sla(_item, params, data):
149 for description, value, unit, type_ in data:
150 if not value:
151 continue
153 state = 0
154 if unit:
155 infotext = '%s: %s %s' % (description, value, unit)
156 else:
157 infotext = '%s: %s' % (description, value)
158 perfdata = []
160 param = params.get(description.lower().replace(' ', '_'))
162 if type_ == 'option':
163 if param and param != value:
164 state = 1
165 infotext += ' (expected %s)' % param
166 elif type_ == 'level':
167 warn, crit = param # a default level hat to exist
168 if value >= crit:
169 state = 2
170 elif value >= warn:
171 state = 1
173 if state:
174 infotext += ' (warn/crit at %s/%s)' % (warn, crit)
175 factor = 1e3 if unit == 'ms' else 1e6
176 perfdata = [('rtt', value / factor, warn / factor, crit / factor)]
178 yield state, infotext, perfdata
181 check_info['cisco_ip_sla'] = {
182 'parse_function': parse_cisco_ip_sla,
183 'inventory_function': inventory_cisco_ip_sla,
184 'check_function': check_cisco_ip_sla,
185 'service_description': 'Cisco IP SLA %s',
186 'group': 'cisco_ip_sla',
187 'default_levels_variable': 'cisco_ip_sla_default_levels',
188 'has_perfdata': True,
189 'snmp_scan_function': lambda oid: oid('.1.3.6.1.2.1.1.2.0') in [
190 '.1.3.6.1.4.1.9.1.2068',],
191 'snmp_info': [
193 '.1.3.6.1.4.1.9.9.42.1.2.2.1',
195 BINARY(2), # rttMonEchoAdminTargetAddress
196 BINARY(6), # rttMonEchoAdminSourceAddress
197 # only needed to determine the unit (ms/us)
198 37, # rttMonEchoAdminPrecision
201 '.1.3.6.1.4.1.9.9.42.1.2.1.1',
203 2, # rttMonCtrlAdminOwner
204 3, # rttMonCtrlAdminTag
205 4, # rttMonCtrlAdminRttType
206 5, # rttMonCtrlAdminThreshold
209 '.1.3.6.1.4.1.9.9.42.1.2.9.1',
211 10, # rttMonCtrlOperState
212 2, # rttMonCtrlOperDiagText
213 5, # rttMonCtrlOperConnectionLostOccurred
214 6, # rttMonCtrlOperTimeoutOccurred
215 7, # rttMonCtrlOperOverThresholdOccurred
218 '.1.3.6.1.4.1.9.9.42.1.2.10.1',
220 1, # rttMonLatestRttOperCompletionTime
221 2, # rttMonLatestRttOperSense