Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / lgp_pdu_aux
blobd29e840c2d7bf7a3444f0f2843fdd5d0f2ab4d24
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 # Check has been developed using a Emerson Network Power Rack PDU Card
28 # Agent App Firmware Version 4.840.0
29 # Agent Boot Firmware Version 4.540.3
30 # FDM Version 1209
31 # GDD Version 45585
33 # Example info:
34 # [['10.1.1.1', '2'], ['10.1.2.1', '1'], ['10.1.3.1', '3'], ['10.1.3.2', '3'], ['15.1.1.1', 'SNSR: 1-1'], ['15.1.2.1', 'SNSR: 1-2'], ['15.1.3.1', 'SNSR: 1-3'], ['15.1.3.2', 'SNSR: 1-3'], ['20.1.1.1', 'RAD-LUNEPL-SEN7(80000000B080CF26)'], ['20.1.2.1', 'RAD-LUNEPL-SEN5(Rueckseite-oben)'], ['20.1.3.1', 'RAD-LUNEPL-SEN3(TuerRueckseite)'], ['20.1.3.2', 'RAD-LUNEPL-SEN1(TuerFront)'], ['25.1.1.1', ''], ['25.1.2.1', ''], ['25.1.3.1', ''], ['25.1.3.2', ''], ['30.1.1.1', ''], ['30.1.2.1', ''], ['30.1.3.1', ''], ['30.1.3.2', ''], ['35.1.1.1', '80000000B080CF26'], ['35.1.2.1', 'DD0000000DFAEA42'], ['35.1.3.1', 'EC00000013FBD820'], ['35.1.3.2', 'EC00000013FBD820'], ['40.1.2.1', '873'], ['50.1.2.1', '500'], ['55.1.2.1', '878'], ['60.1.2.1', '590'], ['65.1.2.1', '806'], ['70.1.2.1', '307'], ['75.1.2.1', '100'], ['80.1.2.1', '310'], ['85.1.2.1', '150'], ['90.1.2.1', '270'], ['95.1.1.1', '156'], ['100.1.1.1', '150'], ['105.1.1.1', '600'], ['110.1.1.1', '200'], ['115.1.1.1', '560'], ['120.1.3.1', '2'], ['120.1.3.2', '2'], ['125.1.3.1', '1'], ['125.1.3.2', '1']]
36 # Indexes in lgpPduAuxMeasTable are:
37 # 1. lgpPduEntryIndex
38 # 2. lgpPduAuxMeasSensorIndex
39 # 3. lgpPduAuxMeasSensorMeasurementIndex
41 # 10, # LIEBERT-GP-PDU-MIB::lgpPduAuxMeasType
42 # 15, # LIEBERT-GP-PDU-MIB::lgpPduAuxMeasSensorSysAssignLabel
43 # 20, # LIEBERT-GP-PDU-MIB::lgpPduAuxMeasUsrLabel
44 # 35, # LIEBERT-GP-PDU-MIB::lgpPduAuxMeasSensorSerialNum
45 # 70, # LIEBERT-GP-PDU-MIB::lgpPduAuxMeasTempDeg
46 # 75, # LIEBERT-GP-PDU-MIB::lgpPduAuxMeasTempThrshldUndrAlmDegC
47 # 80, # LIEBERT-GP-PDU-MIB::lgpPduAuxMeasTempThrshldOvrAlmDegC
48 # 85, # LIEBERT-GP-PDU-MIB::lgpPduAuxMeasTempThrshldUndrWarnDegC
49 # 90, # LIEBERT-GP-PDU-MIB::lgpPduAuxMeasTempThrshldOvrWarnDegC
50 # 95, # LIEBERT-GP-PDU-MIB::lgpPduAuxMeasHum
51 # 100, # LIEBERT-GP-PDU-MIB::lgpPduAuxMeasHumThrshldUndrAlm
52 # 105, # LIEBERT-GP-PDU-MIB::lgpPduAuxMeasHumThrshldOvrAlm
53 # 110, # LIEBERT-GP-PDU-MIB::lgpPduAuxMeasHumThrshldUndrWarn
54 # 115, # LIEBERT-GP-PDU-MIB::lgpPduAuxMeasHumThrshldOvrWarn
55 # 120, # LIEBERT-GP-PDU-MIB::lgpPduAuxMeasDrClosureState
56 # 125, # LIEBERT-GP-PDU-MIB::lgpPduAuxMeasDrClosureConfig
58 lgp_pdu_aux_types = {
59 '0': 'UNSPEC',
60 '1': 'TEMP',
61 '2': 'HUM',
62 '3': 'DOOR',
63 '4': 'CONTACT',
66 lgp_pdu_aux_states = [
67 'not-specified',
68 'open',
69 'closed',
72 _lgp_pdu_aux_fields = {
73 # Index, Type, Factor, ID
74 '10': (str, None, 'Type'),
75 '15': (str, None, 'SystemLabel'),
76 '20': (str, None, 'UserLabel'),
77 '35': (str, None, 'SerialNumber'),
78 '70': (savefloat, 0.1, 'Temp'),
79 '75': (savefloat, 0.1, 'TempLowCrit'),
80 '80': (savefloat, 0.1, 'TempHighCrit'),
81 '85': (savefloat, 0.1, 'TempLowWarn'),
82 '90': (savefloat, 0.1, 'TempHighWarn'),
83 '95': (savefloat, 0.1, 'Hum'),
84 '100': (savefloat, 0.1, 'HumLowCrit'),
85 '105': (savefloat, 0.1, 'HumHighCrit'),
86 '110': (savefloat, 0.1, 'HumLowWarn'),
87 '115': (savefloat, 0.1, 'HumHighWarn'),
88 '120': (saveint, None, 'DoorState'),
89 '125': (saveint, None, 'DoorConfig'),
93 def lgp_pdu_aux_fmt(info):
94 new_info = {}
95 for oid, value in info:
96 type_, id_ = oid.split('.', 1)
97 if not id_ in new_info:
98 new_info[id_] = {'TypeIndex': id_.split('.')[-1]}
99 # Skip not handled rows
100 if type_ in _lgp_pdu_aux_fields:
101 ty, factor, key = _lgp_pdu_aux_fields[type_]
103 if key == 'Type':
104 value = lgp_pdu_aux_types.get(value, 'UNHANDLED')
105 else:
106 if factor:
107 value = ty(value) * factor
108 else:
109 value = ty(value)
111 new_info[id_][key] = value
112 return new_info
115 def inventory_lgp_pdu_aux(info):
116 info = lgp_pdu_aux_fmt(info)
117 inv = []
118 for pdu in info.itervalues():
119 # Using SystemLabel as index. But it is not uniq in all cases.
120 # Adding the Type-Index to prevent problems
121 inv.append((pdu['Type'] + '-' + pdu['SystemLabel'] + '-' + pdu['TypeIndex'], None))
122 return inv
125 def check_lgp_pdu_aux(item, params, info):
126 info = lgp_pdu_aux_fmt(info)
127 for pdu in info.itervalues():
128 if item == pdu['Type'] + '-' + pdu['SystemLabel'] + '-' + pdu['TypeIndex']:
129 state = 0
130 output = []
131 perfdata = []
133 if pdu['UserLabel'] != '':
134 output.append('Label: %s (%s)' % (pdu['UserLabel'], pdu['SystemLabel']))
135 else:
136 output.append('Label: ' + pdu['SystemLabel'])
138 def handle_type(ty, label, uom, pdu=pdu):
139 state = 0
140 perfdata = (ty.lower(), pdu[ty],
141 '%0.2f:%0.2f' % (pdu[ty + 'LowWarn'], pdu[ty + 'HighWarn']),
142 '%0.2f:%0.2f' % (pdu[ty + 'LowCrit'], pdu[ty + 'HighCrit']))
143 s_out = ''
144 if pdu[ty] >= pdu[ty + 'HighCrit']:
145 state = 2
146 s_out = ' >= %0.2f (!!)' % pdu[ty + 'HighCrit']
147 elif pdu[ty] <= pdu[ty + 'LowCrit']:
148 state = 2
149 s_out = ' <= %0.2f (!!)' % pdu[ty + 'LowCrit']
150 elif pdu[ty] >= pdu[ty + 'HighWarn']:
151 state = 1
152 s_out = ' >= %0.2f (!)' % pdu[ty + 'HighWarn']
153 elif pdu[ty] <= pdu[ty + 'LowWarn']:
154 state = 1
155 s_out = ' <= %0.2f (!)' % pdu[ty + 'LowWarn']
157 return state, '%s: %0.2f%s%s' % (label, pdu[ty], uom, s_out), perfdata
159 if pdu['Type'] == 'TEMP':
160 state, out, perf = handle_type('Temp', 'Temperature', 'C')
161 output.append(out)
162 perfdata.append(perf)
164 elif pdu['Type'] == 'HUM':
165 state, out, perf = handle_type('Hum', 'Humidity', '%')
166 output.append(out)
167 perfdata.append(perf)
169 elif pdu['Type'] == 'DOOR':
170 # DoorConfig: 1 -> open, 0 -> disabled
171 if pdu['DoorConfig'] == 1 and lgp_pdu_aux_states[pdu['DoorState']] == 'open':
172 state = 2
173 output.append('Door is %s (!!)' % lgp_pdu_aux_states[pdu['DoorState']])
174 else:
175 output.append('Door is %s' % lgp_pdu_aux_states[pdu['DoorState']])
177 return (state, ', '.join(output), perfdata)
179 return (3, 'Could not find given PDU.')
182 check_info['lgp_pdu_aux'] = (check_lgp_pdu_aux, 'Liebert PDU AUX %s', 1, inventory_lgp_pdu_aux)
184 snmp_info['lgp_pdu_aux'] = (
185 '.1.3.6.1.4.1.476.1.42.3.8.60.15',
187 OID_END,
188 '1', # LIEBERT-GP-PDU-MIB::lgpPduAuxMeasTable
191 snmp_scan_functions['lgp_pdu_aux'] = lambda oid: oid('.1.3.6.1.2.1.1.2.0') == \
192 '.1.3.6.1.4.1.476.1.42'
194 #check_info["lgp_pdu_aux"] = {
195 # "check_function" : check_lgp_pdu_aux,
196 # "inventory_function" : inventory_lgp_pdu_aux,
197 # "service_description" : "Liebert PDU AUX %s",
198 # "has_perfdata" : True,
199 # "snmp_scan_function" : lambda oid: oid(".1.3.6.1.2.1.1.2.0") == \
200 # ".1.3.6.1.4.1.476.1.42"