This commit is contained in:
Quentin Garnier 2014-09-16 11:05:18 +02:00
parent ddd0c3c683
commit de81b0084d
8 changed files with 504 additions and 34 deletions

View File

@ -33,7 +33,7 @@
#
####################################################################################
package hardware::ups::eaton::mode::group;
package hardware::epdu::eaton::mode::group;
use base qw(centreon::plugins::mode);

View File

@ -33,7 +33,7 @@
#
####################################################################################
package hardware::ups::eaton::mode::outlet;
package hardware::epdu::eaton::mode::outlet;
use base qw(centreon::plugins::mode);

View File

@ -33,7 +33,7 @@
#
####################################################################################
package hardware::ups::eaton::plugin;
package hardware::epdu::eaton::plugin;
use strict;
use warnings;
@ -47,8 +47,8 @@ sub new {
$self->{version} = '0.1';
%{$self->{modes}} = (
'group' => 'hardware::ups::eaton::mode::group',
'outlet' => 'hardware::ups::eaton::mode::outlet',
'group' => 'hardware::epdu::eaton::mode::group',
'outlet' => 'hardware::epdu::eaton::mode::outlet',
);
return $self;

View File

@ -0,0 +1,214 @@
################################################################################
# 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::ups::powerware::mode::alarms;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::misc;
use centreon::plugins::statefile;
my %alarm_type_map = (
'.1.3.6.1.4.1.534.1.7.3' => 'OnBattery',
'.1.3.6.1.4.1.534.1.7.4' => 'LowBattery',
'.1.3.6.1.4.1.534.1.7.5' => 'UtilityPowerRestored',
'.1.3.6.1.4.1.534.1.7.6' => 'ReturnFromLowBattery',
'.1.3.6.1.4.1.534.1.7.7' => 'OutputOverload',
'.1.3.6.1.4.1.534.1.7.8' => 'InternalFailure',
'.1.3.6.1.4.1.534.1.7.9' => 'BatteryDischarged',
'.1.3.6.1.4.1.534.1.7.10' => 'InverterFailure',
'.1.3.6.1.4.1.534.1.7.11' => 'OnBypass',
'.1.3.6.1.4.1.534.1.7.12' => 'BypassNotAvailable',
'.1.3.6.1.4.1.534.1.7.13' => 'OutputOff',
'.1.3.6.1.4.1.534.1.7.14' => 'InputFailure',
'.1.3.6.1.4.1.534.1.7.15' => 'BuildingAlarm',
'.1.3.6.1.4.1.534.1.7.16' => 'ShutdownImminent',
'.1.3.6.1.4.1.534.1.7.17' => 'OnInverter',
'.1.3.6.1.4.1.534.1.7.20' => 'BreakerOpen',
'.1.3.6.1.4.1.534.1.7.21' => 'AlarmEntryAdded',
'.1.3.6.1.4.1.534.1.7.22' => 'AlarmEntryRemoved',
'.1.3.6.1.4.1.534.1.7.23' => 'AlarmBatteryBad',
'.1.3.6.1.4.1.534.1.7.24' => 'OutputOffAsRequested',
'.1.3.6.1.4.1.534.1.7.25' => 'DiagnosticTestFailed',
'.1.3.6.1.4.1.534.1.7.26' => 'CommunicationsLost',
'.1.3.6.1.4.1.534.1.7.27' => 'UpsShutdownPending',
'.1.3.6.1.4.1.534.1.7.28' => 'AlarmTestInProgress',
'.1.3.6.1.4.1.534.1.7.29' => 'AmbientTempBad',
'.1.3.6.1.4.1.534.1.7.30' => 'LossOfRedundancy',
'.1.3.6.1.4.1.534.1.7.31' => 'AlarmTempBad',
'.1.3.6.1.4.1.534.1.7.32' => 'AlarmChargerFailed',
'.1.3.6.1.4.1.534.1.7.33' => 'AlarmFanFailure',
'.1.3.6.1.4.1.534.1.7.34' => 'AlarmFuseFailure',
'.1.3.6.1.4.1.534.1.7.35' => 'PowerSwitchBad',
'.1.3.6.1.4.1.534.1.7.36' => 'ModuleFailure',
'.1.3.6.1.4.1.534.1.7.37' => 'OnAlternatePowerSource',
'.1.3.6.1.4.1.534.1.7.38' => 'AltPowerNotAvailable',
'.1.3.6.1.4.1.534.1.7.39' => 'NoticeCondition',
'.1.3.6.1.4.1.534.1.7.40' => 'RemoteTempBad',
'.1.3.6.1.4.1.534.1.7.41' => 'RemoteHumidityBad',
'.1.3.6.1.4.1.534.1.7.42' => 'AlarmOutputBad',
'.1.3.6.1.4.1.534.1.7.43' => 'AlarmAwaitingPower',
'.1.3.6.1.4.1.534.1.7.44' => 'OnMaintenanceBypass',
);
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 =>
{
"filter-type:s" => { name => 'filter_type',
default => '^(?!(UtilityPowerRestored|NoticeCondition|ReturnFromLowBattery|AlarmEntryAdded|AlarmEntryRemoved))' },
"memory" => { name => 'memory' },
"warning" => { name => 'warning' },
});
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->check_options(%options);
}
}
sub run {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
$self->{hostname} = $self->{snmp}->get_hostname();
$self->{snmp_port} = $self->{snmp}->get_port();
my $datas = {};
my $last_time;
my $exit = defined($self->{option_results}->{warning}) ? 'WARNING' : 'CRITICAL';
my ($num_alarms_checked, $num_errors) = (0, 0);
if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->read(statefile => "cache_ups_powerware_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode});
$self->{output}->output_add(severity => 'OK',
short_msg => "No new problems detected.");
$last_time = $self->{statefile_cache}->get(name => 'last_time');
} else {
$self->{output}->output_add(severity => 'OK',
short_msg => "No problems detected.");
}
my $oid_xupsAlarmEntry = '.1.3.6.1.4.1.534.1.7.2.1';
my $oid_xupsAlarmDescr = '.1.3.6.1.4.1.534.1.7.2.1.2';
my $oid_xupsAlarmTime = '.1.3.6.1.4.1.534.1.7.2.1.3';
my $result = $self->{snmp}->get_table(oid => $oid_xupsAlarmEntry);
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
next if ($key !~ /^$oid_xupsAlarmDescr\.(\d+)$/);
my $instance = $1;
my $type = $alarm_type_map{$result->{$key}};
my $time = $result->{$oid_xupsAlarmTime . '.' . $instance};
if (defined($self->{option_results}->{memory})) {
$datas->{$instance . '_type'} = $type;
$datas->{$instance . '_time'} = $time;
my $compare_type = $self->{statefile_cache}->get(name => $instance . '_type');
my $compare_time = $self->{statefile_cache}->get(name => $instance . '_time');
next if (defined($compare_type) && defined($compare_time) && $type eq $compare_type && $time eq $compare_time);
}
$num_alarms_checked++;
next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && $type !~ /$self->{option_results}->{filter_type}/);
my ($days, $hours, $minutes, $seconds) = ($time / 100 / 86400, $time / 100 % 86400 / 3600, $time / 100 % 86400 % 3600 / 60, $time / 100 % 86400 % 3600 % 60);
$num_errors++;
$self->{output}->output_add(long_msg => sprintf("%d day(s), %d:%d:%d : %s",
$days, $hours, $minutes, $seconds,
$type
)
);
}
$self->{output}->output_add(long_msg => sprintf("Number of message checked: %s", $num_alarms_checked));
if ($num_errors != 0) {
# Message problem
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("%d problem detected (use verbose for more details)", $num_errors)
);
}
if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->write(data => $datas);
}
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Check alarms (XUPS-MIB).
=over 8
=item B<--warning>
Use warning return instead 'critical'.
=item B<--memory>
Only check new alarms.
=item B<--filter-type>
Filter on type. (can be a regexp)
Default: ^(?!(UtilityPowerRestored|NoticeCondition|ReturnFromLowBattery|AlarmEntryAdded|AlarmEntryRemoved))
=back
=cut

