Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / f5_bigip_pool
blob519da8a763c4f616119541a5928db7f83d1b4ed9
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 # Agent / MIB output
28 # see: 1.3.6.1.4.1.3375.2.2.5.1.2.1
29 # F5-BIGIP-LOCAL-MIB::ltmPoolName. 8.80.111.111.108.asci_encoded_str = Pool_NMA
30 # F5-BIGIP-LOCAL-MIB::ltmPoolMemberCnt. 8.80.111.111.108.95.78.77.65 = 2
31 # F5-BIGIP-LOCAL-MIB::ltmPoolActiveMemberCnt. 8.80.111.111.108.95.78.77.65 = 0
33 # warn, crit numbers of pool members
34 f5_bigip_pool_default_levels = (2, 1)
37 def parse_f5_bigip_pool(info):
38 parsed = {}
39 processed_member_info = False
40 for block in info:
41 if not block:
42 continue
44 # Member information
45 if len(block[0]) == 3 and processed_member_info:
46 break
48 if len(block[0]) == 3:
49 for line in block:
50 parsed.setdefault(line[0], {"act_members": 0, "def_members": 0, "down_info": []})
51 parsed[line[0]]["act_members"] += int(line[1])
52 parsed[line[0]]["def_members"] += int(line[2])
53 processed_member_info = True
55 # Status information
56 elif len(block[0]) == 6:
57 for key, val in parsed.iteritems():
58 for line in block:
59 if key == line[0]:
60 val["down_info"].append(line)
61 return parsed
64 def inventory_f5_bigip_pool(parsed):
65 # inventorize all pools and their member count
66 for item in parsed.keys():
67 if item != "":
68 yield item, "f5_bigip_pool_default_levels"
71 def f5_bigip_pool_get_down_members(down_info):
72 downs = []
73 for line in down_info:
74 if (line[2] != '4' or line[3] != '4' or line[4] in ('2', '3', '4', '5')):
75 if re.match(r"\/\S*\/\S*", line[5]):
76 host = line[5].split("/")[2]
77 else:
78 host = line[5]
79 downs.append(host + ":" + line[1])
80 return downs
83 def check_f5_bigip_pool(item, params, parsed):
84 warn, crit = params
86 pool_info = parsed.get(item)
87 if not pool_info:
88 return
90 pool_act_members = pool_info["act_members"]
91 pool_def_members = pool_info["def_members"]
92 message = "%d of %d members are up" % (pool_act_members, pool_def_members)
93 state = 0
94 if pool_act_members == pool_def_members or pool_act_members >= warn:
95 state = 0
96 elif pool_act_members < crit:
97 state = 2
98 message += " (warn/crit: %s/%s)" % (warn, crit)
99 elif pool_act_members < warn:
100 state = 1
101 message += " (warn/crit: %s/%s)" % (warn, crit)
103 if pool_act_members < pool_def_members:
104 downs = f5_bigip_pool_get_down_members(pool_info["down_info"])
105 if downs:
106 message += ", down/disabled nodes: %s" % ", ".join(downs)
107 return state, message
109 check_info["f5_bigip_pool"] = {
110 'parse_function' : parse_f5_bigip_pool,
111 'check_function' : check_f5_bigip_pool,
112 'group' : 'f5_pools',
113 'inventory_function' : inventory_f5_bigip_pool,
114 'service_description' : 'Load Balancing Pool %s',
115 'snmp_info' : [
116 ('.1.3.6.1.4.1.3375.2.2.5.1.2.1', [
117 1, # ltmPoolEntry
118 8, # ltmPoolActiveMemberCnt
119 23, # ltmPoolMemberCnt
121 ('.1.3.6.1.4.1.3375.2.2.5.3.2.1', [
122 1, # ltmPoolMemberPoolName
123 4, # ltmPoolMemberPort
124 10, # ltmPoolMemberMonitorState
125 11, # ltmPoolMemberMonitorStatus
126 13, # ltmPoolMemberSessionStatus
127 19, # ltmPoolMemberNodeName
130 'snmp_scan_function':
131 lambda oid: '.1.3.6.1.4.1.3375.2' in oid(".1.3.6.1.2.1.1.2.0") \
132 and "big-ip" in oid(".1.3.6.1.4.1.3375.2.1.4.1.0").lower(),