remove useless code

This commit is contained in:
garnier-quentin 2020-07-08 11:20:57 +02:00
parent 9c4654fbdb
commit a426bccbf0
10 changed files with 121 additions and 79 deletions

View File

@ -23,23 +23,22 @@ package storage::synology::snmp::mode::components::disk;
use strict; use strict;
use warnings; use warnings;
my %map_disk_status = ( my $map_disk_status = {
1 => 'Normal', 1 => 'Normal',
2 => 'Initialized', 2 => 'Initialized',
3 => 'NotInitialized', 3 => 'NotInitialized',
4 => 'SystemPartitionFailed', 4 => 'SystemPartitionFailed',
5 => 'Crashed', 5 => 'Crashed'
); };
my $mapping = { my $mapping = {
synoDiskdiskStatus => { oid => '.1.3.6.1.4.1.6574.2.1.1.5', map => \%map_disk_status }, synoDiskdiskStatus => { oid => '.1.3.6.1.4.1.6574.2.1.1.5', map => $map_disk_status }
}; };
my $oid_synoDisk = '.1.3.6.1.4.1.6574.2.1';
sub load { sub load {
my ($self) = @_; my ($self) = @_;
push @{$self->{request}}, { oid => $oid_synoDisk }; push @{$self->{request}}, { oid => $mapping->{synoDiskdiskStatus}->{oid} };
} }
sub check { sub check {
@ -49,20 +48,26 @@ sub check {
$self->{components}->{disk} = {name => 'disk', total => 0, skip => 0}; $self->{components}->{disk} = {name => 'disk', total => 0, skip => 0};
return if ($self->check_filter(section => 'disk')); return if ($self->check_filter(section => 'disk'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_synoDisk}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping->{synoDiskdiskStatus}->{oid} }})) {
next if ($oid !~ /^$mapping->{synoDiskdiskStatus}->{oid}\.(\d+)/); next if ($oid !~ /^$mapping->{synoDiskdiskStatus}->{oid}\.(\d+)/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_synoDisk}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $mapping->{synoDiskdiskStatus}->{oid} }, instance => $instance);
next if ($self->check_filter(section => 'disk', instance => $instance)); next if ($self->check_filter(section => 'disk', instance => $instance));
$self->{components}->{disk}->{total}++; $self->{components}->{disk}->{total}++;
$self->{output}->output_add(long_msg => sprintf("disk '%s' status is %s.", $self->{output}->output_add(
$instance, $result->{synoDiskdiskStatus})); long_msg => sprintf(
"disk '%s' status is %s.",
$instance, $result->{synoDiskdiskStatus}
)
);
my $exit = $self->get_severity(section => 'disk', value => $result->{synoDiskdiskStatus}); my $exit = $self->get_severity(section => 'disk', value => $result->{synoDiskdiskStatus});
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(
short_msg => sprintf("Disk '%s' status is %s", $instance, $result->{synoDiskdiskStatus})); severity => $exit,
short_msg => sprintf("Disk '%s' status is %s", $instance, $result->{synoDiskdiskStatus})
);
} }
} }
} }

View File