View File

@ -0,0 +1,206 @@
################################################################################
# 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::ups::powerware::mode::environment;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::values;
my $maps_counters = {
temperature => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'temperature', no_value => 0, },
],
output_template => 'Ambiant Temperature: %.2f C', output_error_template => 'Ambiant Temperature: %s',
perfdatas => [
{ value => 'temperature_absolute', label => 'temperature', template => '%.2f',
unit => 'C' },
],
}
},
humidity => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'humidity', no_value => 0 },
],
output_template => 'Humidity: %.2f %%', output_error_template => 'Humidity: %s',
perfdatas => [
{ value => 'humidity_absolute', label => 'humidity', template => '%.2f',
unit => '%', min => 0, max => 100 },
],
}
},
};
my $oid_xupsEnvironment = '.1.3.6.1.4.1.534.1.6';
my $oid_xupsEnvAmbientTemp = '.1.3.6.1.4.1.534.1.6.1.0'; # in degree centigrade
my $oid_xupsEnvAmbientLowerLimit = '.1.3.6.1.4.1.534.1.6.2.0';
my $oid_xupsEnvAmbientUpperLimit = '.1.3.6.1.4.1.534.1.6.3.0';
my $oid_xupsEnvAmbientHumidity = '.1.3.6.1.4.1.534.1.6.4.0'; # in %
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 =>
{
});
$self->{instance_selected} = {};
foreach (keys %{$maps_counters}) {
$options{options}->add_options(arguments => {
'warning-' . $_ . ':s' => { name => 'warning-' . $_ },
'critical-' . $_ . ':s' => { name => 'critical-' . $_ },
});
my $class = $maps_counters->{$_}->{class};
$maps_counters->{$_}->{obj} = $class->new(output => $self->{output}, perfdata => $self->{perfdata},
label => $_);
$maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}});
}
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
sub manage_counters {
my ($self, %options) = @_;
foreach (sort keys %{$options{maps_counters}}) {
$options{maps_counters}->{$_}->{obj}->set(instance => $options{instance});
my ($value_check) = $options{maps_counters}->{$_}->{obj}->execute(values => $self->{instance_selected}->{$options{instance}});
# We don't want to display no value
next if ($value_check == -10);
if ($value_check != 0) {
next;
}
my $exit = $options{maps_counters}->{$_}->{obj}->threshold_check();
my $output = $options{maps_counters}->{$_}->{obj}->output();
$self->{output}->output_add(severity => $exit,
short_msg => $output
);
$options{maps_counters}->{$_}->{obj}->perfdata();
}
}
sub run {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
$self->manage_selection();
$self->manage_counters(instance => 'ambiant', maps_counters => $maps_counters);
$self->{output}->display();
$self->{output}->exit();
}
sub manage_selection {
my ($self, %options) = @_;
my $values_ok = 0;
$self->{instance_selected}->{ambiant} = {};
$self->{results} = $self->{snmp}->get_table(oid => $oid_xupsEnvironment,
nothing_quit => 1);
if (defined($self->{results}->{$oid_xupsEnvAmbientTemp}) && $self->{results}->{$oid_xupsEnvAmbientTemp} ne '' &&
$self->{results}->{$oid_xupsEnvAmbientTemp} != 0) {
$self->{instance_selected}->{ambiant}->{temperature} = $self->{results}->{$oid_xupsEnvAmbientTemp};
$values_ok++;
}
if (defined($self->{results}->{$oid_xupsEnvAmbientHumidity}) && $self->{results}->{$oid_xupsEnvAmbientHumidity} ne '' &&
$self->{results}->{$oid_xupsEnvAmbientHumidity} != 0) {
$self->{instance_selected}->{ambiant}->{humidity} = $self->{results}->{$oid_xupsEnvAmbientHumidity};
$values_ok++;
}
if (!defined($self->{option_results}->{'critical-temperature'}) || $self->{option_results}->{'critical-temperature'} eq '') {
my $crit_val = '';
$crit_val = $self->{results}->{$oid_xupsEnvAmbientLowerLimit} . ':' if (defined($self->{results}->{$oid_xupsEnvAmbientLowerLimit}) &&
$self->{results}->{$oid_xupsEnvAmbientLowerLimit} ne '');
$crit_val .= $self->{results}->{$oid_xupsEnvAmbientUpperLimit} if (defined($self->{results}->{$oid_xupsEnvAmbientUpperLimit}) &&
$self->{results}->{$oid_xupsEnvAmbientUpperLimit} ne '' && $self->{results}->{$oid_xupsEnvAmbientUpperLimit} ne 0);
$self->{perfdata}->threshold_validate(label => 'critical-temperature', value => $crit_val);
}
if ($values_ok == 0) {
$self->{output}->add_option_msg(short_msg => "Cannot get temperature and humidity values.");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check environment (temperature and humidity) (XUPS-MIB).
=over 8
=item B<--warning-*>
Threshold warning.
Can be: 'temperature', 'humidity'.
=item B<--critical-*>
Threshold critical.
Can be: 'temperature', 'humidity'.
=back
=cut

View File

@ -39,7 +39,6 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::values;
my $maps_counters = {
@ -257,9 +256,7 @@ sub manage_selection {
}
if (scalar(keys %{$self->{instance_selected}}) <= 0) {
if (defined($self->{option_results}->{name})) {
$self->{output}->add_option_msg(short_msg => "No input lines found.");
}
$self->{output}->add_option_msg(short_msg => "No input lines found.");
$self->{output}->option_exit();
}
}
@ -270,7 +267,7 @@ __END__
=head1 MODE
Check Input lines metrics (frequence, voltage, current and true power).
Check Input lines metrics (frequence, voltage, current and true power) (XUPS-MIB).
=over 8

View File

@ -39,7 +39,6 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::values;
my $maps_counters = {
@ -99,7 +98,7 @@ my $maps_counters2 = {
key_values => [
{ name => 'load', no_value => -1 },
],
output_template => 'Load: %.2f %', output_error_template => 'Load: %s',
output_template => 'Load: %.2f %%', output_error_template => 'Load: %s',
perfdatas => [
{ value => 'load_absolute', label => 'load', template => '%.2f',
unit => '%', min => 0 },
@ -271,9 +270,7 @@ sub manage_selection {
}
if (scalar(keys %{$self->{instance_selected}}) <= 0) {
if (defined($self->{option_results}->{name})) {
$self->{output}->add_option_msg(short_msg => "No output lines found.");
}
$self->{output}->add_option_msg(short_msg => "No output lines found.");
$self->{output}->option_exit();
}
}
@ -284,7 +281,7 @@ __END__
=head1 MODE
Check Output lines metrics (load, voltage, current and true power).
Check Output lines metrics (load, voltage, current and true power) (XUPS-MIB).
=over 8

View File

@ -33,21 +33,34 @@
#
####################################################################################
package hardware::ups::standard::rfc1628::mode::outputsource;
package hardware::ups::powerware::mode::outputsource;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
my %outputsource_status = (
1 => ['other', 'UNKNOWN'],
2 => ['none', 'CRITICAL'],
3 => ['normal', 'OK'],
4 => ['bypass', 'WARNING'],
5 => ['battery', 'WARNING'],
6 => ['booster', 'WARNING'],
7 => ['reducer', 'WARNING'],
my $oid_xupsOutputSource = '.1.3.6.1.4.1.534.1.4.5.0';
my $thresholds = {
osource => [
['normal', 'OK'],
['.*', 'CRITICAL'],
],
};
my %map_osource_status = (
1 => 'other',
2 => 'none',
3 => 'normal',
4 => 'bypass',
5 => 'battery',
6 => 'booster',
7 => 'reducer',
8 => 'parallelCapacity',
9 => 'parallelRedundant',
10 => 'highEfficiencyMode',
11 => 'maintenanceBypass',
);
sub new {
@ -57,7 +70,8 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
{
"threshold-overload:s@" => { name => 'threshold_overload' },
});
return $self;
@ -66,6 +80,21 @@ sub new {
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
$self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
if ($val !~ /^(.*?),(.*)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong treshold-overload option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $status, $filter) = ('osource', $1, $2);
if ($self->{output}->is_litteral_status(status => $status) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong treshold-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};
}
}
sub run {
@ -73,28 +102,55 @@ sub run {
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
my $oid_upsOutputSource = '.1.3.6.1.2.1.33.1.4.1.0';
my $result = $self->{snmp}->get_leef(oids => [$oid_upsOutputSource], nothing_quit => 1);
my $status = $result->{'.1.3.6.1.2.1.33.1.4.1.0'};
$self->{output}->output_add(severity => ${$outputsource_status{$status}}[1],
short_msg => sprintf("Output source status is %s", ${$outputsource_status{$status}}[0]));
my $result = $self->{snmp}->get_leef(oids => [$oid_xupsOutputSource], nothing_quit => 1);
my $exit = $self->get_severity(section => 'osource', value => $map_osource_status{$result->{$oid_xupsOutputSource}});
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Output source status is %s",
$map_osource_status{$result->{$oid_xupsOutputSource}}));
$self->{output}->display();
$self->{output}->exit();
}
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 output source status.
Check output source status (XUPS-MIB).
=over 8
=item B<--threshold-overload>
Set to overload default threshold values (syntax: status,regexp)
It used before default thresholds (order stays).
Example: --threshold-overload='WARNING,bypass|booster'
=back
=cut