Refactored snapin server_time to new snapin API
[check_mk.git] / checks / genua_state_correlation
blob012355deb7eb2b57b5978e5b5058329afa5bf7ee
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
55 def genua_state_str(st):
56 names = {
57 '0' : 'init',
58 '1' : 'backup',
59 '2' : 'master',
61 return names.get(st, st)
63 def check_genua_state(item, _no_params, info):
65 # remove empty elements due to two alternative enterprise ids in snmp_info
66 info = filter(None, info)
67 if not info[0]:
68 return(3, "Invalid Output from Agent")
70 state = 0
71 carp_info = []
73 for ifIndex, ifName, ifType, ifLinkState, ifCarpState in info[0]:
74 if ifType == "6":
75 carp_info.append((ifIndex, ifName, ifType, ifLinkState, ifCarpState))
77 # critical if the carp interfaces dont have the same state
78 carp_states = [ 0, 0, 0 ]
79 for i, elem in enumerate(carp_info):
80 carp_states[int(elem[4])] += 1
81 if carp_info[0][4] != elem[4]:
82 state = 2
84 output = "Number of carp IFs in states "
85 for i in ('0', '1', '2'):
86 output += genua_state_str(i)
87 output += ":%d " % carp_states[int(i)]
89 return(state, output)
91 check_info['genua_state_correlation'] = {
92 "inventory_function" : inventory_genua_state,
93 "check_function" : check_genua_state,
94 "service_description": "Carp Correlation",
95 "snmp_info" : [( ".1.3.6.1.4.1.3717.2.1.2",[
96 "1.1", # "ifIndex"
97 "1.2", # "ifName"
98 "1.3", # "ifType"
99 "1.4", # "ifLinkState"
100 "1.7", # "ifCarpState"
102 ( ".1.3.6.1.4.1.3137.2.1.2",[
103 "1.1", # "ifIndex"
104 "1.2", # "ifName"
105 "1.3", # "ifType"
106 "1.4", # "ifLinkState"
107 "1.7", # "ifCarpState"
108 ])],
109 "snmp_scan_function" : lambda oid: "genuscreen" in oid(".1.3.6.1.2.1.1.1.0").lower()
110 #"snmp_scan_function" : lambda oid: oid(".1.3.6.1.4.1.3717.2.1.2.1.7") != None