This commit is contained in:
Quentin Garnier 2014-12-10 18:27:29 +01:00
parent f0607ebe09
commit 2338454c20
17 changed files with 924 additions and 57 deletions

View File

@ -42,6 +42,12 @@ use warnings;
my $oid_chassisSystemLedAlarm = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.7';
sub load {
my (%options) = @_;
push @{$options{request}}, { oid => $oid_chassisSystemLedAlarm };
}
sub check {
my ($self) = @_;

View File

@ -42,6 +42,12 @@ use warnings;
my $oid_arrayFanEntry_speed = '.1.3.6.1.4.1.35897.1.2.2.3.18.1.3';
sub load {
my (%options) = @_;
push @{$options{request}}, { oid => $oid_arrayFanEntry_speed };
}
sub check {
my ($self) = @_;

View File

@ -45,6 +45,12 @@ my $oid_wwn = '.1.3.6.1.4.1.35897.1.2.1.10.1.3';
my $oid_enable = '.1.3.6.1.4.1.35897.1.2.1.10.1.4';
my $oid_portState = '.1.3.6.1.4.1.35897.1.2.1.10.1.8';
sub load {
my (%options) = @_;
push @{$options{request}}, { oid => $oid_globalTargetFcEntry };
}
sub check {
my ($self) = @_;

View File

@ -45,6 +45,12 @@ my $oid_wwn = '.1.3.6.1.4.1.35897.1.2.1.6.1.2';
my $oid_enable = '.1.3.6.1.4.1.35897.1.2.1.6.1.3';
my $oid_portState = '.1.3.6.1.4.1.35897.1.2.1.6.1.7';
sub load {
my (%options) = @_;
push @{$options{request}}, { oid => $oid_localTargetFcEntry };
}
sub check {
my ($self) = @_;

View File

@ -43,6 +43,13 @@ use warnings;
my $oid_chassisSystemPowerPSUA = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.17';
my $oid_chassisSystemPowerPSUB = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.18';
sub load {
my (%options) = @_;
push @{$options{request}}, { oid => $oid_chassisSystemPowerPSUA };
push @{$options{request}}, { oid => $oid_chassisSystemPowerPSUB };
}
sub psu {
my ($self, %options) = @_;
my $oid = $options{oid};

View File

@ -44,6 +44,14 @@ my $oid_chassisSystemTempAmbient = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.21';
my $oid_chassisSystemTempController = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.21';
my $oid_arrayVimmEntry_temp = '.1.3.6.1.4.1.35897.1.2.2.3.16.1.12';
sub load {
my (%options) = @_;
push @{$options{request}}, { oid => $oid_arrayVimmEntry_temp };
push @{$options{request}}, { oid => $oid_chassisSystemTempAmbient };
push @{$options{request}}, { oid => $oid_chassisSystemTempController };
}
sub temperature {
my ($self, %options) = @_;
my $oid = $options{oid};

View File

@ -53,6 +53,13 @@ my %map_vimm_present = (
2 => 'absent',
);
sub load {
my (%options) = @_;
push @{$options{request}}, { oid => $oid_arrayVimmEntry_present };
push @{$options{request}}, { oid => $oid_arrayVimmEntry_failed };
}
sub check {
my ($self) = @_;

View File

@ -39,25 +39,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::common::violin::snmp::mode::components::ca;
use centreon::common::violin::snmp::mode::components::psu;
use centreon::common::violin::snmp::mode::components::fan;
use centreon::common::violin::snmp::mode::components::vimm;
use centreon::common::violin::snmp::mode::components::temperature;
use centreon::common::violin::snmp::mode::components::lfc;
use centreon::common::violin::snmp::mode::components::gfc;
my $oid_chassisSystemLedAlarm = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.7';
my $oid_chassisSystemPowerPSUA = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.17';
my $oid_chassisSystemPowerPSUB = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.18';
my $oid_chassisSystemTempAmbient = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.21';
my $oid_chassisSystemTempController = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.21';
my $oid_arrayFanEntry_speed = '.1.3.6.1.4.1.35897.1.2.2.3.18.1.3';
my $oid_arrayVimmEntry_present = '.1.3.6.1.4.1.35897.1.2.2.3.16.1.4';
my $oid_arrayVimmEntry_failed = '.1.3.6.1.4.1.35897.1.2.2.3.16.1.10';
my $oid_arrayVimmEntry_temp = '.1.3.6.1.4.1.35897.1.2.2.3.16.1.12';
my $oid_globalTargetFcEntry = '.1.3.6.1.4.1.35897.1.2.1.10.1';
my $oid_localTargetFcEntry = '.1.3.6.1.4.1.35897.1.2.1.6.1';
use centreon::plugins::misc;
my $thresholds = {
vimm => [
@ -111,7 +93,7 @@ sub new {
$options{options}->add_options(arguments =>
{
"exclude:s" => { name => 'exclude' },
"component:s" => { name => 'component', default => 'all' },
"component:s" => { name => 'component', default => '.*' },
"absent-problem:s" => { name => 'absent' },
"no-component:s" => { name => 'no_component' },
"threshold-overload:s@" => { name => 'threshold_overload' },
@ -178,46 +160,32 @@ sub run {
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => [
{ oid => $oid_arrayFanEntry_speed },
{ oid => $oid_arrayVimmEntry_present },
{ oid => $oid_arrayVimmEntry_failed },
{ oid => $oid_arrayVimmEntry_temp },
{ oid => $oid_globalTargetFcEntry },
{ oid => $oid_localTargetFcEntry },
{ oid => $oid_chassisSystemLedAlarm },
{ oid => $oid_chassisSystemPowerPSUA },
{ oid => $oid_chassisSystemPowerPSUB },
{ oid => $oid_chassisSystemTempAmbient },
{ oid => $oid_chassisSystemTempController },
]);
if ($self->{option_results}->{component} eq 'all') {
centreon::common::violin::snmp::mode::components::ca::check($self);
centreon::common::violin::snmp::mode::components::psu::check($self);
centreon::common::violin::snmp::mode::components::fan::check($self);
centreon::common::violin::snmp::mode::components::vimm::check($self);
centreon::common::violin::snmp::mode::components::temperature::check($self);
centreon::common::violin::snmp::mode::components::gfc::check($self);
centreon::common::violin::snmp::mode::components::lfc::check($self);
} elsif ($self->{option_results}->{component} eq 'fan') {
centreon::common::violin::snmp::mode::components::fan::check($self);
} elsif ($self->{option_results}->{component} eq 'psu') {
centreon::common::violin::snmp::mode::components::psu::check($self);
} elsif ($self->{option_results}->{component} eq 'vimm') {
centreon::common::violin::snmp::mode::components::vimm::check($self);
} elsif ($self->{option_results}->{component} eq 'temperature') {
centreon::common::violin::snmp::mode::components::psu::check($self);
} elsif ($self->{option_results}->{component} eq 'ca') {
centreon::common::violin::snmp::mode::components::ca::check($self);
} elsif ($self->{option_results}->{component} eq 'gfc') {
centreon::common::violin::snmp::mode::components::gfc::check($self);
} elsif ($self->{option_results}->{component} eq 'lfc') {
centreon::common::violin::snmp::mode::components::lfc::check($self);
} else {
my $snmp_request = [];
my @components = ('ca', 'psu', 'fan', 'vimm', 'temperature', 'gfc', 'lfc');
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "centreon::common::violin::snmp::mode::components::$_";
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name,
error_msg => "Cannot load module '$mod_name'.");
my $func = $mod_name->can('load');
$func->(request => $snmp_request);
}
}
if (scalar(@{$snmp_request}) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'.");
$self->{output}->option_exit();
}
$self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request);
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "centreon::common::violin::snmp::mode::components::$_";
my $func = $mod_name->can('check');
$func->($self);
}
}
my $total_components = 0;
my $display_by_component = '';
my $display_by_component_append = '';
@ -350,7 +318,7 @@ Check components (Fans, Power Supplies, Temperatures, Chassis alarm, vimm, globa
=item B<--component>
Which component to check (Default: 'all').
Which component to check (Default: '.*').
Can be: 'psu', 'fan', 'ca', 'vimm', 'lfc', 'gfc', 'temperature'.
=item B<--exclude>

View File

@ -765,6 +765,31 @@ sub get_port {
return $self->{snmp_params}->{RemotePort};
}
sub map_instance {
my ($self, %options) = @_;
my $results = {};
foreach my $name (keys %{$options{mapping}}) {
my $entry = $options{mapping}->{$name}->{oid} . '.' . $options{instance};
if (defined($options{results}->{$entry})) {
$results->{$name} = $options{results}->{$entry};
} elsif (defined($options{results}->{$options{mapping}->{$name}->{oid}}->{$entry})) {
$results->{$name} = $options{results}->{$options{mapping}->{$name}->{oid}}->{$entry};
} elsif (defined($options{mapping}->{$name}->{location}) &&
defined($options{results}->{$options{mapping}->{$name}->{location}}->{$entry})) {
$results->{$name} = $options{results}->{$options{mapping}->{$name}->{location}}->{$entry};
} else {
$results->{$name} = defined($options{default}) ? $options{default} : undef;
}
if (defined($options{mapping}->{$name}->{map})) {
$results->{$name} = defined($options{mapping}->{$name}->{map}->{$results->{$name}}) ? $options{mapping}->{$name}->{map}->{$results->{$name}} : (defined($options{default}) ? $options{default} : 'unknown');
}
}
return $results;
}
sub oid_lex_sort {
my $self = shift;

View File

@ -0,0 +1,132 @@
################################################################################
# Copyright 2005-2013 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 : Quentin Garnier <qgarnier@merethis.com>
#
####################################################################################
package hardware::sensors::sensorip::snmp::mode::components::humidity;
use strict;
use warnings;
my %map_hum_status = (
1 => 'noStatus',
2 => 'normal',
3 => 'highWarning',
4 => 'highCritical',
5 => 'lowWarning',
6 => 'lowCritical',
7 => 'sensorError',
);
my %map_hum_online = (
1 => 'online',
2 => 'offline',
);
my $mapping = {
sensorProbeHumidityDescription => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.1' },
sensorProbeHumidityPercent => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.3' },
sensorProbeHumidityStatus => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.4', map => \%map_hum_status },
sensorProbeHumidityOnline => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.5', map => \%map_hum_online },
sensorProbeHumidityHighWarning => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.7' },
sensorProbeHumidityHighCritical => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.8' },
sensorProbeHumidityLowWarning => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.9' },
sensorProbeHumidityLowCritical => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.10' },
};
my $oid_sensorProbeHumidityEntry = '.1.3.6.1.4.1.3854.1.2.2.1.17.1';
sub load {
my (%options) = @_;
push @{$options{request}}, { oid => $oid_sensorProbeHumidityEntry, end => $mapping->{sensorProbeHumidityLowCritical}->{oid} };
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking humidity");
$self->{components}->{humidity} = {name => 'humidity', total => 0, skip => 0};
return if ($self->check_exclude(section => 'humidity'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sensorProbeHumidityEntry}})) {
next if ($oid !~ /^$mapping->{sensorProbeHumidityPercent}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sensorProbeHumidityEntry}, instance => $instance);
next if ($self->check_exclude(section => 'humidity', instance => $instance));
if ($result->{sensorProbeHumidityOnline} =~ /Offline/i) {
$self->absent_problem(section => 'humidity', instance => $instance);
next;
}
$self->{components}->{humidity}->{total}++;
if ($result->{sensorProbeHumidityStatus} =~ /sensorError/i) {
my $exit = $self->get_severity(section => 'humidity', value => $result->{sensorProbeHumidityStatus});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Humidity sensor '%s' status is '%s'", $result->{sensorProbeHumidityDescription}, $result->{sensorProbeTempStatus}));
next;
}
}
$self->{output}->output_add(long_msg => sprintf("Humidity sensor '%s' status is '%s' [instance = %s, value = %s %%]",
$result->{sensorProbeHumidityDescription}, $result->{sensorProbeHumidityStatus}, $instance, $result->{sensorProbeHumidityPercent}));
if (defined($result->{sensorProbeHumidityPercent}) && $result->{sensorProbeHumidityPercent} =~ /[0-9]/) {
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'humidity', instance => $instance, value => $result->{sensorProbeHumidityPercent});
if ($checked == 0) {
my $warn_th = $result->{sensorProbeHumidityLowWarning} . ':' . $result->{sensorProbeHumidityHighWarning};
my $crit_th = $result->{sensorProbeHumidityLowCritical} . ':' . $result->{sensorProbeHumidityHighCritical};
$self->{perfdata}->threshold_validate(label => 'warning-humidity-instance-' . $instance, value => $warn_th);
$self->{perfdata}->threshold_validate(label => 'critical-humidity-instance-' . $instance, value => $crit_th);
$exit = $self->{perfdata}->threshold_check(value => $result->{sensorProbeHumidityPercent}, threshold => [ { label => 'critical-humidity-instance-' . $instance, exit_litteral => 'critical' },
{ label => 'warning-humidity-instance-' . $instance, exit_litteral => 'warning' } ]);
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-humidity-instance-' . $instance);
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-humidity-instance-' . $instance)
}
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Humidity sensor '%s' is %s %%", $result->{sensorProbeHumidityDescription}, $result->{sensorProbeHumidityPercent}));
}
$self->{output}->perfdata_add(label => 'humdity_' . $instance, unit => '%',
value => $result->{sensorProbeHumidityPercent},
warning => $warn,
critical => $crit,
min => 0, max => 100
);
}
}
}
1;

View File

@ -0,0 +1,81 @@
################################################################################
# Copyright 2005-2013 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 : Quentin Garnier <qgarnier@merethis.com>
#
####################################################################################
package hardware::sensors::sensorip::snmp::mode::components::sp;
use strict;
use warnings;
my %map_sp_status = (
1 => 'noStatus',
2 => 'normal',
3 => 'warning',
4 => 'critical',
5 => 'sensorError',
);
my $oid_spStatus = '.1.3.6.1.4.1.3854.1.1.2';
sub load {
my (%options) = @_;
push @{$options{request}}, { oid => $oid_spStatus };
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking sp");
$self->{components}->{sp} = {name => 'sp', total => 0, skip => 0};
return if ($self->check_exclude(section => 'sp'));
my $instance = 0;
my $sp_status = defined($map_sp_status{$self->{results}->{$oid_spStatus}->{$oid_spStatus . '.' . $instance}}) ?
$map_sp_status{$self->{results}->{$oid_spStatus}->{$oid_spStatus . '.' . $instance}} : 'unknown';
return if ($self->check_exclude(section => 'sp', instance => $instance));
return if ($sp_status =~ /noStatus/i &&
$self->absent_problem(section => 'sp', instance => $instance));
$self->{components}->{sp}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Sensor probe '%s' status is '%s'",
$instance, $sp_status));
my $exit = $self->get_severity(section => 'sp', value => $sp_status);
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Sensor probe '%s' status is '%s'", $instance, $sp_status));
}
}
1;

