Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / fritz
blobbf53e790dc2f8a77b72bac3c7766338ca6ef2cdc
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 parse_fritz(info):
29 return {l[0]: ' '.join(l[1:]) for l in info if len(l) > 1}
32 check_info["fritz"] = {
33 'parse_function': parse_fritz,
38 # Internet connection
40 def inventory_fritz_conn(parsed):
41 conn_stat = parsed.get('NewConnectionStatus')
42 if (conn_stat and conn_stat != 'Unconfigured' and 'NewExternalIPAddress' in parsed):
43 return [(None, {})]
46 def check_fritz_conn(_unused, _no_params, parsed):
48 conn_stat = parsed.get('NewConnectionStatus')
49 yield 0, 'Status: %s' % conn_stat
51 if conn_stat not in ('Connected', 'Connecting', 'Disconnected', 'Unconfigured'):
52 yield 3, 'unhandled connection status'
54 if conn_stat == 'Connected':
55 yield 0, 'WAN IP Address: %s' % parsed.get('NewExternalIPAddress')
56 else:
57 yield 1, ''
59 last_err = parsed.get('NewLastConnectionError')
60 if last_err and last_err != 'ERROR_NONE':
61 yield 0, 'Last Error: %s' % last_err
63 uptime = parsed.get('NewUptime')
64 if uptime:
65 conn_time = check_uptime_seconds({}, float(uptime))
66 yield 0, str(conn_time[1]), conn_time[2]
69 check_info['fritz.conn'] = {
70 "inventory_function": inventory_fritz_conn,
71 "check_function": check_fritz_conn,
72 "service_description": "Connection",
73 "includes": ["uptime.include"],
74 "has_perfdata": True,
79 # Config
81 def inventory_fritz_config(parsed):
82 if 'NewDNSServer1' in parsed:
83 return [(None, {})]
86 def check_fritz_config(_unused, _no_params, parsed):
88 label_val = [
89 ('Auto Disconnect Time', parsed.get('NewAutoDisconnectTime', '0.0.0.0')),
90 ('DNS-Server1', parsed.get('NewDNSServer1', '0.0.0.0')),
91 ('DNS-Server2', parsed.get('NewDNSServer2', '0.0.0.0')),
92 ('VoIP-DNS-Server1', parsed.get('NewVoipDNSServer1', '0.0.0.0')),
93 ('VoIP-DNS-Server2', parsed.get('NewVoipDNSServer2', '0.0.0.0')),
94 ('uPnP Config Enabled', parsed.get('NewUpnpControlEnabled', '0.0.0.0')),
97 output = ['%s: %s' % (l, v) for l, v in label_val if v != '0.0.0.0']
99 if output:
100 return 0, ', '.join(output)
101 return 3, 'Configuration info is missing'
104 check_info['fritz.config'] = {
105 "inventory_function": inventory_fritz_config,
106 "check_function": check_fritz_config,
107 "service_description": "Configuration",
112 # WAN Interface Check
114 def fritz_wan_if_to_if64(parsed):
115 link_stat = parsed.get('NewLinkStatus')
116 if not link_stat:
117 oper_status = None
118 elif link_stat == 'Up':
119 oper_status = '1'
120 else:
121 oper_status = '2'
123 return [
124 # ifIndex, ifDescr, ifType, ifSpeed, ifOperStatus,
125 # ifInOctets, inucast, inmcast, inbcast, ifInDiscards, ifInErrors,
126 # ifOutOctets, outucast, outmcast, outbcast, ifOutDiscards, ifOutErrors,
127 # ifOutQLen, ifAlias, ifPhysAddress
128 ('0', 'WAN', '6', parsed.get('NewLayer1DownstreamMaxBitRate'), oper_status,
129 parsed.get('NewTotalBytesReceived'), '0', '0', '0', '0', '0',
130 parsed.get('NewTotalBytesSent'), '0', '0', '0', '0', '0', '0', 'WAN', '')
134 def inventory_fritz_wan_if(parsed):
135 return inventory_if_common(fritz_wan_if_to_if64(parsed))
138 def check_fritz_wan_if(item, params, parsed):
139 if not parsed:
140 return 3, 'Interface info is missing'
142 if_common_params = {
143 'assumed_speed_in': int(parsed['NewLayer1DownstreamMaxBitRate']),
144 'assumed_speed_out': int(parsed['NewLayer1UpstreamMaxBitRate']),
145 'unit': 'bit',
147 if_common_params.update(params)
149 return check_if_common(item, if_common_params, fritz_wan_if_to_if64(parsed))
152 check_info["fritz.wan_if"] = {
153 'check_function': check_fritz_wan_if,
154 'inventory_function': inventory_fritz_wan_if,
155 'service_description': 'Interface %s',
156 'has_perfdata': True,
157 'group': 'if',
158 'default_levels_variable': 'if_default_levels',
159 'includes': ['if.include'],
164 # Link
166 def inventory_fritz_link(parsed):
167 if 'NewLinkStatus' in parsed and 'NewPhysicalLinkStatus' in parsed:
168 return [(None, {})]
171 def check_fritz_link(_no_item, _no_params, parsed):
173 label_val = [
174 ('Link Status', parsed.get('NewLinkStatus')),
175 ('Physical Link Status', parsed.get('NewPhysicalLinkStatus')),
176 ('Link Type', parsed.get('NewLinkType')),
177 ('WAN Access Type', parsed.get('NewWANAccessType')),
180 output = ['%s: %s' % (l, v) for l, v in label_val if v]
182 if output:
183 return 0, ', '.join(output)
184 return 3, 'Link info is missing'
187 check_info["fritz.link"] = {
188 'check_function': check_fritz_link,
189 'inventory_function': inventory_fritz_link,
190 'service_description': 'Link Info',