-
Notifications
You must be signed in to change notification settings - Fork 3
/
check_dell_s_series.py
283 lines (256 loc) · 8.15 KB
/
check_dell_s_series.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Nagios check plugin for Dell | EMC² S-series switches, running OS10 firmware
This check retrieve operational values from Dell specific SNMP MIBs :
- hardware health
- power unit status
- fans status
- temperatures
For switching specific metrics (interface stats, etc) it uses standard NET-SNMP MIBs, so
you can use generic SNMP check as the excellent check_nwc_health from Consol Labs:
https://labs.consol.de/nagios/check_nwc_health/
2018-09-04 - Eric Belhomme <[email protected]>
"""
from __future__ import print_function
import sys
import optparse
import re
import netsnmp
__author__ = 'Eric Belhomme'
__contact__ = '[email protected]'
__version__ = '0.1'
__license__ = 'MIT'
nagiosStatus = {
'0': 'OK',
'1': 'WARNING',
'2': 'CRITICAL',
'3': 'UNKNOWN'
}
Os10CmnOperStatus = {
'1': 'up',
'2': 'down',
'3': 'testing',
'4': 'unknown',
'5': 'dormant',
'6': 'notPresent',
'7': 'lowerLayerDown',
'8': 'failed'
}
Os10ChassisDefType = {
'1': 's6000on',
'2': 's4048on',
'3': 's4048Ton',
'4': 's3048on',
'5': 's6010on',
'6': 's4148Fon',
'7': 's4128Fon',
'8': 's4148Ton',
'9': 's4128Ton',
'10': 's4148FEon',
'11': 's4148Uon',
'12': 's4200on',
'13': 'mx5108Non',
'14': 'mx9116Non',
'15': 's5148Fon',
'16': 'z9100on',
'17': 's4248FBon',
'18': 's4248FBLon',
'19': 's4112Fon',
'20': 's4112Ton',
'21': 'z9264Fon',
'9999': 'unknown'
}
Os10CardOperStatus = {
'1': 'ready',
'2': 'cardMisMatch',
'3': 'cardProblem',
'4': 'diagMode',
'5': 'cardAbsent',
'6': 'offline'
}
def getSnmpOperStatus(snmpOID, textval, warn, crit):
message = []
retCode = 0
countfail =0
var = netsnmp.VarList(netsnmp.Varbind(snmpOID))
vals = snmpSession.walk(var)
if vals:
index = 1
for item in vals:
if int(item) == 4:
retCode = 3
# message.append(textval + ' number '+ index + 'repported as ' + Os10CmnOperStatus.get(item))
else:
if int(item) != 1:
countfail += 1
# message.append(textval + ' number '+ index + 'repported as ' + Os10CmnOperStatus.get(item))
message.append(textval + ' number '+ str(index) + ' reported as ' + Os10CmnOperStatus.get(item))
index += 1
if retCode != 3:
if countfail == 0:
retCode = 0
message.insert(0,'all ' + textval + '(s) OK')
else:
message.insert(0,'failed or error found for ' + textval)
if countfail < warn:
retCode = 1
if countfail < crit:
retCode = 2
else:
retCode = 3
message.insert(0, 'Unable to get SNMP metrics from server !')
print( nagiosStatus.get(str(retCode)), ': ', end='' )
for item in message:
print( item)
print('')
return retCode
def getSystemInfo():
message = []
retCode = 0
cardStatus = 6
vars = netsnmp.VarList(
netsnmp.Varbind('.1.3.6.1.2.1.1.5', 0), # sysName
netsnmp.Varbind('.1.3.6.1.2.1.1.2', 0), # sysObjectId
netsnmp.Varbind('.1.3.6.1.2.1.1.1', 0)) # sysDescr
vals = snmpSession.get(vars)
if vals:
message.append(vals[0] + ' (' + vals[1] + ' - ' + vals[2] + ')')
else:
retCode = 3
message.insert(0, 'Unable to get SNMP metrics from server !')
vars = netsnmp.VarList(
netsnmp.Varbind('.1.3.6.1.4.1.674.11000.5000.100.4.1.1.3.1.2.1'), # chassis type
netsnmp.Varbind('.1.3.6.1.4.1.674.11000.5000.100.4.1.1.3.1.6.1'), # chassis hw rev.
netsnmp.Varbind('.1.3.6.1.4.1.674.11000.5000.100.4.1.1.3.1.4.1'), # chassis p/n
netsnmp.Varbind('.1.3.6.1.4.1.674.11000.5000.100.4.1.1.3.1.7.1')) #chassis service tag
vals = snmpSession.get(vars)
if vals:
message.append('chassis: ' + Os10ChassisDefType.get(vals[0]) + ' (rev. ' + vals[1] + ') - p/n:' + vals[2] + ' - ServiceTag:' + vals[3])
else:
retCode = 3
message.insert(0, 'Unable to get SNMP metrics from server !')
vars = netsnmp.VarList(
netsnmp.Varbind('.1.3.6.1.4.1.674.11000.5000.100.4.1.1.4.1.3.1.1'), # card descr
netsnmp.Varbind('.1.3.6.1.4.1.674.11000.5000.100.4.1.1.4.1.8.1.1'), # card h/w rev.
netsnmp.Varbind('.1.3.6.1.4.1.674.11000.5000.100.4.1.1.4.1.6.1.1'), # card P/N
netsnmp.Varbind('.1.3.6.1.4.1.674.11000.5000.100.4.1.1.4.1.4.1.1'), # card status
netsnmp.Varbind('.1.3.6.1.4.1.674.11000.5000.100.4.1.1.4.1.9.1.1')) # card Service Tag
vals = snmpSession.get(vars)
if vals:
cardStatus = int(vals[3])
message.append('card: ' + vals[0] + ' (rev. ' + vals[1] + ') - p/n:' + vals[2] + ' - ServiceTag:' + vals[4] + ' - status:' + Os10CardOperStatus.get(vals[3]))
else:
retCode = 3
message.insert(0, 'Unable to get SNMP metrics from server !')
if cardStatus != 1:
if (cardStatus == 4 or cardStatus == 6) and retCode < 1:
retCode = 1
else:
retCode = 2
print(nagiosStatus.get(str(retCode)) + ':', end=' ')
for item in message:
print( item)
return retCode
def getTemperatures(warn, crit):
retCode = 0
message = []
vars = netsnmp.VarList(
# netsnmp.Varbind('.1.3.6.1.4.1.674.11000.5000.100.4.1.1.3.1.11'), # chassis temp.
# netsnmp.Varbind('.1.3.6.1.4.1.674.11000.5000.100.4.1.1.4.1.5') # card temp.
netsnmp.Varbind('.1.3.6.1.4.1.674.11000.5000.100.4.1.1.3.1.11.1'), # chassis temp.
netsnmp.Varbind('.1.3.6.1.4.1.674.11000.5000.100.4.1.1.4.1.5.1.1') # card temp.
)
#vals = snmpSession.walk(vars)
vals = snmpSession.get(vars)
if vals:
for temp in vals:
if int(temp) > int(crit) and retCode < 2:
retCode = 2
message.append('temperature sensor at ' + temp + ' °C exceed critical threshold (' + str(crit) + '°C)')
elif int(temp) > int(warn) and retCode < 1:
retCode = 1
message.append('temperature sensor at ' + temp + ' °C exceed warning threshold (' + str(warn) + '°C)')
else:
message.append('temperature sensor at ' + temp + ' °C')
else:
retCode = 3
message.insert(0, 'Unable to get SNMP metrics from server !')
if retCode == 0:
avg = sum(map(int, vals)) / len(vals)
message.insert(0, 'all temperature sensors OK with an average of '+ str(avg) + '°C')
print(nagiosStatus.get(str(retCode)) + ':', end=' ')
for item in message:
print( item)
return retCode
def getArgs():
host=''
community=''
mode=''
warn=0
crit=0
usage = "usage: %prog -H <host> -C <community> -m ( fans | power | health | temp ) [ -w <warn> ] [ -c crit ]"
descr = 'Nagios check plugin for Dell|EMC S-series switches running OS10 firmware'
epilog = __author__ + ' <' + __contact__ + '> - ' + __license__ + ' license'
optp = optparse.OptionParser(usage=usage, version="%prog " + __version__, description=descr, epilog=epilog)
optp.add_option('-H', '--host', help='IP address', dest='host')
optp.add_option('-C', '--community', help='SNMPv2 community', dest='community')
optp.add_option('-m', '--mode', help='mode (fans | power | health | temp)', dest='mode')
optp.add_option('-w', '--warning', help='warning threshold', dest='warning')
optp.add_option('-c', '--critical', help='critical threshold', dest='critical')
opts, args = optp.parse_args()
if opts.host is None:
print('Error: missing IP address')
optp.print_help()
sys.exit(1)
else:
host = opts.host
if opts.mode is None:
print('Error: missing mode')
optp.print_help()
sys.exit(1)
else:
pattern = re.compile('^(fans|power|health|temp)$')
if not pattern.match(opts.mode):
print('Error: unknown mode \'' + opts.mode + '\'')
optp.print_help()
sys.exit(1)
else:
mode = opts.mode
if opts.community is None:
community = 'public'
else:
community = opts.community
if opts.warning is None:
if mode == 'fans':
warn = 1
if mode == 'power':
warn = 0
if mode == 'temp':
warn = 50
else:
warn = opts.warning
if opts.critical is None:
if mode == 'fans':
crit = 2
if mode == 'power':
crit = 1
if mode == 'temp':
crit = 60
else:
crit = opts.critical
return host, community, mode, warn, crit
if __name__ == '__main__':
retCode = 3
host, community, mode, warn, crit = getArgs()
snmpSession = netsnmp.Session( Version = 2, DestHost=host, Community=community )
if mode == 'fans':
# os10FanTrayOperStatus MIB
retCode = getSnmpOperStatus('.1.3.6.1.4.1.674.11000.5000.100.4.1.2.2.1.4', 'fan', warn, crit)
if mode == 'power':
# os10PowerSupplyOperStatus MIB
retCode = getSnmpOperStatus('.1.3.6.1.4.1.674.11000.5000.100.4.1.2.1.1.4', 'PSU', warn, crit)
if mode == 'temp':
retCode = getTemperatures(warn, crit)
if mode == 'health':
retCode = getSystemInfo()
sys.exit(retCode)