| 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 hardware::server::ibm::hmc::ssh::mode::ledstatus; |
| 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 custom_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return 'led state : ' . $self->{result_values}->{ledstate}; |
| 33 |
} |
| 34 |
|
| 35 |
sub prefix_physical_output { |
| 36 |
my ($self, %options) = @_; |
| 37 |
|
| 38 |
return "System '" . $options{instance_value}->{display} . "' physical "; |
| 39 |
} |
| 40 |
|
| 41 |
sub prefix_virtuallpar_output { |
| 42 |
my ($self, %options) = @_; |
| 43 |
|
| 44 |
return "Virtual partition '" . $options{instance_value}->{display} . "' "; |
| 45 |
} |
| 46 |
|
| 47 |
sub set_counters { |
| 48 |
my ($self, %options) = @_; |
| 49 |
|
| 50 |
$self->{maps_counters_type} = [ |
| 51 |
{ name => 'physical', type => 1, cb_prefix_output => 'prefix_physical_output', message_multiple => 'All physical status are ok' }, |
| 52 |
{ name => 'virtuallpar', type => 1, cb_prefix_output => 'prefix_virtuallpar_output', message_multiple => 'All virtual partition status are ok' } |
| 53 |
]; |
| 54 |
|
| 55 |
$self->{maps_counters}->{physical} = [ |
| 56 |
{ label => 'physical-status', type => 2, critical_default => '%{ledstate} =~ /on/', set => { |
| 57 |
key_values => [ { name => 'ledstate' }, { name => 'display' } ], |
| 58 |
closure_custom_output => $self->can('custom_status_output'), |
| 59 |
closure_custom_perfdata => sub { return 0; }, |
| 60 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 61 |
} |
| 62 |
} |
| 63 |
]; |
| 64 |
|
| 65 |
$self->{maps_counters}->{virtuallpar} = [ |
| 66 |
{ label => 'virtuallpar-status', type => 2, critical_default => '%{ledstate} =~ /on/', set => { |
| 67 |
key_values => [ { name => 'ledstate' }, { name => 'display' } ], |
| 68 |
closure_custom_output => $self->can('custom_status_output'), |
| 69 |
closure_custom_perfdata => sub { return 0; }, |
| 70 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 71 |
} |
| 72 |
} |
| 73 |
]; |
| 74 |
} |
| 75 |
|
| 76 |
sub new { |
| 77 |
my ($class, %options) = @_; |
| 78 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 79 |
bless $self, $class; |
| 80 |
|
| 81 |
$options{options}->add_options(arguments => { |
| 82 |
'filter-name:s' => { name => 'filter_name' } |
| 83 |
}); |
| 84 |
|
| 85 |
return $self; |
| 86 |
} |
| 87 |
|
| 88 |
sub manage_selection { |
| 89 |
my ($self, %options) = @_; |
| 90 |
|
| 91 |
#system: Server-8203-E4A-SN06DF9A5 |
| 92 |
# phys led: state=on |
| 93 |
# lpar [LPAR1] led: off |
| 94 |
my ($content) = $options{custom}->execute_command( |
| 95 |
command => 'while read system ; do echo "system: $system"; echo -n " phys led: "; lsled -r sa -m "$system" -t "phys" ; while read lpar; do echo -n " lpar [$lpar] led: "; lsled -m "$system" -r sa -t virtuallpar --filter "lpar_names=$lpar" -F state ; done < <(lssyscfg -m "$system" -r lpar -F name) ; done < <(lssyscfg -r sys -F "name") |
| 96 |
', |
| 97 |
command_options => '2>&1' |
| 98 |
); |
| 99 |
|
| 100 |
$self->{physical} = {}; |
| 101 |
$self->{virtuallpar} = {}; |
| 102 |
while ($content =~ /^system:\s+(.*?)\n(.*?)(?=system:|\Z)/msg) { |
| 103 |
my ($system_name, $subcontent) = ($1, $2); |
| 104 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 105 |
$system_name !~ /$self->{option_results}->{filter_name}/) { |
| 106 |
$self->{output}->output_add(long_msg => "skipping '" . $system_name . "': no matching filter.", debug => 1); |
| 107 |
next; |
| 108 |
} |
| 109 |
|
| 110 |
$subcontent =~ /phys\s+led:\s+state=(\S+)/; |
| 111 |
my $system_ledstate = $1; |
| 112 |
while ($subcontent =~ /lpar\s+\[(.*?)\]\s+led:\s+(\S+)/msg) { |
| 113 |
my ($lpar_name, $lpar_ledstate) = ($system_name . ':' . $1, $2); |
| 114 |
|
| 115 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 116 |
$lpar_name !~ /$self->{option_results}->{filter_name}/) { |
| 117 |
$self->{output}->output_add(long_msg => "skipping '" . $lpar_name . "': no matching filter.", debug => 1); |
| 118 |
next; |
| 119 |
} |
| 120 |
|
| 121 |
$self->{virtuallpar}->{$lpar_name} = { display => $lpar_name, ledstate => $lpar_ledstate }; |
| 122 |
} |
| 123 |
|
| 124 |
$self->{physical}->{$system_name} = { display => $system_name, ledstate => $system_ledstate }; |
| 125 |
} |
| 126 |
|
| 127 |
if (scalar(keys %{$self->{physical}}) <= 0) { |
| 128 |
$self->{output}->add_option_msg(short_msg => 'No managed system found.'); |
| 129 |
$self->{output}->option_exit(); |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
1; |
| 134 |
|
| 135 |
__END__ |
| 136 |
|
| 137 |
=head1 MODE |
| 138 |
|
| 139 |
Check LED status for managed systems. |
| 140 |
|
| 141 |
=over 8 |
| 142 |
|
| 143 |
=item B<--filter-counters> |
| 144 |
|
| 145 |
Only display some counters (regexp can be used). |
| 146 |
Example: --filter-counters='^physical-status$' |
| 147 |
|
| 148 |
=item B<--filter-name> |
| 149 |
|
| 150 |
Filter name (can be a regexp). |
| 151 |
Format of names: systemname[:lparname] |
| 152 |
|
| 153 |
=item B<--warning-physical-status> |
| 154 |
|
| 155 |
Set warning threshold (default: ''). |
| 156 |
You can use the following variables: %{ledstate}, %{display} |
| 157 |
|
| 158 |
=item B<--critical-physical-status> |
| 159 |
|
| 160 |
Set critical threshold (default: '%{ledstate} =~ /on/'). |
| 161 |
You can use the following variables: %{ledstate}, %{display} |
| 162 |
|
| 163 |
=item B<--warning-virtuallpar-status> |
| 164 |
|
| 165 |
Set warning threshold (default: ''). |
| 166 |
You can use the following variables: %{ledstate}, %{display} |
| 167 |
|
| 168 |
=item B<--critical-virtuallpar-status> |
| 169 |
|
| 170 |
Set critical threshold (default: '%{ledstate} =~ /on/'). |
| 171 |
You can use the following variables: %{ledstate}, %{display} |
| 172 |
|
| 173 |
=back |
| 174 |
|
| 175 |
=cut |