From a1b282136092d4b623ed818d80c8f43aeffd5769 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 27 Aug 2015 13:25:29 +0000 Subject: [PATCH] refacto apc pdu --- .../hardware/pdu/apc/mode/humidity.pm | 143 -------- .../hardware/pdu/apc/mode/load.pm | 114 ------ .../hardware/pdu/apc/mode/outlet.pm | 157 -------- centreon-plugins/hardware/pdu/apc/mode/psu.pm | 117 ------ .../hardware/pdu/apc/mode/temperature.pm | 139 ------- .../pdu/apc/snmp/mode/components/humidity.pm | 104 ++++++ .../pdu/apc/snmp/mode/components/psu.pm | 73 ++++ .../apc/snmp/mode/components/temperature.pm | 103 ++++++ .../hardware/pdu/apc/snmp/mode/hardware.pm | 343 ++++++++++++++++++ .../hardware/pdu/apc/snmp/mode/load.pm | 275 ++++++++++++++ .../hardware/pdu/apc/snmp/mode/outlet.pm | 282 ++++++++++++++ .../hardware/pdu/apc/snmp/plugin.pm | 51 +++ 12 files changed, 1231 insertions(+), 670 deletions(-) delete mode 100644 centreon-plugins/hardware/pdu/apc/mode/humidity.pm delete mode 100644 centreon-plugins/hardware/pdu/apc/mode/load.pm delete mode 100644 centreon-plugins/hardware/pdu/apc/mode/outlet.pm delete mode 100644 centreon-plugins/hardware/pdu/apc/mode/psu.pm delete mode 100644 centreon-plugins/hardware/pdu/apc/mode/temperature.pm create mode 100644 centreon-plugins/hardware/pdu/apc/snmp/mode/components/humidity.pm create mode 100644 centreon-plugins/hardware/pdu/apc/snmp/mode/components/psu.pm create mode 100644 centreon-plugins/hardware/pdu/apc/snmp/mode/components/temperature.pm create mode 100644 centreon-plugins/hardware/pdu/apc/snmp/mode/hardware.pm create mode 100644 centreon-plugins/hardware/pdu/apc/snmp/mode/load.pm create mode 100644 centreon-plugins/hardware/pdu/apc/snmp/mode/outlet.pm create mode 100644 centreon-plugins/hardware/pdu/apc/snmp/plugin.pm diff --git a/centreon-plugins/hardware/pdu/apc/mode/humidity.pm b/centreon-plugins/hardware/pdu/apc/mode/humidity.pm deleted file mode 100644 index 5322ae2ed..000000000 --- a/centreon-plugins/hardware/pdu/apc/mode/humidity.pm +++ /dev/null @@ -1,143 +0,0 @@ -# -# Copyright 2015 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package hardware::pdu::apc::mode::humidity; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -my %states = ( - 1 => ['notPresent', 'OK'], - 2 => ['belowMin', 'CRITICAL'], - 3 => ['belowLow', 'WARNING'], - 4 => ['normal', 'OK'], - 5 => ['aboveHigh', 'WARNING'], - 6 => ['aboveMax', 'CRITICAL'], -); - -my %type = ( - 1 => 'temperatureOnly', - 2 => 'temperatureHumidity' -); - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - - my $oid_rPDU2SensorTempHumidityStatusName = '.1.3.6.1.4.1.318.1.1.26.10.2.2.1.3'; - my $oid_rPDU2SensorTempHumidityStatusNumber = '.1.3.6.1.4.1.318.1.1.26.10.2.2.1.4'; - my $oid_rPDU2SensorTempHumidityStatusType = '.1.3.6.1.4.1.318.1.1.26.10.2.2.1.5'; - my $oid_rPDU2SensorTempHumidityStatusRelativeHumidity = '.1.3.6.1.4.1.318.1.1.26.10.2.2.1.10'; - my $oid_rPDU2SensorTempHumidityStatusHumidityStatus = '.1.3.6.1.4.1.318.1.1.26.10.2.2.1.11'; - - $self->{results} = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_rPDU2SensorTempHumidityStatusName }, - { oid => $oid_rPDU2SensorTempHumidityStatusNumber }, - { oid => $oid_rPDU2SensorTempHumidityStatusType }, - { oid => $oid_rPDU2SensorTempHumidityStatusRelativeHumidity }, - { oid => $oid_rPDU2SensorTempHumidityStatusHumidityStatus }, - ], - , nothing_quit => 1); - - - $self->{output}->output_add(severity => 'OK', - short_msg => 'All humidity sensors are ok'); - - foreach my $oid (keys %{$self->{results}->{ $oid_rPDU2SensorTempHumidityStatusName}}) { - $oid =~ /\.([0-9]+)$/; - my $instance = $1; - - next if ($self->{results}->{$oid_rPDU2SensorTempHumidityStatusType}->{$oid_rPDU2SensorTempHumidityStatusType . '.' . $instance} == 1); - - my $sensor_name = $self->{results}->{ $oid_rPDU2SensorTempHumidityStatusName}->{$oid}; - my $sensor_number = $self->{results}->{$oid_rPDU2SensorTempHumidityStatusNumber}->{$oid_rPDU2SensorTempHumidityStatusNumber . '.' . $instance}; - my $sensor_humidity = $self->{results}->{$oid_rPDU2SensorTempHumidityStatusRelativeHumidity}->{$oid_rPDU2SensorTempHumidityStatusRelativeHumidity . '.' . $instance}; - my $sensor_status = $self->{results}->{$oid_rPDU2SensorTempHumidityStatusHumidityStatus}->{$oid_rPDU2SensorTempHumidityStatusHumidityStatus . '.' . $instance}; - - $self->{output}->output_add(long_msg => sprintf("Humidity sensor #%d '%s' is '%d%%'", - $sensor_number, $sensor_name, $sensor_humidity)); - $self->{output}->perfdata_add(label => 'hum' . $sensor_number, - unit => '%', - value => $sensor_humidity, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, - max => 100); - - my $exit = $self->{perfdata}->threshold_check(value => $sensor_humidity, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Temperature sensor #%d '%s' is '%d%%'", - $sensor_number, $sensor_name, $sensor_humidity)); - } - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check APC humidity sensors. - -=over 8 - -=back - -=cut - diff --git a/centreon-plugins/hardware/pdu/apc/mode/load.pm b/centreon-plugins/hardware/pdu/apc/mode/load.pm deleted file mode 100644 index 8fbd295d6..000000000 --- a/centreon-plugins/hardware/pdu/apc/mode/load.pm +++ /dev/null @@ -1,114 +0,0 @@ -# -# Copyright 2015 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package hardware::pdu::apc::mode::load; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -my %states = ( - 1 => ['phaseLoadNormal', 'OK'], - 2 => ['phaseLoadLow', 'WARNING'], - 3 => ['phaseLoadNearOverload', 'WARNING'], - 4 => ['phaseLoadOverload', 'CRITICAL'], -); - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - - my $oid_rPDULoadStatusLoad = '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.2'; - my $oid_rPDULoadStatusLoadState = '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.3'; - my $oid_rPDULoadStatusPhaseNumber = '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.4'; - my $oid_rPDULoadStatusBankNumber = '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.5'; - - $self->{results} = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_rPDULoadStatusLoad }, - { oid => $oid_rPDULoadStatusLoadState }, - { oid => $oid_rPDULoadStatusPhaseNumber }, - { oid => $oid_rPDULoadStatusBankNumber }, - ], - , nothing_quit => 1); - - - $self->{output}->output_add(severity => 'OK', - short_msg => 'All phases are ok'); - - foreach my $oid (keys %{$self->{results}->{$oid_rPDULoadStatusLoad}}) { - $oid =~ /\.([0-9]+)$/; - my $instance = $1; - - my $status_load = $self->{results}->{$oid_rPDULoadStatusLoad}->{$oid} / 10; - my $status_load_state = $self->{results}->{$oid_rPDULoadStatusLoadState}->{$oid_rPDULoadStatusLoadState . '.' . $instance}; - my $status_phase_number = $self->{results}->{$oid_rPDULoadStatusPhaseNumber}->{$oid_rPDULoadStatusPhaseNumber . '.' . $instance}; - my $status_bank_number = $self->{results}->{$oid_rPDULoadStatusBankNumber}->{$oid_rPDULoadStatusBankNumber . '.' . $instance}; - - $self->{output}->output_add(long_msg => sprintf("Phase state on Bank %s is '%s' [Load : %dA]", - $status_bank_number, ${$states{$status_load_state}}[0], $status_load)); - $self->{output}->perfdata_add(label => 'bank' . $status_bank_number, - value => $status_load, - unit => 'A', - min => 0); - if (${$states{$status_load_state}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$states{$status_load_state}}[1], - short_msg => sprintf("Phase state on Bank %s is '%s'", - $status_bank_number, ${$states{$status_load_state}}[0],)); - } - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check APC phase load. - -=over 8 - -=back - -=cut - diff --git a/centreon-plugins/hardware/pdu/apc/mode/outlet.pm b/centreon-plugins/hardware/pdu/apc/mode/outlet.pm deleted file mode 100644 index 9b690e3f9..000000000 --- a/centreon-plugins/hardware/pdu/apc/mode/outlet.pm +++ /dev/null @@ -1,157 +0,0 @@ -# -# Copyright 2015 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package hardware::pdu::apc::mode::outlet; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -my $oid_rPDUOutletStatusOutletName = '.1.3.6.1.4.1.318.1.1.12.3.5.1.1.2'; -my $oid_rPDUOutletStatusOutletPhase = '.1.3.6.1.4.1.318.1.1.12.3.5.1.1.3'; -my $oid_rPDUOutletStatusOutletState = '.1.3.6.1.4.1.318.1.1.12.3.5.1.1.4'; -my $oid_rPDUOutletStatusOutletBank = '.1.3.6.1.4.1.318.1.1.12.3.5.1.1.6'; -my $oid_rPDUOutletStatusLoad = '.1.3.6.1.4.1.318.1.1.12.3.5.1.1.7'; - -my %states = ( - 1 => ['outletStatusOn', 'OK'], - 2 => ['outletStatusOff', 'CRITICAL'], -); - -my %phases = ( - 1 => '1', - 2 => '2', - 3 => '3', - 4 => '1-2', - 5 => '2-3', - 6 => '1-3', -); - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "name:s" => { name => 'name', }, - "regexp" => { name => 'use_regexp', }, - }); - $self->{outlet_selected} = []; - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); -} - -sub manage_selection { - my ($self, %options) = @_; - - $self->{result_names} = $self->{snmp}->get_table(oid => $oid_rPDUOutletStatusOutletName, nothing_quit => 1); - - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{result_names}})) { - next if ($oid !~ /\.([0-9]+)$/); - my $instance = $1; - # Get all without a name - if (!defined($self->{option_results}->{name})) { - push @{$self->{outlet_selected}}, $instance; - next; - } - $self->{result_names}->{$oid} = $self->{output}->to_utf8($self->{result_names}->{$oid}); - if (!defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} eq $self->{option_results}->{name}) { - push @{$self->{outlet_selected}}, $instance; - } - if (defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} =~ /$self->{option_results}->{name}/) { - push @{$self->{outlet_selected}}, $instance; - } - } - if (scalar(@{$self->{outlet_selected}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "No outlet found for name '" . $self->{option_results}->{name} . "'."); - $self->{output}->option_exit(); - } -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - - $self->manage_selection(); - $self->{snmp}->load(oids => [$oid_rPDUOutletStatusOutletPhase, - $oid_rPDUOutletStatusOutletState, - $oid_rPDUOutletStatusOutletBank, - $oid_rPDUOutletStatusLoad], - instances => $self->{outlet_selected}); - my $result = $self->{snmp}->get_leef(); - if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All outlets are ok.'); - } - - foreach my $instance (@{$self->{outlet_selected}}) { - my $outlet_name = $self->{result_names}->{$oid_rPDUOutletStatusOutletName . '.' . $instance}; - my $outlet_phase = $result->{$oid_rPDUOutletStatusOutletPhase . '.' . $instance}; - my $outlet_state = $result->{$oid_rPDUOutletStatusOutletState . '.' . $instance}; - my $outlet_bank = $result->{$oid_rPDUOutletStatusOutletBank . '.' . $instance}; - my $outlet_load = $result->{$oid_rPDUOutletStatusLoad . '.' . $instance} / 10; - - $self->{output}->output_add(long_msg => sprintf("Outlet %s '%s' state is '%s' [Bank : %d , Phase : %d] [Load : %dA]", $instance, $outlet_name, - ${$states{$outlet_state}}[0], $outlet_bank, $phases{$outlet_phase}, $outlet_load)); - if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp})) { - $self->{output}->output_add(severity => ${$states{$outlet_state}}[1], - short_msg => sprintf("Outlet %s '%s' state is '%s' [Bank : %d , Phase : %d]", $instance, $outlet_name, - ${$states{$outlet_state}}[0], $outlet_bank, $phases{$outlet_phase})); - } elsif (${$states{$outlet_state}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$states{$outlet_state}}[1], - short_msg => sprintf("Outlet %s '%s' state is '%s' [Bank : %d , Phase : %d]", $instance, $outlet_name, - ${$states{$outlet_state}}[0], $outlet_bank, $phases{$outlet_phase})); - } - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check APC outlets. - -=over 8 - -=item B<--name> - -Set the outlet name. - -=item B<--regexp> - -Allows to use regexp to filter outlet (with option --name). - -=back - -=cut - diff --git a/centreon-plugins/hardware/pdu/apc/mode/psu.pm b/centreon-plugins/hardware/pdu/apc/mode/psu.pm deleted file mode 100644 index 8eb1e111f..000000000 --- a/centreon-plugins/hardware/pdu/apc/mode/psu.pm +++ /dev/null @@ -1,117 +0,0 @@ -# -# Copyright 2015 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package hardware::pdu::apc::mode::psu; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -my %states_psu_1 = ( - 1 => ['powerSupplyOneOk', 'OK'], - 2 => ['powerSupplyOneFailed', 'CRITICAL'], -); - -my %states_psu_2 = ( - 1 => ['powerSupplyTwoOk', 'OK'], - 2 => ['powerSupplyTwoFailed', 'CRITICAL'], -); - -my %alarms_psu = ( - 1 => ['allAvailablePowerSuppliesOK', 'OK'], - 2 => ['powerSupplyOneFailed', 'CRITICAL'], - 3 => ['powerSupplyTwoFailed', 'CRITICAL'], - 4 => ['powerSupplyOneandTwoFailed', 'CRITICAL'], -); - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - - my $oid_rPDUPowerSupply1Status = '.1.3.6.1.4.1.318.1.1.12.4.1.1.0'; - my $oid_rPDUPowerSupply2Status = '.1.3.6.1.4.1.318.1.1.12.4.1.2.0'; - my $oid_rPDUPowerSupplyAlarm = '.1.3.6.1.4.1.318.1.1.12.4.1.3.0'; - - my $result = $self->{snmp}->get_leef(oids => [$oid_rPDUPowerSupply1Status, $oid_rPDUPowerSupply2Status, $oid_rPDUPowerSupplyAlarm], nothing_quit => 1); - - $self->{output}->output_add(severity => 'OK', - short_msg => 'All power supplies are ok'); - - my $psu_alarm = $result->{$oid_rPDUPowerSupplyAlarm}; - my $psu1_status = $result->{$oid_rPDUPowerSupply2Status}; - my $psu2_status = $result->{$oid_rPDUPowerSupplyAlarm}; - - $self->{output}->output_add(long_msg => sprintf("Power supply 1 state is '%s'", ${$states_psu_1{$psu1_status}}[0])); - $self->{output}->output_add(long_msg => sprintf("Power supply 2 state is '%s'", ${$states_psu_2{$psu2_status}}[0])); - - if (${$alarms_psu{$psu_alarm}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$alarms_psu{$psu_alarm}}[1], - short_msg => sprintf("Power supplies state is '%s'", - ${$alarms_psu{$psu_alarm}}[0])); - } - if (${$states_psu_1{$psu1_status}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$states_psu_1{$psu1_status}}[1], - short_msg => sprintf("Power supply 1 state is '%s'", - ${$states_psu_1{$psu1_status}}[0])); - } - if (${$states_psu_2{$psu2_status}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$states_psu_2{$psu2_status}}[1], - short_msg => sprintf("Power supply 2 state is '%s'", - ${$states_psu_2{$psu2_status}}[0])); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check APC power supplies. - -=over 8 - -=back - -=cut - diff --git a/centreon-plugins/hardware/pdu/apc/mode/temperature.pm b/centreon-plugins/hardware/pdu/apc/mode/temperature.pm deleted file mode 100644 index f06d3dbb5..000000000 --- a/centreon-plugins/hardware/pdu/apc/mode/temperature.pm +++ /dev/null @@ -1,139 +0,0 @@ -# -# Copyright 2015 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package hardware::pdu::apc::mode::temperature; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -my %states = ( - 1 => ['notPresent', 'OK'], - 2 => ['belowMin', 'CRITICAL'], - 3 => ['belowLow', 'WARNING'], - 4 => ['normal', 'OK'], - 5 => ['aboveHigh', 'WARNING'], - 6 => ['aboveMax', 'CRITICAL'], -); - -my %type = ( - 1 => 'temperatureOnly', - 2 => 'temperatureHumidity' -); - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - - my $oid_rPDU2SensorTempHumidityStatusName = '.1.3.6.1.4.1.318.1.1.26.10.2.2.1.3'; - my $oid_rPDU2SensorTempHumidityStatusNumber = '.1.3.6.1.4.1.318.1.1.26.10.2.2.1.4'; - my $oid_rPDU2SensorTempHumidityStatusType = '.1.3.6.1.4.1.318.1.1.26.10.2.2.1.5'; - my $oid_rPDU2SensorTempHumidityStatusTempC = '.1.3.6.1.4.1.318.1.1.26.10.2.2.1.8'; - my $oid_rPDU2SensorTempHumidityStatusTempStatus = '.1.3.6.1.4.1.318.1.1.26.10.2.2.1.9'; - - $self->{results} = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_rPDU2SensorTempHumidityStatusName }, - { oid => $oid_rPDU2SensorTempHumidityStatusNumber }, - { oid => $oid_rPDU2SensorTempHumidityStatusTempC }, - { oid => $oid_rPDU2SensorTempHumidityStatusTempStatus }, - ], - , nothing_quit => 1); - - - $self->{output}->output_add(severity => 'OK', - short_msg => 'All temperature sensors are ok'); - - foreach my $oid (keys %{$self->{results}->{ $oid_rPDU2SensorTempHumidityStatusName}}) { - $oid =~ /\.([0-9]+)$/; - my $instance = $1; - - my $sensor_name = $self->{results}->{ $oid_rPDU2SensorTempHumidityStatusName}->{$oid}; - my $sensor_number = $self->{results}->{$oid_rPDU2SensorTempHumidityStatusNumber}->{$oid_rPDU2SensorTempHumidityStatusNumber . '.' . $instance}; - my $sensor_temperature = $self->{results}->{$oid_rPDU2SensorTempHumidityStatusTempC}->{$oid_rPDU2SensorTempHumidityStatusTempC . '.' . $instance} / 10; - my $sensor_status = $self->{results}->{$oid_rPDU2SensorTempHumidityStatusTempStatus}->{$oid_rPDU2SensorTempHumidityStatusTempStatus . '.' . $instance}; - - $self->{output}->output_add(long_msg => sprintf("Temperature sensor #%d '%s' is '%.1fC'", - $sensor_number, $sensor_name, $sensor_temperature)); - $self->{output}->perfdata_add(label => 'temp' . $sensor_number, - unit => 'C', - value => $sensor_temperature, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); - - my $exit = $self->{perfdata}->threshold_check(value => $sensor_temperature, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Temperature sensor #%d '%s' is '%.1fC'", - $sensor_number, $sensor_name, $sensor_temperature)); - } - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check APC temperature sensors. - -=over 8 - -=back - -=cut - diff --git a/centreon-plugins/hardware/pdu/apc/snmp/mode/components/humidity.pm b/centreon-plugins/hardware/pdu/apc/snmp/mode/components/humidity.pm new file mode 100644 index 000000000..9e2b5bf22 --- /dev/null +++ b/centreon-plugins/hardware/pdu/apc/snmp/mode/components/humidity.pm @@ -0,0 +1,104 @@ +# +# Copyright 2015 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::pdu::apc::snmp::mode::components::humidity; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'notPresent', + 2 => 'belowMin', + 3 => 'belowLow', + 4 => 'normal', + 5 => 'aboveHigh', + 6 => 'aboveMax', +); +my %map_type = ( + 1 => 'temperatureOnly', + 2 => 'temperatureHumidity', + 3 => 'commsLost', + 4 => 'notInstalled', +); + +# In MIB 'PowerNet-MIB' +my $mapping = { + rPDU2SensorTempHumidityStatusName => { oid => '.1.3.6.1.4.1.318.1.1.26.10.2.2.1.3' }, + rPDU2SensorTempHumidityStatusNumber => { oid => '.1.3.6.1.4.1.318.1.1.26.10.2.2.1.4' }, + rPDU2SensorTempHumidityStatusType => { oid => '.1.3.6.1.4.1.318.1.1.26.10.2.2.1.5', map => \%map_type }, + rPDU2SensorTempHumidityStatusRelativeHumidity => { oid => '.1.3.6.1.4.1.318.1.1.26.10.2.2.1.10' }, + rPDU2SensorTempHumidityStatusHumidityStatus => { oid => '.1.3.6.1.4.1.318.1.1.26.10.2.2.1.11', map => \%map_status }, +}; +my $oid_rPDU2SensorTempHumidityStatusEntry = '.1.3.6.1.4.1.318.1.1.26.10.2.2.1'; + +sub load { + my (%options) = @_; + + foreach (@{$options{request}}) { + return if ($_->{oid} eq $oid_rPDU2SensorTempHumidityStatusEntry); + } + push @{$options{request}}, { oid => $oid_rPDU2SensorTempHumidityStatusEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking humidities"); + $self->{components}->{humidity} = {name => 'humidities', total => 0, skip => 0}; + return if ($self->check_filter(section => 'humidity')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rPDU2SensorTempHumidityStatusEntry}})) { + next if ($oid !~ /^$mapping->{rPDU2SensorTempHumidityStatusHumidityStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rPDU2SensorTempHumidityStatusEntry}, instance => $instance); + + next if ($result->{rPDU2SensorTempHumidityStatusType} !~ /temperatureHumidity/i); + next if ($self->check_filter(section => 'humidity', instance => $result->{rPDU2SensorTempHumidityStatusNumber})); + next if ($result->{rPDU2SensorTempHumidityStatusHumidityStatus} !~ /notPresent/i && + $self->absent_problem(section => 'humidity', instance => $result->{rPDU2SensorTempHumidityStatusNumber})); + $self->{components}->{humidity}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Humidity '%s' status is '%s' [instance: %s, value: %s]", + $result->{rPDU2SensorTempHumidityStatusName}, $result->{rPDU2SensorTempHumidityStatusHumidityStatus}, + $result->{rPDU2SensorTempHumidityStatusNumber}, $result->{rPDU2SensorTempHumidityStatusRelativeHumidity})); + my $exit = $self->get_severity(section => 'humidity', instance => $result->{rPDU2SensorTempHumidityStatusName}, value => $result->{rPDU2SensorTempHumidityStatusHumidityStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Humidity '%s' status is %s", + $result->{rPDU2SensorTempHumidityStatusName}, $result->{rPDU2SensorTempHumidityStatusHumidityStatus})); + } + + if (defined($result->{rPDU2SensorTempHumidityStatusRelativeHumidity}) && $result->{rPDU2SensorTempHumidityStatusRelativeHumidity} =~ /[0-9]/) { + my $value = $result->{rPDU2SensorTempHumidityStatusRelativeHumidity} / 10; + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'humidity', instance => $result->{rPDU2SensorTempHumidityStatusNumber}, value => $value); + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Humidity '%s' value is %s %%", $result->{rPDU2SensorTempHumidityStatusName}, $value)); + } + $self->{output}->perfdata_add(label => $result->{rPDU2SensorTempHumidityStatusName}, unit => '%', + value => $value, + warning => $warn, + critical => $crit, + min => 0, max => 100); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/pdu/apc/snmp/mode/components/psu.pm b/centreon-plugins/hardware/pdu/apc/snmp/mode/components/psu.pm new file mode 100644 index 000000000..47379641b --- /dev/null +++ b/centreon-plugins/hardware/pdu/apc/snmp/mode/components/psu.pm @@ -0,0 +1,73 @@ +# +# Copyright 2015 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::pdu::apc::snmp::mode::components::psu; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'ok', + 2 => 'failed', + 3 => 'notPresent', +); + +# In MIB 'PowerNet-MIB' +my $mapping = { + rPDUPowerSupply1Status => { oid => '.1.3.6.1.4.1.318.1.1.12.4.1.1', map => \%map_status }, + rPDUPowerSupply2Status => { oid => '.1.3.6.1.4.1.318.1.1.12.4.1.2', map => \%map_status }, +}; +my $oid_rPDUPowerSupplyDevice = '.1.3.6.1.4.1.318.1.1.12.4.1'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_rPDUPowerSupplyDevice }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking power supplies"); + $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; + return if ($self->check_filter(section => 'psu')); + + if (!defined($self->{results}->{$oid_rPDUPowerSupplyDevice})); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rPDUPowerSupplyDevice}, instance => '0'); + for (my $i = 1; $i <= 2; $i++) { + next if (!defined($result->{'rPDUPowerSupply' . $i . 'Status'})); + next if ($result->{'rPDUPowerSupply' . $i . 'Status'} !~ /notPresent/i && + $self->absent_problem(section => 'psu', instance => $i)); + next if ($self->check_filter(section => 'psu', instance => $i)); + $self->{components}->{psu}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is '%s' [instance: %s]", + $i, $result->{'rPDUPowerSupply' . $i . 'Status'}, + $i)); + my $exit = $self->get_severity(section => 'psu', instance => $i, value => $result->{'rPDUPowerSupply' . $i . 'Status'}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power supply '%s' status is '%s'", + $i, $result->{'rPDUPowerSupply' . $i . 'Status'})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/pdu/apc/snmp/mode/components/temperature.pm b/centreon-plugins/hardware/pdu/apc/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..5f8b09fd7 --- /dev/null +++ b/centreon-plugins/hardware/pdu/apc/snmp/mode/components/temperature.pm @@ -0,0 +1,103 @@ +# +# Copyright 2015 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::pdu::apc::snmp::mode::components::temperature; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'notPresent', + 2 => 'belowMin', + 3 => 'belowLow', + 4 => 'normal', + 5 => 'aboveHigh', + 6 => 'aboveMax', +); +my %map_type = ( + 1 => 'temperatureOnly', + 2 => 'temperatureHumidity', + 3 => 'commsLost', + 4 => 'notInstalled', +); + +# In MIB 'PowerNet-MIB' +my $mapping = { + rPDU2SensorTempHumidityStatusName => { oid => '.1.3.6.1.4.1.318.1.1.26.10.2.2.1.3' }, + rPDU2SensorTempHumidityStatusNumber => { oid => '.1.3.6.1.4.1.318.1.1.26.10.2.2.1.4' }, + rPDU2SensorTempHumidityStatusType => { oid => '.1.3.6.1.4.1.318.1.1.26.10.2.2.1.5', map => \%map_type }, + rPDU2SensorTempHumidityStatusTempC => { oid => '.1.3.6.1.4.1.318.1.1.26.10.2.2.1.8' }, + rPDU2SensorTempHumidityStatusTempStatus => { oid => '.1.3.6.1.4.1.318.1.1.26.10.2.2.1.9', map => \%map_status }, +}; +my $oid_rPDU2SensorTempHumidityStatusEntry = '.1.3.6.1.4.1.318.1.1.26.10.2.2.1'; + +sub load { + my (%options) = @_; + + foreach (@{$options{request}}) { + return if ($_->{oid} eq $oid_rPDU2SensorTempHumidityStatusEntry); + } + push @{$options{request}}, { oid => $oid_rPDU2SensorTempHumidityStatusEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking temperatures"); + $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; + return if ($self->check_filter(section => 'temperature')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rPDU2SensorTempHumidityStatusEntry}})) { + next if ($oid !~ /^$mapping->{rPDU2SensorTempHumidityStatusTempStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rPDU2SensorTempHumidityStatusEntry}, instance => $instance); + + next if ($result->{rPDU2SensorTempHumidityStatusType} !~ /temperatureOnly|temperatureHumidity/i); + next if ($self->check_filter(section => 'temperature', instance => $result->{rPDU2SensorTempHumidityStatusNumber})); + next if ($result->{rPDU2SensorTempHumidityStatusTempStatus} !~ /notPresent/i && + $self->absent_problem(section => 'temperature', instance => $result->{rPDU2SensorTempHumidityStatusNumber})); + $self->{components}->{temperature}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Temperature '%s' status is '%s' [instance: %s, value: %s]", + $result->{rPDU2SensorTempHumidityStatusName}, $result->{rPDU2SensorTempHumidityStatusTempStatus}, + $result->{rPDU2SensorTempHumidityStatusNumber}, $result->{rPDU2SensorTempHumidityStatusTempC})); + my $exit = $self->get_severity(section => 'temperature', instance => $result->{rPDU2SensorTempHumidityStatusNumber}, value => $result->{rPDU2SensorTempHumidityStatusTempStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature '%s' status is %s", + $result->{rPDU2SensorTempHumidityStatusName}, $result->{rPDU2SensorTempHumidityStatusTempStatus})); + } + + if (defined($result->{rPDU2SensorTempHumidityStatusTempC}) && $result->{rPDU2SensorTempHumidityStatusTempC} =~ /[0-9]/) { + my $value = $result->{rPDU2SensorTempHumidityStatusTempC} / 10; + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $result->{rPDU2SensorTempHumidityStatusNumber}, value => $value); + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Temperature '%s' value is %s C", $result->{rPDU2SensorTempHumidityStatusName}, $value)); + } + $self->{output}->perfdata_add(label => $result->{rPDU2SensorTempHumidityStatusName}, unit => 'C', + value => $value, + warning => $warn, + critical => $crit); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/pdu/apc/snmp/mode/hardware.pm b/centreon-plugins/hardware/pdu/apc/snmp/mode/hardware.pm new file mode 100644 index 000000000..a494e6368 --- /dev/null +++ b/centreon-plugins/hardware/pdu/apc/snmp/mode/hardware.pm @@ -0,0 +1,343 @@ +# +# Copyright 2015 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::pdu::apc::snmp::mode::hardware; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::misc; + +my $thresholds = { + humidity => [ + ['notPresent', 'OK'], + ['belowMin', 'CRITICAL'], + ['belowLow', 'WARNING'], + ['normal', 'OK'], + ['aboveHigh', 'WARNING'], + ['aboveMax', 'CRITICAL'], + ], + temperature => [ + ['notPresent', 'OK'], + ['belowMin', 'CRITICAL'], + ['belowLow', 'WARNING'], + ['normal', 'OK'], + ['aboveHigh', 'WARNING'], + ['aboveMax', 'CRITICAL'], + ], + psu => [ + ['ok', 'OK'], + ['failed', 'CRITICAL'], + ['notPresent', 'OK'], + ], +}; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter:s@" => { name => 'filter' }, + "absent-problem:s@" => { name => 'absent_problem' }, + "component:s" => { name => 'component', default => '.*' }, + "no-component:s" => { name => 'no_component' }, + "threshold-overload:s@" => { name => 'threshold_overload' }, + "warning:s@" => { name => 'warning' }, + "critical:s@" => { name => 'critical' }, + }); + + $self->{components} = {}; + $self->{no_components} = undef; + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (defined($self->{option_results}->{no_component})) { + if ($self->{option_results}->{no_component} ne '') { + $self->{no_components} = $self->{option_results}->{no_component}; + } else { + $self->{no_components} = 'critical'; + } + } + + $self->{filter} = []; + foreach my $val (@{$self->{option_results}->{filter}}) { + next if (!defined($val) || $val eq ''); + my @values = split (/,/, $val); + push @{$self->{filter}}, { filter => $values[0], instance => $values[1] }; + } + + $self->{absent_problem} = []; + foreach my $val (@{$self->{option_results}->{absent_problem}}) { + next if (!defined($val) || $val eq ''); + my @values = split (/,/, $val); + push @{$self->{absent_problem}}, { filter => $values[0], instance => $values[1] }; + } + + $self->{overload_th} = {}; + foreach my $val (@{$self->{option_results}->{threshold_overload}}) { + next if (!defined($val) || $val eq ''); + my @values = split (/,/, $val); + if (scalar(@values) < 3) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); + $self->{output}->option_exit(); + } + my ($section, $instance, $status, $filter); + if (scalar(@values) == 3) { + ($section, $status, $filter) = @values; + $instance = '.*'; + } else { + ($section, $instance, $status, $filter) = @values; + } + if ($section !~ /^humidity|temperature|psu$/) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload section '" . $val . "'."); + $self->{output}->option_exit(); + } + if ($self->{output}->is_litteral_status(status => $status) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); + $self->{output}->option_exit(); + } + $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); + push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status, instance => $instance }; + } + + $self->{numeric_threshold} = {}; + foreach my $option (('warning', 'critical')) { + foreach my $val (@{$self->{option_results}->{$option}}) { + next if (!defined($val) || $val eq ''); + if ($val !~ /^(.*?),(.*?),(.*)$/) { + $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); + $self->{output}->option_exit(); + } + my ($section, $instance, $value) = ($1, $2, $3); + if ($section !~ /^humidity|temperature$/) { + $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); + $self->{output}->option_exit(); + } + my $position = 0; + if (defined($self->{numeric_threshold}->{$section})) { + $position = scalar(@{$self->{numeric_threshold}->{$section}}); + } + if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'."); + $self->{output}->option_exit(); + } + $self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section})); + push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, instance => $instance }; + } + } +} + +sub run { + my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; + + my $snmp_request = []; + my @components = ('psu', 'humidity', 'temperature'); + foreach (@components) { + if (/$self->{option_results}->{component}/) { + my $mod_name = "hardware::pdu::apc::snmp::mode::components::$_"; + centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, + error_msg => "Cannot load module '$mod_name'."); + my $func = $mod_name->can('load'); + $func->(request => $snmp_request); + } + } + + if (scalar(@{$snmp_request}) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); + $self->{output}->option_exit(); + } + $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); + + foreach (@components) { + if (/$self->{option_results}->{component}/) { + my $mod_name = "hardware::pdu::apc::snmp::mode::components::$_"; + my $func = $mod_name->can('check'); + $func->($self); + } + } + + my $total_components = 0; + my $display_by_component = ''; + my $display_by_component_append = ''; + foreach my $comp (sort(keys %{$self->{components}})) { + # Skipping short msg when no components + next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); + $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; + my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; + $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; + $display_by_component_append = ', '; + } + + $self->{output}->output_add(severity => 'OK', + short_msg => sprintf("All %s components are ok [%s].", + $total_components, + $display_by_component) + ); + + if (defined($self->{option_results}->{no_component}) && $total_components == 0) { + $self->{output}->output_add(severity => $self->{no_components}, + short_msg => 'No components are checked.'); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +sub absent_problem { + my ($self, %options) = @_; + + foreach (@{$self->{absent_problem}}) { + if ($options{section} =~ /$_->{filter}/) { + if (!defined($_->{instance}) || $options{instance} =~ /$_->{instance}/) { + $self->{output}->output_add(severity => 'CRITICAL', + short_msg => sprintf("Component '%s' instance '%s' is not present", + $options{section}, $options{instance})); + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance (not present)")); + $self->{components}->{$options{section}}->{skip}++; + return 1; + } + } + } + + return 0; +} + +sub check_filter { + my ($self, %options) = @_; + + foreach (@{$self->{filter}}) { + if ($options{section} =~ /$_->{filter}/) { + if (!defined($options{instance}) && !defined($_->{instance})) { + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); + return 1; + } elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) { + $self->{components}->{$options{section}}->{skip}++ if (defined($self->{components}->{$options{section}})); + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); + return 1; + } + } + } + + return 0; +} + +sub get_severity_numeric { + my ($self, %options) = @_; + my $status = 'OK'; # default + my $thresholds = { warning => undef, critical => undef }; + my $checked = 0; + + if (defined($self->{numeric_threshold}->{$options{section}})) { + my $exits = []; + foreach (@{$self->{numeric_threshold}->{$options{section}}}) { + if ($options{instance} =~ /$_->{instance}/) { + push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]); + $thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label}); + $checked = 1; + } + } + $status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0); + } + + return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked); +} + +sub get_severity { + my ($self, %options) = @_; + my $status = 'UNKNOWN'; # default + + if (defined($self->{overload_th}->{$options{section}})) { + foreach (@{$self->{overload_th}->{$options{section}}}) { + if ($options{value} =~ /$_->{filter}/i && + (!defined($options{instance}) || $options{instance} =~ /$_->{instance}/)) { + $status = $_->{status}; + return $status; + } + } + } + my $label = defined($options{label}) ? $options{label} : $options{section}; + foreach (@{$thresholds->{$label}}) { + if ($options{value} =~ /$$_[0]/i) { + $status = $$_[1]; + return $status; + } + } + + return $status; +} + +1; + +__END__ + +=head1 MODE + +Check components (humidity, temperature, power supplies). + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'psu', 'humidity', 'temperature'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=temperature --filter=humidity) +Can also exclude specific instance: --filter=temperature,1 + +=item B<--absent-problem> + +Return an error if an entity is not 'present' (default is skipping) (comma seperated list) +Can be specific or global: --absent-problem=psu + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='temperature,CRITICAL,^(?!(normal)$)' + +=item B<--warning> + +Set warning threshold for temperatures (syntax: type,instance,threshold) +Example: --warning='temperature,.*,30' + +=item B<--critical> + +Set critical threshold for temperatures (syntax: type,instance,threshold) +Example: --critical='temperature,.*,40' +=back + +=cut \ No newline at end of file diff --git a/centreon-plugins/hardware/pdu/apc/snmp/mode/load.pm b/centreon-plugins/hardware/pdu/apc/snmp/mode/load.pm new file mode 100644 index 000000000..0818bf90a --- /dev/null +++ b/centreon-plugins/hardware/pdu/apc/snmp/mode/load.pm @@ -0,0 +1,275 @@ +# +# Copyright 2015 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::pdu::apc::snmp::mode::load; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::misc; + +my $thresholds = { + load => [ + ['phaseLoadNormal', 'OK'], + ['phaseLoadLow', 'WARNING'], + ['phaseLoadNearOverload', 'WARNING'], + ['phaseLoadOverload', 'CRITICAL'], + ], +}; +my %map_status = ( + 1 => 'phaseLoadNormal', + 2 => 'phaseLoadLow', + 3 => 'phaseLoadNearOverload', + 4 => 'phaseLoadOverload', +); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter:s@" => { name => 'filter' }, + "threshold-overload:s@" => { name => 'threshold_overload' }, + "warning:s@" => { name => 'warning' }, + "critical:s@" => { name => 'critical' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + $self->{filter} = []; + foreach my $val (@{$self->{option_results}->{filter}}) { + next if (!defined($val) || $val eq ''); + my @values = split (/,/, $val); + push @{$self->{filter}}, { filter => $values[0], instance => $values[1] }; + } + + $self->{overload_th} = {}; + foreach my $val (@{$self->{option_results}->{threshold_overload}}) { + next if (!defined($val) || $val eq ''); + my @values = split (/,/, $val); + if (scalar(@values) < 3) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); + $self->{output}->option_exit(); + } + my ($section, $instance, $status, $filter); + if (scalar(@values) == 3) { + ($section, $status, $filter) = @values; + $instance = '.*'; + } else { + ($section, $instance, $status, $filter) = @values; + } + if ($section !~ /^load$/) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload section '" . $val . "'."); + $self->{output}->option_exit(); + } + if ($self->{output}->is_litteral_status(status => $status) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); + $self->{output}->option_exit(); + } + $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); + push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status, instance => $instance }; + } + + $self->{numeric_threshold} = {}; + foreach my $option (('warning', 'critical')) { + foreach my $val (@{$self->{option_results}->{$option}}) { + next if (!defined($val) || $val eq ''); + if ($val !~ /^(.*?),(.*?),(.*)$/) { + $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); + $self->{output}->option_exit(); + } + my ($section, $instance, $value) = ($1, $2, $3); + if ($section !~ /^load$/) { + $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); + $self->{output}->option_exit(); + } + my $position = 0; + if (defined($self->{numeric_threshold}->{$section})) { + $position = scalar(@{$self->{numeric_threshold}->{$section}}); + } + if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'."); + $self->{output}->option_exit(); + } + $self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section})); + push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, instance => $instance }; + } + } +} + +my $mapping = { + rPDULoadStatusLoad => { oid => '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.2' }, + rPDULoadStatusLoadState => { oid => '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.3', map => \%map_status }, + rPDULoadStatusPhaseNumber => { oid => '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.4' }, + rPDULoadStatusBankNumber => { oid => '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.5' }, +}; + +sub run { + my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; + + my $oid_rPDULoadStatusEntry = '.1.3.6.1.4.1.318.1.1.12.2.3.1.1'; + + $self->{results} = $self->{snmp}->get_table(oid => $oid_rPDULoadStatusEntry, nothing_quit => 1); + + $self->{output}->output_add(severity => 'OK', + short_msg => 'All phase/bank loads are ok'); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}})) { + next if ($oid !~ /^$mapping->{rPDULoadStatusLoadState}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + + next if ($self->check_filter(section => 'load', instance => $instance)); + + $self->{output}->output_add(long_msg => sprintf("Phase '%s' on Bank '%s' status is '%s' [instance: %s, value: %s]", + $result->{rPDULoadStatusPhaseNumber}, $result->{rPDULoadStatusBankNumber}, $result->{rPDULoadStatusLoadState}, + $instance, $result->{rPDULoadStatusLoad})); + my $exit = $self->get_severity(section => 'load', instance => $instance, value => $result->{rPDULoadStatusLoadState}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Phase '%s' on Bank '%s' status is '%s'", + $result->{rPDULoadStatusPhaseNumber}, $result->{rPDULoadStatusBankNumber}, $result->{rPDULoadStatusLoadState})); + } + + if (defined($result->{rPDULoadStatusLoad}) && $result->{rPDULoadStatusLoad} =~ /[0-9]/) { + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'load', instance => $instance, value => $result->{rPDULoadStatusLoad}); + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Phase '%s' on Bank '%s' load is %s A", + $result->{rPDULoadStatusPhaseNumber}, $result->{rPDULoadStatusBankNumber}, $result->{rPDULoadStatusLoad})); + } + $self->{output}->perfdata_add(label => 'load_bank_' . $result->{rPDULoadStatusBankNumber} . '_phase_' . $result->{rPDULoadStatusPhaseNumber}, unit => 'A', + value => $result->{rPDULoadStatusLoad}, + warning => $warn, + critical => $crit, + min => 0); + } + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +sub check_filter { + my ($self, %options) = @_; + + foreach (@{$self->{filter}}) { + if ($options{section} =~ /$_->{filter}/) { + if (!defined($options{instance}) && !defined($_->{instance})) { + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); + return 1; + } elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) { + $self->{components}->{$options{section}}->{skip}++ if (defined($self->{components}->{$options{section}})); + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); + return 1; + } + } + } + + return 0; +} + +sub get_severity_numeric { + my ($self, %options) = @_; + my $status = 'OK'; # default + my $thresholds = { warning => undef, critical => undef }; + my $checked = 0; + + if (defined($self->{numeric_threshold}->{$options{section}})) { + my $exits = []; + foreach (@{$self->{numeric_threshold}->{$options{section}}}) { + if ($options{instance} =~ /$_->{instance}/) { + push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]); + $thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label}); + $checked = 1; + } + } + $status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0); + } + + return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked); +} + +sub get_severity { + my ($self, %options) = @_; + my $status = 'UNKNOWN'; # default + + if (defined($self->{overload_th}->{$options{section}})) { + foreach (@{$self->{overload_th}->{$options{section}}}) { + if ($options{value} =~ /$_->{filter}/i && + (!defined($options{instance}) || $options{instance} =~ /$_->{instance}/)) { + $status = $_->{status}; + return $status; + } + } + } + my $label = defined($options{label}) ? $options{label} : $options{section}; + foreach (@{$thresholds->{$label}}) { + if ($options{value} =~ /$$_[0]/i) { + $status = $$_[1]; + return $status; + } + } + + return $status; +} + +1; + +__END__ + +=head1 MODE + +Check phase/bank load state. + +=over 8 + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter=load,1 + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='load,CRITICAL,^(?!(PhaseLoadNormal)$)' + +=item B<--warning> + +Set warning threshold for temperatures (syntax: type,instance,threshold) +Example: --warning='load,.*,30' + +=item B<--critical> + +Set critical threshold for temperatures (syntax: type,instance,threshold) +Example: --critical='load,.*,40' +=back + +=cut \ No newline at end of file diff --git a/centreon-plugins/hardware/pdu/apc/snmp/mode/outlet.pm b/centreon-plugins/hardware/pdu/apc/snmp/mode/outlet.pm new file mode 100644 index 000000000..950dfd35e --- /dev/null +++ b/centreon-plugins/hardware/pdu/apc/snmp/mode/outlet.pm @@ -0,0 +1,282 @@ +# +# Copyright 2015 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::pdu::apc::snmp::mode::outlet; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::misc; + +my $thresholds = { + outlet => [ + ['outletStatusOn', 'OK'], + ['outletStatusOff', 'CRITICAL'], + ], +}; +my %map_status = ( + 1 => 'outletStatusOn', + 2 => 'outletStatusOff', +); +my %map_phase = ( + 1 => 'phase1', + 2 => 'phase2', + 3 => 'phase3', + 4 => 'phase1-2', + 5 => 'phase2-3', + 6 => 'phase3-1', +); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter:s@" => { name => 'filter' }, + "threshold-overload:s@" => { name => 'threshold_overload' }, + "warning:s@" => { name => 'warning' }, + "critical:s@" => { name => 'critical' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + $self->{filter} = []; + foreach my $val (@{$self->{option_results}->{filter}}) { + next if (!defined($val) || $val eq ''); + my @values = split (/,/, $val); + push @{$self->{filter}}, { filter => $values[0], instance => $values[1] }; + } + + $self->{overload_th} = {}; + foreach my $val (@{$self->{option_results}->{threshold_overload}}) { + next if (!defined($val) || $val eq ''); + my @values = split (/,/, $val); + if (scalar(@values) < 3) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); + $self->{output}->option_exit(); + } + my ($section, $instance, $status, $filter); + if (scalar(@values) == 3) { + ($section, $status, $filter) = @values; + $instance = '.*'; + } else { + ($section, $instance, $status, $filter) = @values; + } + if ($section !~ /^outlet$/) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload section '" . $val . "'."); + $self->{output}->option_exit(); + } + if ($self->{output}->is_litteral_status(status => $status) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); + $self->{output}->option_exit(); + } + $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); + push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status, instance => $instance }; + } + + $self->{numeric_threshold} = {}; + foreach my $option (('warning', 'critical')) { + foreach my $val (@{$self->{option_results}->{$option}}) { + next if (!defined($val) || $val eq ''); + if ($val !~ /^(.*?),(.*?),(.*)$/) { + $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); + $self->{output}->option_exit(); + } + my ($section, $instance, $value) = ($1, $2, $3); + if ($section !~ /^load$/) { + $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); + $self->{output}->option_exit(); + } + my $position = 0; + if (defined($self->{numeric_threshold}->{$section})) { + $position = scalar(@{$self->{numeric_threshold}->{$section}}); + } + if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'."); + $self->{output}->option_exit(); + } + $self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section})); + push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, instance => $instance }; + } + } +} + +my $mapping = { + rPDUOutletStatusOutletName => { oid => '.1.3.6.1.4.1.318.1.1.12.3.5.1.1.2' }, + rPDUOutletStatusOutletPhase => { oid => '.1.3.6.1.4.1.318.1.1.12.3.5.1.1.3', map => \%map_phase }, + rPDUOutletStatusOutletState => { oid => '.1.3.6.1.4.1.318.1.1.12.3.5.1.1.4', map => \%map_status }, + rPDUOutletStatusOutletBank => { oid => '.1.3.6.1.4.1.318.1.1.12.3.5.1.1.6' }, + rPDUOutletStatusLoad => { oid => '.1.3.6.1.4.1.318.1.1.12.3.5.1.1.7' }, +}; + +sub run { + my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; + + my $oid_rPDUOutletStatusEntry = '.1.3.6.1.4.1.318.1.1.12.3.5.1.1'; + + $self->{results} = $self->{snmp}->get_table(oid => $oid_rPDUOutletStatusEntry, nothing_quit => 1); + + $self->{output}->output_add(severity => 'OK', + short_msg => 'All outlets are ok'); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}})) { + next if ($oid !~ /^$mapping->{rPDUOutletStatusOutletState}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + + next if ($self->check_filter(section => 'outlet', instance => $instance)); + + $self->{output}->output_add(long_msg => sprintf("Outlet '%s' state is '%s' [instance: %s, bank : %s, phase : %s, load: %s]", + $result->{rPDUOutletStatusOutletName}, $result->{rPDUOutletStatusOutletState}, + $instance, $result->{rPDUOutletStatusOutletBank}, $result->{rPDUOutletStatusOutletPhase}, $result->{rPDUOutletStatusLoad})); + my $exit = $self->get_severity(section => 'outlet', instance => $instance, value => $result->{rPDUOutletStatusOutletState}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Outlet '%s' state is '%s' [bank : %s, phase : %s]", + $result->{rPDUOutletStatusOutletName}, $result->{rPDUOutletStatusOutletState}, + $result->{rPDUOutletStatusOutletBank}, $result->{rPDUOutletStatusOutletPhase})); + } + + if (defined($result->{rPDUOutletStatusLoad}) && $result->{rPDUOutletStatusLoad} =~ /[0-9]/) { + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'load', instance => $instance, value => $result->{rPDUOutletStatusLoad}); + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Outlet '%s' load is %s A [bank : %s, phase : %s]", + $result->{rPDUOutletStatusOutletName}, $result->{rPDUOutletStatusLoad}, + $result->{rPDUOutletStatusOutletBank}, $result->{rPDUOutletStatusOutletPhase})); + } + $self->{output}->perfdata_add(label => 'load_' . $result->{rPDUOutletStatusOutletName} . '_bank_' . $result->{rPDUOutletStatusOutletBank} . '_' . $result->{rPDUOutletStatusOutletPhase}, unit => 'A', + value => $result->{rPDULoadStatusLoad}, + warning => $warn, + critical => $crit, + min => 0); + } + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +sub check_filter { + my ($self, %options) = @_; + + foreach (@{$self->{filter}}) { + if ($options{section} =~ /$_->{filter}/) { + if (!defined($options{instance}) && !defined($_->{instance})) { + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); + return 1; + } elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) { + $self->{components}->{$options{section}}->{skip}++ if (defined($self->{components}->{$options{section}})); + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); + return 1; + } + } + } + + return 0; +} + +sub get_severity_numeric { + my ($self, %options) = @_; + my $status = 'OK'; # default + my $thresholds = { warning => undef, critical => undef }; + my $checked = 0; + + if (defined($self->{numeric_threshold}->{$options{section}})) { + my $exits = []; + foreach (@{$self->{numeric_threshold}->{$options{section}}}) { + if ($options{instance} =~ /$_->{instance}/) { + push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]); + $thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label}); + $checked = 1; + } + } + $status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0); + } + + return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked); +} + +sub get_severity { + my ($self, %options) = @_; + my $status = 'UNKNOWN'; # default + + if (defined($self->{overload_th}->{$options{section}})) { + foreach (@{$self->{overload_th}->{$options{section}}}) { + if ($options{value} =~ /$_->{filter}/i && + (!defined($options{instance}) || $options{instance} =~ /$_->{instance}/)) { + $status = $_->{status}; + return $status; + } + } + } + my $label = defined($options{label}) ? $options{label} : $options{section}; + foreach (@{$thresholds->{$label}}) { + if ($options{value} =~ /$$_[0]/i) { + $status = $$_[1]; + return $status; + } + } + + return $status; +} + +1; + +__END__ + +=head1 MODE + +Check outlet state. + +=over 8 + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter=outlet,1 + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='outlet,WARNING,^(?!(outletStatusOn)$)' + +=item B<--warning> + +Set warning threshold for temperatures (syntax: type,instance,threshold) +Example: --warning='load,.*,30' + +=item B<--critical> + +Set critical threshold for temperatures (syntax: type,instance,threshold) +Example: --critical='load,.*,40' +=back + +=cut \ No newline at end of file diff --git a/centreon-plugins/hardware/pdu/apc/snmp/plugin.pm b/centreon-plugins/hardware/pdu/apc/snmp/plugin.pm new file mode 100644 index 000000000..33f4f6de7 --- /dev/null +++ b/centreon-plugins/hardware/pdu/apc/snmp/plugin.pm @@ -0,0 +1,51 @@ +# +# Copyright 2015 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::pdu::apc::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + # $options->{options} = options object + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'load' => 'hardware::pdu::apc::snmp::mode::load', + 'hardware' => 'hardware::pdu::apc::snmp::mode::hardware', + 'outlet' => 'hardware::pdu::apc::snmp::mode::outlet', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check APC PDU in SNMP (PowerNet-MIB). + +=cut