| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package storage::hp::3par::ssh::mode::psu; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); |
| 28 |
|
| 29 |
sub psu_long_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf( |
| 33 |
"checking node '%s' power supply '%s'", |
| 34 |
$options{instance_value}->{node_id}, |
| 35 |
$options{instance_value}->{psu_id} |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
sub prefix_psu_output { |
| 40 |
my ($self, %options) = @_; |
| 41 |
|
| 42 |
return sprintf( |
| 43 |
"node '%s' power supply '%s' ", |
| 44 |
$options{instance_value}->{node_id}, |
| 45 |
$options{instance_value}->{psu_id} |
| 46 |
); |
| 47 |
} |
| 48 |
|
| 49 |
sub set_counters { |
| 50 |
my ($self, %options) = @_; |
| 51 |
|
| 52 |
$self->{maps_counters_type} = [ |
| 53 |
{ |
| 54 |
name => 'psu', type => 3, cb_prefix_output => 'prefix_psu_output', cb_long_output => 'psu_long_output', indent_long_output => ' ', message_multiple => 'All power supplies are ok', |
| 55 |
group => [ |
| 56 |
{ name => 'global', type => 0 }, |
| 57 |
{ name => 'ac', type => 0 }, |
| 58 |
{ name => 'dc', type => 0 }, |
| 59 |
{ name => 'fan', type => 0 }, |
| 60 |
{ name => 'battery', type => 0 } |
| 61 |
] |
| 62 |
} |
| 63 |
]; |
| 64 |
|
| 65 |
$self->{maps_counters}->{global} = [ |
| 66 |
{ |
| 67 |
label => 'status', |
| 68 |
type => 2, |
| 69 |
critical_default => '%{status} !~ /ok/i', |
| 70 |
set => { |
| 71 |
key_values => [ { name => 'status' }, { name => 'node_id' }, { name => 'psu_id' } ], |
| 72 |
output_template => 'status: %s', |
| 73 |
closure_custom_perfdata => sub { return 0; }, |
| 74 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 75 |
} |
| 76 |
} |
| 77 |
]; |
| 78 |
|
| 79 |
foreach ('ac', 'dc', 'fan', 'battery') { |
| 80 |
$self->{maps_counters}->{$_} = [ |
| 81 |
{ |
| 82 |
label => $_ . '-status', |
| 83 |
type => 2, |
| 84 |
critical_default => '%{status} !~ /ok/i', |
| 85 |
set => { |
| 86 |
key_values => [ { name => 'status' }, { name => 'node_id' }, { name => 'psu_id' } ], |
| 87 |
output_template => $_ . ' status: %s', |
| 88 |
closure_custom_perfdata => sub { return 0; }, |
| 89 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 90 |
} |
| 91 |
} |
| 92 |
]; |
| 93 |
} |
| 94 |
|
| 95 |
push @{$self->{maps_counters}->{battery}}, |
| 96 |
{ label => 'charge-remaining', nlabel => 'battery.charge.remaining.percent', set => { |
| 97 |
key_values => [ { name => 'capacity' }, { name => 'node_id' }, { name => 'psu_id' } ], |
| 98 |
output_template => 'remaining capacity: %.2f %%', |
| 99 |
closure_custom_perfdata => sub { |
| 100 |
my ($self, %options) = @_; |
| 101 |
|
| 102 |
$self->{output}->perfdata_add( |
| 103 |
nlabel => $self->{nlabel}, |
| 104 |
unit => '%', |
| 105 |
instances => ['node' . $self->{result_values}->{node_id}, 'psu' . $self->{result_values}->{psu_id}], |
| 106 |
value => sprintf('%.2f', $self->{result_values}->{capacity}), |
| 107 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 108 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 109 |
min => 0, max => 100 |
| 110 |
); |
| 111 |
} |
| 112 |
} |
| 113 |
}, |
| 114 |
{ label => 'charge-remaining-minutes', nlabel => 'battery.charge.remaining.minutes', set => { |
| 115 |
key_values => [ { name => 'time' }, { name => 'node_id' }, { name => 'psu_id' } ], |
| 116 |
output_template => 'remaining time: %s minutes', |
| 117 |
closure_custom_perfdata => sub { |
| 118 |
my ($self, %options) = @_; |
| 119 |
|
| 120 |
$self->{output}->perfdata_add( |
| 121 |
nlabel => $self->{nlabel}, |
| 122 |
unit => 'm', |
| 123 |
instances => ['node' . $self->{result_values}->{node_id}, 'psu' . $self->{result_values}->{psu_id}], |
| 124 |
value => sprintf('%s', $self->{result_values}->{time}), |
| 125 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 126 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 127 |
min => 0 |
| 128 |
); |
| 129 |
} |
| 130 |
} |
| 131 |
}; |
| 132 |
} |
| 133 |
|
| 134 |
sub new { |
| 135 |
my ($class, %options) = @_; |
| 136 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 137 |
bless $self, $class; |
| 138 |
|
| 139 |
$options{options}->add_options(arguments => { |
| 140 |
'filter-node-id:s' => { name => 'filter_node_id' }, |
| 141 |
'filter-psu-id:s' => { name => 'filter_psu_id' } |
| 142 |
}); |
| 143 |
|
| 144 |
return $self; |
| 145 |
} |
| 146 |
|
| 147 |
sub manage_selection { |
| 148 |
my ($self, %options) = @_; |
| 149 |
|
| 150 |
my ($content) = $options{custom}->execute_command(commands => ['shownode -ps -verbose']); |
| 151 |
#---------------Node 0 PS 0---------------- |
| 152 |
#Node ID : 0 |
| 153 |
#Power Supply ID : 0 |
| 154 |
#Manufacturer : XYRATEX |
| 155 |
#Assembly Part : 682372-001 |
| 156 |
#Assembly Serial Number : 5CQLQAXXXXXXX1 |
| 157 |
#State : OK |
| 158 |
#Fan State : OK |
| 159 |
#Fan Speed : Low |
| 160 |
#AC State : OK |
| 161 |
#DC State : OK |
| 162 |
#Battery State : OK |
| 163 |
#Battery Detail State : normal |
| 164 |
#Battery Charge State : FullyCharged |
| 165 |
#Battery Charge Level(%) : 100 |
| 166 |
#Max Battery Life(mins) : 16 |
| 167 |
# |
| 168 |
#---------------Node 0 PS 1---------------- |
| 169 |
#Node ID : 0 |
| 170 |
#Power Supply ID : 1 |
| 171 |
#Manufacturer : XYRATEX |
| 172 |
#Assembly Part : 682372-001 |
| 173 |
#Assembly Serial Number : 5CQLQAXXXXXXX2 |
| 174 |
#State : OK |
| 175 |
#Fan State : OK |
| 176 |
#Fan Speed : Low |
| 177 |
#AC State : OK |
| 178 |
#DC State : OK |
| 179 |
#Battery State : OK |
| 180 |
#Battery Detail State : normal |
| 181 |
#Battery Charge State : FullyCharged |
| 182 |
#Battery Charge Level(%) : 100 |
| 183 |
#Max Battery Life(mins) : 16 |
| 184 |
|
| 185 |
$self->{psu} = {}; |
| 186 |
while ($content =~ /^(Node ID.*?)(?=Node ID|\Z$)/msig) { |
| 187 |
my $entry = $1; |
| 188 |
my ($node_id, $psu_id); |
| 189 |
$node_id = $1 if ($entry =~ /^Node\s+ID\s*:\s*(\S+)/msi); |
| 190 |
$psu_id = $1 if ($entry =~ /^Power\s+Supply\s+ID\s*:\s*(\S+)/msi); |
| 191 |
next if (!defined($node_id)); |
| 192 |
|
| 193 |
next if (defined($self->{option_results}->{filter_node_id}) && $self->{option_results}->{filter_node_id} ne '' && |
| 194 |
$node_id !~ /$self->{option_results}->{filter_node_id}/); |
| 195 |
next if (defined($self->{option_results}->{filter_psu_id}) && $self->{option_results}->{filter_psu_id} ne '' && |
| 196 |
$psu_id !~ /$self->{option_results}->{filter_psu_id}/); |
| 197 |
|
| 198 |
$self->{psu}->{ $node_id . ':' . $psu_id } = { |
| 199 |
node_id => $node_id, |
| 200 |
psu_id => $psu_id, |
| 201 |
global => { node_id => $node_id, psu_id => $psu_id }, |
| 202 |
ac => { node_id => $node_id, psu_id => $psu_id }, |
| 203 |
dc => { node_id => $node_id, psu_id => $psu_id }, |
| 204 |
fan => { node_id => $node_id, psu_id => $psu_id }, |
| 205 |
battery => { node_id => $node_id, psu_id => $psu_id }, |
| 206 |
}; |
| 207 |
$self->{psu}->{ $node_id . ':' . $psu_id }->{global}->{status} = $1 if ($entry =~ /^State\s*:\s*(\S+)/msi); |
| 208 |
$self->{psu}->{ $node_id . ':' . $psu_id }->{ac}->{status} = $1 if ($entry =~ /^AC\s+State\s*:\s*(\S+)/msi); |
| 209 |
$self->{psu}->{ $node_id . ':' . $psu_id }->{dc}->{status} = $1 if ($entry =~ /^DC\s+State\s*:\s*(\S+)/msi); |
| 210 |
$self->{psu}->{ $node_id . ':' . $psu_id }->{fan}->{status} = $1 if ($entry =~ /^Fan\s+State\s*:\s*(\S+)/msi); |
| 211 |
$self->{psu}->{ $node_id . ':' . $psu_id }->{battery}->{status} = $1 if ($entry =~ /^Battery\s+State\s*:\s*(\S+)/msi); |
| 212 |
$self->{psu}->{ $node_id . ':' . $psu_id }->{battery}->{capacity} = $1 if ($entry =~ /^Battery\s+Charge\s+Level.*?:\s*(\S+)/msi); |
| 213 |
$self->{psu}->{ $node_id . ':' . $psu_id }->{battery}->{time} = $1 if ($entry =~ /^Max\s+Battery\s+Life.*?:\s*(\S+)/msi); |
| 214 |
} |
| 215 |
|
| 216 |
if (scalar(keys %{$self->{psu}}) <= 0) { |
| 217 |
$self->{output}->add_option_msg(short_msg => "Couldn't get power supplies information"); |
| 218 |
$self->{output}->option_exit(); |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
1; |
| 223 |
|
| 224 |
__END__ |
| 225 |
|
| 226 |
=head1 MODE |
| 227 |
|
| 228 |
Check power supplies. |
| 229 |
|
| 230 |
=over 8 |
| 231 |
|
| 232 |
=item B<--filter-node-id> |
| 233 |
|
| 234 |
Filter nodes by ID (can be a regexp). |
| 235 |
|
| 236 |
=item B<--filter-psu-id> |
| 237 |
|
| 238 |
Filter power supplies by ID (can be a regexp). |
| 239 |
|
| 240 |
=item B<--unknown-status> |
| 241 |
|
| 242 |
Define the conditions to match for the status to be UNKNOWN. |
| 243 |
You can use the following variables: %{status}, %{node_id}, %{psu_id} |
| 244 |
|
| 245 |
=item B<--warning-status> |
| 246 |
|
| 247 |
Define the conditions to match for the status to be WARNING. |
| 248 |
You can use the following variables: %{status}, %{node_id}, %{psu_id} |
| 249 |
|
| 250 |
=item B<--critical-status> |
| 251 |
|
| 252 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /ok/i'). |
| 253 |
You can use the following variables: %{status}, %{node_id}, %{psu_id} |
| 254 |
|
| 255 |
=item B<--unknown-ac-status> |
| 256 |
|
| 257 |
Set unknown threshold for AC status. |
| 258 |
You can use the following variables: %{status}, %{node_id}, %{psu_id} |
| 259 |
|
| 260 |
=item B<--warning-ac-status> |
| 261 |
|
| 262 |
Set warning threshold for AC status. |
| 263 |
You can use the following variables: %{status}, %{node_id}, %{psu_id} |
| 264 |
|
| 265 |
=item B<--critical-ac-status> |
| 266 |
|
| 267 |
Set critical threshold for AC status (default: '%{status} !~ /ok/i'). |
| 268 |
You can use the following variables: %{status}, %{node_id}, %{psu_id} |
| 269 |
|
| 270 |
=item B<--unknown-dc-status> |
| 271 |
|
| 272 |
Set unknown threshold for DC status. |
| 273 |
You can use the following variables: %{status}, %{node_id}, %{psu_id} |
| 274 |
|
| 275 |
=item B<--warning-dc-status> |
| 276 |
|
| 277 |
Set warning threshold for DC status. |
| 278 |
You can use the following variables: %{status}, %{node_id}, %{psu_id} |
| 279 |
|
| 280 |
=item B<--critical-dc-status> |
| 281 |
|
| 282 |
Set critical threshold for DC status (default: '%{status} !~ /ok/i'). |
| 283 |
You can use the following variables: %{status}, %{node_id}, %{psu_id} |
| 284 |
|
| 285 |
=item B<--unknown-fan-status> |
| 286 |
|
| 287 |
Set unknown threshold for fan status. |
| 288 |
You can use the following variables: %{status}, %{node_id}, %{psu_id} |
| 289 |
|
| 290 |
=item B<--warning-fan-status> |
| 291 |
|
| 292 |
Set warning threshold for fan status. |
| 293 |
You can use the following variables: %{status}, %{node_id}, %{psu_id} |
| 294 |
|
| 295 |
=item B<--critical-fan-status> |
| 296 |
|
| 297 |
Set critical threshold for fan status (default: '%{status} !~ /ok/i'). |
| 298 |
You can use the following variables: %{status}, %{node_id}, %{psu_id} |
| 299 |
|
| 300 |
=item B<--unknown-battery-status> |
| 301 |
|
| 302 |
Set unknown threshold for battery status. |
| 303 |
You can use the following variables: %{status}, %{node_id}, %{psu_id} |
| 304 |
|
| 305 |
=item B<--warning-battery-status> |
| 306 |
|
| 307 |
Set warning threshold for battery status. |
| 308 |
You can use the following variables: %{status}, %{node_id}, %{psu_id} |
| 309 |
|
| 310 |
=item B<--critical-battery-status> |
| 311 |
|
| 312 |
Set critical threshold for battery status (default: '%{status} !~ /ok/i'). |
| 313 |
You can use the following variables: %{status}, %{node_id}, %{psu_id} |
| 314 |
|
| 315 |
=item B<--warning-*> B<--critical-*> |
| 316 |
|
| 317 |
Thresholds. |
| 318 |
Can be: 'charge-remaining', 'charge-remaining-minutes. |
| 319 |
|
| 320 |
=back |
| 321 |
|
| 322 |
=cut |