Debian Codegraph @

check_hpasm/check_hpasm-4.9/plugins-scripts/HP/Proliant.pm

raw
1 package HP::Proliant;
2
3 use strict;
4 use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
5 use Data::Dumper;
6
7 our @ISA = qw(HP::Server);
8
9 sub init {
10 my $self = shift;
11 $self->{components} = {
12 powersupply_subsystem => undef,
13 fan_subsystem => undef,
14 temperature_subsystem => undef,
15 cpu_subsystem => undef,
16 memory_subsystem => undef,
17 nic_subsystem => undef,
18 disk_subsystem => undef,
19 asr_subsystem => undef,
20 event_subsystem => undef,
21 battery_subsystem => undef,
22 };
23 $self->{serial} = 'unknown';
24 $self->{product} = 'unknown';
25 $self->{romversion} = 'unknown';
26 $self->collect();
27 if (! $self->{runtime}->{plugin}->check_messages() &&
28 ! exists $self->{noinst_hint}) {
29 $self->set_serial();
30 $self->check_for_buggy_firmware();
31 $self->analyze_cpus();
32 $self->analyze_powersupplies();
33 $self->analyze_fan_subsystem();
34 $self->analyze_temperatures();
35 $self->analyze_memory_subsystem();
36 $self->analyze_nic_subsystem();
37 $self->analyze_disk_subsystem();
38 $self->analyze_asr_subsystem();
39 $self->analyze_event_subsystem();
40 $self->analyze_battery_subsystem();
41 $self->auto_blacklist();
42 $self->check_cpus();
43 $self->check_powersupplies();
44 $self->check_fan_subsystem();
45 $self->check_temperatures();
46 $self->check_memory_subsystem();
47 $self->check_nic_subsystem();
48 $self->check_disk_subsystem();
49 $self->check_asr_subsystem();
50 $self->check_event_subsystem();
51 $self->check_battery_subsystem();
52 }
53 }
54
55 sub identify {
56 my $self = shift;
57 foreach (qw(product serial romversion)) {
58 $self->{$_} =~ s/^\s+//;
59 $self->{$_} =~ s/\s+$//;
60 }
61 return sprintf "System: '%s', S/N: '%s', ROM: '%s'",
62 $self->{product}, $self->{serial}, $self->{romversion};
63 }
64
65 sub check_for_buggy_firmware {
66 my $self = shift;
67 my @buggyfirmwares = (
68 "P24 12/11/2001",
69 "P24 11/15/2002",
70 "D13 06/03/2003",
71 "D13 09/15/2004",
72 "P20 12/17/2002"
73 );
74 if ($self->{romversion} =~ /^\w+ \d+\/\d+\/\d+$/) {
75 $self->{runtime}->{options}->{buggy_firmware} =
76 grep /^$self->{romversion}/, @buggyfirmwares;
77 } else {
78 # nicht parsbarer schrott in cpqSeSysRomVer, gesehen bei Gen9
79 $self->{runtime}->{options}->{buggy_firmware} = undef;
80 }
81 }
82
83 sub dump {
84 my $self = shift;
85 printf STDERR "serial %s\n", $self->{serial};
86 printf STDERR "product %s\n", $self->{product};
87 printf STDERR "romversion %s\n", $self->{romversion};
88 printf STDERR "%s\n", Data::Dumper::Dumper($self->{components});
89 }
90
91 sub analyze_powersupplies {
92 my $self = shift;
93 $self->{components}->{powersupply_subsystem} =
94 HP::Proliant::Component::PowersupplySubsystem->new(
95 rawdata => $self->{rawdata},
96 method => $self->{method},
97 runtime => $self->{runtime},
98 );
99 }
100
101 sub analyze_fan_subsystem {
102 my $self = shift;
103 $self->{components}->{fan_subsystem} =
104 HP::Proliant::Component::FanSubsystem->new(
105 rawdata => $self->{rawdata},
106 method => $self->{method},
107 runtime => $self->{runtime},
108 );
109 }
110
111 sub analyze_temperatures {
112 my $self = shift;
113 $self->{components}->{temperature_subsystem} =
114 HP::Proliant::Component::TemperatureSubsystem->new(
115 rawdata => $self->{rawdata},
116 method => $self->{method},
117 runtime => $self->{runtime},
118 );
119 }
120
121 sub analyze_cpus {
122 my $self = shift;
123 $self->{components}->{cpu_subsystem} =
124 HP::Proliant::Component::CpuSubsystem->new(
125 rawdata => $self->{rawdata},
126 method => $self->{method},
127 runtime => $self->{runtime},
128 );
129 }
130
131 sub analyze_memory_subsystem {
132 my $self = shift;
133 $self->{components}->{memory_subsystem} =
134 HP::Proliant::Component::MemorySubsystem->new(
135 rawdata => $self->{rawdata},
136 method => $self->{method},
137 runtime => $self->{runtime},
138 );
139 }
140
141 sub analyze_nic_subsystem {
142 my $self = shift;
143 return if $self->{method} ne "snmp";
144 $self->{components}->{nic_subsystem} =
145 HP::Proliant::Component::NicSubsystem->new(
146 rawdata => $self->{rawdata},
147 method => $self->{method},
148 runtime => $self->{runtime},
149 );
150 }
151
152 sub analyze_disk_subsystem {
153 my $self = shift;
154 $self->{components}->{disk_subsystem} =
155 HP::Proliant::Component::DiskSubsystem->new(
156 rawdata => $self->{rawdata},
157 method => $self->{method},
158 runtime => $self->{runtime},
159 );
160 }
161
162 sub analyze_asr_subsystem {
163 my $self = shift;
164 $self->{components}->{asr_subsystem} =
165 HP::Proliant::Component::AsrSubsystem->new(
166 rawdata => $self->{rawdata},
167 method => $self->{method},
168 runtime => $self->{runtime},
169 );
170 }
171
172 sub analyze_event_subsystem {
173 my $self = shift;
174 $self->{components}->{event_subsystem} =
175 HP::Proliant::Component::EventSubsystem->new(
176 rawdata => $self->{rawdata},
177 method => $self->{method},
178 runtime => $self->{runtime},
179 );
180 }
181
182 sub analyze_battery_subsystem {
183 my $self = shift;
184 $self->{components}->{battery_subsystem} =
185 HP::Proliant::Component::BatterySubsystem->new(
186 rawdata => $self->{rawdata},
187 method => $self->{method},
188 runtime => $self->{runtime},
189 );
190 }
191
192 sub check_cpus {
193 my $self = shift;
194 $self->{components}->{cpu_subsystem}->check();
195 $self->{components}->{cpu_subsystem}->dump()
196 if $self->{runtime}->{options}->{verbose} >= 2;
197 }
198
199 sub check_powersupplies {
200 my $self = shift;
201 $self->{components}->{powersupply_subsystem}->check();
202 $self->{components}->{powersupply_subsystem}->dump()
203 if $self->{runtime}->{options}->{verbose} >= 2;
204 }
205
206 sub check_fan_subsystem {
207 my $self = shift;
208 $self->{components}->{fan_subsystem}->check();
209 $self->{components}->{fan_subsystem}->dump()
210 if $self->{runtime}->{options}->{verbose} >= 2;
211 }
212
213 sub check_temperatures {
214 my $self = shift;
215 $self->{components}->{temperature_subsystem}->check();
216 $self->{components}->{temperature_subsystem}->dump()
217 if $self->{runtime}->{options}->{verbose} >= 2;
218 }
219
220 sub check_memory_subsystem {
221 my $self = shift;
222 $self->{components}->{memory_subsystem}->check();
223 $self->{components}->{memory_subsystem}->dump()
224 if $self->{runtime}->{options}->{verbose} >= 2;
225 }
226
227 sub check_nic_subsystem {
228 my $self = shift;
229 return if $self->{method} ne "snmp";
230 if ($self->{runtime}->{plugin}->{opts}->get('eval-nics')) {
231 $self->{components}->{nic_subsystem}->check();
232 $self->{components}->{nic_subsystem}->dump()
233 if $self->{runtime}->{options}->{verbose} >= 2;
234 }
235 }
236 sub check_disk_subsystem {
237 my $self = shift;
238 $self->{components}->{disk_subsystem}->check();
239 $self->{components}->{disk_subsystem}->dump()
240 if $self->{runtime}->{options}->{verbose} >= 2;
241 # zum anhaengen an die normale ausgabe... da: 2 logical drives, 5 physical...
242 $self->{runtime}->{plugin}->add_message(OK,
243 $self->{components}->{disk_subsystem}->{summary})
244 if $self->{components}->{disk_subsystem}->{summary};
245 }
246
247 sub check_asr_subsystem {
248 my $self = shift;
249 $self->{components}->{asr_subsystem}->check();
250 $self->{components}->{asr_subsystem}->dump()
251 if $self->{runtime}->{options}->{verbose} >= 2;
252 }
253
254 sub check_event_subsystem {
255 my $self = shift;
256 $self->{components}->{event_subsystem}->check();
257 $self->{components}->{event_subsystem}->dump()
258 if $self->{runtime}->{options}->{verbose} >= 2;
259 }
260
261 sub check_battery_subsystem {
262 my $self = shift;
263 $self->{components}->{battery_subsystem}->check();
264 $self->{components}->{battery_subsystem}->dump()
265 if $self->{runtime}->{options}->{verbose} >= 2;
266 }
267
268 sub auto_blacklist() {
269 my $self = shift;
270 if ($self->{product} =~ /380 g6/) {
271 # http://bizsupport1.austin.hp.com/bc/docs/support/SupportManual/c01723408/c01723408.pdf seite 19
272 if ($self->{components}->{cpu_subsystem}->num_cpus() == 1) {
273 $self->add_blacklist('ff/f:5,6');
274 }
275 } elsif ($self->{product} =~ /380 g6/) {
276 # http://bizsupport1.austin.hp.com/bc/docs/support/SupportManual/c01704762/c01704762.pdf Fan 2 is only required when processor 2 is installed in the server.
277 }
278 }
279
280
281 package HP::Proliant::CLI;
282
283 use strict;
284 use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
285
286 our @ISA = qw(HP::Proliant);
287
288 sub collect {
289 my $self = shift;
290 my $hpasmcli = undef;
291 if (($self->{runtime}->{plugin}->opts->hpasmcli) &&
292 (-f $self->{runtime}->{plugin}->opts->hpasmcli) &&
293 (! -x $self->{runtime}->{plugin}->opts->hpasmcli)) {
294 no strict 'refs';
295 open(BIRK, $self->{runtime}->{plugin}->opts->hpasmcli);
296 # all output in one file prefixed with server|powersupply|fans|temp|dimm
297 while(<BIRK>) {
298 chomp;
299 $self->{rawdata} .= $_."\n";
300 }
301 close BIRK;
302 # If you run this script and redirect it's output to a file
303 # you can use it for testing purposes with
304 # --hpasmcli <output>
305 # It must not be executable. (chmod 644)
306 my $diag = <<'EOEO';
307 hpasmcli=$(which hpasmcli)
308 hpacucli=$(which hpacucli)
309 for i in server powersupply fans temp dimm
310 do
311 $hpasmcli -s "show $i" | while read line
312 do
313 printf "%s %s\n" $i "$line"
314 done
315 done
316 if [ -x "$hpacucli" ]; then
317 for i in config status
318 do
319 $hpacucli ctrl all show $i | while read line
320 do
321 printf "%s %s\n" $i "$line"
322 done
323 done
324 fi
325 EOEO
326 } else {
327 #die "exec hpasmcli";
328 # alles einsammeln und in rawdata stecken
329 my $hpasmcli = undef;
330 $hpasmcli = $self->{runtime}->{plugin}->opts->hpasmcli ?
331 $self->{runtime}->{plugin}->opts->hpasmcli : '/sbin/hpasmcli';
332 # check if this exists at all
333 # descend the directory
334 if ($self->{runtime}->{plugin}->opts->hpasmcli &&
335 -e $self->{runtime}->{plugin}->opts->hpasmcli) {
336 $hpasmcli = $self->{runtime}->{plugin}->opts->hpasmcli;
337 } elsif (-e '/sbin/hpasmcli') {
338 $hpasmcli = '/sbin/hpasmcli';
339 } else {
340 $hpasmcli = undef;
341 }
342 if ($hpasmcli) {
343 if ($< != 0) {
344 close STDIN;
345 $hpasmcli = "sudo -S ".$hpasmcli;
346 }
347 $self->trace(2, sprintf "calling %s\n", $hpasmcli);
348 $self->check_daemon();
349 if (! $self->{runtime}->{plugin}->check_messages()) {
350 $self->check_hpasm_client($hpasmcli);
351 if (! $self->{runtime}->{plugin}->check_messages()) {
352 foreach my $component (qw(server fans temp dimm powersupply iml)) {
353 if (open HPASMCLI, "$hpasmcli -s \"show $component\" </dev/null |") {
354 my @output = <HPASMCLI>;
355 close HPASMCLI;
356 $self->{rawdata} .= join("\n", map {
357 $component.' '.$_;
358 } @output);
359 }
360 }
361 if ($self->{runtime}->{options}->{hpacucli}) {
362 #1 oder 0. pfad selber finden
363 my $hpacucli = undef;
364 if (-e '/usr/sbin/hpssacli') {
365 $hpacucli = '/usr/sbin/hpssacli';
366 } elsif (-e '/usr/local/sbin/hpssacli') {
367 $hpacucli = '/usr/local/sbin/hpssacli';
368 } elsif (-e '/usr/sbin/hpacucli') {
369 $hpacucli = '/usr/sbin/hpacucli';
370 } elsif (-e '/usr/local/sbin/hpacucli') {
371 $hpacucli = '/usr/local/sbin/hpacucli';
372 } elsif (-e '/usr/sbin/hpssacli') {
373 $hpacucli = '/usr/sbin/hpssacli';
374 } elsif (-e '/usr/local/sbin/hpssacli') {
375 $hpacucli = '/usr/local/sbin/hpssacli';
376 } else {
377 $hpacucli = $hpasmcli;
378 $hpacucli =~ s/^sudo\s*//;
379 $hpacucli =~ s/hpasmcli/hpacucli/;
380 $hpacucli = -e $hpacucli ? $hpacucli : undef;
381 if (! $hpacucli) {
382 $hpacucli = $hpasmcli;
383 $hpacucli =~ s/^sudo\s*//;
384 $hpacucli =~ s/hpasmcli/hpssacli/;
385 $hpacucli = -e $hpacucli ? $hpacucli : undef;
386 }
387 }
388 if ($hpacucli) {
389 if ($< != 0) {
390 close STDIN;
391 $hpacucli = "sudo -S ".$hpacucli;
392 }
393 $self->trace(2, sprintf "calling %s\n", $hpacucli);
394 $self->check_hpacu_client($hpacucli);
395 if (! $self->{runtime}->{plugin}->check_messages()) {
396 if (open HPACUCLI, "$hpacucli ctrl all show status 2>&1|") {
397 my @output = <HPACUCLI>;
398 close HPACUCLI;
399 $self->{rawdata} .= join("\n", map {
400 'status '.$_;
401 } @output);
402 }
403 if (open HPACUCLI, "$hpacucli ctrl all show config 2>&1|") {
404 my @output = <HPACUCLI>;
405 close HPACUCLI;
406 $self->{rawdata} .= join("\n", map {
407 'config '.$_;
408 } @output);
409 if (grep /Syntax error at "config"/, @output) {
410 # older version of hpacucli CLI 7.50.18.0
411 foreach my $slot (0..10) {
412 if (open HPACUCLI, "$hpacucli ctrl slot=$slot logicaldrive all show 2>&1|") {
413 my @output = <HPACUCLI>;
414 close HPACUCLI;
415 $self->{rawdata} .= join("\n", map {
416 'config '.$_;
417 } @output);
418 }
419 if (open HPACUCLI, "$hpacucli ctrl slot=$slot physicaldrive all show 2>&1|") {
420 my @output = <HPACUCLI>;
421 close HPACUCLI;
422 $self->{rawdata} .= join("\n", map {
423 'config '.$_;
424 } @output);
425 }
426 }
427 }
428 }
429 } elsif ($self->{runtime}->{options}->{hpacucli} == 2) {
430 # we probably don't have sudo-privileges, but we were compiled with
431 # --enable-hpacucli=maybe
432 # so we cover it up in silence
433 $self->remove_message(UNKNOWN);
434 $self->trace(2, sprintf "calling %s seems to have failed, but nobody cares\n", $hpacucli);
435 }
436 } else {
437 if ($self->{runtime}->{options}->{noinstlevel} eq 'ok') {
438 $self->add_message(OK,
439 'hpacucli is not installed. let\'s hope the best...');
440 } else {
441 $self->add_message(
442 uc $self->{runtime}->{options}->{noinstlevel},
443 'hpacucli is not installed.');
444 }
445 }
446 }
447 }
448 }
449 } else {
450 if ($self->{runtime}->{options}->{noinstlevel} eq 'ok') {
451 $self->add_message(OK,
452 'hpasm is not installed, i can only guess');
453 $self->{noinst_hint} = 1;
454 } else {
455 $self->add_message(
456 uc $self->{runtime}->{options}->{noinstlevel},
457 'hpasmcli is not installed.');
458 }
459 }
460 }
461 }
462
463
464 sub check_daemon {
465 my $self = shift;
466 my $multiproc_os_signatures_files = {
467 '/etc/SuSE-release' => 'VERSION\s*=\s*8',
468 '/etc/trustix-release' => '.*',
469 '/etc/redhat-release' => '.*Pensacola.*',
470 '/etc/debian_version' => '3\.1',
471 '/etc/issue' => '.*Kernel 2\.4\.9-vmnix2.*', # VMware ESX Server 2.5.4
472 };
473 if (open PS, "/bin/ps -e -ocmd|") {
474 my $numprocs = 0;
475 my $numcliprocs = 0;
476 my @procs = <PS>;
477 close PS;
478 $numprocs = grep /hpasm.*d$/, map { (split /\s+/, $_)[0] } @procs;
479 $numcliprocs = grep /hpasmcli/, grep !/check_hpasm/, @procs;
480 if (! $numprocs ) {
481 $self->add_message(CRITICAL, 'hpasmd needs to be restarted');
482 } elsif ($numprocs > 1) {
483 my $known = 0;
484 foreach my $osfile (keys %{$multiproc_os_signatures_files}) {
485 if (-f $osfile) {
486 open OSSIG, $osfile;
487 if (grep /$multiproc_os_signatures_files->{$osfile}/, <OSSIG>) {
488 $known = 1;
489 }
490 close OSSIG;
491 }
492 }
493 if (! $known) {
494 $self->add_message(UNKNOWN, 'multiple hpasmd procs');
495 }
496 }
497 if ($numcliprocs == 1) {
498 $self->add_message(UNKNOWN, 'another hpasmcli is running');
499 } elsif ($numcliprocs > 1) {
500 $self->add_message(UNKNOWN, 'hanging hpasmcli processes');
501 }
502 }
503 }
504
505 sub check_hpasm_client {
506 my $self = shift;
507 my $hpasmcli = shift;
508 if (open HPASMCLI, "$hpasmcli -s help 2>&1 |") {
509 my @output = <HPASMCLI>;
510 close HPASMCLI;
511 if (grep /Could not communicate with hpasmd/, @output) {
512 $self->add_message(CRITICAL, 'hpasmd needs to be restarted');
513 } elsif (grep /(asswor[dt]:)|(You must be root)/, @output) {
514 $self->add_message(UNKNOWN,
515 sprintf "insufficient rights to call %s", $hpasmcli);
516 } elsif (grep /must have a tty/, @output) {
517 $self->add_message(CRITICAL,
518 'sudo must be configured with requiretty=no (man sudo)');
519 } elsif (grep /ERROR: hpasmcli only runs on HPE Proliant Servers/, @output) {
520 $self->add_message(UNKNOWN, "hpasmcli detected incompatible hardware");
521 } elsif (! grep /CLEAR/, @output) {
522 $self->add_message(UNKNOWN,
523 sprintf "insufficient rights to call %s", $hpasmcli);
524 }
525 } else {
526 $self->add_message(UNKNOWN,
527 sprintf "insufficient rights to call %s", $hpasmcli);
528 }
529 }
530
531 sub check_hpacu_client {
532 my $self = shift;
533 my $hpacucli = shift;
534 if (open HPACUCLI, "$hpacucli help 2>&1 |") {
535 my @output = <HPACUCLI>;
536 close HPACUCLI;
537 if (grep /Another instance of hpacucli is running/, @output) {
538 $self->add_message(UNKNOWN, 'another hpacucli is running');
539 } elsif (grep /You need to have administrator rights/, @output) {
540 $self->add_message(UNKNOWN,
541 sprintf "insufficient rights to call %s", $hpacucli);
542 } elsif (grep /(asswor[dt]:)|(You must be root)/, @output) {
543 $self->add_message(UNKNOWN,
544 sprintf "insufficient rights to call %s", $hpacucli);
545 } elsif (! grep /(CLI Syntax)|(ACU CLI)/, @output) {
546 $self->add_message(UNKNOWN,
547 sprintf "insufficient rights to call %s", $hpacucli);
548 }
549 } else {
550 $self->add_message(UNKNOWN,
551 sprintf "insufficient rights to call %s", $hpacucli);
552 }
553 }
554
555 sub set_serial {
556 my $self = shift;
557 foreach (grep(/^server/, split(/\n/, $self->{rawdata}))) {
558 if (/System\s+:\s+(.*[^\s])/) {
559 $self->{product} = lc $1;
560 } elsif (/Serial No\.\s+:\s+(\w+)/) {
561 $self->{serial} = $1;
562 } elsif (/ROM version\s+:\s+(.*[^\s])/) {
563 $self->{romversion} = $1;
564 }
565 }
566 $self->{serial} = $self->{serial};
567 $self->{product} = lc $self->{product};
568 $self->{romversion} = $self->{romversion};
569 foreach (qw(serial product romversion)) {
570 $self->{$_} =~ s/\s+$//g;
571 }
572 }
573
574
575 package HP::Proliant::SNMP;
576
577 use strict;
578 use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
579
580 our @ISA = qw(HP::Proliant);
581
582 sub collect {
583 my $self = shift;
584 my %oidtables = (
585 system => "1.3.6.1.2.1.1",
586 cpqSeProcessor => "1.3.6.1.4.1.232.1.2.2",
587 cpqHePWSComponent => "1.3.6.1.4.1.232.6.2.9",
588 cpqHeThermal => "1.3.6.1.4.1.232.6.2.6",
589 cpqHeMComponent => "1.3.6.1.4.1.232.6.2.14",
590 cpqDaComponent => "1.3.6.1.4.1.232.3.2",
591 cpqSiComponent => "1.3.6.1.4.1.232.2.2",
592 cpqSeRom => "1.3.6.1.4.1.232.1.2.6",
593 cpqSasComponent => "1.3.6.1.4.1.232.5",
594 cpqIdeComponent => "1.3.6.1.4.1.232.14",
595 cpqFcaComponent => "1.3.6.1.4.1.232.16.2",
596 cpqHeAsr => "1.3.6.1.4.1.232.6.2.5",
597 cpqNic => "1.3.6.1.4.1.232.18.2",
598 cpqHeEventLog => "1.3.6.1.4.1.232.6.2.11",
599 cpqHeSysBackupBattery => "1.3.6.1.4.1.232.6.2.17",
600
601 # cpqHeComponent => "1.3.6.1.4.1.232.6.2",
602 # cpqHeFComponent => "1.3.6.1.4.1.232.6.2.6.7",
603 # cpqHeTComponent => "1.3.6.1.4.1.232.6.2.6.8",
604 );
605 my %oidvalues = (
606 cpqHeEventLogSupported => "1.3.6.1.4.1.232.6.2.11.1.0",
607 cpqHeEventLogCondition => "1.3.6.1.4.1.232.6.2.11.2.0",
608 cpqNicIfLogMapOverallCondition => "1.3.6.1.4.1.232.18.2.2.2.0",
609 cpqHeThermalTempStatus => "1.3.6.1.4.1.232.6.2.6.3.0",
610 cpqHeThermalSystemFanStatus => "1.3.6.1.4.1.232.6.2.6.4.0",
611 cpqHeThermalCpuFanStatus => "1.3.6.1.4.1.232.6.2.6.5.0",
612 cpqHeAsrStatus => "1.3.6.1.4.1.232.6.2.5.1.0",
613 cpqHeAsrCondition => "1.3.6.1.4.1.232.6.2.5.17.0",
614 );
615 if ($self->{runtime}->{plugin}->opts->snmpwalk) {
616 my $cpqSeMibCondition = '1.3.6.1.4.1.232.1.1.3.0'; # 2=ok
617 my $cpqHeMibCondition = '1.3.6.1.4.1.232.6.1.3.0'; # hat nicht jeder
618 if ($self->{productname} =~ /4LEE/) {
619 # rindsarsch!
620 $self->{rawdata}->{$cpqHeMibCondition} = 0;
621 }
622 if (! exists $self->{rawdata}->{$cpqHeMibCondition} &&
623 ! exists $self->{rawdata}->{$cpqSeMibCondition}) { # vlt. geht doch was
624 $self->add_message(CRITICAL,
625 'snmpwalk returns no health data (cpqhlth-mib)');
626 }
627 $self->{fullrawdata} = {};
628 %{$self->{fullrawdata}} = %{$self->{rawdata}};
629 $self->{rawdata} = {};
630 if (! $self->{runtime}->{plugin}->check_messages()) {
631 # for a better simulation, only put those oids into
632 # rawdata which would also be put by a real snmp agent.
633 foreach my $table (keys %oidtables) {
634 my $oid = $oidtables{$table};
635 $oid =~ s/\./\\./g;
636 my $tmpoids = {};
637 my $tic = time;
638 map { $tmpoids->{$_} = $self->{fullrawdata}->{$_} }
639 grep /^$oid/, %{$self->{fullrawdata}};
640 my $tac = time;
641 $self->trace(2, sprintf "%03d seconds for walk %s (%d oids)",
642 $tac - $tic, $table, scalar(keys %{$tmpoids}));
643 map { $self->{rawdata}->{$_} = $tmpoids->{$_} } keys %{$tmpoids};
644 }
645 my @oids = values %oidvalues;
646 map { $self->{rawdata}->{$_} = $self->{fullrawdata}->{$_} } @oids;
647 }
648 } else {
649 my $net_snmp_version = Net::SNMP->VERSION(); # 5.002000 or 6.000000
650 #$params{'-translate'} = [
651 # -all => 0x0
652 #];
653 my ($session, $error) =
654 Net::SNMP->session(%{$self->{runtime}->{snmpparams}});
655 if (! defined $session) {
656 $self->{plugin}->add_message(CRITICAL, 'cannot create session object');
657 $self->trace(1, Data::Dumper::Dumper($self->{runtime}->{snmpparams}));
658 } else {
659 $session->translate(['-timeticks' => 0]);
660 # revMajor is often used for discovery of hp devices
661 my $cpqHeMibRev = '1.3.6.1.4.1.232.6.1';
662 my $cpqHeMibRevMajor = '1.3.6.1.4.1.232.6.1.1.0';
663 my $cpqHeMibCondition = '1.3.6.1.4.1.232.6.1.3.0';
664 my $result = $session->get_request(
665 -varbindlist => [$cpqHeMibCondition]
666 );
667 if ($self->{productname} =~ /4LEE/) {
668 # rindsarsch!
669 $result->{$cpqHeMibCondition} = 0;
670 }
671 if (!defined($result) ||
672 $result->{$cpqHeMibCondition} eq 'noSuchInstance' ||
673 $result->{$cpqHeMibCondition} eq 'noSuchObject' ||
674 $result->{$cpqHeMibCondition} eq 'endOfMibView') {
675 $self->add_message(CRITICAL,
676 'snmpwalk returns no health data (cpqhlth-mib)');
677 $session->close;
678 } else {
679 # this is not reliable. many agents return 4=failed
680 #if ($result->{$cpqHeMibCondition} != 2) {
681 # $obstacle = "cmapeerstart";
682 #}
683 }
684 }
685 if (! $self->{runtime}->{plugin}->check_messages()) {
686 # snmp peer is alive
687 $self->trace(2, sprintf "Protocol is %s",
688 $self->{runtime}->{snmpparams}->{'-version'});
689 $session->translate;
690 my $response = {}; #break the walk up in smaller pieces
691 foreach my $table (keys %oidtables) {
692 my $oid = $oidtables{$table};
693 my $tic = time;
694 my $tmpresponse = $session->get_table(
695 -baseoid => $oid);
696 if (scalar (keys %{$tmpresponse}) == 0) {
697 $self->trace(2, sprintf "maxrepetitions failed. fallback");
698 $tmpresponse = $session->get_table(
699 -maxrepetitions => 1,
700 -baseoid => $oid);
701 }
702 my $tac = time;
703 $self->trace(2, sprintf "%03d seconds for walk %s (%d oids)",
704 $tac - $tic, $table, scalar(keys %{$tmpresponse}));
705 map { $response->{$_} = $tmpresponse->{$_} } keys %{$tmpresponse};
706 }
707 my @oids = values %oidvalues;
708 my $tic = time;
709 my $tmpresponse = $session->get_request(
710 -varbindlist => \@oids,
711 );
712 my $tac = time;
713 $self->trace(2, sprintf "%03d seconds for get various (%d oids)",
714 $tac - $tic, scalar(keys %{$tmpresponse}));
715 map { $response->{$_} = $tmpresponse->{$_} } keys %{$tmpresponse};
716 $session->close();
717 $self->{rawdata} = $response;
718 }
719 }
720 return $self->{runtime}->{plugin}->check_messages();
721 }
722
723 sub set_serial {
724 my $self = shift;
725
726 my $cpqSiSysSerialNum = "1.3.6.1.4.1.232.2.2.2.1.0";
727 my $cpqSiProductName = "1.3.6.1.4.1.232.2.2.4.2.0";
728 my $cpqSeSysRomVer = "1.3.6.1.4.1.232.1.2.6.1.0";
729 my $cpqSeRedundantSysRomVer = "1.3.6.1.4.1.232.1.2.6.4.0";
730
731 $self->{serial} =
732 SNMP::Utils::get_object($self->{rawdata}, $cpqSiSysSerialNum);
733 $self->{product} =
734 SNMP::Utils::get_object($self->{rawdata}, $cpqSiProductName);
735 $self->{romversion} =
736 SNMP::Utils::get_object($self->{rawdata}, $cpqSeSysRomVer);
737 $self->{redundantromversion} =
738 SNMP::Utils::get_object($self->{rawdata}, $cpqSeRedundantSysRomVer);
739 if ($self->{romversion} && $self->{romversion} =~
740 #/(\d{2}\/\d{2}\/\d{4}).*?([ADP]{1}\d{2}).*/) {
741 /(\d{2}\/\d{2}\/\d{4}).*?Family.*?([A-Z]{1})(\d+).*/) {
742 $self->{romversion} = sprintf("%s%02d %s", $2, $3, $1);
743 } elsif ($self->{romversion} && $self->{romversion} =~
744 # "P73 07/01/2013"
745 /([ADP]{1}\d{2})\-(\d{2}\/\d{2}\/\d{4})/) {
746 $self->{romversion} = sprintf("%s %s", $1, $2);
747 } elsif ($self->{romversion} && $self->{romversion} =~
748 # U30 v2.36 (07/16/2020) ... bei Gen10
749 /([A-Z]{1}\d{2}) (v[\d\.]+) \((\d{2}\/\d{2}\/\d{4})\)/) {
750 $self->{romversion} = sprintf("%s %s", $1, $2);
751 } else {
752 # fallback if romversion is broken, redundantromversion not
753 #.1.3.6.1.4.1.232.1.2.6.1.0 = STRING: "4), Family "
754 #.1.3.6.1.4.1.232.1.2.6.3.0 = ""
755 #.1.3.6.1.4.1.232.1.2.6.4.0 = STRING: "v1.20 (08/26/2014), Family "
756 if ($self->{redundantromversion} && $self->{redundantromversion} =~
757 /(\d{2}\/\d{2}\/\d{4}).*?Family.*?([A-Z]{1})(\d+).*/) {
758 $self->{romversion} = sprintf("%s%02d %s", $2, $3, $1);
759 } elsif ($self->{redundantromversion} && $self->{redundantromversion} =~
760 /([ADP]{1}\d{2})\-(\d{2}\/\d{2}\/\d{4})/) {
761 $self->{romversion} = sprintf("%s %s", $1, $2);
762 }
763 }
764 if (!$self->{serial} && $self->{romversion}) {
765 # this probably is a very, very old server.
766 $self->{serial} = "METHUSALEM";
767 $self->{runtime}->{scrapiron} = 1;
768 }
769 $self->{serial} = $self->{serial};
770 $self->{product} = lc $self->{product};
771 $self->{romversion} = $self->{romversion};
772 $self->{runtime}->{product} = $self->{product};
773 }
774
775
776 1;