enhance and clean netgear ready nas plugin

This commit is contained in:
garnier-quentin 2019-01-09 17:24:58 +01:00
parent 50317c1c31
commit 053ebba292
6 changed files with 128 additions and 129 deletions

View File

@ -25,27 +25,26 @@ package storage::netgear::readynas::snmp::mode::components::disk;
use strict;
use warnings;
my ($mapping, $oid_diskTable);
my $mapping_v6 = {
diskState => { oid => '.1.3.6.1.4.1.4526.22.3.1.9' },
diskTemperature => { oid => '.1.3.6.1.4.1.4526.22.3.1.10' },
my $mapping = {
v6 => {
diskState => { oid => '.1.3.6.1.4.1.4526.22.3.1.9' },
diskTemperature => { oid => '.1.3.6.1.4.1.4526.22.3.1.10' },
},
v4 => {
diskState => { oid => '.1.3.6.1.4.1.4526.18.3.1.4' },
diskTemperature => { oid => '.1.3.6.1.4.1.4526.18.3.1.5' },
},
};
my $oid_diskTable_v6 = '.1.3.6.1.4.1.4526.22.3';
my $mapping_v4 = {
diskState => { oid => '.1.3.6.1.4.1.4526.18.3.1.4' },
diskTemperature => { oid => '.1.3.6.1.4.1.4526.18.3.1.5' },
my $oid_diskTable = {
v4 => '.1.3.6.1.4.1.4526.18.3',
v6 => '.1.3.6.1.4.1.4526.22.3',
};
my $oid_diskTable_v4 = '.1.3.6.1.4.1.4526.18.3';
sub load {
my ($self) = @_;
$mapping = $self->{mib_ver} == 4 ? $mapping_v4 : $mapping_v6;
$oid_diskTable = $self->{mib_ver} == 4 ? $oid_diskTable_v4 : $oid_diskTable_v6;
push @{$self->{request}}, { oid => $oid_diskTable };
push @{$self->{request}}, { oid => $oid_diskTable->{$self->{mib_ver}},
start => $mapping->{$self->{mib_ver}}->{diskState}, end => $mapping->{$self->{mib_ver}}->{diskTemperature} };
}
sub check {
@ -55,10 +54,10 @@ sub check {
$self->{components}->{disk} = {name => 'disk', total => 0, skip => 0};
return if ($self->check_filter(section => 'disk'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_diskTable}})) {
next if ($oid !~ /^$mapping->{diskState}->{oid}\.(\d+)/);
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $oid_diskTable->{$self->{mib_ver}} }})) {
next if ($oid !~ /^$mapping->{$self->{mib_ver}}->{diskState}->{oid}\.(\d+)/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_diskTable}, instance => $instance);
my $result = $self->{snmp}->map_instance(mapping => $mapping->{$self->{mib_ver}}, results => $self->{results}->{ $oid_diskTable->{$self->{mib_ver}} }, instance => $instance);
next if ($self->check_filter(section => 'disk', instance => $instance));
$self->{components}->{disk}->{total}++;

View File