@ -23,18 +23,20 @@ package storage::synology::snmp::mode::components::fan;
use strict; use strict;
use warnings; use warnings;
my %map_status = (1 => 'Normal', 2 => 'Failed'); my $map_status = { 1 => 'Normal', 2 => 'Failed' };
my $mapping = { my $mapping = {
synoSystemsystemFanStatus => { oid => '.1.3.6.1.4.1.6574.1.4.1', map => \%map_status }, synoSystemsystemFanStatus => { oid => '.1.3.6.1.4.1.6574.1.4.1', map => $map_status },
synoSystemcpuFanStatus => { oid => '.1.3.6.1.4.1.6574.1.4.2', map => \%map_status }, synoSystemcpuFanStatus => { oid => '.1.3.6.1.4.1.6574.1.4.2', map => map_status }
}; };
my $oid_fan = '.1.3.6.1.4.1.6574.1.4'; my $oid_fan = '.1.3.6.1.4.1.6574.1.4';
sub load { sub load {
my ($self) = @_; my ($self) = @_;
push @{$self->{request}}, { oid => $oid_fan }; push @{$self->{request}}, {
oid => $oid_fan
};
} }
sub check { sub check {
@ -48,23 +50,35 @@ sub check {
if (!$self->check_filter(section => 'fan', instance => 'cpu')) { if (!$self->check_filter(section => 'fan', instance => 'cpu')) {
$self->{components}->{fan}->{total}++; $self->{components}->{fan}->{total}++;
$self->{output}->output_add(long_msg => sprintf("cpu fan state is %s.", $self->{output}->output_add(
$result->{synoSystemcpuFanStatus})); long_msg => sprintf(
"cpu fan state is %s.",
$result->{synoSystemcpuFanStatus}
)
);
my $exit = $self->get_severity(label => 'default', section => 'fan', instance => 'cpu', value => $result->{synoSystemcpuFanStatus}); my $exit = $self->get_severity(label => 'default', section => 'fan', instance => 'cpu', value => $result->{synoSystemcpuFanStatus});
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(
short_msg => sprintf("CPU fan status is %s", $result->{synoSystemcpuFanStatus})); severity => $exit,
short_msg => sprintf("CPU fan status is %s", $result->{synoSystemcpuFanStatus})
);
} }
} }
if (!$self->check_filter(section => 'fan', instance => 'system')) { if (!$self->check_filter(section => 'fan', instance => 'system')) {
$self->{components}->{fan}->{total}++; $self->{components}->{fan}->{total}++;
$self->{output}->output_add(long_msg => sprintf("system fan state is %s.", $self->{output}->output_add(
$result->{synoSystemsystemFanStatus})); long_msg => sprintf(
"system fan state is %s.",
$result->{synoSystemsystemFanStatus}
)
);
my $exit = $self->get_severity(label => 'default', section => 'fan', instance => 'system', value => $result->{synoSystemsystemFanStatus}); my $exit = $self->get_severity(label => 'default', section => 'fan', instance => 'system', value => $result->{synoSystemsystemFanStatus});
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(
short_msg => sprintf("System fan status is %s", $result->{synoSystemsystemFanStatus})); severity => $exit,
short_msg => sprintf("System fan status is %s", $result->{synoSystemsystemFanStatus})
);
} }
} }
} }

View File

@ -23,10 +23,10 @@ package storage::synology::snmp::mode::components::psu;
use strict; use strict;
use warnings; use warnings;
my %map_status = (1 => 'Normal', 2 => 'Failed'); my $map_status = { 1 => 'Normal', 2 => 'Failed' };
my $mapping = { my $mapping = {
synoSystempowerStatus => { oid => '.1.3.6.1.4.1.6574.1.3', map => \%map_status }, synoSystempowerStatus => { oid => '.1.3.6.1.4.1.6574.1.3', map => $map_status }
}; };
sub load { sub load {
@ -44,12 +44,18 @@ sub check {
$self->{components}->{psu}->{total}++; $self->{components}->{psu}->{total}++;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{synoSystempowerStatus}->{oid}}, instance => '0'); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{synoSystempowerStatus}->{oid}}, instance => '0');
$self->{output}->output_add(long_msg => sprintf("power supply status is %s.", $self->{output}->output_add(
$result->{synoSystempowerStatus})); long_msg => sprintf(
"power supply status is %s.",
$result->{synoSystempowerStatus}
)
);
my $exit = $self->get_severity(label => 'default', section => 'psu', value => $result->{synoSystempowerStatus}); my $exit = $self->get_severity(label => 'default', section => 'psu', value => $result->{synoSystempowerStatus});
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(
short_msg => sprintf("Power Supply status is %s.", $result->{synoSystempowerStatus})); severity => $exit,
short_msg => sprintf("Power Supply status is %s.", $result->{synoSystempowerStatus})
);
} }
} }

View File

