enhance raisecom snmp plugin

This commit is contained in:
qgarnier 2017-08-10 16:37:23 +02:00
parent 4dabc5181b
commit 6202d2ee7e
7 changed files with 67 additions and 64 deletions

View File

@ -29,8 +29,8 @@ my %map_fan_state = (
); );
my $mapping = { my $mapping = {
raisecomFanSpeedValue => { oid => '.1.3.6.1.4.1.8886.1.1.5.2.2.1.2' }, 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 }, 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'; 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)); $instance, $result->{raisecomFanWorkState}, $instance));
my $exit = $self->get_severity(section => 'fan', value => $result->{raisecomFanWorkState}); my $exit = $self->get_severity(section => 'fan', value => $result->{raisecomFanWorkState});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit, $self->{output}->output_add(severity => $exit,
short_msg => sprintf("Fan '%s' status is '%s'", $instance, $result->{raisecomFanWorkState})); 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}); 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)) { if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit2, $self->{output}->output_add(severity => $exit2,
short_msg => sprintf("Fan speed '%s' is %s rpm", $instance, $result->{raisecomFanSpeedValue})); 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}, value => $result->{raisecomFanSpeedValue},
warning => $warn, warning => $warn,
critical => $crit, critical => $crit,
); min => 0);
}
} }
} }

View File

@ -24,9 +24,9 @@ use strict;
use warnings; use warnings;
my $mapping = { my $mapping = {
raisecomTemperatureValue => { oid => '.1.3.6.1.4.1.8886.1.1.4.2.1' }, 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' }, 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' }, 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'; 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}); my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{raisecomTemperatureValue});
if ($checked == 0) { if ($checked == 0) {
my $warn_th = ':' . $result->{raisecomTemperatureThresholdLow}; my $warn_th = $result->{raisecomTemperatureThresholdLow} . ':';
my $crit_th = ':' . $result->{raisecomTemperatureThresholdHigh}; my $crit_th = ':' . $result->{raisecomTemperatureThresholdHigh};
$self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th); $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th);
$self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th); $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th);

View File