@ -25,25 +25,70 @@ package storage::netgear::readynas::snmp::mode::components::fan;
use strict;
use warnings;
my ($mapping, $oid_fanTable);
my $mapping_v6 = {
fanStatus => { oid => '.1.3.6.1.4.1.4526.22.4.1.3' },
my $mapping = {
v6 => {
fanStatus => { oid => '.1.3.6.1.4.1.4526.22.4.1.3' },
},
v4 => {
fanRPM => { oid => '.1.3.6.1.4.1.4526.18.4.1.2' },
},
};
my $oid_fanTable_v6 = '.1.3.6.1.4.1.4526.22.4';
my $mapping_v4 = {
fanRPM => { oid => '.1.3.6.1.4.1.4526.18.4.1.2' },
};
my $oid_fanTable_v4 = '.1.3.6.1.4.1.4526.18.4';
sub load {
my ($self) = @_;
if ($self->{mib_ver} eq 'v4') {
push @{$self->{request}}, { oid => $mapping->{$self->{mib_ver}}->{fanRPM}->{oid} };
} else {
push @{$self->{request}}, { oid => $mapping->{$self->{mib_ver}}->{fanStatus}->{oid} };
}
}
sub check_v6 {
my ($self) = @_;
$mapping = $self->{mib_ver} == 4 ? $mapping_v4 : $mapping_v6;
$oid_fanTable = $self->{mib_ver} == 4 ? $oid_fanTable_v4 : $oid_fanTable_v6;
return if ($self->{mib_ver} ne 'v6');
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping->{$self->{mib_ver}}->{fanStatus}->{oid} }})) {
$oid =~ /^$mapping->{$self->{mib_ver}}->{fanStatus}->{oid}\.(\d+)/;
my $instance = $1;
my $status = $self->{results}->{ $mapping->{$self->{mib_ver}}->{fanStatus}->{oid} }->{$oid};
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));
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));
}
}
}
sub check_v4 {
my ($self) = @_;
push @{$self->{request}}, { oid => $oid_fanTable };
return if ($self->{mib_ver} ne 'v4');
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping->{$self->{mib_ver}}->{fanRPM}->{oid} }})) {
$oid =~ /^$mapping->{$self->{mib_ver}}->{fanRPM}->{oid}\.(\d+)/;
my $instance = $1;
my $fanrpm = $self->{results}->{ $mapping->{$self->{mib_ver}}->{fanRPM}->{oid} }->{$oid};
next if ($self->check_filter(section => 'fan', instance => $instance));
$self->{components}->{fan}->{total}++;
$self->{output}->output_add(long_msg => sprintf("fan '%s' rpm is %s.", $instance, $fanrpm));
my ($exit, $warn, $crit) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $fanrpm);
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("fan '%s' rpm is %s", $instance, $fanrpm));
}
$self->{output}->perfdata_add(label => "fan_" . $instance, unit => 'rpm',
value => $fanrpm,
warning => $warn,
critical => $crit);
}
}
sub check {
@ -53,45 +98,8 @@ sub check {
$self->{components}->{fan} = {name => 'fan', total => 0, skip => 0};
return if ($self->check_filter(section => 'fan'));
if ($self->{mib_ver} == 6) {
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_fanTable}})) {
next if ($oid !~ /^$mapping->{fanStatus}->{oid}\.(\d+)/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fanTable}, 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, $result->{fanStatus}));
my $exit = $self->get_severity(label => 'default', section => 'fan', value => $result->{fanStatus});
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->{fanStatus}));
}
}
return ;
}
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_fanTable}})) {
next if ($oid !~ /^$mapping->{fanRPM}->{oid}\.(\d+)/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fanTable}, instance => $instance);
next if ($self->check_filter(section => 'fan', instance => $instance));
$self->{components}->{fan}->{total}++;
$self->{output}->output_add(long_msg => sprintf("fan '%s' rpm is %s.", $instance, $result->{fanRPM}));
my ($exit, $warn, $crit) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{fanRPM});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("fan '%s' rpm is %s", $instance, $result->{fanRPM}));
}
$self->{output}->perfdata_add(label => "fan_" . $instance, unit => 'rpm',
value => $result->{fanRPM},
warning => $warn,
critical => $crit);
}
check_v6($self);
check_v4($self);
}
1;

View File

