Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / cisco_stack
blob82e7db6081381cddd14f719d3b2adfd99b33f819
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2018 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 factory_settings["cisco_stack"] = {
28 "waiting": 0,
29 "progressing": 0,
30 "added": 0,
31 "ready": 0,
32 "sdmMismatch": 1,
33 "verMismatch": 1,
34 "featureMismatch": 1,
35 "newMasterInit": 0,
36 "provisioned": 0,
37 "invalid": 2,
38 "removed": 2,
42 def parse_cisco_stack(info):
44 switch_state_names = {
45 "1": "waiting",
46 "2": "progressing",
47 "3": "added",
48 "4": "ready",
49 "5": "sdmMismatch",
50 "6": "verMismatch",
51 "7": "featureMismatch",
52 "8": "newMasterInit",
53 "9": "provisioned",
54 "10": "invalid",
55 "11": "removed",
58 switch_role_names = {
59 "1": "master",
60 "2": "member",
61 "3": "notMember",
64 parsed = {}
65 for line in info:
66 parsed[line[0]] = {
67 "switch_role": switch_role_names.get(line[1], "unknown"),
68 "switch_state": switch_state_names.get(line[2], "unknown"),
70 return parsed
73 def inventory_cisco_stack(parsed):
74 for item in parsed:
75 yield item, {}
78 def check_cisco_stack(item, params, parsed):
80 switch_state_descriptions = {
81 "waiting": "Waiting for other switches to come online",
82 "progressing": "Master election or mismatch checks in progress",
83 "added": "Added to stack",
84 "ready": "Ready",
85 "sdmMismatch": "SDM template mismatch",
86 "verMismatch": "OS version mismatch",
87 "featureMismatch": "Configured feature mismatch",
88 "newMasterInit": "Waiting for new master initialization",
89 "provisioned": "Not an active member of the stack",
90 "invalid": "State machine in invalid state",
91 "removed": "Removed from stack",
94 data = parsed.get(item)
95 if data is None:
96 return
98 switch_state = data["switch_state"]
99 switch_role = data["switch_role"]
101 status = params.get(data["switch_state"], 3)
102 infotext = "Switch state: %s (%s), switch role: %s" % (switch_state_descriptions.get(
103 switch_state, "Unknown"), switch_state, switch_role)
104 return status, infotext
107 check_info['cisco_stack'] = {
108 'default_levels_variable': 'cisco_stack',
109 'parse_function': parse_cisco_stack,
110 'inventory_function': inventory_cisco_stack,
111 'check_function': check_cisco_stack,
112 'service_description': 'Switch stack status %s',
113 'snmp_info': (
114 '.1.3.6.1.4.1.9.9.500.1.2.1.1',
116 "1", # cswSwitchNumCurrent
117 "3", # cswSwitchRole
118 "6", # cswSwitchState
120 'snmp_scan_function':
121 lambda oid: (oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.9.1.1208") or oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.9.1.1745")),
122 'group': 'cisco_stack',