Refactor #5844
This commit is contained in:
parent
2d8a0bbc4a
commit
04d78a9a70
|
@ -33,7 +33,7 @@
|
|||
#
|
||||
####################################################################################
|
||||
|
||||
package storage::synology::mode::hardware;
|
||||
package storage::synology::mode::components;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
|
@ -45,6 +45,10 @@ my $oid_synoSystemsystemFanStatus = '.1.3.6.1.4.1.6574.1.4.1.0';
|
|||
my $oid_synoSystemcpuFanStatus = '.1.3.6.1.4.1.6574.1.4.2.0';
|
||||
my $oid_synoDisk = '.1.3.6.1.4.1.6574.2.1';
|
||||
my $oid_synoDiskdiskStatus = '.1.3.6.1.4.1.6574.2.1.1.5';
|
||||
my $oid_synoSystemsystemStatus = '.1.3.6.1.4.1.6574.1.1.0';
|
||||
my $oid_synoRaid = '.1.3.6.1.4.1.6574.3.1.1';
|
||||
my $oid_synoRaidraidName = '.1.3.6.1.4.1.6574.3.1.1.2';
|
||||
my $oid_synoRaidraidStatus = '.1.3.6.1.4.1.6574.3.1.1.3';
|
||||
|
||||
my $thresholds = {
|
||||
psu => [
|
||||
|
@ -62,6 +66,24 @@ my $thresholds = {
|
|||
['SystemPartitionFailed', 'CRITICAL'],
|
||||
['Crashed', 'CRITICAL'],
|
||||
],
|
||||
raid => [
|
||||
['Normal', 'OK'],
|
||||
['Repairing', 'OK'],
|
||||
['Migrating', 'OK'],
|
||||
['Expanding', 'OK'],
|
||||
['Deleting', 'OK'],
|
||||
['Creating', 'OK'],
|
||||
['RaidSyncing', 'OK'],
|
||||
['RaidParityChecking', 'OK'],
|
||||
['RaidAssembling', 'OK'],
|
||||
['Canceling', 'OK'],
|
||||
['Degrade', 'WARNING'],
|
||||
['Crashed', 'CRITICAL'],
|
||||
],
|
||||
system => [
|
||||
['Normal', 'OK'],
|
||||
['Failed', 'CRITICAL'],
|
||||
],
|
||||
};
|
||||
|
||||
my %map_states_fan = (
|
||||
|
@ -82,6 +104,26 @@ my %map_states_disk = (
|
|||
5 => 'Crashed',
|
||||
);
|
||||
|
||||
my %map_states_raid = (
|
||||
1 => 'Normal',
|
||||
2 => 'Repairing',
|
||||
3 => 'Migrating',
|
||||
4 => 'Expanding',
|
||||
5 => 'Deleting',
|
||||
6 => 'Creating',
|
||||
7 => 'RaidSyncing',
|
||||
8 => 'RaidParityChecking',
|
||||
9 => 'RaidAssembling',
|
||||
10 => 'Canceling',
|
||||
11 => 'Degrade',
|
||||
12 => 'Crashed',
|
||||
);
|
||||
|
||||
my %map_states_system = (
|
||||
1 => 'Normal',
|
||||
2 => 'Failed',
|
||||
);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
|
@ -136,14 +178,16 @@ sub run {
|
|||
$self->{snmp} = $options{snmp};
|
||||
|
||||
|
||||
$self->{results} = $self->{snmp}->get_leef(oids => [$oid_synoSystempowerStatus, $oid_synoSystemcpuFanStatus, $oid_synoSystemsystemFanStatus],
|
||||
nothing_quit => 1);
|
||||
$self->{results} = $self->{snmp}->get_leef(oids => [$oid_synoSystempowerStatus, $oid_synoSystemcpuFanStatus, $oid_synoSystemsystemFanStatus, $oid_synoSystemsystemStatus],
|
||||
nothing_quit => 1);
|
||||
|
||||
if ($self->{option_results}->{component} eq 'all') {
|
||||
$self->check_fan_cpu();
|
||||
$self->check_fan_psu();
|
||||
$self->check_psu();
|
||||
$self->check_disk();
|
||||
$self->check_system();
|
||||
$self->check_raid();
|
||||
} elsif ($self->{option_results}->{component} eq 'fan_cpu') {
|
||||
$self->check_fan_cpu();
|
||||
} elsif ($self->{option_results}->{component} eq 'fan_psu') {
|
||||
|
@ -152,6 +196,10 @@ sub run {
|
|||
$self->check_psu();
|
||||
} elsif ($self->{option_results}->{component} eq 'disk') {
|
||||
$self->check_disk();
|
||||
} elsif ($self->{option_results}->{component} eq 'system') {
|
||||
$self->check_status();
|
||||
} elsif ($self->{option_results}->{component} eq 'raid') {
|
||||
$self->check_raid();
|
||||
} else {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
|
@ -277,6 +325,24 @@ sub check_psu {
|
|||
}
|
||||
}
|
||||
|
||||
sub check_system {
|
||||
my ($self) = @_;
|
||||
|
||||
$self->{output}->output_add(long_msg => "Checking system status");
|
||||
$self->{components}->{system} = {name => 'system', total => 0, skip => 0};
|
||||
return if ($self->check_exclude(section => 'system'));
|
||||
$self->{components}->{system}->{total}++;
|
||||
|
||||
my $system_state = $self->{results}->{$oid_synoSystemsystemStatus};
|
||||
$self->{output}->output_add(long_msg => sprintf("System status is %s.",
|
||||
$map_states_system{$system_state}));
|
||||
my $exit = $self->get_severity(section => 'system', value => $map_states_system{$system_state});
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("System status is %s.", $map_states_system{$system_state}));
|
||||
}
|
||||
}
|
||||
|
||||
sub check_disk {
|
||||
my ($self) = @_;
|
||||
|
||||
|
@ -289,16 +355,16 @@ sub check_disk {
|
|||
|
||||
my $instance = 0;
|
||||
|
||||
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$results)) {
|
||||
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$results)) {
|
||||
next if ($key !~ /^$oid_synoDiskdiskStatus\.(\d+)/);
|
||||
my $index = $1;
|
||||
$instance = $1;
|
||||
my $disk_state = $results->{$oid_synoDiskdiskStatus . '.' . $index};
|
||||
$instance = $1;
|
||||
my $disk_state = $results->{$oid_synoDiskdiskStatus . '.' . $index};
|
||||
|
||||
next if ($self->check_exclude(section => 'disk', instance => $instance));
|
||||
|
||||
$self->{components}->{disk}->{total}++;
|
||||
|
||||
|
||||
$self->{output}->output_add(long_msg => sprintf("Disk '%s' state is %s.",
|
||||
$index, $map_states_disk{$disk_state}));
|
||||
my $exit = $self->get_severity(section => 'disk', value => $map_states_disk{$disk_state});
|
||||
|
@ -309,20 +375,53 @@ sub check_disk {
|
|||
}
|
||||
}
|
||||
|
||||
sub check_raid {
|
||||
my ($self) = @_;
|
||||
|
||||
$self->{output}->output_add(long_msg => "Checking raid");
|
||||
$self->{components}->{raid} = {name => 'raid', total => 0, skip => 0};
|
||||
return if ($self->check_exclude(section => 'raid'));
|
||||
|
||||
my $results = $self->{snmp}->get_table(oid => $oid_synoRaid, start => $oid_synoRaidraidName, end => $oid_synoRaidraidStatus, nothing_quit => 1);
|
||||
|
||||
my $instance = 0;
|
||||
|
||||
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$results)) {
|
||||
next if ($key !~ /^$oid_synoRaidraidName\.(.*)/);
|
||||
my $id = $1;
|
||||
$instance = $1;
|
||||
my $raid_name = $results->{$key};
|
||||
my $raid_state = $results->{$oid_synoRaidraidStatus . '.' . $id};
|
||||
|
||||
next if ($self->check_exclude(section => 'raid', instance => $instance));
|
||||
|
||||
$self->{components}->{raid}->{total}++;
|
||||
|
||||
$self->{output}->output_add(long_msg => sprintf("Raid '%s' state is %s.",
|
||||
$raid_name, $map_states_raid{$raid_state}));
|
||||
my $exit = $self->get_severity(section => 'raid', value => $map_states_raid{$raid_state});
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Raid '%s' state is %s.", $raid_name, $map_states_raid{$raid_state}));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check hardware (SYNOLOGY-SYSTEM-MIB) (Fans, Power Supplies, Disk status).
|
||||
Check hardware (SYNOLOGY-SYSTEM-MIB, SYNOLOGY-RAID-MIB) (Fans, Power Supplies, Disk status, Raid status, System status).
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--component>
|
||||
|
||||
Which component to check (Default: 'all').
|
||||
Can be: 'psu', 'fan_cpu', 'fan_psu', 'disk'.
|
||||
Can be: 'psu', 'fan_cpu', 'fan_psu', 'disk', 'raid', 'system'.
|
||||
|
||||
=item B<--exclude>
|
||||
|
|
@ -1,152 +0,0 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2014 MERETHIS
|
||||
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
|
||||
# GPL Licence 2.0.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation ; either version 2 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, see <http://www.gnu.org/licenses>.
|
||||
#
|
||||
# Linking this program statically or dynamically with other modules is making a
|
||||
# combined work based on this program. Thus, the terms and conditions of the GNU
|
||||
# General Public License cover the whole combination.
|
||||
#
|
||||
# As a special exception, the copyright holders of this program give MERETHIS
|
||||
# permission to link this program with independent modules to produce an executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable under terms of MERETHIS choice, provided that
|
||||
# MERETHIS also meet, for each linked independent module, the terms and conditions
|
||||
# of the license of that module. An independent module is a module which is not
|
||||
# derived from this program. If you modify this program, you may extend this
|
||||
# exception to your version of the program, but you are not obliged to do so. If you
|
||||
# do not wish to do so, delete this exception statement from your version.
|
||||
#
|
||||
# For more information : contact@centreon.com
|
||||
# Authors : Mathieu Cinquin <mcinquin@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package storage::synology::mode::raidstatus;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $thresholds = {
|
||||
raid => [
|
||||
['Normal', 'OK'],
|
||||
['Repairing', 'OK'],
|
||||
['Migrating', 'OK'],
|
||||
['Expanding', 'OK'],
|
||||
['Deleting', 'OK'],
|
||||
['Creating', 'OK'],
|
||||
['RaidSyncing', 'OK'],
|
||||
['RaidParityChecking', 'OK'],
|
||||
['RaidAssembling', 'OK'],
|
||||
['Canceling', 'OK'],
|
||||
['Degrade', 'WARNING'],
|
||||
['Crashed', 'CRITICAL'],
|
||||
],
|
||||
};
|
||||
|
||||
my %map_states_raid = (
|
||||
1 => 'Normal',
|
||||
2 => 'Repairing',
|
||||
3 => 'Migrating',
|
||||
4 => 'Expanding',
|
||||
5 => 'Deleting',
|
||||
6 => 'Creating',
|
||||
7 => 'RaidSyncing',
|
||||
8 => 'RaidParityChecking',
|
||||
9 => 'RaidAssembling',
|
||||
10 => 'Canceling',
|
||||
11 => 'Degrade',
|
||||
12 => 'Crashed',
|
||||
);
|
||||
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{snmp} = snmp object
|
||||
$self->{snmp} = $options{snmp};
|
||||
|
||||
my $oid_synoRaid = '.1.3.6.1.4.1.6574.3.1.1';
|
||||
my $oid_synoRaidraidName = '.1.3.6.1.4.1.6574.3.1.1.2';
|
||||
my $oid_synoRaidraidStatus = '.1.3.6.1.4.1.6574.3.1.1.3';
|
||||
|
||||
my $result = $self->{snmp}->get_table(oid => $oid_synoRaid, start => $oid_synoRaidraidName, end => $oid_synoRaidraidStatus, nothing_quit => 1);
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'All raid volumes are ok.');
|
||||
|
||||
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
|
||||
next if ($key !~ /^$oid_synoRaidraidName\.(.*)/);
|
||||
my $id = $1;
|
||||
my $raid_name = $result->{$key};
|
||||
my $raid_state = $result->{$oid_synoRaidraidStatus . '.' . $id};
|
||||
|
||||
my $exit = $self->get_severity(section => 'raid', value => $map_states_raid{$raid_state});
|
||||
|
||||
$self->{output}->output_add(long_msg => sprintf("RAID '%s' status is %s.", $raid_name, $map_states_raid{$raid_state}));
|
||||
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("RAID '%s' state is %s.", $raid_name, $map_states_raid{$raid_state}));
|
||||
}
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub get_severity {
|
||||
my ($self, %options) = @_;
|
||||
my $status = 'UNKNOWN'; # default
|
||||
|
||||
foreach (@{$thresholds->{$options{section}}}) {
|
||||
if ($options{value} =~ /$$_[0]/i) {
|
||||
$status = $$_[1];
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check RAID status (SYNOLOGY-RAID-MIB).
|
||||
|
||||
=over 8
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -1,118 +0,0 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2014 MERETHIS
|
||||
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
|
||||
# GPL Licence 2.0.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation ; either version 2 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, see <http://www.gnu.org/licenses>.
|
||||
#
|
||||
# Linking this program statically or dynamically with other modules is making a
|
||||
# combined work based on this program. Thus, the terms and conditions of the GNU
|
||||
# General Public License cover the whole combination.
|
||||
#
|
||||
# As a special exception, the copyright holders of this program give MERETHIS
|
||||
# permission to link this program with independent modules to produce an executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable under terms of MERETHIS choice, provided that
|
||||
# MERETHIS also meet, for each linked independent module, the terms and conditions
|
||||
# of the license of that module. An independent module is a module which is not
|
||||
# derived from this program. If you modify this program, you may extend this
|
||||
# exception to your version of the program, but you are not obliged to do so. If you
|
||||
# do not wish to do so, delete this exception statement from your version.
|
||||
#
|
||||
# For more information : contact@centreon.com
|
||||
# Authors : Mathieu Cinquin <mcinquin@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package storage::synology::mode::systemstatus;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $thresholds = {
|
||||
system => [
|
||||
['Normal', 'OK'],
|
||||
['Failed', 'CRITICAL'],
|
||||
],
|
||||
};
|
||||
|
||||
my %map_states_system = (
|
||||
1 => 'Normal',
|
||||
2 => 'Failed',
|
||||
);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{snmp} = snmp object
|
||||
$self->{snmp} = $options{snmp};
|
||||
|
||||
my $oid_synoSystemsystemStatus = '.1.3.6.1.4.1.6574.1.1.0';
|
||||
|
||||
my $result = $self->{snmp}->get_leef(oids => [$oid_synoSystemsystemStatus],
|
||||
nothing_quit => 1);
|
||||
my $system_state = $result->{$oid_synoSystemsystemStatus};
|
||||
|
||||
my $exit = $self->get_severity(section => 'system', value => $map_states_system{$system_state});
|
||||
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("System status is %s", $map_states_system{$system_state}));
|
||||
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub get_severity {
|
||||
my ($self, %options) = @_;
|
||||
my $status = 'UNKNOWN'; # default
|
||||
|
||||
foreach (@{$thresholds->{$options{section}}}) {
|
||||
if ($options{value} =~ /$$_[0]/i) {
|
||||
$status = $$_[1];
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check system status (SYNOLOGY-SYSTEM-MIB).
|
||||
|
||||
=over 8
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -47,10 +47,9 @@ sub new {
|
|||
|
||||
$self->{version} = '1.0';
|
||||
%{$self->{modes}} = (
|
||||
'hardware' => 'storage::synology::mode::hardware',
|
||||
'components' => 'storage::synology::mode::components',
|
||||
'temperature' => 'storage::synology::mode::temperature',
|
||||
'raidstatus' => 'storage::synology::mode::raidstatus',
|
||||
'systemstatus' => 'storage::synology::mode::systemstatus',
|
||||
'ups' => 'storage::synology::mode::ups',
|
||||
'traffic' => 'snmp_standard::mode::traffic',
|
||||
'cpu' => 'snmp_standard::mode::cpu',
|
||||
'memory' => 'snmp_standard::mode::memory',
|
||||
|
|
Loading…
Reference in New Issue