Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / hivemanager_devices
blob0bf371d65082c5c77838832532b891de34986f51
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2013 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 #<<<hivemanager_devices:sep(124)>>>
28 #BBSA-WIFI-LSN-Rhod-F4-1|8|Cleared|True|21 Days, 17 Hrs 43 Mins 43 Secs
29 #BBSA-WIFI-LSN-Rhod-F4-2|8|Cleared|True|21 Days, 17 Hrs 43 Mins 43 Secs
30 #BBSA-WIFI-LSN-Hald-F4-1|4|Cleared|True|2 Days, 0 Hrs 30 Mins 41 Secs
31 #BBSA-WIFI-LSN-Hald-F2-1|24|Cleared|True|57 Days, 3 Hrs 24 Mins 22 Secs
33 factory_settings['hivemanger_devices'] = {
34 'alert_on_loss': True,
35 'max_clients': (25, 50),
36 'crit_states': ['Critical'],
37 'warn_states': ['Maybe', 'Major', 'Minor'],
41 def inventory_hivemanager_devices(info):
42 for line in info:
43 infos = dict([x.split('::') for x in line])
44 yield infos['hostName'], {}
47 def check_hivemanager_devices(item, params, info):
48 for line in info:
49 infos = dict([x.split('::') for x in line])
50 if infos['hostName'] == item:
51 # Check for Alarm State
52 alarmstate = "Alarm state: " + infos['alarm']
53 if infos['alarm'] in params['warn_states']:
54 yield 1, alarmstate
55 elif infos['alarm'] in params['crit_states']:
56 yield 2, alarmstate
58 # If activated, Check for lost connection of client
59 if params['alert_on_loss']:
60 if infos['connection'] == 'False':
61 yield 2, "Connection lost"
63 # The number of clients
64 number_of_clients = int(infos['clients'])
65 warn, crit = params['max_clients']
67 perfdata = [('client_count', number_of_clients, warn, crit)]
68 infotext = "Clients: %s" % number_of_clients
69 levels = ' Warn/Crit at %s/%s' % (warn, crit)
71 if number_of_clients >= crit:
72 yield 2, infotext + levels, perfdata
73 elif number_of_clients >= warn:
74 yield 1, infotext + levels, perfdata
75 else:
76 yield 0, infotext, perfdata
78 # Uptime
79 state = 0
80 warn, crit = 0, 0
81 infotext = ''
82 uptime_secs = 0
83 if infos['upTime'] != 'down':
84 uptime_tokens = map(int, infos['upTime'].split()[-2::-2])
85 token_multiplier = [1, 60, 3600, 86400, 31536000]
86 for idx, entry in enumerate(uptime_tokens):
87 uptime_secs += token_multiplier[idx] * entry
88 infotext = "Uptime: %s" % get_age_human_readable(uptime_secs)
89 if 'max_uptime' in params:
90 warn, crit = params['max_uptime']
91 if uptime_secs >= crit:
92 state = 2
93 elif uptime_secs >= warn:
94 state = 1
95 yield state, infotext, [('uptime', uptime_secs, warn, crit)]
97 # Additional Information
98 additional_informations = [
99 'eth0LLDPPort', 'eth0LLDPSysName', 'hive', 'hiveOS', 'hwmodel', 'serialNumber',
100 'nodeId', 'location', 'networkPolicy'
102 yield 0, ", ".join(["%s: %s" % (x, y) for x, y in infos.items() \
103 if x in additional_informations and y != "-"])
106 check_info["hivemanager_devices"] = {
107 "check_function": check_hivemanager_devices,
108 "inventory_function": inventory_hivemanager_devices,
109 "service_description": "Client %s",
110 "default_levels_variable": "hivemanger_devices",
111 "group": "hivemanager_devices",
112 "has_perfdata": True,