Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / genua_carp
blob27efb1a5befe27a89bc9444aa984bfe25bf03d99
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.2.9 = STRING: "carp0"
31 #.1.3.6.1.4.1.3137.2.1.2.1.2.10 = STRING: "carp1"
32 #.1.3.6.1.4.1.3137.2.1.2.1.4.9 = INTEGER: 2
33 #.1.3.6.1.4.1.3137.2.1.2.1.4.10 = INTEGER: 2
34 #.1.3.6.1.4.1.3137.2.1.2.1.7.9 = INTEGER: 2
35 #.1.3.6.1.4.1.3137.2.1.2.1.7.10 = INTEGER: 2
38 def inventory_genua_carp(info):
39 inventory = []
41 # remove empty elements due to two alternative enterprise ids in snmp_info
42 info = filter(None, info)
44 if info[0]:
45 for ifName, _ifLinkState, ifCarpState in info[0]:
46 if ifCarpState in ["0", "1", "2"]:
47 inventory.append((ifName, None))
48 return inventory
51 def genua_linkstate(st):
52 names = {
53 '0': 'unknown',
54 '1': 'down',
55 '2': 'up',
56 '3': 'hd',
57 '4': 'fd',
59 return names.get(st, st)
62 def genua_carpstate(st):
63 names = {
64 '0': 'init',
65 '1': 'backup',
66 '2': 'master',
68 return names.get(st, st)
71 def check_genua_carp(item, _no_params, info):
73 # remove empty elements due to two alternative enterprise ids in snmp_info
74 info = filter(None, info)
76 if not info[0]:
77 return (3, "Invalid Output from Agent")
78 state = 0
79 nodes = len(info)
80 masters = 0
81 output = ""
82 if nodes > 1:
83 prefix = "Cluster test: "
84 else:
85 prefix = "Node test: "
87 # Loop over all nodes, just one line if not a cluster
88 for line in info:
89 # Loop over interfaces on node
90 for ifName, ifLinkState, ifCarpState in line:
91 ifLinkStateStr = genua_linkstate(str(ifLinkState))
92 ifCarpStateStr = genua_carpstate(str(ifCarpState))
93 # is inventorized interface in state carp master ?
94 if ifName == item and ifCarpState == "2":
95 # is master
96 masters += 1
97 if masters == 1:
98 if nodes > 1:
99 output = "one "
100 output += "node in carp state %s with IfLinkState %s" \
101 % (ifCarpStateStr,ifLinkStateStr)
102 # first master
103 if ifLinkState == "2":
104 state = 0
105 elif ifLinkState == "1":
106 state = 2
107 elif ifLinkState in ["0", "3"]:
108 state = 1
109 else:
110 state = 3
111 else:
112 state = 2
113 output = "%d nodes in carp state %s on cluster with %d nodes" \
114 % (masters,ifCarpStateStr,nodes)
115 # look for non-masters, only interesting if no cluster
116 elif ifName == item and nodes == 1:
117 output = "node in carp state %s with IfLinkState %s" \
118 % (ifCarpStateStr,ifLinkStateStr)
119 # carp backup
120 if ifCarpState == "1" and ifLinkState == "1":
121 state = 0
122 else:
123 state = 1
125 # no masters found in cluster
126 if nodes > 1 and masters == 0:
127 state = 2
128 output = "No master found on cluster with %d nodes" % nodes
130 output = prefix + output
131 return (state, output)
134 check_info['genua_carp'] = {
135 "inventory_function": inventory_genua_carp,
136 "check_function": check_genua_carp,
137 "service_description": "Carp Interface %s",
138 "snmp_info": [
140 ".1.3.6.1.4.1.3137.2.1.2",
142 "1.2", # "ifName"
143 "1.4", # "ifLinkState"
144 "1.7", # "ifCarpState"
147 ".1.3.6.1.4.1.3717.2.1.2",
149 "1.2", # "ifName"
150 "1.4", # "ifLinkState"
151 "1.7", # "ifCarpState"
154 "snmp_scan_function": scan_genua,
155 "includes": ["genua.include"],