@ -25,25 +25,19 @@ package storage::netgear::readynas::snmp::mode::components::psu;
use strict;
use warnings;
my ($mapping, $oid_psuTable);
my $mapping_v6 = {
psuStatus => { oid => '.1.3.6.1.4.1.4526.22.8.1.3' },
my $mapping = {
v6 => {
psuStatus => { oid => '.1.3.6.1.4.1.4526.22.8.1.3' },
},
v4 => {
psuStatus => { oid => '.1.3.6.1.4.1.4526.18.8.1.3' },
},
};
my $oid_psuTable_v6 = '.1.3.6.1.4.1.4526.22.8';
my $mapping_v4 = {
psuStatus => { oid => '.1.3.6.1.4.1.4526.18.8.1.3' },
};
my $oid_psuTable_v4 = '.1.3.6.1.4.1.4526.18.8';
sub load {
my ($self) = @_;
$mapping = $self->{mib_ver} == 4 ? $mapping_v4 : $mapping_v6;
$oid_psuTable = $self->{mib_ver} == 4 ? $oid_psuTable_v4 : $oid_psuTable_v6;
push @{$self->{request}}, { oid => $oid_psuTable };
push @{$self->{request}}, { oid => $mapping->{$self->{mib_ver}}->{psuStatus}->{oid} };
}
sub check {
@ -53,20 +47,20 @@ sub check {
$self->{components}->{psu} = {name => 'psu', total => 0, skip => 0};
return if ($self->check_filter(section => 'psu'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_psuTable}})) {
next if ($oid !~ /^$mapping->{psuStatus}->{oid}\.(\d+)/);
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping->{$self->{mib_ver}}->{psuStatus}->{oid} }})) {
$oid =~ /^$mapping->{$self->{mib_ver}}->{psuStatus}->{oid}\.(\d+)/;
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_psuTable}, instance => $instance);
my $status = $self->{results}->{ $mapping->{$self->{mib_ver}}->{psuStatus}->{oid} }->{$oid};
next if ($self->check_filter(section => 'psu', instance => $instance));
$self->{components}->{psu}->{total}++;
$self->{output}->output_add(long_msg => sprintf("power supply '%s' status is %s.",
$instance, $result->{psuStatus}));
my $exit = $self->get_severity(section => 'psu', value => $result->{psuStatus});
$instance, $status));
my $exit = $self->get_severity(section => 'psu', value => $status);
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, $result->{psuStatus}));
short_msg => sprintf("Power Supply '%s' status is %s.", $instance, $status));
}
}
}

View File

@ -25,28 +25,27 @@ package storage::netgear::readynas::snmp::mode::components::temperature;
use strict;
use warnings;
my ($mapping, $oid_temperatureTable);
my $mapping_v6 = {
temperatureValue => { oid => '.1.3.6.1.4.1.4526.22.5.1.2' },
temperatureType => { oid => '.1.3.6.1.4.1.4526.22.5.1.3' },
temperatureMax => { oid => '.1.3.6.1.4.1.4526.22.5.1.5' },
my $mapping = {
v6 => {
temperatureValue => { oid => '.1.3.6.1.4.1.4526.22.5.1.2' },
temperatureType => { oid => '.1.3.6.1.4.1.4526.22.5.1.3' },
temperatureMax => { oid => '.1.3.6.1.4.1.4526.22.5.1.5' },
},
v4 => {
temperatureValue => { oid => '.1.3.6.1.4.1.4526.18.5.1.2' },
temperatureStatus => { oid => '.1.3.6.1.4.1.4526.18.5.1.3' },
},
};
my $oid_temperatureTable_v6 = '.1.3.6.1.4.1.4526.22.5';
my $mapping_v4 = {
temperatureValue => { oid => '.1.3.6.1.4.1.4526.18.5.1.2' },
temperatureStatus => { oid => '.1.3.6.1.4.1.4526.18.5.1.3' },
my $oid_temperatureTable = {
v4 => '.1.3.6.1.4.1.4526.18.5',
v6 => '.1.3.6.1.4.1.4526.22.5',
};
my $oid_temperatureTable_v4 = '.1.3.6.1.4.1.4526.18.5';
sub load {
my ($self) = @_;
$mapping = $self->{mib_ver} == 4 ? $mapping_v4 : $mapping_v6;
$oid_temperatureTable = $self->{mib_ver} == 4 ? $oid_temperatureTable_v4 : $oid_temperatureTable_v6;
push @{$self->{request}}, { oid => $oid_temperatureTable };
push @{$self->{request}}, { oid => $oid_temperatureTable->{$self->{mib_ver}},
start => $mapping->{$self->{mib_ver}}->{temperatureValue} };
}
sub check {
@ -56,10 +55,10 @@ sub check {
$self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 };
return if ($self->check_filter(section => 'temperature'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_temperatureTable}})) {
next if ($oid !~ /^$mapping->{temperatureValue}->{oid}\.(.*)$/);
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $oid_temperatureTable->{$self->{mib_ver}} }})) {
next if ($oid !~ /^$mapping->{$self->{mib_ver}}->{temperatureValue}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_temperatureTable}, instance => $instance);
my $result = $self->{snmp}->map_instance(mapping => $mapping->{$self->{mib_ver}}, results => $self->{results}->{ $oid_temperatureTable->{$self->{mib_ver}} }, instance => $instance);
$instance .= "_" . $result->{temperatureType} if (defined($result->{temperatureType}));
next if ($self->check_filter(section => 'temperature', instance => $instance));

