Debian Codegraph @

check_hpasm/check_hpasm-4.9/plugins-scripts/HP/Proliant/Component/PowersupplySubsystem/CLI.pm

raw
1 package HP::Proliant::Component::PowersupplySubsystem::CLI;
2 our @ISA = qw(HP::Proliant::Component::PowersupplySubsystem);
3
4 use strict;
5 use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
6
7 sub new {
8 my $class = shift;
9 my %params = @_;
10 my $self = {
11 runtime => $params{runtime},
12 rawdata => $params{rawdata},
13 powersupplies => [],
14 powerconverters => [],
15 blacklisted => 0,
16 info => undef,
17 extendedinfo => undef,
18 };
19 bless $self, $class;
20 $self->init(%params);
21 return $self;
22 }
23
24 sub init {
25 my $self = shift;
26 my %params = @_;
27 my %tmpps = (
28 runtime => $self->{runtime},
29 cpqHeFltTolPowerSupplyChassis => 1,
30 );
31 my $inblock = 0;
32 foreach (grep(/^powersupply/, split(/\n/, $self->{rawdata}))) {
33 s/^powersupply\s*//g;
34 if (/^Power supply #(\d+)/) {
35 if ($inblock) {
36 $inblock = 0;
37 push(@{$self->{powersupplies}},
38 HP::Proliant::Component::PowersupplySubsystem::Powersupply->new(%tmpps));
39 %tmpps = (
40 runtime => $self->{runtime},
41 cpqHeFltTolPowerSupplyChassis => 1,
42 );
43 }
44 $tmpps{cpqHeFltTolPowerSupplyBay} = $1;
45 $inblock = 1;
46 } elsif (/\s*Present\s+:\s+(\w+)/) {
47 $tmpps{cpqHeFltTolPowerSupplyPresent} = lc $1 eq 'yes' ? 'present' :
48 lc $1 eq 'no' ? 'absent': 'other';
49 } elsif (/\s*Redundant\s*:\s+(\w+)/) {
50 $tmpps{cpqHeFltTolPowerSupplyRedundant} = lc $1 eq 'yes' ? 'redundant' :
51 lc $1 eq 'no' ? 'notRedundant' : 'other';
52 } elsif (/\s*Condition\s*:\s+(\w+)/) {
53 $tmpps{cpqHeFltTolPowerSupplyCondition} = lc $1;
54 } elsif (/\s*Power\s*:\s+(\d+)/) {
55 $tmpps{cpqHeFltTolPowerSupplyCapacityUsed} = $1;
56 } elsif (/\s*Power Supply not present/) {
57 $tmpps{cpqHeFltTolPowerSupplyPresent} = "absent";
58 $tmpps{cpqHeFltTolPowerSupplyCondition} = "other";
59 $tmpps{cpqHeFltTolPowerSupplyRedundant} = "notRedundant";
60 } elsif (/^\s*$/) {
61 if ($inblock) {
62 $inblock = 0;
63 push(@{$self->{powersupplies}},
64 HP::Proliant::Component::PowersupplySubsystem::Powersupply->new(%tmpps));
65 %tmpps = (
66 runtime => $self->{runtime},
67 cpqHeFltTolPowerSupplyChassis => 1,
68 );
69 }
70 }
71 }
72 if ($inblock) {
73 push(@{$self->{powersupplies}},
74 HP::Proliant::Component::PowersupplySubsystem::Powersupply->new(%tmpps));
75 %tmpps = (
76 runtime => $params{runtime},
77 );
78 }
79 }
80
81 1;