@ -23,7 +23,7 @@ package storage::synology::snmp::mode::components::raid;
use strict; use strict;
use warnings; use warnings;
my %map_raid_status = ( my $map_raid_status = {
1 => 'Normal', 1 => 'Normal',
2 => 'Repairing', 2 => 'Repairing',
3 => 'Migrating', 3 => 'Migrating',
@ -44,19 +44,23 @@ my %map_raid_status = (
18 => 'RaidExpandingUnfinishedSHR', 18 => 'RaidExpandingUnfinishedSHR',
19 => 'RaidConvertSHRToPool', 19 => 'RaidConvertSHRToPool',
20 => 'RaidMigrateSHR1ToSHR2', 20 => 'RaidMigrateSHR1ToSHR2',
21 => 'RaidUnknownStatus', 21 => 'RaidUnknownStatus'
); };
my $mapping = { my $mapping = {
synoRaidraidName => { oid => '.1.3.6.1.4.1.6574.3.1.1.2' }, synoRaidraidName => { oid => '.1.3.6.1.4.1.6574.3.1.1.2' },
synoRaidraidStatus => { oid => '.1.3.6.1.4.1.6574.3.1.1.3', map => \%map_raid_status }, synoRaidraidStatus => { oid => '.1.3.6.1.4.1.6574.3.1.1.3', map => $map_raid_status }
}; };
my $oid_synoRaid = '.1.3.6.1.4.1.6574.3.1.1'; my $oid_synoRaid = '.1.3.6.1.4.1.6574.3.1.1';
sub load { sub load {
my ($self) = @_; my ($self) = @_;
push @{$self->{request}}, { oid => $oid_synoRaid }; push @{$self->{request}}, {
oid => $oid_synoRaid,
start => $mapping->{synoRaidraidName}->{oid},
end => $mapping->{synoRaidraidStatus}->{oid}
};
} }
sub check { sub check {
@ -74,13 +78,22 @@ sub check {
next if ($self->check_filter(section => 'raid', instance => $instance)); next if ($self->check_filter(section => 'raid', instance => $instance));
$self->{components}->{raid}->{total}++; $self->{components}->{raid}->{total}++;
$self->{output}->output_add(long_msg => sprintf("raid '%s' status is %s [instance: %s]", $self->{output}->output_add(
$result->{synoRaidraidName}, $result->{synoRaidraidStatus}, $instance)); long_msg => sprintf(
"raid '%s' status is %s [instance: %s]",
$result->{synoRaidraidName}, $result->{synoRaidraidStatus}, $instance
)
);
my $exit = $self->get_severity(section => 'raid', value => $result->{synoRaidraidStatus}); my $exit = $self->get_severity(section => 'raid', value => $result->{synoRaidraidStatus});
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(
short_msg => sprintf("Raid '%s' status is %s", severity => $exit,
$result->{synoRaidraidName}, $result->{synoRaidraidStatus})); short_msg => sprintf(
"Raid '%s' status is %s",
$result->{synoRaidraidName}, $result->{synoRaidraidStatus}
)
);
} }
} }
} }

View File

@ -23,10 +23,10 @@ package storage::synology::snmp::mode::components::system;
use strict; use strict;
use warnings; use warnings;
my %map_status = (1 => 'Normal', 2 => 'Failed'); my $map_status = { 1 => 'Normal', 2 => 'Failed' };
my $mapping = { my $mapping = {
synoSystemsystemStatus => { oid => '.1.3.6.1.4.1.6574.1.1', map => \%map_status }, synoSystemsystemStatus => { oid => '.1.3.6.1.4.1.6574.1.1', map => $map_status }
}; };
sub load { sub load {
@ -44,12 +44,18 @@ sub check {
$self->{components}->{system}->{total}++; $self->{components}->{system}->{total}++;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{synoSystemsystemStatus}->{oid}}, instance => '0'); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{synoSystemsystemStatus}->{oid}}, instance => '0');
$self->{output}->output_add(long_msg => sprintf("system partition status is %s.", $self->{output}->output_add(
$result->{synoSystemsystemStatus})); long_msg => sprintf(
"system partition status is %s.",
$result->{synoSystemsystemStatus}
)
);
my $exit = $self->get_severity(label => 'default', section => 'system', value => $result->{synoSystemsystemStatus}); my $exit = $self->get_severity(label => 'default', section => 'system', value => $result->{synoSystemsystemStatus});
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(
short_msg => sprintf("System status is %s.", $result->{synoSystemsystemStatus})); severity => $exit,
short_msg => sprintf("System status is %s.", $result->{synoSystemsystemStatus})
);
} }
} }

View File

@ -61,7 +61,7 @@ sub set_counters {
key_values => [ { name => 'heartbeat_latency' } ], key_values => [ { name => 'heartbeat_latency' } ],
output_template => 'heartbeat latency: %s us', output_template => 'heartbeat latency: %s us',
perfdatas => [ perfdatas => [
{ value => 'heartbeat_latency', template => '%s', min => 0, unit => 'us' } { template => '%s', min => 0, unit => 'us' }
] ]
} }
} }

View File

@ -28,7 +28,7 @@ use warnings;
sub set_system { sub set_system {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(fan|psu|disk|system|raid)$'; $self->{regexp_threshold_overload_check_section_option} = '^(?:fan|psu|disk|system|raid)$';
$self->{cb_hook2} = 'snmp_execute'; $self->{cb_hook2} = 'snmp_execute';
@ -36,14 +36,14 @@ sub set_system {
# system, fan, psu # system, fan, psu
default => [ default => [
['Normal', 'OK'], ['Normal', 'OK'],
['Failed', 'CRITICAL'], ['Failed', 'CRITICAL']
], ],
disk => [ disk => [
['Normal', 'OK'], ['Normal', 'OK'],
['Initialized', 'OK'], ['Initialized', 'OK'],
['NotInitialized', 'OK'], ['NotInitialized', 'OK'],
['SystemPartitionFailed', 'CRITICAL'], ['SystemPartitionFailed', 'CRITICAL'],
['Crashed', 'CRITICAL'], ['Crashed', 'CRITICAL']
], ],
raid => [ raid => [
['Normal', 'OK'], ['Normal', 'OK'],
@ -66,8 +66,8 @@ sub set_system {
['RaidExpandingUnfinishedSHR', 'OK'], ['RaidExpandingUnfinishedSHR', 'OK'],
['RaidConvertSHRToPool', 'OK'], ['RaidConvertSHRToPool', 'OK'],
['RaidMigrateSHR1ToSHR2', 'OK'], ['RaidMigrateSHR1ToSHR2', 'OK'],
['RaidUnknownStatus', 'UNKNOWN'], ['RaidUnknownStatus', 'UNKNOWN']
], ]
}; };
$self->{components_path} = 'storage::synology::snmp::mode::components'; $self->{components_path} = 'storage::synology::snmp::mode::components';
@ -86,9 +86,7 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => { });
{
});
return $self; return $self;
} }

