Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / hivemanager_ng_devices
blob8c1bd2381f6bbb37160589bd47c5a75e8425c881
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2017 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_ng_devices:sep(124)>>>
28 #osVersion::8.1.2.1|ip::10.8.92.100|hostName::Host-1|lastUpdated::2017-11-08T10:01:43.674Z|activeClients::0|connected::True|serialId::00000000000001
29 #osVersion::8.1.2.1|ip::10.8.92.130|hostName::Host-2|lastUpdated::2017-11-08T10:01:44.056Z|activeClients::14|connected::True|serialId::00000000000002
30 #osVersion::8.1.2.1|ip::10.8.92.135|hostName::Host-3|lastUpdated::2017-11-08T10:01:44.153Z|activeClients::12|connected::True|serialId::00000000000003
31 #osVersion::8.1.2.1|ip::10.8.92.140|hostName::Host-4|lastUpdated::2017-11-08T10:01:44.361Z|activeClients::10|connected::True|serialId::00000000000004
32 #osVersion::8.1.2.1|ip::10.8.92.145|hostName::Host-5|lastUpdated::2017-11-08T10:01:44.362Z|activeClients::5|connected::True|serialId::00000000000005
33 #osVersion::8.1.2.1|ip::10.8.92.150|hostName::Host-6|lastUpdated::2017-11-08T10:01:44.638Z|activeClients::13|connected::True|serialId::00000000000006
34 #osVersion::8.1.2.1|ip::10.8.92.155|hostName::Host-7|lastUpdated::2017-11-08T10:01:44.667Z|activeClients::14|connected::True|serialId::00000000000007
35 #osVersion::8.1.2.1|ip::10.8.92.160|hostName::Host-8|lastUpdated::2017-11-08T10:01:44.690Z|activeClients::10|connected::True|serialId::00000000000008
36 #osVersion::6.5.8.1|ip::10.8.95.100|hostName::Host-9|lastUpdated::2017-11-07T22:50:20.425Z|activeClients::9|connected::True|serialId::12345678912345
38 factory_settings['hivemanger_ng_devices'] = {
39 'max_clients': (25, 50),
43 def parse_hivemanager_ng_devices(info):
44 parsed = {}
45 for device in info:
46 data = dict(element.split('::') for element in device)
48 data['connected'] = (data['connected'] == 'True')
49 data['activeClients'] = int(data['activeClients'])
51 host = data.pop('hostName')
52 parsed[host] = data
54 return parsed
57 def inventory_hivemanager_ng_devices(parsed):
58 for host in parsed:
59 yield host, {}
62 def check_hivemanager_ng_devices(item, params, parsed):
63 device = parsed.get(item)
64 if not device:
65 yield 2, 'No data for device.'
67 status, connected = 0, device['connected']
68 if connected != True:
69 status = 2
70 yield status, 'Connected: %s' % connected
72 status, clients = 0, device['activeClients']
73 infotext = 'active clients: %s' % clients
74 warn, crit = params['max_clients']
75 if clients >= crit:
76 status = 2
77 infotext += ' (warn/crit at %s/%s)' % (warn, crit)
78 elif clients >= warn:
79 status = 1
80 infotext += ' (warn/crit at %s/%s)' % (warn, crit)
81 perfdata = [('connections', clients, warn, crit)]
82 yield status, infotext, perfdata
84 informational = [
85 ('ip', 'IP address'),
86 ('serialId', 'serial ID'),
87 ('osVersion', 'OS version'),
88 ('lastUpdated', 'last updated'),
90 for (key, text) in informational:
91 yield 0, "%s: %s" % (text, device[key])
94 check_info["hivemanager_ng_devices"] = {
95 "parse_function": parse_hivemanager_ng_devices,
96 "check_function": check_hivemanager_ng_devices,
97 "inventory_function": inventory_hivemanager_ng_devices,
98 "service_description": "Client %s",
99 "default_levels_variable": "hivemanger_ng_devices",
100 "group": "hivemanager_ng_devices",
101 "has_perfdata": True,