View File

@ -0,0 +1,97 @@
################################################################################
# Copyright 2005-2013 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 : Quentin Garnier <qgarnier@merethis.com>
#
####################################################################################
package hardware::sensors::sensorip::snmp::mode::components::switch;
use strict;
use warnings;
my %map_sw_status = (
1 => 'noStatus',
2 => 'normal',
4 => 'highCritical',
6 => 'lowCritical',
7 => 'sensorError',
8 => 'relayOn',
9 => 'relayOff',
);
my %map_sw_online = (
1 => 'online',
2 => 'offline',
);
my $mapping = {
sensorProbeSwitchDescription => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.18.1.1' },
sensorProbeSwitchStatus => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.18.1.3', map => \%map_sw_status },
sensorProbeSwitchOnline => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.18.1.4', map => \%map_sw_online },
};
my $oid_sensorProbeSwitchEntry = '.1.3.6.1.4.1.3854.1.2.2.1.18.1';
sub load {
my (%options) = @_;
push @{$options{request}}, { oid => $oid_sensorProbeSwitchEntry, end => $mapping->{sensorProbeSwitchOnline}->{oid} };
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking switch");
$self->{components}->{switch} = {name => 'switch', total => 0, skip => 0};
return if ($self->check_exclude(section => 'switch'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sensorProbeSwitchEntry}})) {
next if ($oid !~ /^$mapping->{sensorProbeSwitchStatus}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sensorProbeSwitchEntry}, instance => $instance);
next if ($self->check_exclude(section => 'switch', instance => $instance));
if ($result->{sensorProbeSwitchOnline} =~ /Offline/i) {
$self->absent_problem(section => 'switch', instance => $instance);
next;
}
$self->{components}->{switch}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Switch sensor '%s' status is '%s' [instance : %s]",
$result->{sensorProbeSwitchDescription}, $result->{sensorProbeSwitchStatus}, $instance));
my $exit = $self->get_severity(section => 'switch', value => $result->{sensorProbeSwitchStatus});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Switch sensor '%s' status is '%s'", $result->{sensorProbeSwitchDescription}, $result->{sensorProbeSwitchStatus}));
}
}
}
1;

