-
Notifications
You must be signed in to change notification settings - Fork 3
/
check_dell_powerconnect
executable file
·375 lines (340 loc) · 11.3 KB
/
check_dell_powerconnect
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#!/usr/bin/perl
# This Plugin checks the hardware of DELL 35XX and 62XX Switches (fans, temp-sensor, power supply)
# tested only with PC3524 and the PC6248.
#
# Copyright (c) 2019 Gerrit Doornenbal, g(dot)doornenbal(at)hccnet(dot)nl
# Many thanks to Sascha Tentscher , who provided a very good example with his 3com plugin!
# feb.2012: Thanks to Vicente Gavara Padilla for his work to address hash/communication/time-out errors.
#
# release history:
# 2009 Initial release, no version number.
# 2-2012 Version 1.1: update to address has/communication/time-out errors.
# 2-2019 Version 1.2: added support for N1100 series, and probably N1500,N2000,N2100,N3000,N3100 and N4000 too.
# added debug option, firmware version, fixed unit temperature.
# rewrite view of Fans; when OK, just counting, with error printing out.
# added option to check number of (stackunits), and give failure when missing
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-130
use strict;
use Net::SNMP;
my %status = ( 'OK' => '0',
'WARNING' => '1',
'CRITICAL' => '2',
'UNKNOWN' => '3' );
my %unitstates = ( '1' => 'unknown',
'2' => 'inactive',
'3' => 'OK',
'4' => 'loading' );
my %entitystate = ( '1' => 'normal',
'2' => 'warning',
'3' => 'critical',
'4' => 'shutdown',
'5' => 'notPresent',
'6' => 'notFunctioning' );
sub pars_args
{
my $ip = "";
my $community = "";
my $units = 0;
my $debug = 0;
while($ARGV[0] =~/^-/)
{
if($ARGV[0] =~/^-H|^--host/)
{
$ip = $ARGV[1];
shift @ARGV;
shift @ARGV;
next;
}
if($ARGV[0] =~/^-C|^--Community/)
{
$community = $ARGV[1];
shift @ARGV;
shift @ARGV;
next;
}
if($ARGV[0] =~/^-U|^--units/)
{
$units = $ARGV[1];
shift @ARGV;
shift @ARGV;
next;
}
if($ARGV[0] =~/^-d|^--debug/)
{
$debug = 1;
shift @ARGV;
next;
}
}
return ($ip, $community, $units, $debug);
}
sub print_help()
{
print "check_dell_powerconnect.pl v1.2 (feb-2019)\n\n";
print "This Plugin checks the hardware of DELL 35XX,62XX,N11XX\nswitches (fans, temp-sensor, power supply), and probably\nmore models! (not tested)\n\n";
print "Usage: check_dell_powerconnect -H host -C community [-d]\n";
print "Options:\n";
print " -H --host STRING or IPADDRESS\n";
print " Check interface on the indicated host.\n";
print " -C --community STRING\n";
print " Community-String for SNMP-Walk.\n";
print " -U --units INTEGER\n";
print " Number of units in stack.\n";
print " -d --debug\n";
print " Extended output for debugging.\n\n";
exit($status{"UNKNOWN"});
}
sub get_snmp_session
{
my $ip = $_[0];
my $community = $_[1];
my ($session, $error) = Net::SNMP->session(
-hostname => $ip,
-community => $community,
-port => 161,
-timeout => 1,
-retries => 3,
-translate => [-timeticks => 0x0] #schaltet Umwandlung von Timeticks in Zeitformat aus
);
return ($session, $error);
}
sub close_snmp_session
{
my $session = $_[0];
$session->close();
}
sub get_snmp_request
{
my $session = $_[0];
my $oid = $_[1];
return $session->get_request($oid);
}
sub get_snmp_table
{
my $session = $_[0];
my $oid = $_[1];
return $session->get_table($oid);
}
if ($#ARGV == -1)
{
print_help();
}
my ($ip, $community, $units, $debug) = pars_args();
my ($session, $error) = get_snmp_session($ip, $community);
#Code String to show degrees sign in output..
#see https://stackoverflow.com/questions/8334266/how-to-make-special-characters-in-a-bash-script-for-conky
my $degree = "C";
my $result;
#find out what type switch.. powerconnect or OS10 series.
#and load the respective oid's.
my $oid_sysName = ".1.3.6.1.2.1.1.5.0";
my $oid_ObjectId = ".1.3.6.1.2.1.1.2.0";
my $oid_unitdesc = ".1.3.6.1.2.1.1.1.0";
my ($oid_unitstate,$oid_firmware,$oid_fanname,$oid_fanstate,$oid_psuname,$oid_psustate,$oid_temperature);
my $unitoid;
if ($result = get_snmp_request($session, $oid_ObjectId)) {
$unitoid = $result->{$oid_ObjectId};
if ($unitoid =~ /11000/i) {
if ( $debug ) { print "This is a OS10 Series switch.\n"; }
$oid_unitdesc = ".1.3.6.1.2.1.1.1.0";
#$oid_unitdesc = ".1.3.6.1.4.1.674.11000.5000.100.4.1.1.4.1.3.1.1";
$oid_unitstate = ".1.3.6.1.4.1.674.11000.5000.100.4.1.1.4.1.4.1.1";
#$oid_firmware = ".1.3.6.1.4.1.674.10895.3000.1.2.100.4.0";
$oid_fanname = ".1.3.6.1.4.1.674.11000.5000.100.4.1.2.2.1.5";
$oid_fanstate = ".1.3.6.1.4.1.674.11000.5000.100.4.1.2.2.1.4";
$oid_psuname = ".1.3.6.1.4.1.674.11000.5000.100.4.1.2.1.1.6";
$oid_psustate = ".1.3.6.1.4.1.674.11000.5000.100.4.1.2.1.1.4";
$oid_temperature = ".1.3.6.1.4.1.674.11000.5000.100.4.1.1.3.1.11.1";
%unitstates = ( '1' => 'ready',
'2' => 'cardMisMatch',
'3' => 'cardProblem',
'4' => 'diagMode',
'5' => 'cardAbsent',
'6' => 'offline' );
} else {
if ( $debug ) { print "This is a PowerConnect series switch.\n"; }
$oid_unitdesc = ".1.3.6.1.4.1.674.10895.3000.1.2.100.1.0";
$oid_unitstate = ".1.3.6.1.4.1.674.10895.3000.1.2.110.1.0";
$oid_firmware = ".1.3.6.1.4.1.674.10895.3000.1.2.100.4.0";
$oid_fanname = ".1.3.6.1.4.1.674.10895.3000.1.2.110.7.1.1.2";
$oid_fanstate = ".1.3.6.1.4.1.674.10895.3000.1.2.110.7.1.1.3";
$oid_psuname = ".1.3.6.1.4.1.674.10895.3000.1.2.110.7.2.1.2";
$oid_psustate = ".1.3.6.1.4.1.674.10895.3000.1.2.110.7.2.1.3";
}
} else {
# Code added for managing SNMP get request errors
print "UNKNOWN - Unable to get unitObjectID from $ip\n";
exit($status{UNKNOWN});
}
if ( $debug ) { print "UnitObjectId: ".$unitoid."\n"; }
my $unitdesc;
if ($result = get_snmp_request($session, $oid_unitdesc)) {
$unitdesc = $result->{$oid_unitdesc};
} else {
print "UNKNOWN - Unable to get unitdescription from $ip\n";
exit($status{UNKNOWN});
}
my @unitarray = split "\n", $unitdesc;
if ( $debug ) { print "Unitdesc: ".$unitdesc."\n"; }
#my $oid_tempstatus = ".1.3.6.1.4.1.89.53.15.1.9.1";
my $oid_tempstatus = "";
if ($unitdesc =~ /62/i) { $oid_tempstatus = ".1.3.6.1.4.1.674.10895.5000.2.6132.1.1.43.1.8.1.4"; } #PC62XX series
if ($unitdesc =~ /N11/i) { $oid_tempstatus = ".1.3.6.1.4.1.674.10895.5000.2.6132.1.1.43.1.8.1.5"; } #N Series
if ($unitarray[0] =~ /OS10/i) { $oid_tempstatus = ".1.3.6.1.4.1.674.11000.5000.100.4.1.1.4.1.5.1"; } #OS10 Series
my $firmware;
if ( $oid_firmware != "") {
if ($result = get_snmp_request($session, $oid_firmware)) {
$firmware = $result->{$oid_firmware};
#$unitdesc = (split ' ', $unitdesc)[-1];
} else {
print "UNKNOWN - Unable to get unit firmwareversion from $ip\n";
exit($status{UNKNOWN});
}
} else {
#OS10 get firmware out of sysdescr.
#print "OS10 firmware: $unitarray[3]\n";
$firmware = (split ' ', $unitarray[3])[-1];
$unitdesc = (split ' ', $unitarray[4])[-1];
}
if ( $debug ) { print "Unit firmware: ".$firmware."\n"; }
my $unitstate;
if ($result = get_snmp_request($session, $oid_unitstate)) {
$unitstate = $result->{$oid_unitstate};
if ( $debug ) { print "Unitstate: ".$unitstate.": ".$unitstates{$unitstate}."\n"; }
$unitstate = $unitstates{$unitstate}.",";
} else {
print "UNKNOWN - Unable to get data from $ip\n";
exit($status{UNKNOWN});
}
#check temperature if possible (Only PC35XX ..??)
my $temperature = "";
my %tempresult = %{get_snmp_table($session, $oid_tempstatus)};
my $unitcount = 0;
#find tempstates
foreach my $oid(sort keys %tempresult)
{
if ( $temperature ne "" ) { $temperature .= ", "; }
$unitcount++;
$temperature .= "Temp".$unitcount.": ".$tempresult{$oid}.$degree;
}
$temperature = " ".$temperature;
if ( $debug ) { print "Number of units: ".$unitcount."\nUnittemp: ".$temperature."\n"; }
# Check if it is a stack or not..
my $stack;
if ( $unitcount == 1 ) {
#no stack
$stack = "";
} else {
$stack= " ".$unitcount." Units"
#stack!
}
if ( $units != 0 and $unitcount != $units) {
# number of units in stack is checked and unit is missing!
my $m = "";
if ( $unitcount != 1 ) { $m = "s"; }
$stack = " ".$unitcount." Unit".$m." found, ".$units." expected!";
$unitstate = "CRITICAL:";
}
my %result1 = %{get_snmp_table($session, $oid_fanname)};
my %result2 = %{get_snmp_table($session, $oid_fanstate)};
my $counter = 0;
my $counter1 = 0;
my @fanname;
my @fanstate;
#find fan states
foreach my $oid(sort keys %result1)
{
$fanname[$counter] = $result1{$oid};
$counter++;
}
$counter = 0;
foreach my $oid(sort keys %result2)
{
$fanstate[$counter] = $result2{$oid};
$counter++;
}
# Create Fan status line
my $fanstring;
my $okfans = 0;
for(my $i = 0; $i<$counter; $i++) {
if ($fanstate[$i] !=5) { #is present
if ($fanstate[$i] == 1) {
$okfans++
} else {
$fanstring = $fanstring.", ";
$fanstring .= $fanname[$i]." ".$entitystate{$fanstate[$i]};
if ( $unitstate eq "OK," ) { $unitstate = "WARNING:"; }
}
}
}
$fanstring = ", ".$okfans." Fans OK".$fanstring;
#find PSU states
my @psuname;
my @psustate;
my $psustring;
#if (! $unitdesc =~ /N11/i) {
if ( index($unitdesc, "N11" ) == -1 ) {
if ( $debug ) { print "Checking PSU states..\n"; }
my %result3 = %{get_snmp_table($session, $oid_psuname)};
my %result4 = %{get_snmp_table($session, $oid_psustate)};
$counter1 = 0;
foreach my $oid(sort keys %result3)
{
$psuname[$counter1] = $result3{$oid};
$counter1++;
}
$counter1 = 0;
foreach my $oid(sort keys %result4)
{
$psustate[$counter1] = $result4{$oid};
$counter1++;
}
close_snmp_session($session);
# Create PSU status line
my $psulong;
my $okpsus = 0;
for(my $i =0; $i<$counter1; $i++) {
if ( $debug ) { print $psuname[$i]." ".$entitystate{$psustate[$i]}."\n"; }
if ($psustate[$i] !=5) { #notInstalled
if ($psustate[$i] != 1) {
$psulong .= ", ";
$psulong .= $psuname[$i]." ".$entitystate{$psustate[$i]};
} else {
$okpsus++
}
}
}
$psustring=", $okpsus PSU's OK$psulong";
}
# Create output line
my $string = $unitdesc." v".$firmware.": ".$unitstate.$stack.$temperature.$fanstring.$psustring;
# Create correct exit state
my $state = "OK";
if($string =~/UNKNOWN/)
{
$state = "UNKNOWN";
}
if($string =~/inactive|notpresent|warning|WARNING/)
{
$state = "WARNING";
}
if($string =~/Error|critical|CRITICAL/)
{
$state = "CRITICAL";
}
if ( $debug ) { print "Exit state is: ".$state." (".$status{$state}.")\n"; }
print $string."\n";
exit($status{$state});