View File

@ -25,27 +25,26 @@ package storage::netgear::readynas::snmp::mode::components::volume;
use strict;
use warnings;
my ($mapping, $oid_volumeTable);
my $mapping_v6 = {
volumeName => { oid => '.1.3.6.1.4.1.4526.22.7.1.2' },
volumeStatus => { oid => '.1.3.6.1.4.1.4526.22.7.1.4' },
my $mapping = {
v6 => {
volumeName => { oid => '.1.3.6.1.4.1.4526.22.7.1.2' },
volumeStatus => { oid => '.1.3.6.1.4.1.4526.22.7.1.4' },
},
v4 => {
volumeName => { oid => '.1.3.6.1.4.1.4526.18.7.1.2' },
volumeStatus => { oid => '.1.3.6.1.4.1.4526.18.7.1.4' },
},
};
my $oid_volumeTable_v6 = '.1.3.6.1.4.1.4526.22.7';
my $mapping_v4 = {
volumeName => { oid => '.1.3.6.1.4.1.4526.18.7.1.2' },
volumeStatus => { oid => '.1.3.6.1.4.1.4526.18.7.1.4' },
my $oid_volumeTable = {
v4 => '.1.3.6.1.4.1.4526.18.7',
v6 => '.1.3.6.1.4.1.4526.22.7',
};
my $oid_volumeTable_v4 = '.1.3.6.1.4.1.4526.18.7';
sub load {
my ($self) = @_;
$mapping = $self->{mib_ver} == 4 ? $mapping_v4 : $mapping_v6;
$oid_volumeTable = $self->{mib_ver} == 4 ? $oid_volumeTable_v4 : $oid_volumeTable_v6;
push @{$self->{request}}, { oid => $oid_volumeTable };
push @{$self->{request}}, { oid => $oid_volumeTable->{$self->{mib_ver}},
start => $mapping->{$self->{mib_ver}}->{volumeName}, end => $mapping->{$self->{mib_ver}}->{volumeStatus} };
}
sub check {
@ -55,10 +54,10 @@ sub check {
$self->{components}->{volume} = {name => 'volume', total => 0, skip => 0};
return if ($self->check_filter(section => 'volume'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_volumeTable}})) {
next if ($oid !~ /^$mapping->{volumeStatus}->{oid}\.(\d+)/);
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $oid_volumeTable->{$self->{mib_ver}} }})) {
next if ($oid !~ /^$mapping->{$self->{mib_ver}}->{volumeStatus}->{oid}\.(\d+)/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_volumeTable}, instance => $instance);
my $result = $self->{snmp}->map_instance(mapping => $mapping->{$self->{mib_ver}}, results => $self->{results}->{ $oid_volumeTable->{$self->{mib_ver}} }, instance => $instance);
next if ($self->check_filter(section => 'volume', instance => $instance));
$self->{components}->{volume}->{total}++;

View File

@ -78,7 +78,7 @@ sub init_mib_ver {
my $result = $options{snmp}->get_leef(oids => [$oid_MgrSoftwareVersion_v4, $oid_MgrSoftwareVersion_v6]);
$self->{mib_ver} = defined($result->{$oid_MgrSoftwareVersion_v4}) ? 4 : 6;
$self->{mib_ver} = defined($result->{$oid_MgrSoftwareVersion_v4}) ? 'v4' : 'v6';
}
sub snmp_execute {