| 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::fujitsu::eternus::dx::ssh::mode::psu; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::misc; |
| 28 |
|
| 29 |
my $thresholds = { |
| 30 |
psu => [ |
| 31 |
['Normal', 'OK'], |
| 32 |
['Warning', 'WARNING'], |
| 33 |
['Maintenance', 'WARNING'], |
| 34 |
['Check1', 'WARNING'], |
| 35 |
['Undefined', 'WARNING'], |
| 36 |
['Normal (Inside unused parts)', 'WARNING'], |
| 37 |
['Error', 'CRITICAL'], |
| 38 |
['Unknown', 'UNKNOWN'] |
| 39 |
] |
| 40 |
}; |
| 41 |
|
| 42 |
sub new { |
| 43 |
my ($class, %options) = @_; |
| 44 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 45 |
bless $self, $class; |
| 46 |
|
| 47 |
$options{options}->add_options(arguments => { |
| 48 |
'filter:s@' => { name => 'filter' }, |
| 49 |
'threshold-overload:s@' => { name => 'threshold_overload' }, |
| 50 |
'no-component:s' => { name => 'no_component' } |
| 51 |
}); |
| 52 |
|
| 53 |
$self->{no_components} = undef; |
| 54 |
return $self; |
| 55 |
} |
| 56 |
|
| 57 |
sub check_options { |
| 58 |
my ($self, %options) = @_; |
| 59 |
$self->SUPER::init(%options); |
| 60 |
|
| 61 |
$self->{filter} = []; |
| 62 |
foreach my $val (@{$self->{option_results}->{filter}}) { |
| 63 |
next if (!defined($val) || $val eq ''); |
| 64 |
my @values = split (/,/, $val); |
| 65 |
push @{$self->{filter}}, { filter => $values[0], instance => $values[1] }; |
| 66 |
} |
| 67 |
|
| 68 |
$self->{overload_th} = {}; |
| 69 |
foreach my $val (@{$self->{option_results}->{threshold_overload}}) { |
| 70 |
if ($val !~ /^(.*?),(.*?),(.*)$/) { |
| 71 |
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); |
| 72 |
$self->{output}->option_exit(); |
| 73 |
} |
| 74 |
my ($section, $status, $filter) = ($1, $2, $3); |
| 75 |
if ($self->{output}->is_litteral_status(status => $status) == 0) { |
| 76 |
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); |
| 77 |
$self->{output}->option_exit(); |
| 78 |
} |
| 79 |
$self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); |
| 80 |
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; |
| 81 |
} |
| 82 |
|
| 83 |
if (defined($self->{option_results}->{no_component})) { |
| 84 |
if ($self->{option_results}->{no_component} ne '') { |
| 85 |
$self->{no_components} = $self->{option_results}->{no_component}; |
| 86 |
} else { |
| 87 |
$self->{no_components} = 'critical'; |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
sub run { |
| 93 |
my ($self, %options) = @_; |
| 94 |
|
| 95 |
my ($stdout) = $options{custom}->execute_command( |
| 96 |
command => 'show', |
| 97 |
command_options => "enclosure-status -type all\n", |
| 98 |
ssh_pipe => 1 |
| 99 |
); |
| 100 |
|
| 101 |
#Controller Enclosure #0 Information |
| 102 |
#... |
| 103 |
#Controller Enclosure #0 Status |
| 104 |
# Controller Module Status/Status Code |
| 105 |
# CM#0 [Normal / 0xE001] |
| 106 |
# CM#1 [Normal / 0xE001] |
| 107 |
# PCIe Flash Module Status/Status Code |
| 108 |
# CM#0 PFM#0 [Undefined / 0x6000] |
| 109 |
# CM#0 PFM#1 [Undefined / 0x6000] |
| 110 |
# CM#1 PFM#0 [Undefined / 0x6000] |
| 111 |
# CM#1 PFM#1 [Undefined / 0x6000] |
| 112 |
# Power Supply Unit Status/Status Code |
| 113 |
# PSU#0 [Normal / 0xE001] |
| 114 |
# PSU#1 [Normal / 0xE001] |
| 115 |
# |
| 116 |
#Controller Enclosure #1 Information |
| 117 |
#.. |
| 118 |
#Controller Module Status/Status Code |
| 119 |
# CM#0 [Normal / 0xE001] |
| 120 |
# CM#1 [Normal / 0xE001] |
| 121 |
# PCIe Flash Module Status/Status Code |
| 122 |
# CM#0 PFM#0 [Undefined / 0x6000] |
| 123 |
# CM#0 PFM#1 [Undefined / 0x6000] |
| 124 |
# CM#1 PFM#0 [Undefined / 0x6000] |
| 125 |
# CM#1 PFM#1 [Undefined / 0x6000] |
| 126 |
# Power Supply Unit Status/Status Code |
| 127 |
# PSU#0 [Normal / 0xE001] |
| 128 |
# PSU#1 [Normal / 0xE001] |
| 129 |
# |
| 130 |
#Frontend Enclosure Information |
| 131 |
#... |
| 132 |
#Frontend Enclosure Status |
| 133 |
# Front End Router Status/Status Code |
| 134 |
# Power Supply Unit Status/Status Code |
| 135 |
# PSU#0 [Normal / 0xE001] |
| 136 |
# PSU#1 [Normal / 0xE001] |
| 137 |
|
| 138 |
my $total_components = 0; |
| 139 |
while ($stdout =~ /^(Controller|Frontend|Drive)\s+Enclosure\s+(#\d+\s+|)Status(.*?)(\n\n|\Z)/msg) { |
| 140 |
my ($type, $num, $content) = ($1, $2, $3); |
| 141 |
|
| 142 |
my $prefix = 'fe'; |
| 143 |
if ($type =~ /controller/i) { |
| 144 |
$prefix = 'ce' . centreon::plugins::misc::trim($num); |
| 145 |
} elsif ($type =~ /drive/i) { |
| 146 |
$prefix = 'drive' . centreon::plugins::misc::trim($num); |
| 147 |
} |
| 148 |
while ($content =~ /PSU#(\d+)\s+\[\s*(\S+)/msig) { |
| 149 |
my ($psu_number, $psu_status) = ($1, $2); |
| 150 |
my $psu_name = $prefix . '_' . $psu_number; |
| 151 |
|
| 152 |
next if ($self->check_filter(section => 'psu', instance => $psu_name)); |
| 153 |
|
| 154 |
$total_components++; |
| 155 |
$self->{output}->output_add(long_msg => sprintf("Power Supply '%s' status is '%s'", $psu_name, $psu_status)); |
| 156 |
my $exit = $self->get_severity(section => 'psu', value => $psu_status); |
| 157 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 158 |
$self->{output}->output_add( |
| 159 |
severity => $exit, |
| 160 |
short_msg => sprintf("Power Supply '%s' status is '%s'.", $psu_name, $psu_status) |
| 161 |
); |
| 162 |
} |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
$self->{output}->output_add( |
| 167 |
severity => 'OK', |
| 168 |
short_msg => sprintf("All %d power supplies are ok.", $total_components) |
| 169 |
); |
| 170 |
|
| 171 |
if (defined($self->{option_results}->{no_component}) && $total_components == 0) { |
| 172 |
$self->{output}->output_add( |
| 173 |
severity => $self->{no_components}, |
| 174 |
short_msg => 'No components are checked.' |
| 175 |
); |
| 176 |
} |
| 177 |
|
| 178 |
$self->{output}->display(); |
| 179 |
$self->{output}->exit(); |
| 180 |
} |
| 181 |
|
| 182 |
sub check_filter { |
| 183 |
my ($self, %options) = @_; |
| 184 |
|
| 185 |
foreach (@{$self->{filter}}) { |
| 186 |
if ($options{section} =~ /$_->{filter}/) { |
| 187 |
if (!defined($options{instance}) && !defined($_->{instance})) { |
| 188 |
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); |
| 189 |
return 1; |
| 190 |
} elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) { |
| 191 |
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); |
| 192 |
return 1; |
| 193 |
} |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
return 0; |
| 198 |
} |
| 199 |
|
| 200 |
sub get_severity { |
| 201 |
my ($self, %options) = @_; |
| 202 |
my $status = 'UNKNOWN'; # default |
| 203 |
|
| 204 |
if (defined($self->{overload_th}->{$options{section}})) { |
| 205 |
foreach (@{$self->{overload_th}->{$options{section}}}) { |
| 206 |
if ($options{value} =~ /$_->{filter}/i) { |
| 207 |
$status = $_->{status}; |
| 208 |
return $status; |
| 209 |
} |
| 210 |
} |
| 211 |
} |
| 212 |
foreach (@{$thresholds->{$options{section}}}) { |
| 213 |
if ($options{value} =~ /$$_[0]/i) { |
| 214 |
$status = $$_[1]; |
| 215 |
return $status; |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
return $status; |
| 220 |
} |
| 221 |
|
| 222 |
1; |
| 223 |
|
| 224 |
__END__ |
| 225 |
|
| 226 |
=head1 MODE |
| 227 |
|
| 228 |
Check power supplies. |
| 229 |
|
| 230 |
Command used: show enclosure-status -type all |
| 231 |
|
| 232 |
=over 8 |
| 233 |
|
| 234 |
=item B<--filter> |
| 235 |
|
| 236 |
Exclude some parts (comma separated list) |
| 237 |
You can also exclude items from specific instances: --filter=psu,ce#0_0 |
| 238 |
|
| 239 |
=item B<--threshold-overload> |
| 240 |
|
| 241 |
Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,status,regexp). |
| 242 |
Example: --threshold-overload='psu,CRITICAL,^(?!(Normal)$)' |
| 243 |
|
| 244 |
=item B<--no-component> |
| 245 |
|
| 246 |
Define the expected status if no components are found (default: critical). |
| 247 |
|
| 248 |
=back |
| 249 |
|
| 250 |
=cut |