View File

@ -0,0 +1,131 @@
################################################################################
# Copyright 2005-2013 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 : Quentin Garnier <qgarnier@merethis.com>
#
####################################################################################
package hardware::sensors::sensorip::snmp::mode::components::temperature;
use strict;
use warnings;
my %map_temp_status = (
1 => 'noStatus',
2 => 'normal',
3 => 'highWarning',
4 => 'highCritical',
5 => 'lowWarning',
6 => 'lowCritical',
7 => 'sensorError',
);
my %map_temp_online = (
1 => 'online',
2 => 'offline',
);
my $mapping = {
sensorProbeTempDescription => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.1' },
sensorProbeTempDegree => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.3' },
sensorProbeTempStatus => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.4', map => \%map_temp_status },
sensorProbeTempOnline => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.5', map => \%map_temp_online },
sensorProbeTempHighWarning => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.7' },
sensorProbeTempHighCritical => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.8' },
sensorProbeTempLowWarning => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.9' },
sensorProbeTempLowCritical => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.10' },
};
my $oid_sensorProbeTempEntry = '.1.3.6.1.4.1.3854.1.2.2.1.16.1';
sub load {
my (%options) = @_;
push @{$options{request}}, { oid => $oid_sensorProbeTempEntry, end => $mapping->{sensorProbeTempLowCritical}->{oid} };
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking temperatures");
$self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
return if ($self->check_exclude(section => 'temperature'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sensorProbeTempEntry}})) {
next if ($oid !~ /^$mapping->{sensorProbeTempDegree}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sensorProbeTempEntry}, instance => $instance);
next if ($self->check_exclude(section => 'temperature', instance => $instance));
if ($result->{sensorProbeTempOnline} =~ /Offline/i) {
$self->absent_problem(section => 'temperature', instance => $instance);
next;
}
$self->{components}->{temperature}->{total}++;
if ($result->{sensorProbeTempStatus} =~ /sensorError/i) {
my $exit = $self->get_severity(section => 'temperature', value => $result->{sensorProbeTempStatus});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Temperature sensor '%s' status is '%s'", $result->{sensorProbeTempDescription}, $result->{sensorProbeTempStatus}));
next;
}
}
$self->{output}->output_add(long_msg => sprintf("Temperature sensor '%s' status is '%s' [instance = %s, value = %s]",
$result->{sensorProbeTempDescription}, $result->{sensorProbeTempStatus}, $instance, $result->{sensorProbeTempDegree}));
if (defined($result->{sensorProbeTempDegree}) && $result->{sensorProbeTempDegree} =~ /[0-9]/) {
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{sensorProbeTempDegree});
if ($checked == 0) {
my $warn_th = $result->{sensorProbeTempLowWarning} . ':' . $result->{sensorProbeTempHighWarning};
my $crit_th = $result->{sensorProbeTempLowCritical} . ':' . $result->{sensorProbeTempHighCritical};
$self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th);
$self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th);
$exit = $self->{perfdata}->threshold_check(value => $result->{sensorProbeTempDegree}, threshold => [ { label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' },
{ label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' } ]);
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance);
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance)
}
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Temperature sensor '%s' is %s degree centigrade", $result->{sensorProbeTempDescription}, $result->{sensorProbeTempDegree}));
}
$self->{output}->perfdata_add(label => 'temp_' . $instance, unit => 'C',
value => $result->{sensorProbeTempDegree},
warning => $warn,
critical => $crit,
);
}
}
}
1;

