Refactoring: Changed remaining check parameters starting with an 's' to the new rules...
[check_mk.git] / checks / ibm_svc_host
blob404087317652385d577381528722b06140e23856
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 # Example output from agent:
28 # <<<ibm_svc_host:sep(58)>>>
29 # 0:h_esx01:2:4:degraded
30 # 1:host206:2:2:online
31 # 2:host105:2:2:online
32 # 3:host106:2:2:online
35 def inventory_ibm_svc_host(info):
36 return [(None, {})]
39 def check_ibm_svc_host(item, params, info):
40 degraded = 0
41 offline = 0
42 active = 0
43 inactive = 0
44 other = 0
46 if params is None:
47 # Old inventory rule until version 1.2.7
48 # params were None instead of empty dictionary
49 params = {'always_ok': False}
51 for line in info:
52 if line[4] == 'degraded':
53 degraded += 1
54 elif line[4] == 'offline':
55 offline += 1
56 elif line[4] == 'active' or line[4] == 'online':
57 active += 1
58 elif line[4] == 'inactive':
59 inactive += 1
60 else:
61 other += 1
63 if 'always_ok' in params:
64 # Old configuration rule
65 # This was used with only one parameter always_ok until version 1.2.7
66 perfdata = [
67 ("active", active),
68 ("inactive", inactive),
69 ("degraded", degraded),
70 ("offline", offline),
71 ("other", other),
73 yield 0, "%s active, %s inactive" % (active, inactive), perfdata
75 if degraded > 0:
76 yield (not params['always_ok'] and 1 or 0), "%s degraded" % degraded
77 if offline > 0:
78 yield (not params['always_ok'] and 2 or 0), "%s offline" % offline
79 if other > 0:
80 yield (not params['always_ok'] and 1 or 0), "%s in an unidentified state" % other
81 else:
82 warn, crit = params.get('active_hosts', (None, None))
84 if crit is not None and active <= crit:
85 yield 2, "%s active" % active
86 elif warn is not None and active <= warn:
87 yield 1, "%s active" % active
88 else:
89 yield 0, "%s active" % active
91 for ident, value in [
92 ('inactive', inactive),
93 ('degraded', degraded),
94 ('offline', offline),
95 ('other', other),
97 warn, crit = params.get(ident + '_hosts', (None, None))
99 if crit is not None and value >= crit:
100 state = 2
101 if warn is not None and value >= warn:
102 state = 1
103 else:
104 state = 0
105 yield state, "%s %s" % (value, ident), [(ident, value, warn, crit)]
108 check_info["ibm_svc_host"] = {
109 "check_function": check_ibm_svc_host,
110 "inventory_function": inventory_ibm_svc_host,
111 "service_description": "Hosts",
112 "has_perfdata": True,
113 "group": "ibm_svc_host",