diff --git a/network/radware/alteon/snmp/mode/cpu.pm b/network/radware/alteon/snmp/mode/cpu.pm index b5f75b0ea2..17952b1015 100644 --- a/network/radware/alteon/snmp/mode/cpu.pm +++ b/network/radware/alteon/snmp/mode/cpu.pm @@ -20,11 +20,55 @@ package network::radware::alteon::snmp::mode::cpu; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_cpu_output' } + ]; + + $self->{maps_counters}->{global} = [ + { label => '1s', set => { + key_values => [ { name => '1s' } ], + output_template => '%.2f%% (1sec)', + perfdatas => [ + { label => 'cpu_1s', value => '1s_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => '4s', set => { + key_values => [ { name => '4s' } ], + output_template => '%.2f%% (4sec)', + perfdatas => [ + { label => 'cpu_4s', value => '4s_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => '64s', set => { + key_values => [ { name => '64s' } ], + output_template => '%.2f%% (64sec)', + perfdatas => [ + { label => 'cpu_64s', value => '64s_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + ]; +} + +sub prefix_cpu_output { + my ($self, %options) = @_; + + return "MP CPU Usage: "; +} + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); @@ -33,90 +77,23 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "warning:s" => { name => 'warning', default => '' }, - "critical:s" => { name => 'critical', default => '' }, }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - ($self->{warn1s}, $self->{warn4s}, $self->{warn64s}) = split /,/, $self->{option_results}->{warning}; - ($self->{crit1s}, $self->{crit4s}, $self->{crit64s}) = split /,/, $self->{option_results}->{critical}; - - if (($self->{perfdata}->threshold_validate(label => 'warn1s', value => $self->{warn1s})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning (1sec) threshold '" . $self->{warn1s} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'warn4s', value => $self->{warn4s})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning (4sec) threshold '" . $self->{warn4s} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'warn64s', value => $self->{warn64s})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning (64sec) threshold '" . $self->{warn64s} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'crit1s', value => $self->{crit1s})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical (1sec) threshold '" . $self->{crit1s} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'crit4s', value => $self->{crit4s})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical (4sec) threshold '" . $self->{crit4s} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'crit64s', value => $self->{crit64s})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical (64sec) threshold '" . $self->{crit64s} . "'."); - $self->{output}->option_exit(); - } -} - -sub run { +sub manage_selection { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; my $oid_mpCpuStatsUtil1Second = '.1.3.6.1.4.1.1872.2.5.1.2.2.1.0'; my $oid_mpCpuStatsUtil4Seconds = '.1.3.6.1.4.1.1872.2.5.1.2.2.2.0'; my $oid_mpCpuStatsUtil64Seconds = '.1.3.6.1.4.1.1872.2.5.1.2.2.3.0'; - my $result = $self->{snmp}->get_leef(oids => [$oid_mpCpuStatsUtil1Second, $oid_mpCpuStatsUtil4Seconds, - $oid_mpCpuStatsUtil64Seconds], nothing_quit => 1); - - my $cpu1sec = $result->{$oid_mpCpuStatsUtil1Second}; - my $cpu4sec = $result->{$oid_mpCpuStatsUtil4Seconds}; - my $cpu64sec = $result->{$oid_mpCpuStatsUtil64Seconds}; - - my $exit1 = $self->{perfdata}->threshold_check(value => $cpu1sec, - threshold => [ { label => 'crit1s', 'exit_litteral' => 'critical' }, { label => 'warn1s', exit_litteral => 'warning' } ]); - my $exit2 = $self->{perfdata}->threshold_check(value => $cpu4sec, - threshold => [ { label => 'crit4s', 'exit_litteral' => 'critical' }, { label => 'warn4s', exit_litteral => 'warning' } ]); - my $exit3 = $self->{perfdata}->threshold_check(value => $cpu64sec, - threshold => [ { label => 'crit64s', 'exit_litteral' => 'critical' }, { label => 'warn64s', exit_litteral => 'warning' } ]); - my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]); - - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("MP CPU Usage: %.2f%% (1sec), %.2f%% (4sec), %.2f%% (64sec)", - $cpu1sec, $cpu4sec, $cpu64sec)); - - $self->{output}->perfdata_add(label => "cpu_1s", unit => '%', - value => $cpu1sec, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1s'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1s'), - min => 0, max => 100); - $self->{output}->perfdata_add(label => "cpu_4s", unit => '%', - value => $cpu4sec, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn4s'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit4s'), - min => 0, max => 100); - $self->{output}->perfdata_add(label => "cpu_64s", unit => '%', - value => $cpu64sec, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn64s'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit64s'), - min => 0, max => 100); - - $self->{output}->display(); - $self->{output}->exit(); + my $snmp_result = $options{snmp}->get_leef(oids => [ + $oid_mpCpuStatsUtil1Second, $oid_mpCpuStatsUtil4Seconds, + $oid_mpCpuStatsUtil64Seconds], nothing_quit => 1); + + $self->{global} = { '1s' => $snmp_result->{$oid_mpCpuStatsUtil1Second}, '4s' => $snmp_result->{$oid_mpCpuStatsUtil4Seconds}, + '64s' => $snmp_result->{$oid_mpCpuStatsUtil64Seconds} }; } 1; @@ -129,13 +106,20 @@ Check MP cpu usage (ALTEON-CHEETAH-SWITCH-MIB). =over 8 -=item B<--warning> +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^(64s)$' + +=item B<--warning-*> -Threshold warning in percent (1s,4s,64s). +Threshold warning. +Can be: '1s', '4s', '64s'. -=item B<--critical> +=item B<--critical-*> -Threshold critical in percent (1s,4s,64s). +Threshold critical. +Can be: '1s', '4s', '64s'. =back diff --git a/network/radware/alteon/snmp/mode/hardware.pm b/network/radware/alteon/snmp/mode/hardware.pm index a445b3206a..dfa3bee60c 100644 --- a/network/radware/alteon/snmp/mode/hardware.pm +++ b/network/radware/alteon/snmp/mode/hardware.pm @@ -20,40 +20,45 @@ package network::radware::alteon::snmp::mode::hardware; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); -use strict; -use warnings; - -my %states_temp_cpu = ( - 1 => ['normal', 'OK'], - 2 => ['warning', 'WARNING'], - 3 => ['critical', 'CRITICAL'], -); -my %states_temp = ( - 1 => ['ok', 'OK'], - 2 => ['exceed', 'WARNING'], -); -my %states_psu = ( - 1 => ['single power supply ok', 'WARNING'], - 2 => ['first powerSupply failed', 'CRITICAL'], - 3 => ['second power supply failed', 'CRITICAL'], - 4 => ['double power supply ok', 'OK'], - 5 => ['unknown power supply failed', 'UNKNOWN'], -); -my %states_fan = ( - 1 => ['ok', 'OK'], - 2 => ['fail', 'CRITICAL'], -); -my $oid_hwTemperatureStatus = '.1.3.6.1.4.1.1872.2.5.1.3.1.3.0'; -my $oid_hwFanStatus = '.1.3.6.1.4.1.1872.2.5.1.3.1.4.0'; -my $oid_hwTemperatureThresholdStatusCPU1Get = '.1.3.6.1.4.1.1872.2.5.1.3.1.28.3.0'; -my $oid_hwTemperatureThresholdStatusCPU2Get = '.1.3.6.1.4.1.1872.2.5.1.3.1.28.4.0'; -my $oid_hwPowerSupplyStatus = '.1.3.6.1.4.1.1872.2.5.1.3.1.29.2.0'; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(cpu|temperature|psu|fan)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + cpu => [ + ['normal', 'OK'], + ['warning', 'WARNING'], + ['critical', 'CRITICAL'], + ], + psu => [ + ['singlePowerSupplyOk', 'OK'], + ['firstPowerSupplyFailed', 'CRITICAL'], + ['secondPowerSupplyFailed', 'CRITICAL'], + ['doublePowerSupplyOk', 'OK'], + ['unknownPowerSupplyFailed', 'UNKNOWN'], + ], + temperature => [ + ['ok', 'OK'], + ['exceed', 'WARNING'], + ], + fan => [ + ['ok', 'OK'], + ['fail', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'network::radware::alteon::snmp::mode::components'; + $self->{components_module} = ['cpu', 'temperature', 'psu', 'fan']; +} 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, no_load_components => 1); bless $self, $class; $self->{version} = '1.0'; @@ -64,116 +69,212 @@ sub new { return $self; } -sub check_options { +sub snmp_execute { my ($self, %options) = @_; - $self->SUPER::init(%options); + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_leef(oids => $self->{request}); } -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; +1; - $self->{components_fans} = 0; - $self->{components_psus} = 0; - $self->{components_temperatures} = 0; - - $self->{global_result} = $self->{snmp}->get_leef(oids => [$oid_hwTemperatureStatus, $oid_hwFanStatus, - $oid_hwTemperatureThresholdStatusCPU1Get, $oid_hwTemperatureThresholdStatusCPU2Get, - $oid_hwPowerSupplyStatus], - nothing_quit => 1); - - $self->check_fans(); - $self->check_psus(); - $self->check_temperatures(); +=head1 MODE + +Check hardware (ALTEON-CHEETAH-SWITCH-MIB). + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'cpu', 'temperature', 'psu', 'fan'. + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter=cpu,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,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='psu,OK,unknownPowerSupplyFailed' + +=back + +=cut + +package network::radware::alteon::snmp::mode::components::cpu; + +use strict; +use warnings; + +my %map_cpu_status = (1 => 'normal', 2 => 'warning', 3 => 'critical'); + +my $mapping_cpu = { + hwTemperatureThresholdStatusCPU1Get => { oid => '.1.3.6.1.4.1.1872.2.5.1.3.1.28.3', map => \%map_cpu_status }, + hwTemperatureThresholdStatusCPU2Get => { oid => '.1.3.6.1.4.1.1872.2.5.1.3.1.28.4', map => \%map_cpu_status }, +}; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, $mapping_cpu->{hwTemperatureThresholdStatusCPU1Get}->{oid} . '.0', $mapping_cpu->{hwTemperatureThresholdStatusCPU2Get}->{oid} . '.0'; +} + +sub check_cpu { + my ($self, %options) = @_; - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %d components [%d fans, %d power supplies, %d temperatures] are ok", - ($self->{components_fans} + $self->{components_psus} + $self->{components_temperatures}), - $self->{components_fans}, $self->{components_psus}, $self->{components_temperatures})); + return if (!defined($options{status})); + return if ($self->check_filter(section => 'cpu', instance => $options{instance})); - $self->{output}->display(); - $self->{output}->exit(); + $self->{components}->{cpu}->{total}++; + $self->{output}->output_add(long_msg => sprintf("cpu '%s' status is '%s' [instance = %s]", + $options{instance}, $options{status}, $options{instance})); + my $exit = $self->get_severity(section => 'cpu', value => $options{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Cpu '%s' status is '%s'", $options{instance}, $options{status})); + } +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking cpu"); + $self->{components}->{cpu} = {name => 'cpu', total => 0, skip => 0}; + return if ($self->check_filter(section => 'cpu')); + + my $result = $self->{snmp}->map_instance(mapping => $mapping_cpu, results => $self->{results}, instance => '0'); + + check_cpu($self, status => $result->{hwTemperatureThresholdStatusCPU1Get}, instance => 1); + check_cpu($self, status => $result->{hwTemperatureThresholdStatusCPU2Get}, instance => 2); +} + +1; + +package network::radware::alteon::snmp::mode::components::fan; + +use strict; +use warnings; + +my %map_fan_status = (1 => 'ok', 2 => 'fail'); + +my $mapping_fan = { + hwFanStatus => { oid => '.1.3.6.1.4.1.1872.2.5.1.3.1.4', map => \%map_fan_status }, +}; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, $mapping_fan->{hwFanStatus}->{oid} . '.0'; } -sub check_fans { +sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking fans"); - return if (!defined($self->{global_result}->{$oid_hwFanStatus})); - - $self->{components_fans}++; - my $fan_state = $self->{global_result}->{$oid_hwFanStatus}; - - $self->{output}->output_add(long_msg => sprintf("Fan status is %s.", ${$states_fan{$fan_state}}[0])); - if (${$states_fan{$fan_state}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$states_fan{$fan_state}}[1], - short_msg => sprintf("Fan status is %s.", ${$states_fan{$fan_state}}[0])); + $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; + return if ($self->check_filter(section => 'fan')); + + my $result = $self->{snmp}->map_instance(mapping => $mapping_fan, results => $self->{results}, instance => '0'); + + return if (!defined($result->{hwFanStatus})); + $self->{components}->{fan}->{total}++; + $self->{output}->output_add(long_msg => sprintf("fan status is '%s' [instance = %s]", + $result->{hwFanStatus}, '0')); + my $exit = $self->get_severity(section => 'fan', value => $result->{hwFanStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Fan status is '%s'", $result->{hwFanStatus})); } } -sub check_psus { +1; + +package network::radware::alteon::snmp::mode::components::temperature; + +use strict; +use warnings; + +my %map_temp_status = (1 => 'ok', 2 => 'exceed'); + +my $mapping_temp = { + hwTemperatureStatus => { oid => '.1.3.6.1.4.1.1872.2.5.1.3.1.3', map => \%map_temp_status }, +}; + +sub load { my ($self) = @_; - $self->{output}->output_add(long_msg => "Checking power supplies"); - return if (!defined($self->{global_result}->{$oid_hwPowerSupplyStatus})); - - $self->{components_psus}++; - my $psu_state = $self->{global_result}->{$oid_hwPowerSupplyStatus}; - - $self->{output}->output_add(long_msg => sprintf("Power supplies status is %s.", ${$states_psu{$psu_state}}[0])); - if (${$states_psu{$psu_state}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$states_psu{$psu_state}}[1], - short_msg => sprintf("Power supplies status is %s.", ${$states_psu{$psu_state}}[0])); - } + push @{$self->{request}}, $mapping_temp->{hwTemperatureStatus}->{oid} . '.0'; } -sub check_temperatures { +sub check { my ($self) = @_; - $self->{output}->output_add(long_msg => "Checking temperatures global"); - return if (!defined($self->{global_result}->{$oid_hwTemperatureStatus})); - - $self->{components_temperatures}++; - my $temp_state = $self->{global_result}->{$oid_hwTemperatureStatus}; - - $self->{output}->output_add(long_msg => sprintf("Global temperature sensor status is %s.", ${$states_temp{$temp_state}}[0])); - if (${$states_temp{$temp_state}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$states_temp{$temp_state}}[1], - short_msg => sprintf("Global temperature sensor status is %s.", ${$states_temp{$temp_state}}[0])); - } - - $self->{output}->output_add(long_msg => "Checking temperatures cpus"); - return if (!defined($self->{global_result}->{$oid_hwTemperatureThresholdStatusCPU1Get}) && - !defined($self->{global_result}->{$oid_hwTemperatureThresholdStatusCPU2Get})); - - $self->{components_temperatures} += 2; - my $temp_cpu1_state = $self->{global_result}->{$oid_hwTemperatureThresholdStatusCPU1Get}; - my $temp_cpu2_state = $self->{global_result}->{$oid_hwTemperatureThresholdStatusCPU2Get}; - - $self->{output}->output_add(long_msg => sprintf("Temperature cpu 1 status is %s.", ${$states_temp_cpu{$temp_cpu1_state}}[0])); - if (${$states_temp_cpu{$temp_cpu1_state}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$states_temp_cpu{$temp_cpu1_state}}[1], - short_msg => sprintf("Temperature cpu 1 status is %s.", ${$states_temp_cpu{$temp_cpu1_state}}[0])); - } - - $self->{output}->output_add(long_msg => sprintf("Temperature cpu 2 status is %s.", ${$states_temp_cpu{$temp_cpu2_state}}[0])); - if (${$states_temp_cpu{$temp_cpu2_state}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$states_temp_cpu{$temp_cpu2_state}}[1], - short_msg => sprintf("Temperature cpu 2 status is %s.", ${$states_temp_cpu{$temp_cpu2_state}}[0])); + $self->{output}->output_add(long_msg => "Checking temperature"); + $self->{components}->{temperature} = {name => 'temperature', total => 0, skip => 0}; + return if ($self->check_filter(section => 'temperature')); + + my $result = $self->{snmp}->map_instance(mapping => $mapping_temp, results => $self->{results}, instance => '0'); + + return if (!defined($result->{hwTemperatureStatus})); + $self->{components}->{temperature}->{total}++; + $self->{output}->output_add(long_msg => sprintf("temperature status is '%s' [instance = %s]", + $result->{hwTemperatureStatus}, '0')); + my $exit = $self->get_severity(section => 'temperature', value => $result->{hwTemperatureStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature status is '%s'", $result->{hwTemperatureStatus})); } } 1; -__END__ +package network::radware::alteon::snmp::mode::components::psu; -=head1 MODE +use strict; +use warnings; -Check Hardware (ALTEON-CHEETAH-SWITCH-MIB) (Fans, Power Supplies, Temperatures). +my %map_psu_status = (1 => 'singlePowerSupplyOk', + 2 => 'firstPowerSupplyFailed', 3 => 'secondPowerSupplyFailed', 4 => 'doublePowerSupplyOk', + 5 => 'unknownPowerSupplyFailed' +); -=over 8 +my $mapping_psu = { + hwPowerSupplyStatus => { oid => '.1.3.6.1.4.1.1872.2.5.1.3.1.29.2', map => \%map_psu_status }, +}; -=back +sub load { + my ($self) = @_; -=cut + push @{$self->{request}}, $mapping_psu->{hwPowerSupplyStatus}->{oid} . '.0'; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking psus"); + $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; + return if ($self->check_filter(section => 'psu')); + + my $result = $self->{snmp}->map_instance(mapping => $mapping_psu, results => $self->{results}, instance => '0'); + + return if (!defined($result->{hwPowerSupplyStatus})); + $self->{components}->{psu}->{total}++; + $self->{output}->output_add(long_msg => sprintf("power supply status is '%s' [instance = %s]", + $result->{hwPowerSupplyStatus}, '0')); + my $exit = $self->get_severity(section => 'psu', value => $result->{hwPowerSupplyStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power supply status is '%s'", $result->{hwPowerSupplyStatus})); + } +} + +1; \ No newline at end of file