From 6202d2ee7e1107c8b7acff85c76db8ff9d39456f Mon Sep 17 00:00:00 2001 From: qgarnier Date: Thu, 10 Aug 2017 16:37:23 +0200 Subject: [PATCH] enhance raisecom snmp plugin --- network/raisecom/snmp/mode/components/fan.pm | 16 ++--- .../snmp/mode/components/temperature.pm | 8 +-- .../raisecom/snmp/mode/components/voltage.pm | 14 ++--- network/raisecom/snmp/mode/cpu.pm | 63 ++++++++++--------- network/raisecom/snmp/mode/hardware.pm | 10 +-- network/raisecom/snmp/mode/memory.pm | 8 +-- network/raisecom/snmp/plugin.pm | 12 ++-- 7 files changed, 67 insertions(+), 64 deletions(-) diff --git a/network/raisecom/snmp/mode/components/fan.pm b/network/raisecom/snmp/mode/components/fan.pm index f00eebb57..f75b3ca9b 100644 --- a/network/raisecom/snmp/mode/components/fan.pm +++ b/network/raisecom/snmp/mode/components/fan.pm @@ -29,8 +29,8 @@ my %map_fan_state = ( ); my $mapping = { - raisecomFanSpeedValue => { oid => '.1.3.6.1.4.1.8886.1.1.5.2.2.1.2' }, - raisecomFanWorkState => { oid => '.1.3.6.1.4.1.8886.1.1.5.2.2.1.3', map => \%map_fan_state }, + raisecomFanSpeedValue => { oid => '.1.3.6.1.4.1.8886.1.1.5.2.2.1.2' }, + raisecomFanWorkState => { oid => '.1.3.6.1.4.1.8886.1.1.5.2.2.1.3', map => \%map_fan_state }, }; my $oid_raisecomFanMonitorStateEntry = '.1.3.6.1.4.1.8886.1.1.5.2.2.1'; @@ -59,19 +59,21 @@ sub check { $instance, $result->{raisecomFanWorkState}, $instance)); my $exit = $self->get_severity(section => 'fan', value => $result->{raisecomFanWorkState}); 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, $result->{raisecomFanWorkState})); + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Fan '%s' status is '%s'", $instance, $result->{raisecomFanWorkState})); } + my ($exit2, $warn, $crit) = $self->get_severity_numeric(section => 'fan.speed', instance => $instance, value => $result->{raisecomFanSpeedValue}); if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit2, short_msg => sprintf("Fan speed '%s' is %s rpm", $instance, $result->{raisecomFanSpeedValue})); - $self->{output}->perfdata_add(label => 'fan_speed_' . $instance, unit => 'rpm', + } + + $self->{output}->perfdata_add(label => 'fan_' . $instance, unit => 'rpm', value => $result->{raisecomFanSpeedValue}, warning => $warn, critical => $crit, - ); - } + min => 0); } } diff --git a/network/raisecom/snmp/mode/components/temperature.pm b/network/raisecom/snmp/mode/components/temperature.pm index 7d84746f6..03b5844a3 100644 --- a/network/raisecom/snmp/mode/components/temperature.pm +++ b/network/raisecom/snmp/mode/components/temperature.pm @@ -24,9 +24,9 @@ use strict; use warnings; my $mapping = { - raisecomTemperatureValue => { oid => '.1.3.6.1.4.1.8886.1.1.4.2.1' }, - raisecomTemperatureThresholdLow => { oid => '.1.3.6.1.4.1.8886.1.1.4.2.5' }, - raisecomTemperatureThresholdHigh => { oid => '.1.3.6.1.4.1.8886.1.1.4.2.6' }, + raisecomTemperatureValue => { oid => '.1.3.6.1.4.1.8886.1.1.4.2.1' }, + raisecomTemperatureThresholdLow => { oid => '.1.3.6.1.4.1.8886.1.1.4.2.5' }, + raisecomTemperatureThresholdHigh => { oid => '.1.3.6.1.4.1.8886.1.1.4.2.6' }, }; my $oid_raisecomTemperatureEntry = '.1.3.6.1.4.1.8886.1.1.4.2'; @@ -57,7 +57,7 @@ sub check { my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{raisecomTemperatureValue}); if ($checked == 0) { - my $warn_th = ':' . $result->{raisecomTemperatureThresholdLow}; + my $warn_th = $result->{raisecomTemperatureThresholdLow} . ':'; my $crit_th = ':' . $result->{raisecomTemperatureThresholdHigh}; $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th); $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th); diff --git a/network/raisecom/snmp/mode/components/voltage.pm b/network/raisecom/snmp/mode/components/voltage.pm index 83f50d25a..af685576c 100644 --- a/network/raisecom/snmp/mode/components/voltage.pm +++ b/network/raisecom/snmp/mode/components/voltage.pm @@ -24,9 +24,9 @@ use strict; use warnings; my $mapping = { - raisecomVoltValue => { oid => '.1.3.6.1.4.1.8886.1.1.4.3.1.1.3' }, - raisecomVoltThresholdLow => { oid => '.1.3.6.1.4.1.8886.1.1.4.3.1.1.7' }, - raisecomVoltThresholdHigh => { oid => '.1.3.6.1.4.1.8886.1.1.4.3.1.1.8' }, + raisecomVoltValue => { oid => '.1.3.6.1.4.1.8886.1.1.4.3.1.1.3' }, + raisecomVoltThresholdLow => { oid => '.1.3.6.1.4.1.8886.1.1.4.3.1.1.7' }, + raisecomVoltThresholdHigh => { oid => '.1.3.6.1.4.1.8886.1.1.4.3.1.1.8' }, }; my $oid_raisecomVoltEntry = '.1.3.6.1.4.1.8886.1.1.4.3.1.1'; @@ -51,13 +51,13 @@ sub check { next if ($self->check_filter(section => 'voltage', instance => $instance)); $self->{components}->{voltage}->{total}++; - $self->{output}->output_add(long_msg => sprintf("voltage '%s' is %.2f V [instance: %s].", + $self->{output}->output_add(long_msg => sprintf("voltage '%s' is %.2f mV [instance: %s].", $instance, $result->{raisecomVoltValue}, $instance )); my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, value => $result->{raisecomVoltValue}); if ($checked == 0) { - my $warn_th = ':' . $result->{raisecomVoltThresholdLow}; + my $warn_th = $result->{raisecomVoltThresholdLow} . ':'; my $crit_th = ':' . $result->{raisecomVoltThresholdHigh}; $self->{perfdata}->threshold_validate(label => 'warning-voltage-instance-' . $instance, value => $warn_th); $self->{perfdata}->threshold_validate(label => 'critical-voltage-instance-' . $instance, value => $crit_th); @@ -70,9 +70,9 @@ sub check { if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Voltage '%s' is %.2f V", $instance, $result->{raisecomVoltValue})); + short_msg => sprintf("Voltage '%s' is %.2f mV", $instance, $result->{raisecomVoltValue})); } - $self->{output}->perfdata_add(label => 'volt_' . $instance, unit => 'V', + $self->{output}->perfdata_add(label => 'volt_' . $instance, unit => 'mV', value => $result->{raisecomVoltValue}, warning => $warn, critical => $crit, diff --git a/network/raisecom/snmp/mode/cpu.pm b/network/raisecom/snmp/mode/cpu.pm index a8cbb1e8c..b267f7bcf 100644 --- a/network/raisecom/snmp/mode/cpu.pm +++ b/network/raisecom/snmp/mode/cpu.pm @@ -31,49 +31,49 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'cpu', type => 0, cb_prefix_output => 'prefix_cpu_output' } ]; - + $self->{maps_counters}->{cpu} = [ { label => '1s', set => { - key_values => [ { name => 'raisecomCPUUtilization1sec' } ], + key_values => [ { name => 'oneSec' } ], output_template => '1 seconde : %.2f %%', perfdatas => [ - { label => 'cpu_1s', value => 'raisecomCPUUtilization1sec_absolute', template => '%.2f', + { label => 'cpu_1s', value => 'oneSec_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, ], } }, { label => '5s', set => { - key_values => [ { name => 'raisecomCPUUtilization5sec' } ], + key_values => [ { name => 'fiveSec' } ], output_template => '5 secondes : %.2f %%', perfdatas => [ - { label => 'cpu_5s', value => 'raisecomCPUUtilization5sec_absolute', template => '%.2f', + { label => 'cpu_5s', value => 'fiveSec_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, ], } }, { label => '1m', set => { - key_values => [ { name => 'raisecomCPUUtilization1min' } ], + key_values => [ { name => 'oneMin' } ], output_template => '1 minute : %.2f %%', perfdatas => [ - { label => 'cpu_1m', value => 'raisecomCPUUtilization1min_absolute', template => '%.2f', + { label => 'cpu_1m', value => 'oneMin_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, ], } }, { label => '10m', set => { - key_values => [ { name => 'raisecomCPUUtilization10min' } ], + key_values => [ { name => 'tenMin' } ], output_template => '10 minutes : %.2f %%', perfdatas => [ - { label => 'cpu_10m', value => 'raisecomCPUUtilization10min_absolute', template => '%.2f', + { label => 'cpu_10m', value => 'tenMin_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, ], } }, { label => '2h', set => { - key_values => [ { name => 'raisecomCPUUtilization2h' } ], + key_values => [ { name => 'twoHour' } ], output_template => '2 hours : %.2f %%', perfdatas => [ - { label => 'cpu_2h', value => 'raisecomCPUUtilization2h_absolute', template => '%.2f', + { label => 'cpu_2h', value => 'twoHour_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, ], } @@ -100,27 +100,28 @@ sub new { return $self; } +my %mapping_period = (1 => 'oneSec', 2 => 'fiveSec', 3 => 'oneMin', 4 => 'tenMin', 5 => 'twoHour'); + +my $mapping = { + raisecomCPUUtilizationPeriod => { oid => '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1.2', map => \%mapping_period }, + raisecomCPUUtilization => { oid => '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1.3' }, +}; + +my $oid_raisecomCPUUtilizationEntry = '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1'; + sub manage_selection { my ($self, %options) = @_; - # RAISECOM-SYSTEM-MIB - my $oid_raisecomCPUUtilization1sec = '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1.3.1'; - my $oid_raisecomCPUUtilization5sec = '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1.3.2'; - my $oid_raisecomCPUUtilization1min = '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1.3.3'; - my $oid_raisecomCPUUtilization10min = '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1.3.4'; - my $oid_raisecomCPUUtilization2h = '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1.3.5'; - - my $results = $options{snmp}->get_leef(oids => [$oid_raisecomCPUUtilization1sec, $oid_raisecomCPUUtilization5sec, - $oid_raisecomCPUUtilization1min, , $oid_raisecomCPUUtilization10min, - $oid_raisecomCPUUtilization2h ], - nothing_quit => 1); - - $self->{cpu} = { raisecomCPUUtilization1sec => $results->{$oid_raisecomCPUUtilization1sec}, - raisecomCPUUtilization5sec => $results->{$oid_raisecomCPUUtilization5sec}, - raisecomCPUUtilization1min => $results->{$oid_raisecomCPUUtilization1min}, - raisecomCPUUtilization10min => $results->{$oid_raisecomCPUUtilization10min}, - raisecomCPUUtilization2h => $results->{$oid_raisecomCPUUtilization2h}, - }; + $self->{cpu} = {}; + my $snmp_result = $options{snmp}->get_table(oid => $oid_raisecomCPUUtilizationEntry, + nothing_quit => 1); + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{raisecomCPUUtilization}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + $self->{cpu}->{$result->{raisecomCPUUtilizationPeriod}} = $result->{raisecomCPUUtilization}; + } } 1; @@ -141,12 +142,12 @@ Example: --filter-counters='^(1s|1m)$' =item B<--warning-*> Threshold warning. -Can be: '1s', '5s', '1m', '10m', '2h' +Can be: '1s', '5s', '1m', '10m', '2h'. =item B<--critical-*> Threshold critical. -Can be: '1s', '5s', '1m', '10m', '2h' +Can be: '1s', '5s', '1m', '10m', '2h'. =back diff --git a/network/raisecom/snmp/mode/hardware.pm b/network/raisecom/snmp/mode/hardware.pm index 3f82c2737..45be0e383 100644 --- a/network/raisecom/snmp/mode/hardware.pm +++ b/network/raisecom/snmp/mode/hardware.pm @@ -29,7 +29,7 @@ sub set_system { my ($self, %options) = @_; $self->{regexp_threshold_overload_check_section_option} = '^(temperature|fan|voltage)$'; - $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|fan|voltage)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|fan.speed|voltage)$'; $self->{cb_hook2} = 'snmp_execute'; @@ -70,18 +70,18 @@ __END__ =head1 MODE -Check hardware (temperatures, fans, voltages). +Check hardware. =over 8 =item B<--component> Which component to check (Default: '.*'). -Can be: 'temperature'. +Can be: 'temperature', 'fan', 'voltage'. =item B<--filter> -Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu) +Exclude some parts (comma seperated list) (Example: --filter=fan Can also exclude specific instance: --filter=fan,1 =item B<--no-component> @@ -93,7 +93,7 @@ If total (with skipped) is 0. (Default: 'critical' returns). Set to overload default threshold values (syntax: section,[instance,]status,regexp) It used before default thresholds (order stays). -Example: --threshold-overload='fan,CRITICAL,^(?!(good)$)' +Example: --threshold-overload='fan,WARNING,twoHour' =item B<--warning> diff --git a/network/raisecom/snmp/mode/memory.pm b/network/raisecom/snmp/mode/memory.pm index c54e462dd..58e1cfa2e 100644 --- a/network/raisecom/snmp/mode/memory.pm +++ b/network/raisecom/snmp/mode/memory.pm @@ -44,12 +44,12 @@ sub check_options { $self->SUPER::init(%options); if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); } } diff --git a/network/raisecom/snmp/plugin.pm b/network/raisecom/snmp/plugin.pm index 8294d0df6..bcfde70be 100644 --- a/network/raisecom/snmp/plugin.pm +++ b/network/raisecom/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cpu' => 'network::raisecom::snmp::mode::cpu', - 'memory' => 'network::raisecom::snmp::mode::memory', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'hardware' => 'network::raisecom::snmp::mode::hardware', - ); + 'cpu' => 'network::raisecom::snmp::mode::cpu', + 'hardware' => 'network::raisecom::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::raisecom::snmp::mode::memory', + ); return $self; }