@ -24,9 +24,9 @@ use strict;
use warnings; use warnings;
my $mapping = { my $mapping = {
raisecomVoltValue => { oid => '.1.3.6.1.4.1.8886.1.1.4.3.1.1.3' }, 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' }, 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' }, 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'; 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)); next if ($self->check_filter(section => 'voltage', instance => $instance));
$self->{components}->{voltage}->{total}++; $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 $instance, $result->{raisecomVoltValue}, $instance
)); ));
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, value => $result->{raisecomVoltValue}); my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, value => $result->{raisecomVoltValue});
if ($checked == 0) { if ($checked == 0) {
my $warn_th = ':' . $result->{raisecomVoltThresholdLow}; my $warn_th = $result->{raisecomVoltThresholdLow} . ':';
my $crit_th = ':' . $result->{raisecomVoltThresholdHigh}; my $crit_th = ':' . $result->{raisecomVoltThresholdHigh};
$self->{perfdata}->threshold_validate(label => 'warning-voltage-instance-' . $instance, value => $warn_th); $self->{perfdata}->threshold_validate(label => 'warning-voltage-instance-' . $instance, value => $warn_th);
$self->{perfdata}->threshold_validate(label => 'critical-voltage-instance-' . $instance, value => $crit_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)) { if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit, $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}, value => $result->{raisecomVoltValue},
warning => $warn, warning => $warn,
critical => $crit, critical => $crit,

View File

@ -31,49 +31,49 @@ sub set_counters {
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'cpu', type => 0, cb_prefix_output => 'prefix_cpu_output' } { name => 'cpu', type => 0, cb_prefix_output => 'prefix_cpu_output' }
]; ];
$self->{maps_counters}->{cpu} = [ $self->{maps_counters}->{cpu} = [
{ label => '1s', set => { { label => '1s', set => {
key_values => [ { name => 'raisecomCPUUtilization1sec' } ], key_values => [ { name => 'oneSec' } ],
output_template => '1 seconde : %.2f %%', output_template => '1 seconde : %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'cpu_1s', value => 'raisecomCPUUtilization1sec_absolute', template => '%.2f', { label => 'cpu_1s', value => 'oneSec_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' }, min => 0, max => 100, unit => '%' },
], ],
} }
}, },
{ label => '5s', set => { { label => '5s', set => {
key_values => [ { name => 'raisecomCPUUtilization5sec' } ], key_values => [ { name => 'fiveSec' } ],
output_template => '5 secondes : %.2f %%', output_template => '5 secondes : %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'cpu_5s', value => 'raisecomCPUUtilization5sec_absolute', template => '%.2f', { label => 'cpu_5s', value => 'fiveSec_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' }, min => 0, max => 100, unit => '%' },
], ],
} }
}, },
{ label => '1m', set => { { label => '1m', set => {
key_values => [ { name => 'raisecomCPUUtilization1min' } ], key_values => [ { name => 'oneMin' } ],
output_template => '1 minute : %.2f %%', output_template => '1 minute : %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'cpu_1m', value => 'raisecomCPUUtilization1min_absolute', template => '%.2f', { label => 'cpu_1m', value => 'oneMin_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' }, min => 0, max => 100, unit => '%' },
], ],
} }
}, },
{ label => '10m', set => { { label => '10m', set => {
key_values => [ { name => 'raisecomCPUUtilization10min' } ], key_values => [ { name => 'tenMin' } ],
output_template => '10 minutes : %.2f %%', output_template => '10 minutes : %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'cpu_10m', value => 'raisecomCPUUtilization10min_absolute', template => '%.2f', { label => 'cpu_10m', value => 'tenMin_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' }, min => 0, max => 100, unit => '%' },
], ],
} }
}, },
{ label => '2h', set => { { label => '2h', set => {
key_values => [ { name => 'raisecomCPUUtilization2h' } ], key_values => [ { name => 'twoHour' } ],
output_template => '2 hours : %.2f %%', output_template => '2 hours : %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'cpu_2h', value => 'raisecomCPUUtilization2h_absolute', template => '%.2f', { label => 'cpu_2h', value => 'twoHour_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' }, min => 0, max => 100, unit => '%' },
], ],
} }
@ -100,27 +100,28 @@ sub new {
return $self; 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 { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
# RAISECOM-SYSTEM-MIB $self->{cpu} = {};
my $oid_raisecomCPUUtilization1sec = '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1.3.1'; my $snmp_result = $options{snmp}->get_table(oid => $oid_raisecomCPUUtilizationEntry,
my $oid_raisecomCPUUtilization5sec = '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1.3.2'; nothing_quit => 1);
my $oid_raisecomCPUUtilization1min = '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1.3.3'; foreach my $oid (keys %{$snmp_result}) {
my $oid_raisecomCPUUtilization10min = '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1.3.4'; next if ($oid !~ /^$mapping->{raisecomCPUUtilization}->{oid}\.(.*)$/);
my $oid_raisecomCPUUtilization2h = '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1.3.5'; my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
my $results = $options{snmp}->get_leef(oids => [$oid_raisecomCPUUtilization1sec, $oid_raisecomCPUUtilization5sec,
$oid_raisecomCPUUtilization1min, , $oid_raisecomCPUUtilization10min, $self->{cpu}->{$result->{raisecomCPUUtilizationPeriod}} = $result->{raisecomCPUUtilization};
$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},
};
} }
1; 1;
@ -141,12 +142,12 @@ Example: --filter-counters='^(1s|1m)$'
=item B<--warning-*> =item B<--warning-*>
Threshold warning. Threshold warning.
Can be: '1s', '5s', '1m', '10m', '2h' Can be: '1s', '5s', '1m', '10m', '2h'.
=item B<--critical-*> =item B<--critical-*>
Threshold critical. Threshold critical.
Can be: '1s', '5s', '1m', '10m', '2h' Can be: '1s', '5s', '1m', '10m', '2h'.
=back =back

View File

@ -29,7 +29,7 @@ sub set_system {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(temperature|fan|voltage)$'; $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'; $self->{cb_hook2} = 'snmp_execute';
@ -70,18 +70,18 @@ __END__
=head1 MODE =head1 MODE
Check hardware (temperatures, fans, voltages). Check hardware.
=over 8 =over 8
=item B<--component> =item B<--component>
Which component to check (Default: '.*'). Which component to check (Default: '.*').
Can be: 'temperature'. Can be: 'temperature', 'fan', 'voltage'.
=item B<--filter> =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 Can also exclude specific instance: --filter=fan,1
=item B<--no-component> =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) Set to overload default threshold values (syntax: section,[instance,]status,regexp)
It used before default thresholds (order stays). It used before default thresholds (order stays).
Example: --threshold-overload='fan,CRITICAL,^(?!(good)$)' Example: --threshold-overload='fan,WARNING,twoHour'
=item B<--warning> =item B<--warning>

View File

@ -44,12 +44,12 @@ sub check_options {
$self->SUPER::init(%options); $self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { 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}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { 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}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
} }

View File

@ -31,12 +31,12 @@ sub new {
$self->{version} = '0.1'; $self->{version} = '0.1';
%{$self->{modes}} = ( %{$self->{modes}} = (
'cpu' => 'network::raisecom::snmp::mode::cpu', 'cpu' => 'network::raisecom::snmp::mode::cpu',
'memory' => 'network::raisecom::snmp::mode::memory', 'hardware' => 'network::raisecom::snmp::mode::hardware',
'interfaces' => 'snmp_standard::mode::interfaces', 'interfaces' => 'snmp_standard::mode::interfaces',
'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'hardware' => 'network::raisecom::snmp::mode::hardware', 'memory' => 'network::raisecom::snmp::mode::memory',
); );
return $self; return $self;
} }