Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / genua_state_correlation
blobbaf9d5ae3fcf504813c30d4a253e4fa927b83610
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 Agent Output:
28 # GENUA-MIB:
30 # .1.3.6.1.4.1.3137.2.1.2.1.1.9 = INTEGER: 9
31 # .1.3.6.1.4.1.3137.2.1.2.1.1.10 = INTEGER: 10
32 # .1.3.6.1.4.1.3137.2.1.2.1.2.9 = STRING: "carp0"
33 # .1.3.6.1.4.1.3137.2.1.2.1.2.10 = STRING: "carp1"
34 # .1.3.6.1.4.1.3137.2.1.2.1.3.9 = INTEGER: 5
35 # .1.3.6.1.4.1.3137.2.1.2.1.3.10 = INTEGER: 5
36 # .1.3.6.1.4.1.3137.2.1.2.1.4.9 = INTEGER: 2
37 # .1.3.6.1.4.1.3137.2.1.2.1.4.10 = INTEGER: 2
38 # .1.3.6.1.4.1.3137.2.1.2.1.7.9 = INTEGER: 2
39 # .1.3.6.1.4.1.3137.2.1.2.1.7.10 = INTEGER: 2
42 def inventory_genua_state(info):
43 # remove empty elements due to two alternative enterprise ids in snmp_info
44 info = filter(None, info)
45 if info[0]:
46 numifs = 0
47 for _ifIndex, _ifName, _ifType, _ifLinkState, ifCarpState in info[0]:
48 if ifCarpState in ["0", "1", "2"]:
49 numifs += 1
50 # inventorize only if we find at least two carp interfaces
51 if numifs > 1:
52 return [(None, None)]
53 return None
56 def genua_state_str(st):
57 names = {
58 '0': 'init',
59 '1': 'backup',
60 '2': 'master',
62 return names.get(st, st)
65 def check_genua_state(item, _no_params, info):
67 # remove empty elements due to two alternative enterprise ids in snmp_info
68 info = filter(None, info)
69 if not info[0]:
70 return (3, "Invalid Output from Agent")
72 state = 0
73 carp_info = []
75 for ifIndex, ifName, ifType, ifLinkState, ifCarpState in info[0]:
76 if ifType == "6":
77 carp_info.append((ifIndex, ifName, ifType, ifLinkState, ifCarpState))
79 # critical if the carp interfaces dont have the same state
80 carp_states = [0, 0, 0]
81 for i, elem in enumerate(carp_info):
82 carp_states[int(elem[4])] += 1
83 if carp_info[0][4] != elem[4]:
84 state = 2
86 output = "Number of carp IFs in states "
87 for i in ('0', '1', '2'):
88 output += genua_state_str(i)
89 output += ":%d " % carp_states[int(i)]
91 return (state, output)
94 check_info['genua_state_correlation'] = {
95 "inventory_function": inventory_genua_state,
96 "check_function": check_genua_state,
97 "service_description": "Carp Correlation",
98 "snmp_info": [
100 ".1.3.6.1.4.1.3717.2.1.2",
102 "1.1", # "ifIndex"
103 "1.2", # "ifName"
104 "1.3", # "ifType"
105 "1.4", # "ifLinkState"
106 "1.7", # "ifCarpState"
109 ".1.3.6.1.4.1.3137.2.1.2",
111 "1.1", # "ifIndex"
112 "1.2", # "ifName"
113 "1.3", # "ifType"
114 "1.4", # "ifLinkState"
115 "1.7", # "ifCarpState"
118 "snmp_scan_function": scan_genua,
119 "includes": ["genua.include"],