View File

@ -29,7 +29,7 @@ sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 0 }, { name => 'global', type => 0 }
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
@ -37,10 +37,10 @@ sub set_counters {
key_values => [ { name => 'temperature' } ], key_values => [ { name => 'temperature' } ],
output_template => 'system temperature: %s C', output_template => 'system temperature: %s C',
perfdatas => [ perfdatas => [
{ value => 'temperature', template => '%s', unit => 'C' }, { template => '%s', unit => 'C' }
], ]
}
} }
},
]; ];
} }
@ -66,7 +66,7 @@ sub manage_selection {
); );
$self->{global} = { $self->{global} = {
temperature => $snmp_result->{$oid_synoSystemtemperature}, temperature => $snmp_result->{$oid_synoSystemtemperature}
}; };
} }

View File

@ -29,7 +29,7 @@ sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }, { name => 'global', type => 0, skipped_code => { -10 => 1 } }
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
@ -37,26 +37,26 @@ sub set_counters {
key_values => [ { name => 'ups_load' } ], key_values => [ { name => 'ups_load' } ],
output_template => 'ups load: %s%%', output_template => 'ups load: %s%%',
perfdatas => [ perfdatas => [
{ value => 'ups_load', template => '%s', min => 0, max => 100, unit => '%' }, { template => '%s', min => 0, max => 100, unit => '%' }
], ]
} }
}, },
{ label => 'charge-remaining', nlabel => 'battery.charge.remaining.percent', set => { { label => 'charge-remaining', nlabel => 'battery.charge.remaining.percent', set => {
key_values => [ { name => 'charge_remain' } ], key_values => [ { name => 'charge_remain' } ],
output_template => 'battery charge remaining: %s%%', output_template => 'battery charge remaining: %s%%',
perfdatas => [ perfdatas => [
{ value => 'charge_remain', template => '%s', min => 0, max => 100, unit => '%' }, { template => '%s', min => 0, max => 100, unit => '%' }
], ]
} }
}, },
{ label => 'lifetime-remaining', nlabel => 'battery.lifetime.remaining.seconds', set => { { label => 'lifetime-remaining', nlabel => 'battery.lifetime.remaining.seconds', set => {
key_values => [ { name => 'lifetime_remain' } ], key_values => [ { name => 'lifetime_remain' } ],
output_template => 'battery estimated lifetime: %s seconds', output_template => 'battery estimated lifetime: %s seconds',
perfdatas => [ perfdatas => [
{ value => 'lifetime_remain', template => '%s', min => 0, unit => 's' }, { template => '%s', min => 0, unit => 's' }
], ]
}
} }
},
]; ];
} }

View File

@ -30,7 +30,7 @@ sub new {
bless $self, $class; bless $self, $class;
$self->{version} = '1.1'; $self->{version} = '1.1';
%{$self->{modes}} = ( $self->{modes} = {
'components' => 'storage::synology::snmp::mode::hardware', 'components' => 'storage::synology::snmp::mode::hardware',
'cpu' => 'snmp_standard::mode::cpu', 'cpu' => 'snmp_standard::mode::cpu',
'ha' => 'storage::synology::snmp::mode::ha', 'ha' => 'storage::synology::snmp::mode::ha',
@ -42,8 +42,8 @@ sub new {
'temperature' => 'storage::synology::snmp::mode::temperature', 'temperature' => 'storage::synology::snmp::mode::temperature',
'time' => 'snmp_standard::mode::ntp', 'time' => 'snmp_standard::mode::ntp',
'ups' => 'storage::synology::snmp::mode::ups', 'ups' => 'storage::synology::snmp::mode::ups',
'uptime' => 'snmp_standard::mode::uptime', 'uptime' => 'snmp_standard::mode::uptime'
); };
return $self; return $self;
} }