diff --git a/centreon-plugins/hardware/server/hp/proliant/snmp/mode/hardware.pm b/centreon-plugins/hardware/server/hp/proliant/snmp/mode/hardware.pm index 8b04c70d8..e8c201cd1 100644 --- a/centreon-plugins/hardware/server/hp/proliant/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/server/hp/proliant/snmp/mode/hardware.pm @@ -496,7 +496,7 @@ Check Hardware (CPUs, Power Supplies, Power converters, Fans). =item B<--component> -Which component to check (Default: 'all'). +Which component to check (Default: '.*'). Can be: 'cpu', 'psu', 'pc', 'fan', 'temperature', 'lnic', 'pnic',... There are some magic words like: 'network', 'storage'. diff --git a/centreon-plugins/network/checkpoint/mode/components/fan.pm b/centreon-plugins/network/checkpoint/mode/components/fan.pm index 140947071..c809d1496 100644 --- a/centreon-plugins/network/checkpoint/mode/components/fan.pm +++ b/centreon-plugins/network/checkpoint/mode/components/fan.pm @@ -44,41 +44,44 @@ my %map_states_fan = ( 2 => 'reading error', ); +my $mapping = { + fanSpeedSensorName => { oid => '.1.3.6.1.4.1.2620.1.6.7.8.2.1.2' }, + fanSpeedSensorValue => { oid => '.1.3.6.1.4.1.2620.1.6.7.8.2.1.3' }, + fanSpeedSensorStatus => { oid => '.1.3.6.1.4.1.2620.1.6.7.8.2.1.6', map => \%map_states_fan }, +}; +my $oid_fanSpeedSensorEntry = '.1.3.6.1.4.1.2620.1.6.7.8.2.1'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_fanSpeedSensorEntry, start => $mapping->{fanSpeedSensorName}->{oid}, end => $mapping->{fanSpeedSensorStatus}->{oid} }; +} + 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')); - - my $oid_fanSpeedSensorEntry = '.1.3.6.1.4.1.2620.1.6.7.8.2.1'; - my $oid_fanSpeedSensorStatus = '.1.3.6.1.4.1.2620.1.6.7.8.2.1.6'; - my $oid_fanSpeedSensorValue = '.1.3.6.1.4.1.2620.1.6.7.8.2.1.3'; - my $oid_fanSpeedSensorName = '.1.3.6.1.4.1.2620.1.6.7.8.2.1.2'; - - my $result = $self->{snmp}->get_table(oid => $oid_fanSpeedSensorEntry); - return if (scalar(keys %$result) <= 0); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /^$oid_fanSpeedSensorStatus\.(\d+).(\d+)$/); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_fanSpeedSensorEntry}})) { + next if ($oid !~ /^$mapping->{fanSpeedSensorStatus}->{oid}\.(.*)$/); my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fanSpeedSensorEntry}, instance => $instance); next if ($self->check_exclude(section => 'fan', instance => $instance)); - - my $fan_name = $result->{$oid_fanSpeedSensorName . '.' . $instance}; - my $fan_state = $result->{$oid_fanSpeedSensorStatus . '.' . $instance}; $self->{components}->{fan}->{total}++; $self->{output}->output_add(long_msg => sprintf("Fan '%s' sensor out of range status is '%s'", - $fan_name, $map_states_fan{$fan_state})); - my $exit = $self->get_severity(section => 'fan', value => $map_states_fan{$fan_state}); + $result->{fanSpeedSensorName}, $result->{fanSpeedSensorStatus})); + my $exit = $self->get_severity(section => 'fan', value => $result->{fanSpeedSensorStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Fan '%s' sensor out of range status is '%s'", $fan_name, $map_states_fan{$fan_state})); + short_msg => sprintf("Fan '%s' sensor out of range status is '%s'", $result->{fanSpeedSensorName}, $result->{fanSpeedSensorStatus})); } - $self->{output}->perfdata_add(label => $fan_name , unit => 'rpm', - value => sprintf("%d", $result->{$oid_fanSpeedSensorValue . '.' . $instance})); + $self->{output}->perfdata_add(label => $result->{fanSpeedSensorName}, unit => 'rpm', + value => sprintf("%d", $result->{fanSpeedSensorValue})); } } diff --git a/centreon-plugins/network/checkpoint/mode/components/psu.pm b/centreon-plugins/network/checkpoint/mode/components/psu.pm index 3e1ca50bc..99afe159d 100644 --- a/centreon-plugins/network/checkpoint/mode/components/psu.pm +++ b/centreon-plugins/network/checkpoint/mode/components/psu.pm @@ -38,33 +38,38 @@ package network::checkpoint::mode::components::psu; use strict; use warnings; +my $mapping = { + powerSupplyStatus => { oid => '.1.3.6.1.4.1.2620.1.6.7.9.1.1.2' }, +}; +my $oid_powerSupplyStatus = '.1.3.6.1.4.1.2620.1.6.7.9.1.1.2'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_powerSupplyStatus }; +} + 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')); - - my $oid_powerSupplyStatus = '.1.3.6.1.4.1.2620.1.6.7.9.1.1.2'; - - my $result = $self->{snmp}->get_table(oid => $oid_powerSupplyStatus); - return if (scalar(keys %$result) <= 0); - - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - $key =~ /^$oid_powerSupplyStatus\.(\d+).(\d+)$/; + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_powerSupplyStatus}})) { + next if ($oid !~ /^$mapping->{powerSupplyStatus}->{oid}\.(.*)$/); my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_powerSupplyStatus}, instance => $instance); next if ($self->check_exclude(section => 'psu', instance => $instance)); - - my $psu_state = $result->{$key}; $self->{components}->{psu}->{total}++; $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is '%s'", - $instance, $psu_state)); - my $exit = $self->get_severity(section => 'psu', value => $psu_state); + $instance, $result->{powerSupplyStatus})); + my $exit = $self->get_severity(section => 'psu', value => $result->{powerSupplyStatus}); 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'", $instance, $psu_state)); + short_msg => sprintf("Power supply '%s' status is '%s'", $instance, $result->{powerSupplyStatus})); } } } diff --git a/centreon-plugins/network/checkpoint/mode/components/temperature.pm b/centreon-plugins/network/checkpoint/mode/components/temperature.pm index bb9b8231f..c2a7a4deb 100644 --- a/centreon-plugins/network/checkpoint/mode/components/temperature.pm +++ b/centreon-plugins/network/checkpoint/mode/components/temperature.pm @@ -44,6 +44,18 @@ my %map_states_temperature = ( 2 => 'reading error', ); +my $mapping = { + tempertureSensorName => { oid => '.1.3.6.1.4.1.2620.1.6.7.8.1.1.2' }, + tempertureSensorValue => { oid => '.1.3.6.1.4.1.2620.1.6.7.8.1.1.3' }, + tempertureSensorStatus => { oid => '.1.3.6.1.4.1.2620.1.6.7.8.1.1.6', map => \%map_states_temperature }, +}; +my $oid_tempertureSensorEntry = '.1.3.6.1.4.1.2620.1.6.7.8.1.1'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_tempertureSensorEntry, start => $mapping->{tempertureSensorName}->{oid}, end => $mapping->{tempertureSensorStatus}->{oid} }; +} sub check { my ($self) = @_; @@ -51,34 +63,25 @@ 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')); - - my $oid_tempertureSensorEntry = '.1.3.6.1.4.1.2620.1.6.7.8.1.1'; - my $oid_tempertureSensorName = '.1.3.6.1.4.1.2620.1.6.7.8.1.1.2'; - my $oid_tempertureSensorValue = '.1.3.6.1.4.1.2620.1.6.7.8.1.1.3'; - my $oid_tempertureSensorStatus = '.1.3.6.1.4.1.2620.1.6.7.8.1.1.6'; - my $result = $self->{snmp}->get_table(oid => $oid_tempertureSensorEntry); - return if (scalar(keys %$result) <= 0); - - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /^$oid_tempertureSensorValue\.(\d+).(\d+)$/); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_tempertureSensorEntry}})) { + next if ($oid !~ /^$mapping->{tempertureSensorStatus}->{oid}\.(.*)$/); my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_tempertureSensorEntry}, instance => $instance); next if ($self->check_exclude(section => 'temperature', instance => $instance)); - my $temperature_name = $result->{$oid_tempertureSensorName . '.' . $instance}; - my $temperature_state = $result->{$oid_tempertureSensorStatus . '.' . $instance}; $self->{components}->{temperature}->{total}++; $self->{output}->output_add(long_msg => sprintf("Temperature '%s' sensor out of range status is '%s'", - $temperature_name, $map_states_temperature{$temperature_state})); - my $exit = $self->get_severity(section => 'temperature', value => $map_states_temperature{$temperature_state}); + $result->{tempertureSensorName}, $result->{tempertureSensorStatus})); + my $exit = $self->get_severity(section => 'temperature', value => $result->{tempertureSensorStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Temperature '%s' sensor out of range status is '%s'", $temperature_name, $map_states_temperature{$temperature_state})); + short_msg => sprintf("Temperature '%s' sensor out of range status is '%s'", $result->{tempertureSensorName}, $result->{tempertureSensorStatus})); } - $self->{output}->perfdata_add(label => $temperature_name , unit => 'C', - value => sprintf("%.2f", $result->{$oid_tempertureSensorValue . '.' . $instance})); + $self->{output}->perfdata_add(label => $result->{tempertureSensorName} , unit => 'C', + value => sprintf("%.2f", $result->{tempertureSensorValue})); } } diff --git a/centreon-plugins/network/checkpoint/mode/components/voltage.pm b/centreon-plugins/network/checkpoint/mode/components/voltage.pm index 0b72c8a03..6fa3bb188 100644 --- a/centreon-plugins/network/checkpoint/mode/components/voltage.pm +++ b/centreon-plugins/network/checkpoint/mode/components/voltage.pm @@ -44,39 +44,43 @@ my %map_states_voltage = ( 2 => 'reading error', ); +my $mapping = { + voltageSensorName => { oid => '.1.3.6.1.4.1.2620.1.6.7.8.3.1.2' }, + voltageSensorValue => { oid => '.1.3.6.1.4.1.2620.1.6.7.8.3.1.3' }, + voltageSensorStatus => { oid => '.1.3.6.1.4.1.2620.1.6.7.8.3.1.6', map => \%map_states_voltage }, +}; +my $oid_voltageSensorEntry = '.1.3.6.1.4.1.2620.1.6.7.8.3.1'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_voltageSensorEntry, start => $mapping->{voltageSensorName}->{oid}, end => $mapping->{voltageSensorStatus}->{oid} }; +} + sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking voltages"); $self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0}; return if ($self->check_exclude(section => 'voltage')); - - my $oid_voltageSensorEntry = '.1.3.6.1.4.1.2620.1.6.7.8.3.1'; - my $oid_voltageSensorStatus = '.1.3.6.1.4.1.2620.1.6.7.8.3.1.6'; - my $oid_voltageSensorValue = '.1.3.6.1.4.1.2620.1.6.7.8.3.1.3'; - my $oid_voltageSensorName = '.1.3.6.1.4.1.2620.1.6.7.8.3.1.2'; - - my $result = $self->{snmp}->get_table(oid => $oid_voltageSensorEntry); - return if (scalar(keys %$result) <= 0); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /^$oid_voltageSensorStatus\.(\d+).(\d+)$/); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_voltageSensorEntry}})) { + next if ($oid !~ /^$mapping->{voltageSensorStatus}->{oid}\.(.*)$/); my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_voltageSensorEntry}, instance => $instance); next if ($self->check_exclude(section => 'voltage', instance => $instance)); - my $voltage_name = $result->{$oid_voltageSensorName . '.' . $instance}; - my $voltage_state = $result->{$oid_voltageSensorStatus . '.' . $instance}; $self->{components}->{voltage}->{total}++; $self->{output}->output_add(long_msg => sprintf("Voltage '%s' sensor out of range status is '%s'", - $voltage_name, $map_states_voltage{$voltage_state})); - my $exit = $self->get_severity(section => 'voltage', value => $map_states_voltage{$voltage_state}); + $result->{voltageSensorName}, $result->{voltageSensorStatus})); + my $exit = $self->get_severity(section => 'voltage', value => $result->{voltageSensorStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Voltage '%s' sensor out of range status is '%s'", $voltage_name, $map_states_voltage{$voltage_state})); + short_msg => sprintf("Voltage '%s' sensor out of range status is '%s'", $result->{voltageSensorName}, $result->{voltageSensorStatus})); } - $self->{output}->perfdata_add(label => $voltage_name , unit => 'V', - value => sprintf("%d", $result->{$oid_voltageSensorValue . '.' . $instance})); + $self->{output}->perfdata_add(label => $result->{voltageSensorName} , unit => 'V', + value => sprintf("%d", $result->{voltageSensorValue})); } } diff --git a/centreon-plugins/network/checkpoint/mode/hardware.pm b/centreon-plugins/network/checkpoint/mode/hardware.pm index 960893074..cf237d023 100644 --- a/centreon-plugins/network/checkpoint/mode/hardware.pm +++ b/centreon-plugins/network/checkpoint/mode/hardware.pm @@ -40,11 +40,6 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use network::checkpoint::mode::components::fan; -use network::checkpoint::mode::components::voltage; -use network::checkpoint::mode::components::temperature; -use network::checkpoint::mode::components::psu; - my $thresholds = { temperature => [ ['true', 'CRITICAL'], @@ -77,7 +72,7 @@ sub new { $options{options}->add_options(arguments => { "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => 'all' }, + "component:s" => { name => 'component', default => '.*' }, "no-component:s" => { name => 'no_component' }, "threshold-overload:s@" => { name => 'threshold_overload' }, }); @@ -114,34 +109,36 @@ sub check_options { } } -sub global { - my ($self, %options) = @_; - - network::checkpoint::mode::components::temperature::check($self); - network::checkpoint::mode::components::fan::check($self); - network::checkpoint::mode::components::voltage::check($self); - network::checkpoint::mode::components::psu::check($self); -} - sub run { my ($self, %options) = @_; # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; - if ($self->{option_results}->{component} eq 'all') { - $self->global(); - } elsif ($self->{option_results}->{component} eq 'fan') { - network::checkpoint::mode::components::fan::check($self); - } elsif ($self->{option_results}->{component} eq 'voltage') { - network::checkpoint::mode::components::voltage::check($self); - } elsif ($self->{option_results}->{component} eq 'temperature') { - network::checkpoint::mode::components::temperature::check($self); - } elsif ($self->{option_results}->{component} eq 'psu') { - network::checkpoint::mode::components::psu::check($self); - } else { + my $snmp_request = []; + my @components = ('voltage', 'fan', 'temperature', 'psu'); + foreach (@components) { + if (/$self->{option_results}->{component}/) { + my $mod_name = "network::checkpoint::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 = "network::checkpoint::mode::components::$_"; + my $func = $mod_name->can('check'); + $func->($self); + } + } my $total_components = 0; my $display_by_component = ''; @@ -220,7 +217,7 @@ Check hardware (fans, power supplies, temperatures, voltages). =item B<--component> -Which component to check (Default: 'all'). +Which component to check (Default: '.*'). Can be: 'psu', 'fan', 'temperature', 'voltage'. =item B<--exclude>