View File

@ -0,0 +1,319 @@
################################################################################
# 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 : Quentin Garnier <qgarnier@merethis.com>
#
####################################################################################
package hardware::sensors::sensorip::snmp::mode::sensors;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::misc;
my $thresholds = {
sp => [
['noStatus', 'UNKNOWN'],
['normal', 'OK'],
['warning', 'WARNING'],
['critical', 'CRITICAL'],
['sensorError', 'CRITICAL'],
],
switch => [
['noStatus', 'UNKNOWN'],
['normal', 'OK'],
['highCritical', 'CRITICAL'],
['lowCritical', 'CRITICAL'],
['sensorError', 'CRITICAL'],
['relayOn', 'OK'],
['relayOff', 'OK'],
],
};
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"exclude:s" => { name => 'exclude' },
"component:s" => { name => 'component', default => '.*' },
"absent-problem:s" => { name => 'absent' },
"no-component:s" => { name => 'no_component' },
"threshold-overload:s@" => { name => 'threshold_overload' },
"warning:s@" => { name => 'warning' },
"critical:s@" => { name => 'critical' },
});
$self->{components} = {};
$self->{no_components} = undef;
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (defined($self->{option_results}->{no_component})) {
if ($self->{option_results}->{no_component} ne '') {
$self->{no_components} = $self->{option_results}->{no_component};
} else {
$self->{no_components} = 'critical';
}
}
$self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
if ($val !~ /^(.*?),(.*?),(.*)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $status, $filter) = ($1, $2, $3);
if ($self->{output}->is_litteral_status(status => $status) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'.");
$self->{output}->option_exit();
}
$self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
}
$self->{numeric_threshold} = {};
foreach my $option (('warning', 'critical')) {
foreach my $val (@{$self->{option_results}->{$option}}) {
if ($val !~ /^(.*?),(.*?),(.*)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $regexp, $value) = ($1, $2, $3);
if ($section !~ /(humidity|temperature)/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: battery or temperature).");
$self->{output}->option_exit();
}
my $position = 0;
if (defined($self->{numeric_threshold}->{$section})) {
$position = scalar(@{$self->{numeric_threshold}->{$section}});
}
if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'.");
$self->{output}->option_exit();
}
$self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section}));
push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, regexp => $regexp };
}
}
}
sub run {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
my $snmp_request = [];
my @components = ('sp', 'temperature', 'humidity', 'switch');
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "hardware::sensors::sensorip::snmp::mode::components::$_";
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name,
error_msg => "Cannot load module '$mod_name'.");
my $func = $mod_name->can('load');
$func->(request => $snmp_request);
}
}
if (scalar(@{$snmp_request}) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'.");
$self->{output}->option_exit();
}
$self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request);
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "hardware::sensors::sensorip::snmp::mode::components::$_";
my $func = $mod_name->can('check');
$func->($self);
}
}
my $total_components = 0;
my $display_by_component = '';
my $display_by_component_append = '';
foreach my $comp (sort(keys %{$self->{components}})) {
# Skipping short msg when no components
next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0);
$total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
$display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name};
$display_by_component_append = ', ';
}
$self->{output}->output_add(severity => 'OK',
short_msg => sprintf("All %s components are ok [%s].",
$total_components,
$display_by_component)
);
if (defined($self->{option_results}->{no_component}) && $total_components == 0) {
$self->{output}->output_add(severity => $self->{no_components},
short_msg => 'No components are checked.');
}
$self->{output}->display();
$self->{output}->exit();
}
sub check_exclude {
my ($self, %options) = @_;
if (defined($options{instance})) {
if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) {
$self->{components}->{$options{section}}->{skip}++;
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
return 1;
}
} elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) {
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
return 1;
}
return 0;
}
sub absent_problem {
my ($self, %options) = @_;
if (defined($self->{option_results}->{absent}) &&
$self->{option_results}->{absent} =~ /(^|\s|,)($options{section}(\s*,|$)|${options{section}}[^,]*#\Q$options{instance}\E#)/) {
$self->{output}->output_add(severity => 'CRITICAL',
short_msg => sprintf("Component '%s' instance '%s' is not present",
$options{section}, $options{instance}));
}
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance (not present)"));
$self->{components}->{$options{section}}->{skip}++;
return 1;
}
sub get_severity_numeric {
my ($self, %options) = @_;
my $status = 'OK'; # default
my $thresholds = { warning => undef, critical => undef };
my $checked = 0;
if (defined($self->{numeric_threshold}->{$options{section}})) {
my $exits = [];
foreach (@{$self->{numeric_threshold}->{$options{section}}}) {
if ($options{instance} =~ /$_->{regexp}/) {
push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]);
$thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label});
$checked = 1;
}
}
$status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0);
}
return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked);
}
sub get_severity {
my ($self, %options) = @_;
my $status = 'UNKNOWN'; # default
if (defined($self->{overload_th}->{$options{section}})) {
foreach (@{$self->{overload_th}->{$options{section}}}) {
if ($options{value} =~ /$_->{filter}/i) {
$status = $_->{status};
return $status;
}
}
}
foreach (@{$thresholds->{$options{section}}}) {
if ($options{value} =~ /$$_[0]/i) {
$status = $$_[1];
return $status;
}
}
return $status;
}
1;
__END__
=head1 MODE
Check sensor components (Sensor Probe status, Temperatures, Humidity, Switch).
=over 8
=item B<--component>
Which component to check (Default: '.*').
Can be: 'sp', 'temperature', 'humidity', 'switch'.
=item B<--exclude>
Exclude some parts (comma seperated list) (Example: --exclude=psu)
Can also exclude specific instance: --exclude='humidty#0#'
=item B<--absent-problem>
Return an error if an entity is not 'present' (default is skipping) (comma seperated list)
Can be specific or global: --absent-problem=temperature#2#
=item B<--no-component>
Return an error if no compenents are checked.
If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--threshold-overload>
Set to overload default threshold values (syntax: section,status,regexp)
It used before default thresholds (order stays).
Example: --threshold-overload='temperature,CRITICAL,^(?!(normal)$)'
=item B<--warning>
Set warning threshold for temperatures and humidity (syntax: type,regexp,treshold)
Example: --warning='temperature,.*,30' --warning='humidity,.*,90'
=item B<--critical>
Set critical threshold for temperature and humidity (syntax: type,regexp,treshold)
Example: --critical='temperature,.*,40'
=back
=cut

View File

@ -0,0 +1,64 @@
################################################################################
# Copyright 2005-2013 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 : Quentin Garnier <qgarnier@merethis.com>
#
####################################################################################
package hardware::sensors::sensorip::snmp::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_snmp);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
# $options->{options} = options object
$self->{version} = '1.0';
%{$self->{modes}} = (
'sensors' => 'hardware::sensors::sensorip::snmp::mode::sensors',
);
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Sensor-IP sensors in SNMP.
=cut

View File

@ -46,6 +46,8 @@ my %map_disk_status = (
2 => 'unknown',
3 => 'absent',
4 => 'failed',
5 => 'spare', # since OS 5.4
6 => 'available', # since OS 5.4
);
sub check {

View File

@ -76,6 +76,8 @@ my $thresholds = {
],
disk => [
['ok', 'OK'],
['spare', 'OK'],
['available', 'OK'],
['unknown', 'UNKNOWN'],
['absent', 'OK'],
['failed', 'CRITICAL'],