Cleanup config.nodes_of
[check_mk.git] / checks / megaraid_pdisks
blob4dc42f0b8f8519642724b23a0ca8b706af75cb86
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 output from agent:
28 # Slot Number: 0
29 # Device Id: 4
30 # Raw Size: 140014MB [0x11177330 Sectors]
31 # Firmware state: Unconfigured(good)
32 # Inquiry Data: FUJITSU MBB2147RC 5204BS04P9104BV5
33 # Slot Number: 1
34 # Device Id: 5
35 # Raw Size: 140014MB [0x11177330 Sectors]
36 # Firmware state: Unconfigured(good)
37 # Inquiry Data: FUJITSU MBB2147RC 5204BS04P9104BSC
39 # The agent provides some new information since 1.1.9.
40 # The dev2enc infos are sent from the agent to have the
41 # real enclosure numbers instead of the device ids which
42 # seem to be generated somehow.
44 # dev2enc Enclosure 0 Device ID 6
45 # dev2enc Enclosure 1 Device ID 252
47 # On new inventory runs the enclosure number is used as
48 # index and item part.
49 megaraid_pdisks_legacy_mode = False
50 # This makes service descriptions backward compatible to match
51 # inventory made by older versions that didn't support multiple
52 # controllers
53 megaraid_pdisks_adapterstr = ['e', 'f', 'g', 'h', 'i', 'j', 'k', 'l']
56 def megaraid_pdisks_parse(info):
57 adapters = {0: {}}
58 current_adapter = adapters[0]
59 return_var = []
60 adapter = 0
61 enclosure_devid = -181
62 for line in info:
63 if line[0] == 'adapter':
64 current_adapter = {}
65 adapters[int(line[1])] = current_adapter
66 elif line[0] == 'dev2enc':
67 if line[2].isdigit():
68 current_adapter[int(line[5])] = int(line[2])
69 elif line[0] == 'Adapter' and len(line) == 2:
70 current_adapter = adapters[int(line[1][1:])] # Raute weglassen
71 adapter = int(line[1][1:])
72 elif line[0] == "Enclosure" and line[1] == "Device":
73 try:
74 enclosure_devid = int(line[-1])
75 # this should fix inventory problems.
76 adapters[adapter][enclosure_devid] = enclosure_devid
78 except: # no enclosure device
79 enclosure_devid = 0
80 adapters[adapter][0] = 0
81 elif line[0] == "Enclosure" and line[1] == "Number:":
82 for devid, number in current_adapter.items():
83 if number == int(line[-1]):
84 enclosure_devid = devid
85 break
87 elif line[0] == "Slot":
88 slot = int(line[-1])
89 elif line[0] == "Firmware" and line[1] == "state:":
90 state = line[2].rstrip(',')
91 elif line[0] == "Inquiry" and line[1] == "Data:":
92 name = " ".join(line[2:])
93 #Adapter, Enclosure, Encolsure Device ID, Slot, State, Name
94 return_var.append(
95 (megaraid_pdisks_adapterstr[adapter], adapters[adapter][enclosure_devid],
96 enclosure_devid, slot, state, name))
98 return return_var
101 def inventory_megaraid_pdisks(info):
102 info = megaraid_pdisks_parse(info)
103 inventory = []
104 for adapter, enclosure, _enc_dev_id, slot, _state, _name in info:
105 inventory.append(("%s%s/%s" % (adapter, enclosure, slot), None))
106 return inventory
109 megaraid_pdisks_states = {
110 'Online': 0,
111 'Hotspare': 0,
112 'Unconfigured(good)': 0,
113 'JBOD': 0,
114 'Failed': 2,
115 'Unconfigured(bad)': 1,
116 'Copyback': 1,
117 'Rebuild': 1,
121 def check_megaraid_pdisks(item, _no_params, info):
122 info = megaraid_pdisks_parse(info)
123 for adapter, enclosure, _enc_dev_id, slot, state, name in info:
124 if "%s%s/%s" % (adapter, enclosure, slot) == item:
125 return megaraid_pdisks_states.get(state, 3), "%s (%s)" % (state, name)
126 return 3, "No disk in encl/slot %s found" % item
129 check_info["megaraid_pdisks"] = {
130 'check_function': check_megaraid_pdisks,
131 'inventory_function': inventory_megaraid_pdisks,
132 'service_description': 'RAID PDisk Adapt/Enc/Sl %s',
133 'has_perfdata': False,