Debian Codegraph @

check_hpasm/src/plugins-scripts/HP/BladeSystem/Component/PowerSupplySubsystem.pm

raw
1 package HP::BladeSystem::Component::PowerSupplySubsystem;
2 our @ISA = qw(HP::BladeSystem::Component);
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 method => $params{method},
14 power_supplies => [],
15 blacklisted => 0,
16 info => undef,
17 extendedinfo => undef,
18 };
19 bless $self, $class;
20 $self->init();
21 return $self;
22 }
23
24 sub init {
25 my $self = shift;
26 my $oids = {
27 cpqRackPowerSupplyEntry => '1.3.6.1.4.1.232.22.2.5.1.1.1',
28 cpqRackPowerSupplyRack => '1.3.6.1.4.1.232.22.2.5.1.1.1.1',
29 cpqRackPowerSupplyChassis => '1.3.6.1.4.1.232.22.2.5.1.1.1.2',
30 cpqRackPowerSupplyIndex => '1.3.6.1.4.1.232.22.2.5.1.1.1.3',
31 cpqRackPowerSupplyEnclosureName => '1.3.6.1.4.1.232.22.2.5.1.1.1.4',
32 cpqRackPowerSupplySerialNum => '1.3.6.1.4.1.232.22.2.5.1.1.1.5',
33 cpqRackPowerSupplySparePartNumber => '1.3.6.1.4.1.232.22.2.5.1.1.1.7',
34 cpqRackPowerSupplyFWRev => '1.3.6.1.4.1.232.22.2.5.1.1.1.8',
35 cpqRackPowerSupplyMaxPwrOutput => '1.3.6.1.4.1.232.22.2.5.1.1.1.9',
36 cpqRackPowerSupplyCurPwrOutput => '1.3.6.1.4.1.232.22.2.5.1.1.1.10',
37 cpqRackPowerSupplyIntakeTemp => '1.3.6.1.4.1.232.22.2.5.1.1.1.12',
38 cpqRackPowerSupplyExhaustTemp => '1.3.6.1.4.1.232.22.2.5.1.1.1.13',
39 cpqRackPowerSupplyStatus => '1.3.6.1.4.1.232.22.2.5.1.1.1.14',
40 cpqRackPowerSupplySupplyInputLineStatus => '1.3.6.1.4.1.232.22.2.5.1.1.1.15',
41 cpqRackPowerSupplyPresent => '1.3.6.1.4.1.232.22.2.5.1.1.1.16',
42 cpqRackPowerSupplyCondition => '1.3.6.1.4.1.232.22.2.5.1.1.1.17',
43 cpqRackPowerSupplySupplyInputLineStatusValue => {
44 1 => 'noError',
45 2 => 'lineOverVoltage',
46 3 => 'lineUnderVoltage',
47 4 => 'lineHit',
48 5 => 'brownOut',
49 6 => 'linePowerLoss',
50 },
51 cpqRackPowerSupplyStatusValue => {
52 1 => 'noError',
53 2 => 'generalFailure',
54 3 => 'bistFailure',
55 4 => 'fanFailure',
56 5 => 'tempFailure',
57 6 => 'interlockOpen',
58 7 => 'epromFailed',
59 8 => 'vrefFailed',
60 9 => 'dacFailed',
61 10 => 'ramTestFailed',
62 11 => 'voltageChannelFailed',
63 12 => 'orringdiodeFailed',
64 13 => 'brownOut',
65 14 => 'giveupOnStartup',
66 15 => 'nvramInvalid',
67 16 => 'calibrationTableInvalid',
68 },
69 cpqRackPowerSupplyPresentValue => {
70 1 => 'other',
71 2 => 'absent',
72 3 => 'present',
73 },
74 cpqRackPowerSupplyConditionValue => {
75 1 => 'other',
76 2 => 'ok',
77 3 => 'degraded',
78 4 => 'failed',
79 },
80 };
81
82
83 # INDEX { cpqRackPowerSupplyRack, cpqRackPowerSupplyChassis, cpqRackPowerSupplyIndex }
84 foreach ($self->get_entries($oids, 'cpqRackPowerSupplyEntry')) {
85 push(@{$self->{power_supplies}},
86 HP::BladeSystem::Component::PowerSupplySubsystem::PowerSupply->new(%{$_}));
87 }
88 }
89
90 sub check {
91 my $self = shift;
92 my $total_current_watt = 0;
93 my $total_max_watt = 0;
94 my $total_in_temp = 0;
95 my $total_out_temp = 0;
96 my $num_ps = 0;
97 foreach (@{$self->{power_supplies}}) {
98 $_->check() if $_->{cpqRackPowerSupplyPresent} eq 'present' ||
99 $self->{runtime}->{options}->{verbose} >= 3; # absent nur bei -vvv
100 if ($_->{cpqRackPowerSupplyPresent} eq 'present') {
101 $total_max_watt += $_->{cpqRackPowerSupplyMaxPwrOutput};
102 $total_current_watt += $_->{cpqRackPowerSupplyCurPwrOutput};
103 $total_in_temp += $_->{cpqRackPowerSupplyIntakeTemp}
104 if $_->{cpqRackPowerSupplyIntakeTemp} != -1;
105 $total_out_temp += $_->{cpqRackPowerSupplyExhaustTemp}
106 if $_->{cpqRackPowerSupplyExhaustTemp} != -1;
107 $num_ps++;
108 }
109 }
110 $self->{runtime}->{plugin}->add_perfdata(
111 label => 'watt_total',
112 value => $total_current_watt,
113 warning => $total_max_watt,
114 critical => $total_max_watt,
115 );
116 #$self->{runtime}->{plugin}->add_perfdata(
117 # label => 'watt_total_pct',
118 # value => ($total_current_watt == 0 ? 0 :
119 # sprintf("%.2f",
120 # ($total_current_watt / $total_max_watt * 100))),
121 # warning => 100,
122 # critical => 100,
123 # uom => '%',
124 #);
125 if ($total_in_temp) {
126 $self->{runtime}->{plugin}->add_perfdata(
127 label => 'in_temp',
128 value => $total_in_temp / $num_ps,
129 );
130 }
131 if ($total_out_temp) {
132 $self->{runtime}->{plugin}->add_perfdata(
133 label => 'out_temp',
134 value => $total_out_temp / $num_ps,
135 );
136 }
137 }
138
139 sub dump {
140 my $self = shift;
141 foreach (@{$self->{power_supplies}}) {
142 $_->dump() if $_->{cpqRackPowerSupplyPresent} eq 'present' ||
143 $self->{runtime}->{options}->{verbose} >= 3; # absent nur bei -vvv
144 }
145 }
146
147
148 package HP::BladeSystem::Component::PowerSupplySubsystem::PowerSupply;
149 our @ISA = qw(HP::BladeSystem::Component::PowerSupplySubsystem);
150
151 use strict;
152 use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
153
154 sub new {
155 my $class = shift;
156 my %params = @_;
157 my $self = {
158 runtime => $params{runtime},
159 rawdata => $params{rawdata},
160 method => $params{method},
161 blacklisted => 0,
162 info => undef,
163 extendedinfo => undef,
164 };
165 map { $self->{$_} = $params{$_} } grep /cpqRackPowerSupply/, keys %params;
166 $self->{name} = $params{cpqRackPowerSupplyRack}.
167 ':'.$params{cpqRackPowerSupplyChassis}.
168 ':'.$params{cpqRackPowerSupplyIndex};
169 $self->{serfw} = sprintf "Ser: %s, FW: %s", $self->{cpqRackPowerSupplySerialNum}, $self->{cpqRackPowerSupplyFWRev};
170 bless $self, $class;
171 return $self;
172 }
173
174 sub check {
175 my $self = shift;
176 $self->blacklist('ps', $self->{name});
177 my $info = sprintf 'power supply %s is %s, condition is %s (%s)',
178 $self->{name}, $self->{cpqRackPowerSupplyPresent},
179 $self->{cpqRackPowerSupplyCondition}, $self->{serfw};
180 $self->add_info($info);
181 if ($self->{cpqRackPowerSupplyPresent} eq 'present') {
182 if ($self->{cpqRackPowerSupplyCondition} eq 'degraded') {
183 $info .= sprintf " (SparePartNum %s)", $self->{cpqRackPowerSupplySparePartNumber};
184 $self->add_message(WARNING, $info);
185 $self->add_info(sprintf 'power supply %s status is %s, inp.line status is %s',
186 $self->{name}, $self->{cpqRackPowerSupplyStatus},
187 $self->{cpqRackPowerSupplySupplyInputLineStatus});
188 } elsif ($self->{cpqRackPowerSupplyCondition} eq 'failed') {
189 $info .= sprintf " (SparePartNum %s)", $self->{cpqRackPowerSupplySparePartNumber};
190 $self->add_message(CRITICAL, $info);
191 $self->add_info(sprintf 'power supply %s status is %s, inp.line status is %s',
192 $self->{name}, $self->{cpqRackPowerSupplyStatus},
193 $self->{cpqRackPowerSupplySupplyInputLineStatus});
194 }
195 if ($self->{runtime}->{options}->{perfdata} != 2) {
196 $self->{runtime}->{plugin}->add_perfdata(
197 label => sprintf('watt_%s', $self->{name}),
198 value => $self->{cpqRackPowerSupplyCurPwrOutput},
199 warning => $self->{cpqRackPowerSupplyMaxPwrOutput},
200 critical => $self->{cpqRackPowerSupplyMaxPwrOutput}
201 );
202 #$self->{runtime}->{plugin}->add_perfdata(
203 # label => sprintf('watt_pct_%s', $self->{name}),
204 # value => ($self->{cpqRackPowerSupplyCurPwrOutput} == 0 ? 0 :
205 # sprintf ("%.2f",
206 # ($self->{cpqRackPowerSupplyCurPwrOutput} /
207 # $self->{cpqRackPowerSupplyMaxPwrOutput} * 100))),
208 # warning => 100,
209 # critical => 100,
210 # uom => '%',
211 #);
212 if ($self->{cpqRackPowerSupplyIntakeTemp} != -1) {
213 $self->{runtime}->{plugin}->add_perfdata(
214 label => sprintf('in_temp_%s', $self->{name}),
215 value => $self->{cpqRackPowerSupplyIntakeTemp},
216 );
217 }
218 if ($self->{cpqRackPowerSupplyExhaustTemp} != -1) {
219 $self->{runtime}->{plugin}->add_perfdata(
220 label => sprintf('out_temp_%s', $self->{name}),
221 value => $self->{cpqRackPowerSupplyExhaustTemp},
222 );
223 }
224 }
225 }
226 }
227
228 sub dump {
229 my $self = shift;
230 printf "[POWER_SUPPLY%s]\n", $self->{name};
231 foreach (qw(cpqRackPowerSupplyRack cpqRackPowerSupplyChassis cpqRackPowerSupplyIndex cpqRackPowerSupplyEnclosureName cpqRackPowerSupplySerialNum cpqRackPowerSupplySparePartNumber cpqRackPowerSupplyFWRev cpqRackPowerSupplyMaxPwrOutput cpqRackPowerSupplyCurPwrOutput cpqRackPowerSupplyIntakeTemp cpqRackPowerSupplyExhaustTemp cpqRackPowerSupplyStatus cpqRackPowerSupplySupplyInputLineStatus cpqRackPowerSupplyPresent cpqRackPowerSupplyCondition)) {
232 printf "%s: %s\n", $_, $self->{$_};
233 }
234 printf "\n";
235 }
236
237
238 1;