diff --git a/centreon/common/radlan/mode/components/fan.pm b/centreon/common/radlan/mode/components/fan.pm new file mode 100644 index 000000000..c91449654 --- /dev/null +++ b/centreon/common/radlan/mode/components/fan.pm @@ -0,0 +1,74 @@ +# +# Copyright 2019 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 centreon::common::radlan::mode::components::fan; + +use strict; +use warnings; + +my %map_states = ( + 1 => 'normal', + 2 => 'warning', + 3 => 'critical', + 4 => 'shutdown', + 5 => 'notPresent', + 6 => 'notFunctioning', +); + +my $mapping = { + rlEnvMonFanStatusDescr => { oid => '.1.3.6.1.4.1.89.83.1.1.1.2' }, + rlEnvMonFanState => { oid => '.1.3.6.1.4.1.89.83.1.1.1.3', map => \%map_states }, +}; +my $oid_rlEnvMonFanStatusEntry = '.1.3.6.1.4.1.89.83.1.1.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_rlEnvMonFanStatusEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking fans'); + $self->{components}->{fan} = { name => 'fans', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'fan')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonFanStatusEntry}})) { + next if ($oid !~ /^$mapping->{rlEnvMonFanState}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rlEnvMonFanStatusEntry}, instance => $instance); + + next if ($self->check_filter(section => 'fan', instance => $instance, name => $result->{rlEnvMonFanStatusDescr})); + next if ($result->{rlEnvMonFanState} eq 'notPresent' && + $self->absent_problem(section => 'fan', instance => $instance, name => $result->{rlEnvMonFanStatusDescr})); + + $self->{components}->{fan}->{total}++; + $self->{output}->output_add(long_msg => sprintf("fan '%s' state is %s [instance: %s]", + $result->{rlEnvMonFanStatusDescr}, $result->{rlEnvMonFanState}, $instance)); + my $exit = $self->get_severity(section => 'fan', value => $result->{rlEnvMonFanState}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Fan '%s' state is %s.", $result->{rlEnvMonFanStatusDescr}, $result->{rlEnvMonFanState})); + } + } +} + +1; diff --git a/centreon/common/radlan/mode/components/psu.pm b/centreon/common/radlan/mode/components/psu.pm new file mode 100644 index 000000000..0e72fbdc5 --- /dev/null +++ b/centreon/common/radlan/mode/components/psu.pm @@ -0,0 +1,74 @@ +# +# Copyright 2019 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 centreon::common::radlan::mode::components::psu; + +use strict; +use warnings; + +my %map_states = ( + 1 => 'normal', + 2 => 'warning', + 3 => 'critical', + 4 => 'shutdown', + 5 => 'notPresent', + 6 => 'notFunctioning', +); + +my $mapping = { + rlEnvMonSupplyStatusDescr => { oid => '.1.3.6.1.4.1.89.83.1.2.1' }, + rlEnvMonSupplyState => { oid => '.1.3.6.1.4.1.89.83.1.2.1.3', map => \%map_states }, +}; +my $oid_rlEnvMonSupplyStatusEntry = '.1.3.6.1.4.1.89.83.1.2.1.2'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_rlEnvMonSupplyStatusEntry }; +} + +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')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonSupplyStatusEntry}})) { + next if ($oid !~ /^$mapping->{rlEnvMonSupplyState}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rlEnvMonSupplyStatusEntry}, instance => $instance); + + next if ($self->check_filter(section => 'psu', instance => $instance, name => $result->{rlEnvMonSupplyStatusDescr})); + next if ($result->{rlEnvMonSupplyState} eq 'notPresent' && + $self->absent_problem(section => 'psu', instance => $instance, name => $result->{rlEnvMonSupplyStatusDescr})); + + $self->{components}->{psu}->{total}++; + $self->{output}->output_add(long_msg => sprintf("power supply '%s' state is %s [instance: %s]", + $result->{rlEnvMonSupplyStatusDescr}, $result->{rlEnvMonSupplyState}, $instance)); + my $exit = $self->get_severity(section => 'psu', value => $result->{rlEnvMonSupplyState}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power supply '%s' state is %s.", $result->{rlEnvMonSupplyStatusDescr}, $result->{rlEnvMonSupplyState})); + } + } +} + +1; diff --git a/centreon/common/radlan/mode/environment.pm b/centreon/common/radlan/mode/environment.pm index fb1e83487..ca5762645 100644 --- a/centreon/common/radlan/mode/environment.pm +++ b/centreon/common/radlan/mode/environment.pm @@ -20,256 +20,57 @@ package centreon::common::radlan::mode::environment; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -my $oid_rlEnvMonFanStatusEntry = '.1.3.6.1.4.1.89.83.1.1.1'; -my $oid_rlEnvMonFanStatusDescr = '.1.3.6.1.4.1.89.83.1.1.1.2'; -my $oid_rlEnvMonFanState = '.1.3.6.1.4.1.89.83.1.1.1.3'; -my $oid_rlEnvMonSupplyStatusEntry = '.1.3.6.1.4.1.89.83.1.2.1'; -my $oid_rlEnvMonSupplyStatusDescr = '.1.3.6.1.4.1.89.83.1.2.1.2'; -my $oid_rlEnvMonSupplyState = '.1.3.6.1.4.1.89.83.1.2.1.3'; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^fan|psu$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + default => [ + ['shutdown', 'WARNING'], + ['warning', 'WARNING'], + ['critical', 'CRITICAL'], + ['notFunctioning', 'CRITICAL'], + ['notPresent', 'OK'], + ['normal', 'OK'], + ], + }; + + $self->{components_path} = 'centreon::common::radlan::mode::components'; + $self->{components_module} = ['fan', 'psu']; +} -my $thresholds = { - psu => [ - ['shutdown', 'WARNING'], - ['warning', 'WARNING'], - ['critical', 'CRITICAL'], - ['notFunctioning', 'CRITICAL'], - ['notPresent', 'OK'], - ['normal', 'OK'], - ], - fan => [ - ['shutdown', 'WARNING'], - ['warning', 'WARNING'], - ['critical', 'CRITICAL'], - ['notFunctioning', 'CRITICAL'], - ['notPresent', 'OK'], - ['normal', 'OK'], - ], -}; +sub snmp_execute { + my ($self, %options) = @_; -my %map_states = ( - 1 => 'normal', - 2 => 'warning', - 3 => 'critical', - 4 => 'shutdown', - 5 => 'notPresent', - 6 => 'notFunctioning', -); + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => 'all' }, - "absent-problem:s" => { name => 'absent' }, - "no-component:s" => { name => 'no_component' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - }); - - $self->{components} = {}; - $self->{no_components} = undef; + $options{options}->add_options(arguments => {}); + 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->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ($1, $2, $3); - 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}; - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - # There is a bug with get_leef and snmpv1. - $self->{results} = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_rlEnvMonFanStatusEntry }, - { oid => $oid_rlEnvMonSupplyStatusEntry }, - ]); - - if ($self->{option_results}->{component} eq 'all') { - $self->check_fan(); - $self->check_psu(); - } elsif ($self->{option_results}->{component} eq 'fan') { - $self->check_fan(); - } elsif ($self->{option_results}->{component} eq 'psu') { - $self->check_psu(); - } else { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - - 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 check_exclude { - my ($self, %options) = @_; - - if (defined($options{instance})) { - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { - $self->{components}->{$options{section}}->{skip}++; - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } - return 0; -} - -sub absent_problem { - my ($self, %options) = @_; - - if (defined($self->{option_results}->{absent}) && - $self->{option_results}->{absent} =~ /(^|\s|,)($options{section}(\s*,|$)|${options{section}}[^,]*#\Q$options{instance}\E#)/) { - $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; -} - -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) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - -sub check_fan { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking fans"); - $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'fan')); - - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonFanStatusEntry}})) { - next if ($oid !~ /^$oid_rlEnvMonFanStatusDescr\.(.*)/); - my $instance = $self->{results}->{$oid_rlEnvMonFanStatusEntry}->{$oid}; - my $fan_state = $self->{results}->{$oid_rlEnvMonFanStatusEntry}->{$oid_rlEnvMonFanState . '.' . $1}; - - next if ($self->check_exclude(section => 'fan', instance => $instance)); - next if ($map_states{$fan_state} eq 'notPresent' && - $self->absent_problem(section => 'fan', instance => $instance)); - - $self->{components}->{fan}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Fan '%s' state is %s.", - $instance, $map_states{$fan_state})); - my $exit = $self->get_severity(section => 'fan', value => $map_states{$fan_state}); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Fan '%s' state is %s.", $instance, $map_states{$fan_state})); - } - } -} - -sub check_psu { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking power supplies"); - $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'psu')); - - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonSupplyStatusEntry}})) { - next if ($oid !~ /^$oid_rlEnvMonSupplyStatusDescr\.(.*)/); - my $instance = $self->{results}->{$oid_rlEnvMonSupplyStatusEntry}->{$oid}; - my $psu_state = $self->{results}->{$oid_rlEnvMonSupplyStatusEntry}->{$oid_rlEnvMonSupplyState . '.' . $1}; - - next if ($self->check_exclude(section => 'psu', instance => $instance)); - next if ($map_states{$psu_state} eq 'notPresent' && - $self->absent_problem(section => 'psu', instance => $instance)); - - $self->{components}->{psu}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Power supply '%s' state is %s.", - $instance, $map_states{$psu_state})); - my $exit = $self->get_severity(section => 'psu', value => $map_states{$psu_state}); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Power supply '%s' state is %s.", $instance, $map_states{$psu_state})); - } - } -} - 1; __END__ =head1 MODE -Check environment (RADLAN-HWENVIROMENT) (Fans, Power Supplies). +Check environment (RADLAN-HWENVIROMENT). =over 8 @@ -278,10 +79,10 @@ Check environment (RADLAN-HWENVIROMENT) (Fans, Power Supplies). Which component to check (Default: 'all'). Can be: 'psu', 'fan'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=psu) -Can also exclude specific instance: --exclude='fan#fan2_unit1#' +Exclude some parts (comma seperated list) (Example: --filter=psu) +Can also exclude specific instance: --filter=fan,1 =item B<--absent-problem> diff --git a/hardware/sensors/sensorip/snmp/mode/components/humidity.pm b/hardware/sensors/sensorip/snmp/mode/components/humidity.pm index a4a7fc38d..9a21fd097 100644 --- a/hardware/sensors/sensorip/snmp/mode/components/humidity.pm +++ b/hardware/sensors/sensorip/snmp/mode/components/humidity.pm @@ -50,9 +50,9 @@ my $mapping = { my $oid_sensorProbeHumidityEntry = '.1.3.6.1.4.1.3854.1.2.2.1.17.1'; sub load { - my (%options) = @_; - - push @{$options{request}}, { oid => $oid_sensorProbeHumidityEntry, end => $mapping->{sensorProbeHumidityLowCritical}->{oid} }; + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_sensorProbeHumidityEntry, end => $mapping->{sensorProbeHumidityLowCritical}->{oid} }; } sub check { @@ -60,14 +60,14 @@ sub check { $self->{output}->output_add(long_msg => "Checking humidity"); $self->{components}->{humidity} = {name => 'humidity', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'humidity')); + return if ($self->check_filter(section => 'humidity')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sensorProbeHumidityEntry}})) { next if ($oid !~ /^$mapping->{sensorProbeHumidityPercent}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sensorProbeHumidityEntry}, instance => $instance); - next if ($self->check_exclude(section => 'humidity', instance => $instance)); + next if ($self->check_filter(section => 'humidity', instance => $instance)); if ($result->{sensorProbeHumidityOnline} =~ /Offline/i) { $self->absent_problem(section => 'humidity', instance => $instance); next; diff --git a/hardware/sensors/sensorip/snmp/mode/components/sp.pm b/hardware/sensors/sensorip/snmp/mode/components/sp.pm index b7a790a23..214e5b64a 100644 --- a/hardware/sensors/sensorip/snmp/mode/components/sp.pm +++ b/hardware/sensors/sensorip/snmp/mode/components/sp.pm @@ -33,23 +33,24 @@ my %map_sp_status = ( my $oid_spStatus = '.1.3.6.1.4.1.3854.1.1.2'; sub load { - my (%options) = @_; - - push @{$options{request}}, { oid => $oid_spStatus }; + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_spStatus }; } sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking sp"); - $self->{components}->{sp} = {name => 'sp', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'sp')); + $self->{components}->{sp} = { name => 'sp', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'sp')); + return if (scalar(keys %{$self->{results}->{$oid_spStatus}}) <= 0); my $instance = 0; my $sp_status = defined($map_sp_status{$self->{results}->{$oid_spStatus}->{$oid_spStatus . '.' . $instance}}) ? $map_sp_status{$self->{results}->{$oid_spStatus}->{$oid_spStatus . '.' . $instance}} : 'unknown'; - return if ($self->check_exclude(section => 'sp', instance => $instance)); + return if ($self->check_filter(section => 'sp', instance => $instance)); return if ($sp_status =~ /noStatus/i && $self->absent_problem(section => 'sp', instance => $instance)); @@ -63,4 +64,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/hardware/sensors/sensorip/snmp/mode/components/switch.pm b/hardware/sensors/sensorip/snmp/mode/components/switch.pm index adf941de7..dccd15c5c 100644 --- a/hardware/sensors/sensorip/snmp/mode/components/switch.pm +++ b/hardware/sensors/sensorip/snmp/mode/components/switch.pm @@ -45,9 +45,9 @@ my $mapping = { my $oid_sensorProbeSwitchEntry = '.1.3.6.1.4.1.3854.1.2.2.1.18.1'; sub load { - my (%options) = @_; - - push @{$options{request}}, { oid => $oid_sensorProbeSwitchEntry, end => $mapping->{sensorProbeSwitchOnline}->{oid} }; + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_sensorProbeSwitchEntry, end => $mapping->{sensorProbeSwitchOnline}->{oid} }; } sub check { @@ -55,14 +55,14 @@ sub check { $self->{output}->output_add(long_msg => "Checking switch"); $self->{components}->{switch} = {name => 'switch', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'switch')); + return if ($self->check_filter(section => 'switch')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sensorProbeSwitchEntry}})) { next if ($oid !~ /^$mapping->{sensorProbeSwitchStatus}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sensorProbeSwitchEntry}, instance => $instance); - next if ($self->check_exclude(section => 'switch', instance => $instance)); + next if ($self->check_filter(section => 'switch', instance => $instance)); if ($result->{sensorProbeSwitchOnline} =~ /Offline/i) { $self->absent_problem(section => 'switch', instance => $instance); next; @@ -79,4 +79,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/hardware/sensors/sensorip/snmp/mode/components/temperature.pm b/hardware/sensors/sensorip/snmp/mode/components/temperature.pm index dd108cb4c..e2610e1e2 100644 --- a/hardware/sensors/sensorip/snmp/mode/components/temperature.pm +++ b/hardware/sensors/sensorip/snmp/mode/components/temperature.pm @@ -50,9 +50,9 @@ my $mapping = { my $oid_sensorProbeTempEntry = '.1.3.6.1.4.1.3854.1.2.2.1.16.1'; sub load { - my (%options) = @_; - - push @{$options{request}}, { oid => $oid_sensorProbeTempEntry, end => $mapping->{sensorProbeTempLowCritical}->{oid} }; + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_sensorProbeTempEntry, end => $mapping->{sensorProbeTempLowCritical}->{oid} }; } sub check { @@ -60,14 +60,14 @@ sub check { $self->{output}->output_add(long_msg => "Checking temperatures"); $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'temperature')); + return if ($self->check_filter(section => 'temperature')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sensorProbeTempEntry}})) { next if ($oid !~ /^$mapping->{sensorProbeTempDegree}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sensorProbeTempEntry}, instance => $instance); - next if ($self->check_exclude(section => 'temperature', instance => $instance)); + next if ($self->check_filter(section => 'temperature', instance => $instance)); if ($result->{sensorProbeTempOnline} =~ /Offline/i) { $self->absent_problem(section => 'temperature', instance => $instance); next; diff --git a/hardware/sensors/sensorip/snmp/mode/sensors.pm b/hardware/sensors/sensorip/snmp/mode/sensors.pm index 80af242b5..540f3e92f 100644 --- a/hardware/sensors/sensorip/snmp/mode/sensors.pm +++ b/hardware/sensors/sensorip/snmp/mode/sensors.pm @@ -20,243 +20,66 @@ package hardware::sensors::sensorip::snmp::mode::sensors; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -use centreon::plugins::misc; -my $thresholds = { - sp => [ - ['noStatus', 'UNKNOWN'], - ['normal', 'OK'], - ['warning', 'WARNING'], - ['critical', 'CRITICAL'], - ['sensorError', 'CRITICAL'], - ], - switch => [ - ['noStatus', 'UNKNOWN'], - ['normal', 'OK'], - ['highCritical', 'CRITICAL'], - ['lowCritical', 'CRITICAL'], - ['sensorError', 'CRITICAL'], - ['relayOn', 'OK'], - ['relayOff', 'OK'], - ], -}; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^sp|temperature|humidity|switch$'; + $self->{regexp_threshold_numeric_check_section_option} = '^humidity|temperature$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + sp => [ + ['noStatus', 'UNKNOWN'], + ['normal', 'OK'], + ['warning', 'WARNING'], + ['critical', 'CRITICAL'], + ['sensorError', 'CRITICAL'], + ], + switch => [ + ['noStatus', 'UNKNOWN'], + ['normal', 'OK'], + ['highCritical', 'CRITICAL'], + ['lowCritical', 'CRITICAL'], + ['sensorError', 'CRITICAL'], + ['relayOn', 'OK'], + ['relayOff', 'OK'], + ], + }; + + $self->{components_path} = 'hardware::sensors::sensorip::snmp::mode::components'; + $self->{components_module} = ['sp', 'temperature', 'humidity', 'switch']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => '.*' }, - "absent-problem:s" => { name => 'absent' }, - "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; + $options{options}->add_options(arguments => {}); + 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->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ($1, $2, $3); - 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}; - } - - $self->{numeric_threshold} = {}; - foreach my $option (('warning', 'critical')) { - foreach my $val (@{$self->{option_results}->{$option}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $regexp, $value) = ($1, $2, $3); - if ($section !~ /(humidity|temperature)/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: battery or temperature)."); - $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, regexp => $regexp }; - } - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - my $snmp_request = []; - my @components = ('sp', 'temperature', 'humidity', 'switch'); - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "hardware::sensors::sensorip::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::sensors::sensorip::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 check_exclude { - my ($self, %options) = @_; - - if (defined($options{instance})) { - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { - $self->{components}->{$options{section}}->{skip}++; - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } - return 0; -} - -sub absent_problem { - my ($self, %options) = @_; - - if (defined($self->{option_results}->{absent}) && - $self->{option_results}->{absent} =~ /(^|\s|,)($options{section}(\s*,|$)|${options{section}}[^,]*#\Q$options{instance}\E#)/) { - $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; -} - -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} =~ /$_->{regexp}/) { - 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) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - 1; __END__ =head1 MODE -Check sensor components (Sensor Probe status, Temperatures, Humidity, Switch). +Check sensor components. =over 8 @@ -265,10 +88,10 @@ Check sensor components (Sensor Probe status, Temperatures, Humidity, Switch). Which component to check (Default: '.*'). Can be: 'sp', 'temperature', 'humidity', 'switch'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=psu) -Can also exclude specific instance: --exclude='humidty#0#' +Exclude some parts (comma seperated list) (Example: --filter=psu) +Can also exclude specific instance: --filter=humidty,0 =item B<--absent-problem> diff --git a/hardware/server/fujitsu/snmp/mode/components/cpu.pm b/hardware/server/fujitsu/snmp/mode/components/cpu.pm index d27ac3766..afd9af382 100644 --- a/hardware/server/fujitsu/snmp/mode/components/cpu.pm +++ b/hardware/server/fujitsu/snmp/mode/components/cpu.pm @@ -45,7 +45,7 @@ my $oid_sc2CPUs = '.1.3.6.1.4.1.231.2.10.2.2.10.6.4.1'; sub load { my ($self) = @_; - + push @{$self->{request}}, { oid => $oid_sc2CPUs, end => $mapping->{sc2}->{sc2cpuStatus} }, { oid => $mapping->{sc}->{cpuStatus}->{oid} }; } diff --git a/hardware/server/sun/mgmt_cards/components/showenvironment/disk.pm b/hardware/server/sun/mgmt_cards/components/showenvironment/disk.pm index d402d5185..df2a63d95 100644 --- a/hardware/server/sun/mgmt_cards/components/showenvironment/disk.pm +++ b/hardware/server/sun/mgmt_cards/components/showenvironment/disk.pm @@ -28,7 +28,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking disks"); $self->{components}->{disk} = {name => 'disks', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'disk')); + return if ($self->check_filter(section => 'disk')); if ($self->{stdout} =~ /^System Disks.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) { #Disk Status Service OK2RM @@ -41,7 +41,7 @@ sub check { my $disk_status = defined($2) ? $2 : 'unknown'; my $disk_name = defined($1) ? $1 : 'unknown'; - next if ($self->check_exclude(section => 'disk', instance => $disk_name)); + next if ($self->check_filter(section => 'disk', instance => $disk_name)); $self->{components}->{disk}->{total}++; $self->{output}->output_add(long_msg => "Disk Status '" . $disk_name . "' is " . $disk_status); @@ -54,4 +54,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/hardware/server/sun/mgmt_cards/components/showenvironment/fan.pm b/hardware/server/sun/mgmt_cards/components/showenvironment/fan.pm index 83cdca804..10c932241 100644 --- a/hardware/server/sun/mgmt_cards/components/showenvironment/fan.pm +++ b/hardware/server/sun/mgmt_cards/components/showenvironment/fan.pm @@ -28,7 +28,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking fans"); $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'fan')); + return if ($self->check_filter(section => 'fan')); if ($self->{stdout} =~ /^Fans.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) { #Sensor Status Speed Warn Low @@ -41,7 +41,7 @@ sub check { my $fan_status = defined($2) ? $2 : 'unknown'; my $fan_name = defined($1) ? $1 : 'unknown'; - next if ($self->check_exclude(section => 'fan', instance => $fan_name)); + next if ($self->check_filter(section => 'fan', instance => $fan_name)); $self->{components}->{fan}->{total}++; $self->{output}->output_add(long_msg => "Fan Sensor Status '" . $fan_name . "' is " . $fan_status); @@ -54,4 +54,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/hardware/server/sun/mgmt_cards/components/showenvironment/psu.pm b/hardware/server/sun/mgmt_cards/components/showenvironment/psu.pm index eac47116c..c773c21c3 100644 --- a/hardware/server/sun/mgmt_cards/components/showenvironment/psu.pm +++ b/hardware/server/sun/mgmt_cards/components/showenvironment/psu.pm @@ -28,7 +28,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking power supplies"); $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'psu')); + return if ($self->check_filter(section => 'psu')); if ($self->{stdout} =~ /^Power Supplies.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) { #Supply Status Underspeed Overtemp Overvolt Undervolt Overcurrent @@ -40,7 +40,7 @@ sub check { my $ps_status = defined($2) ? $2 : 'unknown'; my $ps_name = defined($1) ? $1 : 'unknown'; - next if ($self->check_exclude(section => 'psu', instance => $ps_name)); + next if ($self->check_filter(section => 'psu', instance => $ps_name)); $self->{components}->{psu}->{total}++; $self->{output}->output_add(long_msg => "Power Supplies Sensor Status '" . $ps_name . "' is " . $ps_status); @@ -53,4 +53,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/hardware/server/sun/mgmt_cards/components/showenvironment/resources.pm b/hardware/server/sun/mgmt_cards/components/showenvironment/resources.pm deleted file mode 100644 index 2b4aea7aa..000000000 --- a/hardware/server/sun/mgmt_cards/components/showenvironment/resources.pm +++ /dev/null @@ -1,63 +0,0 @@ -# -# Copyright 2019 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::server::sun::mgmt_cards::components::showenvironment::resources; - -use strict; -use warnings; -use Exporter; - -our $thresholds; - -our @ISA = qw(Exporter); -our @EXPORT_OK = qw($thresholds); - -$thresholds = { - temperature => [ - ['^(?!(OK)$)', 'CRITICAL'], - ['^OK$', 'OK'], - ], - si => [ - ['^(?!(OFF)$)', 'CRITICAL'], - ['^OFF$', 'OK'], - ], - disk => [ - ['^(?!(OK|NOT PRESENT)$)', 'CRITICAL'], - ['^OK|NOT PRESENT$', 'OK'], - ], - fan => [ - ['^(?!(OK|NOT PRESENT)$)', 'CRITICAL'], - ['^OK|NOT PRESENT$', 'OK'], - ], - voltage => [ - ['^(?!(OK)$)', 'CRITICAL'], - ['^OK$', 'OK'], - ], - psu => [ - ['^(?!(OK|NOT PRESENT)$)', 'CRITICAL'], - ['^OK|NOT PRESENT$', 'OK'], - ], - sensors => [ - ['^(?!(OK)$)', 'CRITICAL'], - ['^OK$', 'OK'], - ], -}; - -1; \ No newline at end of file diff --git a/hardware/server/sun/mgmt_cards/components/showenvironment/sensors.pm b/hardware/server/sun/mgmt_cards/components/showenvironment/sensors.pm index 8c59a8b1a..247ba6900 100644 --- a/hardware/server/sun/mgmt_cards/components/showenvironment/sensors.pm +++ b/hardware/server/sun/mgmt_cards/components/showenvironment/sensors.pm @@ -28,7 +28,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking sensors"); $self->{components}->{sensors} = {name => 'sensors', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'sensors')); + return if ($self->check_filter(section => 'sensors')); if ($self->{stdout} =~ /^Current sensors.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) { #Sensor Status @@ -40,7 +40,7 @@ sub check { my $sensor_status = defined($2) ? $2 : 'unknown'; my $sensor_name = defined($1) ? $1 : 'unknown'; - next if ($self->check_exclude(section => 'sensors', instance => $sensor_name)); + next if ($self->check_filter(section => 'sensors', instance => $sensor_name)); $self->{components}->{sensors}->{total}++; $self->{output}->output_add(long_msg => "Current Sensor status '" . $sensor_name . "' is " . $sensor_status); @@ -53,4 +53,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/hardware/server/sun/mgmt_cards/components/showenvironment/si.pm b/hardware/server/sun/mgmt_cards/components/showenvironment/si.pm index c909d0dc7..42407a5fe 100644 --- a/hardware/server/sun/mgmt_cards/components/showenvironment/si.pm +++ b/hardware/server/sun/mgmt_cards/components/showenvironment/si.pm @@ -28,7 +28,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking system indicator"); $self->{components}->{si} = {name => 'system indicator', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'si')); + return if ($self->check_filter(section => 'si')); #-------------------------------------------------------- #System Indicator Status: @@ -55,7 +55,7 @@ sub check { my $si_name = defined($1) ? $1 : 'unknown'; my $si_status = defined($2) ? $2 : 'unknown'; - next if ($self->check_exclude(section => 'si', instance => $si_name)); + next if ($self->check_filter(section => 'si', instance => $si_name)); $self->{components}->{si}->{total}++; $self->{output}->output_add(long_msg => "System Indicator Status '$si_name' is " . $si_status); @@ -68,4 +68,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/hardware/server/sun/mgmt_cards/components/showenvironment/temperature.pm b/hardware/server/sun/mgmt_cards/components/showenvironment/temperature.pm index 9acb2740e..519f85b25 100644 --- a/hardware/server/sun/mgmt_cards/components/showenvironment/temperature.pm +++ b/hardware/server/sun/mgmt_cards/components/showenvironment/temperature.pm @@ -28,7 +28,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking temperatures"); $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'temperature')); + return if ($self->check_filter(section => 'temperature')); if ($self->{stdout} =~ /^System Temperatures.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) { #Sensor Status Temp LowHard LowSoft LowWarn HighWarn HighSoft HighHard @@ -40,7 +40,7 @@ sub check { my $sensor_status = defined($2) ? $2 : 'unknown'; my $sensor_name = defined($1) ? $1 : 'unknown'; - next if ($self->check_exclude(section => 'temperature', instance => $sensor_name)); + next if ($self->check_filter(section => 'temperature', instance => $sensor_name)); $self->{components}->{temperature}->{total}++; $self->{output}->output_add(long_msg => "System Temperature Sensor '" . $sensor_name . "' is " . $sensor_status); @@ -53,4 +53,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/hardware/server/sun/mgmt_cards/components/showenvironment/voltage.pm b/hardware/server/sun/mgmt_cards/components/showenvironment/voltage.pm index 2782499fb..24b8a3e4c 100644 --- a/hardware/server/sun/mgmt_cards/components/showenvironment/voltage.pm +++ b/hardware/server/sun/mgmt_cards/components/showenvironment/voltage.pm @@ -28,7 +28,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking voltages"); $self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'voltage')); + return if ($self->check_filter(section => 'voltage')); if ($self->{stdout} =~ /^Voltage sensors.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) { #Sensor Status Voltage LowSoft LowWarn HighWarn HighSoft @@ -41,7 +41,7 @@ sub check { my $voltage_status = defined($2) ? $2 : 'unknown'; my $voltage_name = defined($1) ? $1 : 'unknown'; - next if ($self->check_exclude(section => 'voltage', instance => $voltage_name)); + next if ($self->check_filter(section => 'voltage', instance => $voltage_name)); $self->{components}->{voltage}->{total}++; $self->{output}->output_add(long_msg => "Voltage Sensor status '" . $voltage_name . "' is " . $voltage_status); @@ -54,4 +54,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/hardware/server/sun/mgmt_cards/mode/showenvironment.pm b/hardware/server/sun/mgmt_cards/mode/showenvironment.pm index f18e984ac..8b2196a25 100644 --- a/hardware/server/sun/mgmt_cards/mode/showenvironment.pm +++ b/hardware/server/sun/mgmt_cards/mode/showenvironment.pm @@ -20,47 +20,78 @@ package hardware::server::sun::mgmt_cards::mode::showenvironment; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; use centreon::plugins::misc; -use hardware::server::sun::mgmt_cards::components::showenvironment::resources qw($thresholds); -use hardware::server::sun::mgmt_cards::components::showenvironment::psu; -use hardware::server::sun::mgmt_cards::components::showenvironment::fan; -use hardware::server::sun::mgmt_cards::components::showenvironment::temperature; -use hardware::server::sun::mgmt_cards::components::showenvironment::sensors; -use hardware::server::sun::mgmt_cards::components::showenvironment::voltage; -use hardware::server::sun::mgmt_cards::components::showenvironment::si; -use hardware::server::sun::mgmt_cards::components::showenvironment::disk; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = + '^temperature|si|disk|fan|voltage|psu|sensors$'; + + $self->{cb_hook2} = 'execute_command'; + + $self->{components_exec_load} = 0; + + $self->{thresholds} = { + temperature => [ + ['^(?!(OK)$)', 'CRITICAL'], + ['^OK$', 'OK'], + ], + si => [ + ['^(?!(OFF)$)', 'CRITICAL'], + ['^OFF$', 'OK'], + ], + disk => [ + ['^(?!(OK|NOT PRESENT)$)', 'CRITICAL'], + ['^OK|NOT PRESENT$', 'OK'], + ], + fan => [ + ['^(?!(OK|NOT PRESENT)$)', 'CRITICAL'], + ['^OK|NOT PRESENT$', 'OK'], + ], + voltage => [ + ['^(?!(OK)$)', 'CRITICAL'], + ['^OK$', 'OK'], + ], + psu => [ + ['^(?!(OK|NOT PRESENT)$)', 'CRITICAL'], + ['^OK|NOT PRESENT$', 'OK'], + ], + sensors => [ + ['^(?!(OK)$)', 'CRITICAL'], + ['^OK$', 'OK'], + ], + }; + + $self->{components_path} = 'hardware::server::sun::mgmt_cards::components::showenvironment'; + $self->{components_module} = ['temperature', 'si', 'disk', 'fan', 'voltage', 'psu', 'sensors']; +} sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1, no_absent => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => 23 }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "command-plink:s" => { name => 'command_plink', default => 'plink' }, - "ssh" => { name => 'ssh' }, - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => 'all' }, - "no-component:s" => { name => 'no_component' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - }); - $self->{components} = {}; - $self->{no_components} = undef; + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port', default => 23 }, + 'username:s' => { name => 'username' }, + 'password:s' => { name => 'password' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'command-plink:s' => { name => 'command_plink', default => 'plink' }, + 'ssh' => { name => 'ssh' }, + }); + return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); + $self->SUPER::check_options(%options); if (!defined($self->{option_results}->{hostname})) { $self->{output}->add_option_msg(short_msg => "Need to specify a hostname."); @@ -78,29 +109,6 @@ sub check_options { if (!defined($self->{option_results}->{ssh})) { require hardware::server::sun::mgmt_cards::lib::telnet; } - - 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->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ($1, $2, $3); - 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}; - } } sub ssh_command { @@ -109,10 +117,11 @@ sub ssh_command { my $cmd_in = $self->{option_results}->{username} . '\n' . $self->{option_results}->{password} . '\nshowenvironment\nlogout\n'; my $cmd = "echo -e '$cmd_in' | " . $self->{option_results}->{command_plink} . " -batch " . $self->{option_results}->{hostname} . " 2>&1"; my ($lerror, $stdout, $exit_code) = centreon::plugins::misc::backtick( - command => $cmd, - timeout => $self->{option_results}->{timeout}, - wait_exit => 1 - ); + command => $cmd, + timeout => $self->{option_results}->{timeout}, + wait_exit => 1 + ); + $stdout =~ s/\r//g; if ($lerror <= -1000) { $self->{output}->output_add(severity => 'UNKNOWN', @@ -139,128 +148,24 @@ sub ssh_command { return $stdout; } -sub global { +sub execute_command { my ($self, %options) = @_; - hardware::server::sun::mgmt_cards::components::showenvironment::psu::check($self); - hardware::server::sun::mgmt_cards::components::showenvironment::fan::check($self); - hardware::server::sun::mgmt_cards::components::showenvironment::temperature::check($self); - hardware::server::sun::mgmt_cards::components::showenvironment::sensors::check($self); - hardware::server::sun::mgmt_cards::components::showenvironment::voltage::check($self); - hardware::server::sun::mgmt_cards::components::showenvironment::si::check($self); - hardware::server::sun::mgmt_cards::components::showenvironment::disk::check($self); -} - -sub component { - my ($self, %options) = @_; - - if ($self->{option_results}->{component} eq 'si') { - hardware::server::sun::mgmt_cards::components::showenvironment::si::check($self); - } elsif ($self->{option_results}->{component} eq 'psu') { - hardware::server::sun::mgmt_cards::components::showenvironment::psu::check($self); - } elsif ($self->{option_results}->{component} eq 'fan') { - hardware::server::sun::mgmt_cards::components::showenvironment::fan::check($self); - } elsif ($self->{option_results}->{component} eq 'temperature') { - hardware::server::sun::mgmt_cards::components::showenvironment::temperature::check($self); - } elsif ($self->{option_results}->{component} eq 'sensors') { - hardware::server::sun::mgmt_cards::components::showenvironment::sensors::check($self); - } elsif ($self->{option_results}->{component} eq 'voltage') { - hardware::server::sun::mgmt_cards::components::showenvironment::voltage::check($self); - } elsif ($self->{option_results}->{component} eq 'disk') { - hardware::server::sun::mgmt_cards::components::showenvironment::disk::check($self); - } else { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } -} - -sub run { - my ($self, %options) = @_; - if (defined($self->{option_results}->{ssh})) { $self->{stdout} = $self->ssh_command(); } else { my $telnet_handle = hardware::server::sun::mgmt_cards::lib::telnet::connect( - username => $self->{option_results}->{username}, - password => $self->{option_results}->{password}, - hostname => $self->{option_results}->{hostname}, - port => $self->{option_results}->{port}, - timeout => $self->{option_results}->{timeout}, - output => $self->{output}); + username => $self->{option_results}->{username}, + password => $self->{option_results}->{password}, + hostname => $self->{option_results}->{hostname}, + port => $self->{option_results}->{port}, + timeout => $self->{option_results}->{timeout}, + output => $self->{output} + ); my @lines = $telnet_handle->cmd("showenvironment"); $self->{stdout} = join("", @lines); } - $self->{stdout} =~ s/\r//msg; - - if ($self->{option_results}->{component} eq 'all') { - $self->global(); - } else { - $self->component(); - } - - 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}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $self->{components}->{$comp}->{skip} . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components [%s] are ok.", - $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 check_exclude { - my ($self, %options) = @_; - - if (defined($options{instance})) { - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { - $self->{components}->{$options{section}}->{skip}++; - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } - return 0; -} - -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) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; } 1; @@ -303,13 +208,13 @@ Use ssh (with plink) instead of telnet. =item B<--component> -Which component to check (Default: 'all'). +Which component to check (Default: '.*'). Can be: 'temperature', 'si', 'disk', 'fan', 'voltage', 'psu', 'sensors'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=fan) -Can also exclude specific instance: --exclude=fan#F1.RS# +Exclude some parts (comma seperated list) (Example: --filter=fan) +Can also exclude specific instance: --filter=fan,F1.RS =item B<--no-component> diff --git a/os/solaris/local/mode/lomv120.pm b/os/solaris/local/mode/lomv120.pm index 72cf0e7e8..30f38f3ff 100644 --- a/os/solaris/local/mode/lomv120.pm +++ b/os/solaris/local/mode/lomv120.pm @@ -20,131 +20,66 @@ package os::solaris::local::mode::lomv120; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; use centreon::plugins::misc; -use os::solaris::local::mode::lomv120components::fan; -use os::solaris::local::mode::lomv120components::psu; -use os::solaris::local::mode::lomv120components::voltage; -use os::solaris::local::mode::lomv120components::sf; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^fan|psu|voltage|sf$'; + + $self->{cb_hook2} = 'command_execute'; + + $self->{thresholds} = { + default => [ + ['^(?!(OK)$)' => 'CRITICAL'], + ], + }; + + $self->{components_exec_load} = 0; + + $self->{components_path} = 'os::solaris::local::mode::lomv120components'; + $self->{components_module} = ['fan', 'psu', 'voltage', 'sf']; +} + +sub command_execute { + my ($self, %options) = @_; + + ($self->{stdout}) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}, + no_quit => 1 + ); +} sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "remote" => { name => 'remote' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'lom' }, - "command-path:s" => { name => 'command_path', default => '/usr/sbin' }, - "command-options:s" => { name => 'command_options', default => '-fpv 2>&1'}, - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => 'all' }, - "no-component:s" => { name => 'no_component' }, - }); - $self->{components} = {}; - $self->{no_components} = undef; + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'remote' => { name => 'remote' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'lom' }, + 'command-path:s' => { name => 'command_path', default => '/usr/sbin' }, + 'command-options:s' => { name => 'command_options', default => '-fpv 2>&1'}, + }); + 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'; - } - } -} - -sub component { - my ($self, %options) = @_; - - if ($self->{option_results}->{component} eq 'all') { - os::solaris::local::mode::lomv120components::fan::check($self); - os::solaris::local::mode::lomv120components::psu::check($self); - os::solaris::local::mode::lomv120components::voltage::check($self); - os::solaris::local::mode::lomv120components::sf::check($self); - } elsif ($self->{option_results}->{component} eq 'fan') { - os::solaris::local::mode::lomv120components::fan::check($self); - } elsif ($self->{option_results}->{component} eq 'psu') { - os::solaris::local::mode::lomv120components::psu::check($self); - } elsif ($self->{option_results}->{component} eq 'voltage') { - os::solaris::local::mode::lomv120components::voltage::check($self); - } elsif ($self->{option_results}->{component} eq 'sf') { - os::solaris::local::mode::lomv120components::sf::check($self); - } else { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - - 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}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $self->{components}->{$comp}->{skip} . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components [%s] are ok.", - $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.'); - } -} - -sub run { - my ($self, %options) = @_; - - ($self->{stdout}) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - sudo => $self->{option_results}->{sudo}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}, - no_quit => 1); - $self->component(); - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub check_exclude { - my ($self, %options) = @_; - - if (defined($options{instance})) { - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { - $self->{components}->{$options{section}}->{skip}++; - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } - return 0; -} - 1; __END__ @@ -198,19 +133,25 @@ Command options (Default: '-fpv 2>&1'). =item B<--component> -Which component to check (Default: 'all'). +Which component to check (Default: '.*'). Can be: 'fan', 'psu', 'voltage', 'sf'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=fan,sf) -Can also exclude specific instance: --exclude=fan#1#,sf +Exclude some parts (comma seperated list) (Example: --filter=fan) +Can also exclude specific instance: --filter=fan,1 =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,status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='psu,WARNING,^(?!(ok)$)' + =back =cut diff --git a/os/solaris/local/mode/lomv120components/fan.pm b/os/solaris/local/mode/lomv120components/fan.pm index bff26f283..73161bf42 100644 --- a/os/solaris/local/mode/lomv120components/fan.pm +++ b/os/solaris/local/mode/lomv120components/fan.pm @@ -23,16 +23,12 @@ package os::solaris::local::mode::lomv120components::fan; use strict; use warnings; -my %conditions = ( - 1 => ['^(?!(OK)$)' => 'CRITICAL'], -); - sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking fans"); $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'fan')); + return if ($self->check_filter(section => 'fan')); #Fans: #1 FAULT speed 0% @@ -48,21 +44,22 @@ sub check { next if ($line !~ /^\s*(\S+)\s+(\S+)/); my ($instance, $status) = ($1, $2); - next if ($self->check_exclude(section => 'fan', instance => $instance)); + next if ($self->check_filter(section => 'fan', instance => $instance)); $self->{components}->{fan}->{total}++; - $self->{output}->output_add(long_msg => sprintf("fan '%s' status is %s.", - $instance, $status) - ); - foreach (keys %conditions) { - if ($status =~ /${$conditions{$_}}[0]/i) { - $self->{output}->output_add(severity => ${$conditions{$_}}[1], - short_msg => sprintf("fan '%s' status is %s", - $instance, $status)); - last; - } + $self->{output}->output_add( + long_msg => sprintf( + "fan '%s' status is %s.", + $instance, $status + ) + ); + my $exit = $self->get_severity(label => 'default', section => 'fan', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("fan '%s' status is %s", + $instance, $status)); } } } -1; \ No newline at end of file +1; diff --git a/os/solaris/local/mode/lomv120components/psu.pm b/os/solaris/local/mode/lomv120components/psu.pm index 2685b6a2b..9e2891a44 100644 --- a/os/solaris/local/mode/lomv120components/psu.pm +++ b/os/solaris/local/mode/lomv120components/psu.pm @@ -23,16 +23,12 @@ package os::solaris::local::mode::lomv120components::psu; use strict; use warnings; -my %conditions = ( - 1 => ['^(?!(OK)$)' => 'CRITICAL'], -); - 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_exclude(section => 'psu')); + return if ($self->check_filter(section => 'psu')); #PSUs: #1 OK @@ -44,21 +40,22 @@ sub check { next if ($line !~ /^\s*(\S+)\s+(\S+)/); my ($instance, $status) = ($1, $2); - next if ($self->check_exclude(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance)); $self->{components}->{psu}->{total}++; - $self->{output}->output_add(long_msg => sprintf("psu '%s' status is %s.", - $instance, $status) - ); - foreach (keys %conditions) { - if ($status =~ /${$conditions{$_}}[0]/i) { - $self->{output}->output_add(severity => ${$conditions{$_}}[1], - short_msg => sprintf("psu '%s' status is %s", - $instance, $status)); - last; - } + $self->{output}->output_add( + long_msg => sprintf( + "psu '%s' status is %s.", + $instance, $status + ) + ); + my $exit = $self->get_severity(label => 'default', section => 'psu', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("psu '%s' status is %s", + $instance, $status)); } } } -1; \ No newline at end of file +1; diff --git a/os/solaris/local/mode/lomv120components/sf.pm b/os/solaris/local/mode/lomv120components/sf.pm index 9921f8234..afcbacaba 100644 --- a/os/solaris/local/mode/lomv120components/sf.pm +++ b/os/solaris/local/mode/lomv120components/sf.pm @@ -24,16 +24,12 @@ use strict; use warnings; use centreon::plugins::misc; -my %conditions = ( - 1 => ['^(?!(ok)$)' => 'CRITICAL'], -); - sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking system flag"); $self->{components}->{sf} = {name => 'system flag', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'sf')); + return if ($self->check_filter(section => 'sf')); #System status flags: # 1 SCSI-Term status=ok @@ -48,21 +44,22 @@ sub check { next if ($line !~ /^\s*(\S+).*?status=(.*)/); my ($instance, $status) = ($1, $2); - next if ($self->check_exclude(section => 'sf', instance => $instance)); + next if ($self->check_filter(section => 'sf', instance => $instance)); $self->{components}->{sf}->{total}++; - $self->{output}->output_add(long_msg => sprintf("System flag '%s' status is %s.", - $instance, $status) - ); - foreach (keys %conditions) { - if ($status =~ /${$conditions{$_}}[0]/i) { - $self->{output}->output_add(severity => ${$conditions{$_}}[1], - short_msg => sprintf("System flag '%s' status is %s", - $instance, $status)); - last; - } + $self->{output}->output_add( + long_msg => sprintf( + "system flag '%s' status is %s.", + $instance, $status + ) + ); + my $exit = $self->get_severity(label => 'default', section => 'sf', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("system flag '%s' status is %s", + $instance, $status)); } } } -1; \ No newline at end of file +1; diff --git a/os/solaris/local/mode/lomv120components/voltage.pm b/os/solaris/local/mode/lomv120components/voltage.pm index 199eaaa4d..c7d2e8695 100644 --- a/os/solaris/local/mode/lomv120components/voltage.pm +++ b/os/solaris/local/mode/lomv120components/voltage.pm @@ -24,16 +24,12 @@ use strict; use warnings; use centreon::plugins::misc; -my %conditions = ( - 1 => ['^(?!(ok)$)' => 'CRITICAL'], -); - sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking supply voltages"); $self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'voltage')); + return if ($self->check_filter(section => 'voltage')); #Supply voltages: #1 5V status=ok @@ -48,21 +44,22 @@ sub check { next if ($line !~ /^\s*(\S+).*?status=(.*)/); my ($instance, $status) = ($1, $2); - next if ($self->check_exclude(section => 'voltage', instance => $instance)); + next if ($self->check_filter(section => 'voltage', instance => $instance)); $self->{components}->{voltage}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Supply voltage '%s' status is %s.", - $instance, $status) - ); - foreach (keys %conditions) { - if ($status =~ /${$conditions{$_}}[0]/i) { - $self->{output}->output_add(severity => ${$conditions{$_}}[1], - short_msg => sprintf("Supply voltage '%s' status is %s", - $instance, $status)); - last; - } + $self->{output}->output_add( + long_msg => sprintf( + "Supply voltage '%s' status is %s.", + $instance, $status + ) + ); + my $exit = $self->get_severity(label => 'default', section => 'voltage', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("supply voltage '%s' status is %s", + $instance, $status)); } } } -1; \ No newline at end of file +1;